コード例 #1
0
ファイル: test_io.py プロジェクト: xinfanmeng/Theano
 def test_invalid_modes(self):
     # Modes 'r+', 'r', and 'w+' cannot work with Theano, becausei
     # the output array may be modified inplace, and that should not
     # modify the original file.
     path = Variable(Generic())
     for mmap_mode in ('r+', 'r', 'w+', 'toto'):
         self.assertRaises(ValueError, tensor.load, path, 'int32',
                           (False, ), mmap_mode)
コード例 #2
0
ファイル: test_io.py プロジェクト: xinfanmeng/Theano
 def test0(self):
     path = Variable(Generic())
     # Not specifying mmap_mode defaults to None, and the data is
     # copied into main memory
     x = tensor.load(path, 'int32', (False, ))
     y = x * 2
     fn = function([path], y)
     assert (fn(self.filename) == (self.data * 2)).all()
コード例 #3
0
 def test_memmap(self):
     data = numpy.arange(5, dtype=numpy.int32)
     filename = os.path.join(theano.config.base_compiledir, "_test.npy")
     numpy.save(filename, data)
     path = Variable(Generic())
     x = tensor.load(path, 'int32', (False,), mmap_mode='r+')
     fn = function([path], x)
     assert type(fn(filename)) == numpy.core.memmap
コード例 #4
0
 def test_invalid_modes(self):
     # Modes 'r+', 'r', and 'w+' cannot work with Theano, becausei
     # the output array may be modified inplace, and that should not
     # modify the original file.
     path = Variable(Generic())
     for mmap_mode in ("r+", "r", "w+", "toto"):
         with pytest.raises(ValueError):
             tensor.load(path, "int32", (False, ), mmap_mode)
コード例 #5
0
 def test0(self):
     data = numpy.arange(5, dtype=numpy.int32)
     filename = os.path.join(theano.config.base_compiledir, "_test.npy")
     numpy.save(filename, data)
     path = Variable(Generic())
     x = tensor.load(path, 'int32', (False,))
     y = x*2
     fn = function([path], y)
     assert (fn(filename) == data*2).all()
コード例 #6
0
ファイル: test_io.py プロジェクト: xinfanmeng/Theano
 def test1(self):
     path = Variable(Generic())
     # 'c' means "copy-on-write", which allow the array to be overwritten
     # by an inplace Op in the graph, without modifying the underlying
     # file.
     x = tensor.load(path, 'int32', (False, ), 'c')
     # x ** 2 has been chosen because it will work inplace.
     y = (x**2).sum()
     fn = function([path], y)
     # Call fn() twice, to check that inplace ops do not cause trouble
     assert (fn(self.filename) == (self.data**2).sum()).all()
     assert (fn(self.filename) == (self.data**2).sum()).all()
コード例 #7
0
ファイル: test_io.py プロジェクト: xinfanmeng/Theano
 def test_memmap(self):
     path = Variable(Generic())
     x = tensor.load(path, 'int32', (False, ), mmap_mode='c')
     fn = function([path], x)
     assert type(fn(self.filename)) == numpy.core.memmap