<s> import DeepFried2 as df <EOL> import unittest <EOL> import numpy as np <EOL> class TestBackward ( unittest . TestCase ) : <EOL> def testSimple ( self ) : <EOL> l = df . Linear ( <NUM_LIT:2> , <NUM_LIT:3> , bias = False ) <EOL> W = l . parameters ( ) [ <NUM_LIT:0> ] . get_value ( ) <EOL> net = df . Sequential ( l , df . Backward ( l ) ) <EOL> self . assertEqual ( len ( net . parameters ( ) ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( net [ <NUM_LIT:0> ] . parameters ( ) , net [ <NUM_LIT:1> ] . parameters ( ) ) <EOL> X = np . random . randn ( <NUM_LIT:4> , <NUM_LIT:2> ) . astype ( df . floatX ) <EOL> Y = net . forward ( X ) <EOL> np . testing . assert_array_equal ( Y , np . dot ( np . dot ( X , W ) , W . T ) ) <EOL> net . evaluate ( ) <EOL> Y = net . forward ( X ) <EOL> np . testing . assert_array_equal ( Y , np . dot ( np . dot ( X , W ) , W . T ) ) <EOL> def testWrt ( self ) : <EOL> l1 = df . Linear ( <NUM_LIT:2> , <NUM_LIT:3> , bias = False ) <EOL> l2 = df . Linear ( <NUM_LIT:2> , <NUM_LIT:3> , bias = False ) <EOL> W1 = l1 . parameters ( ) [ <NUM_LIT:0> ] . get_value ( ) <EOL> W2 = l2 . parameters ( ) [ <NUM_LIT:0> ] . get_value ( ) <EOL> net = df . Sequential ( l1 , df . Backward ( l2 , wrt = l1 ) ) <EOL> self . assertEqual ( len ( net . parameters ( ) ) , <NUM_LIT:2> ) <EOL> p1 , p2 = net . parameters ( ) <EOL> self . assertNotEqual ( p1 , p2 ) <EOL> self . assertFalse ( np . all ( p1 . get_value ( ) == p2 . get_value ( ) ) ) <EOL> X = np . random . randn ( <NUM_LIT:4> , <NUM_LIT:2> ) . astype ( df . floatX ) <EOL> Y = net . forward ( X ) <EOL> np . testing . assert_array_equal ( Y , np . dot ( np . dot ( X , W1 ) , W2 . T ) ) <EOL> net . evaluate ( ) <EOL> Y = net . forward ( X ) <EOL> np . testing . assert_array_equal ( Y , np . dot ( np . dot ( X , W1 ) , W2 . T ) ) <EOL> def testGraph ( self ) : <EOL> l1 = df . Linear ( <NUM_LIT:3> , <NUM_LIT:4> ) <EOL> b1 = df . Backward ( l1 ) <EOL> net = df . Sequential ( df . Linear ( <NUM_LIT:3> , <NUM_LIT:3> ) , l1 , df . Linear ( <NUM_LIT:4> , <NUM_LIT:4> ) , b1 , df . Linear ( <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> X = np . random . randn ( <NUM_LIT:2> , <NUM_LIT:3> ) . astype ( df . floatX ) <EOL> self . assertEqual ( net . forward ( X ) . shape , ( <NUM_LIT:2> , <NUM_LIT:3> ) ) </s>
