<s> import numpy <EOL> import numpy . testing <EOL> import random <EOL> import time <EOL> class NumpyTestCases ( object ) : <EOL> @ staticmethod <EOL> def compareButDontCheckTypes ( x , y ) : <EOL> if isinstance ( x , basestring ) and isinstance ( y , basestring ) : <EOL> return x == y <EOL> if hasattr ( x , '<STR_LIT>' ) and hasattr ( y , '<STR_LIT>' ) : <EOL> l1 = len ( x ) <EOL> l2 = len ( y ) <EOL> if l1 != l2 : <EOL> return False <EOL> for idx in range ( l1 ) : <EOL> if not NumpyTestCases . compareButDontCheckTypes ( x [ idx ] , y [ idx ] ) : <EOL> return False <EOL> return True <EOL> else : <EOL> return x == y <EOL> def test_numpy ( self ) : <EOL> n = numpy . zeros ( <NUM_LIT:10> ) <EOL> def f ( ) : <EOL> return n . shape <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_empty_array_ctor ( self ) : <EOL> def f ( ) : <EOL> return numpy . array ( [ ] ) <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_repeated_array_ctor ( self ) : <EOL> x = numpy . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ] ) <EOL> def f ( ) : <EOL> return numpy . array ( x ) <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_pinverse_2 ( self ) : <EOL> numpy . random . seed ( <NUM_LIT> ) <EOL> def f ( array ) : <EOL> return numpy . linalg . pinv ( array ) <EOL> arr = numpy . random . rand ( <NUM_LIT:20> , <NUM_LIT:10> ) * <NUM_LIT:1000> <EOL> t1 = time . time ( ) <EOL> r1 = self . evaluateWithExecutor ( f , arr ) <EOL> t2 = time . time ( ) <EOL> r2 = f ( arr ) <EOL> t3 = time . time ( ) <EOL> print t3 - t2 , t2 - t1 <EOL> self . assertArraysAreAlmostEqual ( r1 , r2 ) <EOL> def test_numpy_pinverse_1 ( self ) : <EOL> def f ( arr ) : <EOL> array = numpy . array ( arr ) <EOL> return numpy . linalg . pinv ( array ) <EOL> arr1 = [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] <EOL> r1 = self . evaluateWithExecutor ( f , arr1 ) <EOL> r2 = f ( arr1 ) <EOL> self . assertArraysAreAlmostEqual ( r1 , r2 ) <EOL> arr2 = [ [ <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:1.0> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:9> ] ] <EOL> r1 = self . evaluateWithExecutor ( f , arr2 ) <EOL> r2 = f ( arr2 ) <EOL> self . assertArraysAreAlmostEqual ( r1 , r2 ) <EOL> def test_numpy_transpose ( self ) : <EOL> def f ( ) : <EOL> array = numpy . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> return array . transpose ( ) <EOL> self . equivalentEvaluationTest ( f ) <EOL> def f2 ( ) : <EOL> arr = numpy . array ( [ [ [ <NUM_LIT> ] , [ <NUM_LIT> ] ] , [ [ <NUM_LIT> ] , [ <NUM_LIT> ] ] , [ [ <NUM_LIT> ] , [ <NUM_LIT> ] ] ] ) <EOL> return arr . transpose ( ) <EOL> self . equivalentEvaluationTest ( f2 ) <EOL> def f3 ( ) : <EOL> arr = numpy . array ( [ <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> return arr . transpose ( ) <EOL> self . equivalentEvaluationTest ( f3 ) <EOL> def test_numpy_indexing_1 ( self ) : <EOL> def f ( ) : <EOL> array = numpy . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> toReturn = [ ] <EOL> l = len ( array ) <EOL> l2 = len ( array [ <NUM_LIT:0> ] ) <EOL> for x in range ( l ) : <EOL> for y in range ( l2 ) : <EOL> toReturn = toReturn + [ array [ x ] [ y ] ] <EOL> return toReturn <EOL> self . equivalentEvaluationTest ( <EOL> f , comparisonFunction = NumpyTestCases . compareButDontCheckTypes <EOL> ) <EOL> def test_numpy_indexing_2 ( self ) : <EOL> def f ( ) : <EOL> arr = numpy . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> return ( arr , arr [ <NUM_LIT:0> ] , arr [ <NUM_LIT:1> ] , arr [ <NUM_LIT:8> ] ) <EOL> self . equivalentEvaluationTest ( <EOL> f , comparisonFunction = NumpyTestCases . compareButDontCheckTypes <EOL> ) <EOL> def test_numpy_indexing_3 ( self ) : <EOL> def f ( ) : <EOL> arr = numpy . array ( [ [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] , [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] ] ) <EOL> return ( arr , arr [ <NUM_LIT:0> ] , arr [ <NUM_LIT:1> ] , arr [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , arr [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) <EOL> self . equivalentEvaluationTest ( <EOL> f , comparisonFunction = NumpyTestCases . compareButDontCheckTypes ) <EOL> def f2 ( ) : <EOL> arr = numpy . array ( [ [ [ <NUM_LIT> ] , [ <NUM_LIT> ] ] , [ [ <NUM_LIT> ] , [ <NUM_LIT> ] ] , [ [ <NUM_LIT> ] , [ <NUM_LIT> ] ] ] ) <EOL> return ( arr , arr [ <NUM_LIT:0> ] , arr [ <NUM_LIT:1> ] , arr [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , arr [ <NUM_LIT:2> ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> self . equivalentEvaluationTest ( <EOL> f2 , comparisonFunction = NumpyTestCases . compareButDontCheckTypes ) <EOL> def f3 ( ) : <EOL> arr = numpy . array ( [ [ [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] , [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] ] , [ [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] , [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] ] ] ) <EOL> return ( arr , arr [ <NUM_LIT:0> ] , arr [ <NUM_LIT:1> ] , arr [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , arr [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , arr [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) <EOL> self . equivalentEvaluationTest ( <EOL> f3 , comparisonFunction = NumpyTestCases . compareButDontCheckTypes ) <EOL> def test_return_numpy ( self ) : <EOL> n = numpy . zeros ( <NUM_LIT:10> ) <EOL> def f ( ) : <EOL> return n <EOL> res = self . evaluateWithExecutor ( f ) <EOL> self . assertTrue ( isinstance ( res , numpy . ndarray ) , res ) <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_flatten ( self ) : <EOL> def f ( lists ) : <EOL> b = numpy . array ( lists ) <EOL> return b . flatten ( ) <EOL> a = [ <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> self . equivalentEvaluationTest ( f , a ) <EOL> b = [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] <EOL> self . equivalentEvaluationTest ( f , b ) <EOL> c = [ [ [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] , [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] ] , [ [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] , [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] ] ] <EOL> self . equivalentEvaluationTest ( f , c ) <EOL> def test_numpy_arrays_are_iterable ( self ) : <EOL> def f ( ) : <EOL> array = numpy . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> toReturn = [ ] <EOL> for val in array : <EOL> toReturn = toReturn + [ val ] <EOL> return toReturn <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_tolist ( self ) : <EOL> def f ( lists ) : <EOL> b = numpy . array ( lists ) <EOL> return b . tolist ( ) <EOL> a = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] <EOL> self . equivalentEvaluationTest ( f , a ) <EOL> b = [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] <EOL> self . equivalentEvaluationTest ( f , b ) <EOL> c = [ [ [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] , [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] ] , [ [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] , [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] ] ] <EOL> self . equivalentEvaluationTest ( f , c ) <EOL> def test_numpy_dot_product_1a ( self ) : <EOL> random . seed ( <NUM_LIT> ) <EOL> listLength = <NUM_LIT:20> <EOL> def f ( arr1 , arr2 ) : <EOL> return numpy . dot ( arr1 , arr2 ) <EOL> for _ in range ( <NUM_LIT:10> ) : <EOL> x1 = [ random . uniform ( - <NUM_LIT:10> , <NUM_LIT:10> ) for _ in range ( <NUM_LIT:0> , listLength ) ] <EOL> x2 = [ random . uniform ( - <NUM_LIT:10> , <NUM_LIT:10> ) for _ in range ( <NUM_LIT:0> , listLength ) ] <EOL> self . equivalentEvaluationTest ( <EOL> f , x1 , x2 , <EOL> comparisonFunction = numpy . isclose <EOL> ) <EOL> def test_numpy_dot_product_1b ( self ) : <EOL> random . seed ( <NUM_LIT> ) <EOL> listLength = <NUM_LIT:20> <EOL> def f ( arr1 , arr2 ) : <EOL> return arr1 . dot ( arr2 ) <EOL> for _ in range ( <NUM_LIT:10> ) : <EOL> x1 = numpy . array ( [ <EOL> random . uniform ( - <NUM_LIT:10> , <NUM_LIT:10> ) for _ in range ( <NUM_LIT:0> , listLength ) ] ) <EOL> x2 = [ random . uniform ( - <NUM_LIT:10> , <NUM_LIT:10> ) for _ in range ( <NUM_LIT:0> , listLength ) ] <EOL> self . equivalentEvaluationTest ( <EOL> f , x1 , x2 , <EOL> comparisonFunction = numpy . isclose <EOL> ) <EOL> def test_numpy_dot_product_2a ( self ) : <EOL> random . seed ( <NUM_LIT> ) <EOL> listLength = <NUM_LIT:20> <EOL> arr1 = [ random . uniform ( - <NUM_LIT:10> , <NUM_LIT:10> ) for _ in range ( <NUM_LIT:0> , listLength ) ] <EOL> arr2 = [ random . uniform ( - <NUM_LIT:10> , <NUM_LIT:10> ) for _ in range ( <NUM_LIT:0> , listLength ) ] <EOL> def f ( ) : <EOL> a = numpy . array ( arr1 ) <EOL> b = numpy . array ( arr2 ) <EOL> return numpy . dot ( a , b ) <EOL> r1 = self . evaluateWithExecutor ( f ) <EOL> r2 = f ( ) <EOL> numpy . testing . assert_allclose ( r1 , r2 ) <EOL> def test_numpy_dot_product_2b ( self ) : <EOL> random . seed ( <NUM_LIT> ) <EOL> listLength = <NUM_LIT:20> <EOL> arr1 = [ random . uniform ( - <NUM_LIT:10> , <NUM_LIT:10> ) for _ in range ( <NUM_LIT:0> , listLength ) ] <EOL> arr2 = [ random . uniform ( - <NUM_LIT:10> , <NUM_LIT:10> ) for _ in range ( <NUM_LIT:0> , listLength ) ] <EOL> def f ( ) : <EOL> a = numpy . array ( arr1 ) <EOL> b = numpy . array ( arr2 ) <EOL> return a . dot ( b ) <EOL> r1 = self . evaluateWithExecutor ( f ) <EOL> r2 = f ( ) <EOL> numpy . testing . assert_allclose ( r1 , r2 ) <EOL> def test_numpy_dot_product_3a ( self ) : <EOL> def f ( ) : <EOL> m1 = numpy . array ( [ <NUM_LIT:1.0> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) <EOL> m2 = numpy . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> return numpy . dot ( m1 , m2 ) <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_dot_product_3b ( self ) : <EOL> def f ( ) : <EOL> m1 = numpy . array ( [ <NUM_LIT:1.0> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) <EOL> m2 = numpy . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> return m1 . dot ( m2 ) <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_dot_product_4a ( self ) : <EOL> def f ( ) : <EOL> m1 = numpy . array ( [ <NUM_LIT:1.0> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> m2 = numpy . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> return numpy . dot ( m2 , m1 ) <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_dot_product_4b ( self ) : <EOL> def f ( ) : <EOL> m1 = numpy . array ( [ <NUM_LIT:1.0> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> m2 = numpy . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> return numpy . dot ( m2 , m1 ) <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_dot_product_4c ( self ) : <EOL> def f ( ) : <EOL> m1 = [ <NUM_LIT:1.0> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> m2 = numpy . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> return numpy . dot ( m2 , m1 ) <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_dot_product_5a ( self ) : <EOL> x = numpy . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ] ) <EOL> y = numpy . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> with self . assertRaises ( ValueError ) : <EOL> with self . create_executor ( ) as fora : <EOL> with fora . remotely : <EOL> numpy . dot ( y , x ) <EOL> def test_numpy_dot_product_5a ( self ) : <EOL> x = numpy . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ] ) <EOL> y = numpy . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> with self . assertRaises ( ValueError ) : <EOL> with self . create_executor ( ) as fora : <EOL> with fora . remotely : <EOL> numpy . dot ( y , x ) <EOL> def test_numpy_dot_product_5b ( self ) : <EOL> x = numpy . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ] ) <EOL> y = numpy . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> with self . assertRaises ( ValueError ) : <EOL> with self . create_executor ( ) as fora : <EOL> with fora . remotely : <EOL> y . dot ( x ) <EOL> def test_numpy_matrix_multiplication_1a ( self ) : <EOL> def f ( ) : <EOL> m1 = numpy . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> m2 = m1 . transpose ( ) <EOL> return numpy . dot ( m1 , m2 ) <EOL> r1 = self . evaluateWithExecutor ( f ) <EOL> r2 = f ( ) <EOL> self . assertArraysAreAlmostEqual ( r1 , r2 ) <EOL> def test_numpy_matrix_multiplication_1b ( self ) : <EOL> def f ( ) : <EOL> m1 = numpy . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> m2 = m1 . transpose ( ) <EOL> return numpy . dot ( m1 , m2 ) <EOL> r1 = self . evaluateWithExecutor ( f ) <EOL> r2 = f ( ) <EOL> self . assertArraysAreAlmostEqual ( r1 , r2 ) <EOL> def test_numpy_matrix_multiplication_misaligned_1 ( self ) : <EOL> m1 = numpy . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ] ) <EOL> m2 = numpy . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] , [ <NUM_LIT:5> , <NUM_LIT:6> ] ] ) <EOL> with self . assertRaises ( ValueError ) : <EOL> with self . create_executor ( ) as fora : <EOL> with fora . remotely : <EOL> numpy . dot ( m1 , m2 ) <EOL> def test_numpy_matrix_multiplication_misaligned_2 ( self ) : <EOL> m1 = numpy . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> m2 = numpy . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] , [ <NUM_LIT:5> , <NUM_LIT:6> ] ] ) <EOL> with self . assertRaises ( ValueError ) : <EOL> with self . create_executor ( ) as fora : <EOL> with fora . remotely : <EOL> numpy . dot ( m1 , m2 ) <EOL> def test_numpy_reshape ( self ) : <EOL> def f ( newShape ) : <EOL> m1 = numpy . array ( [ <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> return m1 . reshape ( newShape ) <EOL> self . equivalentEvaluationTest ( f , ( <NUM_LIT:1> , <NUM_LIT> ) ) <EOL> self . equivalentEvaluationTest ( f , ( <NUM_LIT:2> , <NUM_LIT:9> ) ) <EOL> self . equivalentEvaluationTest ( f , ( <NUM_LIT:3> , <NUM_LIT:6> ) ) <EOL> self . equivalentEvaluationTestThatHandlesExceptions ( f , ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> def test_numpy_matrix_division ( self ) : <EOL> random . seed ( <NUM_LIT> ) <EOL> matrix = numpy . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> for _ in range ( <NUM_LIT:10> ) : <EOL> def f ( x ) : <EOL> return matrix / x <EOL> self . equivalentEvaluationTest ( f , random . uniform ( - <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> def f2 ( x ) : <EOL> return matrix * x <EOL> self . equivalentEvaluationTest ( f2 , random . uniform ( - <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> def f3 ( x ) : <EOL> return matrix + x <EOL> self . equivalentEvaluationTest ( f3 , random . uniform ( - <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> def f4 ( x ) : <EOL> return matrix - x <EOL> self . equivalentEvaluationTest ( f4 , random . uniform ( - <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> def f5 ( x ) : <EOL> return matrix ** x <EOL> self . equivalentEvaluationTest ( f5 , random . uniform ( - <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> def test_numpy_make_array ( self ) : <EOL> def f ( ) : <EOL> return numpy . zeros ( <NUM_LIT:10> ) <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_addition_1 ( self ) : <EOL> def f ( ) : <EOL> x1 = numpy . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ] ) <EOL> x2 = numpy . array ( [ [ <NUM_LIT:8> , <NUM_LIT:7> ] , [ <NUM_LIT:6> , <NUM_LIT:5> ] ] ) <EOL> return x1 + x2 <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_binary_ops ( self ) : <EOL> def f ( ) : <EOL> x1 = numpy . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ] ) <EOL> x2 = numpy . array ( [ [ <NUM_LIT:8> , <NUM_LIT:7> ] , [ <NUM_LIT:6> , <NUM_LIT:5> ] ] ) <EOL> return ( x1 / x2 ) ** <NUM_LIT:2> - x2 ** x2 <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_addition_2 ( self ) : <EOL> def f ( ) : <EOL> x1 = numpy . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ] ) <EOL> x2 = numpy . array ( [ [ <NUM_LIT:8> , <NUM_LIT:7> , <NUM_LIT:5> , <NUM_LIT:6> ] ] ) <EOL> return x1 + x2 <EOL> with self . assertRaises ( ValueError ) : <EOL> with self . create_executor ( ) as fora : <EOL> with fora . remotely : <EOL> f ( ) <EOL> def test_numpy_arange ( self ) : <EOL> def f ( ) : <EOL> return numpy . arange ( - <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) <EOL> r1 = self . evaluateWithExecutor ( f ) <EOL> r2 = f ( ) <EOL> self . assertArraysAreAlmostEqual ( r1 , r2 ) <EOL> def test_numpy_zeros_1 ( self ) : <EOL> def f ( ) : <EOL> return numpy . zeros ( ( <NUM_LIT:10> , <NUM_LIT:2> ) ) <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_zeros_2 ( self ) : <EOL> def f ( ) : <EOL> return numpy . zeros ( <NUM_LIT:10> ) <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_linsolve_1 ( self ) : <EOL> a = numpy . array ( [ [ - <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> b = numpy . array ( [ [ <NUM_LIT:1.0> ] , [ <NUM_LIT> ] ] ) <EOL> def f ( ) : <EOL> return numpy . linalg . solve ( a , b ) <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_linsolve_2 ( self ) : <EOL> a = numpy . array ( [ [ - <NUM_LIT> , <NUM_LIT> ] , [ - <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> b = numpy . array ( [ [ <NUM_LIT:1.0> ] , [ <NUM_LIT> ] ] ) <EOL> def f ( ) : <EOL> return numpy . linalg . solve ( a , b ) <EOL> try : <EOL> self . evaluateWithExecutor ( f ) <EOL> self . assertTrue ( False ) <EOL> except : <EOL> pass <EOL> def test_numpy_linsolve_3 ( self ) : <EOL> a = numpy . array ( [ [ - <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> b = numpy . array ( [ <NUM_LIT:1.0> , <NUM_LIT> ] ) <EOL> def f ( ) : <EOL> return numpy . linalg . solve ( a , b ) <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_slicing_1 ( self ) : <EOL> size = <NUM_LIT:3> <EOL> def f ( lowIx , highIx ) : <EOL> x = numpy . array ( range ( size ) ) <EOL> return x [ lowIx : highIx ] <EOL> for ix in range ( size ) : <EOL> for jx in range ( size ) : <EOL> self . equivalentEvaluationTest ( f , ix , jx ) <EOL> def test_numpy_eq ( self ) : <EOL> x = numpy . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> y = numpy . array ( [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> ] ) <EOL> def f ( ) : <EOL> return x == y <EOL> self . equivalentEvaluationTest ( f ) <EOL> def test_numpy_isnan ( self ) : <EOL> def f ( x ) : <EOL> return [ numpy . isnan ( elt ) for elt in x ] <EOL> vals = [ <NUM_LIT:1> , <NUM_LIT> , numpy . nan , numpy . inf , - numpy . nan ] <EOL> numpy . testing . assert_allclose ( <EOL> f ( vals ) , <EOL> self . evaluateWithExecutor ( f , vals ) <EOL> ) <EOL> def test_numpy_isinf_1 ( self ) : <EOL> def f ( x ) : <EOL> return [ numpy . isnan ( elt ) for elt in x ] <EOL> vals = [ <NUM_LIT:1> , <NUM_LIT> , numpy . nan , numpy . inf , - numpy . nan ] <EOL> numpy . testing . assert_allclose ( <EOL> f ( vals ) , <EOL> self . evaluateWithExecutor ( f , vals ) <EOL> ) <EOL> def test_numpy_isinf_2 ( self ) : <EOL> def f ( x ) : <EOL> return numpy . isinf ( x ) <EOL> arrays = [ numpy . array ( [ <NUM_LIT:1.0> , <NUM_LIT> ] ) , <EOL> numpy . array ( [ [ <NUM_LIT:1.0> , <NUM_LIT> ] , [ numpy . inf , <NUM_LIT> ] ] ) ] <EOL> for array in arrays : <EOL> numpy . testing . assert_array_equal ( <EOL> f ( array ) , <EOL> self . evaluateWithExecutor ( f , array ) <EOL> ) <EOL> def test_numpy_isfinite_1 ( self ) : <EOL> def f ( x ) : <EOL> return [ numpy . isnan ( elt ) for elt in x ] <EOL> vals = [ <NUM_LIT:1> , <NUM_LIT> , numpy . nan , numpy . inf , - numpy . nan ] <EOL> numpy . testing . assert_allclose ( <EOL> f ( vals ) , <EOL> self . evaluateWithExecutor ( f , vals ) <EOL> ) <EOL> def test_numpy_isfinite_2 ( self ) : <EOL> def f ( x ) : <EOL> return numpy . isfinite ( x ) <EOL> arrays = [ numpy . array ( [ <NUM_LIT:1.0> , <NUM_LIT> ] ) , <EOL> numpy . array ( [ [ <NUM_LIT:1.0> , <NUM_LIT> ] , [ numpy . inf , <NUM_LIT> ] ] ) ] <EOL> for array in arrays : <EOL> numpy . testing . assert_array_equal ( <EOL> f ( array ) , <EOL> self . evaluateWithExecutor ( f , array ) <EOL> ) <EOL> def test_numpy_all_1 ( self ) : <EOL> def f ( x ) : <EOL> return numpy . all ( x ) <EOL> array = [ <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:0.0> , True , False , numpy . nan , numpy . inf , - numpy . inf ] <EOL> for val in array : <EOL> self . assertEqual ( <EOL> f ( val ) , <EOL> self . evaluateWithExecutor ( f , val ) <EOL> ) <EOL> def test_numpy_all_2 ( self ) : <EOL> def f ( x ) : <EOL> return numpy . all ( x ) <EOL> array = [ <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:0.0> , True , False , numpy . nan , numpy . inf , - numpy . inf ] <EOL> for ix in range ( len ( array ) ) : <EOL> sliced_array = array [ : ix ] <EOL> self . assertEqual ( <EOL> f ( sliced_array ) , <EOL> self . evaluateWithExecutor ( f , sliced_array ) , <EOL> msg = str ( sliced_array ) <EOL> ) <EOL> def check_svd ( self , x ) : <EOL> def svd ( a ) : <EOL> return numpy . linalg . svd ( a ) <EOL> pyforaRes = self . evaluateWithExecutor ( svd , x ) <EOL> numpyRes = svd ( x ) <EOL> self . assertEqual ( len ( pyforaRes ) , len ( numpyRes ) ) <EOL> for ix in xrange ( len ( pyforaRes ) ) : <EOL> numpy . testing . assert_allclose ( <EOL> pyforaRes [ ix ] , <EOL> numpyRes [ ix ] <EOL> ) <EOL> def test_svd_1 ( self ) : <EOL> self . check_svd ( numpy . array ( [ [ <NUM_LIT:1> , <NUM_LIT:3> ] , [ <NUM_LIT:2> , <NUM_LIT:4> ] ] ) ) <EOL> def test_isinstance_on_remote ( self ) : <EOL> from pyfora . pure_modules . pure_numpy import PurePythonNumpyArray <EOL> with self . create_executor ( ) as ufora : <EOL> with ufora . remotely : <EOL> a = numpy . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ] ) <EOL> with ufora . remotely . downloadAll ( ) : <EOL> res = isinstance ( a , PurePythonNumpyArray ) <EOL> self . assertTrue ( res ) <EOL> def test_norm_1 ( self ) : <EOL> def f ( x ) : <EOL> return numpy . linalg . norm ( x ) <EOL> x = numpy . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> self . assertEqual ( <EOL> f ( x ) , <EOL> self . evaluateWithExecutor ( f , x ) <EOL> ) <EOL> x = x . reshape ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( <EOL> f ( x ) , <EOL> self . evaluateWithExecutor ( f , x ) <EOL> ) <EOL> def check_lstsq ( self , a , b ) : <EOL> def f ( ) : <EOL> return numpy . linalg . lstsq ( a , b ) <EOL> x1 , resid1 , rank1 , sing1 = f ( ) <EOL> print f ( ) <EOL> x2 , resid2 , rank2 , sing2 = self . evaluateWithExecutor ( f ) <EOL> numpy . testing . assert_allclose ( x1 , x2 ) <EOL> numpy . testing . assert_almost_equal ( resid1 , resid2 ) <EOL> numpy . testing . assert_allclose ( rank1 , rank2 ) <EOL> numpy . testing . assert_allclose ( sing1 , sing2 ) <EOL> def test_lstsq_1 ( self ) : <EOL> a = numpy . array ( [ [ <NUM_LIT:1.> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> b = numpy . array ( [ <NUM_LIT> , <NUM_LIT:1.> , <NUM_LIT> ] ) <EOL> self . check_lstsq ( a , b ) <EOL> def test_lstsq_2 ( self ) : <EOL> a = numpy . array ( [ [ <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> b = numpy . array ( [ <NUM_LIT> , <NUM_LIT:1.> ] ) <EOL> self . check_lstsq ( a , b ) <EOL> def test_numpy_eye ( self ) : <EOL> def f ( nRows , nColumns ) : <EOL> return numpy . eye ( nRows , nColumns ) <EOL> self . equivalentEvaluationTest ( f , <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> self . equivalentEvaluationTest ( f , <NUM_LIT:2> , <NUM_LIT:4> ) <EOL> self . equivalentEvaluationTest ( f , <NUM_LIT:5> , <NUM_LIT:3> ) <EOL> def test_numpy_inv_1 ( self ) : <EOL> def f ( x ) : <EOL> return numpy . linalg . inv ( x ) <EOL> x = numpy . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ] ) <EOL> numpy . testing . assert_allclose ( <EOL> f ( x ) , <EOL> self . evaluateWithExecutor ( f , x ) <EOL> ) <EOL> def test_numpy_inv_2 ( self ) : <EOL> def f ( x ) : <EOL> return numpy . linalg . inv ( x ) <EOL> x = numpy . array ( [ [ <NUM_LIT:1> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:1> ] ] ) <EOL> try : <EOL> self . evaluateWithExecutor ( f , x ) <EOL> except Exception as e : <EOL> self . assertEqual ( <EOL> e . remoteException . message , <EOL> "<STR_LIT>" <EOL> ) <EOL> return <EOL> self . assertTrue ( False ) <EOL> def test_numpy_eigh_1 ( self ) : <EOL> def f ( x , uplo = '<STR_LIT:L>' ) : <EOL> return numpy . linalg . eigh ( x ) <EOL> x = numpy . array ( [ [ <NUM_LIT:2> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:1> ] ] ) <EOL> res1 = f ( x ) <EOL> res2 = self . evaluateWithExecutor ( f , x ) <EOL> numpy . testing . assert_allclose ( res1 [ <NUM_LIT:0> ] , res2 [ <NUM_LIT:0> ] ) <EOL> numpy . testing . assert_allclose ( res1 [ <NUM_LIT:1> ] , res1 [ <NUM_LIT:1> ] ) <EOL> def test_numpy_abs ( self ) : <EOL> def f ( x ) : <EOL> return numpy . abs ( x ) <EOL> x = numpy . array ( [ [ - <NUM_LIT> , <NUM_LIT:1.0> ] , [ - <NUM_LIT> , <NUM_LIT:0.0> ] ] ) <EOL> self . equivalentEvaluationTest ( f , x ) </s>
