Skip to content

Commit

Permalink
BUG: Be explicit about allowing all integer types in matrix exponenti…
Browse files Browse the repository at this point in the history
…ation

Fixes gh-9506, unsigned exponentiation
  • Loading branch information
eric-wieser committed Aug 6, 2017
1 parent bfe43b2 commit 6a119c9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion numpy/matrixlib/defmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def matrix_power(M, n):
M = asanyarray(M)
if M.ndim != 2 or M.shape[0] != M.shape[1]:
raise ValueError("input must be a square array")
if not issubdtype(type(n), int):
if not issubdtype(type(n), N.integer):
raise TypeError("exponent must be an integer")

from numpy.linalg import inv
Expand Down
6 changes: 6 additions & 0 deletions numpy/matrixlib/tests/test_defmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ def test_pow(self):
assert_array_almost_equal(m4, np.dot(m2, m2))
assert_array_almost_equal(np.dot(mi, m), np.eye(2))

def test_scalar_type_pow(self):
m = matrix([[1, 2], [3, 4]])
for scalar_t in [np.int8, np.uint8]:
two = scalar_t(2)
assert_array_almost_equal(m ** 2, m ** two)

def test_notimplemented(self):
'''Check that 'not implemented' operations produce a failure.'''
A = matrix([[1., 2.],
Expand Down

0 comments on commit 6a119c9

Please sign in to comment.