<s> import logging <EOL> import sys <EOL> import unittest <EOL> from nose . plugins . skip import SkipTest <EOL> import numpy <EOL> from six import StringIO <EOL> from six . moves import xrange <EOL> import theano <EOL> from theano . compat import exc_message , izip , PY3 <EOL> from theano . compile import DeepCopyOp <EOL> from theano import config <EOL> from theano import gof <EOL> import theano . scalar as scal <EOL> import theano . tensor as tensor <EOL> from theano . tests import unittest_tools as utt <EOL> from theano . tensor . subtensor import ( inc_subtensor , set_subtensor , <EOL> advanced_inc_subtensor1 , <EOL> advanced_set_subtensor1 , <EOL> advanced_inc_subtensor , <EOL> advanced_set_subtensor , <EOL> Subtensor , IncSubtensor , <EOL> AdvancedSubtensor1 , AdvancedSubtensor , <EOL> advanced_subtensor1 , inplace_increment , <EOL> AdvancedIncSubtensor1 , <EOL> AdvancedIncSubtensor , <EOL> get_canonical_form_slice ) <EOL> from theano . tensor import ( as_tensor_variable , _shared , <EOL> NotScalarConstantError , <EOL> fscalar , iscalar , dscalar , cscalar , <EOL> vector , dvector , fvector , lvector , lrow , <EOL> fmatrix , dmatrix , lmatrix , matrix , <EOL> ctensor3 , dtensor4 ) <EOL> from theano . tensor . tests . test_basic import rand , randint_ranged , inplace_func <EOL> from theano . tests . unittest_tools import attr <EOL> if PY3 : <EOL> def L ( i ) : <EOL> return i <EOL> else : <EOL> def L ( i ) : <EOL> return long ( i ) <EOL> class T_subtensor ( unittest . TestCase , utt . TestOptimizationMixin ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , shared = tensor . _shared , <EOL> sub = tensor . Subtensor , <EOL> inc_sub = tensor . IncSubtensor , <EOL> adv_sub1 = tensor . AdvancedSubtensor1 , <EOL> adv_incsub1 = tensor . AdvancedIncSubtensor1 , <EOL> mode = None , <EOL> dtype = theano . config . floatX , <EOL> type = tensor . TensorType , <EOL> ignore_topo = DeepCopyOp ) : <EOL> self . shared = shared <EOL> self . sub = sub <EOL> self . inc_sub = inc_sub <EOL> self . adv_sub1 = adv_sub1 <EOL> self . adv_incsub1 = adv_incsub1 <EOL> if mode is None : <EOL> mode = theano . compile . mode . get_default_mode ( ) <EOL> self . mode = mode <EOL> self . dtype = dtype <EOL> self . type = type <EOL> self . ignore_topo = ignore_topo <EOL> self . fast_compile = theano . config . mode == '<STR_LIT>' <EOL> self . ops = ( sub , inc_sub , adv_sub1 , adv_incsub1 ) <EOL> return super ( T_subtensor , self ) . __init__ ( name ) <EOL> def function ( self , inputs , outputs , accept_inplace = False , <EOL> op = None , mode = None , N = <NUM_LIT:1> , N_fast = None ) : <EOL> """<STR_LIT>""" <EOL> if self . fast_compile and N_fast is not None : <EOL> N = N_fast <EOL> if mode is None : <EOL> mode = self . mode <EOL> if op is None : <EOL> op = self . sub <EOL> f = theano . function ( inputs , outputs , mode = mode , <EOL> accept_inplace = accept_inplace ) <EOL> self . assertFunctionContainsClassN ( f , op , N ) <EOL> return f <EOL> def setUp ( self ) : <EOL> Subtensor . debug = False <EOL> utt . seed_rng ( ) <EOL> def eval_output_and_check ( self , t , list = False , mode = None ) : <EOL> if mode is None : <EOL> mode = self . mode <EOL> f = inplace_func ( [ ] , t , mode = mode ) <EOL> topo = f . maker . fgraph . toposort ( ) <EOL> topo_ = [ node for node in topo if not isinstance ( node . op , <EOL> self . ignore_topo ) ] <EOL> assert len ( topo_ ) == <NUM_LIT:1> <EOL> if not list : <EOL> assert isinstance ( topo_ [ <NUM_LIT:0> ] . op , self . sub ) <EOL> else : <EOL> assert isinstance ( topo_ [ <NUM_LIT:0> ] . op , self . adv_sub1 ) <EOL> tval = f ( ) <EOL> return tval <EOL> def test0_err_invalid ( self ) : <EOL> n = self . shared ( numpy . ones ( ( ) , dtype = self . dtype ) ) <EOL> try : <EOL> t = n [ <NUM_LIT:0> ] <EOL> except ValueError as e : <EOL> self . assertTrue ( hasattr ( e , '<STR_LIT>' ) ) <EOL> return <EOL> self . fail ( ) <EOL> def test1_err_bounds ( self ) : <EOL> n = self . shared ( numpy . ones ( <NUM_LIT:3> , dtype = self . dtype ) ) <EOL> ctv_backup = config . compute_test_value <EOL> config . compute_test_value = '<STR_LIT>' <EOL> try : <EOL> t = n [ <NUM_LIT:7> ] <EOL> finally : <EOL> config . compute_test_value = ctv_backup <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> _logger = logging . getLogger ( '<STR_LIT>' ) <EOL> oldlevel = _logger . level <EOL> _logger . setLevel ( logging . CRITICAL ) <EOL> try : <EOL> try : <EOL> self . eval_output_and_check ( t ) <EOL> except IndexError as e : <EOL> return <EOL> self . fail ( ) <EOL> finally : <EOL> _logger . setLevel ( oldlevel ) <EOL> def test1_err_subslice ( self ) : <EOL> n = self . shared ( numpy . ones ( <NUM_LIT:3> , dtype = self . dtype ) ) <EOL> try : <EOL> t = n [ slice ( <NUM_LIT:0> , slice ( <NUM_LIT:1> , <NUM_LIT:2> , None ) , None ) ] <EOL> except Exception as e : <EOL> return <EOL> self . fail ( ) <EOL> def test1_ok_range_finite ( self ) : <EOL> n = self . shared ( numpy . arange ( <NUM_LIT:3> , dtype = self . dtype ) ) <EOL> t = n [ <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> tval = self . eval_output_and_check ( t ) <EOL> self . assertTrue ( tval . shape == ( <NUM_LIT:2> , ) ) <EOL> self . assertTrue ( ( tval == [ <NUM_LIT:0> , <NUM_LIT:1> ] ) . all ( ) ) <EOL> def test2_ok_range_finite ( self ) : <EOL> n = self . shared ( numpy . arange ( <NUM_LIT:12> , dtype = self . dtype ) . reshape ( ( <NUM_LIT:3> , <NUM_LIT:4> ) ) ) <EOL> for idx in [ ( slice ( <NUM_LIT:0> , <NUM_LIT:2> ) , <NUM_LIT:3> ) , ( ( slice ( <NUM_LIT:0> , <NUM_LIT:2> ) , - <NUM_LIT:1> ) ) , ( slice ( <NUM_LIT:0> , <NUM_LIT:2> ) , - <NUM_LIT:4> ) ] : <EOL> t = n [ idx ] <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> tval = self . eval_output_and_check ( t ) <EOL> self . assertTrue ( tval . shape == ( <NUM_LIT:2> , ) ) <EOL> self . assertTrue ( numpy . allclose ( tval , n . get_value ( ) [ idx ] ) ) <EOL> def test1_0_dims ( self ) : <EOL> n = self . shared ( numpy . ones ( ( ) , dtype = self . dtype ) ) <EOL> t = self . sub ( [ ] ) ( n ) <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> self . eval_output_and_check ( <EOL> t , mode = self . mode . excluding ( "<STR_LIT>" ) ) <EOL> def test1_err_invalid ( self ) : <EOL> n = self . shared ( numpy . ones ( <NUM_LIT:1> , dtype = self . dtype ) ) <EOL> try : <EOL> t = n [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> except ValueError as e : <EOL> self . assertTrue ( hasattr ( e , '<STR_LIT>' ) ) <EOL> return <EOL> self . fail ( ) <EOL> def test1_ok_elem ( self ) : <EOL> n = self . shared ( numpy . ones ( <NUM_LIT:1> , dtype = self . dtype ) * <NUM_LIT:5> ) <EOL> t = n [ <NUM_LIT:0> ] <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> tval = self . eval_output_and_check ( t ) <EOL> self . assertTrue ( tval . shape == ( ) ) <EOL> self . assertTrue ( tval == <NUM_LIT> ) <EOL> def test1_ok_range_infinite ( self ) : <EOL> n = self . shared ( numpy . arange ( <NUM_LIT:3> , dtype = self . dtype ) ) <EOL> t = n [ <NUM_LIT:1> : ] <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> tval = self . eval_output_and_check ( t ) <EOL> self . assertTrue ( tval . shape == ( <NUM_LIT:2> , ) ) <EOL> self . assertTrue ( ( tval == [ <NUM_LIT:1.0> , <NUM_LIT> ] ) . all ( ) ) <EOL> def test1_ok_strided ( self ) : <EOL> n = self . shared ( numpy . arange ( <NUM_LIT:5> , dtype = self . dtype ) ) <EOL> t = n [ <NUM_LIT:1> : : <NUM_LIT:2> ] <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> tval = self . eval_output_and_check ( t ) <EOL> self . assertTrue ( tval . shape == ( <NUM_LIT:2> , ) ) <EOL> self . assertTrue ( ( tval == [ <NUM_LIT:1.0> , <NUM_LIT> ] ) . all ( ) ) <EOL> t = n [ <NUM_LIT:0> : - <NUM_LIT:1> : <NUM_LIT:2> ] <EOL> tval = self . eval_output_and_check ( t ) <EOL> self . assertTrue ( tval . shape == ( <NUM_LIT:2> , ) ) <EOL> self . assertTrue ( ( tval == [ <NUM_LIT:0.0> , <NUM_LIT> ] ) . all ( ) ) <EOL> def test2_err_bounds0 ( self ) : <EOL> n = self . shared ( numpy . ones ( ( <NUM_LIT:2> , <NUM_LIT:3> ) , dtype = self . dtype ) * <NUM_LIT:5> ) <EOL> ctv_backup = config . compute_test_value <EOL> config . compute_test_value = '<STR_LIT>' <EOL> try : <EOL> for idx in [ ( <NUM_LIT:0> , <NUM_LIT:4> ) , ( <NUM_LIT:0> , - <NUM_LIT:4> ) ] : <EOL> t = n [ idx ] <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> _logger = logging . getLogger ( '<STR_LIT>' ) <EOL> oldlevel = _logger . level <EOL> _logger . setLevel ( logging . CRITICAL ) <EOL> try : <EOL> self . assertRaises ( IndexError , <EOL> self . eval_output_and_check , [ t ] ) <EOL> finally : <EOL> _logger . setLevel ( oldlevel ) <EOL> finally : <EOL> config . compute_test_value = ctv_backup <EOL> def test2_err_bounds1 ( self ) : <EOL> n = self . shared ( ( numpy . ones ( ( <NUM_LIT:2> , <NUM_LIT:3> ) , dtype = self . dtype ) * <NUM_LIT:5> ) ) <EOL> t = n [ <NUM_LIT:4> : <NUM_LIT:5> , <NUM_LIT:3> ] <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> old_stderr = sys . stderr <EOL> sys . stderr = StringIO ( ) <EOL> try : <EOL> self . assertRaises ( IndexError , <EOL> self . eval_output_and_check , [ t ] ) <EOL> finally : <EOL> sys . stderr = old_stderr <EOL> def test2_ok_elem ( self ) : <EOL> n = self . shared ( numpy . arange ( <NUM_LIT:6> , dtype = self . dtype ) . reshape ( ( <NUM_LIT:2> , <NUM_LIT:3> ) ) ) <EOL> t = n [ <NUM_LIT:0> , <NUM_LIT:2> ] <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> tval = self . eval_output_and_check ( t ) <EOL> self . assertTrue ( tval . shape == ( ) ) <EOL> self . assertTrue ( numpy . all ( tval == <NUM_LIT:2> ) ) <EOL> def test2_ok_row ( self ) : <EOL> n = self . shared ( numpy . arange ( <NUM_LIT:6> , dtype = self . dtype ) . reshape ( ( <NUM_LIT:2> , <NUM_LIT:3> ) ) ) <EOL> t = n [ <NUM_LIT:1> ] <EOL> self . assertFalse ( any ( n . type . broadcastable ) ) <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> tval = self . eval_output_and_check ( t ) <EOL> self . assertTrue ( tval . shape == ( <NUM_LIT:3> , ) ) <EOL> self . assertTrue ( numpy . all ( tval == [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) ) <EOL> def test2_ok_col ( self ) : <EOL> n = self . shared ( numpy . arange ( <NUM_LIT:6> , dtype = self . dtype ) . reshape ( ( <NUM_LIT:2> , <NUM_LIT:3> ) ) ) <EOL> t = n [ : , <NUM_LIT:0> ] <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> self . assertFalse ( any ( n . type . broadcastable ) ) <EOL> tval = self . eval_output_and_check ( t ) <EOL> self . assertTrue ( tval . shape == ( <NUM_LIT:2> , ) ) <EOL> self . assertTrue ( numpy . all ( tval == [ <NUM_LIT:0> , <NUM_LIT:3> ] ) ) <EOL> def test2_ok_rows_finite ( self ) : <EOL> n = self . shared ( numpy . arange ( <NUM_LIT:12> , dtype = self . dtype ) . reshape ( ( <NUM_LIT:4> , <NUM_LIT:3> ) ) ) <EOL> t = n [ <NUM_LIT:1> : <NUM_LIT:3> , <NUM_LIT:0> ] <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> tval = self . eval_output_and_check ( t ) <EOL> self . assertTrue ( tval . shape == ( <NUM_LIT:2> , ) ) <EOL> self . assertTrue ( numpy . all ( tval == [ <NUM_LIT:3> , <NUM_LIT:6> ] ) ) <EOL> def test2_ok_cols_infinite ( self ) : <EOL> n = self . shared ( numpy . arange ( <NUM_LIT:12> , dtype = self . dtype ) . reshape ( ( <NUM_LIT:4> , <NUM_LIT:3> ) ) ) <EOL> t = n [ <NUM_LIT:1> , <NUM_LIT:2> : ] <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> tval = self . eval_output_and_check ( t ) <EOL> self . assertTrue ( tval . shape == ( <NUM_LIT:1> , ) ) <EOL> self . assertTrue ( numpy . all ( tval == <NUM_LIT:5> ) ) <EOL> def test2_ok_strided ( self ) : <EOL> n = self . shared ( numpy . arange ( <NUM_LIT:20> , dtype = self . dtype ) . reshape ( ( <NUM_LIT:4> , <NUM_LIT:5> ) ) ) <EOL> t = n [ <NUM_LIT:1> : <NUM_LIT:4> : <NUM_LIT:2> , <NUM_LIT:1> : <NUM_LIT:5> : <NUM_LIT:2> ] <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> tval = self . eval_output_and_check ( t ) <EOL> self . assertTrue ( tval . shape == ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> self . assertTrue ( numpy . all ( tval == [ [ <NUM_LIT:6> , <NUM_LIT:8> ] , [ <NUM_LIT:16> , <NUM_LIT> ] ] ) ) <EOL> def test3_ok_mat ( self ) : <EOL> n = self . shared ( numpy . arange ( <NUM_LIT> , dtype = self . dtype ) . reshape ( ( <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ) ) ) <EOL> t = n [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> tval = self . eval_output_and_check ( t ) <EOL> self . assertTrue ( tval . shape == ( ) ) <EOL> self . assertTrue ( numpy . all ( tval == <NUM_LIT:0> ) ) <EOL> def test_long ( self ) : <EOL> n = self . shared ( numpy . arange ( <NUM_LIT:12> , dtype = self . dtype ) . reshape ( ( <NUM_LIT:4> , <NUM_LIT:3> ) ) ) <EOL> t = n [ L ( <NUM_LIT:1> ) : L ( <NUM_LIT:4> ) : L ( <NUM_LIT:2> ) , L ( <NUM_LIT:1> ) ] <EOL> self . assertTrue ( isinstance ( t . owner . op , Subtensor ) ) <EOL> tval = self . eval_output_and_check ( t ) <EOL> self . assertTrue ( tval . shape == ( <NUM_LIT:2> , ) ) <EOL> self . assertTrue ( numpy . all ( tval == [ <NUM_LIT:4> , <NUM_LIT:10> ] ) ) <EOL> def test_long_too_big ( self ) : <EOL> n = self . shared ( numpy . arange ( <NUM_LIT:12> , dtype = self . dtype ) . reshape ( ( <NUM_LIT:4> , <NUM_LIT:3> ) ) ) <EOL> self . assertRaises ( Exception , lambda : n [ : L ( <NUM_LIT:2> ** <NUM_LIT> ) ] ) <EOL> def test_list_slice ( self ) : <EOL> x = theano . tensor . arange ( <NUM_LIT:100> ) . reshape ( ( <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:4> ) ) <EOL> res = x [ [ slice ( <NUM_LIT:1> , - <NUM_LIT:1> ) ] * x . ndim ] . eval ( ) <EOL> x = numpy . arange ( <NUM_LIT:100> ) . reshape ( ( <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:4> ) ) <EOL> numpy . allclose ( res , x [ [ slice ( <NUM_LIT:1> , - <NUM_LIT:1> ) ] * x . ndim ] ) <EOL> def test_newaxis ( self ) : <EOL> """<STR_LIT>""" <EOL> newaxis = numpy . newaxis <EOL> n = self . shared ( numpy . arange ( <NUM_LIT> , dtype = self . dtype ) . reshape ( ( <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ) ) ) <EOL> assert n . ndim == <NUM_LIT:3> <EOL> n4 = n [ newaxis , : , : , : ] <EOL> assert n4 . broadcastable == ( True , False , False , False ) , n4 <EOL> n4 = n [ : , newaxis , : , : ] <EOL> assert n4 . broadcastable == ( False , True , False , False ) , n4 <EOL> n4 = n [ : , : , newaxis , : ] <EOL> assert n4 . broadcastable == ( False , False , True , False ) , n4 <EOL> n4 = n [ : , : , : , newaxis ] <EOL> assert n4 . broadcastable == ( False , False , False , True ) , n4 <EOL> n3 = n . flatten ( ) [ newaxis , : , newaxis ] <EOL> assert n3 . broadcastable == ( True , False , True ) , n3 <EOL> s = cscalar ( ) <EOL> s1 = s [ newaxis ] <EOL> assert s1 . broadcastable == ( True , ) , s1 <EOL> vs1 , vn3 , vn4 = theano . function ( [ s ] , [ s1 , n3 , n4 ] ) ( - <NUM_LIT> ) <EOL> assert numpy . all ( vs1 == [ - <NUM_LIT> ] ) <EOL> assert numpy . all ( vn3 <EOL> == numpy . arange ( <NUM_LIT> ) [ newaxis , : , newaxis ] ) <EOL> assert numpy . all ( vn4 <EOL> == numpy . arange ( <NUM_LIT> ) . reshape ( ( <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ) ) [ : , : , : , newaxis ] ) <EOL> def test_grad_1d ( self ) : <EOL> subi = <NUM_LIT:0> <EOL> data = numpy . asarray ( rand ( <NUM_LIT:2> , <NUM_LIT:3> ) , dtype = self . dtype ) <EOL> n = self . shared ( data ) <EOL> z = scal . constant ( subi ) <EOL> t = n [ z : , z ] <EOL> gn = theano . tensor . grad ( theano . tensor . sum ( theano . tensor . exp ( t ) ) , n ) <EOL> f = inplace_func ( [ ] , gn , mode = self . mode ) <EOL> topo = f . maker . fgraph . toposort ( ) <EOL> topo_ = [ node for node in topo if not isinstance ( node . op , <EOL> self . ignore_topo ) ] <EOL> if not self . fast_compile : <EOL> assert len ( topo_ ) == <NUM_LIT:6> <EOL> assert numpy . sum ( [ isinstance ( node . op , self . inc_sub ) <EOL> for node in topo_ ] ) == <NUM_LIT:1> <EOL> assert numpy . sum ( [ isinstance ( node . op , self . sub ) <EOL> for node in topo_ ] ) == <NUM_LIT:1> <EOL> gval = f ( ) <EOL> good = numpy . zeros_like ( data ) <EOL> good [ subi : , subi ] = numpy . exp ( data [ subi : , subi ] ) <EOL> self . assertTrue ( numpy . allclose ( gval , good ) , ( gval , good ) ) <EOL> def test_grad_2d_inc_set_subtensor ( self ) : <EOL> for n_shape , m_shape in [ <EOL> [ ( <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:2> , <NUM_LIT:2> ) ] , <EOL> [ ( <NUM_LIT:3> , <NUM_LIT:2> ) , ( <NUM_LIT:2> , <NUM_LIT:2> ) ] , <EOL> [ ( <NUM_LIT:3> , <NUM_LIT:2> ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) ] , <EOL> [ ( <NUM_LIT:3> , <NUM_LIT:2> ) , ( <NUM_LIT:2> , ) ] , <EOL> ] : <EOL> for op in [ inc_subtensor , set_subtensor ] : <EOL> subi = <NUM_LIT:2> <EOL> data = numpy . asarray ( rand ( * n_shape ) , dtype = self . dtype ) <EOL> n = self . shared ( data ) <EOL> z = scal . constant ( subi ) <EOL> m = matrix ( '<STR_LIT:m>' , dtype = self . dtype ) <EOL> mv = numpy . asarray ( rand ( * m_shape ) , dtype = self . dtype ) <EOL> t = op ( n [ : z , : z ] , m ) <EOL> gn , gm = theano . tensor . grad ( theano . tensor . sum ( t ) , [ n , m ] ) <EOL> utt . verify_grad ( lambda m : op ( n [ : z , : z ] , m ) , [ mv ] ) <EOL> utt . verify_grad ( lambda nn : op ( nn [ : z , : z ] , mv ) , [ data ] ) <EOL> def test_grad_0d ( self ) : <EOL> data = numpy . asarray ( rand ( <NUM_LIT:2> , <NUM_LIT:3> ) , dtype = self . dtype ) <EOL> n = self . shared ( data ) <EOL> t = n [ <NUM_LIT:1> , <NUM_LIT:0> ] <EOL> gn = theano . tensor . grad ( theano . tensor . sum ( theano . tensor . exp ( t ) ) , n ) <EOL> f = self . function ( [ ] , gn ) <EOL> topo = f . maker . fgraph . toposort ( ) <EOL> topo_ = [ node for node in topo if not isinstance ( node . op , <EOL> self . ignore_topo ) ] <EOL> if not self . fast_compile : <EOL> assert len ( topo_ ) == <NUM_LIT:6> <EOL> assert numpy . sum ( [ isinstance ( node . op , self . inc_sub ) <EOL> for node in topo_ ] ) == <NUM_LIT:1> <EOL> assert numpy . sum ( [ isinstance ( node . op , self . sub ) <EOL> for node in topo_ ] ) == <NUM_LIT:1> <EOL> gval = f ( ) <EOL> good = numpy . zeros_like ( data ) <EOL> good [ <NUM_LIT:1> , <NUM_LIT:0> ] = numpy . exp ( data [ <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> self . assertTrue ( numpy . allclose ( gval , good ) , ( gval , good ) ) <EOL> def test_ok_list ( self ) : <EOL> for data , idx in [ ( rand ( <NUM_LIT:4> ) , [ <NUM_LIT:1> , <NUM_LIT:0> ] ) , <EOL> ( rand ( <NUM_LIT:4> , <NUM_LIT:5> ) , [ <NUM_LIT:2> , <NUM_LIT:3> , - <NUM_LIT:1> ] ) , <EOL> ( rand ( <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:3> ) , [ <NUM_LIT:0> , <NUM_LIT:3> ] ) , <EOL> ( rand ( <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:3> ) , [ <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:0> ] ) , <EOL> ( rand ( <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:3> ) , [ <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:0> , <EOL> - <NUM_LIT:1> , - <NUM_LIT:2> , - <NUM_LIT:3> , - <NUM_LIT:4> ] ) , <EOL> ( rand ( <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:3> ) , [ <NUM_LIT:3> , <EOL> <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT:1> , - <NUM_LIT:2> , - <NUM_LIT:3> , - <NUM_LIT:4> ] ) , <EOL> ( rand ( <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:3> ) , <EOL> theano . tensor . constant ( [ <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:0> ] ) ) , <EOL> ] : <EOL> data = numpy . asarray ( data , dtype = self . dtype ) <EOL> n = self . shared ( data ) <EOL> t = n [ idx ] <EOL> self . assertTrue ( isinstance ( t . owner . op , tensor . AdvancedSubtensor1 ) ) <EOL> val = self . eval_output_and_check ( t , list = True ) <EOL> if isinstance ( idx , list ) : <EOL> good = data [ idx ] <EOL> else : <EOL> good = data [ idx . data ] <EOL> self . assertTrue ( val . ndim == data . ndim ) <EOL> self . assertTrue ( numpy . allclose ( val , good ) , ( val , good ) ) <EOL> if type ( self . adv_sub1 ) == tensor . AdvancedSubtensor1 : <EOL> op = self . adv_sub1 ( ) <EOL> if hasattr ( idx , "<STR_LIT:data>" ) : <EOL> idx = idx . data <EOL> test_out = [ [ None ] ] <EOL> op . perform ( None , [ data , idx ] , test_out ) <EOL> out1 = test_out [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> op . perform ( None , [ data , idx ] , test_out ) <EOL> out2 = test_out [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> assert out1 is out2 <EOL> gn = theano . grad ( t . sum ( ) , n ) <EOL> g = self . function ( [ ] , gn , op = self . adv_incsub1 ) <EOL> utt . verify_grad ( lambda m : m [ [ <NUM_LIT:1> , <NUM_LIT:3> ] ] , <EOL> [ numpy . random . rand ( <NUM_LIT:5> , <NUM_LIT:5> ) . astype ( self . dtype ) ] ) <EOL> g_0 = g ( ) <EOL> utt . verify_grad ( lambda m : m [ idx ] , <EOL> [ data ] ) <EOL> def test_err_invalid_list ( self ) : <EOL> n = self . shared ( numpy . asarray ( <NUM_LIT:5> , dtype = self . dtype ) ) <EOL> self . assertRaises ( TypeError , n . __getitem__ , [ <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> def test_err_invalid_2list_dtype ( self ) : <EOL> n = self . shared ( numpy . ones ( ( <NUM_LIT:3> , <NUM_LIT:3> ) , dtype = self . dtype ) * <NUM_LIT:5> ) <EOL> self . assertRaises ( TypeError , n . __getitem__ , ( [ <NUM_LIT:0.> , <NUM_LIT:0> ] , [ <NUM_LIT:1> , <NUM_LIT:1> ] ) ) <EOL> def test_err_bound_list ( self ) : <EOL> n = self . shared ( numpy . ones ( ( <NUM_LIT:2> , <NUM_LIT:3> ) , dtype = self . dtype ) * <NUM_LIT:5> ) <EOL> l = lvector ( ) <EOL> t = n [ l ] <EOL> self . assertTrue ( isinstance ( t . owner . op , tensor . AdvancedSubtensor1 ) ) <EOL> f = self . function ( [ l ] , t , op = self . adv_sub1 ) <EOL> g = self . function ( [ l ] , <EOL> inc_subtensor ( t , numpy . asarray ( [ [ <NUM_LIT:1.> ] ] , self . dtype ) ) , <EOL> op = self . adv_incsub1 ) <EOL> for shp in [ [ <NUM_LIT:0> , <NUM_LIT:4> ] , [ <NUM_LIT:0> , - <NUM_LIT:3> ] , [ - <NUM_LIT:10> ] ] : <EOL> self . assertRaises ( IndexError , f , shp ) <EOL> self . assertRaises ( IndexError , g , shp ) <EOL> def test_adv_sub1_broadcast ( self ) : <EOL> v = numpy . arange ( <NUM_LIT:3> , dtype = self . dtype ) . reshape ( ( <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> n = self . shared ( v * <NUM_LIT:5> , broadcastable = ( True , False ) ) <EOL> idx = tensor . lvector ( ) <EOL> t = n [ idx ] <EOL> self . assertTrue ( isinstance ( t . owner . op , tensor . AdvancedSubtensor1 ) ) <EOL> f = self . function ( [ idx ] , t , op = self . adv_sub1 ) <EOL> topo = f . maker . fgraph . toposort ( ) <EOL> topo_ = [ node for node in topo if not isinstance ( node . op , <EOL> self . ignore_topo ) ] <EOL> assert len ( topo_ ) == <NUM_LIT:1> <EOL> self . assertTrue ( isinstance ( topo_ [ <NUM_LIT:0> ] . op , self . adv_sub1 ) ) <EOL> f_0 = f ( [ <NUM_LIT:0> ] ) <EOL> self . assertTrue ( f_0 . shape == ( <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> self . assertTrue ( numpy . allclose ( f_0 , v * <NUM_LIT:5> ) ) <EOL> f_00 = f ( [ <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> self . assertTrue ( f_00 . shape == ( <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> self . assertTrue ( numpy . allclose ( f_00 , v * <NUM_LIT:5> ) ) <EOL> self . assertRaises ( IndexError , f , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> c = t . sum ( ) <EOL> gn = theano . grad ( c , n ) <EOL> g = self . function ( [ idx ] , gn , op = self . adv_incsub1 ) <EOL> g_0 = g ( [ <NUM_LIT:0> ] ) <EOL> self . assertTrue ( g_0 . shape == ( <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> self . assertTrue ( numpy . allclose ( g_0 , <NUM_LIT:1> ) ) <EOL> g_00 = g ( [ <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> self . assertTrue ( g_00 . shape == ( <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> self . assertTrue ( numpy . allclose ( g_00 , <NUM_LIT:2> ) ) <EOL> utt . verify_grad ( lambda m : m [ [ <NUM_LIT:1> , <NUM_LIT:3> ] ] , <EOL> [ numpy . random . rand ( <NUM_LIT:5> , <NUM_LIT:5> ) . astype ( self . dtype ) ] ) <EOL> def fun ( x , y ) : <EOL> return advanced_inc_subtensor1 ( x , y , [ <NUM_LIT:1> , <NUM_LIT:3> ] ) <EOL> utt . verify_grad ( fun , [ numpy . random . rand ( <NUM_LIT:5> , <NUM_LIT:5> ) . astype ( self . dtype ) , <EOL> numpy . random . rand ( <NUM_LIT:2> , <NUM_LIT:5> ) . astype ( self . dtype ) ] ) <EOL> def fun ( x , y ) : <EOL> return advanced_set_subtensor1 ( x , y , [ <NUM_LIT:1> , <NUM_LIT:3> ] ) <EOL> utt . verify_grad ( fun , [ numpy . random . rand ( <NUM_LIT:5> , <NUM_LIT:5> ) . astype ( self . dtype ) , <EOL> numpy . random . rand ( <NUM_LIT:2> , <NUM_LIT:5> ) . astype ( self . dtype ) ] ) <EOL> def test_adv_sub1_idx_broadcast ( self ) : <EOL> ones = numpy . ones ( ( <NUM_LIT:4> , <NUM_LIT:3> ) , dtype = self . dtype ) <EOL> n = self . shared ( ones * <NUM_LIT:5> ) <EOL> idx = tensor . TensorType ( dtype = '<STR_LIT>' , broadcastable = ( True , ) ) ( ) <EOL> assert idx . type . broadcastable == ( True , ) <EOL> t = n [ idx ] <EOL> self . assertTrue ( isinstance ( t . owner . op , tensor . AdvancedSubtensor1 ) ) <EOL> f = self . function ( [ idx ] , t , op = self . adv_sub1 ) <EOL> topo = f . maker . fgraph . toposort ( ) <EOL> topo_ = [ node for node in topo if not isinstance ( node . op , <EOL> self . ignore_topo ) ] <EOL> assert len ( topo_ ) == <NUM_LIT:1> <EOL> self . assertTrue ( isinstance ( topo_ [ <NUM_LIT:0> ] . op , self . adv_sub1 ) ) <EOL> f_0 = f ( [ <NUM_LIT:0> ] ) <EOL> self . assertTrue ( f_0 . shape == ( <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> self . assertTrue ( numpy . allclose ( f_0 , <NUM_LIT:5> ) ) <EOL> c = t . sum ( ) <EOL> gn = theano . grad ( c , n ) <EOL> g = self . function ( [ idx ] , gn , op = self . adv_incsub1 ) <EOL> g_0 = g ( [ <NUM_LIT:0> ] ) <EOL> self . assertTrue ( g_0 . shape == ( <NUM_LIT:4> , <NUM_LIT:3> ) ) <EOL> self . assertTrue ( numpy . allclose ( g_0 [ <NUM_LIT:0> ] , <NUM_LIT:1> ) ) <EOL> self . assertTrue ( numpy . allclose ( g_0 [ <NUM_LIT:1> : ] , <NUM_LIT:0> ) ) <EOL> @ attr ( '<STR_LIT>' ) <EOL> def test_shape_i_const ( self ) : <EOL> mode_opt = self . mode . including ( "<STR_LIT>" ) <EOL> data = self . shared ( numpy . array ( numpy . arange ( <NUM_LIT:5> ) , dtype = self . dtype ) ) <EOL> for start in [ None ] + [ - <NUM_LIT:8> , - <NUM_LIT:5> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:8> ] : <EOL> outs = [ ] <EOL> shapes = [ ] <EOL> for stop in [ None ] + [ - <NUM_LIT:8> , - <NUM_LIT:5> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:8> ] : <EOL> for step in [ None ] + [ - <NUM_LIT:3> , - <NUM_LIT:1> , <NUM_LIT:2> ] : <EOL> outs += [ data [ start : stop : step ] . shape ] <EOL> shapes += [ data . get_value ( <EOL> borrow = True ) [ start : stop : step ] . shape ] <EOL> f = self . function ( [ ] , outs , mode = mode_opt , <EOL> op = self . ops , N = <NUM_LIT:0> ) <EOL> t_shapes = f ( ) <EOL> for t_shape , shape in zip ( t_shapes , shapes ) : <EOL> assert numpy . all ( t_shape == shape ) <EOL> assert tensor . Subtensor not in [ x . op for x in <EOL> f . maker . fgraph . toposort ( ) ] <EOL> def test_shape_i_scalar ( self ) : <EOL> mode_opt = self . mode . including ( "<STR_LIT>" ) <EOL> v_data = numpy . array ( numpy . arange ( <NUM_LIT:5> ) , dtype = self . dtype ) <EOL> t_data = self . shared ( v_data ) <EOL> start = tensor . iscalar ( '<STR_LIT:b>' ) <EOL> stop = tensor . iscalar ( '<STR_LIT:e>' ) <EOL> step = tensor . iscalar ( '<STR_LIT:s>' ) <EOL> f = self . function ( [ start , stop , step ] , <EOL> t_data [ start : stop : step ] . shape , <EOL> mode = mode_opt , <EOL> op = self . ops , <EOL> N = <NUM_LIT:0> ) <EOL> assert tensor . Subtensor not in [ x . op for x in f . maker . <EOL> fgraph . toposort ( ) ] <EOL> for start in [ - <NUM_LIT:8> , - <NUM_LIT:5> , - <NUM_LIT:4> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:8> ] : <EOL> for stop in [ - <NUM_LIT:8> , - <NUM_LIT:5> , - <NUM_LIT:4> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:8> ] : <EOL> for step in [ - <NUM_LIT:3> , - <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:5> ] : <EOL> assert numpy . all ( f ( start , stop , step ) == <EOL> v_data [ start : stop : step ] . shape ) <EOL> def test_slice_canonical_form_0 ( self ) : <EOL> start = tensor . iscalar ( '<STR_LIT:b>' ) <EOL> stop = tensor . iscalar ( '<STR_LIT:e>' ) <EOL> step = tensor . iscalar ( '<STR_LIT:s>' ) <EOL> length = tensor . iscalar ( '<STR_LIT:l>' ) <EOL> cnf = get_canonical_form_slice ( slice ( start , stop , step ) , length ) <EOL> f = self . function ( [ start , stop , step , length ] , [ <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . start ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . stop ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . step ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:1> ] ) ] , N = <NUM_LIT:0> , op = self . ops ) <EOL> length = <NUM_LIT:5> <EOL> a = numpy . arange ( length ) <EOL> for start in [ - <NUM_LIT:8> , - <NUM_LIT:5> , - <NUM_LIT:4> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:8> ] : <EOL> for stop in [ - <NUM_LIT:8> , - <NUM_LIT:5> , - <NUM_LIT:4> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:8> ] : <EOL> for step in [ - <NUM_LIT:6> , - <NUM_LIT:3> , - <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:5> ] : <EOL> out = f ( start , stop , step , length ) <EOL> t_out = a [ out [ <NUM_LIT:0> ] : out [ <NUM_LIT:1> ] : out [ <NUM_LIT:2> ] ] [ : : out [ <NUM_LIT:3> ] ] <EOL> v_out = a [ start : stop : step ] <EOL> assert numpy . all ( t_out == v_out ) <EOL> assert numpy . all ( t_out . shape == v_out . shape ) <EOL> def test_slice_canonical_form_1 ( self ) : <EOL> stop = tensor . iscalar ( '<STR_LIT:e>' ) <EOL> step = tensor . iscalar ( '<STR_LIT:s>' ) <EOL> length = tensor . iscalar ( '<STR_LIT:l>' ) <EOL> cnf = get_canonical_form_slice ( slice ( None , stop , step ) , length ) <EOL> f = self . function ( [ stop , step , length ] , [ <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . start ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . stop ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . step ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:1> ] ) ] , N = <NUM_LIT:0> , op = self . ops ) <EOL> length = <NUM_LIT:5> <EOL> a = numpy . arange ( length ) <EOL> for stop in [ - <NUM_LIT:8> , - <NUM_LIT:5> , - <NUM_LIT:4> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:8> ] : <EOL> for step in [ - <NUM_LIT:6> , - <NUM_LIT:3> , - <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:5> ] : <EOL> out = f ( stop , step , length ) <EOL> t_out = a [ out [ <NUM_LIT:0> ] : out [ <NUM_LIT:1> ] : out [ <NUM_LIT:2> ] ] [ : : out [ <NUM_LIT:3> ] ] <EOL> v_out = a [ : stop : step ] <EOL> assert numpy . all ( t_out == v_out ) <EOL> assert numpy . all ( t_out . shape == v_out . shape ) <EOL> def test_slice_canonical_form_2 ( self ) : <EOL> start = tensor . iscalar ( '<STR_LIT:b>' ) <EOL> step = tensor . iscalar ( '<STR_LIT:s>' ) <EOL> length = tensor . iscalar ( '<STR_LIT:l>' ) <EOL> cnf = get_canonical_form_slice ( slice ( start , None , step ) , length ) <EOL> f = self . function ( [ start , step , length ] , [ <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . start ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . stop ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . step ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:1> ] ) ] , N = <NUM_LIT:0> , op = self . ops ) <EOL> length = <NUM_LIT:5> <EOL> a = numpy . arange ( length ) <EOL> for start in [ - <NUM_LIT:8> , - <NUM_LIT:5> , - <NUM_LIT:4> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:8> ] : <EOL> for step in [ - <NUM_LIT:6> , - <NUM_LIT:3> , - <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:5> ] : <EOL> out = f ( start , step , length ) <EOL> t_out = a [ out [ <NUM_LIT:0> ] : out [ <NUM_LIT:1> ] : out [ <NUM_LIT:2> ] ] [ : : out [ <NUM_LIT:3> ] ] <EOL> v_out = a [ start : None : step ] <EOL> assert numpy . all ( t_out == v_out ) <EOL> assert numpy . all ( t_out . shape == v_out . shape ) <EOL> def test_slice_canonical_form_3 ( self ) : <EOL> start = tensor . iscalar ( '<STR_LIT:b>' ) <EOL> stop = tensor . iscalar ( '<STR_LIT:e>' ) <EOL> length = tensor . iscalar ( '<STR_LIT:l>' ) <EOL> cnf = get_canonical_form_slice ( slice ( start , stop , None ) , length ) <EOL> f = self . function ( [ start , stop , length ] , [ <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . start ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . stop ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . step ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:1> ] ) ] , N = <NUM_LIT:0> , op = self . ops ) <EOL> length = <NUM_LIT:5> <EOL> a = numpy . arange ( length ) <EOL> for start in [ - <NUM_LIT:8> , - <NUM_LIT:5> , - <NUM_LIT:4> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:8> ] : <EOL> for stop in [ - <NUM_LIT:8> , - <NUM_LIT:5> , - <NUM_LIT:4> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:8> ] : <EOL> out = f ( start , stop , length ) <EOL> t_out = a [ out [ <NUM_LIT:0> ] : out [ <NUM_LIT:1> ] : out [ <NUM_LIT:2> ] ] [ : : out [ <NUM_LIT:3> ] ] <EOL> v_out = a [ start : stop : None ] <EOL> assert numpy . all ( t_out == v_out ) <EOL> assert numpy . all ( t_out . shape == v_out . shape ) <EOL> def test_slice_canonical_form_4 ( self ) : <EOL> step = tensor . iscalar ( '<STR_LIT:s>' ) <EOL> length = tensor . iscalar ( '<STR_LIT:l>' ) <EOL> cnf = get_canonical_form_slice ( slice ( None , None , step ) , length ) <EOL> f = self . function ( [ step , length ] , [ <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . start ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . stop ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . step ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:1> ] ) ] , N = <NUM_LIT:0> , op = self . ops ) <EOL> length = <NUM_LIT:5> <EOL> a = numpy . arange ( length ) <EOL> for step in [ - <NUM_LIT:6> , - <NUM_LIT:3> , - <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:5> ] : <EOL> out = f ( step , length ) <EOL> t_out = a [ out [ <NUM_LIT:0> ] : out [ <NUM_LIT:1> ] : out [ <NUM_LIT:2> ] ] [ : : out [ <NUM_LIT:3> ] ] <EOL> v_out = a [ None : None : step ] <EOL> assert numpy . all ( t_out == v_out ) <EOL> assert numpy . all ( t_out . shape == v_out . shape ) <EOL> def test_slice_canonical_form_5 ( self ) : <EOL> start = tensor . iscalar ( '<STR_LIT:b>' ) <EOL> length = tensor . iscalar ( '<STR_LIT:l>' ) <EOL> cnf = get_canonical_form_slice ( slice ( start , None , None ) , length ) <EOL> f = self . function ( [ start , length ] , [ <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . start ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . stop ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . step ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:1> ] ) ] , N = <NUM_LIT:0> , op = self . ops ) <EOL> length = <NUM_LIT:5> <EOL> a = numpy . arange ( length ) <EOL> for start in [ - <NUM_LIT:8> , - <NUM_LIT:5> , - <NUM_LIT:4> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:8> ] : <EOL> out = f ( start , length ) <EOL> t_out = a [ out [ <NUM_LIT:0> ] : out [ <NUM_LIT:1> ] : out [ <NUM_LIT:2> ] ] [ : : out [ <NUM_LIT:3> ] ] <EOL> v_out = a [ start : None : None ] <EOL> assert numpy . all ( t_out == v_out ) <EOL> assert numpy . all ( t_out . shape == v_out . shape ) <EOL> def test_slice_canonical_form_6 ( self ) : <EOL> stop = tensor . iscalar ( '<STR_LIT:e>' ) <EOL> length = tensor . iscalar ( '<STR_LIT:l>' ) <EOL> cnf = get_canonical_form_slice ( slice ( None , stop , None ) , length ) <EOL> f = self . function ( [ stop , length ] , [ <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . start ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . stop ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:0> ] . step ) , <EOL> tensor . as_tensor_variable ( cnf [ <NUM_LIT:1> ] ) ] , N = <NUM_LIT:0> , op = self . ops ) <EOL> length = <NUM_LIT:5> <EOL> a = numpy . arange ( length ) <EOL> for stop in [ - <NUM_LIT:8> , - <NUM_LIT:5> , - <NUM_LIT:4> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:8> ] : <EOL> out = f ( stop , length ) <EOL> t_out = a [ out [ <NUM_LIT:0> ] : out [ <NUM_LIT:1> ] : out [ <NUM_LIT:2> ] ] [ : : out [ <NUM_LIT:3> ] ] <EOL> v_out = a [ None : stop : None ] <EOL> assert numpy . all ( t_out == v_out ) <EOL> assert numpy . all ( t_out . shape == v_out . shape ) <EOL> def grad_list_ ( self , idxs , data ) : <EOL> n = self . shared ( data ) <EOL> for idx in idxs : <EOL> idx_ = _shared ( numpy . asarray ( idx ) ) <EOL> t = n [ idx_ ] <EOL> gn = theano . tensor . grad ( theano . tensor . sum ( theano . tensor . exp ( t ) ) , n ) <EOL> f = self . function ( [ ] , [ gn , gn . shape ] , op = self . adv_incsub1 ) <EOL> topo = f . maker . fgraph . toposort ( ) <EOL> if not self . fast_compile : <EOL> assert any ( [ isinstance ( node . op , self . <EOL> adv_incsub1 ) and node . op . inplace for node in topo ] ) <EOL> else : <EOL> assert any ( [ isinstance ( node . op , self . <EOL> adv_incsub1 ) for node in topo ] ) <EOL> assert any ( [ isinstance ( node . op , self . adv_sub1 ) for node in topo ] ) <EOL> gval , gshape = f ( ) <EOL> good = numpy . zeros_like ( data ) <EOL> for i in idx : <EOL> good [ i ] += numpy . exp ( data [ i ] ) <EOL> self . assertTrue ( gval . ndim == data . ndim ) <EOL> self . assertTrue ( numpy . allclose ( gval , good ) , ( gval , good ) ) <EOL> self . assertTrue ( numpy . allclose ( gshape , data . shape ) ) <EOL> def fct ( t ) : <EOL> return theano . tensor . sum ( t [ idx_ ] ) <EOL> utt . verify_grad ( fct , [ data ] ) <EOL> def fct2 ( t ) : <EOL> return theano . tensor . grad ( theano . tensor . sum ( t [ idx_ ] ) , t ) <EOL> utt . verify_grad ( fct2 , [ data ] ) <EOL> if not self . fast_compile : <EOL> ops = ( self . adv_incsub1 , self . adv_sub1 ) <EOL> else : <EOL> ops = self . ops <EOL> if idx is idxs [ <NUM_LIT:0> ] : <EOL> f = self . function ( [ ] , [ gn . shape , n [ idx_ ] . shape ] , <EOL> op = ops , <EOL> N = <NUM_LIT:0> , N_fast = <NUM_LIT:2> ) <EOL> f ( ) <EOL> def test_wrong_exception_regression ( self ) : <EOL> a = fscalar ( ) <EOL> b = fscalar ( ) <EOL> c = vector ( ) <EOL> try : <EOL> c [ a : b ] <EOL> except NotImplementedError : <EOL> self . fail ( ) <EOL> except TypeError : <EOL> pass <EOL> try : <EOL> c [ a : ] <EOL> except NotImplementedError : <EOL> self . fail ( ) <EOL> except TypeError : <EOL> pass <EOL> try : <EOL> c [ : b ] <EOL> except NotImplementedError : <EOL> self . fail ( ) <EOL> except TypeError : <EOL> pass <EOL> @ attr ( '<STR_LIT>' ) <EOL> def test_grad_list ( self ) : <EOL> data = rand ( <NUM_LIT:4> ) <EOL> data = numpy . asarray ( data , dtype = self . dtype ) <EOL> idxs = [ [ i ] for i in range ( data . shape [ <NUM_LIT:0> ] ) ] <EOL> for i in range ( data . shape [ <NUM_LIT:0> ] ) : <EOL> for j in range ( <NUM_LIT:0> , data . shape [ <NUM_LIT:0> ] , <NUM_LIT:2> ) : <EOL> idxs . append ( [ i , j , ( i + <NUM_LIT:1> ) % data . shape [ <NUM_LIT:0> ] ] ) <EOL> self . grad_list_ ( idxs , data ) <EOL> data = rand ( <NUM_LIT:4> , <NUM_LIT:3> ) <EOL> data = numpy . asarray ( data , dtype = self . dtype ) <EOL> self . grad_list_ ( idxs , data ) <EOL> data = rand ( <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:2> ) <EOL> data = numpy . asarray ( data , dtype = self . dtype ) <EOL> self . grad_list_ ( idxs , data ) <EOL> def test_shape_list ( self ) : <EOL> for data , idx in [ ( rand ( <NUM_LIT:4> ) , [ <NUM_LIT:1> , <NUM_LIT:0> ] ) , <EOL> ( rand ( <NUM_LIT:4> , <NUM_LIT:2> ) , [ <NUM_LIT:2> , <NUM_LIT:3> ] ) , <EOL> ( rand ( <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:3> ) , [ <NUM_LIT:0> , <NUM_LIT:3> ] ) , <EOL> ( rand ( <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:3> ) , [ <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , ] ) , <EOL> ] : <EOL> data = numpy . asarray ( data , dtype = self . dtype ) <EOL> n = self . shared ( data ) <EOL> t = n [ idx ] <EOL> f = self . function ( [ ] , t . shape , op = self . ops , N = <NUM_LIT:0> , N_fast = <NUM_LIT:1> ) <EOL> val = f ( ) <EOL> self . assertTrue ( numpy . allclose ( val , data [ idx ] . shape ) ) <EOL> def test_grad_advanced_inc_subtensor ( self ) : <EOL> def inc_slice ( * s ) : <EOL> def just_numeric_args ( a , b ) : <EOL> cost = ( a [ s ] + b ) . sum ( ) <EOL> cost_wrt_a = theano . tensor . grad ( cost , a ) <EOL> cost_wrt_b = theano . tensor . grad ( cost , b ) <EOL> grads = cost_wrt_a . sum ( ) + cost_wrt_b . sum ( ) <EOL> return grads <EOL> return just_numeric_args <EOL> utt . verify_grad ( <EOL> inc_slice ( slice ( <NUM_LIT:2> , <NUM_LIT:4> , None ) ) , <EOL> ( numpy . asarray ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT> ] ) , numpy . asarray ( [ <NUM_LIT:9> , <NUM_LIT> ] ) , ) ) <EOL> utt . verify_grad ( <EOL> inc_slice ( slice ( <NUM_LIT:1> , <NUM_LIT:2> , None ) , slice ( None , None , None ) ) , <EOL> ( numpy . asarray ( [ [ <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:3> ] , [ <NUM_LIT:4> , <NUM_LIT> ] ] ) , <EOL> numpy . asarray ( [ [ <NUM_LIT:9> , <NUM_LIT> ] ] ) , ) ) <EOL> utt . verify_grad ( <EOL> inc_slice ( <NUM_LIT:2> , <NUM_LIT:1> ) , <EOL> ( numpy . asarray ( [ [ <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:3> ] , [ <NUM_LIT:4> , <NUM_LIT> ] ] ) , numpy . asarray ( <NUM_LIT> ) , ) ) <EOL> def test_inc_and_set_subtensor ( self ) : <EOL> """<STR_LIT>""" <EOL> X = self . shared ( numpy . ones ( ( <NUM_LIT:9> , <NUM_LIT:9> ) ) . astype ( self . dtype ) ) <EOL> y = set_subtensor ( X [ <NUM_LIT:1> : : , <NUM_LIT:1> : : ] , <NUM_LIT:0> ) <EOL> f = self . function ( [ ] , [ y ] , <EOL> op = self . inc_sub , <EOL> N = <NUM_LIT:1> ) <EOL> out = f ( ) <EOL> res = numpy . ones ( ( <NUM_LIT:9> , <NUM_LIT:9> ) ) <EOL> res [ <NUM_LIT:1> : : , <NUM_LIT:1> : : ] = <NUM_LIT:0> <EOL> assert numpy . allclose ( out , res ) <EOL> def test_advanced1_inc_and_set ( self ) : <EOL> """<STR_LIT>""" <EOL> rng = numpy . random . RandomState ( seed = utt . fetch_seed ( ) ) <EOL> all_inputs_var = [ ] <EOL> all_inputs_num = [ ] <EOL> all_outputs_var = [ ] <EOL> all_outputs_num = [ ] <EOL> for set_instead_of_inc in ( False , True ) : <EOL> for inplace in ( False , True ) : <EOL> for data_shape in ( ( <NUM_LIT:10> , ) , ( <NUM_LIT:4> , <NUM_LIT:5> ) , ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ) ) : <EOL> data_n_dims = len ( data_shape ) <EOL> data_size = numpy . product ( data_shape ) <EOL> data_num_init = numpy . arange ( data_size , dtype = self . dtype ) <EOL> data_num_init = data_num_init . reshape ( data_shape ) <EOL> inc_shapes = [ data_shape [ i : ] <EOL> for i in xrange ( <NUM_LIT:0> , len ( data_shape ) + <NUM_LIT:1> ) ] <EOL> inc_shapes += [ ( <NUM_LIT:1> , ) + inc_shapes [ - <NUM_LIT:1> ] [ <NUM_LIT:1> : ] ] <EOL> for inc_shape in inc_shapes : <EOL> inc_n_dims = len ( inc_shape ) <EOL> data_num = data_num_init . copy ( ) <EOL> data_var = self . type ( <EOL> broadcastable = [ False ] * data_n_dims , <EOL> dtype = self . dtype ) ( ) <EOL> idx_var = theano . tensor . vector ( dtype = '<STR_LIT>' ) <EOL> n_to_inc = rng . randint ( data_shape [ <NUM_LIT:0> ] ) <EOL> if ( n_to_inc == <NUM_LIT:1> and <EOL> len ( inc_shape ) > <NUM_LIT:0> and <EOL> inc_shape [ <NUM_LIT:0> ] == <NUM_LIT:1> and <EOL> data_shape [ <NUM_LIT:0> ] > <NUM_LIT:1> ) : <EOL> n_to_inc = <NUM_LIT:2> <EOL> idx_num = rng . randint ( <NUM_LIT:0> , data_shape [ <NUM_LIT:0> ] , n_to_inc ) <EOL> idx_num = idx_num . astype ( '<STR_LIT>' ) <EOL> inc_var = self . type ( <EOL> broadcastable = [ False ] * inc_n_dims , <EOL> dtype = self . dtype ) ( ) <EOL> if len ( inc_shape ) == len ( data_shape ) and ( <EOL> len ( inc_shapes ) == <NUM_LIT:0> or inc_shape [ <NUM_LIT:0> ] != <NUM_LIT:1> ) : <EOL> inc_shape = ( n_to_inc , ) + inc_shape [ <NUM_LIT:1> : ] <EOL> inc_size = numpy . product ( inc_shape , dtype = '<STR_LIT:int>' ) <EOL> inc_num = rng . uniform ( size = inc_size ) . astype ( self . dtype ) <EOL> inc_num = inc_num . reshape ( inc_shape ) <EOL> if set_instead_of_inc : <EOL> op = set_subtensor <EOL> else : <EOL> op = inc_subtensor <EOL> output = op ( data_var [ idx_var ] , inc_var , <EOL> inplace = inplace ) <EOL> data_copy = data_num . copy ( ) <EOL> for j , idx in enumerate ( idx_num ) : <EOL> if len ( inc_shape ) == len ( data_shape ) : <EOL> if inc_shape [ <NUM_LIT:0> ] == <NUM_LIT:1> : <EOL> inc_num0 = inc_num [ <NUM_LIT:0> ] <EOL> if set_instead_of_inc : <EOL> data_copy [ idx ] = inc_num0 <EOL> else : <EOL> data_copy [ idx ] += inc_num0 <EOL> else : <EOL> if set_instead_of_inc : <EOL> data_copy [ idx ] = inc_num [ j ] <EOL> else : <EOL> data_copy [ idx ] += inc_num [ j ] <EOL> else : <EOL> if set_instead_of_inc : <EOL> data_copy [ idx ] = inc_num <EOL> else : <EOL> data_copy [ idx ] += inc_num <EOL> data_var = theano . In ( data_var , mutable = True ) <EOL> all_inputs_var += [ data_var , idx_var , inc_var ] <EOL> all_inputs_num += [ data_num , idx_num , inc_num ] <EOL> all_outputs_var . append ( output ) <EOL> all_outputs_num . append ( data_copy ) <EOL> if False : <EOL> f = self . function ( [ data_var , idx_var , inc_var ] , <EOL> output , accept_inplace = inplace , <EOL> op = self . adv_incsub1 ) <EOL> if inplace : <EOL> data_num = data_num . copy ( ) <EOL> f_out = f ( data_num . copy ( ) , idx_num , inc_num ) <EOL> assert numpy . allclose ( f_out , data_copy ) <EOL> if not inplace : <EOL> assert ( data_num == data_num_init ) . all ( ) <EOL> orig_warn = theano . config . warn . gpu_set_subtensor1 <EOL> try : <EOL> theano . config . warn . gpu_set_subtensor1 = False <EOL> f = self . function ( all_inputs_var , all_outputs_var , <EOL> accept_inplace = True , <EOL> op = self . adv_incsub1 , <EOL> N = len ( all_outputs_var ) ) <EOL> finally : <EOL> theano . config . warn . gpu_set_subtensor1 = orig_warn <EOL> f_outs = f ( * all_inputs_num ) <EOL> assert len ( f_outs ) == len ( all_outputs_num ) <EOL> for f_out , output_num in izip ( f_outs , all_outputs_num ) : <EOL> assert numpy . allclose ( f_out , output_num ) <EOL> def test_adv_constant_arg ( self ) : <EOL> m = matrix ( '<STR_LIT:m>' ) <EOL> gv = numpy . array ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:3> ] ) <EOL> g = theano . tensor . constant ( gv ) <EOL> i = theano . tensor . lvector ( '<STR_LIT:i>' ) <EOL> s1 = m [ gv , i ] <EOL> s2 = m [ g , i ] <EOL> assert gof . graph . is_same_graph ( s1 , s2 ) <EOL> def test_adv1_inc_sub_notlastdim ( self ) : <EOL> m = matrix ( '<STR_LIT:m>' ) <EOL> i = lvector ( '<STR_LIT:i>' ) <EOL> m1 = set_subtensor ( m [ : , i ] , <NUM_LIT:0> ) <EOL> m2 = inc_subtensor ( m [ : , i ] , <NUM_LIT:1> ) <EOL> f = theano . function ( [ m , i ] , [ m1 , m2 ] ) <EOL> m_val = rand ( <NUM_LIT:3> , <NUM_LIT:5> ) <EOL> i_val = randint_ranged ( min = <NUM_LIT:0> , max = <NUM_LIT:4> , shape = ( <NUM_LIT:4> , ) ) <EOL> m1_ref = m_val . copy ( ) <EOL> m2_ref = m_val . copy ( ) <EOL> m1_val , m2_val = f ( m_val , i_val ) <EOL> for idx in i_val : <EOL> m1_ref [ : , idx ] = <NUM_LIT:0> <EOL> m2_ref [ : , idx ] += <NUM_LIT:1> <EOL> assert numpy . allclose ( m1_val , m1_ref ) , ( m1_val , m1_ref ) <EOL> assert numpy . allclose ( m2_val , m2_ref ) , ( m2_val , m2_ref ) <EOL> def test_adv1_inc_sub_notlastdim_2didx ( self ) : <EOL> m = matrix ( '<STR_LIT:m>' ) <EOL> i = lmatrix ( '<STR_LIT:i>' ) <EOL> m1 = set_subtensor ( m [ : , i ] , <NUM_LIT:0> ) <EOL> m2 = inc_subtensor ( m [ : , i ] , <NUM_LIT:1> ) <EOL> f = theano . function ( [ m , i ] , [ m1 , m2 ] ) <EOL> m_val = rand ( <NUM_LIT:5> , <NUM_LIT:7> ) <EOL> i_val = randint_ranged ( min = <NUM_LIT:0> , max = <NUM_LIT:6> , shape = ( <NUM_LIT:4> , <NUM_LIT:2> ) ) <EOL> m1_ref = m_val . copy ( ) <EOL> m2_ref = m_val . copy ( ) <EOL> m1_val , m2_val = f ( m_val , i_val ) <EOL> for idx in i_val . ravel ( ) : <EOL> m1_ref [ : , idx ] = <NUM_LIT:0> <EOL> m2_ref [ : , idx ] += <NUM_LIT:1> <EOL> assert numpy . allclose ( m1_val , m1_ref ) , ( m1_val , m1_ref ) <EOL> assert numpy . allclose ( m2_val , m2_ref ) , ( m2_val , m2_ref ) <EOL> def test_adv1_inc_sub_notlastdim_1_2dval_broadcast ( self ) : <EOL> m = matrix ( '<STR_LIT:m>' ) <EOL> sym_i = ( lvector ( '<STR_LIT:i>' ) , lmatrix ( '<STR_LIT:i>' ) ) <EOL> shape_i = ( ( <NUM_LIT:4> , ) , ( <NUM_LIT:4> , <NUM_LIT:2> ) ) <EOL> shape_val = ( ( <NUM_LIT:3> , <NUM_LIT:1> ) , ( <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> orig_warn = config . warn . inc_set_subtensor1 <EOL> try : <EOL> config . warn . inc_set_subtensor1 = False <EOL> for i , shp_i , shp_v in zip ( sym_i , shape_i , shape_val ) : <EOL> sub_m = m [ : , i ] <EOL> m1 = set_subtensor ( sub_m , numpy . zeros ( shp_v ) ) <EOL> m2 = inc_subtensor ( sub_m , numpy . ones ( shp_v ) ) <EOL> f = theano . function ( [ m , i ] , [ m1 , m2 ] ) <EOL> m_val = rand ( <NUM_LIT:3> , <NUM_LIT:5> ) <EOL> i_val = randint_ranged ( min = <NUM_LIT:0> , max = <NUM_LIT:4> , shape = shp_i ) <EOL> m1_ref = m_val . copy ( ) <EOL> m2_ref = m_val . copy ( ) <EOL> m1_val , m2_val = f ( m_val , i_val ) <EOL> for idx in i_val . ravel ( ) : <EOL> m1_ref [ : , idx ] = <NUM_LIT:0> <EOL> m2_ref [ : , idx ] += <NUM_LIT:1> <EOL> assert numpy . allclose ( m1_val , m1_ref ) , ( m1_val , m1_ref ) <EOL> assert numpy . allclose ( m2_val , m2_ref ) , ( m2_val , m2_ref ) <EOL> finally : <EOL> config . warn . inc_set_subtensor1 = orig_warn <EOL> def test_adv1_inc_sub_notlastdim_1_2dval_no_broadcast ( self ) : <EOL> m = matrix ( '<STR_LIT:m>' ) <EOL> sym_i = ( lvector ( '<STR_LIT:i>' ) , lmatrix ( '<STR_LIT:i>' ) ) <EOL> shape_i = ( ( <NUM_LIT:4> , ) , ( <NUM_LIT:4> , <NUM_LIT:2> ) ) <EOL> shape_val = ( ( <NUM_LIT:3> , <NUM_LIT:4> ) , ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:2> ) ) <EOL> orig_warn = config . warn . inc_set_subtensor1 <EOL> try : <EOL> config . warn . inc_set_subtensor1 = False <EOL> for i , shp_i , shp_v in zip ( sym_i , shape_i , shape_val ) : <EOL> sub_m = m [ : , i ] <EOL> m1 = set_subtensor ( sub_m , numpy . zeros ( shp_v ) ) <EOL> m2 = inc_subtensor ( sub_m , numpy . ones ( shp_v ) ) <EOL> f = theano . function ( [ m , i ] , [ m1 , m2 ] ) <EOL> m_val = rand ( <NUM_LIT:3> , <NUM_LIT:5> ) <EOL> i_val = randint_ranged ( min = <NUM_LIT:0> , max = <NUM_LIT:4> , shape = shp_i ) <EOL> m1_ref = m_val . copy ( ) <EOL> m2_ref = m_val . copy ( ) <EOL> m1_val , m2_val = f ( m_val , i_val ) <EOL> for idx in i_val . ravel ( ) : <EOL> m1_ref [ : , idx ] = <NUM_LIT:0> <EOL> m2_ref [ : , idx ] += <NUM_LIT:1> <EOL> assert numpy . allclose ( m1_val , m1_ref ) , ( m1_val , m1_ref ) <EOL> assert numpy . allclose ( m2_val , m2_ref ) , ( m2_val , m2_ref ) <EOL> finally : <EOL> config . warn . inc_set_subtensor1 = orig_warn <EOL> class TestIncSubtensor1 ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . s = tensor . iscalar ( ) <EOL> self . v = tensor . fvector ( ) <EOL> self . m = tensor . dmatrix ( ) <EOL> self . t = tensor . ctensor3 ( ) <EOL> self . adv1q = tensor . lvector ( ) <EOL> def test_cant_adv_idx_into_scalar ( self ) : <EOL> self . assertRaises ( TypeError , lambda : self . s [ self . adv1q ] ) <EOL> def test_index_into_vec_w_vec ( self ) : <EOL> a = self . v [ self . adv1q ] <EOL> assert a . type == self . v . type <EOL> def test_1d_set_adv_selection ( self ) : <EOL> a = set_subtensor ( self . v [ self . adv1q ] , self . v [ self . adv1q ] ) <EOL> assert a . type == self . v . type <EOL> f = theano . function ( [ self . v , self . adv1q ] , a , allow_input_downcast = True ) <EOL> aval = f ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> assert numpy . allclose ( aval , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.1> ] ) <EOL> def test_1d_inc_adv_selection ( self ) : <EOL> a = inc_subtensor ( self . v [ self . adv1q ] , self . v [ self . adv1q ] ) <EOL> assert a . type == self . v . type <EOL> f = theano . function ( [ self . v , self . adv1q ] , a , allow_input_downcast = True ) <EOL> aval = f ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> assert numpy . allclose ( aval , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> def test_1d_inc_adv_selection_w_broadcasting ( self ) : <EOL> a = inc_subtensor ( self . v [ self . adv1q ] , <NUM_LIT> ) <EOL> assert a . type == self . v . type <EOL> f = theano . function ( [ self . v , self . adv1q ] , a , allow_input_downcast = True ) <EOL> aval = f ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> assert numpy . allclose ( aval , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> def test_assigning_matrix_to_vector_selection ( self ) : <EOL> self . assertRaises ( TypeError , <EOL> lambda : inc_subtensor ( self . v [ self . adv1q ] , fmatrix ( ) ) ) <EOL> inplace_increment_missing = SkipTest ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> class TestAdvancedSubtensor ( unittest . TestCase ) : <EOL> def __init__ ( self , name , <EOL> shared = tensor . _shared , <EOL> sub = tensor . AdvancedSubtensor , <EOL> inc_sub = tensor . AdvancedIncSubtensor , <EOL> mode = None , <EOL> dtype = theano . config . floatX , <EOL> ignore_topo = DeepCopyOp ) : <EOL> self . shared = shared <EOL> self . sub = sub <EOL> self . inc_sub = inc_sub <EOL> if mode is None : <EOL> mode = theano . compile . mode . get_default_mode ( ) <EOL> self . mode = mode <EOL> self . dtype = dtype <EOL> self . ignore_topo = ignore_topo <EOL> super ( TestAdvancedSubtensor , self ) . __init__ ( name ) <EOL> def setUp ( self ) : <EOL> self . s = iscalar ( ) <EOL> self . v = fvector ( ) <EOL> self . m = dmatrix ( ) <EOL> self . t = ctensor3 ( ) <EOL> self . ix1 = lvector ( ) <EOL> self . ix12 = lvector ( ) <EOL> self . ix2 = lmatrix ( ) <EOL> self . ixr = lrow ( ) <EOL> def eval_output_and_check ( self , t ) : <EOL> f = inplace_func ( [ ] , t , mode = self . mode ) <EOL> topo = f . maker . fgraph . toposort ( ) <EOL> topo_ = [ node for node in topo if not isinstance ( node . op , <EOL> self . ignore_topo ) ] <EOL> assert len ( topo_ ) == <NUM_LIT:1> <EOL> assert isinstance ( topo_ [ <NUM_LIT:0> ] . op , self . sub ) <EOL> tval = f ( ) <EOL> return tval <EOL> def test_cant_adv_idx_into_scalar ( self ) : <EOL> self . assertRaises ( TypeError , lambda : self . s [ self . ix1 ] ) <EOL> def test_index_into_vec_w_vec ( self ) : <EOL> a = self . v [ self . ix1 ] <EOL> assert a . type == self . v . type , ( a . type , self . v . type ) <EOL> def test_index_into_vec_w_matrix ( self ) : <EOL> a = self . v [ self . ix2 ] <EOL> assert a . dtype == self . v . dtype , ( a . dtype , self . v . dtype ) <EOL> assert a . broadcastable == self . ix2 . broadcastable , ( <EOL> a . broadcastable , self . ix2 . broadcastable ) <EOL> def test_index_into_mat_w_row ( self ) : <EOL> a = self . m [ self . ixr ] <EOL> assert a . dtype == self . m . dtype , ( a . dtype , self . m . dtype ) <EOL> assert a . broadcastable == ( True , False , False ) <EOL> def test_index_w_int_and_vec ( self ) : <EOL> for data , idx in [ ( rand ( <NUM_LIT:4> , <NUM_LIT:5> ) , [ <NUM_LIT:2> , <NUM_LIT:3> ] ) , <EOL> ( rand ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:3> ) , [ <NUM_LIT:0> , <NUM_LIT:3> ] ) , <EOL> ( rand ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:3> ) , [ <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:0> ] ) , <EOL> ( rand ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:3> ) , [ <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:0> , <EOL> - <NUM_LIT:1> , - <NUM_LIT:2> , - <NUM_LIT:3> , - <NUM_LIT:4> ] ) , <EOL> ( rand ( <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:3> ) , [ <NUM_LIT:3> , <EOL> <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT:1> , - <NUM_LIT:2> , - <NUM_LIT:3> , - <NUM_LIT:4> ] ) , <EOL> ( rand ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:3> ) , <EOL> theano . tensor . constant ( [ <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:0> ] ) ) , <EOL> ] : <EOL> data = numpy . asarray ( data , dtype = self . dtype ) <EOL> n = self . shared ( data ) <EOL> t = n [ <NUM_LIT:0> , idx ] <EOL> self . assertTrue ( isinstance ( t . owner . op , tensor . AdvancedSubtensor ) ) <EOL> val = self . eval_output_and_check ( t ) <EOL> if isinstance ( idx , list ) : <EOL> good = data [ <NUM_LIT:0> , idx ] <EOL> else : <EOL> good = data [ <NUM_LIT:0> , idx . data ] <EOL> self . assertTrue ( val . ndim == data . ndim - <NUM_LIT:1> ) <EOL> self . assertTrue ( numpy . allclose ( val , good ) , ( val , good ) ) <EOL> def test_inc_adv_subtensor_w_matrix ( self ) : <EOL> subt = self . v [ self . ix2 ] <EOL> a = inc_subtensor ( subt , subt ) <EOL> assert a . type == self . v . type , ( a . type , self . v . type ) <EOL> f = theano . function ( [ self . v , self . ix2 ] , a , allow_input_downcast = True ) <EOL> aval = f ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> ] ] ) <EOL> assert numpy . allclose ( aval , [ <NUM_LIT> , <NUM_LIT> * <NUM_LIT:3> , <NUM_LIT> * <NUM_LIT:3> ] ) <EOL> def test_inc_adv_subtensor_w_2vec ( self ) : <EOL> if inplace_increment is None : <EOL> raise inplace_increment_missing <EOL> subt = self . m [ self . ix1 , self . ix12 ] <EOL> a = inc_subtensor ( subt , subt ) <EOL> typ = tensor . TensorType ( self . m . type . dtype , self . ix2 . type . broadcastable ) <EOL> assert a . type == typ , ( a . type , typ ) <EOL> f = theano . function ( [ self . m , self . ix1 , self . ix12 ] , a , <EOL> allow_input_downcast = True ) <EOL> aval = f ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> assert numpy . allclose ( aval , <EOL> [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:5> * <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:7> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> * <NUM_LIT:2> , <NUM_LIT> ] ] ) , aval <EOL> def test_inc_adv_subtensor_with_broadcasting ( self ) : <EOL> if inplace_increment is None : <EOL> raise inplace_increment_missing <EOL> inc = dscalar ( ) <EOL> a = inc_subtensor ( self . m [ self . ix1 , self . ix12 ] , inc ) <EOL> g_inc = tensor . grad ( a . sum ( ) , inc ) <EOL> assert a . type == self . m . type , ( a . type , self . m . type ) <EOL> f = theano . function ( [ self . m , self . ix1 , self . ix12 , inc ] , [ a , g_inc ] , <EOL> allow_input_downcast = True ) <EOL> aval , gval = f ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> <NUM_LIT> ) <EOL> assert numpy . allclose ( aval , <EOL> [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:5> + <NUM_LIT> * <NUM_LIT:2> , <NUM_LIT:6> , <NUM_LIT:7> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> + <NUM_LIT> , <NUM_LIT> ] ] ) , aval <EOL> assert numpy . allclose ( gval , <NUM_LIT> ) , gval <EOL> def test_inc_adv_subtensor1_with_broadcasting ( self ) : <EOL> if inplace_increment is None : <EOL> raise inplace_increment_missing <EOL> inc = dscalar ( ) <EOL> a = inc_subtensor ( self . m [ self . ix1 ] , inc ) <EOL> g_inc = tensor . grad ( a . sum ( ) , inc ) <EOL> assert a . type == self . m . type , ( a . type , self . m . type ) <EOL> f = theano . function ( [ self . m , self . ix1 , inc ] , [ a , g_inc ] , <EOL> allow_input_downcast = True ) <EOL> aval , gval = f ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> <NUM_LIT> ) <EOL> assert numpy . allclose ( aval , <EOL> [ [ <NUM_LIT> + <NUM_LIT> * <NUM_LIT:2> , <NUM_LIT> + <NUM_LIT> * <NUM_LIT:2> , <NUM_LIT> + <NUM_LIT> * <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:5> + <NUM_LIT> , <NUM_LIT:6> + <NUM_LIT> , <NUM_LIT:7> + <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) , aval <EOL> assert numpy . allclose ( gval , <NUM_LIT> ) , gval <EOL> def test_inc_adv_subtensor_with_index_broadcasting ( self ) : <EOL> if inplace_increment is None : <EOL> raise inplace_increment_missing <EOL> a = inc_subtensor ( self . m [ self . ix1 , self . ix2 ] , <NUM_LIT> ) <EOL> assert a . type == self . m . type , ( a . type , self . m . type ) <EOL> f = theano . function ( [ self . m , self . ix1 , self . ix2 ] , a , <EOL> allow_input_downcast = True ) <EOL> aval = f ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:0> ] , <EOL> [ [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ] ] ) <EOL> assert numpy . allclose ( aval , <EOL> [ [ <NUM_LIT> + <NUM_LIT:2> * <NUM_LIT> , <NUM_LIT> , <NUM_LIT> + <NUM_LIT:2> * <NUM_LIT> ] , <EOL> [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> + <NUM_LIT> , <NUM_LIT> + <NUM_LIT> ] ] ) , aval <EOL> def test_advanced_indexing ( self ) : <EOL> rng = numpy . random . RandomState ( utt . seed_rng ( ) ) <EOL> a = rng . uniform ( size = ( <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> b = theano . shared ( a ) <EOL> i = tensor . iscalar ( ) <EOL> j = tensor . iscalar ( ) <EOL> z = b [ [ i , j ] , : ] <EOL> f1 = theano . function ( [ i , j ] , z ) <EOL> cmd = f1 ( <NUM_LIT:0> , <NUM_LIT:1> ) == a [ [ <NUM_LIT:0> , <NUM_LIT:1> ] , : ] <EOL> self . assertTrue ( cmd . all ( ) ) <EOL> aa = rng . uniform ( size = ( <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> bb = theano . shared ( aa ) <EOL> k = tensor . iscalar ( ) <EOL> z = bb [ [ i , j , k ] , : , i : k ] <EOL> f2 = theano . function ( [ i , j , k ] , z ) <EOL> cmd = f2 ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) == aa [ [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] , : , <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> self . assertTrue ( cmd . all ( ) ) <EOL> def test_grad ( self ) : <EOL> ones = numpy . ones ( ( <NUM_LIT:1> , <NUM_LIT:3> ) , dtype = self . dtype ) <EOL> n = self . shared ( ones * <NUM_LIT:5> , broadcastable = ( True , False ) ) <EOL> idx = tensor . lvector ( ) <EOL> idx2 = tensor . lvector ( ) <EOL> t = n [ idx , idx2 ] <EOL> self . assertTrue ( isinstance ( t . owner . op , tensor . AdvancedSubtensor ) ) <EOL> utt . verify_grad ( lambda m : m [ [ <NUM_LIT:1> , <NUM_LIT:3> ] , [ <NUM_LIT:2> , <NUM_LIT:4> ] ] , <EOL> [ numpy . random . rand ( <NUM_LIT:5> , <NUM_LIT:5> ) . astype ( self . dtype ) ] ) <EOL> def fun ( x , y ) : <EOL> return advanced_inc_subtensor ( x , y , [ <NUM_LIT:1> , <NUM_LIT:3> ] , [ <NUM_LIT:2> , <NUM_LIT:4> ] ) <EOL> utt . verify_grad ( fun , [ numpy . random . rand ( <NUM_LIT:5> , <NUM_LIT:5> ) . astype ( self . dtype ) , <EOL> numpy . random . rand ( <NUM_LIT:2> ) . astype ( self . dtype ) ] ) <EOL> def fun ( x , y ) : <EOL> return advanced_set_subtensor ( x , y , [ <NUM_LIT:1> , <NUM_LIT:3> ] , [ <NUM_LIT:2> , <NUM_LIT:4> ] ) <EOL> utt . verify_grad ( fun , [ numpy . random . rand ( <NUM_LIT:5> , <NUM_LIT:5> ) . astype ( self . dtype ) , <EOL> numpy . random . rand ( <NUM_LIT:2> ) . astype ( self . dtype ) ] ) <EOL> class TestInferShape ( utt . InferShapeTester ) : <EOL> @ attr ( '<STR_LIT>' ) <EOL> def test_infer_shape ( self ) : <EOL> admat = dmatrix ( ) <EOL> bdmat = dmatrix ( ) <EOL> advec = dvector ( ) <EOL> adscal = dscalar ( ) <EOL> admat_val = rand ( <NUM_LIT:5> , <NUM_LIT:4> ) <EOL> self . _compile_and_check ( [ admat , bdmat ] , <EOL> [ inc_subtensor ( admat [ <NUM_LIT:2> : <NUM_LIT:4> ] , bdmat ) ] , <EOL> [ admat_val , [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ] ] , IncSubtensor ) <EOL> self . _compile_and_check ( [ admat , advec ] , <EOL> [ inc_subtensor ( admat [ <NUM_LIT:2> ] , advec ) ] , <EOL> [ admat_val , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ] , IncSubtensor ) <EOL> self . _compile_and_check ( [ admat , adscal ] , <EOL> [ inc_subtensor ( admat [ <NUM_LIT:2> , <NUM_LIT:3> ] , adscal ) ] , <EOL> [ admat_val , <NUM_LIT:1> ] , IncSubtensor ) <EOL> self . _compile_and_check ( [ admat , adscal ] , <EOL> [ inc_subtensor ( admat [ <NUM_LIT:1> : <NUM_LIT:3> , <NUM_LIT:2> ] , adscal ) ] , <EOL> [ admat_val , <NUM_LIT:1> ] , IncSubtensor ) <EOL> self . _compile_and_check ( [ admat , bdmat ] , <EOL> [ set_subtensor ( admat [ <NUM_LIT:2> : <NUM_LIT:4> ] , bdmat ) ] , <EOL> [ admat_val , [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ] ] , IncSubtensor ) <EOL> self . _compile_and_check ( [ admat , advec ] , <EOL> [ set_subtensor ( admat [ <NUM_LIT:2> ] , advec ) ] , <EOL> [ admat_val , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ] , IncSubtensor ) <EOL> self . _compile_and_check ( [ admat , adscal ] , <EOL> [ set_subtensor ( admat [ <NUM_LIT:2> , <NUM_LIT:3> ] , adscal ) ] , <EOL> [ admat_val , <NUM_LIT:1> ] , IncSubtensor ) <EOL> self . _compile_and_check ( [ admat , adscal ] , <EOL> [ set_subtensor ( admat [ <NUM_LIT:1> : <NUM_LIT:3> , <NUM_LIT:2> ] , adscal ) ] , <EOL> [ admat_val , <NUM_LIT:1> ] , IncSubtensor ) <EOL> adtens4 = dtensor4 ( ) <EOL> bdtens4 = dtensor4 ( ) <EOL> adtens4_val = rand ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:5> ) <EOL> self . _compile_and_check ( [ adtens4 , bdtens4 ] , <EOL> [ inc_subtensor ( adtens4 [ : : , <NUM_LIT:2> : <NUM_LIT:4> , : : , : : ] , bdtens4 ) ] , <EOL> [ adtens4_val , [ [ [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ] ] ] ] , IncSubtensor , <EOL> warn = False ) <EOL> self . _compile_and_check ( [ adtens4 , bdmat ] , <EOL> [ inc_subtensor ( adtens4 [ <NUM_LIT:2> , <NUM_LIT:2> : <NUM_LIT:4> , <NUM_LIT:1> , : : ] , bdmat ) ] , <EOL> [ adtens4_val , [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ] ] , IncSubtensor ) <EOL> self . _compile_and_check ( [ adtens4 , advec ] , <EOL> [ inc_subtensor ( adtens4 [ <NUM_LIT:0> , <NUM_LIT:1> , : : , <NUM_LIT:4> ] , advec ) ] , <EOL> [ adtens4_val , [ <NUM_LIT:1> , <NUM_LIT:2> ] ] , IncSubtensor ) <EOL> self . _compile_and_check ( [ adtens4 , adscal ] , <EOL> [ inc_subtensor ( adtens4 [ <NUM_LIT:1> : <NUM_LIT:3> , <NUM_LIT:1> , : : , <NUM_LIT:2> : <NUM_LIT:4> ] , adscal ) ] , <EOL> [ adtens4_val , <NUM_LIT:1> ] , IncSubtensor ) <EOL> self . _compile_and_check ( [ adtens4 , bdtens4 ] , <EOL> [ set_subtensor ( adtens4 [ : : , <NUM_LIT:2> : <NUM_LIT:4> , : : , : : ] , bdtens4 ) ] , <EOL> [ adtens4_val , [ [ [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ] ] ] ] , IncSubtensor , <EOL> warn = False ) <EOL> self . _compile_and_check ( [ adtens4 , bdmat ] , <EOL> [ set_subtensor ( adtens4 [ <NUM_LIT:2> , <NUM_LIT:2> : <NUM_LIT:4> , <NUM_LIT:1> , : : ] , bdmat ) ] , <EOL> [ adtens4_val , [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ] ] , IncSubtensor ) <EOL> self . _compile_and_check ( [ adtens4 , advec ] , <EOL> [ set_subtensor ( adtens4 [ <NUM_LIT:0> , <NUM_LIT:1> , : : , <NUM_LIT:4> ] , advec ) ] , <EOL> [ adtens4_val , [ <NUM_LIT:1> , <NUM_LIT:2> ] ] , IncSubtensor ) <EOL> self . _compile_and_check ( [ adtens4 , adscal ] , <EOL> [ set_subtensor ( adtens4 [ <NUM_LIT:1> : <NUM_LIT:3> , <NUM_LIT:1> , : : , <NUM_LIT:2> : <NUM_LIT:4> ] , adscal ) ] , <EOL> [ adtens4_val , <NUM_LIT:1> ] , IncSubtensor ) <EOL> admat = dmatrix ( ) <EOL> bdmat = dmatrix ( ) <EOL> advec = dvector ( ) <EOL> adscal = dscalar ( ) <EOL> admat_val = rand ( <NUM_LIT:5> , <NUM_LIT:4> ) <EOL> aivec_val = [ <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> self . _compile_and_check ( [ admat , bdmat ] , <EOL> [ set_subtensor ( admat [ aivec_val ] , bdmat ) ] , <EOL> [ admat_val , [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ] ] , AdvancedIncSubtensor1 ) <EOL> aivec_val = [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:2> ] <EOL> self . _compile_and_check ( [ admat , advec ] , <EOL> [ set_subtensor ( admat [ aivec_val ] , advec ) ] , <EOL> [ admat_val , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ] , AdvancedIncSubtensor1 ) <EOL> aivec_val = [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:0> ] <EOL> self . _compile_and_check ( [ admat , adscal ] , <EOL> [ set_subtensor ( admat [ aivec_val ] , adscal ) ] , <EOL> [ admat_val , <NUM_LIT:1> ] , AdvancedIncSubtensor1 ) <EOL> bdtens4 = dtensor4 ( ) <EOL> adtens4_val = rand ( <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:5> ) <EOL> aivec_val = [ <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> self . _compile_and_check ( [ adtens4 , bdtens4 ] , <EOL> [ set_subtensor ( adtens4 [ aivec_val ] , bdtens4 ) ] , <EOL> [ adtens4_val , [ [ [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ] ] ] ] , <EOL> AdvancedIncSubtensor1 , <EOL> warn = False ) <EOL> aivec_val = [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:2> ] <EOL> self . _compile_and_check ( [ adtens4 , advec ] , <EOL> [ set_subtensor ( adtens4 [ aivec_val ] , advec ) ] , <EOL> [ adtens4_val , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ] , <EOL> AdvancedIncSubtensor1 ) <EOL> aivec_val = [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:0> ] <EOL> self . _compile_and_check ( [ adtens4 , adscal ] , <EOL> [ set_subtensor ( adtens4 [ aivec_val ] , adscal ) ] , <EOL> [ adtens4_val , <NUM_LIT:1> ] , <EOL> AdvancedIncSubtensor1 ) <EOL> aivec_val = [ <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> self . _compile_and_check ( [ admat , bdmat ] , <EOL> [ inc_subtensor ( admat [ aivec_val ] , bdmat ) ] , <EOL> [ admat_val , [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] ] ] , <EOL> AdvancedIncSubtensor1 ) <EOL> aivec_val = [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:2> ] <EOL> self . _compile_and_check ( [ admat , advec ] , <EOL> [ inc_subtensor ( admat [ aivec_val ] , advec ) ] , <EOL> [ admat_val , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ] , AdvancedIncSubtensor1 ) <EOL> aivec_val = [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:0> ] <EOL> self . _compile_and_check ( [ admat , adscal ] , <EOL> [ inc_subtensor ( admat [ aivec_val ] , adscal ) ] , <EOL> [ admat_val , <NUM_LIT:1> ] , AdvancedIncSubtensor1 ) <EOL> bdtens4 = dtensor4 ( ) <EOL> adtens4_val = rand ( <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:5> ) <EOL> aivec_val = [ <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> self . _compile_and_check ( [ adtens4 , bdtens4 ] , <EOL> [ inc_subtensor ( adtens4 [ aivec_val ] , bdtens4 ) ] , <EOL> [ adtens4_val , [ [ [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ] ] , <EOL> [ [ [ <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> ] ] ] ] ] , <EOL> AdvancedIncSubtensor1 , <EOL> warn = False ) <EOL> aivec_val = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> ] <EOL> self . _compile_and_check ( [ adtens4 , advec ] , <EOL> [ inc_subtensor ( adtens4 [ aivec_val ] , advec ) ] , <EOL> [ adtens4_val , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ] , <EOL> AdvancedIncSubtensor1 ) <EOL> aivec_val = [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:0> ] <EOL> self . _compile_and_check ( [ adtens4 , adscal ] , <EOL> [ inc_subtensor ( adtens4 [ aivec_val ] , adscal ) ] , <EOL> [ adtens4_val , <NUM_LIT:2> ] , <EOL> AdvancedIncSubtensor1 ) <EOL> aivec_val = [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:2> ] <EOL> bivec_val = [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:3> ] <EOL> advec_val = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> self . _compile_and_check ( [ admat , advec ] , <EOL> [ set_subtensor ( admat [ aivec_val , bivec_val ] , advec ) ] , <EOL> [ admat_val , advec_val ] , AdvancedIncSubtensor ) <EOL> def test_adv_sub ( self ) : <EOL> admat = dmatrix ( ) <EOL> aivec = lvector ( ) <EOL> bivec = lvector ( ) <EOL> admat_val = rand ( <NUM_LIT:5> , <NUM_LIT:4> ) <EOL> aivec_val = [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:2> ] <EOL> bivec_val = [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:3> ] <EOL> self . _compile_and_check ( [ admat , aivec , bivec ] , <EOL> [ admat [ aivec , bivec ] ] , <EOL> [ admat_val , aivec_val , bivec_val ] , AdvancedSubtensor ) <EOL> self . _compile_and_check ( [ admat , aivec ] , <EOL> [ admat [ aivec , <NUM_LIT:1> : <NUM_LIT:3> ] ] , <EOL> [ admat_val , aivec_val ] , AdvancedSubtensor , <EOL> check_topo = False ) <EOL> self . _compile_and_check ( [ admat , aivec ] , <EOL> [ admat [ <NUM_LIT:1> : <NUM_LIT:3> , aivec ] ] , <EOL> [ admat_val , aivec_val ] , AdvancedSubtensor , <EOL> check_topo = False ) </s>
