Skip to content
Snippets Groups Projects
Commit bce254e7 authored by Yichao Yu's avatar Yichao Yu
Browse files

workaround for unhashable pypy dtype

parent 31b8ee0d
No related branches found
No related tags found
No related merge requests found
......@@ -37,7 +37,9 @@ import re
from pyopencl.compyte.dtypes import ( # noqa
get_or_register_dtype, TypeNameNotKnown,
register_dtype, dtype_to_ctype)
register_dtype, dtype_to_ctype,
dtype_hashable as _dtype_hashable,
dtype_to_key as _dtype_to_key)
def _register_types():
......@@ -507,8 +509,15 @@ class _CDeclList:
return result
if _dtype_hashable:
_memoize_match_dtype_to_c_struct = memoize
else:
import json as _json
_memoize_match_dtype_to_c_struct = memoize(
key=lambda device, name, dtype, context=None:
(device, name, _dtype_to_key(dtype), context))
@memoize
@_memoize_match_dtype_to_c_struct
def match_dtype_to_c_struct(device, name, dtype, context=None):
"""Return a tuple `(dtype, c_decl)` such that the C struct declaration
in `c_decl` and the structure :class:`numpy.dtype` instance `dtype`
......@@ -656,8 +665,14 @@ def match_dtype_to_c_struct(device, name, dtype, context=None):
return dtype, c_decl
if _dtype_hashable:
_memoize_dtype_to_c_struct = memoize
else:
import json as _json
_memoize_dtype_to_c_struct = memoize(
key=lambda device, dtype: (device, _dtype_to_key(dtype)))
@memoize
@_memoize_dtype_to_c_struct
def dtype_to_c_struct(device, dtype):
matched_dtype, c_decl = match_dtype_to_c_struct(
device, dtype_to_ctype(dtype), dtype)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment