Skip to content

Conversation

@awestover
Copy link
Contributor

@awestover awestover commented Apr 2, 2020

I think that prefixsum(ft, x) should give 0 when x<1 instead of an ArgumentError, just like how sum([12,3,4,5,6][1:0]) = 0.
In particular I was editing some code, and I assumed that sum(my_array[1:x]) == prefixsum(FenwickTree(my_array), x) would always be true. I was surprised that it wasn't true for all x, and think that this should be changed.

I think that `prefixsum(ft, x)` should give `0` instead of an ArgumentError, just like how `sum([12,3,4,5,6][1:0]) = 0`.
@codecov
Copy link

codecov bot commented Apr 2, 2020

Codecov Report

Merging #602 into master will increase coverage by 0.1%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #602     +/-   ##
=========================================
+ Coverage   95.04%   95.15%   +0.1%     
=========================================
  Files          33       33             
  Lines        2825     2827      +2     
=========================================
+ Hits         2685     2690      +5     
+ Misses        140      137      -3
Impacted Files Coverage Δ
src/fenwick.jl 96.77% <50%> (-3.23%) ⬇️
src/robin_dict.jl 99.14% <0%> (+1.71%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 774a2a8...f71326e. Read the comment docs.

@eulerkochy
Copy link
Member

cool! I would certainly say that since sum(my_array[1:x]) allows x to be 0, I'm definitely in for this change. Nice catch btw!

Copy link
Member

@eulerkochy eulerkochy left a comment

Choose a reason for hiding this comment

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

Can you add tests for the change? Then I think this PR is good to go!

@eulerkochy eulerkochy changed the title prefixsum(ft, non_positive_integer) = 0 prefixsum for non-positive index in FenwickTree Apr 4, 2020
@eulerkochy eulerkochy added bug Needs tests Tests for the added functionality have not yet been added labels Apr 4, 2020
awestover and others added 3 commits April 4, 2020 00:45
@eulerkochy eulerkochy removed the Needs tests Tests for the added functionality have not yet been added label Apr 4, 2020
Copy link
Member

@eulerkochy eulerkochy left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for your contribution! 😃

@eulerkochy eulerkochy merged commit 8026be0 into JuliaCollections:master Apr 4, 2020
@awestover awestover deleted the patch-1 branch April 7, 2020 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants