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

Fix map and lastwithindex bugs in ResizableArray #228

Merged
merged 3 commits into from
Apr 19, 2024
Merged

Conversation

wouterwln
Copy link
Member

No description provided.

@wouterwln wouterwln requested a review from bvdmitri April 18, 2024 14:41
@@ -241,7 +244,7 @@ end
function lastwithindex(array::ResizableArray{T, V, N}) where {T, V, N}
for index in reverse(CartesianIndices(reverse(size(array)))) #TODO improve performance of this function since it uses splatting
Copy link
Member

Choose a reason for hiding this comment

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

I think the TODO comment is old, the splatting by itself does not hurt performance, but wrong usage of splatting does. Here everything should be fine imo

@@ -181,14 +181,17 @@ function Base.iterate(array::ResizableArray, state)
return nothing
end
nindex, nstate = niterate
while !isassigned(array, nindex.I...)
Copy link
Member

@bvdmitri bvdmitri Apr 18, 2024

Choose a reason for hiding this comment

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

This might be dangerous, lets discuss tomorrow ?, I didn't do this operation for a reason. Otherwise the zip with a Matrix is error prone. I wanted it to throw an error if something is not assigned. Maybe we should make a special method for map? Or we could add an option to the iterate method to skip things that aren't set, and then map could use that.

Copy link
Member

@bvdmitri bvdmitri Apr 18, 2024

Choose a reason for hiding this comment

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

E.g. this branch:

julia> s = GraphPPL.ResizableArray(Float64, Val(2))
0×0 GraphPPL.ResizableArray{Float64, Vector{Vector{Float64}}, 2}

julia> s[1, 1] = 1.0;
julia> s[2, 2] = 2.0;
julia> s[3, 3] = 3.0;

julia> map(sum, zip(s, Diagonal(ones(3))))
3×3 Matrix{Float64}:
 2.0           2.0  0.0
 2.62258e-314  1.0  0.0
 2.62258e-314  3.0  2.2241e-314

On the main it throws (which is better than silently getting wrong result):

julia> map(sum, zip(s, Diagonal(ones(3))))
ERROR: BoundsError: attempt to access 1-element Vector{Float64} at index [2]

The zip operation is used in ReactiveMP to connect ResizableArray with some data. So a user might give Diagonal data and get some wrong results instead of an error

Copy link

codecov bot commented Apr 18, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 91.07%. Comparing base (c9a744a) to head (775ac69).
Report is 10 commits behind head on main.

Files Patch % Lines
src/resizable_array.jl 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #228      +/-   ##
==========================================
+ Coverage   90.90%   91.07%   +0.17%     
==========================================
  Files          15       15              
  Lines        1979     1995      +16     
==========================================
+ Hits         1799     1817      +18     
+ Misses        180      178       -2     

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

Copy link
Member

@bvdmitri bvdmitri left a comment

Choose a reason for hiding this comment

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

Thanks @wouterwln

@bvdmitri bvdmitri merged commit 2928be9 into main Apr 19, 2024
6 of 7 checks passed
@bvdmitri bvdmitri deleted the resizablearray_bugs branch April 19, 2024 18:48
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