NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
self_type & reshape(size_type inSize)
Definition NdArrayCore.hpp:4347
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:47
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59