Ejemplo n.º 1
0
 def test_mul(self):
     assert_equals(self.x_spmat * self.x_spmat, self.x_spmat)
     assert_equals(self.diag_spmat * self.coo_spmat, self.coo_spmat)
     assert_equals(BoolMat.mul(self.diag_spmat, (4,4), True, (1,1)), self.diag_spmat)
     assert_equals(BoolMat.mul(False, (1,1), self.diag_spmat, (4,4)), False)
     assert_equals(self.x_spmat * self.coo_spmat, self.x_spmat)
     assert_equals(self.x_spmat * self.empty_spmat, self.empty_spmat)
Ejemplo n.º 2
0
 def test_mul(self):
     assert_equals(self.true_mat * self.true_mat, self.true_mat)
     assert_equals(self.true_mat * self.false_vec, self.false_vec)
     assert_equals(BoolMat.mul(self.false_mat, (4,4), True, (1,1)), self.false_mat)
     assert_equals(BoolMat.mul(False, (1,1), self.true_mat, (4,4)), False)
     assert_equals(self.mixed_mat * self.true_vec, self.true_vec)
     assert_equals(self.mixed_mat * self.mixed_mat, self.mixed_mat)
Ejemplo n.º 3
0
    def test_promote(self):
        arr = BoolMat.promote(True, (3,2))
        assert_equals(arr.value.shape, (3,2))
        assert_equals(arr.value[0,0], True)

        arr = BoolMat.promote(False, (4,3))
        assert_equals(arr.value.shape, (4,3))
        assert_equals(arr.value[0,0], False)

        arr = BoolMat.promote(arr, (4,4))
        assert_equals(arr.value.shape, (4,3))

        arr = BoolMat.promote(True, (1,1))
        assert_equals(arr, True)
Ejemplo n.º 4
0
    def setup_class(self):
        n = 4
        # Vectors.
        self.arr = np.array(n*[True])
        self.mixed_arr = np.array(n/2 * [True, False])
        self.true_vec = BoolMat(self.arr)
        self.false_vec = BoolMat(~self.arr)

        # Matrices.
        self.mat = np.vstack(n*[self.arr])
        self.mixed = np.vstack(n*[self.mixed_arr])
        self.true_mat = BoolMat(self.mat)
        self.false_mat = BoolMat(~self.mat)
        self.mixed_mat = BoolMat(self.mixed)
Ejemplo n.º 5
0
class TestBoolMat(object):
    """ Unit tests for the utilities/BoolMat class. """
    @classmethod
    def setup_class(self):
        n = 4
        # Vectors.
        self.arr = np.array(n*[True])
        self.mixed_arr = np.array(n/2 * [True, False])
        self.true_vec = BoolMat(self.arr)
        self.false_vec = BoolMat(~self.arr)

        # Matrices.
        self.mat = np.vstack(n*[self.arr])
        self.mixed = np.vstack(n*[self.mixed_arr])
        self.true_mat = BoolMat(self.mat)
        self.false_mat = BoolMat(~self.mat)
        self.mixed_mat = BoolMat(self.mixed)

    # Test the | operator.
    def test_or(self):
        assert_equals(self.false_mat | self.false_mat, self.false_mat)
        assert_equals(self.true_mat | self.false_mat, self.true_mat)
        assert_equals(self.true_mat | True, True)
        assert_equals(False | self.false_mat, self.false_mat)
        assert_equals(self.mixed_mat | self.true_mat, self.true_mat)
        assert_equals(self.false_mat | self.mixed_mat, self.mixed_mat)

    # Test the & operator.
    def test_and(self):
        assert_equals(self.true_mat & self.true_mat, self.true_mat)
        assert_equals(self.true_mat & self.false_mat, self.false_mat)
        assert_equals(self.true_mat & True, self.true_mat)
        assert_equals(False & self.false_mat, False)
        assert_equals(self.mixed_mat & self.true_mat, self.mixed_mat)
        assert_equals(self.false_mat & self.mixed_mat, self.false_mat)
        assert_equals(BoolMat(~self.mixed) & self.mixed_mat, self.false_mat)

    # Test the * operator.
    def test_mul(self):
        assert_equals(self.true_mat * self.true_mat, self.true_mat)
        assert_equals(self.true_mat * self.false_vec, self.false_vec)
        assert_equals(bu.mul(self.false_mat, (4,4), True, (1,1)), self.false_mat)
        assert_equals(bu.mul(False, (1,1), self.true_mat, (4,4)), False)
        assert_equals(self.mixed_mat * self.true_vec, self.true_vec)
        assert_equals(self.mixed_mat * self.mixed_mat, self.mixed_mat)

    # Test the any operator.
    def test_any(self):
        assert self.true_mat.any()
        assert not self.false_mat.any()
        assert self.mixed_mat.any()

    # Test the promote method.
    def test_promote(self):
        arr = BoolMat.promote(True, (3,2))
        assert_equals(arr.value.shape, (3,2))
        assert_equals(arr.value[0,0], True)

        arr = BoolMat.promote(False, (4,3))
        assert_equals(arr.value.shape, (4,3))
        assert_equals(arr.value[0,0], False)

        arr = BoolMat.promote(arr, (4,4))
        assert_equals(arr.value.shape, (4,3))

        arr = BoolMat.promote(True, (1,1))
        assert_equals(arr, True)