diff options
author | Nathaniel J. Smith <njs@pobox.com> | 2012-05-15 22:12:41 +0100 |
---|---|---|
committer | Nathaniel J. Smith <njs@pobox.com> | 2012-05-16 14:11:28 +0100 |
commit | bea52bf307782b2a211b7fcfa6696fad45dae275 (patch) | |
tree | 435834d34ff9dd7a12f5acc62b45cbf77d623453 /numpy/core/numeric.py | |
parent | d403fed2423caec4149937fe48781ac68b21fddb (diff) | |
download | numpy-bea52bf307782b2a211b7fcfa6696fad45dae275.tar.gz |
Transition scheme for allowing PyArray_Diagonal to return a view
PyArray_Diagonal is changed to return a copy of the diagonal (as in
numpy 1.6 and earlier), but with a new (hidden) WARN_ON_WRITE flag
set. Writes to this array (or views thereof) will continue to work as
normal, but the first write will trigger a DeprecationWarning.
We also issue this warning if someone extracts a non-numpy writeable
view of the array (e.g., by accessing the Python-level .data
attribute). There are likely still places where the data buffer is
exposed that I've missed -- review welcome!
New known-fail test: eye() for maskna arrays was only implemented by
exploiting ndarray.diagonal's view-ness, so it is now unimplemented
again, and the corresponding test is marked known-fail.
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r-- | numpy/core/numeric.py | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 9a51229a1..aa7d2c29b 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -1956,9 +1956,8 @@ def identity(n, dtype=None, maskna=False): [ 0., 0., 1.]]) """ - a = zeros((n,n), dtype=dtype, maskna=maskna) - a.diagonal()[...] = 1 - return a + from numpy import eye + return eye(n, dtype=dtype, maskna=maskna) def allclose(a, b, rtol=1.e-5, atol=1.e-8): """ |