NumCpp  2.17.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
solve.hpp
Go to the documentation of this file.
1
28#pragma once
29
33#include "NumCpp/Linalg/inv.hpp"
34#include "NumCpp/NdArray.hpp"
35
36namespace nc::linalg
37{
38 //============================================================================
39 // Method Description:
50 template<typename dtype>
52 {
54
55 if (!inA.issquare())
56 {
57 THROW_INVALID_ARGUMENT_ERROR("input array a must be square.");
58 }
59
60 if (!inB.isflat())
61 {
62 THROW_INVALID_ARGUMENT_ERROR("input array b must be flat.");
63 }
64
65 if (inA.numCols() != inB.size())
66 {
67 THROW_INVALID_ARGUMENT_ERROR("input array b size must be the same as the square size of a.");
68 }
69
70 return dot(inv(inA), inB.template astype<double>().reshape(inB.size(), 1)).reshape(inB.shape());
71 }
72} // namespace nc::linalg
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:139
size_type size() const noexcept
Definition NdArrayCore.hpp:4604
bool issquare() const noexcept
Definition NdArrayCore.hpp:3089
bool isflat() const noexcept
Definition NdArrayCore.hpp:3025
size_type numCols() const noexcept
Definition NdArrayCore.hpp:3545
const Shape & shape() const noexcept
Definition NdArrayCore.hpp:4591
Definition cholesky.hpp:41
NdArray< double > inv(const NdArray< dtype > &inArray)
Definition inv.hpp:54
NdArray< double > solve(const NdArray< dtype > &inA, const NdArray< dtype > &inB)
Definition solve.hpp:51
NdArray< dtype > dot(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition dot.hpp:48
NdArray< dtypeOut > astype(const NdArray< dtype > inArray)
Definition astype.hpp:45