def test_zero(self):
        z = Zero()
        assert z == 0
        assert not (z < 0)
        assert z <= 0
        assert not (z > 0)
        assert z >= 0
        assert +z == z
        assert -z == z
        assert z + 1 == 1
        assert z + 3 + z == 3
        assert z - 3 == -3
        assert z - 3 - z == -3
        assert 3 * z == 0
        assert z * 3 == 0
        assert z / 3 == 0

        a = 1
        a += z
        assert a == 1
        a = 1
        a += z
        assert a == 1
        self.assertRaises(ZeroDivisionError, lambda: 3 / z)

        assert mkvc(z) == 0
        assert sdiag(z) * a == 0
        assert z.T == 0
        assert z.transpose() == 0
    def test_numpy_multiply(self):
        z = Zero()
        x = np.r_[1, 2, 3]
        a = x * z
        assert isinstance(a, Zero)

        z = Zero()
        x = np.r_[1, 2, 3]
        a = z * x
        assert isinstance(a, Zero)
 def test_both(self):
     z = Zero()
     o = Identity()
     assert o * z == 0
     assert o * z + o == 1
     assert o - z == 1
 def test_mat_zero(self):
     z = Zero()
     S = sdiag(np.r_[2, 3])
     assert S * z == 0
示例#5
0
def sdiag(h):
    """Sparse diagonal matrix"""
    if isinstance(h, Zero):
        return Zero()

    return sp.spdiags(mkvc(h), 0, h.size, h.size, format="csr")