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

Method test_basic

numpy/matrixlib/tests/test_defmatrix.py:212–235  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

210
211class TestAlgebra:
212 def test_basic(self):
213 import numpy.linalg as linalg
214
215 A = np.array([[1., 2.], [3., 4.]])
216 mA = matrix(A)
217
218 B = np.identity(2)
219 for i in range(6):
220 assert_(np.allclose((mA ** i).A, B))
221 B = np.dot(B, A)
222
223 Ainv = linalg.inv(A)
224 B = np.identity(2)
225 for i in range(6):
226 assert_(np.allclose((mA ** -i).A, B))
227 B = np.dot(B, Ainv)
228
229 assert_(np.allclose((mA * mA).A, np.dot(A, A)))
230 assert_(np.allclose((mA + mA).A, (A + A)))
231 assert_(np.allclose((3*mA).A, (3*A)))
232
233 mA2 = matrix(A)
234 mA2 *= 3
235 assert_(np.allclose(mA2.A, 3*A))
236
237 def test_pow(self):
238 """Test raising a matrix to an integer power works as expected."""

Callers

nothing calls this directly

Calls 4

matrixClass · 0.90
assert_Function · 0.90
identityMethod · 0.80
dotMethod · 0.80

Tested by

no test coverage detected