-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor LinearCombination #47
Conversation
Codecov Report
@@ Coverage Diff @@
## main #47 +/- ##
==========================================
- Coverage 94.79% 94.50% -0.29%
==========================================
Files 9 9
Lines 96 91 -5
==========================================
- Hits 91 86 -5
Misses 5 5
Continue to review full report at Codecov.
|
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.
Balance is restored - looks good. I don't mind the 0-dimensional array. I just think the default dimension should be flipped.
Should this also have a version bump?
yes, I'm tempted to say patch as this is fixing an inherent inconsistency we should have solved, that includes the 0-dim change. |
Yeah overall I think patch is justified, given the previous related PR and the main docs describing what |
Follow up to #45
This PR aligns the convention for
dims
used byLinearCombination
with that of the rest of the package.It also decouples the tests to make them independent with some minor refactoring to the code (renaming
x
->A
) to make it more consistent with other files.There is one other change implemented in 5220430, which might be controversial and/or out of scope but it came up in the refactoring so I'll put it here for comment.
The basic idea is that a reduction operation should reduce the dimension of the input by 1.
That is, an N-dimensional array input should be reduced to an (N-1)-dimensional output.
This really only gets interesting when the input is a vector and N=1. Intuitively, one expects the result of this to be a scalar. But Julia actually returns a 0-dimensional array, which as far as I understand are like magic scalars? As in, you can pass them to another function by reference but they also support array-arithmetic. See:
(I think this also makes this function type-stable since it always returns an Array?)
In any case,
main
currently returns a 1-d vector, which is definitely inconsistent given the reasoning above if you ask me.The question is: do we trust Julia to return a 0-dim array, or do we want to override it and return a scalar explicitly?
background
Note that we want to emulate
sum(A; dims=d)
behaviour, that is, compute the linear combination and reduce over dimensiond
.main
currently gives the opposite result:this branch gives correct result:
The changes also makes this much more performant.
See previous benchmarks for setup: