|
2 | 2 |
|
3 | 3 | """
|
4 | 4 | import functools
|
| 5 | +import operator |
5 | 6 |
|
6 | 7 | from numpy.core.numeric import (
|
7 | 8 | asanyarray, arange, zeros, greater_equal, multiply, ones,
|
@@ -214,6 +215,11 @@ def eye(N, M=None, k=0, dtype=float, order='C', *, like=None):
|
214 | 215 | m = zeros((N, M), dtype=dtype, order=order)
|
215 | 216 | if k >= M:
|
216 | 217 | return m
|
| 218 | + # Ensure M and k are integers, so we don't get any surprise casting |
| 219 | + # results in the expressions `M-k` and `M+1` used below. This avoids |
| 220 | + # a problem with inputs with type (for example) np.uint64. |
| 221 | + M = operator.index(M) |
| 222 | + k = operator.index(k) |
217 | 223 | if k >= 0:
|
218 | 224 | i = k
|
219 | 225 | else:
|
@@ -494,8 +500,8 @@ def triu(m, k=0):
|
494 | 500 | Upper triangle of an array.
|
495 | 501 |
|
496 | 502 | Return a copy of an array with the elements below the `k`-th diagonal
|
497 |
| - zeroed. For arrays with ``ndim`` exceeding 2, `triu` will apply to the final |
498 |
| - two axes. |
| 503 | + zeroed. For arrays with ``ndim`` exceeding 2, `triu` will apply to the |
| 504 | + final two axes. |
499 | 505 |
|
500 | 506 | Please refer to the documentation for `tril` for further details.
|
501 | 507 |
|
@@ -804,7 +810,7 @@ def histogram2d(x, y, bins=10, range=None, normed=None, weights=None,
|
804 | 810 | >>> plt.show()
|
805 | 811 | """
|
806 | 812 | from numpy import histogramdd
|
807 |
| - |
| 813 | + |
808 | 814 | if len(x) != len(y):
|
809 | 815 | raise ValueError('x and y must have the same length.')
|
810 | 816 |
|
|
0 commit comments