📄 matrixfunctions.h
字号:
XprBinOp< \ Fcnl_##NAME< POD, typename E::value_type>, \ XprLiteral< POD >, \ XprMatrix<E, Rows, Cols> \ >, \ Rows, Cols \> \NAME (POD lhs, const XprMatrix<E, Rows, Cols>& rhs) { \ typedef XprBinOp< \ Fcnl_##NAME< POD, typename E::value_type>, \ XprLiteral< POD >, \ XprMatrix<E, Rows, Cols> \ > expr_type; \ return XprMatrix<expr_type, Rows, Cols>( \ expr_type(XprLiteral< POD >(lhs), rhs)); \}TVMET_IMPLEMENT_MACRO(add, int)TVMET_IMPLEMENT_MACRO(sub, int)TVMET_IMPLEMENT_MACRO(mul, int)TVMET_IMPLEMENT_MACRO(div, int)#if defined(TVMET_HAVE_LONG_LONG)TVMET_IMPLEMENT_MACRO(add, long long int)TVMET_IMPLEMENT_MACRO(sub, long long int)TVMET_IMPLEMENT_MACRO(mul, long long int)TVMET_IMPLEMENT_MACRO(div, long long int)#endifTVMET_IMPLEMENT_MACRO(add, float)TVMET_IMPLEMENT_MACRO(sub, float)TVMET_IMPLEMENT_MACRO(mul, float)TVMET_IMPLEMENT_MACRO(div, float)TVMET_IMPLEMENT_MACRO(add, double)TVMET_IMPLEMENT_MACRO(sub, double)TVMET_IMPLEMENT_MACRO(mul, double)TVMET_IMPLEMENT_MACRO(div, double)#if defined(TVMET_HAVE_LONG_DOUBLE)TVMET_IMPLEMENT_MACRO(add, long double)TVMET_IMPLEMENT_MACRO(sub, long double)TVMET_IMPLEMENT_MACRO(mul, long double)TVMET_IMPLEMENT_MACRO(div, long double)#endif#undef TVMET_IMPLEMENT_MACRO#if defined(TVMET_HAVE_COMPLEX)/* * function(XprMatrix<E, Rows, Cols>, complex<T>) * function(complex<T>, XprMatrix<E, Rows, Cols>) * Note: - operations +,-,*,/ are per se element wise * \todo type promotion */#define TVMET_IMPLEMENT_MACRO(NAME) \template<class E, class T, std::size_t Rows, std::size_t Cols> \inline \XprMatrix< \ XprBinOp< \ Fcnl_##NAME<typename E::value_type, std::complex<T> >, \ XprMatrix<E, Rows, Cols>, \ XprLiteral< std::complex<T> > \ >, \ Rows, Cols \> \NAME (const XprMatrix<E, Rows, Cols>& lhs, \ const std::complex<T>& rhs) { \ typedef XprBinOp< \ Fcnl_##NAME<typename E::value_type, std::complex<T> >, \ XprMatrix<E, Rows, Cols>, \ XprLiteral< std::complex<T> > \ > expr_type; \ return XprMatrix<expr_type, Rows, Cols>( \ expr_type(lhs, XprLiteral< std::complex<T> >(rhs))); \} \ \template<class T, class E, std::size_t Rows, std::size_t Cols> \inline \XprMatrix< \ XprBinOp< \ Fcnl_##NAME< std::complex<T>, typename E::value_type>, \ XprLiteral< std::complex<T> >, \ XprMatrix<E, Rows, Cols> \ >, \ Rows, Cols \> \NAME (const std::complex<T>& lhs, \ const XprMatrix<E, Rows, Cols>& rhs) { \ typedef XprBinOp< \ Fcnl_##NAME< std::complex<T>, typename E::value_type>, \ XprLiteral< std::complex<T> >, \ XprMatrix<E, Rows, Cols> \ > expr_type; \ return XprMatrix<expr_type, Rows, Cols>( \ expr_type(XprLiteral< std::complex<T> >(lhs), rhs)); \}TVMET_IMPLEMENT_MACRO(add)TVMET_IMPLEMENT_MACRO(sub)TVMET_IMPLEMENT_MACRO(mul)TVMET_IMPLEMENT_MACRO(div)#undef TVMET_IMPLEMENT_MACRO#endif // defined(TVMET_HAVE_COMPLEX)/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * matrix prod( ... ) functions *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*//** * \fn prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs) * \brief Evaluate the product of two XprMatrix. * Perform on given Matrix M1 and M2: * \f[ * M_1\,M_2 * \f] * \note The numer of Rows2 has to be equal to Cols1. * \ingroup _binary_function */template<class E1, std::size_t Rows1, std::size_t Cols1, class E2, std::size_t Cols2>inlineXprMatrix< XprMMProduct< XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) XprMatrix<E2, Cols1, Cols2>, Cols2 >, Rows1, Cols2 // return Dim>prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs) { typedef XprMMProduct< XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, XprMatrix<E2, Cols1, Cols2>, Cols2 > expr_type; return XprMatrix<expr_type, Rows1, Cols2>(expr_type(lhs, rhs));}/** * \fn trans_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs) * \brief Function for the trans(matrix-matrix-product) * Perform on given Matrix M1 and M2: * \f[ * (M_1\,M_2)^T * \f] * \note The numer of Rows2 has to be equal to Cols1. * \ingroup _binary_function */template<class E1, std::size_t Rows1, std::size_t Cols1, class E2, std::size_t Cols2>inlineXprMatrix< XprMMProductTransposed< XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) XprMatrix<E2, Cols1, Cols2>, Cols2 // M2(Cols1, Cols2) >, Cols2, Rows1 // return Dim>trans_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs) { typedef XprMMProductTransposed< XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, XprMatrix<E2, Cols1, Cols2>, Cols2 > expr_type; return XprMatrix<expr_type, Cols2, Rows1>(expr_type(lhs, rhs));}/** * \fn MtM_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Rows1, Cols2>& rhs) * \brief Function for the trans(matrix)-matrix-product. * using formula * \f[ * M_1^{T}\,M_2 * \f] * \note The number of cols of matrix 2 have to be equal to number of rows of * matrix 1, since matrix 1 is trans - the result is a (Cols1 x Cols2) * matrix. * \ingroup _binary_function */template<class E1, std::size_t Rows1, std::size_t Cols1, class E2, std::size_t Cols2> // Rows2 = Rows1inlineXprMatrix< XprMtMProduct< XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) XprMatrix<E2, Rows1, Cols2>, Cols2 // M2(Rows1, Cols2) >, Cols1, Cols2 // return Dim>MtM_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Rows1, Cols2>& rhs) { typedef XprMtMProduct< XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, XprMatrix<E2, Rows1, Cols2>, Cols2 > expr_type; return XprMatrix<expr_type, Cols1, Cols2>(expr_type(lhs, rhs));}/** * \fn MMt_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Rows2, Cols1>& rhs) * \brief Function for the matrix-trans(matrix)-product. * \ingroup _binary_function * \note The cols2 has to be equal to cols1. */template<class E1, std::size_t Rows1, std::size_t Cols1, class E2, std::size_t Rows2> // Cols2 = Cols1inlineXprMatrix< XprMMtProduct< XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) XprMatrix<E2, Rows2, Cols1>, Cols1 // M2(Rows2, Cols1) >, Rows1, Rows2 // return Dim>MMt_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Rows2, Cols1>& rhs) { typedef XprMMtProduct< XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, XprMatrix<E2, Rows2, Cols1>, Cols1 > expr_type; return XprMatrix<expr_type, Rows1, Rows2>(expr_type(lhs, rhs));}/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * matrix-vector specific prod( ... ) functions *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*//** * \fn prod(const XprMatrix<E1, Rows, Cols>& lhs, const XprVector<E2, Cols>& rhs) * \brief Evaluate the product of XprMatrix and XprVector. * \ingroup _binary_function */template<class E1, std::size_t Rows, std::size_t Cols, class E2>inlineXprVector< XprMVProduct< XprMatrix<E1, Rows, Cols>, Rows, Cols, XprVector<E2, Cols> >, Rows>prod(const XprMatrix<E1, Rows, Cols>& lhs, const XprVector<E2, Cols>& rhs) { typedef XprMVProduct< XprMatrix<E1, Rows, Cols>, Rows, Cols, XprVector<E2, Cols> > expr_type; return XprVector<expr_type, Rows>(expr_type(lhs, rhs));}/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * matrix specific functions *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*//** * \fn trans(const XprMatrix<E, Rows, Cols>& rhs) * \brief Transpose an expression matrix. * \ingroup _unary_function */template<class E, std::size_t Rows, std::size_t Cols>inlineXprMatrix< XprMatrixTranspose< XprMatrix<E, Rows, Cols> >, Cols, Rows>trans(const XprMatrix<E, Rows, Cols>& rhs) { typedef XprMatrixTranspose< XprMatrix<E, Rows, Cols> > expr_type; return XprMatrix<expr_type, Cols, Rows>(expr_type(rhs));}/* * \fn trace(const XprMatrix<E, Sz, Sz>& m) * \brief Compute the trace of a square matrix. * \ingroup _unary_function * * Simply compute the trace of the given matrix expression as: * \f[ * \sum_{k = 0}^{Sz-1} m(k, k) * \f] */template<class E, std::size_t Sz>inlinetypename NumericTraits<typename E::value_type>::sum_typetrace(const XprMatrix<E, Sz, Sz>& m) { return meta::Matrix<Sz, Sz, 0, 0>::trace(m);}/** * \fn row(const XprMatrix<E, Rows, Cols>& m, std::size_t no) * \brief Returns a row vector of the given matrix. * \ingroup _binary_function */template<class E, std::size_t Rows, std::size_t Cols>inlineXprVector< XprMatrixRow< XprMatrix<E, Rows, Cols>, Rows, Cols >, Cols>row(const XprMatrix<E, Rows, Cols>& m, std::size_t no) { typedef XprMatrixRow< XprMatrix<E, Rows, Cols>, Rows, Cols > expr_type; return XprVector<expr_type, Cols>(expr_type(m, no));}/** * \fn col(const XprMatrix<E, Rows, Cols>& m, std::size_t no) * \brief Returns a column vector of the given matrix. * \ingroup _binary_function */template<class E, std::size_t Rows, std::size_t Cols>inlineXprVector< XprMatrixCol< XprMatrix<E, Rows, Cols>, Rows, Cols >, Rows>col(const XprMatrix<E, Rows, Cols>& m, std::size_t no) { typedef XprMatrixCol< XprMatrix<E, Rows, Cols>, Rows, Cols > expr_type; return XprVector<expr_type, Cols>(expr_type(m, no));}/** * \fn diag(const XprMatrix<E, Sz, Sz>& m) * \brief Returns the diagonal vector of the given square matrix. * \ingroup _unary_function */template<class E, std::size_t Sz>inlineXprVector< XprMatrixDiag< XprMatrix<E, Sz, Sz>, Sz >, Sz>diag(const XprMatrix<E, Sz, Sz>& m) { typedef XprMatrixDiag< XprMatrix<E, Sz, Sz>, Sz> expr_type; return XprVector<expr_type, Sz>(expr_type(m));}} // namespace tvmet#endif // TVMET_XPR_MATRIX_FUNCTIONS_H// Local Variables:// mode:C++// tab-width:8// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -