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

Resolve deprecation warnings for v0.7 #86

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ce68214
Resolve deprecation warnings for v0.7
halleysfifthinc Jul 30, 2018
4bf5b9b
Drop v0.5 and v0.6, add v0.7
halleysfifthinc Jul 30, 2018
497519e
Remove precompile statement
halleysfifthinc Aug 1, 2018
412151e
Make MatlabString const (Only used as a singleton)
halleysfifthinc Aug 1, 2018
de295c2
Update .travis.yml
halleysfifthinc Aug 27, 2018
439f035
Fix HDF5 build hang on OSX
halleysfifthinc Aug 27, 2018
27fae3d
Didn't work
halleysfifthinc Aug 27, 2018
abdcc68
Take #2 to fix Travis on OSX
halleysfifthinc Aug 27, 2018
d974cdc
Update REQUIRE
halleysfifthinc Aug 27, 2018
1ea692b
Fix Complex reads
halleysfifthinc Sep 6, 2018
ccad554
Avoid copying string
halleysfifthinc Sep 19, 2018
3f090ae
Simplify read_complex
halleysfifthinc Sep 19, 2018
835bf4b
Simplify read(obj, ::Type{Array{Bool}})
halleysfifthinc Sep 19, 2018
c40d0e0
Add two more tests for complex writes
halleysfifthinc Sep 19, 2018
4cf604e
Simplify m_writearray
halleysfifthinc Sep 19, 2018
da1cdaf
Simplify silly bit-twiddling in m_write
halleysfifthinc Sep 19, 2018
c60910b
Change potentially costly length call
halleysfifthinc Sep 19, 2018
c9a85b9
Preserve magic and identifier during unsafe copy
halleysfifthinc Sep 20, 2018
fbbde1b
Fix extra copies in read(obj, ::Type{Array{Bool}})
halleysfifthinc Sep 20, 2018
a1e7ae6
Fix extra copies in read_matrix
halleysfifthinc Sep 20, 2018
a5a874e
Resolve deprecation warnings for v0.7
halleysfifthinc Jul 30, 2018
a221115
Drop v0.6
halleysfifthinc Jul 30, 2018
a1fc40c
Remove precompile statement
halleysfifthinc Aug 1, 2018
c65debe
Make MatlabString const (Only used as a singleton)
halleysfifthinc Aug 1, 2018
e5998ae
Update .travis.yml
halleysfifthinc Aug 27, 2018
33f7418
Fix HDF5 build hang on OSX
halleysfifthinc Aug 27, 2018
9d6ce95
Didn't work
halleysfifthinc Aug 27, 2018
044bda6
Take #2 to fix Travis on OSX
halleysfifthinc Aug 27, 2018
3471b03
Fix Complex reads
halleysfifthinc Sep 6, 2018
a60bf9c
Avoid copying string
halleysfifthinc Sep 19, 2018
8a1d2d4
Simplify read_complex
halleysfifthinc Sep 19, 2018
8286039
Simplify read(obj, ::Type{Array{Bool}})
halleysfifthinc Sep 19, 2018
e056598
Add two more tests for complex writes
halleysfifthinc Sep 19, 2018
43facae
Simplify m_writearray
halleysfifthinc Sep 19, 2018
02de0ed
Simplify silly bit-twiddling in m_write
halleysfifthinc Sep 19, 2018
aa3e95a
Change potentially costly length call
halleysfifthinc Sep 19, 2018
7796d77
Preserve magic and identifier during unsafe copy
halleysfifthinc Sep 20, 2018
6138fcd
Fix extra copies in read(obj, ::Type{Array{Bool}})
halleysfifthinc Sep 20, 2018
227d129
Fix extra copies in read_matrix
halleysfifthinc Sep 20, 2018
faa1e9f
Fix extra copies
nicoleepp Nov 22, 2018
d922093
Fix the last two remaining copies
halleysfifthinc Nov 22, 2018
fe0cdae
Merge branch 'ne/fix-copies' into v0.7-update
halleysfifthinc Nov 22, 2018
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
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ os:
- linux
- osx
julia:
- 0.5
- 0.6
- 0.7
- 1.0
- nightly
addons:
apt:
packages:
- hdf5-tools
before_script:
- if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; brew link --overwrite gcc; brew install hdf5; fi
notifications:
email: false
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone(pwd()); Pkg.build("MAT"); Pkg.test("MAT"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("MAT")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.5
julia 0.7-beta2
Copy link
Member

Choose a reason for hiding this comment

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

just julia 0.7

HDF5
BufferedStreams 0.2.0
Libz
Expand Down
10 changes: 4 additions & 6 deletions src/MAT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

VERSION >= v"0.4.0-dev+6521" && __precompile__()

module MAT

using HDF5, Compat
using HDF5, Compat, SparseArrays

include("MAT_HDF5.jl")
include("MAT_v5.jl")
Expand All @@ -53,7 +51,7 @@ function matopen(filename::AbstractString, rd::Bool, wr::Bool, cr::Bool, tr::Boo
rawfid = open(filename, "r")

# Check for MAT v4 file
magic = read!(rawfid, Vector{UInt8}(4))
magic = read!(rawfid, Vector{UInt8}(undef, 4))
for i = 1:length(magic)
if magic[i] == 0
close(rawfid)
Expand All @@ -76,7 +74,7 @@ function matopen(filename::AbstractString, rd::Bool, wr::Bool, cr::Bool, tr::Boo
# Check for HDF5 file
for offset = 512:512:fs-8
seek(rawfid, offset)
if read!(rawfid, Vector{UInt8}(8)) == HDF5_HEADER
if read!(rawfid, Vector{UInt8}(undef, 8)) == HDF5_HEADER
close(rawfid)
return MAT_HDF5.matopen(filename, rd, wr, cr, tr, ff)
end
Expand Down Expand Up @@ -143,7 +141,7 @@ end
Write a dictionary containing variable names as keys and values as values
to a Matlab file, opening and closing it automatically.
"""
function matwrite{S, T}(filename::AbstractString, dict::Associative{S, T})
function matwrite(filename::AbstractString, dict::AbstractDict{S, T}) where {S, T}
file = matopen(filename, "w")
try
for (k, v) in dict
Expand Down
52 changes: 26 additions & 26 deletions src/MAT_HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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]]
Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

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

The issue is that you don't want to broadcast on toarray because it can be called on arrays, (which is supposed to be a no-op), but broadcasting would return an array of arrays, which is not the intent. Additionally, the two methods dealing with Bool aren't doing the same thing. toarray(::Bool) is both converting to UInt8 and wrapping in an array, while toarray(::Array{Bool}) is just converting to UInt8. (Or did I misunderstand what you were referring to?)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean this is a copy that didn't exist before.

Copy link
Author

Choose a reason for hiding this comment

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

Just to be clear, you are referring to the broadcasted reinterpret?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes.

Choose a reason for hiding this comment

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

Can this be solved by simply doing toarray(x::Array{Bool}) = Array{UInt8}(x)?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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")
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -532,7 +532,7 @@ end

## Type conversion operations ##

type MatlabString; end
struct MatlabString end

const str2type_matlab = Dict(
"canonical empty" => nothing,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading