NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
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
size_type size() const noexcept
Definition: NdArrayCore.hpp:4524
self_type & reshape(size_type inSize)
Definition: NdArrayCore.hpp:4271
bool issquare() const noexcept
Definition: NdArrayCore.hpp:3009
bool isflat() const noexcept
Definition: NdArrayCore.hpp:2945
size_type numCols() const noexcept
Definition: NdArrayCore.hpp:3465
const Shape & shape() const noexcept
Definition: NdArrayCore.hpp:4511
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