Skip to content

Commit

Permalink
MAINT: sparse: simplify bool_ops.h
Browse files Browse the repository at this point in the history
If the value is a private member, then we don't need to check at every
access whether it's really boolean (1 or 0).
  • Loading branch information
larsmans committed Sep 27, 2015
1 parent c1f6b24 commit 4e5a657
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions scipy/sparse/sparsetools/bool_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Functions to handle arithmetic operations on NumPy Bool values.
*/
#include <numpy/arrayobject.h>
#include <assert.h>

/*
* A compiler time (ct) assert macro from
Expand All @@ -14,31 +13,28 @@
#define ct_assert(e) extern char (*ct_assert(void)) [sizeof(char[1 - 2*!(e)])]

class npy_bool_wrapper {
public:
private:
char value;


public:
/* operators */
operator char() const {
if(value != 0) {
return 1;
} else {
return 0;
}
return value;
}
npy_bool_wrapper& operator=(const npy_bool_wrapper& x) {
value = x;
value = x.value;
return (*this);
}
npy_bool_wrapper operator+(const npy_bool_wrapper& x) {
return (x || value) ? 1 : 0;
return value || x.value;
}
/* inplace operators */
npy_bool_wrapper operator+=(const npy_bool_wrapper& x) {
value = (x || value) ? 1 : 0;
value = (value || x.value);
return (*this);
}
npy_bool_wrapper operator*=(const npy_bool_wrapper& x) {
value = (value && x) ? 1 : 0;
value = (value && x.value);
return (*this);
}
/* constructors */
Expand All @@ -47,7 +43,7 @@ class npy_bool_wrapper {
}
template <class T>
npy_bool_wrapper(T x) {
value = (x) ? 1 : 0;
value = (x != 0);
}
};

Expand Down

0 comments on commit 4e5a657

Please sign in to comment.