def test_values_eq_approx(): a = rand_gpuarray(20, dtype="float32") assert GpuArrayType.values_eq_approx(a, a) b = a.copy() b[0] = np.asarray(b[0]) + 1.0 assert not GpuArrayType.values_eq_approx(a, b) b = a.copy() b[0] = -np.asarray(b[0]) assert not GpuArrayType.values_eq_approx(a, b)
def test_rebroadcast(): for dtype in ["float16", "float32"]: a = rand_gpuarray(1, dtype=dtype) g = GpuArrayType(dtype=dtype, broadcastable=(False, ))("g") f = theano.function([g], Rebroadcast((0, True))(g)) assert isinstance(f.maker.fgraph.toposort()[0].op, Rebroadcast) res = f(a) assert GpuArrayType.values_eq(res, a)
def test_deep_copy(): for dtype in ["float16", "float32"]: a = rand_gpuarray(20, dtype=dtype) g = GpuArrayType(dtype=dtype, broadcastable=(False, ))("g") f = theano.function([g], g) assert isinstance(f.maker.fgraph.toposort()[0].op, DeepCopyOp) res = f(a) assert GpuArrayType.values_eq(res, a)
def test_view(): for dtype in ["float16", "float32"]: a = rand_gpuarray(20, dtype=dtype) g = GpuArrayType(dtype=dtype, broadcastable=(False, ))("g") m = theano.compile.get_default_mode().excluding("local_view_op") f = theano.function([g], ViewOp()(g), mode=m) assert isinstance(f.maker.fgraph.toposort()[0].op, ViewOp) res = f(a) assert GpuArrayType.values_eq(res, a)
def rand_cval(self, shp): return rand_gpuarray(*shp, **dict(cls=gpuarray))
def get_gpu_value(self): return rand_gpuarray(*self.shape)
def test_specify_shape(): for dtype in ["float16", "float32"]: a = rand_gpuarray(20, dtype=dtype) g = GpuArrayType(dtype=dtype, broadcastable=(False, ))("g") f = theano.function([g], theano.tensor.specify_shape(g, [20])) f(a)
def test_specify_shape(): for dtype in ("float16", "float32"): a = rand_gpuarray(20, dtype=dtype) g = GpuArrayType(dtype=dtype, broadcastable=(False, ))("g") f = aesara.function([g], specify_shape(g, [20])) f(a)
def rand_cval(self, shp): return rand_gpuarray(*shp, cls=gpuarray)