Skip to content

Commit

Permalink
Fix the compile time checks in the constructors and assignment operat…
Browse files Browse the repository at this point in the history
…ors of the 'SymmetricMatrix' class template
  • Loading branch information
igl42 committed Apr 8, 2015
1 parent bf46c24 commit e45d05d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 60 deletions.
23 changes: 6 additions & 17 deletions blaze/math/adaptors/symmetricmatrix/DenseNonNumeric.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@
#include <blaze/math/shims/Move.h>
#include <blaze/math/traits/MultTrait.h>
#include <blaze/math/typetraits/IsComputation.h>
#include <blaze/math/typetraits/IsLower.h>
#include <blaze/math/typetraits/IsResizable.h>
#include <blaze/math/typetraits/IsSparseMatrix.h>
#include <blaze/math/typetraits/IsSquare.h>
#include <blaze/math/typetraits/IsSymmetric.h>
#include <blaze/math/typetraits/IsUpper.h>
#include <blaze/math/typetraits/RemoveAdaptor.h>
#include <blaze/math/views/DenseSubmatrix.h>
#include <blaze/math/views/Submatrix.h>
Expand Down Expand Up @@ -705,9 +703,6 @@ inline SymmetricMatrix<MT,SO,true,false>::SymmetricMatrix( const Matrix<MT2,SO>&
typedef typename RemoveAdaptor<typename MT2::ResultType>::Type RT;
typedef typename If< IsComputation<MT2>, RT, const MT2& >::Type Tmp;

if( IsLower<MT2>::value || IsUpper<MT2>::value )
throw std::invalid_argument( "Invalid setup of symmetric matrix" );

if( IsSymmetric<MT2>::value ) {
resize( matrix_, (~m).rows(), (~m).columns() );
assign( ~m );
Expand Down Expand Up @@ -750,9 +745,6 @@ inline SymmetricMatrix<MT,SO,true,false>::SymmetricMatrix( const Matrix<MT2,!SO>
typedef typename RemoveAdaptor<typename MT2::ResultType>::Type RT;
typedef typename If< IsComputation<MT2>, RT, const MT2& >::Type Tmp;

if( IsLower<MT2>::value || IsUpper<MT2>::value )
throw std::invalid_argument( "Invalid setup of symmetric matrix" );

if( IsSymmetric<MT2>::value ) {
resize( matrix_, (~m).rows(), (~m).columns() );
assign( trans( ~m ) );
Expand Down Expand Up @@ -1104,8 +1096,7 @@ inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,false>
{
using blaze::resize;

if( IsLower<MT2>::value || IsUpper<MT2>::value ||
( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) )
if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

if( (~rhs).isAliased( this ) ) {
Expand Down Expand Up @@ -1154,7 +1145,7 @@ inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,false>&
, typename MT2::CompositeType
, typename MT2::ResultType >::Type Tmp;

if( IsLower<MT2>::value || IsUpper<MT2>::value || !isSquare( ~rhs ) )
if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

Tmp tmp( ~rhs );
Expand Down Expand Up @@ -1223,8 +1214,7 @@ template< typename MT2 > // Type of the right-hand side matrix
inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,false>& >::Type
SymmetricMatrix<MT,SO,true,false>::operator+=( const Matrix<MT2,SO>& rhs )
{
if( IsLower<MT2>::value || IsUpper<MT2>::value ||
( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) )
if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

addAssign( ~rhs );
Expand Down Expand Up @@ -1261,7 +1251,7 @@ inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,false>&
, typename MT2::CompositeType
, typename MT2::ResultType >::Type Tmp;

if( IsLower<MT2>::value || IsUpper<MT2>::value || !isSquare( ~rhs ) )
if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

Tmp tmp( ~rhs );
Expand Down Expand Up @@ -1327,8 +1317,7 @@ template< typename MT2 > // Type of the right-hand side matrix
inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,false>& >::Type
SymmetricMatrix<MT,SO,true,false>::operator-=( const Matrix<MT2,SO>& rhs )
{
if( IsLower<MT2>::value || IsUpper<MT2>::value ||
( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) )
if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

subAssign( ~rhs );
Expand Down Expand Up @@ -1365,7 +1354,7 @@ inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,false>&
, typename MT2::CompositeType
, typename MT2::ResultType >::Type Tmp;

if( IsLower<MT2>::value || IsUpper<MT2>::value || !isSquare( ~rhs ) )
if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

Tmp tmp( ~rhs );
Expand Down
23 changes: 8 additions & 15 deletions blaze/math/adaptors/symmetricmatrix/DenseNumeric.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@
#include <blaze/math/shims/Clear.h>
#include <blaze/math/shims/Move.h>
#include <blaze/math/typetraits/IsComputation.h>
#include <blaze/math/typetraits/IsLower.h>
#include <blaze/math/typetraits/IsResizable.h>
#include <blaze/math/typetraits/IsSquare.h>
#include <blaze/math/typetraits/IsSymmetric.h>
#include <blaze/math/typetraits/IsUpper.h>
#include <blaze/math/views/Column.h>
#include <blaze/math/views/DenseColumn.h>
#include <blaze/math/views/DenseRow.h>
Expand Down Expand Up @@ -811,8 +809,7 @@ template< typename MT2 > // Type of the foreign matrix
inline SymmetricMatrix<MT,SO,true,true>::SymmetricMatrix( const Matrix<MT2,SO>& m )
: matrix_( ~m ) // The adapted dense matrix
{
if( IsLower<MT2>::value || IsUpper<MT2>::value ||
( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) ) )
if( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) )
throw std::invalid_argument( "Invalid setup of symmetric matrix" );

BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
Expand All @@ -837,8 +834,7 @@ template< typename MT2 > // Type of the foreign matrix
inline SymmetricMatrix<MT,SO,true,true>::SymmetricMatrix( const Matrix<MT2,!SO>& m )
: matrix_( trans( ~m ) ) // The adapted dense matrix
{
if( IsLower<MT2>::value || IsUpper<MT2>::value ||
( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) ) )
if( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) )
throw std::invalid_argument( "Invalid setup of symmetric matrix" );

BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
Expand Down Expand Up @@ -1148,8 +1144,7 @@ template< typename MT2 > // Type of the right-hand side matrix
inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,true>& >::Type
SymmetricMatrix<MT,SO,true,true>::operator=( const Matrix<MT2,SO>& rhs )
{
if( IsLower<MT2>::value || IsUpper<MT2>::value ||
( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) )
if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

matrix_ = ~rhs;
Expand Down Expand Up @@ -1179,7 +1174,7 @@ template< typename MT2 > // Type of the right-hand side matrix
inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,true>& >::Type
SymmetricMatrix<MT,SO,true,true>::operator=( const Matrix<MT2,SO>& rhs )
{
if( IsLower<MT2>::value || IsUpper<MT2>::value || !isSquare( ~rhs ) )
if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

if( IsSymmetric<MT2>::value ) {
Expand Down Expand Up @@ -1244,8 +1239,7 @@ template< typename MT2 > // Type of the right-hand side matrix
inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,true>& >::Type
SymmetricMatrix<MT,SO,true,true>::operator+=( const Matrix<MT2,SO>& rhs )
{
if( IsLower<MT2>::value || IsUpper<MT2>::value ||
( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) )
if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

matrix_ += ~rhs;
Expand Down Expand Up @@ -1275,7 +1269,7 @@ template< typename MT2 > // Type of the right-hand side matrix
inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,true>& >::Type
SymmetricMatrix<MT,SO,true,true>::operator+=( const Matrix<MT2,SO>& rhs )
{
if( IsLower<MT2>::value || IsUpper<MT2>::value || !isSquare( ~rhs ) )
if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

if( IsSymmetric<MT2>::value ) {
Expand Down Expand Up @@ -1341,8 +1335,7 @@ template< typename MT2 > // Type of the right-hand side matrix
inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,true>& >::Type
SymmetricMatrix<MT,SO,true,true>::operator-=( const Matrix<MT2,SO>& rhs )
{
if( IsLower<MT2>::value || IsUpper<MT2>::value ||
( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) )
if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

matrix_ -= ~rhs;
Expand Down Expand Up @@ -1372,7 +1365,7 @@ template< typename MT2 > // Type of the right-hand side matrix
inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,true>& >::Type
SymmetricMatrix<MT,SO,true,true>::operator-=( const Matrix<MT2,SO>& rhs )
{
if( IsLower<MT2>::value || IsUpper<MT2>::value || !isSquare( ~rhs ) )
if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

if( IsSymmetric<MT2>::value ) {
Expand Down
17 changes: 4 additions & 13 deletions blaze/math/adaptors/symmetricmatrix/SparseNonNumeric.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@
#include <blaze/math/traits/MultTrait.h>
#include <blaze/math/traits/SubTrait.h>
#include <blaze/math/typetraits/IsComputation.h>
#include <blaze/math/typetraits/IsLower.h>
#include <blaze/math/typetraits/IsResizable.h>
#include <blaze/math/typetraits/IsSquare.h>
#include <blaze/math/typetraits/IsSymmetric.h>
#include <blaze/math/typetraits/IsUpper.h>
#include <blaze/math/typetraits/RemoveAdaptor.h>
#include <blaze/util/Assert.h>
#include <blaze/util/constraints/Const.h>
Expand Down Expand Up @@ -755,9 +753,6 @@ inline SymmetricMatrix<MT,SO,false,false>::SymmetricMatrix( const Matrix<MT2,SO>
typedef typename RemoveAdaptor<typename MT2::ResultType>::Type RT;
typedef typename If< IsComputation<MT2>, RT, const MT2& >::Type Tmp;

if( IsLower<MT2>::value || IsUpper<MT2>::value )
throw std::invalid_argument( "Invalid setup of symmetric matrix" );

Tmp tmp( ~m );

if( !IsSymmetric<MT2>::value && !isSymmetric( tmp ) )
Expand Down Expand Up @@ -793,9 +788,6 @@ inline SymmetricMatrix<MT,SO,false,false>::SymmetricMatrix( const Matrix<MT2,!SO
typedef typename RemoveAdaptor<typename MT2::ResultType>::Type RT;
typedef typename If< IsComputation<MT2>, RT, const MT2& >::Type Tmp;

if( IsLower<MT2>::value || IsUpper<MT2>::value )
throw std::invalid_argument( "Invalid setup of symmetric matrix" );

Tmp tmp( ~m );

if( !IsSymmetric<MT2>::value && !isSymmetric( tmp ) )
Expand Down Expand Up @@ -1069,8 +1061,7 @@ inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,false
{
using blaze::resize;

if( IsLower<MT2>::value || IsUpper<MT2>::value ||
( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) )
if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

if( (~rhs).canAlias( this ) ) {
Expand Down Expand Up @@ -1113,7 +1104,7 @@ inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,false>
{
using blaze::resize;

if( IsLower<MT2>::value || IsUpper<MT2>::value || !isSquare( ~rhs ) )
if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

typename MT2::ResultType tmp( ~rhs );
Expand Down Expand Up @@ -1182,7 +1173,7 @@ inline SymmetricMatrix<MT,SO,false,false>&

typedef typename AddTrait<MT,typename MT2::ResultType>::Type Tmp;

if( IsLower<MT2>::value || IsUpper<MT2>::value || !isSquare( ~rhs ) )
if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

Tmp tmp( (*this) + ~rhs );
Expand Down Expand Up @@ -1251,7 +1242,7 @@ inline SymmetricMatrix<MT,SO,false,false>&

typedef typename SubTrait<MT,typename MT2::ResultType>::Type Tmp;

if( IsLower<MT2>::value || IsUpper<MT2>::value || !isSquare( ~rhs ) )
if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

Tmp tmp( (*this) - ~rhs );
Expand Down
23 changes: 8 additions & 15 deletions blaze/math/adaptors/symmetricmatrix/SparseNumeric.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@
#include <blaze/math/sparse/SparseElement.h>
#include <blaze/math/sparse/SparseMatrix.h>
#include <blaze/math/typetraits/IsComputation.h>
#include <blaze/math/typetraits/IsLower.h>
#include <blaze/math/typetraits/IsResizable.h>
#include <blaze/math/typetraits/IsSquare.h>
#include <blaze/math/typetraits/IsSymmetric.h>
#include <blaze/math/typetraits/IsUpper.h>
#include <blaze/util/Assert.h>
#include <blaze/util/constraints/Const.h>
#include <blaze/util/constraints/Numeric.h>
Expand Down Expand Up @@ -931,8 +929,7 @@ template< typename MT2 > // Type of the foreign matrix
inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( const Matrix<MT2,SO>& m )
: matrix_( ~m ) // The adapted sparse matrix
{
if( IsLower<MT2>::value || IsUpper<MT2>::value ||
( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) ) )
if( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) )
throw std::invalid_argument( "Invalid setup of symmetric matrix" );

BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
Expand All @@ -957,8 +954,7 @@ template< typename MT2 > // Type of the foreign matrix
inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( const Matrix<MT2,!SO>& m )
: matrix_( trans( ~m ) ) // The adapted sparse matrix
{
if( IsLower<MT2>::value || IsUpper<MT2>::value ||
( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) ) )
if( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) )
throw std::invalid_argument( "Invalid setup of symmetric matrix" );

BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
Expand Down Expand Up @@ -1215,8 +1211,7 @@ template< typename MT2 > // Type of the right-hand side matrix
inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
SymmetricMatrix<MT,SO,false,true>::operator=( const Matrix<MT2,SO>& rhs )
{
if( IsLower<MT2>::value || IsUpper<MT2>::value ||
( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) )
if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

matrix_ = ~rhs;
Expand Down Expand Up @@ -1246,7 +1241,7 @@ template< typename MT2 > // Type of the right-hand side matrix
inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
SymmetricMatrix<MT,SO,false,true>::operator=( const Matrix<MT2,SO>& rhs )
{
if( IsLower<MT2>::value || IsUpper<MT2>::value || !isSquare( ~rhs ) )
if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

if( IsSymmetric<MT2>::value ) {
Expand Down Expand Up @@ -1311,8 +1306,7 @@ template< typename MT2 > // Type of the right-hand side matrix
inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
SymmetricMatrix<MT,SO,false,true>::operator+=( const Matrix<MT2,SO>& rhs )
{
if( IsLower<MT2>::value || IsUpper<MT2>::value ||
( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) )
if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

matrix_ += ~rhs;
Expand Down Expand Up @@ -1342,7 +1336,7 @@ template< typename MT2 > // Type of the right-hand side matrix
inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
SymmetricMatrix<MT,SO,false,true>::operator+=( const Matrix<MT2,SO>& rhs )
{
if( IsLower<MT2>::value || IsUpper<MT2>::value || !isSquare( ~rhs ) )
if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

if( IsSymmetric<MT2>::value ) {
Expand Down Expand Up @@ -1408,8 +1402,7 @@ template< typename MT2 > // Type of the right-hand side matrix
inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
SymmetricMatrix<MT,SO,false,true>::operator-=( const Matrix<MT2,SO>& rhs )
{
if( IsLower<MT2>::value || IsUpper<MT2>::value ||
( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) )
if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

matrix_ -= ~rhs;
Expand Down Expand Up @@ -1439,7 +1432,7 @@ template< typename MT2 > // Type of the right-hand side matrix
inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
SymmetricMatrix<MT,SO,false,true>::operator-=( const Matrix<MT2,SO>& rhs )
{
if( IsLower<MT2>::value || IsUpper<MT2>::value || !isSquare( ~rhs ) )
if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
throw std::invalid_argument( "Invalid assignment to symmetric matrix" );

if( IsSymmetric<MT2>::value ) {
Expand Down

0 comments on commit e45d05d

Please sign in to comment.