NumCpp  2.16.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 const auto svd = SVD{ inArray };
56
57 outU = svd.u();
58 outS = std::move(svd.s()[Slice(std::min(inArray.numRows(), inArray.numCols()))]);
59 outVT = std::move(svd.v().transpose());
60 }
61} // 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
size_type numCols() const noexcept
Definition: NdArrayCore.hpp:3545
size_type numRows() const noexcept
Definition: NdArrayCore.hpp:3557
A Class for slicing into NdArrays.
Definition: Slice.hpp:45
Performs the singular value decomposition of a general matrix.
Definition: svd/SVD.hpp:50
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 > min(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: min.hpp:44