template<class ArrayT>
Definition at line 120 of file MatInverse.h. References Lubksb(), Ludcmp(), MatE(), MatNrCol(), MatNrRow(), and MatSet(). Referenced by Impala::Core::Array::Pattern::PatGeometricOp(), and Impala::Core::Tracking::Classifier::UpdateClassifiers(). 00121 { 00122 if (MatNrCol(a) != MatNrRow(a)) 00123 { 00124 std::cerr << "MatInverse: matrix is not square!" << std::endl; 00125 return 0; 00126 } 00127 00128 int size = MatNrRow(a); 00129 ArrayT* m = MatCreate<ArrayT>(size, size); 00130 ArrayT* tmp = MatCreate<ArrayT>(MatNrRow(a), MatNrCol(a)); 00131 MatSet(tmp, a); 00132 short* idx = new short[size]; 00133 double d; 00134 if (!Ludcmp(MatE(tmp, 0, 0), size, idx, &d)) 00135 { 00136 std::cerr << "MatInverse: singular matrix can't be inverted." << std::endl; 00137 delete [] idx; 00138 return 0; 00139 } 00140 00141 double* res = new double[size]; 00142 for (int j=0 ; j<size ; j++) 00143 { 00144 for (int i=0 ; i<size; i++) 00145 res[i] = 0.0; 00146 res[j] = 1.0; 00147 Lubksb(MatE(tmp, 0, 0), size, idx, res); 00148 for (int k=0 ; k<size ; k++) 00149 *MatE(m, k, j) = res[k]; 00150 } 00151 00152 delete [] res; 00153 delete [] idx; 00154 delete tmp; 00155 00156 return m; 00157 }
Here is the call graph for this function:
|