#NEWLINE# def test_fast_dot( ) : #NEWLINE# #INDENT# if ( fast_dot is np . dot ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# rng = np . random . RandomState ( 42 ) #NEWLINE# A = rng . random_sample ( [ 2 , 10 ] ) #NEWLINE# B = rng . random_sample ( [ 2 , 10 ] ) #NEWLINE# try : #NEWLINE# #INDENT# linalg . get_blas_funcs ( [ 'gemm' ] ) [ 0 ] #NEWLINE# has_blas = True #NEWLINE# #UNINDENT# except ( AttributeError , ValueError ) : #NEWLINE# #INDENT# has_blas = False #NEWLINE# #UNINDENT# if has_blas : #NEWLINE# #INDENT# for ( dt1 , dt2 ) in [ [ 'f8' , 'f4' ] , [ 'i4' , 'i4' ] ] : #NEWLINE# #INDENT# assert_raises ( ValueError , _fast_dot , A . astype ( dt1 ) , B . astype ( dt2 ) . T ) #NEWLINE# #UNINDENT# E = np . empty ( 0 ) #NEWLINE# assert_raises ( ValueError , _fast_dot , E , E ) #NEWLINE# assert_raises ( ValueError , _fast_dot , A , A [ 0 ] ) #NEWLINE# assert_raises ( ValueError , _fast_dot , A . T , np . array ( [ A , A ] ) ) #NEWLINE# assert_raises ( ValueError , _fast_dot , A , A [ 0 , : ] [ None , : ] ) #NEWLINE# assert_raises ( ValueError , _fast_dot , A , A ) #NEWLINE# #UNINDENT# for dtype in [ 'f8' , 'f4' ] : #NEWLINE# #INDENT# A = A . astype ( dtype ) #NEWLINE# B = B . astype ( dtype ) #NEWLINE# C = np . dot ( A . T , A ) #NEWLINE# C_ = fast_dot ( A . T , A ) #NEWLINE# assert_almost_equal ( C , C_ , decimal = 5 ) #NEWLINE# C = np . dot ( A . T , B ) #NEWLINE# C_ = fast_dot ( A . T , B ) #NEWLINE# assert_almost_equal ( C , C_ , decimal = 5 ) #NEWLINE# C = np . dot ( A , B . T ) #NEWLINE# C_ = fast_dot ( A , B . T ) #NEWLINE# assert_almost_equal ( C , C_ , decimal = 5 ) #NEWLINE# #UNINDENT# A = rng . random_sample ( [ 2 , 2 ] ) #NEWLINE# for dtype in [ 'f8' , 'f4' ] : #NEWLINE# #INDENT# A = A . astype ( dtype ) #NEWLINE# B = B . astype ( dtype ) #NEWLINE# C = np . dot ( A , B ) #NEWLINE# C_ = fast_dot ( A , B ) #NEWLINE# assert_almost_equal ( C , C_ , decimal = 5 ) #NEWLINE# C = np . dot ( A . T , B ) #NEWLINE# C_ = fast_dot ( A . T , B ) #NEWLINE# assert_almost_equal ( C , C_ , decimal = 5 ) #NEWLINE# #UNINDENT# if has_blas : #NEWLINE# #INDENT# for x in [ np . array ( ( [ ( [ d ] * 10 ) ] * 2 ) ) for d in [ np . inf , np . nan ] ] : #NEWLINE# #INDENT# assert_raises ( ValueError , _fast_dot , x , x . T )