<s> from __future__ import absolute_import , print_function , division <EOL> import unittest <EOL> import numpy <EOL> import numpy . linalg <EOL> from numpy . testing import assert_array_almost_equal <EOL> from numpy . testing import dec , assert_array_equal , assert_allclose <EOL> from numpy import inf <EOL> from six . moves import xrange <EOL> import theano <EOL> from theano import tensor , function <EOL> from theano . tensor . basic import _allclose <EOL> from theano . tests . test_rop import break_op <EOL> from theano . tests import unittest_tools as utt <EOL> from theano import config <EOL> from theano . tensor . nlinalg import ( MatrixInverse , <EOL> matrix_inverse , <EOL> MatrixPinv , <EOL> pinv , <EOL> AllocDiag , <EOL> alloc_diag , <EOL> ExtractDiag , <EOL> extract_diag , <EOL> diag , <EOL> trace , <EOL> Det , <EOL> det , <EOL> Eig , <EOL> eig , <EOL> Eigh , <EOL> EighGrad , <EOL> eigh , <EOL> matrix_dot , <EOL> _zero_disconnected , <EOL> qr , <EOL> matrix_power , <EOL> norm , <EOL> svd <EOL> ) <EOL> from nose . plugins . attrib import attr <EOL> from nose . plugins . skip import SkipTest <EOL> from nose . tools import assert_raises <EOL> def test_pseudoinverse_correctness ( ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> d1 = rng . randint ( <NUM_LIT:4> ) + <NUM_LIT:2> <EOL> d2 = rng . randint ( <NUM_LIT:4> ) + <NUM_LIT:2> <EOL> r = rng . randn ( d1 , d2 ) . astype ( theano . config . floatX ) <EOL> x = tensor . matrix ( ) <EOL> xi = pinv ( x ) <EOL> ri = function ( [ x ] , xi ) ( r ) <EOL> assert ri . shape [ <NUM_LIT:0> ] == r . shape [ <NUM_LIT:1> ] <EOL> assert ri . shape [ <NUM_LIT:1> ] == r . shape [ <NUM_LIT:0> ] <EOL> assert ri . dtype == r . dtype <EOL> assert _allclose ( ri , numpy . linalg . pinv ( r ) ) <EOL> class test_MatrixInverse ( utt . InferShapeTester ) : <EOL> def setUp ( self ) : <EOL> super ( test_MatrixInverse , self ) . setUp ( ) <EOL> self . op_class = MatrixInverse <EOL> self . op = matrix_inverse <EOL> self . rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> def test_inverse_correctness ( self ) : <EOL> r = self . rng . randn ( <NUM_LIT:4> , <NUM_LIT:4> ) . astype ( theano . config . floatX ) <EOL> x = tensor . matrix ( ) <EOL> xi = self . op ( x ) <EOL> ri = function ( [ x ] , xi ) ( r ) <EOL> assert ri . shape == r . shape <EOL> assert ri . dtype == r . dtype <EOL> rir = numpy . dot ( ri , r ) <EOL> rri = numpy . dot ( r , ri ) <EOL> assert _allclose ( numpy . identity ( <NUM_LIT:4> ) , rir ) , rir <EOL> assert _allclose ( numpy . identity ( <NUM_LIT:4> ) , rri ) , rri <EOL> def test_infer_shape ( self ) : <EOL> r = self . rng . randn ( <NUM_LIT:4> , <NUM_LIT:4> ) . astype ( theano . config . floatX ) <EOL> x = tensor . matrix ( ) <EOL> xi = self . op ( x ) <EOL> self . _compile_and_check ( [ x ] , [ xi ] , [ r ] , <EOL> self . op_class , warn = False ) <EOL> def test_matrix_dot ( ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> n = rng . randint ( <NUM_LIT:4> ) + <NUM_LIT:2> <EOL> rs = [ ] <EOL> xs = [ ] <EOL> for k in xrange ( n ) : <EOL> rs += [ rng . randn ( <NUM_LIT:4> , <NUM_LIT:4> ) . astype ( theano . config . floatX ) ] <EOL> xs += [ tensor . matrix ( ) ] <EOL> sol = matrix_dot ( * xs ) <EOL> theano_sol = function ( xs , sol ) ( * rs ) <EOL> numpy_sol = rs [ <NUM_LIT:0> ] <EOL> for r in rs [ <NUM_LIT:1> : ] : <EOL> numpy_sol = numpy . dot ( numpy_sol , r ) <EOL> assert _allclose ( numpy_sol , theano_sol ) <EOL> def test_qr_modes ( ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> A = tensor . matrix ( "<STR_LIT:A>" , dtype = theano . config . floatX ) <EOL> a = rng . rand ( <NUM_LIT:4> , <NUM_LIT:4> ) . astype ( theano . config . floatX ) <EOL> f = function ( [ A ] , qr ( A ) ) <EOL> t_qr = f ( a ) <EOL> n_qr = numpy . linalg . qr ( a ) <EOL> assert _allclose ( n_qr , t_qr ) <EOL> for mode in [ "<STR_LIT>" , "<STR_LIT:r>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> f = function ( [ A ] , qr ( A , mode ) ) <EOL> t_qr = f ( a ) <EOL> n_qr = numpy . linalg . qr ( a , mode ) <EOL> if isinstance ( n_qr , ( list , tuple ) ) : <EOL> assert _allclose ( n_qr [ <NUM_LIT:0> ] , t_qr [ <NUM_LIT:0> ] ) <EOL> assert _allclose ( n_qr [ <NUM_LIT:1> ] , t_qr [ <NUM_LIT:1> ] ) <EOL> else : <EOL> assert _allclose ( n_qr , t_qr ) <EOL> try : <EOL> n_qr = numpy . linalg . qr ( a , "<STR_LIT>" ) <EOL> f = function ( [ A ] , qr ( A , "<STR_LIT>" ) ) <EOL> t_qr = f ( a ) <EOL> assert _allclose ( n_qr , t_qr ) <EOL> except TypeError as e : <EOL> assert "<STR_LIT>" in str ( e ) <EOL> def test_svd ( ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> A = tensor . matrix ( "<STR_LIT:A>" , dtype = theano . config . floatX ) <EOL> U , V , T = svd ( A ) <EOL> fn = function ( [ A ] , [ U , V , T ] ) <EOL> a = rng . rand ( <NUM_LIT:4> , <NUM_LIT:4> ) . astype ( theano . config . floatX ) <EOL> n_u , n_v , n_t = numpy . linalg . svd ( a ) <EOL> t_u , t_v , t_t = fn ( a ) <EOL> assert _allclose ( n_u , t_u ) <EOL> assert _allclose ( n_v , t_v ) <EOL> assert _allclose ( n_t , t_t ) <EOL> def test_inverse_singular ( ) : <EOL> singular = numpy . array ( [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] ] + [ [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] ] * <NUM_LIT:2> , <EOL> dtype = theano . config . floatX ) <EOL> a = tensor . matrix ( ) <EOL> f = function ( [ a ] , matrix_inverse ( a ) ) <EOL> try : <EOL> f ( singular ) <EOL> except numpy . linalg . LinAlgError : <EOL> return <EOL> assert False <EOL> def test_inverse_grad ( ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> r = rng . randn ( <NUM_LIT:4> , <NUM_LIT:4> ) <EOL> tensor . verify_grad ( matrix_inverse , [ r ] , rng = numpy . random ) <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> r = rng . randn ( <NUM_LIT:4> , <NUM_LIT:4> ) <EOL> tensor . verify_grad ( matrix_inverse , [ r ] , rng = numpy . random ) <EOL> def test_det ( ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> r = rng . randn ( <NUM_LIT:5> , <NUM_LIT:5> ) . astype ( config . floatX ) <EOL> x = tensor . matrix ( ) <EOL> f = theano . function ( [ x ] , det ( x ) ) <EOL> assert numpy . allclose ( numpy . linalg . det ( r ) , f ( r ) ) <EOL> def test_det_grad ( ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> r = rng . randn ( <NUM_LIT:5> , <NUM_LIT:5> ) . astype ( config . floatX ) <EOL> tensor . verify_grad ( det , [ r ] , rng = numpy . random ) <EOL> def test_det_shape ( ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> r = rng . randn ( <NUM_LIT:5> , <NUM_LIT:5> ) . astype ( config . floatX ) <EOL> x = tensor . matrix ( ) <EOL> f = theano . function ( [ x ] , det ( x ) ) <EOL> f_shape = theano . function ( [ x ] , det ( x ) . shape ) <EOL> assert numpy . all ( f ( r ) . shape == f_shape ( r ) ) <EOL> class test_diag ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , mode = None , shared = tensor . _shared , <EOL> floatX = None , type = tensor . TensorType ) : <EOL> self . mode = mode <EOL> self . shared = shared <EOL> if floatX is None : <EOL> floatX = config . floatX <EOL> self . floatX = floatX <EOL> self . type = type <EOL> super ( test_diag , self ) . __init__ ( name ) <EOL> def test_alloc_diag ( self ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> x = theano . tensor . vector ( ) <EOL> g = alloc_diag ( x ) <EOL> f = theano . function ( [ x ] , g ) <EOL> for shp in [ <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:1> ] : <EOL> m = rng . rand ( shp ) . astype ( self . floatX ) <EOL> v = numpy . diag ( m ) <EOL> r = f ( m ) <EOL> assert ( r == v ) . all ( ) <EOL> xx = theano . tensor . matrix ( ) <EOL> ok = False <EOL> try : <EOL> alloc_diag ( xx ) <EOL> except TypeError : <EOL> ok = True <EOL> assert ok <EOL> f = theano . function ( [ x ] , g . shape ) <EOL> topo = f . maker . fgraph . toposort ( ) <EOL> if config . mode != '<STR_LIT>' : <EOL> assert sum ( [ node . op . __class__ == AllocDiag for node in topo ] ) == <NUM_LIT:0> <EOL> for shp in [ <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:1> ] : <EOL> m = rng . rand ( shp ) . astype ( self . floatX ) <EOL> assert ( f ( m ) == m . shape ) . all ( ) <EOL> def test_alloc_diag_grad ( self ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> x = rng . rand ( <NUM_LIT:5> ) <EOL> tensor . verify_grad ( alloc_diag , [ x ] , rng = rng ) <EOL> def test_diag ( self ) : <EOL> x = theano . tensor . vector ( ) <EOL> y = diag ( x ) <EOL> assert y . owner . op . __class__ == AllocDiag <EOL> x = theano . tensor . matrix ( ) <EOL> y = extract_diag ( x ) <EOL> assert y . owner . op . __class__ == ExtractDiag <EOL> x = theano . tensor . tensor3 ( ) <EOL> ok = False <EOL> try : <EOL> y = extract_diag ( x ) <EOL> except TypeError : <EOL> ok = True <EOL> assert ok <EOL> def test_extract_diag ( self ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> m = rng . rand ( <NUM_LIT:2> , <NUM_LIT:3> ) . astype ( self . floatX ) <EOL> x = self . shared ( m ) <EOL> g = extract_diag ( x ) <EOL> f = theano . function ( [ ] , g ) <EOL> assert [ isinstance ( node . inputs [ <NUM_LIT:0> ] . type , self . type ) <EOL> for node in f . maker . fgraph . toposort ( ) <EOL> if isinstance ( node . op , ExtractDiag ) ] == [ True ] <EOL> for shp in [ ( <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:3> , <NUM_LIT:2> ) , ( <NUM_LIT:3> , <NUM_LIT:3> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ] : <EOL> m = rng . rand ( * shp ) . astype ( self . floatX ) <EOL> x . set_value ( m ) <EOL> v = numpy . diag ( m ) <EOL> r = f ( ) <EOL> assert ( r == v ) . all ( ) <EOL> xx = theano . tensor . vector ( ) <EOL> ok = False <EOL> try : <EOL> extract_diag ( xx ) <EOL> except TypeError : <EOL> ok = True <EOL> assert ok <EOL> f = theano . function ( [ ] , g . shape ) <EOL> topo = f . maker . fgraph . toposort ( ) <EOL> if config . mode != '<STR_LIT>' : <EOL> assert sum ( [ node . op . __class__ == ExtractDiag <EOL> for node in topo ] ) == <NUM_LIT:0> <EOL> for shp in [ ( <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:3> , <NUM_LIT:2> ) , ( <NUM_LIT:3> , <NUM_LIT:3> ) ] : <EOL> m = rng . rand ( * shp ) . astype ( self . floatX ) <EOL> x . set_value ( m ) <EOL> assert f ( ) == min ( shp ) <EOL> def test_extract_diag_grad ( self ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> x = rng . rand ( <NUM_LIT:5> , <NUM_LIT:4> ) . astype ( self . floatX ) <EOL> tensor . verify_grad ( extract_diag , [ x ] , rng = rng ) <EOL> @ attr ( '<STR_LIT>' ) <EOL> def test_extract_diag_empty ( self ) : <EOL> c = self . shared ( numpy . array ( [ [ ] , [ ] ] , self . floatX ) ) <EOL> f = theano . function ( [ ] , extract_diag ( c ) , mode = self . mode ) <EOL> assert [ isinstance ( node . inputs [ <NUM_LIT:0> ] . type , self . type ) <EOL> for node in f . maker . fgraph . toposort ( ) <EOL> if isinstance ( node . op , ExtractDiag ) ] == [ True ] <EOL> def test_trace ( ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> x = theano . tensor . matrix ( ) <EOL> g = trace ( x ) <EOL> f = theano . function ( [ x ] , g ) <EOL> for shp in [ ( <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:3> , <NUM_LIT:2> ) , ( <NUM_LIT:3> , <NUM_LIT:3> ) ] : <EOL> m = rng . rand ( * shp ) . astype ( config . floatX ) <EOL> v = numpy . trace ( m ) <EOL> assert v == f ( m ) <EOL> xx = theano . tensor . vector ( ) <EOL> ok = False <EOL> try : <EOL> trace ( xx ) <EOL> except TypeError : <EOL> ok = True <EOL> assert ok <EOL> class test_Eig ( utt . InferShapeTester ) : <EOL> op_class = Eig <EOL> op = eig <EOL> dtype = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> super ( test_Eig , self ) . setUp ( ) <EOL> self . rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> self . A = theano . tensor . matrix ( dtype = self . dtype ) <EOL> X = numpy . asarray ( self . rng . rand ( <NUM_LIT:5> , <NUM_LIT:5> ) , <EOL> dtype = self . dtype ) <EOL> self . S = X . dot ( X . T ) <EOL> def test_infer_shape ( self ) : <EOL> A = self . A <EOL> S = self . S <EOL> self . _compile_and_check ( [ A ] , <EOL> self . op ( A ) , <EOL> [ S ] , <EOL> self . op_class , <EOL> warn = False ) <EOL> def test_eval ( self ) : <EOL> A = theano . tensor . matrix ( dtype = self . dtype ) <EOL> self . assertEqual ( [ e . eval ( { A : [ [ <NUM_LIT:1> ] ] } ) for e in self . op ( A ) ] , <EOL> [ [ <NUM_LIT:1.0> ] , [ [ <NUM_LIT:1.0> ] ] ] ) <EOL> x = [ [ <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:0> ] ] <EOL> w , v = [ e . eval ( { A : x } ) for e in self . op ( A ) ] <EOL> assert_array_almost_equal ( numpy . dot ( x , v ) , w * v ) <EOL> class test_Eigh ( test_Eig ) : <EOL> op = staticmethod ( eigh ) <EOL> def test_uplo ( self ) : <EOL> S = self . S <EOL> a = theano . tensor . matrix ( dtype = self . dtype ) <EOL> wu , vu = [ out . eval ( { a : S } ) for out in self . op ( a , '<STR_LIT>' ) ] <EOL> wl , vl = [ out . eval ( { a : S } ) for out in self . op ( a , '<STR_LIT:L>' ) ] <EOL> assert_array_almost_equal ( wu , wl ) <EOL> assert_array_almost_equal ( vu * numpy . sign ( vu [ <NUM_LIT:0> , : ] ) , <EOL> vl * numpy . sign ( vl [ <NUM_LIT:0> , : ] ) ) <EOL> def test_grad ( self ) : <EOL> S = self . S <EOL> utt . verify_grad ( lambda x : self . op ( x ) [ <NUM_LIT:0> ] , [ S ] , rng = self . rng ) <EOL> utt . verify_grad ( lambda x : self . op ( x ) [ <NUM_LIT:1> ] , [ S ] , rng = self . rng ) <EOL> utt . verify_grad ( lambda x : self . op ( x , '<STR_LIT>' ) [ <NUM_LIT:0> ] , [ S ] , rng = self . rng ) <EOL> utt . verify_grad ( lambda x : self . op ( x , '<STR_LIT>' ) [ <NUM_LIT:1> ] , [ S ] , rng = self . rng ) <EOL> class test_Eigh_float32 ( test_Eigh ) : <EOL> dtype = '<STR_LIT>' <EOL> @ utt . AttemptManyTimes ( n_attempts = <NUM_LIT:3> , n_req_successes = <NUM_LIT:2> ) <EOL> def test_uplo ( self ) : <EOL> super ( test_Eigh_float32 , self ) . test_uplo ( ) <EOL> @ utt . AttemptManyTimes ( n_attempts = <NUM_LIT:3> , n_req_successes = <NUM_LIT:2> ) <EOL> def test_grad ( self ) : <EOL> super ( test_Eigh_float32 , self ) . test_grad ( ) <EOL> class T_lstsq ( unittest . TestCase ) : <EOL> def test_correct_solution ( self ) : <EOL> x = tensor . lmatrix ( ) <EOL> y = tensor . lmatrix ( ) <EOL> z = tensor . lscalar ( ) <EOL> b = theano . tensor . nlinalg . lstsq ( ) ( x , y , z ) <EOL> f = function ( [ x , y , z ] , b ) <EOL> TestMatrix1 = numpy . asarray ( [ [ <NUM_LIT:2> , <NUM_LIT:1> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ] ) <EOL> TestMatrix2 = numpy . asarray ( [ [ <NUM_LIT> , <NUM_LIT:20> ] , [ <NUM_LIT> , <NUM_LIT:50> ] ] ) <EOL> TestScalar = numpy . asarray ( <NUM_LIT:1> ) <EOL> f = function ( [ x , y , z ] , b ) <EOL> m = f ( TestMatrix1 , TestMatrix2 , TestScalar ) <EOL> self . assertTrue ( numpy . allclose ( TestMatrix2 , numpy . dot ( TestMatrix1 , m [ <NUM_LIT:0> ] ) ) ) <EOL> def test_wrong_coefficient_matrix ( self ) : <EOL> x = tensor . vector ( ) <EOL> y = tensor . vector ( ) <EOL> z = tensor . scalar ( ) <EOL> b = theano . tensor . nlinalg . lstsq ( ) ( x , y , z ) <EOL> f = function ( [ x , y , z ] , b ) <EOL> self . assertRaises ( numpy . linalg . linalg . LinAlgError , f , [ <NUM_LIT:2> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:1> ] , <NUM_LIT:1> ) <EOL> def test_wrong_rcond_dimension ( self ) : <EOL> x = tensor . vector ( ) <EOL> y = tensor . vector ( ) <EOL> z = tensor . vector ( ) <EOL> b = theano . tensor . nlinalg . lstsq ( ) ( x , y , z ) <EOL> f = function ( [ x , y , z ] , b ) <EOL> self . assertRaises ( numpy . linalg . LinAlgError , f , [ <NUM_LIT:2> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:1> ] ) <EOL> class Matrix_power ( unittest . TestCase ) : <EOL> def test_numpy_compare ( self ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> A = tensor . matrix ( "<STR_LIT:A>" , dtype = theano . config . floatX ) <EOL> Q = matrix_power ( A , <NUM_LIT:3> ) <EOL> fn = function ( [ A ] , [ Q ] ) <EOL> a = rng . rand ( <NUM_LIT:4> , <NUM_LIT:4> ) . astype ( theano . config . floatX ) <EOL> n_p = numpy . linalg . matrix_power ( a , <NUM_LIT:3> ) <EOL> t_p = fn ( a ) <EOL> assert numpy . allclose ( n_p , t_p ) <EOL> def test_non_square_matrix ( self ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> A = tensor . matrix ( "<STR_LIT:A>" , dtype = theano . config . floatX ) <EOL> Q = matrix_power ( A , <NUM_LIT:3> ) <EOL> f = function ( [ A ] , [ Q ] ) <EOL> a = rng . rand ( <NUM_LIT:4> , <NUM_LIT:3> ) . astype ( theano . config . floatX ) <EOL> self . assertRaises ( ValueError , f , a ) <EOL> class T_NormTests ( unittest . TestCase ) : <EOL> def test_wrong_type_of_ord_for_vector ( self ) : <EOL> self . assertRaises ( ValueError , norm , [ <NUM_LIT:2> , <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> def test_wrong_type_of_ord_for_matrix ( self ) : <EOL> self . assertRaises ( ValueError , norm , [ [ <NUM_LIT:2> , <NUM_LIT:1> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ] , <NUM_LIT:0> ) <EOL> def test_non_tensorial_input ( self ) : <EOL> self . assertRaises ( ValueError , norm , <NUM_LIT:3> , None ) <EOL> def test_tensor_input ( self ) : <EOL> self . assertRaises ( NotImplementedError , norm , numpy . random . rand ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) , None ) <EOL> def test_numpy_compare ( self ) : <EOL> rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) <EOL> M = tensor . matrix ( "<STR_LIT:A>" , dtype = theano . config . floatX ) <EOL> V = tensor . vector ( "<STR_LIT>" , dtype = theano . config . floatX ) <EOL> a = rng . rand ( <NUM_LIT:4> , <NUM_LIT:4> ) . astype ( theano . config . floatX ) <EOL> b = rng . rand ( <NUM_LIT:4> ) . astype ( theano . config . floatX ) <EOL> A = ( [ None , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> , - <NUM_LIT:1> , None , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:2> , - <NUM_LIT:2> ] , <EOL> [ M , M , M , M , M , M , V , V , V , V , V , V , V , V ] , <EOL> [ a , a , a , a , a , a , b , b , b , b , b , b , b , b ] , <EOL> [ None , '<STR_LIT>' , inf , - inf , <NUM_LIT:1> , - <NUM_LIT:1> , None , inf , - inf , <NUM_LIT:0> , <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:2> , - <NUM_LIT:2> ] ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT> ) : <EOL> f = function ( [ A [ <NUM_LIT:1> ] [ i ] ] , norm ( A [ <NUM_LIT:1> ] [ i ] , A [ <NUM_LIT:0> ] [ i ] ) ) <EOL> t_n = f ( A [ <NUM_LIT:2> ] [ i ] ) <EOL> n_n = numpy . linalg . norm ( A [ <NUM_LIT:2> ] [ i ] , A [ <NUM_LIT:3> ] [ i ] ) <EOL> assert _allclose ( n_n , t_n ) </s>
