MCPcopy Create free account
hub / github.com/numpy/numpy / test_vecobject

Method test_vecobject

numpy/core/tests/test_multiarray.py:6596–6627  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

6594 assert_almost_equal(res, tgt, decimal=self.N)
6595
6596 def test_vecobject(self):
6597 class Vec:
6598 def __init__(self, sequence=None):
6599 if sequence is None:
6600 sequence = []
6601 self.array = np.array(sequence)
6602
6603 def __add__(self, other):
6604 out = Vec()
6605 out.array = self.array + other.array
6606 return out
6607
6608 def __sub__(self, other):
6609 out = Vec()
6610 out.array = self.array - other.array
6611 return out
6612
6613 def __mul__(self, other): # with scalar
6614 out = Vec(self.array.copy())
6615 out.array *= other
6616 return out
6617
6618 def __rmul__(self, other):
6619 return self*other
6620
6621 U_non_cont = np.transpose([[1., 1.], [1., 2.]])
6622 U_cont = np.ascontiguousarray(U_non_cont)
6623 x = np.array([Vec([1., 0.]), Vec([0., 1.])])
6624 zeros = np.array([Vec([0., 0.]), Vec([0., 0.])])
6625 zeros_test = np.dot(U_cont, x) - np.dot(U_non_cont, x)
6626 assert_equal(zeros[0].array, zeros_test[0].array)
6627 assert_equal(zeros[1].array, zeros_test[1].array)
6628
6629 def test_dot_2args(self):
6630 from numpy.core.multiarray import dot

Callers

nothing calls this directly

Calls 3

assert_equalFunction · 0.90
VecClass · 0.85
dotMethod · 0.80

Tested by

no test coverage detected