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

sum for OneElement #375

Merged
merged 8 commits into from
Aug 27, 2024
Merged

sum for OneElement #375

merged 8 commits into from
Aug 27, 2024

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Aug 19, 2024

This computes the sum over a OneElement in O(1). Along with the new FillMatrix multiplication method, this also means that we don't need to specialize ::AbstractFillMatrix * ::OneElementVector anymore.

Copy link

codecov bot commented Aug 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.91%. Comparing base (9868632) to head (647c554).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #375   +/-   ##
=======================================
  Coverage   99.90%   99.91%           
=======================================
  Files           8        8           
  Lines        1110     1112    +2     
=======================================
+ Hits         1109     1111    +2     
  Misses          1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dlfivefifty
Copy link
Member

We also want to support dims keyword

but should we be overloading mapreduce directly?

@jishnub
Copy link
Member Author

jishnub commented Aug 21, 2024

In principle, we should be specializing mapreduce, but that's more effort. We can do that in the future and remove this sum specialization. As of now, sum is more useful than other functions.

@dlfivefifty
Copy link
Member

I do think we should support dims. Ie sum(::OneElementMatrix; dims=1) would return a OneElementMatrix

Or at the very least we need tests. Actually I suspect this has broken dims

@dlfivefifty
Copy link
Member

It might be necessary to overload Base._sum to ensure type stability

@jishnub
Copy link
Member Author

jishnub commented Aug 21, 2024

I don't think this has broken dims, as sum(A::OneElement; dims) would fall back to the method for AbstractArrays. We may specialize the method with dims, though.
Currently

julia> A = OneElement(3, 4);

julia> sum(A, dims=1) == sum(Array(A), dims=1)
true

julia> sum(A, dims=2) == sum(Array(A), dims=2)
true

julia> sum(A, dims=1:2) == sum(Array(A), dims=1:2)
true

Is there anything in particular that you think is broken? Also, what type-stability were you referring to? Between the method without dims and the one with it? As such, these are different methods, and each is type-stable by itself, although they return different types.

@dlfivefifty dlfivefifty merged commit 414dba7 into master Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants