#include #include #ifdef WITH_IPP_OPTIMIZATION #include #endif namespace icl{ #ifdef WITH_IPP_OPTIMIZATION template DynMatrix apply_dyn_matrix_inv(const DynMatrix &s){ if(s.cols() != s.rows()){ throw InvalidMatrixDimensionException("inverse matrix can only be calculated on square matrices"); } unsigned int wh = s.cols(); DynMatrix d(wh,wh); std::vector buffer(wh*wh+wh); IppStatus st = ippFunc(s.data(),wh*sizeof(T),sizeof(T), buffer.data(), d.data(),wh*sizeof(T),sizeof(T), wh); if(st != ippStsNoErr){ throw SingularMatrixException("matrix is too singular"); } return d; } template T apply_dyn_matrix_det(const DynMatrix &s){ if(s.cols() != s.rows()){ throw InvalidMatrixDimensionException("matrix determinant can only be calculated on square matrices"); } unsigned int wh = s.cols(); std::vector buffer(wh*wh+wh); T det(0); IppStatus st = ippFunc(s.data(),wh*sizeof(T),sizeof(T), wh,buffer.data(),&det); if(st != ippStsNoErr){ ERROR_LOG("matrix determinant could not be calculated"); } return det; } #endif template DynMatrix DynMatrix::inv() const throw (InvalidMatrixDimensionException,SingularMatrixException){ ERROR_LOG("not implemented (only with IPP and only for float and double)"); return DynMatrix(1,1); } template T DynMatrix::det() const throw (InvalidMatrixDimensionException){ ERROR_LOG("not implemented (only with IPP and only for float and double)"); return T(); } #ifdef WITH_IPP_OPTIMIZATION template<> DynMatrix DynMatrix::inv() const throw (InvalidMatrixDimensionException,SingularMatrixException){ return apply_dyn_matrix_inv(*this); } template<> DynMatrix DynMatrix::inv() const throw (InvalidMatrixDimensionException,SingularMatrixException){ return apply_dyn_matrix_inv(*this); } template<> float DynMatrix::det() const throw (InvalidMatrixDimensionException){ return apply_dyn_matrix_det(*this); } template<> double DynMatrix::det() const throw (InvalidMatrixDimensionException){ return apply_dyn_matrix_det(*this); } #endif template DynMatrix DynMatrix::inv()const throw (InvalidMatrixDimensionException,SingularMatrixException); template DynMatrix DynMatrix::inv()const throw (InvalidMatrixDimensionException,SingularMatrixException); template float DynMatrix::det()const throw (InvalidMatrixDimensionException); template double DynMatrix::det()const throw (InvalidMatrixDimensionException); }