summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAntoine Pitrou <antoine@python.org>2014-12-03 11:43:28 +0100
committerAntoine Pitrou <antoine@python.org>2015-04-04 18:45:14 +0200
commitcca2c1a4fecfa5533b5579204c5f28a12c5b078a (patch)
treecdad45dbf12ce88fbfdef9dbae343c425c56d01e /doc
parentc3cd4bfa57992bb804f5efc41e93e5354d7dfef3 (diff)
downloadnumpy-cca2c1a4fecfa5533b5579204c5f28a12c5b078a.tar.gz
ENH: cache dtype.__hash__
Computing the type of a dhash can be slow for complex (e.g. structured) dtypes. Hashing dtypes can be useful in some applications, such as when doing type-based dispatching, and speed can be critical in those cases. This enhancement caches the once-computed hash value in the dtype structure, so as to save time on further lookups. The cached value is invalidated in the rare cases where the dtype is mutated. Benchmarks numbers: python3.4 -m timeit -s "import numpy as np; t=np.dtype('uint64')" "hash(t)" * before patch: 1000000 loops, best of 3: 0.498 usec per loop * after patch: 10000000 loops, best of 3: 0.0616 usec per loop python3.4 -m timeit -s "import numpy as np; t=np.dtype([(s, 'f') for s in 'abcdefghij'])" "hash(t)" * before patch: 100000 loops, best of 3: 4.43 usec per loop * after patch: 10000000 loops, best of 3: 0.0603 usec per loop Closes #5339.
Diffstat (limited to 'doc')
-rw-r--r--doc/release/1.10.0-notes.rst3
1 files changed, 3 insertions, 0 deletions
diff --git a/doc/release/1.10.0-notes.rst b/doc/release/1.10.0-notes.rst
index d5cd99203..a7c0e2852 100644
--- a/doc/release/1.10.0-notes.rst
+++ b/doc/release/1.10.0-notes.rst
@@ -61,6 +61,9 @@ C API
The changes to *swapaxes* also apply to the *PyArray_SwapAxes* C function,
which now returns a view in all cases.
+The dtype structure (PyArray_Descr) has a new member at the end to cache
+its hash value. This shouldn't affect any well-written applications.
+
recarray field return types
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Previously the returned types for recarray fields accessed by attribute and by