Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ authors = ["Albin Severinson <albin@severinson.org> and contributors"]
version = "0.3.0"

[deps]
H5Zblosc = "c8ec2601-a99c-407f-b158-e79c03c2f5f7"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
HDF5 = "0.15"
julia = "1"

[extras]
Expand Down
30 changes: 15 additions & 15 deletions src/H5Sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Support for out-of-core sparse arrays backed by a HDF5 file stored on disk. Prov
"""
module H5Sparse

using HDF5, SparseArrays
using HDF5, H5Zblosc, SparseArrays

export H5SparseMatrixCSC

Expand Down Expand Up @@ -66,7 +66,7 @@ struct H5SparseMatrixCSC{Tv, Ti<:Integer, Td<:HDF5.H5DataStore} <: SparseArrays.
name::String # Dataset name, i.e., data is stored in fid[name]
rows::UnitRange{Int} # Subset of rows stored in fid[name] accessible via this instance
cols::UnitRange{Int} # Subset of columns stored in fid[name] accessible via this instance
function H5SparseMatrixCSC(fid::HDF5.H5DataStore, name::AbstractString, rows::UnitRange{Int}, cols::UnitRange{Int}) where {Tv,Ti<:Integer}
function H5SparseMatrixCSC(fid::HDF5.H5DataStore, name::AbstractString, rows::UnitRange{Int}, cols::UnitRange{Int}) # where {Tv,Ti<:Integer}
name in keys(fid) || throw(ArgumentError("$name is not in $fid"))
g = fid[name]
g isa HDF5.Group || throw(ArgumentError("fid[name] is $g, but must be a HDF5.Group"))
Expand All @@ -80,16 +80,16 @@ struct H5SparseMatrixCSC{Tv, Ti<:Integer, Td<:HDF5.H5DataStore} <: SparseArrays.
length(size(g["nzval"])) == 1 || throw(ArgumentError("expected nzval to have 1 dimension, but got $(size(g["nzval"]))"))
eltype(g["colptr"]) == eltype(g["rowval"]) || throw(ArgumentError("colptr has eltype $(g["colptr"])), but rowval has eltype $(g["rowval"]))"))
m, n = g["m"][], g["n"][]
(iszero(m) && first(rows) == 0) || 0 < first(rows) || throw(ArgumentError("first row is $(first(rows)), but m is $m"))
(iszero(m) && last(rows) == 0) || 0 < last(rows) || throw(ArgumentError("last row is $(last(rows)), but m is $m"))
first(rows) <= m || throw(ArgumentError("first row is $(first(rows)), but m is $m"))
last(rows) <= m || throw(ArgumentError("last row is $(last(rows)), but m is $m"))
first(rows) <= last(rows) || throw(ArgumentError("first row is $(first(rows)), but last row is $(last(rows))"))
(iszero(n) && first(cols) == 0) || 0 < first(cols) || throw(ArgumentError("first column is $(first(cols)), but n is $n"))
(iszero(n) && last(cols) == 0) || 0 < last(cols) || throw(ArgumentError("last column is $(last(cols)), but n is $n"))
first(cols) <= n || throw(ArgumentError("first column is $(first(cols)), but n is $n"))
last(cols) <= n || throw(ArgumentError("last column is $(last(cols)), but n is $n"))
first(cols) <= last(cols) || throw(ArgumentError("first columns is $(first(cols)), but last column is $(last(cols))"))
if m==0
rows==1:0 || throw(ArgumentError("0-row matrix must have rows==1:0"))
else
0 < first(rows) <= last(rows) <= m || throw(ArgumentError("rows is $rows, not in 1:$m"))
end
if n==0
cols==1:0 || throw(ArgumentError("0-column matrix must have cols==1:0"))
else
0 < first(cols) <= last(cols) <= n || throw(ArgumentError("cols is $cols, not in 1:$n"))
end
new{eltype(g["nzval"]),eltype(g["rowval"]),typeof(fid)}(fid, String(name), rows, cols)
end
end
Expand All @@ -98,8 +98,8 @@ function H5SparseMatrixCSC(fid::HDF5.H5DataStore, name::AbstractString, B::Spars
h5writecsc(fid, name, B; kwargs...)
H5SparseMatrixCSC(
fid, name,
size(B, 1) > 0 ? (1:size(B, 1)) : (0:0),
size(B, 2) > 0 ? (1:size(B, 2)) : (0:0),
size(B, 1) > 0 ? (1:size(B, 1)) : (1:0),
size(B, 2) > 0 ? (1:size(B, 2)) : (1:0),
)
end
function H5SparseMatrixCSC(fid::HDF5.H5DataStore, name::AbstractString)
Expand Down Expand Up @@ -357,4 +357,4 @@ function h5isvalidcsc(filename::AbstractString, name::AbstractString)
end
end

end
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using H5Sparse
using Test
using HDF5, SparseArrays
using HDF5, H5Zblosc, SparseArrays

@testset "H5Sparse.jl" begin
B = sprand(10, 10, 0.5)
Expand Down