<s> from sympy . core import ( pi , oo , symbols , Rational , Integer , <EOL> GoldenRatio , EulerGamma , Catalan , Lambda , Dummy , Eq ) <EOL> from sympy . functions import ( Piecewise , sin , cos , Abs , exp , ceiling , sqrt , <EOL> gamma , sign ) <EOL> from sympy . logic import ITE <EOL> from sympy . utilities . pytest import raises <EOL> from sympy . printing . ccode import CCodePrinter <EOL> from sympy . utilities . lambdify import implemented_function <EOL> from sympy . tensor import IndexedBase , Idx <EOL> from sympy . matrices import Matrix , MatrixSymbol <EOL> from sympy import ccode <EOL> x , y , z = symbols ( '<STR_LIT>' ) <EOL> def test_printmethod ( ) : <EOL> class fabs ( Abs ) : <EOL> def _ccode ( self , printer ) : <EOL> return "<STR_LIT>" % printer . _print ( self . args [ <NUM_LIT:0> ] ) <EOL> assert ccode ( fabs ( x ) ) == "<STR_LIT>" <EOL> def test_ccode_sqrt ( ) : <EOL> assert ccode ( sqrt ( x ) ) == "<STR_LIT>" <EOL> assert ccode ( x ** <NUM_LIT:0.5> ) == "<STR_LIT>" <EOL> assert ccode ( sqrt ( x ) ) == "<STR_LIT>" <EOL> def test_ccode_Pow ( ) : <EOL> assert ccode ( x ** <NUM_LIT:3> ) == "<STR_LIT>" <EOL> assert ccode ( x ** ( y ** <NUM_LIT:3> ) ) == "<STR_LIT>" <EOL> g = implemented_function ( '<STR_LIT:g>' , Lambda ( x , <NUM_LIT:2> * x ) ) <EOL> assert ccode ( <NUM_LIT:1> / ( g ( x ) * <NUM_LIT> ) ** ( x - y ** x ) / ( x ** <NUM_LIT:2> + y ) ) == "<STR_LIT>" <EOL> assert ccode ( x ** - <NUM_LIT:1.0> ) == '<STR_LIT>' <EOL> assert ccode ( x ** Rational ( <NUM_LIT:2> , <NUM_LIT:3> ) ) == '<STR_LIT>' <EOL> _cond_cfunc = [ ( lambda base , exp : exp . is_integer , "<STR_LIT>" ) , <EOL> ( lambda base , exp : not exp . is_integer , "<STR_LIT>" ) ] <EOL> assert ccode ( x ** <NUM_LIT:3> , user_functions = { '<STR_LIT>' : _cond_cfunc } ) == '<STR_LIT>' <EOL> assert ccode ( x ** <NUM_LIT> , user_functions = { '<STR_LIT>' : _cond_cfunc } ) == '<STR_LIT>' <EOL> def test_ccode_constants_mathh ( ) : <EOL> assert ccode ( exp ( <NUM_LIT:1> ) ) == "<STR_LIT>" <EOL> assert ccode ( pi ) == "<STR_LIT>" <EOL> assert ccode ( oo ) == "<STR_LIT>" <EOL> assert ccode ( - oo ) == "<STR_LIT>" <EOL> def test_ccode_constants_other ( ) : <EOL> assert ccode ( <NUM_LIT:2> * GoldenRatio ) == "<STR_LIT>" <EOL> assert ccode ( <EOL> <NUM_LIT:2> * Catalan ) == "<STR_LIT>" <EOL> assert ccode ( <NUM_LIT:2> * EulerGamma ) == "<STR_LIT>" <EOL> def test_ccode_Rational ( ) : <EOL> assert ccode ( Rational ( <NUM_LIT:3> , <NUM_LIT:7> ) ) == "<STR_LIT>" <EOL> assert ccode ( Rational ( <NUM_LIT> , <NUM_LIT:9> ) ) == "<STR_LIT:2>" <EOL> assert ccode ( Rational ( <NUM_LIT:3> , - <NUM_LIT:7> ) ) == "<STR_LIT>" <EOL> assert ccode ( Rational ( - <NUM_LIT:3> , - <NUM_LIT:7> ) ) == "<STR_LIT>" <EOL> assert ccode ( x + Rational ( <NUM_LIT:3> , <NUM_LIT:7> ) ) == "<STR_LIT>" <EOL> assert ccode ( Rational ( <NUM_LIT:3> , <NUM_LIT:7> ) * x ) == "<STR_LIT>" <EOL> def test_ccode_Integer ( ) : <EOL> assert ccode ( Integer ( <NUM_LIT> ) ) == "<STR_LIT>" <EOL> assert ccode ( Integer ( - <NUM_LIT:1> ) ) == "<STR_LIT>" <EOL> def test_ccode_functions ( ) : <EOL> assert ccode ( sin ( x ) ** cos ( x ) ) == "<STR_LIT>" <EOL> def test_ccode_inline_function ( ) : <EOL> x = symbols ( '<STR_LIT:x>' ) <EOL> g = implemented_function ( '<STR_LIT:g>' , Lambda ( x , <NUM_LIT:2> * x ) ) <EOL> assert ccode ( g ( x ) ) == "<STR_LIT>" <EOL> g = implemented_function ( '<STR_LIT:g>' , Lambda ( x , <NUM_LIT:2> * x / Catalan ) ) <EOL> assert ccode ( <EOL> g ( x ) ) == "<STR_LIT>" % Catalan . n ( ) <EOL> A = IndexedBase ( '<STR_LIT:A>' ) <EOL> i = Idx ( '<STR_LIT:i>' , symbols ( '<STR_LIT:n>' , integer = True ) ) <EOL> g = implemented_function ( '<STR_LIT:g>' , Lambda ( x , x * ( <NUM_LIT:1> + x ) * ( <NUM_LIT:2> + x ) ) ) <EOL> assert ccode ( g ( A [ i ] ) , assign_to = A [ i ] ) == ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:}>" <EOL> ) <EOL> def test_ccode_exceptions ( ) : <EOL> assert ccode ( ceiling ( x ) ) == "<STR_LIT>" <EOL> assert ccode ( Abs ( x ) ) == "<STR_LIT>" <EOL> assert ccode ( gamma ( x ) ) == "<STR_LIT>" <EOL> def test_ccode_user_functions ( ) : <EOL> x = symbols ( '<STR_LIT:x>' , integer = False ) <EOL> n = symbols ( '<STR_LIT:n>' , integer = True ) <EOL> custom_functions = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ( lambda x : not x . is_integer , "<STR_LIT>" ) , ( lambda x : x . is_integer , "<STR_LIT>" ) ] , <EOL> } <EOL> assert ccode ( ceiling ( x ) , user_functions = custom_functions ) == "<STR_LIT>" <EOL> assert ccode ( Abs ( x ) , user_functions = custom_functions ) == "<STR_LIT>" <EOL> assert ccode ( Abs ( n ) , user_functions = custom_functions ) == "<STR_LIT>" <EOL> def test_ccode_boolean ( ) : <EOL> assert ccode ( x & y ) == "<STR_LIT>" <EOL> assert ccode ( x | y ) == "<STR_LIT>" <EOL> assert ccode ( ~ x ) == "<STR_LIT>" <EOL> assert ccode ( x & y & z ) == "<STR_LIT>" <EOL> assert ccode ( x | y | z ) == "<STR_LIT>" <EOL> assert ccode ( ( x & y ) | z ) == "<STR_LIT>" <EOL> assert ccode ( ( x | y ) & z ) == "<STR_LIT>" <EOL> def test_ccode_Piecewise ( ) : <EOL> expr = Piecewise ( ( x , x < <NUM_LIT:1> ) , ( x ** <NUM_LIT:2> , True ) ) <EOL> assert ccode ( expr ) == ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> assert ccode ( expr , assign_to = "<STR_LIT:c>" ) == ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:}>" ) <EOL> expr = Piecewise ( ( x , x < <NUM_LIT:1> ) , ( x + <NUM_LIT:1> , x < <NUM_LIT:2> ) , ( x ** <NUM_LIT:2> , True ) ) <EOL> assert ccode ( expr ) == ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> assert ccode ( expr , assign_to = '<STR_LIT:c>' ) == ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:}>" ) <EOL> expr = Piecewise ( ( x , x < <NUM_LIT:1> ) , ( x ** <NUM_LIT:2> , x > <NUM_LIT:1> ) , ( sin ( x ) , x > <NUM_LIT:0> ) ) <EOL> raises ( ValueError , lambda : ccode ( expr ) ) <EOL> def test_ccode_Piecewise_deep ( ) : <EOL> p = ccode ( <NUM_LIT:2> * Piecewise ( ( x , x < <NUM_LIT:1> ) , ( x + <NUM_LIT:1> , x < <NUM_LIT:2> ) , ( x ** <NUM_LIT:2> , True ) ) ) <EOL> assert p == ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> expr = x * y * z + x ** <NUM_LIT:2> + y ** <NUM_LIT:2> + Piecewise ( ( <NUM_LIT:0> , x < <NUM_LIT:0.5> ) , ( <NUM_LIT:1> , True ) ) + cos ( z ) - <NUM_LIT:1> <EOL> assert ccode ( expr ) == ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> assert ccode ( expr , assign_to = '<STR_LIT:c>' ) == ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def test_ccode_ITE ( ) : <EOL> expr = ITE ( x < <NUM_LIT:1> , x , x ** <NUM_LIT:2> ) <EOL> assert ccode ( expr ) == ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def test_ccode_settings ( ) : <EOL> raises ( TypeError , lambda : ccode ( sin ( x ) , method = "<STR_LIT>" ) ) <EOL> def test_ccode_Indexed ( ) : <EOL> from sympy . tensor import IndexedBase , Idx <EOL> from sympy import symbols <EOL> n , m , o = symbols ( '<STR_LIT>' , integer = True ) <EOL> i , j , k = Idx ( '<STR_LIT:i>' , n ) , Idx ( '<STR_LIT>' , m ) , Idx ( '<STR_LIT:k>' , o ) <EOL> p = CCodePrinter ( ) <EOL> p . _not_c = set ( ) <EOL> x = IndexedBase ( '<STR_LIT:x>' ) [ j ] <EOL> assert p . _print_Indexed ( x ) == '<STR_LIT>' <EOL> A = IndexedBase ( '<STR_LIT:A>' ) [ i , j ] <EOL> assert p . _print_Indexed ( A ) == '<STR_LIT>' % ( m * i + j ) <EOL> B = IndexedBase ( '<STR_LIT:B>' ) [ i , j , k ] <EOL> assert p . _print_Indexed ( B ) == '<STR_LIT>' % ( i * o * m + j * o + k ) <EOL> assert p . _not_c == set ( ) <EOL> def test_ccode_Indexed_without_looking_for_contraction ( ) : <EOL> len_y = <NUM_LIT:5> <EOL> y = IndexedBase ( '<STR_LIT:y>' , shape = ( len_y , ) ) <EOL> x = IndexedBase ( '<STR_LIT:x>' , shape = ( len_y , ) ) <EOL> Dy = IndexedBase ( '<STR_LIT>' , shape = ( len_y - <NUM_LIT:1> , ) ) <EOL> i = Idx ( '<STR_LIT:i>' , len_y - <NUM_LIT:1> ) <EOL> e = Eq ( Dy [ i ] , ( y [ i + <NUM_LIT:1> ] - y [ i ] ) / ( x [ i + <NUM_LIT:1> ] - x [ i ] ) ) <EOL> code0 = ccode ( e . rhs , assign_to = e . lhs , contract = False ) <EOL> assert code0 == '<STR_LIT>' % ( i + <NUM_LIT:1> , i + <NUM_LIT:1> ) <EOL> def test_ccode_loops_matrix_vector ( ) : <EOL> n , m = symbols ( '<STR_LIT>' , integer = True ) <EOL> A = IndexedBase ( '<STR_LIT:A>' ) <EOL> x = IndexedBase ( '<STR_LIT:x>' ) <EOL> y = IndexedBase ( '<STR_LIT:y>' ) <EOL> i = Idx ( '<STR_LIT:i>' , m ) <EOL> j = Idx ( '<STR_LIT>' , n ) <EOL> s = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( i * n + j ) + '<STR_LIT>' <EOL> '<STR_LIT:}>' <EOL> ) <EOL> c = ccode ( A [ i , j ] * x [ j ] , assign_to = y [ i ] ) <EOL> assert c == s <EOL> def test_dummy_loops ( ) : <EOL> i , m = symbols ( '<STR_LIT>' , integer = True , cls = Dummy ) <EOL> x = IndexedBase ( '<STR_LIT:x>' ) <EOL> y = IndexedBase ( '<STR_LIT:y>' ) <EOL> i = Idx ( i , m ) <EOL> expected = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT:}>' <EOL> ) % { '<STR_LIT>' : i . label . dummy_index , '<STR_LIT>' : m . dummy_index } <EOL> code = ccode ( x [ i ] , assign_to = y [ i ] ) <EOL> assert code == expected <EOL> def test_ccode_loops_add ( ) : <EOL> from sympy . tensor import IndexedBase , Idx <EOL> from sympy import symbols <EOL> n , m = symbols ( '<STR_LIT>' , integer = True ) <EOL> A = IndexedBase ( '<STR_LIT:A>' ) <EOL> x = IndexedBase ( '<STR_LIT:x>' ) <EOL> y = IndexedBase ( '<STR_LIT:y>' ) <EOL> z = IndexedBase ( '<STR_LIT:z>' ) <EOL> i = Idx ( '<STR_LIT:i>' , m ) <EOL> j = Idx ( '<STR_LIT>' , n ) <EOL> s = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( i * n + j ) + '<STR_LIT>' <EOL> '<STR_LIT:}>' <EOL> ) <EOL> c = ccode ( A [ i , j ] * x [ j ] + x [ i ] + z [ i ] , assign_to = y [ i ] ) <EOL> assert c == s <EOL> def test_ccode_loops_multiple_contractions ( ) : <EOL> from sympy . tensor import IndexedBase , Idx <EOL> from sympy import symbols <EOL> n , m , o , p = symbols ( '<STR_LIT>' , integer = True ) <EOL> a = IndexedBase ( '<STR_LIT:a>' ) <EOL> b = IndexedBase ( '<STR_LIT:b>' ) <EOL> y = IndexedBase ( '<STR_LIT:y>' ) <EOL> i = Idx ( '<STR_LIT:i>' , m ) <EOL> j = Idx ( '<STR_LIT>' , n ) <EOL> k = Idx ( '<STR_LIT:k>' , o ) <EOL> l = Idx ( '<STR_LIT:l>' , p ) <EOL> s = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( j * o * p + k * p + l , i * n * o * p + j * o * p + k * p + l ) + '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT:}>' <EOL> ) <EOL> c = ccode ( b [ j , k , l ] * a [ i , j , k , l ] , assign_to = y [ i ] ) <EOL> assert c == s <EOL> def test_ccode_loops_addfactor ( ) : <EOL> from sympy . tensor import IndexedBase , Idx <EOL> from sympy import symbols <EOL> n , m , o , p = symbols ( '<STR_LIT>' , integer = True ) <EOL> a = IndexedBase ( '<STR_LIT:a>' ) <EOL> b = IndexedBase ( '<STR_LIT:b>' ) <EOL> c = IndexedBase ( '<STR_LIT:c>' ) <EOL> y = IndexedBase ( '<STR_LIT:y>' ) <EOL> i = Idx ( '<STR_LIT:i>' , m ) <EOL> j = Idx ( '<STR_LIT>' , n ) <EOL> k = Idx ( '<STR_LIT:k>' , o ) <EOL> l = Idx ( '<STR_LIT:l>' , p ) <EOL> s = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( i * n * o * p + j * o * p + k * p + l , i * n * o * p + j * o * p + k * p + l , j * o * p + k * p + l ) + '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT:}>' <EOL> ) <EOL> c = ccode ( ( a [ i , j , k , l ] + b [ i , j , k , l ] ) * c [ j , k , l ] , assign_to = y [ i ] ) <EOL> assert c == s <EOL> def test_ccode_loops_multiple_terms ( ) : <EOL> from sympy . tensor import IndexedBase , Idx <EOL> from sympy import symbols <EOL> n , m , o , p = symbols ( '<STR_LIT>' , integer = True ) <EOL> a = IndexedBase ( '<STR_LIT:a>' ) <EOL> b = IndexedBase ( '<STR_LIT:b>' ) <EOL> c = IndexedBase ( '<STR_LIT:c>' ) <EOL> y = IndexedBase ( '<STR_LIT:y>' ) <EOL> i = Idx ( '<STR_LIT:i>' , m ) <EOL> j = Idx ( '<STR_LIT>' , n ) <EOL> k = Idx ( '<STR_LIT:k>' , o ) <EOL> s0 = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> s1 = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( i * n * o + j * o + k ) + '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> s2 = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( i * o + k ) + '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> s3 = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( i * n + j ) + '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> c = ccode ( <EOL> b [ j ] * a [ i , j ] + b [ k ] * a [ i , k ] + b [ j ] * b [ k ] * c [ i , j , k ] , assign_to = y [ i ] ) <EOL> assert ( c == s0 + s1 + s2 + s3 [ : - <NUM_LIT:1> ] or <EOL> c == s0 + s1 + s3 + s2 [ : - <NUM_LIT:1> ] or <EOL> c == s0 + s2 + s1 + s3 [ : - <NUM_LIT:1> ] or <EOL> c == s0 + s2 + s3 + s1 [ : - <NUM_LIT:1> ] or <EOL> c == s0 + s3 + s1 + s2 [ : - <NUM_LIT:1> ] or <EOL> c == s0 + s3 + s2 + s1 [ : - <NUM_LIT:1> ] ) <EOL> def test_dereference_printing ( ) : <EOL> expr = x + y + sin ( z ) + z <EOL> assert ccode ( expr , dereference = [ z ] ) == "<STR_LIT>" <EOL> def test_Matrix_printing ( ) : <EOL> mat = Matrix ( [ x * y , Piecewise ( ( <NUM_LIT:2> + x , y > <NUM_LIT:0> ) , ( y , True ) ) , sin ( z ) ] ) <EOL> A = MatrixSymbol ( '<STR_LIT:A>' , <NUM_LIT:3> , <NUM_LIT:1> ) <EOL> assert ccode ( mat , A ) == ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> expr = Piecewise ( ( <NUM_LIT:2> * A [ <NUM_LIT:2> , <NUM_LIT:0> ] , x > <NUM_LIT:0> ) , ( A [ <NUM_LIT:2> , <NUM_LIT:0> ] , True ) ) + sin ( A [ <NUM_LIT:1> , <NUM_LIT:0> ] ) + A [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> assert ccode ( expr ) == ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> q = MatrixSymbol ( '<STR_LIT:q>' , <NUM_LIT:5> , <NUM_LIT:1> ) <EOL> M = MatrixSymbol ( '<STR_LIT:M>' , <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> m = Matrix ( [ [ sin ( q [ <NUM_LIT:1> , <NUM_LIT:0> ] ) , <NUM_LIT:0> , cos ( q [ <NUM_LIT:2> , <NUM_LIT:0> ] ) ] , <EOL> [ q [ <NUM_LIT:1> , <NUM_LIT:0> ] + q [ <NUM_LIT:2> , <NUM_LIT:0> ] , q [ <NUM_LIT:3> , <NUM_LIT:0> ] , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:2> * q [ <NUM_LIT:4> , <NUM_LIT:0> ] / q [ <NUM_LIT:1> , <NUM_LIT:0> ] , sqrt ( q [ <NUM_LIT:0> , <NUM_LIT:0> ] ) + <NUM_LIT:4> , <NUM_LIT:0> ] ] ) <EOL> assert ccode ( m , M ) == ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def test_ccode_reserved_words ( ) : <EOL> x , y = symbols ( '<STR_LIT>' ) <EOL> assert ccode ( y ** <NUM_LIT:2> ) == '<STR_LIT>' <EOL> assert ccode ( x * y ** <NUM_LIT:2> , dereference = [ y ] ) == '<STR_LIT>' <EOL> expected = '<STR_LIT>' <EOL> assert ccode ( y ** <NUM_LIT:2> , reserved_word_suffix = '<STR_LIT>' ) == expected <EOL> with raises ( ValueError ) : <EOL> ccode ( y ** <NUM_LIT:2> , error_on_reserved = True ) <EOL> def test_ccode_sign ( ) : <EOL> expr = sign ( x ) * y <EOL> assert ccode ( expr ) == '<STR_LIT>' <EOL> assert ccode ( expr , '<STR_LIT:z>' ) == '<STR_LIT>' <EOL> assert ccode ( sign ( <NUM_LIT:2> * x + x ** <NUM_LIT:2> ) * x + x ** <NUM_LIT:2> ) == '<STR_LIT>' <EOL> expr = sign ( cos ( x ) ) <EOL> assert ccode ( expr ) == '<STR_LIT>' </s>
