Changeset 10381
- Timestamp:
- Dec 1, 2006, 11:48:47 AM (20 years ago)
- Location:
- trunk/psLib/src/math
- Files:
-
- 2 edited
-
psMatrix.c (modified) (2 diffs)
-
psMatrix.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psMatrix.c
r10251 r10381 20 20 * @author Ross Harman, MHPCC 21 21 * @author Robert DeSonia, MHPCC 22 * @author Andy Becker, University of Washington (SVD). 22 23 * 23 * @version $Revision: 1.4 5$ $Name: not supported by cvs2svn $24 * @date $Date: 2006-1 1-29 02:14:49$24 * @version $Revision: 1.46 $ $Name: not supported by cvs2svn $ 25 * @date $Date: 2006-12-01 21:48:47 $ 25 26 * 26 27 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 871 872 return outImage; 872 873 } 874 875 // This code supplied by Andy Becker (becker@astro.washington.edu) 876 psImage *psMatrixSVDSolve(psImage* evec, psVector* eval, const psImage* in) 877 { 878 #define psMatrixSVD_EXIT {psFree(evec); psFree(eval); return NULL;} 879 880 // Error checks Missing one for eval 881 PS_ASSERT_GENERAL_IMAGE_NON_NULL(in, psMatrixSVD_EXIT); 882 PS_CHECK_POINTERS(in, evec, psMatrixSVD_EXIT); 883 PS_CHECK_DIMEN_AND_TYPE(in, PS_DIMEN_IMAGE, psMatrixSVD_EXIT); 884 885 // evec ends up : numCols x numCols 886 evec = psImageRecycle(evec, in->numCols, in->numCols, in->type.type); 887 eval = psVectorRecycle(eval, in->numCols, in->type.type); 888 889 // Initialize data 890 int numRows = in->numRows; 891 int numCols = in->numCols; 892 893 gsl_matrix *A = gsl_matrix_alloc(numRows, numCols); 894 gsl_matrix *V = gsl_matrix_alloc(numCols, numCols); 895 gsl_vector *S = gsl_vector_alloc(numCols); 896 gsl_vector *work = gsl_vector_alloc(numCols); 897 898 // Copy psImage data into GSL matrix data 899 psImageToGslMatrix(A, in); 900 901 // Calculate SVD decomposition 902 gsl_linalg_SV_decomp(A, V, S, work); 903 904 // Copy GSL matrix data to psImage data 905 gslMatrixToPsImage(evec, V); 906 gslVectorToPsVector(eval, S); 907 908 // Take the square root of eval 909 for (int i = 0; i < eval->n; i++) { 910 eval->data.F64[i] = sqrt(eval->data.F64[i]); 911 /* make sure that these things are sorted! */ 912 if (i > 0) { 913 assert(eval->data.F64[i] > eval->data.F64[i-1]); 914 } 915 } 916 917 // Free GSL data 918 gsl_matrix_free(A); 919 gsl_matrix_free(V); 920 gsl_vector_free(S); 921 gsl_vector_free(work); 922 923 return evec; 924 } -
trunk/psLib/src/math/psMatrix.h
r10251 r10381 21 21 * @author Ross Harman, MHPCC 22 22 * 23 * @version $Revision: 1.2 4$ $Name: not supported by cvs2svn $24 * @date $Date: 2006-1 1-29 02:14:49$23 * @version $Revision: 1.25 $ $Name: not supported by cvs2svn $ 24 * @date $Date: 2006-12-01 21:48:47 $ 25 25 * 26 26 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 179 179 ); 180 180 181 /// Single value decomposition, provided by Andy Becker 182 psImage *psMatrixSVDSolve(psImage* evec, psVector* eval, const psImage* in); 183 181 184 /// @} 182 185
Note:
See TracChangeset
for help on using the changeset viewer.
