def wrapped_ndpointer(*args, **kwargs):
"""
Specifies an ndpointer type that wraps numpy.ctypeslib.ndpointer and
allows a value of None to be passed to an argument of that type.
Taken from http://stackoverflow.com/questions/32120178
"""
if sys.version_info < (3,):
if 'flags' in kwargs:
kwargs['flags'] = tuple(
f.encode('ascii') for f in kwargs['flags'])
base = ndpointer(*args, **kwargs)
def from_param(cls, obj):
if obj is None:
return obj
return base.from_param(obj)
return type(base.__name__, (base,),
{'from_param': classmethod(from_param)})
评论列表
文章目录