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
pinv.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <string>
31
33#include "NumCpp/Core/Types.hpp"
35#include "NumCpp/Linalg/svd.hpp"
36#include "NumCpp/NdArray.hpp"
37
38namespace nc::linalg
39{
40 //============================================================================
41 // Method Description:
49 template<typename dtype>
51 {
53
57 svd(inArray, u, d, v);
58
59 const auto inShape = inArray.shape();
60 auto dPlus = nc::zeros<double>(inShape.cols, inShape.rows); // transpose
61
62 for (uint32 i = 0; i < d.shape().rows; ++i)
63 {
64 dPlus(i, i) = 1. / d(i, i);
65 }
66
67 return v.transpose().dot(dPlus).dot(u.transpose());
68 }
69} // namespace nc::linalg
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition StaticAsserts.hpp:56
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:139
self_type transpose() const
Definition NdArrayCore.hpp:4958
self_type dot(const self_type &inOtherArray) const
Definition NdArrayCore.hpp:2795
Definition cholesky.hpp:41
NdArray< double > pinv(const NdArray< dtype > &inArray)
Definition pinv.hpp:50
void svd(const NdArray< dtype > &inArray, NdArray< double > &outU, NdArray< double > &outS, NdArray< double > &outVt)
Definition svd.hpp:51
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
std::uint32_t uint32
Definition Types.hpp:40