File: utils.py

package info (click to toggle)
theano 1.0.3+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 30,752 kB
  • sloc: python: 141,182; ansic: 9,505; makefile: 259; sh: 214; pascal: 81
file content (19 lines) | stat: -rw-r--r-- 912 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from __future__ import absolute_import, print_function, division
from theano.gof.utils import hash_from_code


def hash_from_sparse(data):
    # We need to hash the shapes as hash_from_code only hashes
    # the data buffer. Otherwise, this will cause problem with shapes like:
    # (1, 0) and (2, 0)
    # We also need to add the dtype to make the distinction between
    # uint32 and int32 of zeros with the same shape.

    # Python hash is not strong, so use sha256 instead. To avoid having a too
    # long hash, I call it again on the contatenation of all parts.
    return hash_from_code(hash_from_code(data.data) +
                          hash_from_code(data.indices) +
                          hash_from_code(data.indptr) +
                          hash_from_code(str(data.shape)) +
                          hash_from_code(str(data.dtype)) +
                          hash_from_code(data.format))