Dear all,

I'm playing around with generating some C code for numerical analysis and 
simulation. The library is good and easy to work with in general, only 
thing I'm not sure so far is how sympy is treating multi-dimensional arrays.

Simple example of what I'm looking for:
sympy code: U[i, j] = U[i, j-1] + U[i, j-2]
C code: U[i][j] = U[i][j-1] + U[i][j-2]

As you see it's pretty much direct substitution of symbols. However in 
order to handle >2D array, I need to replace 
printing.ccode._print_Indexed() with something like below:

def _print_Indexed(self, expr):
    # Array base and append indices
    output = self._print(expr.base.label) + ''.join([ '[' + self._print(x) 
+ ']' for x in expr.indices ])
    return output

The current implementation seems to try to flatten the multi-dimensional 
array into 1D vector, so I will get a 1D array back and I need to supply 
the IndexedBase with its shape:

for i in reversed(range(expr.rank)):
    elem += expr.indices[i]*offset
    offset *= dims[i]
return "%s[%s]" % (self._print(expr.base.label), self._print(elem))

Can someone shed some light on why it is done this way? Thanks vm.

Regards,
-TS

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/2df58b51-b384-4eff-809b-785c1dbe7f19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to