<s> from unittest import TestCase <EOL> from nose . plugins . skip import SkipTest <EOL> import numpy <EOL> import theano <EOL> from theano import tensor <EOL> from theano . tests import unittest_tools as utt <EOL> from theano . tensor . blas import gemv_inplace , gemm_inplace , _dot22 <EOL> from theano . tensor . tests . test_blas import TestGer , BaseGemv <EOL> from . . import gpuarray_shared_constructor <EOL> from . config import mode_with_gpu <EOL> from . test_basic_ops import makeTester , rand <EOL> from . . blas import ( gpugemv_inplace , gpugemv_no_inplace , <EOL> gpugemm_inplace , <EOL> gpuger_inplace , gpuger_no_inplace , <EOL> GpuGer , gpu_dot22 , GpuGemm ) <EOL> GpuGemvTester = makeTester ( <EOL> '<STR_LIT>' , <EOL> op = gemv_inplace , gpu_op = gpugemv_inplace , <EOL> cases = dict ( dot_vv = [ rand ( <NUM_LIT:1> ) , <NUM_LIT:1> , rand ( <NUM_LIT:1> , <NUM_LIT:2> ) , rand ( <NUM_LIT:2> ) , <NUM_LIT:0> ] , <EOL> dot_vm = [ rand ( <NUM_LIT:3> ) , <NUM_LIT:1> , rand ( <NUM_LIT:3> , <NUM_LIT:2> ) , rand ( <NUM_LIT:2> ) , <NUM_LIT:0> ] , <EOL> test_stride = [ rand ( <NUM_LIT:3> ) [ : : - <NUM_LIT:1> ] , <NUM_LIT:1> , rand ( <NUM_LIT:3> , <NUM_LIT:2> ) [ : : - <NUM_LIT:1> ] , rand ( <NUM_LIT:2> ) [ : : - <NUM_LIT:1> ] , <NUM_LIT:0> ] , <EOL> ) <EOL> ) <EOL> class TestGpuSgemv ( TestCase , BaseGemv , utt . TestOptimizationMixin ) : <EOL> mode = mode_with_gpu <EOL> dtype = '<STR_LIT>' <EOL> gemv = gpugemv_no_inplace <EOL> gemv_inplace = gpugemv_inplace <EOL> @ staticmethod <EOL> def shared ( val ) : <EOL> try : <EOL> return gpuarray_shared_constructor ( val ) <EOL> except TypeError : <EOL> return theano . shared ( val ) <EOL> GpuGemmTester = makeTester ( <EOL> '<STR_LIT>' , <EOL> op = gemm_inplace , gpu_op = gpugemm_inplace , <EOL> cases = dict ( test1 = [ rand ( <NUM_LIT:3> , <NUM_LIT:4> ) , <NUM_LIT:1.0> , rand ( <NUM_LIT:3> , <NUM_LIT:5> ) , rand ( <NUM_LIT:5> , <NUM_LIT:4> ) , <NUM_LIT:0.0> ] , <EOL> test2 = [ rand ( <NUM_LIT:3> , <NUM_LIT:4> ) , <NUM_LIT:1.0> , rand ( <NUM_LIT:3> , <NUM_LIT:5> ) , rand ( <NUM_LIT:5> , <NUM_LIT:4> ) , <NUM_LIT:1.0> ] , <EOL> test3 = [ rand ( <NUM_LIT:3> , <NUM_LIT:4> ) , <NUM_LIT:1.0> , rand ( <NUM_LIT:3> , <NUM_LIT:5> ) , rand ( <NUM_LIT:5> , <NUM_LIT:4> ) , - <NUM_LIT:1.0> ] , <EOL> test4 = [ rand ( <NUM_LIT:3> , <NUM_LIT:4> ) , <NUM_LIT:0.0> , rand ( <NUM_LIT:3> , <NUM_LIT:5> ) , rand ( <NUM_LIT:5> , <NUM_LIT:4> ) , <NUM_LIT:0.0> ] , <EOL> test5 = [ rand ( <NUM_LIT:3> , <NUM_LIT:4> ) , <NUM_LIT:0.0> , rand ( <NUM_LIT:3> , <NUM_LIT:5> ) , rand ( <NUM_LIT:5> , <NUM_LIT:4> ) , <NUM_LIT> ] , <EOL> test6 = [ rand ( <NUM_LIT:3> , <NUM_LIT:4> ) , <NUM_LIT:0.0> , rand ( <NUM_LIT:3> , <NUM_LIT:5> ) , rand ( <NUM_LIT:5> , <NUM_LIT:4> ) , - <NUM_LIT:1.0> ] , <EOL> test7 = [ rand ( <NUM_LIT:3> , <NUM_LIT:4> ) , - <NUM_LIT:1.0> , rand ( <NUM_LIT:3> , <NUM_LIT:5> ) , rand ( <NUM_LIT:5> , <NUM_LIT:4> ) , <NUM_LIT:0.0> ] , <EOL> test8 = [ rand ( <NUM_LIT:3> , <NUM_LIT:4> ) , - <NUM_LIT:1.0> , rand ( <NUM_LIT:3> , <NUM_LIT:5> ) , rand ( <NUM_LIT:5> , <NUM_LIT:4> ) , <NUM_LIT> ] , <EOL> test9 = [ rand ( <NUM_LIT:3> , <NUM_LIT:4> ) , - <NUM_LIT:1.0> , rand ( <NUM_LIT:3> , <NUM_LIT:5> ) , rand ( <NUM_LIT:5> , <NUM_LIT:4> ) , - <NUM_LIT> ] , <EOL> ) <EOL> ) <EOL> class TestGpuSger ( TestGer ) : <EOL> def setUp ( self ) : <EOL> self . mode = mode_with_gpu <EOL> dtype = self . dtype = '<STR_LIT>' <EOL> self . A = tensor . tensor ( dtype = dtype , broadcastable = ( False , False ) ) <EOL> self . a = tensor . tensor ( dtype = dtype , broadcastable = ( ) ) <EOL> self . x = tensor . tensor ( dtype = dtype , broadcastable = ( False , ) ) <EOL> self . y = tensor . tensor ( dtype = dtype , broadcastable = ( False , ) ) <EOL> self . ger_destructive = gpuger_inplace <EOL> self . ger = gpuger_inplace <EOL> self . gemm = gpugemm_inplace <EOL> def test_f32_0_0 ( self ) : <EOL> raise SkipTest ( '<STR_LIT>' ) <EOL> def test_f32_1_0 ( self ) : <EOL> raise SkipTest ( '<STR_LIT>' ) <EOL> def test_f32_0_1 ( self ) : <EOL> raise SkipTest ( '<STR_LIT>' ) <EOL> class TestGpuSgerNoTransfer ( TestGpuSger ) : <EOL> shared = staticmethod ( gpuarray_shared_constructor ) <EOL> class TestGpuGer_OpContract ( TestCase , utt . T_OpContractMixin ) : <EOL> def setUp ( self ) : <EOL> self . ops = [ gpuger_no_inplace , gpuger_inplace ] <EOL> def clone ( self , op ) : <EOL> return GpuGer ( inplace = op . inplace ) <EOL> GpuDot22Tester = makeTester ( <EOL> '<STR_LIT>' , <EOL> op = _dot22 , gpu_op = gpu_dot22 , <EOL> cases = dict ( <EOL> test1 = [ rand ( <NUM_LIT:3> , <NUM_LIT:4> ) , rand ( <NUM_LIT:4> , <NUM_LIT:5> ) ] , <EOL> test2 = [ rand ( <NUM_LIT:1> , <NUM_LIT:4> ) , rand ( <NUM_LIT:4> , <NUM_LIT:5> ) ] , <EOL> test3 = [ rand ( <NUM_LIT:3> , <NUM_LIT:1> ) , rand ( <NUM_LIT:1> , <NUM_LIT:5> ) ] , <EOL> test4 = [ rand ( <NUM_LIT:3> , <NUM_LIT:4> ) , rand ( <NUM_LIT:4> , <NUM_LIT:1> ) ] , <EOL> ) <EOL> ) <EOL> def test_hgemm_swap ( ) : <EOL> from theano . sandbox . cuda import nvcc_compiler <EOL> if nvcc_compiler . nvcc_version < '<STR_LIT>' : <EOL> raise SkipTest ( "<STR_LIT>" ) <EOL> v = tensor . vector ( dtype = '<STR_LIT>' ) <EOL> m = tensor . matrix ( dtype = '<STR_LIT>' ) <EOL> m2 = tensor . matrix ( dtype = '<STR_LIT>' ) <EOL> m32 = tensor . matrix ( dtype = '<STR_LIT>' ) <EOL> f = theano . function ( [ v , m ] , tensor . dot ( v , m ) , mode = mode_with_gpu ) <EOL> assert len ( [ node for node in f . maker . fgraph . apply_nodes <EOL> if isinstance ( node . op , GpuGemm ) ] ) == <NUM_LIT:0> <EOL> f = theano . function ( [ m32 , m ] , tensor . dot ( m32 , m ) , mode = mode_with_gpu ) <EOL> assert len ( [ node for node in f . maker . fgraph . apply_nodes <EOL> if isinstance ( node . op , GpuGemm ) ] ) == <NUM_LIT:0> <EOL> f = theano . function ( [ m , m2 ] , tensor . dot ( m , m2 ) , mode = mode_with_gpu ) <EOL> assert len ( [ node for node in f . maker . fgraph . apply_nodes <EOL> if isinstance ( node . op , GpuGemm ) ] ) == <NUM_LIT:1> <EOL> v1 = numpy . random . random ( ( <NUM_LIT:3> , <NUM_LIT:4> ) ) . astype ( '<STR_LIT>' ) <EOL> v2 = numpy . random . random ( ( <NUM_LIT:4> , <NUM_LIT:2> ) ) . astype ( '<STR_LIT>' ) <EOL> of = f ( v1 , v2 ) <EOL> on = numpy . dot ( v1 , v2 ) <EOL> utt . assert_allclose ( of , on ) <EOL> def test_hgemm_alpha_output_merge ( ) : <EOL> from theano . sandbox . cuda import nvcc_compiler <EOL> if nvcc_compiler . nvcc_version < '<STR_LIT>' : <EOL> raise SkipTest ( "<STR_LIT>" ) <EOL> m1 = tensor . matrix ( dtype = '<STR_LIT>' ) <EOL> m2 = tensor . matrix ( dtype = '<STR_LIT>' ) <EOL> b = tensor . matrix ( dtype = '<STR_LIT>' ) <EOL> hgemm = numpy . asarray ( <NUM_LIT> , dtype = '<STR_LIT>' ) * ( tensor . dot ( m1 , m2 ) + b ) <EOL> f = theano . function ( [ m1 , m2 , b ] , hgemm , mode = mode_with_gpu ) <EOL> assert len ( f . maker . fgraph . apply_nodes ) == <NUM_LIT:5> </s>
