def __getstate__(self):
        """
        Support method for pickling. Returns the complete state of this object
        as a dictionary, which is then pickled.

        This state does not include the memmaps' contents. Rather, it includes
        enough info to find the memmap and re-load it from disk in the same
        state.

        Note that pickling a NORB will set its memmaps (self.X and self.y) to
        be read-only. This is to prevent the memmaps from accidentally being
        edited after the save. To make them writeable again, the user must
        explicitly call setflags(write=True) on the memmaps.
        """
        _check_pickling_support()

        result = copy.copy(self.__dict__)

        assert isinstance(self.X, numpy.memmap), ("Expected X to be a memmap, "
                                                  "but it was a %s." %
                                                  str(type(self.X)))
        assert isinstance(self.y, numpy.memmap), ("Expected y to be a memmap, "
                                                  "but it was a %s." %
                                                  str(type(self.y)))

        # We don't want to pickle the memmaps; they're already on disk.
        del result['X']
        del result['y']

        # Replace memmaps with their constructor arguments
        def get_memmap_info(memmap):
            assert isinstance(memmap, numpy.memmap)

            if not isinstance(memmap.filename, str):
                raise ValueError("Expected memmap.filename to be a str; "
                                 "instead got a %s, %s" %
                                 (type(memmap.filename), str(memmap.filename)))

            result = {}

            def get_relative_path(full_path):
                """
                Returns the relative path to the PYLEARN2_DATA_PATH.
                """
                data_dir = string_utils.preprocess('${PYLEARN2_DATA_PATH}')

                if not memmap.filename.startswith(data_dir):
                    raise ValueError("Expected memmap.filename to start with "
                                     "the PYLEARN2_DATA_PATH (%s). Instead it "
                                     "was %s." % (data_dir, memmap.filename))

                return os.path.relpath(full_path, data_dir)

            return {'filename': get_relative_path(memmap.filename),
                    'dtype': memmap.dtype,
                    'shape': memmap.shape,
                    'offset': memmap.offset,
                    # We never want to set mode to w+, even if memmap.mode
                    # is w+. Otherwise we'll overwrite the memmap's contents
                    # when we open it.
                    'mode': 'r+' if ('r+', 'w+') in memmap.mode else 'r'}

        result['X_info'] = get_memmap_info(self.X)
        result['y_info'] = get_memmap_info(self.y)

        # This prevents self.X and self.y from being accidentally written to
        # after the save, thus unexpectedly changing the saved file. If the
        # user really wants to, they can make the memmaps writeable again
        # by calling setflags(write=True) on the memmaps.
        for memmap in (self.X, self.y):
            memmap.flush()
            memmap.setflags(write=False)

        return result
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/datasets/new_norb.py/NORB.__getstate__/swapped operands of `in`