00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef TVMET_MATRIX_IMPL_H
00025 #define TVMET_MATRIX_IMPL_H
00026
00027 #include <iomanip>
00028
00029 #include <tvmet/Functional.h>
00030 #include <tvmet/Io.h>
00031
00032
00033 namespace tvmet {
00034
00035
00036
00037
00038
00039 template<class T, std::size_t NRows, std::size_t NCols>
00040 std::ostream& Matrix<T, NRows, NCols>::print_xpr(std::ostream& os, std::size_t l) const
00041 {
00042 os << IndentLevel(l++) << "Matrix[" << ops << "]<"
00043 << typeid(T).name() << ", " << Rows << ", " << Cols << ">,"
00044 << IndentLevel(--l)
00045 << std::endl;
00046
00047 return os;
00048 }
00049
00050
00051 template<class T, std::size_t NRows, std::size_t NCols>
00052 std::ostream& Matrix<T, NRows, NCols>::print_on(std::ostream& os) const
00053 {
00054 enum {
00055 complex_type = NumericTraits<value_type>::is_complex
00056 };
00057
00058 std::streamsize w = IoPrintHelper<Matrix>::width(dispatch<complex_type>(), *this);
00059
00060 os << std::setw(0) << "[\n";
00061 for(std::size_t i = 0; i < Rows; ++i) {
00062 os << " [";
00063 for(std::size_t j = 0; j < (Cols - 1); ++j) {
00064 os << std::setw(w) << this->operator()(i, j) << ", ";
00065 }
00066 os << std::setw(w) << this->operator()(i, Cols - 1)
00067 << (i != (Rows-1) ? "],\n" : "]\n");
00068 }
00069 os << "]";
00070
00071 return os;
00072 }
00073
00074
00075
00076
00077
00078 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
00079 template<class T, std::size_t NRows, std::size_t NCols> \
00080 inline \
00081 Matrix<T, NRows, NCols>& \
00082 Matrix<T, NRows, NCols>::operator OP (value_type rhs) { \
00083 typedef XprLiteral<value_type> expr_type; \
00084 this->M_##NAME(XprMatrix<expr_type, Rows, Cols>(expr_type(rhs))); \
00085 return *this; \
00086 }
00087
00088 TVMET_IMPLEMENT_MACRO(add_eq, +=)
00089 TVMET_IMPLEMENT_MACRO(sub_eq, -=)
00090 TVMET_IMPLEMENT_MACRO(mul_eq, *=)
00091 TVMET_IMPLEMENT_MACRO(div_eq, /=)
00092 #undef TVMET_IMPLEMENT_MACRO
00093
00094
00095 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
00096 template<class T, std::size_t NRows, std::size_t NCols> \
00097 inline \
00098 Matrix<T, NRows, NCols>& \
00099 Matrix<T, NRows, NCols>::operator OP (std::size_t rhs) { \
00100 typedef XprLiteral<value_type> expr_type; \
00101 this->M_##NAME(XprMatrix<expr_type, Rows, Cols>(expr_type(rhs))); \
00102 return *this; \
00103 }
00104
00105 TVMET_IMPLEMENT_MACRO(mod_eq, %=)
00106 TVMET_IMPLEMENT_MACRO(xor_eq,^=)
00107 TVMET_IMPLEMENT_MACRO(and_eq, &=)
00108 TVMET_IMPLEMENT_MACRO(or_eq, |=)
00109 TVMET_IMPLEMENT_MACRO(shl_eq, <<=)
00110 TVMET_IMPLEMENT_MACRO(shr_eq, >>=)
00111 #undef TVMET_IMPLEMENT_MACRO
00112
00113
00114
00115
00116
00117 #define TVMET_IMPLEMENT_MACRO(NAME) \
00118 template<class T1, std::size_t NRows, std::size_t NCols> \
00119 template <class T2> \
00120 inline \
00121 Matrix<T1, NRows, NCols>& \
00122 Matrix<T1, NRows, NCols>::M_##NAME (const Matrix<T2, Rows, Cols>& rhs) { \
00123 this->M_##NAME( XprMatrix<typename Matrix<T2, Rows, Cols>::ConstReference, Rows, Cols>(rhs.const_ref()) ); \
00124 return *this; \
00125 }
00126
00127 TVMET_IMPLEMENT_MACRO(add_eq)
00128 TVMET_IMPLEMENT_MACRO(sub_eq)
00129 TVMET_IMPLEMENT_MACRO(mul_eq)
00130 TVMET_IMPLEMENT_MACRO(div_eq)
00131 TVMET_IMPLEMENT_MACRO(mod_eq)
00132 TVMET_IMPLEMENT_MACRO(xor_eq)
00133 TVMET_IMPLEMENT_MACRO(and_eq)
00134 TVMET_IMPLEMENT_MACRO(or_eq)
00135 TVMET_IMPLEMENT_MACRO(shl_eq)
00136 TVMET_IMPLEMENT_MACRO(shr_eq)
00137 #undef TVMET_IMPLEMENT_MACRO
00138
00139
00140
00141
00142
00143 #define TVMET_IMPLEMENT_MACRO(NAME) \
00144 template<class T, std::size_t NRows, std::size_t NCols> \
00145 template<class E> \
00146 inline \
00147 Matrix<T, NRows, NCols>& \
00148 Matrix<T, NRows, NCols>::M_##NAME (const XprMatrix<E, Rows, Cols>& rhs) { \
00149 rhs.assign_to(*this, Fcnl_##NAME<value_type, typename E::value_type>()); \
00150 return *this; \
00151 }
00152
00153 TVMET_IMPLEMENT_MACRO(add_eq)
00154 TVMET_IMPLEMENT_MACRO(sub_eq)
00155 TVMET_IMPLEMENT_MACRO(mul_eq)
00156 TVMET_IMPLEMENT_MACRO(div_eq)
00157 TVMET_IMPLEMENT_MACRO(mod_eq)
00158 TVMET_IMPLEMENT_MACRO(xor_eq)
00159 TVMET_IMPLEMENT_MACRO(and_eq)
00160 TVMET_IMPLEMENT_MACRO(or_eq)
00161 TVMET_IMPLEMENT_MACRO(shl_eq)
00162 TVMET_IMPLEMENT_MACRO(shr_eq)
00163 #undef TVMET_IMPLEMENT_MACRO
00164
00165
00166
00167
00168
00169
00170 #define TVMET_IMPLEMENT_MACRO(NAME) \
00171 template<class T1, std::size_t NRows, std::size_t NCols> \
00172 template <class T2> \
00173 inline \
00174 Matrix<T1, NRows, NCols>& \
00175 Matrix<T1, NRows, NCols>::alias_##NAME (const Matrix<T2, Rows, Cols>& rhs) { \
00176 this->alias_##NAME( XprMatrix<typename Matrix<T2, Rows, Cols>::ConstReference, Rows, Cols>(rhs.const_ref()) ); \
00177 return *this; \
00178 }
00179
00180 TVMET_IMPLEMENT_MACRO(assign)
00181 TVMET_IMPLEMENT_MACRO(add_eq)
00182 TVMET_IMPLEMENT_MACRO(sub_eq)
00183 TVMET_IMPLEMENT_MACRO(mul_eq)
00184 TVMET_IMPLEMENT_MACRO(div_eq)
00185 #undef TVMET_IMPLEMENT_MACRO
00186
00187
00188
00189
00190
00191
00192 #define TVMET_IMPLEMENT_MACRO(NAME) \
00193 template<class T, std::size_t NRows, std::size_t NCols> \
00194 template<class E> \
00195 inline \
00196 Matrix<T, NRows, NCols>& \
00197 Matrix<T, NRows, NCols>::alias_##NAME (const XprMatrix<E, Rows, Cols>& rhs) { \
00198 typedef Matrix<T, NRows, NCols> temp_type; \
00199 temp_type(rhs).assign_to(*this, Fcnl_##NAME<value_type, typename E::value_type>()); \
00200 return *this; \
00201 }
00202
00203 TVMET_IMPLEMENT_MACRO(assign)
00204 TVMET_IMPLEMENT_MACRO(add_eq)
00205 TVMET_IMPLEMENT_MACRO(sub_eq)
00206 TVMET_IMPLEMENT_MACRO(mul_eq)
00207 TVMET_IMPLEMENT_MACRO(div_eq)
00208 #undef TVMET_IMPLEMENT_MACRO
00209
00210
00211 }
00212
00213 #endif // TVMET_MATRIX_IMPL_H
00214
00215
00216
00217
00218