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

Class TestMatrixPower

numpy/linalg/tests/test_linalg.py:1091–1174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1089
1090@pytest.mark.parametrize('dt', [np.dtype(c) for c in '?bBhHiIqQefdgFDGO'])
1091class TestMatrixPower:
1092
1093 rshft_0 = np.eye(4)
1094 rshft_1 = rshft_0[[3, 0, 1, 2]]
1095 rshft_2 = rshft_0[[2, 3, 0, 1]]
1096 rshft_3 = rshft_0[[1, 2, 3, 0]]
1097 rshft_all = [rshft_0, rshft_1, rshft_2, rshft_3]
1098 noninv = array([[1, 0], [0, 0]])
1099 stacked = np.block([[[rshft_0]]] * 2)
1100 # FIXME the 'e' dtype might work in future
1101 dtnoinv = [object, np.dtype('e'), np.dtype('g'), np.dtype('G')]
1102
1103 def test_large_power(self, dt):
1104 rshft = self.rshft_1.astype(dt)
1105 assert_equal(
1106 matrix_power(rshft, 2**100 + 2**10 + 2**5 + 0), self.rshft_0)
1107 assert_equal(
1108 matrix_power(rshft, 2**100 + 2**10 + 2**5 + 1), self.rshft_1)
1109 assert_equal(
1110 matrix_power(rshft, 2**100 + 2**10 + 2**5 + 2), self.rshft_2)
1111 assert_equal(
1112 matrix_power(rshft, 2**100 + 2**10 + 2**5 + 3), self.rshft_3)
1113
1114 def test_power_is_zero(self, dt):
1115 def tz(M):
1116 mz = matrix_power(M, 0)
1117 assert_equal(mz, identity_like_generalized(M))
1118 assert_equal(mz.dtype, M.dtype)
1119
1120 for mat in self.rshft_all:
1121 tz(mat.astype(dt))
1122 if np.dtype(dt).type is not np.object_:
1123 tz(self.stacked.astype(dt))
1124
1125 def test_power_is_one(self, dt):
1126 def tz(mat):
1127 mz = matrix_power(mat, 1)
1128 assert_equal(mz, mat)
1129 assert_equal(mz.dtype, mat.dtype)
1130
1131 for mat in self.rshft_all:
1132 tz(mat.astype(dt))
1133 if np.dtype(dt).type is not np.object_:
1134 tz(self.stacked.astype(dt))
1135
1136 def test_power_is_two(self, dt):
1137 def tz(mat):
1138 mz = matrix_power(mat, 2)
1139 mmul = matmul if mat.dtype != object else dot
1140 assert_equal(mz, mmul(mat, mat))
1141 assert_equal(mz.dtype, mat.dtype)
1142
1143 for mat in self.rshft_all:
1144 tz(mat.astype(dt))
1145 if np.dtype(dt).type is not np.object_:
1146 tz(self.stacked.astype(dt))
1147
1148 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…