def wrap_namespace(old, new): """ Wraps namespace of array library. """ unchanged_types = {float, int, type(None), type} int_types = { _cp.int, _cp.int8, _cp.int16, _cp.int32, _cp.int64, _cp.integer, } function_types = {_cp.ufunc, types.FunctionType, types.BuiltinFunctionType} for name, obj in old.items(): if obj in notrace_functions: new[name] = notrace_primitive(obj) # Note: type(obj) == _cp.ufunc doesn't work! Should use: # # isinstance(obj, _cp.ufunc) # elif (type(obj) in function_types or isinstance(obj, _cp.ufunc) # or isinstance(obj, _cp.core.fusion.reduction) ): new[name] = primitive(obj) elif type(obj) is type and obj in int_types: new[name] = wrap_intdtype(obj) elif type(obj) in unchanged_types: new[name] = obj
def wrap_namespace(old, new): unchanged_types = {float, int, type(None), type} int_types = {_np.int8, _np.int16, _np.int32, _np.int64, _np.integer} for name, obj in old.items(): if obj in notrace_functions: new[name] = notrace_primitive(obj) elif callable(obj) and type(obj) is not type: new[name] = primitive(obj) elif type(obj) is type and obj in int_types: new[name] = wrap_intdtype(obj) elif type(obj) in unchanged_types: new[name] = obj
def wrap_namespace(old, new): unchanged_types = {float, int, type(None), type} int_types = {_np.int, _np.int8, _np.int16, _np.int32, _np.int64, _np.integer} function_types = {_np.ufunc, types.FunctionType, types.BuiltinFunctionType} for name, obj in old.items(): if obj in notrace_functions: new[name] = notrace_primitive(obj) elif type(obj) in function_types: new[name] = primitive(obj) elif type(obj) is type and obj in int_types: new[name] = wrap_intdtype(obj) elif type(obj) in unchanged_types: new[name] = obj
def wrap_namespace(old, new): unchanged_types = {float, int, type(None), type} int_types = { _np.int, _np.int8, _np.int16, _np.int32, _np.int64, _np.integer } function_types = {_np.ufunc, types.FunctionType, types.BuiltinFunctionType} for name, obj in old.items(): if obj in notrace_functions: # NOTE(brendan): notrace_primitive has to marshal out all of the # values from potentially boxed obj's. new[name] = notrace_primitive(obj) elif type(obj) in function_types: new[name] = primitive(obj) elif type(obj) is type and obj in int_types: new[name] = wrap_intdtype(obj) elif type(obj) in unchanged_types: new[name] = obj
class IntdtypeSubclass(cls): __new__ = notrace_primitive(cls.__new__)