#NEWLINE# def test_loops_c( ) : #NEWLINE# #INDENT# from sympy.tensor import IndexedBase , Idx #NEWLINE# from sympy import symbols #NEWLINE# ( n , m ) = symbols ( 'n m' , integer = True ) #NEWLINE# A = IndexedBase ( 'A' ) #NEWLINE# x = IndexedBase ( 'x' ) #NEWLINE# y = IndexedBase ( 'y' ) #NEWLINE# i = Idx ( 'i' , m ) #NEWLINE# j = Idx ( 'j' , n ) #NEWLINE# ( ( f1 , code ) , ( f2 , interface ) ) = codegen ( ( 'matrix_vector' , Eq ( y [ i ] , ( A [ ( i , j ) ] * x [ j ] ) ) ) , 'C' , 'file' , header = False , empty = False ) #NEWLINE# assert ( f1 == 'file.c' ) #NEWLINE# expected = '#include "file.h"\n#include <math.h>\nvoid matrix_vector(double *A, int m, int n, double *x, double *y) {\n   for (int i=0; i<m; i++){\n      y[i] = 0;\n   }\n   for (int i=0; i<m; i++){\n      for (int j=0; j<n; j++){\n         y[i] = %(rhs)s + y[i];\n      }\n   }\n}\n' #NEWLINE# assert ( ( code == ( expected % { #NEWLINE# #INDENT# 'rhs' : ( 'A[%s]*x[j]' % ( ( i * n ) + j ) ) , #NEWLINE# #UNINDENT# } ) ) or ( code == ( expected % { #NEWLINE# #INDENT# 'rhs' : ( 'A[%s]*x[j]' % ( j + ( i * n ) ) ) , #NEWLINE# #UNINDENT# } ) ) or ( code == ( expected % { #NEWLINE# #INDENT# 'rhs' : ( 'x[j]*A[%s]' % ( ( i * n ) + j ) ) , #NEWLINE# #UNINDENT# } ) ) or ( code == ( j % { #NEWLINE# #INDENT# 'rhs' : ( 'x[j]*A[%s]' % ( j + ( i * n ) ) ) , #NEWLINE# #UNINDENT# } ) ) ) #NEWLINE# assert ( f2 == 'file.h' ) #NEWLINE# assert ( interface == '#ifndef PROJECT__FILE__H\n#define PROJECT__FILE__H\nvoid matrix_vector(double *A, int m, int n, double *x, double *y);\n#endif\n' )