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

Class TestMatrixPower

numpy/linalg/tests/test_linalg.py:998–1081  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

996
997@pytest.mark.parametrize('dt', [np.dtype(c) for c in '?bBhHiIqQefdgFDGO'])
998class TestMatrixPower:
999
1000 rshft_0 = np.eye(4)
1001 rshft_1 = rshft_0[[3, 0, 1, 2]]
1002 rshft_2 = rshft_0[[2, 3, 0, 1]]
1003 rshft_3 = rshft_0[[1, 2, 3, 0]]
1004 rshft_all = [rshft_0, rshft_1, rshft_2, rshft_3]
1005 noninv = array([[1, 0], [0, 0]])
1006 stacked = np.block([[[rshft_0]]]*2)
1007 #FIXME the 'e' dtype might work in future
1008 dtnoinv = [object, np.dtype('e'), np.dtype('g'), np.dtype('G')]
1009
1010 def test_large_power(self, dt):
1011 rshft = self.rshft_1.astype(dt)
1012 assert_equal(
1013 matrix_power(rshft, 2**100 + 2**10 + 2**5 + 0), self.rshft_0)
1014 assert_equal(
1015 matrix_power(rshft, 2**100 + 2**10 + 2**5 + 1), self.rshft_1)
1016 assert_equal(
1017 matrix_power(rshft, 2**100 + 2**10 + 2**5 + 2), self.rshft_2)
1018 assert_equal(
1019 matrix_power(rshft, 2**100 + 2**10 + 2**5 + 3), self.rshft_3)
1020
1021 def test_power_is_zero(self, dt):
1022 def tz(M):
1023 mz = matrix_power(M, 0)
1024 assert_equal(mz, identity_like_generalized(M))
1025 assert_equal(mz.dtype, M.dtype)
1026
1027 for mat in self.rshft_all:
1028 tz(mat.astype(dt))
1029 if dt != object:
1030 tz(self.stacked.astype(dt))
1031
1032 def test_power_is_one(self, dt):
1033 def tz(mat):
1034 mz = matrix_power(mat, 1)
1035 assert_equal(mz, mat)
1036 assert_equal(mz.dtype, mat.dtype)
1037
1038 for mat in self.rshft_all:
1039 tz(mat.astype(dt))
1040 if dt != object:
1041 tz(self.stacked.astype(dt))
1042
1043 def test_power_is_two(self, dt):
1044 def tz(mat):
1045 mz = matrix_power(mat, 2)
1046 mmul = matmul if mat.dtype != object else dot
1047 assert_equal(mz, mmul(mat, mat))
1048 assert_equal(mz.dtype, mat.dtype)
1049
1050 for mat in self.rshft_all:
1051 tz(mat.astype(dt))
1052 if dt != object:
1053 tz(self.stacked.astype(dt))
1054
1055 def test_power_is_minus_one(self, dt):

Callers

nothing calls this directly

Calls 3

arrayFunction · 0.90
blockMethod · 0.80
dtypeMethod · 0.45

Tested by

no test coverage detected