<s> import numpy as np <EOL> import numpy . random as npr <EOL> import kayak <EOL> from . import * <EOL> def test_matadd_values_1 ( ) : <EOL> npr . seed ( <NUM_LIT:1> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_A = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> np_B = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> A = kayak . Parameter ( np_A ) <EOL> B = kayak . Parameter ( np_B ) <EOL> C = A + B <EOL> assert C . shape == np_A . shape <EOL> assert np . all ( close_float ( C . value , np_A + np_B ) ) <EOL> def test_matadd_values_2 ( ) : <EOL> npr . seed ( <NUM_LIT:2> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_A = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> np_B = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> np_C = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> A = kayak . Parameter ( np_A ) <EOL> B = kayak . Parameter ( np_B ) <EOL> C = kayak . Parameter ( np_C ) <EOL> D = A + B + C <EOL> assert D . shape == np_A . shape <EOL> assert np . all ( close_float ( D . value , np_A + np_B + np_C ) ) <EOL> def test_matadd_values_3 ( ) : <EOL> npr . seed ( <NUM_LIT:3> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_A = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> np_B = npr . randn ( <NUM_LIT:1> , <NUM_LIT:6> ) <EOL> A = kayak . Parameter ( np_A ) <EOL> B = kayak . Parameter ( np_B ) <EOL> C = A + B <EOL> assert C . shape == ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> assert np . all ( close_float ( C . value , np_A + np_B ) ) <EOL> def test_matadd_values_4 ( ) : <EOL> npr . seed ( <NUM_LIT:4> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_A = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> np_B = npr . randn ( <NUM_LIT:5> , <NUM_LIT:1> ) <EOL> A = kayak . Parameter ( np_A ) <EOL> B = kayak . Parameter ( np_B ) <EOL> C = A + B <EOL> assert C . shape == ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> assert np . all ( close_float ( C . value , np_A + np_B ) ) <EOL> def test_matadd_values_5 ( ) : <EOL> npr . seed ( <NUM_LIT:5> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_A = npr . randn ( <NUM_LIT:1> , <NUM_LIT:6> ) <EOL> np_B = npr . randn ( <NUM_LIT:5> , <NUM_LIT:1> ) <EOL> A = kayak . Parameter ( np_A ) <EOL> B = kayak . Parameter ( np_B ) <EOL> C = A + B <EOL> assert C . shape == ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> assert np . all ( close_float ( C . value , np_A + np_B ) ) <EOL> def test_matadd_values_6 ( ) : <EOL> npr . seed ( <NUM_LIT:6> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_A = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> np_B = npr . randn ( <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> A = kayak . Parameter ( np_A ) <EOL> B = kayak . Parameter ( np_B ) <EOL> C = A + B <EOL> assert C . shape == ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> assert np . all ( close_float ( C . value , np_A + np_B ) ) <EOL> def test_matadd_values_7 ( ) : <EOL> npr . seed ( <NUM_LIT:7> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_A = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> np_B = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> A = kayak . Parameter ( np_A ) <EOL> B = kayak . Parameter ( np_B ) <EOL> D = A + B + A <EOL> assert D . shape == ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> assert np . all ( close_float ( D . value , <NUM_LIT:2> * np_A + np_B ) ) <EOL> def test_matadd_grad_1 ( ) : <EOL> npr . seed ( <NUM_LIT:8> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_A = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> np_B = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> A = kayak . Parameter ( np_A ) <EOL> B = kayak . Parameter ( np_B ) <EOL> C = A + B <EOL> D = kayak . MatSum ( C ) <EOL> D . value <EOL> assert kayak . util . checkgrad ( A , D ) < MAX_GRAD_DIFF <EOL> assert kayak . util . checkgrad ( B , D ) < MAX_GRAD_DIFF <EOL> def test_matadd_grad_2 ( ) : <EOL> npr . seed ( <NUM_LIT:9> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_A = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> np_B = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> np_C = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> A = kayak . Parameter ( np_A ) <EOL> B = kayak . Parameter ( np_B ) <EOL> C = kayak . Parameter ( np_C ) <EOL> D = A + B + C <EOL> E = kayak . MatSum ( D ) <EOL> E . value <EOL> assert kayak . util . checkgrad ( A , E ) < MAX_GRAD_DIFF <EOL> assert kayak . util . checkgrad ( B , E ) < MAX_GRAD_DIFF <EOL> assert kayak . util . checkgrad ( C , E ) < MAX_GRAD_DIFF <EOL> def test_matadd_grad_3 ( ) : <EOL> npr . seed ( <NUM_LIT:10> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_A = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> np_B = npr . randn ( <NUM_LIT:1> , <NUM_LIT:6> ) <EOL> A = kayak . Parameter ( np_A ) <EOL> B = kayak . Parameter ( np_B ) <EOL> C = A + B <EOL> D = kayak . MatSum ( C ) <EOL> D . value <EOL> print np_A . shape , D . grad ( A ) . shape <EOL> print np_B . shape , D . grad ( B ) . shape <EOL> assert D . grad ( A ) . shape == np_A . shape <EOL> assert D . grad ( B ) . shape == np_B . shape <EOL> assert kayak . util . checkgrad ( A , D ) < MAX_GRAD_DIFF <EOL> assert kayak . util . checkgrad ( B , D ) < MAX_GRAD_DIFF <EOL> def test_matadd_grad_4 ( ) : <EOL> npr . seed ( <NUM_LIT:11> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_A = npr . randn ( <NUM_LIT:5> , <NUM_LIT:1> ) <EOL> np_B = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> A = kayak . Parameter ( np_A ) <EOL> B = kayak . Parameter ( np_B ) <EOL> C = A + B <EOL> D = kayak . MatSum ( C ) <EOL> D . value <EOL> assert D . grad ( A ) . shape == np_A . shape <EOL> assert D . grad ( B ) . shape == np_B . shape <EOL> assert kayak . util . checkgrad ( A , D ) < MAX_GRAD_DIFF <EOL> assert kayak . util . checkgrad ( B , D ) < MAX_GRAD_DIFF <EOL> def test_matadd_grad_5 ( ) : <EOL> npr . seed ( <NUM_LIT:12> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_A = npr . randn ( <NUM_LIT:5> , <NUM_LIT:1> ) <EOL> np_B = npr . randn ( <NUM_LIT:1> , <NUM_LIT:6> ) <EOL> A = kayak . Parameter ( np_A ) <EOL> B = kayak . Parameter ( np_B ) <EOL> C = A + B <EOL> D = kayak . MatSum ( C ) <EOL> D . value <EOL> assert D . grad ( A ) . shape == np_A . shape <EOL> assert D . grad ( B ) . shape == np_B . shape <EOL> assert kayak . util . checkgrad ( A , D ) < MAX_GRAD_DIFF <EOL> assert kayak . util . checkgrad ( B , D ) < MAX_GRAD_DIFF <EOL> def test_matadd_grad_6 ( ) : <EOL> npr . seed ( <NUM_LIT> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_A = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> np_B = npr . randn ( <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> A = kayak . Parameter ( np_A ) <EOL> B = kayak . Parameter ( np_B ) <EOL> C = A + B <EOL> D = kayak . MatSum ( C ) <EOL> D . value <EOL> assert D . grad ( A ) . shape == np_A . shape <EOL> assert D . grad ( B ) . shape == np_B . shape <EOL> assert kayak . util . checkgrad ( A , D ) < MAX_GRAD_DIFF <EOL> assert kayak . util . checkgrad ( B , D ) < MAX_GRAD_DIFF <EOL> def test_matadd_grad_7 ( ) : <EOL> npr . seed ( <NUM_LIT> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_A = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> np_B = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> A = kayak . Parameter ( np_A ) <EOL> B = kayak . Parameter ( np_B ) <EOL> D = A + B + A <EOL> E = kayak . MatSum ( D ) <EOL> E . value <EOL> assert E . grad ( A ) . shape == np_A . shape <EOL> assert E . grad ( B ) . shape == np_B . shape <EOL> assert kayak . util . checkgrad ( A , E ) < MAX_GRAD_DIFF <EOL> assert kayak . util . checkgrad ( B , E ) < MAX_GRAD_DIFF <EOL> def test_matadd_grad_8 ( ) : <EOL> npr . seed ( <NUM_LIT:15> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_A = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> np_B = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> A = kayak . Parameter ( np_A ) <EOL> D = A + A <EOL> E = kayak . MatSum ( D ) <EOL> E . value <EOL> assert E . grad ( A ) . shape == np_A . shape <EOL> assert kayak . util . checkgrad ( A , E ) < MAX_GRAD_DIFF </s>
