-
Notifications
You must be signed in to change notification settings - Fork 143
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
Changes from all commits
1333e09
b3c4f83
df6526a
2285e11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
h5read(filename, name, ur) | ||
end | ||
|
||
function h5writeattr(filename, name::String, data::Dict) | ||
fid = h5open(filename, "r+") | ||
try | ||
|
@@ -845,6 +851,12 @@ root(obj::Union{HDF5Group, HDF5Dataset}) = g_open(file(obj), "/") | |
getindex(parent::Union{HDF5File, HDF5Group}, path::String) = o_open(parent, path) | ||
getindex(dset::HDF5Dataset, name::String) = a_open(dset, name) | ||
getindex(x::HDF5Attributes, name::String) = a_open(x.parent, name) | ||
# getindex for cartesian range | ||
function getindex{N}(dset::HDF5Dataset, cr::CartesianRange{CartesianIndex{N}}) | ||
# transfer to unit range | ||
ur = map((x,y)->x:y, cr.start.I, cr.stop.I) | ||
dset[ur...] | ||
end | ||
|
||
# Path manipulation | ||
function joinpathh5(a::String, b::String) | ||
|
@@ -958,6 +970,15 @@ function setindex!(p::HDF5Properties, val, name::String) | |
funcset(p, val...) | ||
return p | ||
end | ||
|
||
# cartesian range indexing | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why |
||
dset[ur...] = val | ||
end | ||
|
||
# Create a dataset with properties: obj[path, prop1, set1, ...] = val | ||
function setindex!(parent::Union{HDF5File, HDF5Group}, val, path::String, prop1::String, val1, pv...) | ||
if !iseven(length(pv)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using HDF5 | ||
using Base.Test | ||
using Compat | ||
|
||
@testset "cartesian_range" begin | ||
|
||
filename = "$(tempname()).h5" | ||
|
||
h5write(filename, "main", Array(1:10)) | ||
@test h5read(filename, "main", CartesianRange((3:5,))) == [3:5;] | ||
f = h5open(filename,"r+") | ||
dset = f["main"] | ||
# setindex of cartesian range | ||
dset[CartesianRange((3:5,))] = [4:6;] | ||
@test dset[CartesianRange((3:5,))] == [4:6;] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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!) |
||
|
||
close(f) | ||
rm(filename) | ||
|
||
end # end of testset |
There was a problem hiding this comment.
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)
andlast(cr)
thancr.start.I
andcr.stop.I
; in 0.7, the representation of CartesianRange has changed. Indeed, in 0.7 this can just beur = cr.indices
.