JuliaIO / HDF5.jl

Save and load data in the HDF5 file format from Julia
https://juliaio.github.io/HDF5.jl
MIT License
380 stars 138 forks source link

Feature request - add support for SparseMatrixCSC #1131

Open elbert5770 opened 8 months ago

elbert5770 commented 8 months ago
        cell_sparse_def = create_dataset(ga, "cell_sparse", datatype(cell_sparse), dataspace(cell_sparse))
        write(cell_sparse_def,cell_sparse)
MethodError: no method matching strides(::SparseMatrixCSC{Int64, Int64})

Closest candidates are:
  strides(!Matched::SubArray)
   @ Base subarray.jl:360
  strides(!Matched::Union{Base.ReinterpretArray{T, N, S, A, IsReshaped} where {T, N, A<:Union{SubArray{T, N, A, I, true} where {T, N, A<:DenseArray, I<:Union{Tuple{Vararg{Real}}, Tuple{AbstractUnitRange, Vararg{Any}}}}, DenseArray}, IsReshaped, S}, Base.ReshapedArray{T, N, A} where {T, N, A<:Union{Base.ReinterpretArray{T, N, S, A, IsReshaped} where {T, N, A<:Union{SubArray{T, N, A, I, true} where {T, N, A<:DenseArray, I<:Union{Tuple{Vararg{Real}}, Tuple{AbstractUnitRange, Vararg{Any}}}}, DenseArray}, IsReshaped, S}, SubArray{T, N, A, I, true} where {T, N, A<:DenseArray, I<:Union{Tuple{Vararg{Real}}, Tuple{AbstractUnitRange, Vararg{Any}}}}, DenseArray}}, DenseArray})
   @ Base reinterpretarray.jl:173
  strides(!Matched::Base.ReshapedArray)
   @ Base reshapedarray.jl:305
  ...

Stacktrace:
  [1] stride(A::SparseMatrixCSC{Int64, Int64}, k::Int64)
    @ Base .\abstractarray.jl:588
  [2] _check_invalid(dataset::HDF5.Dataset, buf::SparseMatrixCSC{Int64, Int64})
    @ HDF5 C:\Users\elber\.julia\packages\HDF5\Ws1wH\src\datasets.jl:501
  [3] write_dataset(dataset::HDF5.Dataset, memtype::HDF5.Datatype, buf::SparseMatrixCSC{Int64, Int64}, xfer::HDF5.DatasetTransferProperties)     
    @ HDF5 C:\Users\elber\.julia\packages\HDF5\Ws1wH\src\datasets.jl:521
  [4] write_dataset(dataset::HDF5.Dataset, memtype::HDF5.Datatype, buf::SparseMatrixCSC{Int64, Int64})
    @ HDF5 C:\Users\elber\.julia\packages\HDF5\Ws1wH\src\datasets.jl:521
  [5] write(obj::HDF5.Dataset, x::SparseMatrixCSC{Int64, Int64})
    @ HDF5 C:\Users\elber\.julia\packages\HDF5\Ws1wH\src\datasets.jl:335
  [6] (::var"#6#8"{Matrix{Float64}, Matrix{Int64}, Matrix{Float64}, SparseMatrixCSC{Int64, Int64}, Int64, Int64})(file::HDF5.File)
    @ Main C:\Users\elber\Documents\git\MicronsBinder\notebooks\intro\PlyToHdf5_20231107.jl:262
  [7] (::HDF5.var"#17#18"{HDF5.HDF5Context, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, var"#6#8"{Matrix{Float64}, Matrix{Int64}, Matrix{Float64}, SparseMatrixCSC{Int64, Int64}, Int64, Int64}, HDF5.File})()
    @ HDF5 C:\Users\elber\.julia\packages\HDF5\Ws1wH\src\file.jl:101
  [8] task_local_storage(body::HDF5.var"#17#18"{HDF5.HDF5Context, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, var"#6#8"{Matrix{Float64}, Matrix{Int64}, Matrix{Float64}, SparseMatrixCSC{Int64, Int64}, Int64, Int64}, HDF5.File}, key::Symbol, val::HDF5.HDF5Context)
    @ Base .\task.jl:296
  [9] h5open(::var"#6#8"{Matrix{Float64}, Matrix{Int64}, Matrix{Float64}, SparseMatrixCSC{Int64, Int64}, Int64, Int64}, ::String, ::Vararg{String}; context::HDF5.HDF5Context, pv::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ HDF5 C:\Users\elber\.julia\packages\HDF5\Ws1wH\src\file.jl:96
 [10] h5open(::Function, ::String, ::String)
    @ HDF5 C:\Users\elber\.julia\packages\HDF5\Ws1wH\src\file.jl:94
 [11] uniquenode(filename::String)
    @ Main C:\Users\elber\Documents\git\MicronsBinder\notebooks\intro\PlyToHdf5_20231107.jl:238
 [12] job_queue(cell_list::Matrix{Int64})
    @ Main C:\Users\elber\Documents\git\MicronsBinder\notebooks\intro\PlyToHdf5_20231107.jl:462
 [13] top-level scope
    @ C:\Users\elber\Documents\git\MicronsBinder\notebooks\intro\PlyToHdf5_20231107.jl:482
in expression starting at C:\Users\elber\Documents\git\MicronsBinder\notebooks\intro\PlyToHdf5_20231107.jl:482
mkitti commented 8 months ago

This is a bit of tough one. JLD.jl or JLD2.jl might be a better fit for this.