Skip to content
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

Flatten and unflatten by reshaping when possible #154

Closed
wants to merge 3 commits into from

Conversation

alexfikl
Copy link
Collaborator

@alexfikl alexfikl commented Apr 8, 2021

Is this sort of what you hand in mind in inducer/pytential#71 (comment)?
It seems to do the trick, i.e. flatten and unflatten don't show up anywhere near the top of any profiling (for a single group mesh at least).

# NOTE: arrays with one group are common enough and don't require any
# concatenation to "flatten", but can just be reshaped
if len(ary) == 1:
return list(ary)[0].reshape(-1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be safe, I think it'd be useful to verify the memory layout using the strides here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to do something like that, but wasn't sure how it would interfere with the lazy stuff. Would adding an actx.np.reshape and reusing this make more sense?

meshmode/dof_array.py Outdated Show resolved Hide resolved
Comment on lines 501 to 509
if len(ary) == 1:
ary0 = list(ary)[0]
if ary0.flags.c_contiguous:
return ary0.reshape(-1, order="C")
elif ary0.flags.f_contiguous:
return ary0.reshape(-1, order="F")
else:
# NOTE: array has unsupported strides, so we need to do a copy
pass
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't correct. The existing array can be reshaped if and only if the strides are (itemsize*nunit_dofs_per_element, itemsize). (Note that subclassing array contexts might do weird things like introduce extra dimensions.)

@inducer
Copy link
Owner

inducer commented Apr 13, 2021

Unsubscribing... @-mention or request review once it's ready for a look or needs attention.

Co-authored-by: Andreas Klöckner <inform@tiker.net>
@inducer inducer mentioned this pull request May 25, 2021
@alexfikl
Copy link
Collaborator Author

This has been graciously continued by @thomasgibson in #192.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants