[Numpy-svn] [numpy/numpy] cca2c1: ENH: cache dtype.__hash__

GitHub noreply at github.com
Sat Apr 4 18:03:41 EDT 2015


  Branch: refs/heads/master
  Home:   https://github.com/numpy/numpy
  Commit: cca2c1a4fecfa5533b5579204c5f28a12c5b078a
      https://github.com/numpy/numpy/commit/cca2c1a4fecfa5533b5579204c5f28a12c5b078a
  Author: Antoine Pitrou <antoine at python.org>
  Date:   2015-04-04 (Sat, 04 Apr 2015)

  Changed paths:
    M doc/release/1.10.0-notes.rst
    M numpy/core/include/numpy/ndarraytypes.h
    M numpy/core/include/numpy/npy_3kcompat.h
    M numpy/core/include/numpy/npy_common.h
    M numpy/core/src/multiarray/arraytypes.c.src
    M numpy/core/src/multiarray/descriptor.c
    M numpy/core/src/multiarray/hashdescr.c
    M numpy/core/tests/test_dtype.py

  Log Message:
  -----------
  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.


  Commit: e05b75880911172ac2ca4a589aeca28c0ac38729
      https://github.com/numpy/numpy/commit/e05b75880911172ac2ca4a589aeca28c0ac38729
  Author: Charles Harris <charlesr.harris at gmail.com>
  Date:   2015-04-04 (Sat, 04 Apr 2015)

  Changed paths:
    M doc/release/1.10.0-notes.rst
    M numpy/core/include/numpy/ndarraytypes.h
    M numpy/core/include/numpy/npy_3kcompat.h
    M numpy/core/include/numpy/npy_common.h
    M numpy/core/src/multiarray/arraytypes.c.src
    M numpy/core/src/multiarray/descriptor.c
    M numpy/core/src/multiarray/hashdescr.c
    M numpy/core/tests/test_dtype.py

  Log Message:
  -----------
  Merge pull request #5343 from pitrou/cache_dtype_hash

Fix #5339: cache dtype.__hash__.


Compare: https://github.com/numpy/numpy/compare/c3cd4bfa5799...e05b75880911


More information about the Numpy-svn mailing list