-
Notifications
You must be signed in to change notification settings - Fork 72
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
Resolve deprecation warnings for v0.7 #86
Changes from 8 commits
ce68214
4bf5b9b
497519e
412151e
de295c2
439f035
27fae3d
abdcc68
d974cdc
1ea692b
ccad554
3f090ae
835bf4b
c40d0e0
4cf604e
da1cdaf
c60910b
c9a85b9
fbbde1b
a1e7ae6
a5a874e
a221115
a1fc40c
c65debe
e5998ae
33f7418
9d6ce95
044bda6
3471b03
a60bf9c
8a1d2d4
8286039
e056598
43facae
02de0ed
aa3e95a
7796d77
6138fcd
227d129
faa1e9f
d922093
fe0cdae
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
julia 0.5 | ||
julia 0.7-beta2 | ||
HDF5 | ||
BufferedStreams 0.2.0 | ||
Libz | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,15 +28,15 @@ | |
|
||
module MAT_HDF5 | ||
|
||
using HDF5 | ||
using HDF5, SparseArrays | ||
|
||
import Base: read, write, close | ||
import HDF5: names, exists, HDF5ReferenceObj, HDF5BitsKind | ||
|
||
const HDF5Parent = Union{HDF5File, HDF5Group} | ||
const HDF5BitsOrBool = Union{HDF5BitsKind,Bool} | ||
|
||
type MatlabHDF5File <: HDF5.DataFile | ||
mutable struct MatlabHDF5File <: HDF5.DataFile | ||
halleysfifthinc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
plain::HDF5File | ||
toclose::Bool | ||
writeheader::Bool | ||
|
@@ -45,7 +45,7 @@ type MatlabHDF5File <: HDF5.DataFile | |
function MatlabHDF5File(plain, toclose::Bool=true, writeheader::Bool=false, refcounter::Int=0) | ||
f = new(plain, toclose, writeheader, refcounter) | ||
if toclose | ||
finalizer(f, close) | ||
finalizer(close, f) | ||
end | ||
f | ||
end | ||
|
@@ -115,24 +115,24 @@ const sparse_attr_matlab = "MATLAB_sparse" | |
const int_decode_attr_matlab = "MATLAB_int_decode" | ||
|
||
### Reading | ||
function read_complex{T}(dtype::HDF5Datatype, dset::HDF5Dataset, ::Type{Array{T}}) | ||
function read_complex(dtype::HDF5Datatype, dset::HDF5Dataset, ::Type{Array{T}}) where T | ||
if !check_datatype_complex(dtype) | ||
close(dtype) | ||
error("Unrecognized compound data type when reading ", name(dset)) | ||
end | ||
memtype = build_datatype_complex(T) | ||
sz = size(dset) | ||
dbuf = Array{T}(2, sz...) | ||
dbuf = Array{T}(undef, 2, sz...) | ||
st = sizeof(T) | ||
buf = reinterpret(UInt8, dbuf, (2 * st, sz...)) | ||
buf = reshape(reinterpret(UInt8, vec(dbuf)), (2 * st, sz...)) | ||
HDF5.h5d_read(dset.id, memtype.id, HDF5.H5S_ALL, HDF5.H5S_ALL, HDF5.H5P_DEFAULT, buf) | ||
|
||
if T == Float32 | ||
d = reinterpret(Complex64, dbuf, sz) | ||
d = reinterpret(ComplexF32, dbuf, sz) | ||
elseif T == Float64 | ||
d = reinterpret(Complex128, dbuf, sz) | ||
d = collect(reshape(reinterpret(ComplexF64, vec(dbuf)), sz)) | ||
else | ||
d = slicedim(dbuf, 1, 1) + im * slicedim(dbuf, 1, 2) | ||
d = copy(selectdim(dbuf, 1, 1)) + im * copy(selectdim(dbuf, 1, 2)) | ||
end | ||
length(d) == 1 ? d[1] : d | ||
end | ||
|
@@ -146,7 +146,7 @@ function m_read(dset::HDF5Dataset) | |
return "" | ||
else | ||
T = mattype == "canonical empty" ? Union{} : str2eltype_matlab[mattype] | ||
return Array{T}(dims...) | ||
return Array{T}(undef, dims...) | ||
end | ||
end | ||
|
||
|
@@ -155,7 +155,7 @@ function m_read(dset::HDF5Dataset) | |
if mattype == "cell" | ||
# Cell arrays, represented as an array of refs | ||
refs = read(dset, Array{HDF5ReferenceObj}) | ||
out = Array{Any}(size(refs)) | ||
out = Array{Any}(undef, size(refs)) | ||
f = file(dset) | ||
for i = 1:length(refs) | ||
dset = f[refs[i]] | ||
|
@@ -290,12 +290,12 @@ elseif length(s) > 63 | |
end | ||
|
||
toarray(x::Array) = x | ||
toarray(x::Array{Bool}) = reinterpret(UInt8, x) | ||
toarray(x::Array{Bool}) = reinterpret.(UInt8, x) | ||
halleysfifthinc marked this conversation as resolved.
Show resolved
Hide resolved
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. Is this not fixable? It requires looking at what the caller is doing of course. 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 issue is that you don't want to broadcast on 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. I mean this is a copy that didn't exist before. 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. Just to be clear, you are referring to the broadcasted reinterpret? 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. Yes. 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. Can this be solved by simply doing 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. No that s copying |
||
toarray(x::Bool) = UInt8[x] | ||
toarray(x) = [x] | ||
|
||
# Write the MATLAB type string for dset | ||
m_writetypeattr{T}(dset, ::Type{Complex{T}}) = m_writetypeattr(dset, T) | ||
m_writetypeattr(dset, ::Type{Complex{T}}) where T = m_writetypeattr(dset, T) | ||
function m_writetypeattr(dset, T) | ||
if !haskey(type2str_matlab, T) | ||
error("Type ", T, " is not (yet) supported") | ||
|
@@ -324,7 +324,7 @@ function m_writeempty(parent::HDF5Parent, name::String, data::Array) | |
end | ||
|
||
# Write an array to a dataset in a MATLAB file, returning the dataset | ||
function m_writearray{T<:HDF5BitsOrBool}(parent::HDF5Parent, name::String, adata::Array{T}) | ||
function m_writearray(parent::HDF5Parent, name::String, adata::Array{T}) where {T<:HDF5BitsOrBool} | ||
dset, dtype = d_create(parent, name, adata) | ||
try | ||
HDF5.writearray(dset, dtype.id, adata) | ||
|
@@ -336,14 +336,14 @@ function m_writearray{T<:HDF5BitsOrBool}(parent::HDF5Parent, name::String, adata | |
close(dtype) | ||
end | ||
end | ||
function m_writearray{T<:HDF5BitsOrBool}(parent::HDF5Parent, name::String, adata::Array{Complex{T}}) | ||
function m_writearray(parent::HDF5Parent, name::String, adata::Array{Complex{T}}) where {T<:HDF5BitsOrBool} | ||
dtype = build_datatype_complex(T) | ||
try | ||
stype = dataspace(adata) | ||
obj_id = HDF5.h5d_create(parent.id, name, dtype.id, stype.id) | ||
dset = HDF5Dataset(obj_id, file(parent)) | ||
try | ||
arr = reinterpret(T, adata, tuple(2, size(adata)...)) | ||
arr = collect(reshape(reinterpret(T, adata), tuple(2, size(adata)...))) | ||
HDF5.writearray(dset, dtype.id, arr) | ||
catch e | ||
close(dset) | ||
|
@@ -358,7 +358,7 @@ function m_writearray{T<:HDF5BitsOrBool}(parent::HDF5Parent, name::String, adata | |
end | ||
|
||
# Write a scalar or array | ||
function m_write{T<:HDF5BitsOrBool}(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, data::Union{T, Complex{T}, Array{T}, Array{Complex{T}}}) | ||
function m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, data::Union{T, Complex{T}, Array{T}, Array{Complex{T}}}) where {T<:HDF5BitsOrBool} | ||
if isempty(data) | ||
m_writeempty(parent, name, data) | ||
return | ||
|
@@ -372,7 +372,7 @@ function m_write{T<:HDF5BitsOrBool}(mfile::MatlabHDF5File, parent::HDF5Parent, n | |
end | ||
|
||
# Write sparse arrays | ||
function m_write{T}(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, data::SparseMatrixCSC{T}) | ||
function m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, data::SparseMatrixCSC{T}) where T | ||
g = g_create(parent, name) | ||
try | ||
m_writetypeattr(g, T) | ||
|
@@ -425,7 +425,7 @@ function m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, str::A | |
end | ||
|
||
# Write cell arrays | ||
function m_write{T}(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, data::Array{T}) | ||
function m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, data::Array{T}) where T | ||
pathrefs = "/#refs#" | ||
fid = file(parent) | ||
local g | ||
|
@@ -456,7 +456,7 @@ function m_write{T}(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, dat | |
close(a) | ||
end | ||
# Write the items to the reference group | ||
refs = Array{HDF5ReferenceObj}(size(data)) | ||
refs = Array{HDF5ReferenceObj}(undef, size(data)) | ||
for i = 1:length(data) | ||
mfile.refcounter += 1 | ||
itemname = string(mfile.refcounter) | ||
|
@@ -482,7 +482,7 @@ end | |
|
||
# Check that keys are valid for a struct, and convert them to an array of ASCIIStrings | ||
function check_struct_keys(k::Vector) | ||
asckeys = Vector{String}(length(k)) | ||
asckeys = Vector{String}(undef, length(k)) | ||
for i = 1:length(k) | ||
key = k[i] | ||
if !isa(key, AbstractString) | ||
|
@@ -505,7 +505,7 @@ function m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, k::Vec | |
end | ||
|
||
# Write Associative as a struct | ||
m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, s::Associative) = | ||
m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, s::AbstractDict) = | ||
m_write(mfile, parent, name, check_struct_keys(collect(keys(s))), collect(values(s))) | ||
|
||
# Write generic CompositeKind as a struct | ||
|
@@ -532,7 +532,7 @@ end | |
|
||
## Type conversion operations ## | ||
|
||
type MatlabString; end | ||
struct MatlabString end | ||
|
||
const str2type_matlab = Dict( | ||
"canonical empty" => nothing, | ||
|
@@ -590,9 +590,9 @@ function read(obj::HDF5Object, ::Type{MatlabString}) | |
data = reshape(data, sz[2:end]) | ||
end | ||
if ndims(data) == 1 | ||
return convert(String, convert(Vector{Char}, data)) | ||
return String(convert(Vector{Char}, data)) | ||
elseif ndims(data) == 2 | ||
return datap = String[rstrip(convert(String, convert(Vector{Char}, vec(data[i, :])))) for i = 1:size(data, 1)] | ||
return datap = String[rstrip(String(convert(Vector{Char}, vec(data[i, :])))) for i = 1:size(data, 1)] | ||
else | ||
return data | ||
end | ||
|
@@ -603,7 +603,7 @@ function read(obj::HDF5Object, ::Type{Bool}) | |
end | ||
function read(obj::HDF5Object, ::Type{Array{Bool}}) | ||
tf = read(obj, Array{UInt8}) | ||
reinterpret(Bool, tf) | ||
convert(Array{Bool}, reinterpret(Bool, tf)) | ||
end | ||
|
||
## Utilities for handling complex numbers | ||
|
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.
just
julia 0.7