46 #include "AbstractLinAlgPack_AssertOp.hpp"
47 #include "AbstractLinAlgPack_VectorSpace.hpp"
48 #include "AbstractLinAlgPack_VectorMutable.hpp"
49 #include "AbstractLinAlgPack_MatrixOp.hpp"
50 #include "Teuchos_Assert.hpp"
56 struct dump_vec_spaces {
62 :vec_space1(_vec_space1),vec_space1_name(_vec_space1_name)
63 ,vec_space2(_vec_space2),vec_space2_name(_vec_space2_name)
66 const char *vec_space1_name;
68 const char *vec_space2_name;
74 std::ostream& operator<<( std::ostream& o,
const dump_vec_spaces& d )
76 o <<
"Error, " << d.vec_space1_name <<
" at address " << &d.vec_space1
77 <<
" of type \'" <<
typeName(d.vec_space1)
78 <<
"\' with dimension " << d.vec_space1_name <<
".dim() = " << d.vec_space1.dim()
79 <<
" is not compatible with "
80 << d.vec_space2_name <<
" at address " << &d.vec_space2
81 <<
" of type \'" <<
typeName(d.vec_space2)
82 <<
"\' with dimension " << d.vec_space2_name <<
".dim() = " << d.vec_space2.dim();
86 enum EM_VS { SPACE_COLS, SPACE_ROWS };
96 if(M_trans ==
no_trans && M_VS == SPACE_COLS)
98 if(M_trans ==
trans && M_VS == SPACE_COLS)
100 if(M_trans ==
no_trans && M_VS == SPACE_ROWS)
108 #define ASSERT_LHS_ARG(FUNC_NAME,LHS_ARG) \
109 TEUCHOS_TEST_FOR_EXCEPTION( \
110 (LHS_ARG) == NULL, std::invalid_argument \
111 ,FUNC_NAME << " : Error!" \
118 #define ASSERT_VEC_SPACES_NAMES(FUNC_NAME,VS1,VS1_NAME,VS2,VS2_NAME) \
120 const bool is_compatible = (VS1).is_compatible(VS2); \
121 TEUCHOS_TEST_FOR_EXCEPTION( \
122 !is_compatible, VectorSpace::IncompatibleVectorSpaces \
123 ,FUNC_NAME << " : " << dump_vec_spaces(VS1,VS1_NAME,VS2,VS2_NAME) \
127 #define ASSERT_VEC_SPACES(FUNC_NAME,VS1,VS2) \
128 ASSERT_VEC_SPACES_NAMES(FUNC_NAME,VS1,#VS1,VS2,#VS2)
130 #define ASSERT_MAT_VEC_SPACES(FUNC_NAME,M,M_T,M_VS,VS) \
132 std::ostringstream M_VS_name; \
133 M_VS_name << "(" #M << ( M_T == BLAS_Cpp::no_trans ? "" : "'" ) << ")" \
134 << "." << ( M_VS == SPACE_COLS ? "space_cols()" : "space_rows()" ); \
135 ASSERT_VEC_SPACES_NAMES( \
137 ,op(M,M_T,M_VS),M_VS_name.str().c_str() \
142 #define ASSERT_MAT_MAT_SPACES(FUNC_NAME,M1,M1_T,M1_VS,M2,M2_T,M2_VS) \
144 std::ostringstream M1_VS_name, M2_VS_name; \
145 M1_VS_name << "(" #M1 << ( M1_T == BLAS_Cpp::no_trans ? "" : "'" ) << ")" \
146 << "." << ( M1_VS == SPACE_COLS ? "space_cols()" : "space_rows()" ); \
147 M2_VS_name << "(" #M2 << ( M2_T == BLAS_Cpp::no_trans ? "" : "'" ) << ")" \
148 << "." << ( M2_VS == SPACE_COLS ? "space_cols()" : "space_rows()" ); \
149 ASSERT_VEC_SPACES_NAMES( \
151 ,op(M1,M1_T,M1_VS),M1_VS_name.str().c_str() \
152 ,op(M2,M2_T,M2_VS),M2_VS_name.str().c_str() \
158 #ifdef ABSTRACTLINALGPACK_ASSERT_COMPATIBILITY
162 const char func_name[] =
"Vp_V_assert_compatibility(v_lhs,v_rhs)";
163 ASSERT_LHS_ARG(func_name,v_lhs)
174 const char func_name[] =
"VopV_assert_compatibility(v_rhs1,v_rhs2)";
175 ASSERT_VEC_SPACES(func_name,v_rhs1.space(),v_rhs2.space());
193 const char func_name[] =
"Mp_M_assert_compatibility(m_lhs,trans_lhs,m_rhs,trans_rhs)";
194 ASSERT_LHS_ARG(func_name,m_lhs)
195 ASSERT_MAT_MAT_SPACES(func_name,(*m_lhs),trans_lhs,SPACE_COLS,m_rhs,trans_rhs,SPACE_COLS)
196 ASSERT_MAT_MAT_SPACES(func_name,(*m_lhs),trans_lhs,SPACE_ROWS,m_rhs,trans_rhs,SPACE_ROWS)
200 const MatrixOp& m_rhs1, BLAS_Cpp::
Transp trans_rhs1
201 ,const MatrixOp& m_rhs2, BLAS_Cpp::
Transp trans_rhs2 )
203 const char func_name[] =
"MopM_assert_compatibility(m_rhs1,trans_rhs1,m_rhs2,trans_rhs2)";
204 ASSERT_MAT_MAT_SPACES(func_name,m_rhs1,trans_rhs1,SPACE_COLS,m_rhs2,trans_rhs2,SPACE_COLS)
205 ASSERT_MAT_MAT_SPACES(func_name,m_rhs1,trans_rhs1,SPACE_ROWS,m_rhs2,trans_rhs2,SPACE_ROWS)
209 const MatrixOp& m_rhs1, BLAS_Cpp::
Transp trans_rhs1, const Vector& v_rhs2 )
211 const char func_name[] =
"MtV_assert_compatibility(m_rhs1,trans_rhs1,v_rhs2)";
212 ASSERT_MAT_VEC_SPACES(func_name,m_rhs1,trans_rhs1,SPACE_ROWS,v_rhs2.space())
216 const MatrixOp& m_rhs1,
BLAS_Cpp::Transp trans_rhs1,
const SpVectorSlice& sv_rhs2 )
223 ,
const MatrixOp& m_rhs1,
BLAS_Cpp::Transp trans_rhs1,
const Vector& v_rhs2 )
225 const char func_name[] =
"Vp_MtV_assert_compatibility(v_lhs,m_rhs1,trans_rhs1,v_rhs2)";
226 ASSERT_LHS_ARG(func_name,v_lhs)
227 ASSERT_MAT_VEC_SPACES(func_name,m_rhs1,trans_rhs1,SPACE_COLS,v_lhs->space())
228 ASSERT_MAT_VEC_SPACES(func_name,m_rhs1,trans_rhs1,SPACE_ROWS,v_rhs2.space())
233 ,const MatrixOp& m_rhs1, BLAS_Cpp::
Transp trans_rhs1, const SpVectorSlice& sv_rhs2 )
242 const char func_name[] =
"MtM_assert_compatibility(m_rhs1,trans_rhs1,m_rhs2,trans_rhs2)";
243 ASSERT_MAT_MAT_SPACES(func_name,m_rhs1,trans_rhs1,SPACE_COLS,m_rhs2,trans_rhs2,SPACE_ROWS)
244 ASSERT_MAT_MAT_SPACES(func_name,m_rhs1,trans_rhs1,SPACE_ROWS,m_rhs2,trans_rhs2,SPACE_COLS)
248 MatrixOp* m_lhs, BLAS_Cpp::
Transp trans_lhs
249 ,const MatrixOp& m_rhs1, BLAS_Cpp::
Transp trans_rhs1
250 ,const MatrixOp& m_rhs2, BLAS_Cpp::
Transp trans_rhs2 )
252 const char func_name[] =
"Mp_MtM_assert_compatibility(m_lhs,trans_lhsm_rhs1,trans_rhs1,m_rhs2,trans_rhs2)";
253 ASSERT_LHS_ARG(func_name,m_lhs)
254 ASSERT_MAT_MAT_SPACES(func_name,(*m_lhs),trans_lhs,SPACE_COLS,m_rhs1,trans_rhs1,SPACE_COLS)
255 ASSERT_MAT_MAT_SPACES(func_name,(*m_lhs),trans_lhs,SPACE_ROWS,m_rhs2,trans_rhs2,SPACE_ROWS)
256 ASSERT_MAT_MAT_SPACES(func_name,m_rhs1,trans_rhs1,SPACE_ROWS,m_rhs2,trans_rhs2,SPACE_COLS)
259 #endif // ABSTRACTLINALGPACK_ASSERT_COMPATIBILITY
virtual const VectorSpace & space_rows() const =0
Vector space for vectors that are compatible with the rows of the matrix.
void MopM_assert_compatibility(const MatrixOp &m_rhs1, BLAS_Cpp::Transp trans_rhs1, const MatrixOp &m_rhs2, BLAS_Cpp::Transp trans_rhs2)
op(m_rhs1) op op(m_rhs2)
void MtV_assert_compatibility(const MatrixOp &m_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2)
op(m_rhs1) * v_rhs2
void Vp_V_assert_compatibility(VectorMutable *v_lhs, const Vector &v_rhs)
v_lhs += op v_rhs
void MtM_assert_compatibility(const MatrixOp &m_rhs1, BLAS_Cpp::Transp trans_rhs1, const MatrixOp &m_rhs2, BLAS_Cpp::Transp trans_rhs2)
op(m_lhs) += op(m_rhs1)
Abstract interface for objects that represent a space for mutable coordinate vectors.
void Mp_MtM_assert_compatibility(MatrixOp *m_lhs, BLAS_Cpp::Transp trans_lhs, const MatrixOp &m_rhs1, BLAS_Cpp::Transp trans_rhs1, const MatrixOp &m_rhs2, BLAS_Cpp::Transp trans_rhs2)
op(m_lhs) += op(m_rhs1) * op(m_rhs2)
Base class for all matrices that support basic matrix operations.
virtual const VectorSpace & space_cols() const =0
Vector space for vectors that are compatible with the columns of the matrix.
void Vp_MtV_assert_compatibility(VectorMutable *v_lhs, const MatrixOp &m_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2)
v_lhs += op(m_rhs1) * v_rhs2
std::string typeName(const T &t)
void Mp_M_assert_compatibility(MatrixOp *m_lhs, BLAS_Cpp::Transp trans_lhs, const MatrixOp &m_rhs, BLAS_Cpp::Transp trans_rhs)
op(m_lhs) += op op(m_rhs)
void VopV_assert_compatibility(const Vector &v_rhs1, const Vector &v_rhs2)
v_rhs1 op v_rhs2