[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN SVD.h
From: |
Tom Drummond |
Subject: |
[Toon-members] TooN SVD.h |
Date: |
Thu, 23 Apr 2009 22:30:07 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Tom Drummond <twd20> 09/04/23 22:30:07
Modified files:
. : SVD.h
Log message:
much nicer solution the shape/size of U and VT problem
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/SVD.h?cvsroot=toon&r1=1.17&r2=1.18
Patches:
Index: SVD.h
===================================================================
RCS file: /cvsroot/toon/TooN/SVD.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- SVD.h 22 Apr 2009 15:42:27 -0000 1.17
+++ SVD.h 23 Apr 2009 22:30:03 -0000 1.18
@@ -41,64 +41,7 @@
-namespace Internal{
- template<int Rows, int Cols, bool Dynamic = (Rows == -1 || Cols == -1),
bool IsVertical = (Rows >= Cols)> struct UVT
- {
- typedef Matrix<Dynamic> U_type;
- typedef Matrix<Dynamic> VT_type;
-
- static const Matrix<Dynamic>& get_U(const Matrix<Dynamic>&
copy, const Matrix<Dynamic>& square)
- {
- if(copy.num_rows() >= copy.num_cols())
- return copy;
- else
- return square;
- }
-
- static const Matrix<Dynamic>& get_VT(const Matrix<Dynamic>&
copy, const Matrix<Dynamic>& square)
- {
- if(copy.num_rows() >= copy.num_cols())
- return square;
- else
- return copy;
- }
- };
-
- template<int Rows, int Cols> struct UVT<Rows, Cols, 0, 1>
- {
- static const int Min = Rows<Cols?Rows:Cols;
- typedef Matrix<Rows,Cols> U_type;
- typedef Matrix<Min,Min> VT_type;
-
- static const Matrix<Rows, Cols>& get_U(const Matrix<Rows,Cols>&
copy, const Matrix<Min, Min>& square)
- {
- return copy;
- }
-
- static const Matrix<Min, Min>& get_VT(const Matrix<Rows, Cols>&
copy, const Matrix<Min, Min>& square)
- {
- return square;
- }
- };
-
- template<int Rows, int Cols> struct UVT<Rows, Cols, 0, 0>
- {
- static const int Min = Rows<Cols?Rows:Cols;
- typedef Matrix<Min,Min> U_type;
- typedef Matrix<Rows,Cols> VT_type;
-
- static const Matrix<Min, Min>& get_U(const Matrix<Rows, Cols>&
copy, const Matrix<Min, Min>& square)
- {
- return square;
- }
-
- static const Matrix<Rows, Cols>& get_VT(const
Matrix<Rows,Cols>& copy, const Matrix<Min, Min>& square)
- {
- return copy;
- }
- };
-}
/**
@@ -219,7 +162,9 @@
delete[] wk;
}
- bool is_vertical(){ return (my_copy.num_rows() >= my_copy.num_cols()); }
+ bool is_vertical(){
+ return (my_copy.num_rows() >= my_copy.num_cols());
+ }
int min_dim(){ return std::min(my_copy.num_rows(), my_copy.num_cols());
}
@@ -286,19 +231,33 @@
/// Return the U matrix from the decomposition
/// The size of this depends on the shape of the original matrix
/// it is square if the original matrix is wide or tall if the original
matrix is tall
- typename Internal::UVT<Rows, Cols>::U_type get_U()
- {
- return Internal::UVT<Rows, Cols>::get_U(my_copy, my_square);
+ Matrix<Rows,Min_Dim,Precision,Reference::RowMajor> get_U(){
+ if(is_vertical()){
+ return
Matrix<Rows,Min_Dim,Precision,Reference::RowMajor>
+
(my_copy.my_data,my_copy.num_rows(),my_copy.num_cols());
+ } else {
+ return
Matrix<Rows,Min_Dim,Precision,Reference::RowMajor>
+ (my_square.my_data, my_square.num_rows(),
my_square.num_cols());
}
-
- typename Internal::UVT<Rows, Cols>::VT_type get_VT()
- {
- return Internal::UVT<Rows, Cols>::get_VT(my_copy, my_square);
}
/// Return the singular values as a vector
Vector<Min_Dim,Precision>& get_diagonal(){ return my_diagonal; }
+ /// Return the VT matrix from the decomposition
+ /// The size of this depends on the shape of the original matrix
+ /// it is square if the original matrix is tall or wide if the original
matrix is wide
+ Matrix<Min_Dim,Cols,Precision,Reference::RowMajor> get_VT(){
+ if(is_vertical()){
+ return
Matrix<Min_Dim,Cols,Precision,Reference::RowMajor>
+ (my_square.my_data, my_square.num_rows(),
my_square.num_cols());
+ } else {
+ return
Matrix<Min_Dim,Cols,Precision,Reference::RowMajor>
+
(my_copy.my_data,my_copy.num_rows(),my_copy.num_cols());
+ }
+ }
+
+
void get_inv_diag(Vector<Min_Dim>& inv_diag, const Precision condition){
for(int i=0; i<min_dim(); i++){
if(my_diagonal[i] * condition <= my_diagonal[0]){
- [Toon-members] TooN SVD.h, Tom Drummond, 2009/04/10
- [Toon-members] TooN SVD.h, Tom Drummond, 2009/04/20
- [Toon-members] TooN SVD.h, Tom Drummond, 2009/04/20
- [Toon-members] TooN SVD.h, Tom Drummond, 2009/04/20
- [Toon-members] TooN SVD.h, Tom Drummond, 2009/04/20
- [Toon-members] TooN SVD.h, Tom Drummond, 2009/04/20
- [Toon-members] TooN SVD.h,
Tom Drummond <=