def test_gemm_vector_vector(): a = theano._asarray(numpy.random.rand(5,1), dtype='float32') _a = cuda_ndarray.CudaNdarray(a) b = theano._asarray(numpy.random.rand(1,5), dtype='float32') _b = cuda_ndarray.CudaNdarray(b) _c = cuda_ndarray.dot(_a,_b) assert _c.shape == (5,5) assert numpy.allclose(_c, numpy.dot(a, b)) _c = cuda_ndarray.dot(_b,_a) assert _c.shape == (1,1) assert numpy.allclose(_c, numpy.dot(b, a))
def test_dot(): print >>sys.stdout, 'starting test_dot' utt.seed_rng() rng = numpy.random.RandomState(utt.fetch_seed()) a0 = theano._asarray(rng.randn(4, 7), dtype='float32') a1 = theano._asarray(rng.randn(7, 6), dtype='float32') b0 = cuda_ndarray.CudaNdarray(a0) b1 = cuda_ndarray.CudaNdarray(a1) assert _allclose(numpy.dot(a0, a1), cuda_ndarray.dot(b0, b1)) a1 = theano._asarray(rng.randn(6, 7), dtype='float32') b1 = cuda_ndarray.CudaNdarray(a1) numpy_version = numpy.dot(a0, a1.T) transposed = cuda_ndarray.dimshuffle(b1,(1,0)) cuda_version = cuda_ndarray.dot(b0, transposed) assert _allclose(numpy_version, cuda_version) a1 = theano._asarray(rng.randn(7, 6), dtype='float32') b1 = cuda_ndarray.CudaNdarray(a1) a0 = theano._asarray(rng.randn(7, 4), dtype='float32') b0 = cuda_ndarray.CudaNdarray(a0) assert _allclose(numpy.dot(a0.T, a1), cuda_ndarray.dot(cuda_ndarray.dimshuffle(b0,(1,0)), b1)) a1 = theano._asarray(rng.randn(6, 7), dtype='float32') b1 = cuda_ndarray.CudaNdarray(a1) assert _allclose(numpy.dot(a0.T, a1.T), cuda_ndarray.dot(cuda_ndarray.dimshuffle(b0,(1,0)), cuda_ndarray.dimshuffle(b1,(1,0))))