#NEWLINE# def _params_allgood( ishape , kshape , mode , subsample = ( 1 , 1 ) , img_stride = ( 1 , 1 ) , kern_stride = ( 1 , 1 ) , version = ( - 1 ) , verbose = 0 , random = True , print_ = None , id = None , rtol = 1e-05 , atol = 1e-08 , nb_iter = 0 , ones = False , compile_kshp = None , theano_mode = None , cls = None ) : #NEWLINE# #INDENT# if ones : #NEWLINE# #INDENT# assert ( not random ) #NEWLINE# npy_img = theano . _asarray ( numpy . ones ( ishape ) , dtype = 'float32' ) #NEWLINE# npy_kern = ( - theano . _asarray ( numpy . ones ( kshape ) , dtype = 'float32' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if random : #NEWLINE# #INDENT# npy_img = theano . _asarray ( ( numpy . random . rand ( * ishape ) + 1 ) , dtype = 'float32' ) #NEWLINE# npy_kern = theano . _asarray ( ( numpy . random . rand ( * kshape ) - 2 ) , dtype = 'float32' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# npy_img = ( theano . _asarray ( numpy . arange ( numpy . prod ( ishape ) ) . reshape ( ishape ) , dtype = 'float32' ) + 1 ) #NEWLINE# npy_kern = ( - ( theano . _asarray ( numpy . arange ( numpy . prod ( kshape ) ) . reshape ( kshape ) , dtype = 'float32' ) + 1 ) ) #NEWLINE# #UNINDENT# #UNINDENT# img = cuda_ndarray . CudaNdarray ( npy_img ) #NEWLINE# kern = cuda_ndarray . CudaNdarray ( npy_kern ) #NEWLINE# if ( img_stride != ( 1 , 1 ) ) : #NEWLINE# #INDENT# img = img [ : , : , : : img_stride [ 0 ] , : : img_stride [ 1 ] ] #NEWLINE# npy_img = npy_img [ : , : , : : img_stride [ 0 ] , : : img_stride [ 1 ] ] #NEWLINE# #UNINDENT# if ( kern_stride != ( 1 , 1 ) ) : #NEWLINE# #INDENT# kern = kern [ : , : , : : kern_stride [ 0 ] , : : kern_stride [ 1 ] ] #NEWLINE# npy_kern = npy_kern [ : , : , : : kern_stride [ 0 ] , : : kern_stride [ 1 ] ] #NEWLINE# #UNINDENT# i = cuda . CudaNdarrayType ( broadcastable = [ ( sh == 1 ) for sh in npy_img . shape ] ) ( ) #NEWLINE# k = cuda . CudaNdarrayType ( broadcastable = [ ( sh == 1 ) for sh in npy_kern . shape ] ) ( ) #NEWLINE# op = theano . sandbox . cuda . blas . GpuConv ( border_mode = mode , subsample = subsample , version = version , verbose = verbose , kshp = compile_kshp ) ( i , k ) #NEWLINE# f = theano . function ( [ i , k ] , op , mode = theano_mode ) #NEWLINE# if ( cls is not None ) : #NEWLINE# #INDENT# assert any ( [ isinstance ( node . op , cls ) for node in f . maker . fgraph . toposort ( ) ] ) , ( 'Cannot find class %r in %r' % ( cls , f . maker . fgraph . toposort ( ) ) ) #NEWLINE# #UNINDENT# t2 = time . time ( ) #NEWLINE# gpuval = f ( img , kern ) #NEWLINE# t3 = time . time ( ) #NEWLINE# for i in range ( nb_iter ) : #NEWLINE# #INDENT# gpuval2 = f ( img , kern ) #NEWLINE# assert ( numpy . asarray ( gpuval ) == numpy . asarray ( gpuval2 ) ) . all ( ) #NEWLINE# #UNINDENT# gpuval = numpy . asarray ( gpuval ) #NEWLINE# t0 = time . time ( ) #NEWLINE# cpuval = py_conv ( npy_img , npy_kern , mode , subsample ) #NEWLINE# t1 = time . time ( ) #NEWLINE# assert ( gpuval . shape == cpuval . shape ) , ( 'shape mismatch' , gpuval . shape , cpuval . shape ) #NEWLINE# assert_allclose ( cpuval , gpuval , rtol = rtol , atol = atol ) #NEWLINE# assert numpy . all ( numpy . isfinite ( gpuval ) ) , gpuval #NEWLINE# assert [ ( ( sh == 1 ) is br ) for ( sh , br ) in zip ( cpuval . shape [ : 2 ] , op . type . broadcastable [ : 2 ] ) ] #NEWLINE# if ( t2 is not None ) : #NEWLINE# #INDENT# if ( mode == 'valid' ) : #NEWLINE# #INDENT# approx_fp = ( ( ( ( cpuval . size * ishape [ 1 ] ) * kshape [ 2 ] ) * kshape [ 3 ] ) * 2 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# approx_fp = ( ( ( ( ( ( ( ishape [ 0 ] * kshape [ 0 ] ) * kshape [ 1 ] ) * kshape [ 2 ] ) * kshape [ 3 ] ) * ishape [ 2 ] ) * ishape [ 3 ] ) * 2 ) #NEWLINE# #UNINDENT# approx_fp /= 1000000.0 #NEWLINE# cpu_mflops = ( approx_fp / ( t1 - t0 ) ) #NEWLINE# gpu_mflops = ( t0 / ( t3 - t2 ) ) #NEWLINE# if ( verbose > 0 ) : #NEWLINE# #INDENT# print ( ( '%15s' % str ( ishape ) ) , ( '%15s' % str ( kshape ) ) , end = ' ' , file = sys . stdout ) #NEWLINE# print ( ( '%12.5f  %7.2f %7.2f %7.1f' % ( approx_fp , cpu_mflops , gpu_mflops , ( ( t1 - t0 ) / ( t2 - t1 ) ) ) ) , file = sys . stdout )