-
Notifications
You must be signed in to change notification settings - Fork 7
GEM: Simplify Indexed tensors #131
New issue
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
base: main
Are you sure you want to change the base?
Conversation
4cff9b4 to
783e0c4
Compare
33c66b4 to
f445d5b
Compare
f445d5b to
de501c1
Compare
d2e362b to
592061e
Compare
1982373 to
4ab1c0d
Compare
4ab1c0d to
b49eb5c
Compare
|
I marked this PR as Draft as you still seem to be debugging. Please mark it as Ready for review when you become confident. |
996f2b4 to
5dfd17d
Compare
|
Tests are passing (modulo known doc/linkcheck failures) https://github.com/firedrakeproject/firedrake/actions/runs/17322729298/job/49186947155 @ksagiyam I feel quite happy with this, could you review? |
| if isinstance(B, Indexed): | ||
| C, = B.children | ||
| kk = B.multiindex | ||
| if not isinstance(C, ComponentTensor): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to avoid ComponentTensor here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is because for ComponentTensor we cannot replace indices if the substitution involves the free indices, for other classes this seems fine.
| if all(isinstance(elem, Indexed) for elem in array.flat): | ||
| tensor = e0.children[0] | ||
| multiindex = tuple(i for i in e0.multiindex if not isinstance(i, Integral)) | ||
| index_shape = tuple(i.extent for i in multiindex if isinstance(i, Index)) | ||
| if index_shape + array.shape + child_shape == tensor.shape: | ||
| if all(elem.children[0] == tensor for elem in array.flat[1:]): | ||
| if all(elem.multiindex == multiindex + idx for idx, elem in numpy.ndenumerate(array)): | ||
| return partial_indexed(tensor, multiindex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should make it more explicit that we are only handling multiindex of the following pattern: (Index, Index, Index, ..., Integral, Integral, ...). It looks the case where we have VariableIndexs, for instance, is handled in a very obscure way.
| slices = tuple(i if isinstance(i, int) else slice(None) for i in multiindex) | ||
| sub = aggregate.array[slices] | ||
| sub = Literal(sub, dtype=aggregate.dtype) if isinstance(aggregate, Constant) else ListTensor(sub) | ||
| return Indexed(sub, tuple(i for i in multiindex if not isinstance(i, int))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is safe. This is a recursion, and, unlike when we use DAGTraverser, the result is not cached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the issue? Are we potentially creating new objects and not freeing memory for the old ones?
| if all((j in kk) and (j not in ff) for j in jj): | ||
| rep = dict(zip(jj, ii)) | ||
| ll = tuple(rep.get(k, k) for k in kk) | ||
| return Indexed(C, ll) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also causes recursion.
No description provided.