numpy  2.0.0
src/multiarray/hashdescr.c File Reference
#include <Python.h>
#include <numpy/arrayobject.h>
#include "npy_config.h"
#include "npy_pycompat.h"
#include "hashdescr.h"

Defines

#define PY_SSIZE_T_CLEAN
#define NPY_NO_DEPRECATED_API   NPY_API_VERSION
#define _MULTIARRAYMODULE

Functions

static int _is_array_descr_builtin (PyArray_Descr *descr)
static int _array_descr_walk (PyArray_Descr *descr, PyObject *l)
static int _array_descr_walk_fields (PyObject *names, PyObject *fields, PyObject *l)
static int _array_descr_builtin (PyArray_Descr *descr, PyObject *l)
static char _normalize_byteorder (char byteorder)
static int _array_descr_walk_subarray (PyArray_ArrayDescr *adescr, PyObject *l)
static int _PyArray_DescrHashImp (PyArray_Descr *descr, npy_hash_t *hash)
NPY_NO_EXPORT npy_hash_t PyArray_DescrHash (PyObject *odescr)

Define Documentation

#define NPY_NO_DEPRECATED_API   NPY_API_VERSION

Function Documentation

static int _array_descr_builtin ( PyArray_Descr descr,
PyObject *  l 
) [static]
Add to l all the items which uniquely define a builtin type
For builtin type, hash relies on : kind + byteorder + flags + type_num + elsize + alignment
static int _array_descr_walk ( PyArray_Descr descr,
PyObject *  l 
) [static]
'Root' function to walk into a dtype. May be called recursively
static int _array_descr_walk_fields ( PyObject *  names,
PyObject *  fields,
PyObject *  l 
) [static]
Walk inside the fields and add every item which will be used for hashing into the list l
Return 0 on success
For each field, add the key + descr + offset to l
XXX: are those checks necessary ?
static int _array_descr_walk_subarray ( PyArray_ArrayDescr adescr,
PyObject *  l 
) [static]
Walk into subarray, and add items for hashing in l
Return 0 on success
Add shape and descr itself to the list of object to hash
static int _is_array_descr_builtin ( PyArray_Descr descr) [static]
How does this work ? The hash is computed from a list which contains all the information specific to a type. The hard work is to build the list (_array_descr_walk). The list is built as follows:

System Message: ERROR/3 (<string>, line 4) Unexpected indentation.

<blockquote>

  • If the dtype is builtin (no fields, no subarray), then the list
System Message: WARNING/2 (<string>, line 5) Bullet list ends without a blank line; unexpected unindent.
contains 6 items which uniquely define one dtype (_array_descr_builtin) If the dtype is a compound array, one walk on each field. For each field, we append title, names, offset to the final list used for hashing, and then append the list recursively built for each corresponding dtype (_array_descr_walk_fields) If the dtype is a subarray, one adds the shape tuple to the list, and then append the list recursively built for each corresponding dtype (_array_descr_walk_subarray) </blockquote>
Return true if descr is a builtin type

References _normalize_byteorder(), _PyArray_Descr::alignment, _PyArray_Descr::byteorder, _PyArray_Descr::elsize, _PyArray_Descr::flags, and _PyArray_Descr::kind.

static char _normalize_byteorder ( char  byteorder) [static]
normalize endian character: always return 'I', '<' or '>'

Referenced by _is_array_descr_builtin().

static int _PyArray_DescrHashImp ( PyArray_Descr descr,
npy_hash_t hash 
) [static]
Return 0 if successfull
Convert the list to tuple and compute the tuple hash using python builtin function
XXX: does PyObject_Hash set an exception on failure ?
NPY_NO_EXPORT npy_hash_t PyArray_DescrHash ( PyObject *  odescr)