Skip to content
This repository has been archived by the owner on Oct 25, 2019. It is now read-only.

Commit

Permalink
Used assert macro to avoid unused-parameter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus committed Sep 27, 2018
1 parent da021ac commit a535a3c
Show file tree
Hide file tree
Showing 19 changed files with 1,121 additions and 1,109 deletions.
14 changes: 13 additions & 1 deletion src/cppmat/cppmat.h
Expand Up @@ -10,7 +10,6 @@
// =================================================================================================

#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdlib>
#include <iostream>
Expand Down Expand Up @@ -43,6 +42,19 @@
// dummy operation that can be use to suppress the "unused parameter" warnings
#define UNUSED(p) ( (void)(p) )

// -------------------------------------------------------------------------------------------------

#ifndef NDEBUG

#define Assert(x) assert(x)

#else

#include <assert.h>
#define Assert(x) ((void)(x))

#endif

// ====================================== forward declaration ======================================

namespace cppmat {
Expand Down
10 changes: 5 additions & 5 deletions src/cppmat/fix_cartesian.hpp
Expand Up @@ -770,7 +770,7 @@ cppmat::tiny::cartesian::vector<X,ND> cross(
const cppmat::tiny::cartesian::vector<X,ND> &A, const cppmat::tiny::cartesian::vector<X,ND> &B
)
{
assert( false );
Assert( false );

UNUSED(B);

Expand Down Expand Up @@ -915,7 +915,7 @@ template<typename X, size_t ND>
inline
X det(const cppmat::tiny::cartesian::tensor2<X,ND> &A)
{
assert( false );
Assert( false );

UNUSED(A);

Expand All @@ -928,7 +928,7 @@ template<typename X, size_t ND>
inline
X det(const cppmat::tiny::cartesian::tensor2s<X,ND> &A)
{
assert( false );
Assert( false );

UNUSED(A);

Expand Down Expand Up @@ -957,7 +957,7 @@ template<typename X, size_t ND>
inline
cppmat::tiny::cartesian::tensor2<X,ND> inv(const cppmat::tiny::cartesian::tensor2<X,ND> &A)
{
assert(false);
Assert(false);

return A;
}
Expand All @@ -968,7 +968,7 @@ template<typename X, size_t ND>
inline
cppmat::tiny::cartesian::tensor2s<X,ND> inv(const cppmat::tiny::cartesian::tensor2s<X,ND> &A)
{
assert(false);
Assert(false);

return A;
}
Expand Down
98 changes: 49 additions & 49 deletions src/cppmat/fix_diagonal_matrix.hpp
Expand Up @@ -62,8 +62,8 @@ template<typename X, size_t M, size_t N>
inline
matrix<X,M,N>::matrix(const cppmat::diagonal::matrix<X> &A) : cppmat::tiny::diagonal::matrix<X,M,N>()
{
assert( N == A.shape(0) );
assert( N == A.shape(1) );
Assert( N == A.shape(0) );
Assert( N == A.shape(1) );

setCopy(A.begin(), A.end());
}
Expand Down Expand Up @@ -272,8 +272,8 @@ inline
size_t matrix<X,M,N>::shape(int i) const
{
// check axis: (0,1,...,rank-1) or (-1,-2,...,-rank)
assert( i < static_cast<int>(mRank) );
assert( i >= -1 * static_cast<int>(mRank) );
Assert( i < static_cast<int>(mRank) );
Assert( i >= -1 * static_cast<int>(mRank) );

// return shape
return N;
Expand All @@ -286,7 +286,7 @@ inline
size_t matrix<X,M,N>::shape(size_t i) const
{
// check axis: (0,1,...,rank-1)
assert( i < mRank );
Assert( i < mRank );

// return shape
return N;
Expand Down Expand Up @@ -371,7 +371,7 @@ template<typename X, size_t M, size_t N>
inline
X& matrix<X,M,N>::operator[](size_t i)
{
assert( i < mSize );
Assert( i < mSize );

return mData[i];
}
Expand All @@ -382,7 +382,7 @@ template<typename X, size_t M, size_t N>
inline
const X& matrix<X,M,N>::operator[](size_t i) const
{
assert( i < mSize );
Assert( i < mSize );

return mData[i];
}
Expand All @@ -397,8 +397,8 @@ X& matrix<X,M,N>::operator()(int a, int b)
{
int n = static_cast<int>(N);

assert( ( a < n && a >= -n ) or mPeriodic );
assert( ( b < n && b >= -n ) or mPeriodic );
Assert( ( a < n && a >= -n ) or mPeriodic );
Assert( ( b < n && b >= -n ) or mPeriodic );

if ( a != b ) return mZero[0];

Expand All @@ -415,8 +415,8 @@ const X& matrix<X,M,N>::operator()(int a, int b) const
{
int n = static_cast<int>(N);

assert( ( a < n && a >= -n ) or mPeriodic );
assert( ( b < n && b >= -n ) or mPeriodic );
Assert( ( a < n && a >= -n ) or mPeriodic );
Assert( ( b < n && b >= -n ) or mPeriodic );

if ( a != b ) return mZero[0];

Expand All @@ -432,8 +432,8 @@ template<typename T, typename S>
inline
X& matrix<X,M,N>::operator()(T a, T b)
{
assert( a < N );
assert( b < N );
Assert( a < N );
Assert( b < N );

if (a == b) return mData[a];
else return mZero[0];
Expand All @@ -446,8 +446,8 @@ template<typename T, typename S>
inline
const X& matrix<X,M,N>::operator()(T a, T b) const
{
assert( a < N );
assert( b < N );
Assert( a < N );
Assert( b < N );

if (a == b) return mData[a];
else return mZero[0];
Expand All @@ -461,11 +461,11 @@ template<typename X, size_t M, size_t N>
inline
size_t matrix<X,M,N>::compress(int a, int b) const
{
assert( a == b );
Assert( a == b );

int n = static_cast<int>(N);

assert( ( a < n && a >= -n ) or mPeriodic );
Assert( ( a < n && a >= -n ) or mPeriodic );

size_t A = static_cast<size_t>( (n+(a%n)) % n );

Expand All @@ -479,9 +479,9 @@ template<typename T, typename S>
inline
size_t matrix<X,M,N>::compress(T a, T b) const
{
assert( a < N );
assert( b < N );
assert( a == b );
Assert( a < N );
Assert( b < N );
Assert( a == b );

return a;
}
Expand All @@ -495,7 +495,7 @@ inline
std::vector<size_t> matrix<X,M,N>::decompress(size_t i) const
{
// check input
assert( i < mSize );
Assert( i < mSize );

// allocate matrix-index
std::vector<size_t> idx(mRank);
Expand Down Expand Up @@ -614,7 +614,7 @@ template<typename X, size_t M, size_t N>
inline
auto matrix<X,M,N>::index(size_t i)
{
assert( i < mSize );
Assert( i < mSize );

return begin() + i;
}
Expand All @@ -625,7 +625,7 @@ template<typename X, size_t M, size_t N>
inline
auto matrix<X,M,N>::index(size_t i) const
{
assert( i < mSize );
Assert( i < mSize );

return begin() + i;
}
Expand All @@ -638,11 +638,11 @@ template<typename X, size_t M, size_t N>
inline
auto matrix<X,M,N>::item(int a, int b)
{
assert( a == b );
Assert( a == b );

int n = static_cast<int>(N);

assert( ( a < n && a >= -n ) or mPeriodic );
Assert( ( a < n && a >= -n ) or mPeriodic );

size_t A = static_cast<size_t>( (n+(a%n)) % n );

Expand All @@ -655,11 +655,11 @@ template<typename X, size_t M, size_t N>
inline
auto matrix<X,M,N>::item(int a, int b) const
{
assert( a == b );
Assert( a == b );

int n = static_cast<int>(N);

assert( ( a < n && a >= -n ) or mPeriodic );
Assert( ( a < n && a >= -n ) or mPeriodic );

size_t A = static_cast<size_t>( (n+(a%n)) % n );

Expand All @@ -673,9 +673,9 @@ template<typename T, typename S>
inline
auto matrix<X,M,N>::item(T a, T b)
{
assert( a < N );
assert( b < N );
assert( a == b );
Assert( a < N );
Assert( b < N );
Assert( a == b );

return this->begin() + a;
}
Expand All @@ -687,9 +687,9 @@ template<typename T, typename S>
inline
auto matrix<X,M,N>::item(T a, T b) const
{
assert( a < N );
assert( b < N );
assert( a == b );
Assert( a < N );
Assert( b < N );
Assert( a == b );

return this->begin() + a;
}
Expand Down Expand Up @@ -768,7 +768,7 @@ template<class Iterator>
inline
void matrix<X,M,N>::setCopy(Iterator first, Iterator last)
{
assert( mSize == static_cast<size_t>(last-first) );
Assert( mSize == static_cast<size_t>(last-first) );

std::copy(first, last, begin());
}
Expand All @@ -785,7 +785,7 @@ void matrix<X,M,N>::setCopyDense(Iterator first)
for ( size_t i = 0 ; i < N ; ++i )
for ( size_t j = 0 ; j < N ; ++j )
if ( i !=j )
assert( !first[i*N+j] );
Assert( !first[i*N+j] );
#endif

// copy from input (ignores off-diagonal terms)
Expand All @@ -804,14 +804,14 @@ void matrix<X,M,N>::setCopyDense(Iterator first, Iterator last)
UNUSED(last);

// check size
assert( N*N == static_cast<size_t>(last-first) );
Assert( N*N == static_cast<size_t>(last-first) );

// check the input to be diagonal
#ifndef NDEBUG
for ( size_t i = 0 ; i < N ; ++i )
for ( size_t j = 0 ; j < N ; ++j )
if ( i !=j )
assert( !first[i*N+j] );
Assert( !first[i*N+j] );
#endif

// copy from input (ignores off-diagonal terms)
Expand All @@ -838,7 +838,7 @@ template<class Iterator>
inline
void matrix<X,M,N>::copyTo(Iterator first, Iterator last) const
{
assert( mSize == static_cast<size_t>(last-first) );
Assert( mSize == static_cast<size_t>(last-first) );

UNUSED(last);

Expand Down Expand Up @@ -867,7 +867,7 @@ template<class Iterator>
inline
void matrix<X,M,N>::copyToDense(Iterator first, Iterator last) const
{
assert( N*N == static_cast<size_t>(last-first) );
Assert( N*N == static_cast<size_t>(last-first) );

UNUSED(last);

Expand Down Expand Up @@ -959,9 +959,9 @@ template<typename X, size_t M, size_t N>
inline
matrix<X,M,N>& matrix<X,M,N>::operator*= (const matrix<X,M,N> &B)
{
assert( shape() == B.shape() );
assert( rank () == B.rank () );
assert( size () == B.size () );
Assert( shape() == B.shape() );
Assert( rank () == B.rank () );
Assert( size () == B.size () );

for ( size_t i = 0 ; i < mSize ; ++i )
mData[i] *= B[i];
Expand All @@ -975,9 +975,9 @@ template<typename X, size_t M, size_t N>
inline
matrix<X,M,N>& matrix<X,M,N>::operator+= (const matrix<X,M,N> &B)
{
assert( shape() == B.shape() );
assert( rank () == B.rank () );
assert( size () == B.size () );
Assert( shape() == B.shape() );
Assert( rank () == B.rank () );
Assert( size () == B.size () );

for ( size_t i = 0 ; i < mSize ; ++i )
mData[i] += B[i];
Expand All @@ -991,9 +991,9 @@ template<typename X, size_t M, size_t N>
inline
matrix<X,M,N>& matrix<X,M,N>::operator-= (const matrix<X,M,N> &B)
{
assert( shape() == B.shape() );
assert( rank () == B.rank () );
assert( size () == B.size () );
Assert( shape() == B.shape() );
Assert( rank () == B.rank () );
Assert( size () == B.size () );

for ( size_t i = 0 ; i < mSize ; ++i )
mData[i] -= B[i];
Expand Down Expand Up @@ -1384,7 +1384,7 @@ size_t matrix<X,M,N>::where(int index) const
if ( mData[i] )
++nnz;

assert( index < nnz && index >= -nnz );
Assert( index < nnz && index >= -nnz );

index = ( nnz + (index%nnz) ) % nnz;

Expand Down

0 comments on commit a535a3c

Please sign in to comment.