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

add support for CartesianRange indexing #442

Closed
wants to merge 4 commits into from

Conversation

xiuliren
Copy link

CartesianRange is widely used to handle ranges, adding support of CartesianRange to index the arrays inside dataset could make some implementation easier.

These functions were moved from BigArrays.jl
seung-lab/BigArrays.jl#21

function setindex!{N}(dset::HDF5Dataset, val, cr::CartesianRange{CartesianIndex{N}})
# transfer to unit range
ur = map((x,y)->x:y, cr.start.I, cr.stop.I)
@show ur
Copy link
Member

Choose a reason for hiding this comment

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

why @show ur here ?

@musm
Copy link
Member

musm commented Nov 28, 2017

This functionality seems useful although I am not so sure that the implementation is optimal.

I wonder if anyone else has any comments

@@ -710,6 +710,12 @@ function h5read(filename, name::String, indices::Tuple{Vararg{Union{Range{Int},I
dat
end

function h5read{N}(filename, name::String, cr::CartesianRange{CartesianIndex{N}})
# transfer to unit range
ur = map((x,y)->x:y, cr.start.I, cr.stop.I)
Copy link
Member

Choose a reason for hiding this comment

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

Better to use first(cr) and last(cr) than cr.start.I and cr.stop.I; in 0.7, the representation of CartesianRange has changed. Indeed, in 0.7 this can just be ur = cr.indices.

dset = f["main"]
# setindex of cartesian range
dset[CartesianRange((3:5,))] = [4:6;]
@test dset[CartesianRange((3:5,))] == [4:6;]
Copy link
Contributor

Choose a reason for hiding this comment

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

The tests should cover a case with more than one dimension. Also, why is the correct answer not [3:5;] as you would get with a normal range?

Copy link
Member

Choose a reason for hiding this comment

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

because on line 14 he rewrites elements 3:5 to 4:6 (which is testing setindex!)

@musm musm mentioned this pull request Dec 2, 2017
@musm
Copy link
Member

musm commented Dec 2, 2017

addressed review in #459 (review)

@musm musm closed this Dec 2, 2017
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.

4 participants