-
Notifications
You must be signed in to change notification settings - Fork 74
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
Improve performance of multivector arithmetic by avoiding copies #280
base: master
Are you sure you want to change the base?
Conversation
Check out this pull request on You'll be able to see Jupyter notebook diff and discuss changes. Powered by ReviewNB. |
I'm wondering if actually we should just change the default to |
25a38c1
to
31ff317
Compare
This pull request introduces 1 alert and fixes 6 when merging 31ff317 into a5c9431 - view on LGTM.com new alerts:
fixed alerts:
|
The behavior of `MultiVector(layout, some_array)` has always been to copy `some_array`. This change makes that copy opt-out, via `MultiVector(layout, some_array, copy=False)`. This is used internally by all of the arithmetic operators to avoid unnecessary copies.
31ff317
to
677855e
Compare
@@ -195,8 +195,8 @@ def ga_exp(B): | |||
Fast implementation of the translation and rotation specific exp function | |||
""" | |||
if np.sum(np.abs(B.value)) < np.finfo(float).eps: | |||
return layout.MultiVector(unit_scalar_mv.value) | |||
return layout.MultiVector(val_exp(B.value)) | |||
return layout.MultiVector(unit_scalar_mv.value, copy=False) |
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 might cause problems as the unit_scalar is a constant scoped to the whole file
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.
Indeed - however, I don't think this is any worse than the fact that clifford.g3c.e3
is global, and I could do something careless like
my_vector = e3
my_vector.value[:] = e2.value # whoops, now e3 == e2
Perhaps I'll put my patch in to fix that first - the blades that are part of the predefined algebras should definitely be readonly. I'm not sure if layout.blades
should be though.
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.
omg I hate it
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.
Yeah I have no strong feeling about layout.blades but the predefined blades definitely have to be readonly
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.
eo.value[:] = layout.scalar.value[:]
print("Your CGA is now somewhat PGA")
Let's not merge this till we:
|
Multiplications become roughly 20% faster, and addition 33% faster.
There's now a new
copy
argument to theMultiVector
constructor.Some timings:
Edit: These timings are out of date, and include the effects of #283 which used to be part of this PR. We should retime before merging
After:
Before: