コード例 #1
0
    def setUp(self):
        if self.file_type == 'filename':
            fd, path = tempfile.mkstemp()
            os.close(fd)
            self.file = path
        elif self.file_type == 'bytesio':
            self.file = six.BytesIO()
        else:
            assert False

        # Create and save a link
        child = link.Chain()
        with child.init_scope():
            child.linear = links.Linear(2, 3)
        parent = link.Chain()
        with parent.init_scope():
            parent.linear = links.Linear(3, 2)
            parent.child = child
        npz.save_npz(self.file, parent)
        self.source = parent

        if self.file_type == 'bytesio':
            self.file.seek(0)

        self.npzfile = numpy.load(self.file)
        self.deserializer = npz.NpzDeserializer(self.npzfile, strict=False)
コード例 #2
0
    def setUp(self):
        fd, path = tempfile.mkstemp()
        os.close(fd)
        self.temp_file_path = path
        with open(path, 'wb') as f:
            numpy.savez(f, **{'x': numpy.asarray(10)})

        self.npzfile = numpy.load(path)
        self.deserializer = npz.NpzDeserializer(self.npzfile, strict=False)
コード例 #3
0
    def setUp(self):
        fd, path = tempfile.mkstemp()
        os.close(fd)
        self.temp_file_path = path
        with open(path, 'wb') as f:
            numpy.savez(
                f, **{'x': numpy.asarray(10), 'yy': numpy.empty((2, 3))})

        self.npzfile = numpy.load(path)
        self.deserializer = npz.NpzDeserializer(
            self.npzfile, ignore_names=self.ignore_names)
コード例 #4
0
ファイル: test_npz.py プロジェクト: Teppei-Kanayama/myChainer
    def setUp(self):
        self.data = numpy.random.uniform(-1, 1, (2, 3)).astype(numpy.float32)

        fd, path = tempfile.mkstemp()
        os.close(fd)
        self.temp_file_path = path
        with open(path, 'wb') as f:
            savez = numpy.savez_compressed if self.compress else numpy.savez
            savez(f, **{'x/': None, 'y': self.data, 'z': numpy.asarray(10)})

        self.npzfile = numpy.load(path)
        self.deserializer = npz.NpzDeserializer(self.npzfile)
コード例 #5
0
ファイル: test_npz.py プロジェクト: ysekky/chainer
    def setUp(self):
        fd, path = tempfile.mkstemp()
        os.close(fd)
        self.temp_file_path = path

        child = link.Chain(linear=links.Linear(2, 3))
        parent = link.Chain(linear=links.Linear(3, 2), child=child)
        npz.save_npz(self.temp_file_path, parent)
        self.source = parent

        self.npzfile = numpy.load(path)
        self.deserializer = npz.NpzDeserializer(self.npzfile, strict=False)
コード例 #6
0
    def setUp(self):
        fd, path = tempfile.mkstemp()
        os.close(fd)
        self.temp_file_path = path

        child = link.Chain()
        with child.init_scope():
            child.linear2 = links.Linear(2, 3)
        parent = link.Chain()
        with parent.init_scope():
            parent.linear = links.Linear(3, 2)
            parent.child = child
        npz.save_npz(self.temp_file_path, parent)
        self.source = parent

        self.npzfile = numpy.load(path)
        self.deserializer = npz.NpzDeserializer(self.npzfile,
                                                ignore_names=self.ignore_names)
コード例 #7
0
    def setUp(self):
        self.data = numpy.random.uniform(-1, 1, (2, 3)).astype(numpy.float32)

        fd, path = tempfile.mkstemp()
        os.close(fd)
        self.temp_file_path = path
        with open(path, 'wb') as f:
            savez = numpy.savez_compressed if self.compress else numpy.savez
            savez(
                f, **{
                    'x/': None,
                    'y': self.data,
                    'z': numpy.asarray(10),
                    'zf32': numpy.array(-2**60, dtype=numpy.float32),
                    'zi64': numpy.array(-2**60, dtype=numpy.int64),
                    'w': None
                })

        try:
            self.npzfile = numpy.load(path, allow_pickle=True)
        except TypeError:
            self.npzfile = numpy.load(path)
        self.deserializer = npz.NpzDeserializer(self.npzfile)