NumCpp  2.7.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
solve.hpp
Go to the documentation of this file.
1 #pragma once
29 
32 #include "NumCpp/Functions/dot.hpp"
33 #include "NumCpp/Linalg/inv.hpp"
34 #include "NumCpp/NdArray.hpp"
35 
36 namespace nc
37 {
38  namespace linalg
39  {
40  //============================================================================
41  // Method Description:
52  template<typename dtype>
54  {
56 
57  if (!inA.issquare())
58  {
59  THROW_INVALID_ARGUMENT_ERROR("input array a must be square.");
60  }
61 
62  if (!inB.isflat())
63  {
64  THROW_INVALID_ARGUMENT_ERROR("input array b must be flat.");
65  }
66 
67  if (inA.numCols() != inB.size())
68  {
69  THROW_INVALID_ARGUMENT_ERROR("input array b size must be the same as the square size of a.");
70  }
71 
72  return dot(inv(inA), inB.template astype<double>().reshape(inB.size(), 1)).reshape(inB.shape());
73  }
74  } // namespace linalg
75 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
uint32 numCols() const noexcept
Definition: NdArrayCore.hpp:3418
size_type size() const noexcept
Definition: NdArrayCore.hpp:4296
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4283
bool issquare() const noexcept
Definition: NdArrayCore.hpp:2918
bool isflat() const noexcept
Definition: NdArrayCore.hpp:2855
NdArray< dtype > & reshape(size_type inSize)
Definition: NdArrayCore.hpp:4067
NdArray< double > inv(const NdArray< dtype > &inArray)
Definition: inv.hpp:52
NdArray< double > solve(const NdArray< dtype > &inA, const NdArray< dtype > &inB)
Definition: solve.hpp:53
Definition: Coordinate.hpp:45
NdArray< dtype > dot(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: dot.hpp:47