ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkBridgeMathSVD.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkBridgeMathSVD_h
19#define itkBridgeMathSVD_h
20
21#include "itkMacro.h"
23#include "vnl/vnl_matrix.h"
24#include "vnl/vnl_matrix_fixed.h"
25#include "vnl/vnl_vector.h"
26#include "vnl/vnl_vector_fixed.h"
27
28#include "itk_eigen.h"
29#include ITK_EIGEN(Dense)
30
31#include <complex>
32#include <limits>
33#include <type_traits>
34
35namespace itk
36{
37// Forward-declared to break the itkMatrix.h <-> itkBridgeMathSVD.h include
38// cycle; the itk::Matrix SVD overload needs the complete type only at
39// instantiation, where the caller has already included itkMatrix.h.
40template <typename T, unsigned int VRows, unsigned int VColumns>
41class Matrix;
42} // namespace itk
43
44namespace itk::bridge
45{
46namespace Math
47{
48
49namespace detail
50{
51// rcond < 0 selects an automatic relative threshold of n * epsilon.
52template <typename TReal>
53TReal
54ResolveRcond(TReal rcond, unsigned int n)
55{
56 return rcond < TReal{ 0 } ? static_cast<TReal>(n) * std::numeric_limits<TReal>::epsilon() : rcond;
57}
58
59// Moore-Penrose pseudo-inverse V diag(1/w) U^T, with singular values at or below
60// rcond*max(w) treated as zero. U and V may be distinct types (rectangular fixed).
61template <typename TMatrixU, typename TVector, typename TMatrixV, typename TReal>
62auto
63PseudoInverse(const TMatrixU & U, const TVector & W, const TMatrixV & V, TReal rcond)
64{
65 const unsigned int k = W.size();
66 // W is sorted descending (Eigen guarantee), so W[0] is the max without an O(k) scan.
67 const TReal tol = ResolveRcond(rcond, k) * W[0];
68 TMatrixV scaledV = V;
69 for (unsigned int col = 0; col < k; ++col)
70 {
71 const TReal s = (W[col] > tol) ? TReal{ 1 } / W[col] : TReal{ 0 };
72 for (unsigned int i = 0; i < scaledV.rows(); ++i)
73 {
74 scaledV(i, col) *= s;
75 }
76 }
77 return scaledV * U.transpose();
78}
79
80// Least-squares / minimum-norm solution x = V diag(1/w) U^T b of A x = b.
81template <typename TMatrixU, typename TVector, typename TMatrixV, typename TVectorB, typename TReal>
82auto
83SolveLinear(const TMatrixU & U, const TVector & W, const TMatrixV & V, const TVectorB & b, TReal rcond)
84{
85 const unsigned int n = W.size();
86 const TReal tol = ResolveRcond(rcond, n) * W[0]; // W sorted descending; W[0] == max
87 auto utb = U.transpose() * b;
88 for (unsigned int k = 0; k < n; ++k)
89 {
90 utb[k] = (W[k] > tol) ? utb[k] / W[k] : TReal{ 0 };
91 }
92 return V * utb;
93}
94
95template <typename TVector, typename TReal>
96unsigned int
97NumericalRank(const TVector & W, TReal rcond)
98{
99 const unsigned int n = W.size();
100 const TReal tol = ResolveRcond(rcond, n) * W[0]; // W sorted descending; W[0] == max
101 unsigned int count = 0;
102 for (unsigned int k = 0; k < n; ++k)
103 {
104 if (W[k] > tol)
105 {
106 ++count;
107 }
108 }
109 return count;
110}
111
112// Reconstruct U diag(w) V^T, treating singular values at or below rcond*max(w) as
113// zero (a truncated, rank-reduced reconstruction of A).
114template <typename TMatrixU, typename TVector, typename TMatrixV, typename TReal>
115auto
116Recompose(const TMatrixU & U, const TVector & W, const TMatrixV & V, TReal rcond)
117{
118 const unsigned int k = W.size();
119 const TReal tol = ResolveRcond(rcond, k) * W[0]; // W sorted descending; W[0] == max
120 TMatrixU scaledU = U;
121 for (unsigned int col = 0; col < k; ++col)
122 {
123 const TReal s = (W[col] > tol) ? W[col] : TReal{ 0 };
124 for (unsigned int i = 0; i < scaledU.rows(); ++i)
125 {
126 scaledU(i, col) *= s;
127 }
128 }
129 return scaledU * V.transpose();
130}
131
132// Reconstruct U diag(w') V^T with caller-supplied singular values (no truncation);
133// serves the modify-W-then-recompose idiom (value clamping/inversion/zeroing).
134template <typename TMatrixU, typename TVector, typename TMatrixV>
135auto
136RecomposeWith(const TMatrixU & U, const TVector & modifiedW, const TMatrixV & V)
137{
138 TMatrixU scaledU = U;
139 for (unsigned int col = 0; col < modifiedW.size(); ++col)
140 {
141 for (unsigned int i = 0; i < scaledU.rows(); ++i)
142 {
143 scaledU(i, col) *= modifiedW[col];
144 }
145 }
146 return scaledU * V.transpose();
147}
148
149// Reciprocal condition number sigma_min/sigma_max; 0 when the matrix is singular.
150template <typename TVector>
151auto
152WellCondition(const TVector & W) -> std::decay_t<decltype(W[0])>
153{
154 const unsigned int k = W.size();
155 if (k == 0 || W[0] == 0)
156 {
157 return 0;
158 }
159 return W[k - 1] / W[0]; // W sorted descending
160}
161
162// Product of the singular values (|det A| for a square A).
163template <typename TVector>
164auto
165DeterminantMagnitude(const TVector & W) -> std::decay_t<decltype(W[0])>
166{
167 std::decay_t<decltype(W[0])> product{ 1 };
168 for (unsigned int k = 0; k < W.size(); ++k)
169 {
170 product *= W[k];
171 }
172 return product;
173}
174} // namespace detail
175
178template <typename TReal, unsigned int VDim>
180{
181 vnl_matrix_fixed<TReal, VDim, VDim> U{};
182 vnl_vector_fixed<TReal, VDim> W{};
183 vnl_matrix_fixed<TReal, VDim, VDim> V{};
184
186 vnl_matrix_fixed<TReal, VDim, VDim>
187 PseudoInverse(TReal rcond = TReal{ -1 }) const
188 {
189 return detail::PseudoInverse(U, W, V, rcond);
190 }
191
193 vnl_vector_fixed<TReal, VDim>
194 Solve(const vnl_vector_fixed<TReal, VDim> & b, TReal rcond = TReal{ -1 }) const
195 {
196 return detail::SolveLinear(U, W, V, b, rcond);
197 }
198
200 unsigned int
201 Rank(TReal rcond = TReal{ -1 }) const
202 {
203 return detail::NumericalRank(W, rcond);
204 }
205
207 vnl_matrix_fixed<TReal, VDim, VDim>
208 Recompose(TReal rcond = TReal{ -1 }) const
209 {
210 return detail::Recompose(U, W, V, rcond);
211 }
212
214 vnl_matrix_fixed<TReal, VDim, VDim>
215 RecomposeWith(const vnl_vector_fixed<TReal, VDim> & modifiedW) const
216 {
217 return detail::RecomposeWith(U, modifiedW, V);
218 }
219
222 vnl_vector_fixed<TReal, VDim>
224 {
225 return V.get_column(VDim - 1);
226 }
227
229 TReal
231 {
232 return detail::WellCondition(W);
233 }
234
236 TReal
238 {
240 }
241};
242
246template <typename TReal>
248{
249 vnl_matrix<TReal> U{};
250 vnl_vector<TReal> W{};
251 vnl_matrix<TReal> V{};
252
254 vnl_matrix<TReal>
255 PseudoInverse(TReal rcond = TReal{ -1 }) const
256 {
257 return detail::PseudoInverse(U, W, V, rcond);
258 }
259
261 vnl_vector<TReal>
262 Solve(const vnl_vector<TReal> & b, TReal rcond = TReal{ -1 }) const
263 {
264 return detail::SolveLinear(U, W, V, b, rcond);
265 }
266
268 unsigned int
269 Rank(TReal rcond = TReal{ -1 }) const
270 {
271 return detail::NumericalRank(W, rcond);
272 }
273
275 vnl_matrix<TReal>
276 Recompose(TReal rcond = TReal{ -1 }) const
277 {
278 return detail::Recompose(U, W, V, rcond);
279 }
280
282 vnl_matrix<TReal>
283 RecomposeWith(const vnl_vector<TReal> & modifiedW) const
284 {
285 return detail::RecomposeWith(U, modifiedW, V);
286 }
287
292 vnl_vector<TReal>
294 {
295 if (U.rows() < V.rows())
296 {
297 itkGenericExceptionMacro(
298 "NullVector() requires rows >= cols; the thin V of an underdetermined input does not span the nullspace.");
299 }
300 return V.get_column(V.cols() - 1);
301 }
302
304 TReal
306 {
307 return detail::WellCondition(W);
308 }
309
311 TReal
313 {
315 }
316};
317
321template <typename TReal, unsigned int VRows, unsigned int VCols>
323{
324 static constexpr unsigned int K = (VRows < VCols) ? VRows : VCols;
325
326 vnl_matrix_fixed<TReal, VRows, K> U{};
327 vnl_vector_fixed<TReal, K> W{};
328 vnl_matrix_fixed<TReal, VCols, K> V{};
329
331 vnl_matrix_fixed<TReal, VCols, VRows>
332 PseudoInverse(TReal rcond = TReal{ -1 }) const
333 {
334 return detail::PseudoInverse(U, W, V, rcond);
335 }
336
338 vnl_vector_fixed<TReal, VCols>
339 Solve(const vnl_vector_fixed<TReal, VRows> & b, TReal rcond = TReal{ -1 }) const
340 {
341 return detail::SolveLinear(U, W, V, b, rcond);
342 }
343
345 unsigned int
346 Rank(TReal rcond = TReal{ -1 }) const
347 {
348 return detail::NumericalRank(W, rcond);
349 }
350
352 vnl_matrix_fixed<TReal, VRows, VCols>
353 Recompose(TReal rcond = TReal{ -1 }) const
354 {
355 return detail::Recompose(U, W, V, rcond);
356 }
357
359 vnl_matrix_fixed<TReal, VRows, VCols>
360 RecomposeWith(const vnl_vector_fixed<TReal, K> & modifiedW) const
361 {
362 return detail::RecomposeWith(U, modifiedW, V);
363 }
364
368 vnl_vector_fixed<TReal, VCols>
370 {
371 static_assert(VRows >= VCols, "NullVector() requires VRows >= VCols (thin V cannot span the nullspace).");
372 return V.get_column(K - 1);
373 }
374
376 TReal
378 {
379 return detail::WellCondition(W);
380 }
381
383 TReal
385 {
387 }
388};
389
390namespace detail
391{
392// Above this compile-time size the fixed overload delegates to the runtime path
393// (keeps a large VDim off Eigen's stack-allocation limit).
394constexpr unsigned int kFixedSVDMaxDim = 16;
395
396// JacobiSVD+NoQRPreconditioner is fastest for small square inputs; BDCSVD is
397// faster and more accurate for larger n.
398constexpr unsigned int kJacobiMaxDim = 6;
399
400// Runtime-sized square SVD: JacobiSVD + NoQRPreconditioner for small n, BDCSVD for
401// larger n where Jacobi sweeps scale poorly. Throws on a failed decomposition.
402template <typename TReal>
403void
404DynamicSquareSVDEigen(const TReal * inData, unsigned int n, TReal * uData, TReal * wData, TReal * vData)
405{
406 using RowMajor = Eigen::Matrix<TReal, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
407 using ColMajor = Eigen::Matrix<TReal, Eigen::Dynamic, Eigen::Dynamic>;
408 constexpr int full = Eigen::ComputeFullU | Eigen::ComputeFullV;
409
410 const Eigen::Map<const RowMajor> inMap(inData, n, n);
411 Eigen::Map<RowMajor> uMap(uData, n, n);
412 Eigen::Map<RowMajor> vMap(vData, n, n);
413
414 const auto extract = [&](const auto & svd) {
415 if (svd.info() != Eigen::Success)
416 {
417 itkGenericExceptionMacro("itk::bridge::Math::SVD failed; input is likely non-finite (NaN/Inf).");
418 }
419 uMap = svd.matrixU();
420 vMap = svd.matrixV();
421 for (unsigned int i = 0; i < n; ++i)
422 {
423 wData[i] = svd.singularValues()[i];
424 }
425 };
426
427 if (n <= kJacobiMaxDim)
428 {
429 extract(Eigen::JacobiSVD < ColMajor, full | Eigen::NoQRPreconditioner > (inMap));
430 }
431 else
432 {
433 extract(Eigen::BDCSVD<ColMajor, full>(inMap));
434 }
435}
436
437// NoQRPreconditioner skips the column-pivot QR (wasted for a square input); large
438// VDim falls back to the runtime path. Throws on a failed/non-finite decomposition.
439template <unsigned int VDim, typename TReal>
440void
441SquareSVDEigen(const TReal * inData, TReal * uData, TReal * wData, TReal * vData)
442{
443 if constexpr (VDim > kFixedSVDMaxDim)
444 {
445 DynamicSquareSVDEigen<TReal>(inData, VDim, uData, wData, vData);
446 }
447 else
448 {
449 // Compile-time sizes ≤ kFixedSVDMaxDim always take JacobiSVD: it stack-allocates,
450 // fully unrolls, and beats BDCSVD's dynamic setup at these sizes (kJacobiMaxDim
451 // gates only the runtime path, where BDCSVD's allocation pays off for larger n).
452 using RowMajor = Eigen::Matrix<TReal, VDim, VDim, Eigen::RowMajor>;
453 using ColMajor = Eigen::Matrix<TReal, VDim, VDim>;
454 constexpr int options = Eigen::ComputeFullU | Eigen::ComputeFullV | Eigen::NoQRPreconditioner;
455
456 const Eigen::Map<const RowMajor> inMap(inData);
457 const Eigen::JacobiSVD<ColMajor, options> svd(inMap);
458 if (svd.info() != Eigen::Success)
459 {
460 itkGenericExceptionMacro("itk::bridge::Math::SVD failed; input is likely non-finite (NaN/Inf).");
461 }
462
463 Eigen::Map<RowMajor> uMap(uData);
464 Eigen::Map<RowMajor> vMap(vData);
465 uMap = svd.matrixU();
466 vMap = svd.matrixV();
467 for (unsigned int i = 0; i < VDim; ++i)
468 {
469 wData[i] = svd.singularValues()[i];
470 }
471 }
472}
473
474// Rectangular SVD via BDCSVD with thin U/V (Eigen's general engine for non-square
475// inputs). For an m x n input: U is m x k, V is n x k, W has length k = min(m, n).
476// Throws on a failed decomposition.
477template <typename TReal>
478void
479RectangularSVDEigen(const TReal * inData,
480 unsigned int rows,
481 unsigned int cols,
482 TReal * uData,
483 TReal * wData,
484 TReal * vData)
485{
486 using RowMajor = Eigen::Matrix<TReal, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
487 using ColMajor = Eigen::Matrix<TReal, Eigen::Dynamic, Eigen::Dynamic>;
488 constexpr int thin = Eigen::ComputeThinU | Eigen::ComputeThinV;
489 const unsigned int k = (rows < cols) ? rows : cols;
490
491 const Eigen::Map<const RowMajor> inMap(inData, rows, cols);
492 const Eigen::BDCSVD<ColMajor, thin> svd(inMap);
493 if (svd.info() != Eigen::Success)
494 {
495 itkGenericExceptionMacro("itk::bridge::Math::SVD failed; input is likely non-finite (NaN/Inf).");
496 }
497 Eigen::Map<RowMajor> uMap(uData, rows, k);
498 Eigen::Map<RowMajor> vMap(vData, cols, k);
499 uMap = svd.matrixU();
500 vMap = svd.matrixV();
501 for (unsigned int i = 0; i < k; ++i)
502 {
503 wData[i] = svd.singularValues()[i];
504 }
505}
506template <typename T>
507struct IsComplex : std::false_type
508{};
509template <typename T>
510struct IsComplex<std::complex<T>> : std::true_type
511{};
512
513// Eigen's SVD takes complex input and returns real singular values, so complex
514// matrices bypass SVDResult, whose element type doubles as the singular-value type.
515template <typename TComplex>
516vnl_matrix<TComplex>
517ComplexPseudoInverse(const vnl_matrix<TComplex> & A)
518{
519 using TReal = typename TComplex::value_type;
520 using RowMajor = Eigen::Matrix<TComplex, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
521 using ColMajor = Eigen::Matrix<TComplex, Eigen::Dynamic, Eigen::Dynamic>;
522 constexpr int thin = Eigen::ComputeThinU | Eigen::ComputeThinV;
523
524 const unsigned int rows = A.rows();
525 const unsigned int cols = A.cols();
526 if (rows == 0 || cols == 0)
527 {
528 itkGenericExceptionMacro("itk::bridge::Math::PseudoInverse requires a non-empty matrix.");
529 }
530 const Eigen::Map<const RowMajor> inMap(A.data_block(), rows, cols);
531 const Eigen::BDCSVD<ColMajor, thin> svd(inMap);
532 if (svd.info() != Eigen::Success)
533 {
534 itkGenericExceptionMacro("itk::bridge::Math::PseudoInverse failed; input is likely non-finite (NaN/Inf).");
535 }
536
537 const unsigned int k = svd.singularValues().size();
538 const TReal tol = ResolveRcond(TReal{ -1 }, k) * svd.singularValues()[0];
539 ColMajor scaledV = svd.matrixV();
540 for (unsigned int col = 0; col < k; ++col)
541 {
542 const TReal w = svd.singularValues()[col];
543 scaledV.col(col) *= (w > tol) ? TReal{ 1 } / w : TReal{ 0 };
544 }
545 vnl_matrix<TComplex> result(cols, rows);
546 Eigen::Map<RowMajor> resultMap(result.data_block(), cols, rows);
547 resultMap = scaledV * svd.matrixU().adjoint();
548 return result;
549}
550} // namespace detail
551
552// The Eigen JacobiSVD/BDCSVD instantiations behind the detail engines dominate
553// compile memory: without pre-instantiation, GCC needs ~2 GB per translation unit
554// that inverts an itk::Matrix. Declare the common specializations extern and define
555// them once in itkBridgeMathSVD.cxx so consumers link instead of re-instantiating them.
556#if defined(ITKCommon_EXPORTS)
557# define ITKCommon_EXPORT_EXPLICIT ITK_TEMPLATE_EXPORT
558#else
559# define ITKCommon_EXPORT_EXPLICIT ITKCommon_EXPORT
560#endif
561
562#define ITK_MATH_SVD_FIXED_DIMS(F) F(1) F(2) F(3) F(4) F(5) F(6)
563
564namespace detail
565{
566ITK_GCC_PRAGMA_DIAG_PUSH()
567ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
568
569#define ITK_MATH_SVD_EXTERN_FIXED(D) \
570 extern template ITKCommon_EXPORT_EXPLICIT void SquareSVDEigen<D, float>(const float *, float *, float *, float *); \
571 extern template ITKCommon_EXPORT_EXPLICIT void SquareSVDEigen<D, double>( \
572 const double *, double *, double *, double *);
574#undef ITK_MATH_SVD_EXTERN_FIXED
575
576extern template ITKCommon_EXPORT_EXPLICIT void
577DynamicSquareSVDEigen<float>(const float *, unsigned int, float *, float *, float *);
578extern template ITKCommon_EXPORT_EXPLICIT void
579DynamicSquareSVDEigen<double>(const double *, unsigned int, double *, double *, double *);
580extern template ITKCommon_EXPORT_EXPLICIT void
581RectangularSVDEigen<float>(const float *, unsigned int, unsigned int, float *, float *, float *);
582extern template ITKCommon_EXPORT_EXPLICIT void
583RectangularSVDEigen<double>(const double *, unsigned int, unsigned int, double *, double *, double *);
584extern template ITKCommon_EXPORT_EXPLICIT vnl_matrix<std::complex<float>>
585ComplexPseudoInverse<std::complex<float>>(const vnl_matrix<std::complex<float>> &);
586extern template ITKCommon_EXPORT_EXPLICIT vnl_matrix<std::complex<double>>
587ComplexPseudoInverse<std::complex<double>>(const vnl_matrix<std::complex<double>> &);
588
589ITK_GCC_PRAGMA_DIAG_POP()
590} // namespace detail
591
592#undef ITKCommon_EXPORT_EXPLICIT
593
624template <typename TReal, unsigned int VDim>
626SVD(const vnl_matrix_fixed<TReal, VDim, VDim> & A, bool canonicalizeSigns = true)
627{
629 detail::SquareSVDEigen<VDim>(A.data_block(), result.U.data_block(), result.W.data_block(), result.V.data_block());
630 if (canonicalizeSigns)
631 {
633 }
634 return result;
635}
636
638template <typename TReal, unsigned int VDim>
639FixedSquareSVDResult<TReal, VDim>
640SVD(const Matrix<TReal, VDim, VDim> & A, bool canonicalizeSigns = true)
641{
642 return SVD<TReal, VDim>(A.GetVnlMatrix(), canonicalizeSigns);
643}
644
648template <typename TReal, unsigned int VRows, unsigned int VCols, typename = std::enable_if_t<VRows != VCols>>
649FixedRectangularSVDResult<TReal, VRows, VCols>
650SVD(const vnl_matrix_fixed<TReal, VRows, VCols> & A, bool canonicalizeSigns = true)
651{
654 A.data_block(), VRows, VCols, result.U.data_block(), result.W.data_block(), result.V.data_block());
655 if (canonicalizeSigns)
656 {
658 }
659 return result;
660}
661
663template <typename TReal, unsigned int VRows, unsigned int VCols, typename = std::enable_if_t<VRows != VCols>>
664FixedRectangularSVDResult<TReal, VRows, VCols>
665SVD(const Matrix<TReal, VRows, VCols> & A, bool canonicalizeSigns = true)
666{
667 return SVD<TReal, VRows, VCols>(A.GetVnlMatrix(), canonicalizeSigns);
668}
669
673template <typename TReal>
674SVDResult<TReal>
675SVD(const vnl_matrix<TReal> & A, bool canonicalizeSigns = true)
676{
677 const unsigned int rows = A.rows();
678 const unsigned int cols = A.cols();
679 if (rows == 0 || cols == 0)
680 {
681 itkGenericExceptionMacro("itk::bridge::Math::SVD requires a non-empty matrix.");
682 }
683 const unsigned int k = (rows < cols) ? rows : cols;
684 SVDResult<TReal> result;
685 result.U.set_size(rows, k);
686 result.V.set_size(cols, k);
687 result.W.set_size(k);
688 if (rows == cols)
689 {
691 A.data_block(), rows, result.U.data_block(), result.W.data_block(), result.V.data_block());
692 }
693 else
694 {
696 A.data_block(), rows, cols, result.U.data_block(), result.W.data_block(), result.V.data_block());
697 }
698 if (canonicalizeSigns)
699 {
701 }
702 return result;
703}
704
708template <typename TScalar>
709vnl_matrix<TScalar>
710PseudoInverse(const vnl_matrix<TScalar> & A)
711{
713 {
715 }
716 else
717 {
718 return SVD(A).PseudoInverse();
719 }
720}
721
722} // namespace Math
723} // namespace itk::bridge
724
725#endif // itkBridgeMathSVD_h
A templated class holding a M x N size Matrix.
Definition itkMatrix.h:71
InternalMatrixType & GetVnlMatrix()
Definition itkMatrix.h:232
FixedSquareSVDResult< TReal, VDim > SVD(const vnl_matrix_fixed< TReal, VDim, VDim > &A, bool canonicalizeSigns=true)
Singular value decomposition A = U diag(W) V^T, backed by Eigen.
#define ITKCommon_EXPORT_EXPLICIT
#define ITK_MATH_SVD_EXTERN_FIXED(D)
#define ITK_MATH_SVD_FIXED_DIMS(F)
Cholesky-based linear algebra for symmetric matrices, backed by Eigen.
template void DynamicSquareSVDEigen< float >(const float *, unsigned int, float *, float *, float *)
TReal ResolveRcond(TReal rcond, unsigned int n)
auto Recompose(const TMatrixU &U, const TVector &W, const TMatrixV &V, TReal rcond)
void RectangularSVDEigen(const TReal *inData, unsigned int rows, unsigned int cols, TReal *uData, TReal *wData, TReal *vData)
auto DeterminantMagnitude(const TVector &W) -> std::decay_t< decltype(W[0])>
auto WellCondition(const TVector &W) -> std::decay_t< decltype(W[0])>
constexpr unsigned int kFixedSVDMaxDim
vnl_matrix< TComplex > ComplexPseudoInverse(const vnl_matrix< TComplex > &A)
auto SolveLinear(const TMatrixU &U, const TVector &W, const TMatrixV &V, const TVectorB &b, TReal rcond)
unsigned int NumericalRank(const TVector &W, TReal rcond)
constexpr unsigned int kJacobiMaxDim
void SquareSVDEigen(const TReal *inData, TReal *uData, TReal *wData, TReal *vData)
template void DynamicSquareSVDEigen< double >(const double *, unsigned int, double *, double *, double *)
void DynamicSquareSVDEigen(const TReal *inData, unsigned int n, TReal *uData, TReal *wData, TReal *vData)
auto RecomposeWith(const TMatrixU &U, const TVector &modifiedW, const TMatrixV &V)
auto PseudoInverse(const TMatrixU &U, const TVector &W, const TMatrixV &V, TReal rcond)
template void RectangularSVDEigen< double >(const double *, unsigned int, unsigned int, double *, double *, double *)
template void RectangularSVDEigen< float >(const float *, unsigned int, unsigned int, float *, float *, float *)
vnl_matrix< TScalar > PseudoInverse(const vnl_matrix< TScalar > &A)
void CanonicalizeColumnSignsPaired(TMatrixU &u, TMatrixV &paired)
Convenience wrappers over third-party numerical backends, provided as a migration aid rather than as ...
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
STL namespace.
vnl_vector_fixed< TReal, VCols > NullVector() const
vnl_matrix_fixed< TReal, VRows, K > U
vnl_vector_fixed< TReal, VCols > Solve(const vnl_vector_fixed< TReal, VRows > &b, TReal rcond=TReal{ -1 }) const
vnl_matrix_fixed< TReal, VRows, VCols > Recompose(TReal rcond=TReal{ -1 }) const
unsigned int Rank(TReal rcond=TReal{ -1 }) const
vnl_matrix_fixed< TReal, VCols, VRows > PseudoInverse(TReal rcond=TReal{ -1 }) const
vnl_matrix_fixed< TReal, VRows, VCols > RecomposeWith(const vnl_vector_fixed< TReal, K > &modifiedW) const
vnl_matrix_fixed< TReal, VCols, K > V
vnl_vector_fixed< TReal, VDim > Solve(const vnl_vector_fixed< TReal, VDim > &b, TReal rcond=TReal{ -1 }) const
vnl_matrix_fixed< TReal, VDim, VDim > RecomposeWith(const vnl_vector_fixed< TReal, VDim > &modifiedW) const
vnl_matrix_fixed< TReal, VDim, VDim > Recompose(TReal rcond=TReal{ -1 }) const
vnl_matrix_fixed< TReal, VDim, VDim > U
vnl_matrix_fixed< TReal, VDim, VDim > V
unsigned int Rank(TReal rcond=TReal{ -1 }) const
vnl_vector_fixed< TReal, VDim > W
vnl_matrix_fixed< TReal, VDim, VDim > PseudoInverse(TReal rcond=TReal{ -1 }) const
vnl_vector_fixed< TReal, VDim > NullVector() const
unsigned int Rank(TReal rcond=TReal{ -1 }) const
vnl_vector< TReal > NullVector() const
vnl_matrix< TReal > RecomposeWith(const vnl_vector< TReal > &modifiedW) const
vnl_matrix< TReal > Recompose(TReal rcond=TReal{ -1 }) const
vnl_matrix< TReal > PseudoInverse(TReal rcond=TReal{ -1 }) const
vnl_vector< TReal > Solve(const vnl_vector< TReal > &b, TReal rcond=TReal{ -1 }) const