def load_build(self): """ This method is called to set the state of a newly created object. We capture it to replace our place-holder objects, NDArrayWrapper, by the array we are interested in. We replace directly in the stack of pickler. """ Unpickler.load_build(self) if isinstance(self.stack[-1], NDArrayWrapper): if self.np is None: raise ImportError('Trying to unpickle an ndarray, ' "but numpy didn't import correctly") nd_array_wrapper = self.stack.pop() if self.np.__version__ >= '1.3': array = self.np.load(self._open_file( nd_array_wrapper.filename), mmap_mode=self.mmap_mode) else: # Numpy does not have mmap_mode before 1.3 array = self.np.load(self._open_file( nd_array_wrapper.filename), mmap_mode=self.mmap_mode) if not nd_array_wrapper.subclass is self.np.ndarray: # We need to reconstruct another subclass new_array = self.np.core.multiarray._reconstruct( nd_array_wrapper.subclass, (0, ), 'b') new_array.__array_prepare__(array) array = new_array self.stack.append(array)
def load_build(self): """ This method is called to set the state of a newly created object. We capture it to replace our place-holder objects, NDArrayWrapper, by the array we are interested in. We replace directly in the stack of pickler. """ Unpickler.load_build(self) if isinstance(self.stack[-1], NDArrayWrapper): if self.np is None: raise ImportError('Trying to unpickle an ndarray, ' "but numpy didn't import correctly") nd_array_wrapper = self.stack.pop() if self.np.__version__ >= '1.3': array = self.np.load( self._open_file(nd_array_wrapper.filename), mmap_mode=self.mmap_mode) else: # Numpy does not have mmap_mode before 1.3 array = self.np.load( self._open_file(nd_array_wrapper.filename), mmap_mode=self.mmap_mode) if not nd_array_wrapper.subclass is self.np.ndarray: # We need to reconstruct another subclass new_array = self.np.core.multiarray._reconstruct( nd_array_wrapper.subclass, (0,), 'b') new_array.__array_prepare__(array) array = new_array self.stack.append(array)
def load_build(self): """ This method is called to set the state of a newly created object. We capture it to replace our place-holder objects, NDArrayWrapper, by the array we are interested in. We replace them directly in the stack of pickler. """ Unpickler.load_build(self) if isinstance(self.stack[-1], NDArrayWrapper): if self.np is None: raise ImportError('Trying to unpickle an ndarray, ' "but numpy didn't import correctly") nd_array_wrapper = self.stack.pop() array = nd_array_wrapper.read(self) self.stack.append(array)
def load_build(self): """ This method is called to set the state of a knewly created object. We capture it to replace our place-holder objects, NDArrayWrapper, by the array we are interested in. We replace directly in the stack of pickler. """ Unpickler.load_build(self) if isinstance(self.stack[-1], NDArrayWrapper): nd_array_wrapper = self.stack.pop() if self.np.__version__ >= '1.3': array = self.np.load(os.path.join(self._dirname, nd_array_wrapper.filename), mmap_mode=self.mmap_mode) else: # Numpy does not have mmap_mode before 1.3 array = self.np.load( os.path.join(self._dirname, nd_array_wrapper.filename)) self.stack.append(array)
def load_build(self): """ This method is called to set the state of a knewly created object. We capture it to replace our place-holder objects, NDArrayWrapper, by the array we are interested in. We replace directly in the stack of pickler. """ Unpickler.load_build(self) if isinstance(self.stack[-1], NDArrayWrapper): nd_array_wrapper = self.stack.pop() if self.np.__version__ >= '1.3': array = self.np.load(os.path.join(self._dirname, nd_array_wrapper.filename), mmap_mode=self.mmap_mode) else: # Numpy does not have mmap_mode before 1.3 array = self.np.load(os.path.join(self._dirname, nd_array_wrapper.filename)) self.stack.append(array)
def load_build(cls, obj): # Just save the instance in the list of objects. if isinstance(obj, NewUnpickler): obj.objects.append(obj.stack[-2]) Unpickler.load_build(obj)