Hi all,
I'm trying to get some code generation working, and I was hoping to
get some clarification about how IndexedBase objects work inside
codegen. For instance, with this code:
import sympy
from sympy.utilities.codegen import codegen
A, B, C, D = map(sympy.IndexedBase, "ABCD")
m = sympy.Symbol("m", integer=True)
i = sympy.Idx("i", m)
expr = sympy.Equality(D[i], A[i]*B[i]+C[i])
rv = codegen( ("f1", expr), "C", "temp", header=False)
print rv[0][1]
I would naively expect each element in D to be assigned
A[i]*B[i]+C[i]. However, what comes out of codegen iterates over the
index twice:
[snip]
for (int i=0; i<m; i++){
for (int i=0; i<m; i++){
D[i] = A[i]*B[i] + D[i];
}
}
[/snip]
Everything else looks right, including the assignment to the passed
pointer. If I change the expression to A[i]+C[i], so there's no
multiplication, the loop looks like what I'd expect:
[snip]
for (int i=0; i<m; i++){
D[i] = A[i] + C[i];
}
[/snip]
It looks as though the first expression is potentially trying to
evaluate the components as tensors. Is there a way to modify what I'm
doing in the multiplicative expression to indicate I'm actually
multiplying flat arrays, and get a single loop rather than the double
nested one?
Thanks very much,
Matt
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.