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

Method test_subclasses

numpy/lib/tests/test_function_base.py:1770–1788  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1768 f(x)
1769
1770 def test_subclasses(self):
1771 class subclass(np.ndarray):
1772 pass
1773
1774 m = np.array([[1., 0., 0.],
1775 [0., 0., 1.],
1776 [0., 1., 0.]]).view(subclass)
1777 v = np.array([[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]).view(subclass)
1778 # generalized (gufunc)
1779 matvec = np.vectorize(np.matmul, signature='(m,m),(m)->(m)')
1780 r = matvec(m, v)
1781 assert_equal(type(r), subclass)
1782 assert_equal(r, [[1., 3., 2.], [4., 6., 5.], [7., 9., 8.]])
1783
1784 # element-wise (ufunc)
1785 mult = np.vectorize(lambda x, y: x*y)
1786 r = mult(m, v)
1787 assert_equal(type(r), subclass)
1788 assert_equal(r, m * v)
1789
1790 def test_name(self):
1791 #See gh-23021

Callers

nothing calls this directly

Calls 3

assert_equalFunction · 0.90
multFunction · 0.85
viewMethod · 0.45

Tested by

no test coverage detected