Skip to content

# sympy/sympy

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

# [WIP] Temporary variables in `doprint_loops` #17170

Open
wants to merge 1 commit into
from

## Conversation

Contributor

### anpandey commented Jul 9, 2019

#### Brief description of what is fixed or changed

This PR currently only changes the behavior of `_doprint_loops` so that contractions within `Indexed` objects are assigned to a temporary variable before being printed. The goal is to allow the printing of expressions with multiple dummies.

This was the previous behavior:

```>>> from sympy.codegen.ast import Assignment
>>> n = symbols('n', integer=True)
>>> A, B, C = symbols('A:C', cls=IndexedBase)
>>> i, j, k = Idx('i', n), Idx('j', n), Idx('k', n)
>>> assign = Assignment(C[i, k], A[i, j] * B[j, k])
>>> print(ccode(assign))
for (int i=0; i<n; i++){
for (int k=0; k<n; k++){
C[n*i + k] = 0;
}
}
for (int i=0; i<n; i++){
for (int k=0; k<n; k++){
for (int j=0; j<n; j++){
C[n*i + k] = A[n*i + j]*B[n*j + k] + C[n*i + k];
}
}
}```

The output of `ccode` is now:

```for (int i=0; i<n; i++){
for (int k=0; k<n; k++){
C[n*i + k] = 0;
}
}
for (int i=0; i<n; i++){
for (int k=0; k<n; k++){
float accum_2330144 = 0;
for (int j=0; j<n; j++){
accum_2330144 += A[n*i + j]*B[n*j + k];
}
C[n*i + k] = accum_2330144;
}
}```

#### Release Notes

``` Use temporary variable in `doprint_loops` ```
``` 00696df ```

### sympy-bot commented Jul 9, 2019

 Hi, I am the SymPy bot (v147). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. ❌ There was an issue with the release notes. Please do not close this pull request; instead edit the description after reading the guide on how to write release notes. No release notes were found. Please edit the PR description and write the release notes under ``. Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it. Click here to see the pull request description that was parsed. ``````#### Brief description of what is fixed or changed This PR currently only changes the behavior of `_doprint_loops` so that contractions within `Indexed` objects are assigned to a temporary variable before being printed. The goal is to allow the printing of expressions with multiple dummies. This was the previous behavior: ```python >>> from sympy.codegen.ast import Assignment >>> n = symbols('n', integer=True) >>> A, B, C = symbols('A:C', cls=IndexedBase) >>> i, j, k = Idx('i', n), Idx('j', n), Idx('k', n) >>> assign = Assignment(C[i, k], A[i, j] * B[j, k]) >>> print(ccode(assign)) for (int i=0; i ``````

Member

### asmeurer commented Jul 17, 2019

 As we discussed in zulip, it would be helpful to have a more insightful example here. The example given doesn't actually change anything by using an accumulator variable.
to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.