# another, and what about __hash__ ? So the unpickled version doesn't # equal the pickled version, and the cmodule cache is not happy with # the situation. The old back-end have this same comment and use the # same mechanism. def GpuArray_unpickler(npa, ctx_name): if config.experimental.unpickle_gpu_on_cpu: # directly return numpy array warnings.warn( "config.experimental.unpickle_gpu_on_cpu is set to True. " "Unpickling GpuArray as numpy.ndarray") return npa elif pygpu: ctx = get_context(ctx_name) return pygpu.gpuarray.array(npa, copy=True, context=ctx) else: raise ImportError("pygpu not found. Cannot unpickle GpuArray") copyreg.constructor(GpuArray_unpickler) def GpuArray_pickler(cnda): ctx_name = _name_for_ctx(cnda.context) return (GpuArray_unpickler, (np.asarray(cnda), ctx_name)) # In case pygpu is not imported. if pygpu is not None: copyreg.pickle(pygpu.gpuarray.GpuArray, GpuArray_pickler, GpuArray_unpickler)
# THIS WORKS But CudaNdarray instances don't compare equal to one # another, and what about __hash__ ? So the unpickled version doesn't # equal the pickled version, and the cmodule cache is not happy with # the situation. def CudaNdarray_unpickler(npa): if (config.experimental.unpickle_gpu_on_cpu and config.device == 'cpu'): # directly return numpy array warnings.warn( "config.experimental.unpickle_gpu_on_cpu is set to True. Unpickling CudaNdarray as numpy.ndarray" ) return npa elif cuda: return cuda.CudaNdarray(npa) else: raise ImportError("Cuda not found. Cannot unpickle CudaNdarray") copyreg.constructor(CudaNdarray_unpickler) def CudaNdarray_pickler(cnda): return (CudaNdarray_unpickler, (numpy.asarray(cnda), )) # In case cuda is not imported. if cuda is not None: copyreg.pickle(cuda.CudaNdarray, CudaNdarray_pickler, CudaNdarray_unpickler)
version=3, ) # THIS WORKS But CudaNdarray instances don't compare equal to one # another, and what about __hash__ ? So the unpickled version doesn't # equal the pickled version, and the cmodule cache is not happy with # the situation. def CudaNdarray_unpickler(npa): if config.experimental.unpickle_gpu_on_cpu: # directly return numpy array warnings.warn("config.experimental.unpickle_gpu_on_cpu is set to True. Unpickling CudaNdarray as numpy.ndarray") return npa elif cuda: return cuda.CudaNdarray(npa) else: raise ImportError("Cuda not found. Cannot unpickle CudaNdarray") copyreg.constructor(CudaNdarray_unpickler) def CudaNdarray_pickler(cnda): return (CudaNdarray_unpickler, (numpy.asarray(cnda),)) # In case cuda is not imported. if cuda is not None: copyreg.pickle(cuda.CudaNdarray, CudaNdarray_pickler, CudaNdarray_unpickler)
# THIS WORKS But GpuArray instances don't compare equal to one # another, and what about __hash__ ? So the unpickled version doesn't # equal the pickled version, and the cmodule cache is not happy with # the situation. The old back-end have this same comment and use the # same mechanism. def GpuArray_unpickler(npa, ctx_name): if config.experimental.unpickle_gpu_on_cpu: # directly return numpy array warnings.warn( "config.experimental.unpickle_gpu_on_cpu is set to True. " "Unpickling GpuArray as numpy.ndarray") return npa elif pygpu: ctx = get_context(ctx_name) return pygpu.gpuarray.array(npa, copy=True, context=ctx) else: raise ImportError("pygpu not found. Cannot unpickle GpuArray") copyreg.constructor(GpuArray_unpickler) def GpuArray_pickler(cnda): ctx_name = _name_for_ctx(cnda.context) return (GpuArray_unpickler, (numpy.asarray(cnda), ctx_name)) # In case pygpu is not imported. if pygpu is not None: copyreg.pickle(pygpu.gpuarray.GpuArray, GpuArray_pickler, GpuArray_unpickler)
if real_func is None: method = lambda: None else: method = getattr(classifier_cls, real_func) if hasattr(method, 'im_self') and getattr(method, 'im_self'): types.MethodType(method, proxy_class) elif not hasattr(method, 'im_self'): method = staticmethod(method) setattr(proxy_class, proxy_func, method) return proxy_class copyreg.constructor(_create_proxy) copyreg.pickle(_dynamic_proxy_class, _dynamic_proxy_class.__reduce__, _create_proxy) class ProxyClassifierFactory(object): def __init__(self, classifier_cls, learn_func=None, predict_func=None, weights_func=None): learn_func, predict_func, weights_func = \ ProxyClassifierFactory.__find_funcs(classifier_cls, learn_func, predict_func, weights_func) self.__proxyclass = _create_proxy( classifier_cls, learn_func, predict_func, weights_func )