Skip to content

Commit

Permalink
Add != Zeros overload for Matrix, Vector.
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Rosten committed Sep 11, 2012
1 parent b3d2e99 commit 6726662
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile.in
Expand Up @@ -44,7 +44,7 @@ docs:
doxygen


TESTS=lu slice vector_resize gauss_jordan eigen-sqrt determinant chol_toon chol_lapack simplex sym_eigen fill so3 complex qr gr_svd diagonal_matrix gaussian_elimination
TESTS=lu slice vector_resize gauss_jordan eigen-sqrt determinant chol_toon chol_lapack simplex sym_eigen fill so3 complex qr gr_svd diagonal_matrix gaussian_elimination zeros


TEST_RESULT=$(TESTS:%=regressions/%.result)
Expand Down
7 changes: 7 additions & 0 deletions internal/matrix.hh
Expand Up @@ -283,6 +283,13 @@ public:
return 1;
return 0;
}

template<class Op>
bool operator!=(const Operator<Op>& op)
{
return op.notequal(*this);
}


///@}

Expand Down
19 changes: 19 additions & 0 deletions internal/objects.h
Expand Up @@ -145,6 +145,25 @@ template<> struct Operator<Internal::Zero> {
}
///@}

template<int R, int C, class P, class B>
bool notequal(Matrix<R,C,P,B>& m) const {
for(int r=0; r<m.num_rows(); r++)
for(int c=0; c<m.num_cols(); c++)
if(m[r][c] != 0)
return 1;

return 0;
}


template<int S, class P, class B>
bool notequal(Vector<S,P,B>& v) const {
for(int i=0; i<v.size(); i++)
if(v[i] != 0)
return 1;
return 0;
}

///Generate a sized Zero object for constructing dynamic vectors.
Operator<Internal::SizedZero> operator()(int s);
///Generate a sized Zero object for constructing dynamic matrices.
Expand Down
9 changes: 8 additions & 1 deletion internal/vector.hh
Expand Up @@ -357,7 +357,14 @@ public:
return 1;
return 0;
}



template<class Op>
bool operator!=(const Operator<Op>& op)
{
return op.notequal(*this);
}

/// @}

/// @name Misc
Expand Down
28 changes: 28 additions & 0 deletions regressions/zeros.cc
@@ -0,0 +1,28 @@
#include "regressions/regression.h"

int main()
{
Vector<5> v1 = Zeros;
cout << v1 << endl;

Vector<> v2 = Zeros(3);
cout << v2 << endl;

Matrix<3,6> m1 = Zeros;
cout << m1 << endl;

Matrix<> m2 = Zeros(2,3);
cout << m2 << endl;


Vector<4> v3 = Zeros;
cout << (v3 != Zeros) << endl;

v3 = Ones;
cout << (v3 != Zeros) << endl;

Matrix<4> m3 = Zeros;
cout << (m3 != Zeros) << endl;
m3 = Ones;
cout << (m3 != Zeros) << endl;
}
15 changes: 15 additions & 0 deletions regressions/zeros.txt
@@ -0,0 +1,15 @@
0 0 0 0 0

0 0 0

0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0

0 0 0
0 0 0

0
1
0
1

0 comments on commit 6726662

Please sign in to comment.