Ejemplo n.º 1
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)
Ejemplo n.º 2
0
 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()
Ejemplo n.º 3
0
 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()
Ejemplo n.º 4
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
Ejemplo n.º 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()
Ejemplo n.º 6
0
 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()
Ejemplo n.º 7
0
 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()
Ejemplo n.º 8
0
 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
Ejemplo n.º 9
0
 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