def cmp(a_shp, b_shp): a = numpy.random.randn(* a_shp).astype(numpy.float32) b = numpy.random.randn(* b_shp).astype(numpy.float32) x = tensor.ftensor3() y = tensor.ftensor3() f = theano.function([x, y], batched_dot(x, y), mode=mode_with_gpu) z0 = numpy.asarray(f(a, b)) ga = cuda_ndarray.CudaNdarray(a) gb = cuda_ndarray.CudaNdarray(b) z1 = numpy.asarray(f(ga, gb)) z_test = numpy.sum( a[:, :, :, None] * b[:, None, :, :], axis=-2) z1 = numpy.asarray(f(ga, gb)) z_test = numpy.sum( a[:, :, :, None] * b[:, None, :, :], axis=-2) unittest_tools.assert_allclose(z0, z_test) unittest_tools.assert_allclose(z1, z_test)
def fail(a_shp, b_shp): a = numpy.random.randn(*a_shp).astype(numpy.float32) b = numpy.random.randn(*b_shp).astype(numpy.float32) x = tensor.ftensor3() y = tensor.ftensor3() f = theano.function([x, y], batched_dot(x, y), mode=mode_with_gpu) z = f(a, b)
def fail(a_shp, b_shp): a=numpy.random.randn(*a_shp).astype(numpy.float32) b=numpy.random.randn(*b_shp).astype(numpy.float32) x=tensor.ftensor3() y=tensor.ftensor3() f=theano.function([x,y], batched_dot(x,y), mode=mode_with_gpu) z = f(a,b)
def get_output(self, train): X = self.get_input(train) output = self.activation(batched_dot(self.W, X.dimshuffle(1, 2, 0)).dimshuffle(2, 0, 1) + self.b) return output