MCPcopy Create free account
hub / github.com/numpy/numpy / _PyArray_DescrHashImp

Function _PyArray_DescrHashImp

numpy/core/src/multiarray/hashdescr.c:260–297  ·  view source on GitHub ↗

* Return 0 if successful */

Source from the content-addressed store, hash-verified

258 * Return 0 if successful
259 */
260static int _PyArray_DescrHashImp(PyArray_Descr *descr, npy_hash_t *hash)
261{
262 PyObject *l, *tl;
263 int st;
264
265 l = PyList_New(0);
266 if (l == NULL) {
267 return -1;
268 }
269
270 st = _array_descr_walk(descr, l);
271 if (st) {
272 Py_DECREF(l);
273 return -1;
274 }
275
276 /*
277 * Convert the list to tuple and compute the tuple hash using python
278 * builtin function
279 */
280 tl = PyList_AsTuple(l);
281 Py_DECREF(l);
282 if (tl == NULL)
283 return -1;
284
285 *hash = PyObject_Hash(tl);
286 Py_DECREF(tl);
287 if (*hash == -1) {
288 /* XXX: does PyObject_Hash set an exception on failure ? */
289#if 0
290 PyErr_SetString(PyExc_SystemError,
291 "(Hash) Error while hashing final tuple");
292#endif
293 return -1;
294 }
295
296 return 0;
297}
298
299NPY_NO_EXPORT npy_hash_t
300PyArray_DescrHash(PyObject* odescr)

Callers 1

PyArray_DescrHashFunction · 0.85

Calls 1

_array_descr_walkFunction · 0.85

Tested by

no test coverage detected