(self)
| 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 |
nothing calls this directly
no test coverage detected