18 template <
class T,
int Rows,
int Columns, eMatrixOrder Order, eMatrixLayout Layout,
bool Packed>
20 template <
int Rows_,
int Columns_>
23 static constexpr
int Sdim = std::min(Rows, Columns);
24 static constexpr
int Udim = Rows;
25 static constexpr
int Vdim = Columns;
37 template <
class T, eMatrixOrder Order, eMatrixLayout Layout,
bool Packed>
38 void Rq2x2Helper(
const Matrix<T, 2, 2, Order, Layout, Packed>& A, T& x, T& y, T& z, T& c2, T& s2) {
52 T maxden = std::max(abs(c), abs(d));
54 T rcmaxden = 1 / maxden;
58 T den = 1 / sqrt(c * c + d * d);
60 T numx = (-b * c + a * d);
61 T numy = (a * c + b * d);
71 template <
class T, eMatrixOrder Order, eMatrixLayout Layout,
bool Packed>
72 void Svd2x2Helper(
const Matrix<T, 2, 2, Order, Layout, Packed>& A, T& c1, T& s1, T& c2, T& s2, T& d1, T& d2) {
78 T scaler = T(1) / std::max(abs(x), std::max(abs(y), std::numeric_limits<T>::min()));
79 T x_ = x * scaler, y_ = y * scaler, z_ = z * scaler;
80 T numer = ((z_ - x_) * (z_ + x_)) + y_ * y_;
82 numer = numer == 0 ? std::numeric_limits<T>::infinity() : numer;
83 T zeta = numer / gamma;
85 T t = 2 *
sign_nonzero(zeta) / (abs(zeta) + sqrt(zeta * zeta + 4));
88 c1 = T(1) / sqrt(T(1) + t * t);
92 T usa = c1 * x - s1 * y;
93 T usb = s1 * x + c1 * y;
98 t = c1 * c2 + s1 * s2;
99 s2 = c2 * s1 - c1 * s2;
103 d1 = std::hypot(usa, usc);
104 d2 = std::hypot(usb, usd);
105 T dmax = std::max(d1, d2);
106 T usmax1 = d2 > d1 ? usd : usa;
107 T usmax2 = d2 > d1 ? usb : -usc;
110 dmax *= d2 > d1 ? signd1 : 1;
112 T rcpdmax = 1 / dmax;
114 c1 = dmax != T(0) ? usmax1 * rcpdmax : T(1);
115 s1 = dmax != T(0) ? usmax2 * rcpdmax : T(0);
119 template <
class T,
int Rows,
int Columns, eMatrixOrder Order, eMatrixLayout Layout,
bool Packed>
126 if (Rows > Columns) {
129 U = Q.template Submatrix<Rows, Columns>(0, 0);
138 T tolerance = T(1e-6);
148 s += B(i, j) * B(i, j) + B(j, i) * B(j, i);
150 T s1, c1, s2, c2, d1, d2;
162 bElems.
Set(B(i, col), B(j, col), B(i, col), B(j, col));
163 bElems *= givensCoeffs;
164 B(i, col) = bElems(0) + bElems(1);
165 B(j, col) = bElems(2) + bElems(3);
182 }
while (s > tolerance * N);
187 Sout(i, i) = B(i, i);
193 template <
class T,
int Rows,
int Columns, eMatrixOrder Order, eMatrixLayout Layout,
bool Packed>
206 template <
class T,
int Rows,
int Columns, eMatrixOrder Order, eMatrixLayout Layout,
bool Packed>
auto Identity()
Creates an identity matrix or identity quaternion.
Definition: IdentityBuilder.hpp:42
auto DecomposeQR(Matrix< T, Rows, Columns, Order, Layout, Packed > m)
Calculates the QR decomposition of the matrix using Householder transforms.
Definition: DecomposeQR.hpp:34
Matrix< T, Columns, Rows, Order, Layout, Packed > Transpose(const Matrix< T, Rows, Columns, Order, Layout, Packed > &m)
Transposes the matrix in-place.
Definition: MatrixFunction.hpp:34
MatrixT< Sdim, Sdim > S
Definition: DecomposeSVD.hpp:31
Represents a vector in N-dimensional space.
Definition: Definitions.hpp:57
auto DecomposeSVD(Matrix< T, Rows, Columns, Order, Layout, Packed > m, std::true_type)
Definition: DecomposeSVD.hpp:120
T sign_nonzero(T arg)
Definition: MathUtil.hpp:11
Vector & Set(Scalars... scalars)
Sets the vector's elements to the given scalars.
Definition: VectorImpl.hpp:476
T NormSquared(const Matrix< T, Rows, Columns, Order, Layout, Packed > &m)
Calculates the square of the Frobenius norm of the matrix.
Definition: MatrixFunction.hpp:67
std::array< Vector< T, StripeDim, Packed >, StripeCount > stripes
Definition: MatrixImpl.hpp:46
A utility class that can do common operations with the singular value decomposition, i.e. solving equation systems.
Definition: DecomposeSVD.hpp:19
Definition: Approx.hpp:11
auto DecomposeSVD(Matrix< T, Rows, Columns, Order, Layout, Packed > m)
Calculates the thin SVD of the matrix.
Definition: DecomposeSVD.hpp:207
MatrixT< Sdim, Vdim > V
Definition: DecomposeSVD.hpp:32
constexpr int ColumnCount() const
Returns the number of columns of the matrix.
Definition: MatrixImpl.hpp:27
Definition: Definitions.hpp:63
DecompositionSVD(MatrixT< Udim, Sdim > U, MatrixT< Sdim, Sdim > S, MatrixT< Sdim, Vdim > V)
Definition: DecomposeSVD.hpp:28
MatrixT< Udim, Sdim > U
Definition: DecomposeSVD.hpp:30
void Rq2x2Helper(const Matrix< T, 2, 2, Order, Layout, Packed > &A, T &x, T &y, T &z, T &c2, T &s2)
Definition: DecomposeSVD.hpp:38
void Svd2x2Helper(const Matrix< T, 2, 2, Order, Layout, Packed > &A, T &c1, T &s1, T &c2, T &s2, T &d1, T &d2)
Definition: DecomposeSVD.hpp:72
auto Zero()
Creates a matrix with all elements zero.
Definition: ZeroBuilder.hpp:34