From e45d05d222a8631aabc37cabe9b13dd414d46c40 Mon Sep 17 00:00:00 2001 From: Klaus Iglberger Date: Wed, 8 Apr 2015 04:36:13 +0200 Subject: [PATCH] Fix the compile time checks in the constructors and assignment operators of the 'SymmetricMatrix' class template --- .../symmetricmatrix/DenseNonNumeric.h | 23 +++++-------------- .../adaptors/symmetricmatrix/DenseNumeric.h | 23 +++++++------------ .../symmetricmatrix/SparseNonNumeric.h | 17 ++++---------- .../adaptors/symmetricmatrix/SparseNumeric.h | 23 +++++++------------ 4 files changed, 26 insertions(+), 60 deletions(-) diff --git a/blaze/math/adaptors/symmetricmatrix/DenseNonNumeric.h b/blaze/math/adaptors/symmetricmatrix/DenseNonNumeric.h index d849278b..e5016652 100644 --- a/blaze/math/adaptors/symmetricmatrix/DenseNonNumeric.h +++ b/blaze/math/adaptors/symmetricmatrix/DenseNonNumeric.h @@ -59,12 +59,10 @@ #include #include #include -#include #include #include #include #include -#include #include #include #include @@ -705,9 +703,6 @@ inline SymmetricMatrix::SymmetricMatrix( const Matrix& typedef typename RemoveAdaptor::Type RT; typedef typename If< IsComputation, RT, const MT2& >::Type Tmp; - if( IsLower::value || IsUpper::value ) - throw std::invalid_argument( "Invalid setup of symmetric matrix" ); - if( IsSymmetric::value ) { resize( matrix_, (~m).rows(), (~m).columns() ); assign( ~m ); @@ -750,9 +745,6 @@ inline SymmetricMatrix::SymmetricMatrix( const Matrix typedef typename RemoveAdaptor::Type RT; typedef typename If< IsComputation, RT, const MT2& >::Type Tmp; - if( IsLower::value || IsUpper::value ) - throw std::invalid_argument( "Invalid setup of symmetric matrix" ); - if( IsSymmetric::value ) { resize( matrix_, (~m).rows(), (~m).columns() ); assign( trans( ~m ) ); @@ -1104,8 +1096,7 @@ inline typename DisableIf< IsComputation, SymmetricMatrix { using blaze::resize; - if( IsLower::value || IsUpper::value || - ( !IsSymmetric::value && !isSymmetric( ~rhs ) ) ) + if( !IsSymmetric::value && !isSymmetric( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); if( (~rhs).isAliased( this ) ) { @@ -1154,7 +1145,7 @@ inline typename EnableIf< IsComputation, SymmetricMatrix& , typename MT2::CompositeType , typename MT2::ResultType >::Type Tmp; - if( IsLower::value || IsUpper::value || !isSquare( ~rhs ) ) + if( !IsSquare::value && !isSquare( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); Tmp tmp( ~rhs ); @@ -1223,8 +1214,7 @@ template< typename MT2 > // Type of the right-hand side matrix inline typename DisableIf< IsComputation, SymmetricMatrix& >::Type SymmetricMatrix::operator+=( const Matrix& rhs ) { - if( IsLower::value || IsUpper::value || - ( !IsSymmetric::value && !isSymmetric( ~rhs ) ) ) + if( !IsSymmetric::value && !isSymmetric( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); addAssign( ~rhs ); @@ -1261,7 +1251,7 @@ inline typename EnableIf< IsComputation, SymmetricMatrix& , typename MT2::CompositeType , typename MT2::ResultType >::Type Tmp; - if( IsLower::value || IsUpper::value || !isSquare( ~rhs ) ) + if( !IsSquare::value && !isSquare( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); Tmp tmp( ~rhs ); @@ -1327,8 +1317,7 @@ template< typename MT2 > // Type of the right-hand side matrix inline typename DisableIf< IsComputation, SymmetricMatrix& >::Type SymmetricMatrix::operator-=( const Matrix& rhs ) { - if( IsLower::value || IsUpper::value || - ( !IsSymmetric::value && !isSymmetric( ~rhs ) ) ) + if( !IsSymmetric::value && !isSymmetric( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); subAssign( ~rhs ); @@ -1365,7 +1354,7 @@ inline typename EnableIf< IsComputation, SymmetricMatrix& , typename MT2::CompositeType , typename MT2::ResultType >::Type Tmp; - if( IsLower::value || IsUpper::value || !isSquare( ~rhs ) ) + if( !IsSquare::value && !isSquare( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); Tmp tmp( ~rhs ); diff --git a/blaze/math/adaptors/symmetricmatrix/DenseNumeric.h b/blaze/math/adaptors/symmetricmatrix/DenseNumeric.h index 8aa72004..444422b5 100644 --- a/blaze/math/adaptors/symmetricmatrix/DenseNumeric.h +++ b/blaze/math/adaptors/symmetricmatrix/DenseNumeric.h @@ -60,11 +60,9 @@ #include #include #include -#include #include #include #include -#include #include #include #include @@ -811,8 +809,7 @@ template< typename MT2 > // Type of the foreign matrix inline SymmetricMatrix::SymmetricMatrix( const Matrix& m ) : matrix_( ~m ) // The adapted dense matrix { - if( IsLower::value || IsUpper::value || - ( !IsSymmetric::value && !isSymmetric( matrix_ ) ) ) + if( !IsSymmetric::value && !isSymmetric( matrix_ ) ) throw std::invalid_argument( "Invalid setup of symmetric matrix" ); BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" ); @@ -837,8 +834,7 @@ template< typename MT2 > // Type of the foreign matrix inline SymmetricMatrix::SymmetricMatrix( const Matrix& m ) : matrix_( trans( ~m ) ) // The adapted dense matrix { - if( IsLower::value || IsUpper::value || - ( !IsSymmetric::value && !isSymmetric( matrix_ ) ) ) + if( !IsSymmetric::value && !isSymmetric( matrix_ ) ) throw std::invalid_argument( "Invalid setup of symmetric matrix" ); BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" ); @@ -1148,8 +1144,7 @@ template< typename MT2 > // Type of the right-hand side matrix inline typename DisableIf< IsComputation, SymmetricMatrix& >::Type SymmetricMatrix::operator=( const Matrix& rhs ) { - if( IsLower::value || IsUpper::value || - ( !IsSymmetric::value && !isSymmetric( ~rhs ) ) ) + if( !IsSymmetric::value && !isSymmetric( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); matrix_ = ~rhs; @@ -1179,7 +1174,7 @@ template< typename MT2 > // Type of the right-hand side matrix inline typename EnableIf< IsComputation, SymmetricMatrix& >::Type SymmetricMatrix::operator=( const Matrix& rhs ) { - if( IsLower::value || IsUpper::value || !isSquare( ~rhs ) ) + if( !IsSquare::value && !isSquare( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); if( IsSymmetric::value ) { @@ -1244,8 +1239,7 @@ template< typename MT2 > // Type of the right-hand side matrix inline typename DisableIf< IsComputation, SymmetricMatrix& >::Type SymmetricMatrix::operator+=( const Matrix& rhs ) { - if( IsLower::value || IsUpper::value || - ( !IsSymmetric::value && !isSymmetric( ~rhs ) ) ) + if( !IsSymmetric::value && !isSymmetric( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); matrix_ += ~rhs; @@ -1275,7 +1269,7 @@ template< typename MT2 > // Type of the right-hand side matrix inline typename EnableIf< IsComputation, SymmetricMatrix& >::Type SymmetricMatrix::operator+=( const Matrix& rhs ) { - if( IsLower::value || IsUpper::value || !isSquare( ~rhs ) ) + if( !IsSquare::value && !isSquare( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); if( IsSymmetric::value ) { @@ -1341,8 +1335,7 @@ template< typename MT2 > // Type of the right-hand side matrix inline typename DisableIf< IsComputation, SymmetricMatrix& >::Type SymmetricMatrix::operator-=( const Matrix& rhs ) { - if( IsLower::value || IsUpper::value || - ( !IsSymmetric::value && !isSymmetric( ~rhs ) ) ) + if( !IsSymmetric::value && !isSymmetric( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); matrix_ -= ~rhs; @@ -1372,7 +1365,7 @@ template< typename MT2 > // Type of the right-hand side matrix inline typename EnableIf< IsComputation, SymmetricMatrix& >::Type SymmetricMatrix::operator-=( const Matrix& rhs ) { - if( IsLower::value || IsUpper::value || !isSquare( ~rhs ) ) + if( !IsSquare::value && !isSquare( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); if( IsSymmetric::value ) { diff --git a/blaze/math/adaptors/symmetricmatrix/SparseNonNumeric.h b/blaze/math/adaptors/symmetricmatrix/SparseNonNumeric.h index 0b97d312..39bc3da4 100644 --- a/blaze/math/adaptors/symmetricmatrix/SparseNonNumeric.h +++ b/blaze/math/adaptors/symmetricmatrix/SparseNonNumeric.h @@ -65,11 +65,9 @@ #include #include #include -#include #include #include #include -#include #include #include #include @@ -755,9 +753,6 @@ inline SymmetricMatrix::SymmetricMatrix( const Matrix typedef typename RemoveAdaptor::Type RT; typedef typename If< IsComputation, RT, const MT2& >::Type Tmp; - if( IsLower::value || IsUpper::value ) - throw std::invalid_argument( "Invalid setup of symmetric matrix" ); - Tmp tmp( ~m ); if( !IsSymmetric::value && !isSymmetric( tmp ) ) @@ -793,9 +788,6 @@ inline SymmetricMatrix::SymmetricMatrix( const Matrix::Type RT; typedef typename If< IsComputation, RT, const MT2& >::Type Tmp; - if( IsLower::value || IsUpper::value ) - throw std::invalid_argument( "Invalid setup of symmetric matrix" ); - Tmp tmp( ~m ); if( !IsSymmetric::value && !isSymmetric( tmp ) ) @@ -1069,8 +1061,7 @@ inline typename DisableIf< IsComputation, SymmetricMatrix::value || IsUpper::value || - ( !IsSymmetric::value && !isSymmetric( ~rhs ) ) ) + if( !IsSymmetric::value && !isSymmetric( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); if( (~rhs).canAlias( this ) ) { @@ -1113,7 +1104,7 @@ inline typename EnableIf< IsComputation, SymmetricMatrix { using blaze::resize; - if( IsLower::value || IsUpper::value || !isSquare( ~rhs ) ) + if( !IsSquare::value && !isSquare( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); typename MT2::ResultType tmp( ~rhs ); @@ -1182,7 +1173,7 @@ inline SymmetricMatrix& typedef typename AddTrait::Type Tmp; - if( IsLower::value || IsUpper::value || !isSquare( ~rhs ) ) + if( !IsSquare::value && !isSquare( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); Tmp tmp( (*this) + ~rhs ); @@ -1251,7 +1242,7 @@ inline SymmetricMatrix& typedef typename SubTrait::Type Tmp; - if( IsLower::value || IsUpper::value || !isSquare( ~rhs ) ) + if( !IsSquare::value && !isSquare( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); Tmp tmp( (*this) - ~rhs ); diff --git a/blaze/math/adaptors/symmetricmatrix/SparseNumeric.h b/blaze/math/adaptors/symmetricmatrix/SparseNumeric.h index efcc6c7d..6aa5d3dd 100644 --- a/blaze/math/adaptors/symmetricmatrix/SparseNumeric.h +++ b/blaze/math/adaptors/symmetricmatrix/SparseNumeric.h @@ -60,11 +60,9 @@ #include #include #include -#include #include #include #include -#include #include #include #include @@ -931,8 +929,7 @@ template< typename MT2 > // Type of the foreign matrix inline SymmetricMatrix::SymmetricMatrix( const Matrix& m ) : matrix_( ~m ) // The adapted sparse matrix { - if( IsLower::value || IsUpper::value || - ( !IsSymmetric::value && !isSymmetric( matrix_ ) ) ) + if( !IsSymmetric::value && !isSymmetric( matrix_ ) ) throw std::invalid_argument( "Invalid setup of symmetric matrix" ); BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" ); @@ -957,8 +954,7 @@ template< typename MT2 > // Type of the foreign matrix inline SymmetricMatrix::SymmetricMatrix( const Matrix& m ) : matrix_( trans( ~m ) ) // The adapted sparse matrix { - if( IsLower::value || IsUpper::value || - ( !IsSymmetric::value && !isSymmetric( matrix_ ) ) ) + if( !IsSymmetric::value && !isSymmetric( matrix_ ) ) throw std::invalid_argument( "Invalid setup of symmetric matrix" ); BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" ); @@ -1215,8 +1211,7 @@ template< typename MT2 > // Type of the right-hand side matrix inline typename DisableIf< IsComputation, SymmetricMatrix& >::Type SymmetricMatrix::operator=( const Matrix& rhs ) { - if( IsLower::value || IsUpper::value || - ( !IsSymmetric::value && !isSymmetric( ~rhs ) ) ) + if( !IsSymmetric::value && !isSymmetric( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); matrix_ = ~rhs; @@ -1246,7 +1241,7 @@ template< typename MT2 > // Type of the right-hand side matrix inline typename EnableIf< IsComputation, SymmetricMatrix& >::Type SymmetricMatrix::operator=( const Matrix& rhs ) { - if( IsLower::value || IsUpper::value || !isSquare( ~rhs ) ) + if( !IsSquare::value && !isSquare( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); if( IsSymmetric::value ) { @@ -1311,8 +1306,7 @@ template< typename MT2 > // Type of the right-hand side matrix inline typename DisableIf< IsComputation, SymmetricMatrix& >::Type SymmetricMatrix::operator+=( const Matrix& rhs ) { - if( IsLower::value || IsUpper::value || - ( !IsSymmetric::value && !isSymmetric( ~rhs ) ) ) + if( !IsSymmetric::value && !isSymmetric( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); matrix_ += ~rhs; @@ -1342,7 +1336,7 @@ template< typename MT2 > // Type of the right-hand side matrix inline typename EnableIf< IsComputation, SymmetricMatrix& >::Type SymmetricMatrix::operator+=( const Matrix& rhs ) { - if( IsLower::value || IsUpper::value || !isSquare( ~rhs ) ) + if( !IsSquare::value && !isSquare( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); if( IsSymmetric::value ) { @@ -1408,8 +1402,7 @@ template< typename MT2 > // Type of the right-hand side matrix inline typename DisableIf< IsComputation, SymmetricMatrix& >::Type SymmetricMatrix::operator-=( const Matrix& rhs ) { - if( IsLower::value || IsUpper::value || - ( !IsSymmetric::value && !isSymmetric( ~rhs ) ) ) + if( !IsSymmetric::value && !isSymmetric( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); matrix_ -= ~rhs; @@ -1439,7 +1432,7 @@ template< typename MT2 > // Type of the right-hand side matrix inline typename EnableIf< IsComputation, SymmetricMatrix& >::Type SymmetricMatrix::operator-=( const Matrix& rhs ) { - if( IsLower::value || IsUpper::value || !isSquare( ~rhs ) ) + if( !IsSquare::value && !isSquare( ~rhs ) ) throw std::invalid_argument( "Invalid assignment to symmetric matrix" ); if( IsSymmetric::value ) {