NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
svd.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <utility>
31
35#include "NumCpp/NdArray.hpp"
36
37namespace nc::linalg
38{
39 //============================================================================
40 // Method Description:
50 template<typename dtype>
51 void svd(const NdArray<dtype>& inArray, NdArray<double>& outU, NdArray<double>& outS, NdArray<double>& outVt)
52 {
54
55 SVD svdSolver(inArray.template astype<double>());
56 outU = svdSolver.u();
57
58 NdArray<double> vt = svdSolver.v().transpose();
59 outVt = std::move(vt);
60
61 NdArray<double> s = diagflat(svdSolver.s(), 0);
62 outS = std::move(s);
63 }
64} // namespace nc::linalg
#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 transpose() const
Definition: NdArrayCore.hpp:4882
Definition: SVDClass.hpp:47
const NdArray< double > & s() noexcept
Definition: SVDClass.hpp:96
const NdArray< double > & v() noexcept
Definition: SVDClass.hpp:85
const NdArray< double > & u() noexcept
Definition: SVDClass.hpp:74
Definition: cholesky.hpp:41
void svd(const NdArray< dtype > &inArray, NdArray< double > &outU, NdArray< double > &outS, NdArray< double > &outVt)
Definition: svd.hpp:51
NdArray< dtype > diagflat(const NdArray< dtype > &inArray, int32 k=0)
Definition: diagflat.hpp:51