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

Overload accumulate and make types of cumsum consistent with Vector #363

Merged
merged 2 commits into from
May 4, 2024

Conversation

dlfivefifty
Copy link
Member

@jishnub this should simplify BlockArrays v1.0

@dlfivefifty dlfivefifty requested a review from jishnub May 2, 2024 17:07
Copy link

codecov bot commented May 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.90%. Comparing base (45113c3) to head (e947b1c).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #363   +/-   ##
=======================================
  Coverage   99.90%   99.90%           
=======================================
  Files           8        8           
  Lines        1056     1067   +11     
=======================================
+ Hits         1055     1066   +11     
  Misses          1        1           

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

@jishnub
Copy link
Member

jishnub commented May 4, 2024

This seems mostly good. I guess there might be cases where +(v) might not be defined, but a two-term sum is. E.g.:

julia> accumulate(+, fill(CartesianIndex(1,2), 2))
2-element Vector{CartesianIndex{2}}:
 CartesianIndex(1, 2)
 CartesianIndex(2, 4)

julia> accumulate(+, Fill(CartesianIndex(1,2), 2))
ERROR: MethodError: no method matching +(::CartesianIndex{2})

Closest candidates are:
  +(::CartesianIndex{N}, ::CartesianIndex{N}) where N
   @ Base multidimensional.jl:119
  +(::Any, ::Any, ::Any, ::Any...)
   @ Base operators.jl:587
  +(::Complex{Bool}, ::Bool)
   @ Base complex.jl:306
  ...

Stacktrace:
 [1] accumulate(::typeof(+), x::Fill{CartesianIndex{2}, 1, Tuple{Base.OneTo{Int64}}})
   @ FillArrays ~/Dropbox/JuliaPackages/FillArrays.jl/src/FillArrays.jl:590
 [2] top-level scope
   @ REPL[27]:1

However, this seems like a case of a missing method for a CartesianIndex, which shouldn't stop this PR. I suppose +x makes sense for all types that define summation and have an additive identity, as this may be seen as equivalent to zero(x) + x.

@dlfivefifty dlfivefifty merged commit 39df7ec into master May 4, 2024
18 checks passed
@dlfivefifty dlfivefifty deleted the dl/accumulate branch May 4, 2024 17:18
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