MCPcopy Index your code
hub / github.com/numpy/numpy / test_basic

Method test_basic

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

Source from the content-addressed store, hash-verified

215
216class TestAlgebra:
217 def test_basic(self):
218 import numpy.linalg as linalg
219
220 A = np.array([[1., 2.], [3., 4.]])
221 mA = matrix(A)
222
223 B = np.identity(2)
224 for i in range(6):
225 assert_(np.allclose((mA ** i).A, B))
226 B = np.dot(B, A)
227
228 Ainv = linalg.inv(A)
229 B = np.identity(2)
230 for i in range(6):
231 assert_(np.allclose((mA ** -i).A, B))
232 B = np.dot(B, Ainv)
233
234 assert_(np.allclose((mA * mA).A, np.dot(A, A)))
235 assert_(np.allclose((mA + mA).A, (A + A)))
236 assert_(np.allclose((3 * mA).A, (3 * A)))
237
238 mA2 = matrix(A)
239 mA2 *= 3
240 assert_(np.allclose(mA2.A, 3 * A))
241
242 def test_pow(self):
243 """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