PCL
Algebra.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/Algebra.h - Released 2024-06-18T15:48:54Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_Algebra_h
53 #define __PCL_Algebra_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #include <pcl/Matrix.h>
60 #include <pcl/Vector.h>
61 
62 namespace pcl
63 {
64 
65 // ----------------------------------------------------------------------------
66 
82 void PCL_FUNC InPlaceGaussJordan( Matrix& A, Matrix& B );
83 
95 void PCL_FUNC InPlaceGaussJordan( FMatrix& A, FMatrix& B );
96 
101 template <typename T>
102 class PCL_CLASS GenericGaussJordan
103 {
104 public:
105 
110 
114  using matrix_element = typename matrix::element;
115 
119  matrix Ai; // Inverse matrix
120 
124  matrix X; // Solution vectors
125 
132  GenericGaussJordan( const matrix& A, const matrix& B )
133  {
134  Ai = A;
135  X = B;
136  InPlaceGaussJordan( Ai, X );
137  }
138 };
139 
148 class PCL_CLASS GaussJordan : public GenericGaussJordan<double>
149 {
150 public:
151 
157 
162 
167 
174  GaussJordan( const Matrix& A, const Matrix& B )
175  : algorithm_implementation( A, B )
176  {
177  }
178 };
179 
188 class PCL_CLASS FGaussJordan : public GenericGaussJordan<float>
189 {
190 public:
191 
197 
202 
207 
214  FGaussJordan( const FMatrix& A, const FMatrix& B )
215  : algorithm_implementation( A, B )
216  {
217  }
218 };
219 
220 // ----------------------------------------------------------------------------
221 
222 void PCL_FUNC InPlaceSVDImplementation( Matrix&, Vector&, Matrix& );
223 void PCL_FUNC InPlaceSVDImplementation( FMatrix&, FVector&, FMatrix& );
224 
229 template <typename T>
230 class PCL_CLASS GenericInPlaceSVD
231 {
232 public:
233 
238 
243 
248 
252  using matrix_element = typename matrix::element;
253 
260 
267 
281  : W( A.Columns() )
282  , V( A.Columns(), A.Columns() )
283  {
284  InPlaceSVDImplementation( A, W, V );
285  }
286 
292  {
293  return W.IndexOfLargestComponent();
294  }
295 
316  {
317  return W.IndexOfSmallestNonzeroComponent();
318  }
319 };
320 
330 class PCL_CLASS InPlaceSVD : public GenericInPlaceSVD<double>
331 {
332 public:
333 
339 
344 
349 
354 
359 
374  {
375  }
376 };
377 
387 class PCL_CLASS FInPlaceSVD : public GenericInPlaceSVD<float>
388 {
389 public:
390 
396 
401 
406 
411 
416 
431  {
432  }
433 };
434 
439 template <typename T>
440 class PCL_CLASS GenericSVD
441 {
442 public:
443 
449 
454 
459 
463  using vector_component = typename vector::component;
464 
468  using matrix_element = typename matrix::element;
469 
475 
482 
489 
500  GenericSVD( const matrix& A )
501  {
502  U = A;
503  algorithm_implementation svd( U );
504  W = svd.W;
505  V = svd.V;
506  }
507 
513  {
514  return W.IndexOfLargestComponent();
515  }
516 
537  {
538  return W.IndexOfSmallestNonzeroComponent();
539  }
540 };
541 
551 class PCL_CLASS SVD : public GenericSVD<double>
552 {
553 public:
554 
560 
565 
570 
574  using vector_component = vector::component;
575 
579  using matrix_element = matrix::element;
580 
591  SVD( const matrix& A )
593  {
594  }
595 };
596 
606 class PCL_CLASS FSVD : public GenericSVD<float>
607 {
608 public:
609 
615 
620 
625 
629  using vector_component = vector::component;
630 
634  using matrix_element = matrix::element;
635 
646  FSVD( const matrix& A )
648  {
649  }
650 };
651 
652 // ----------------------------------------------------------------------------
653 
654 } // pcl
655 
656 #endif // __PCL_Algebra_h
657 
658 // ----------------------------------------------------------------------------
659 // EOF pcl/Algebra.h - Released 2024-06-18T15:48:54Z
Gauss-Jordan linear system solver for FMatrix objects.
Definition: Algebra.h:189
matrix::element matrix_element
Definition: Algebra.h:206
FGaussJordan(const FMatrix &A, const FMatrix &B)
Definition: Algebra.h:214
In-place singular value decomposition algorithm for FMatrix and FVector objects.
Definition: Algebra.h:388
matrix::element matrix_element
Definition: Algebra.h:415
FInPlaceSVD(matrix &A)
Definition: Algebra.h:429
vector::component vector_component
Definition: Algebra.h:410
32-bit floating point real matrix.
Singular value decomposition algorithm for FMatrix and FVector objects.
Definition: Algebra.h:607
FSVD(const matrix &A)
Definition: Algebra.h:646
algorithm_implementation::vector vector
Definition: Algebra.h:619
matrix::element matrix_element
Definition: Algebra.h:634
algorithm_implementation::matrix matrix
Definition: Algebra.h:624
vector::component vector_component
Definition: Algebra.h:629
32-bit floating point real vector.
Gauss-Jordan linear system solver for Matrix objects.
Definition: Algebra.h:149
GaussJordan(const Matrix &A, const Matrix &B)
Definition: Algebra.h:174
matrix::element matrix_element
Definition: Algebra.h:166
Generic Gauss-Jordan linear system solver.
Definition: Algebra.h:103
typename matrix::element matrix_element
Definition: Algebra.h:114
GenericGaussJordan(const matrix &A, const matrix &B)
Definition: Algebra.h:132
Generic in-place singular value decomposition algorithm.
Definition: Algebra.h:231
typename matrix::element matrix_element
Definition: Algebra.h:252
typename vector::component vector_component
Definition: Algebra.h:247
int IndexOfLargestSingularValue() const
Definition: Algebra.h:291
int IndexOfSmallestSingularValue() const
Definition: Algebra.h:315
GenericInPlaceSVD(matrix &A)
Definition: Algebra.h:280
Generic dynamic matrix of arbitrary dimensions.
Definition: Matrix.h:123
Generic singular value decomposition algorithm.
Definition: Algebra.h:441
typename matrix::element matrix_element
Definition: Algebra.h:468
typename algorithm_implementation::matrix matrix
Definition: Algebra.h:458
int IndexOfSmallestSingularValue() const
Definition: Algebra.h:536
GenericSVD(const matrix &A)
Definition: Algebra.h:500
typename vector::component vector_component
Definition: Algebra.h:463
int IndexOfLargestSingularValue() const
Definition: Algebra.h:512
typename algorithm_implementation::vector vector
Definition: Algebra.h:453
Generic vector of arbitrary length.
Definition: Vector.h:107
In-place singular value decomposition algorithm for Matrix and Vector objects.
Definition: Algebra.h:331
matrix::element matrix_element
Definition: Algebra.h:358
InPlaceSVD(matrix &A)
Definition: Algebra.h:372
vector::component vector_component
Definition: Algebra.h:353
64-bit floating point real matrix.
Singular value decomposition algorithm for Matrix and Vector objects.
Definition: Algebra.h:552
algorithm_implementation::matrix matrix
Definition: Algebra.h:569
vector::component vector_component
Definition: Algebra.h:574
SVD(const matrix &A)
Definition: Algebra.h:591
matrix::element matrix_element
Definition: Algebra.h:579
algorithm_implementation::vector vector
Definition: Algebra.h:564
64-bit floating point real vector.
void PCL_FUNC InPlaceGaussJordan(Matrix &A, Matrix &B)
PCL root namespace.
Definition: AbstractImage.h:77