Skip to content

Commit

Permalink
Merge pull request #116 from jrevels/jr/arraydepwarn
Browse files Browse the repository at this point in the history
Array(T, dims...) to Array{T}(dims...) (ref JuliaLang/julia#19989)
  • Loading branch information
tkelman authored Jan 14, 2017
2 parents fc5553c + 6390d55 commit 0cb8489
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 45 deletions.
37 changes: 18 additions & 19 deletions src/JLD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function jldopen(filename::AbstractString, rd::Bool, wr::Bool, cr::Bool, tr::Boo
if sz < 512
error("File size indicates $filename cannot be a Julia data file")
end
magic = Array(UInt8, 512)
magic = Vector{UInt8}(512)
rawfid = open(filename, "r")
try
magic = read!(rawfid, magic)
Expand Down Expand Up @@ -393,8 +393,7 @@ function read(obj::JldDataset)
T = jldatatype(file(obj), dtype)
end
if exists(obj, "dims")
dims = a_read(obj.plain, "dims")
return Array(T, dims...)
return Array{T}(a_read(obj.plain, "dims"))
else
return T[]
end
Expand All @@ -408,7 +407,7 @@ end
read_scalar{T<:BitsKindOrString}(obj::JldDataset, dtype::HDF5Datatype, ::Type{T}) =
read(obj.plain, T)
function read_scalar(obj::JldDataset, dtype::HDF5Datatype, T::Type)
buf = Array(UInt8, sizeof(dtype))
buf = Vector{UInt8}(sizeof(dtype))
HDF5.readarray(obj.plain, dtype.id, buf)
return readas(jlconvert(T, file(obj), pointer(buf)))
end
Expand All @@ -432,7 +431,7 @@ end
if obj.file.mmaparrays && HDF5.iscontiguous(obj.plain) && dsel_id == HDF5.H5S_ALL
readmmap(obj.plain, Array{T})
else
out = Array(T, dims)
out = Array{T}(dims)
HDF5.h5d_read(obj.plain.id, dtype.id, dspace_id, dsel_id, HDF5.H5P_DEFAULT, out)
out
end
Expand All @@ -441,14 +440,14 @@ end
# Arrays of immutables/bitstypes
function read_vals(obj::JldDataset, dtype::HDF5Datatype, T::Type, dspace_id::HDF5.Hid,
dsel_id::HDF5.Hid, dims::@compat Tuple{Vararg{Int}})
out = Array(T, dims)
out = Array{T}(dims)
# Empty objects don't need to be read at all
T.size == 0 && !T.mutable && return out

# Read from file
n = prod(dims)
h5sz = sizeof(dtype)
buf = Array(UInt8, h5sz*n)
buf = Vector{UInt8}(h5sz*n)
HDF5.h5d_read(obj.plain.id, dtype.id, dspace_id, dsel_id, HDF5.H5P_DEFAULT, buf)

f = file(obj)
Expand Down Expand Up @@ -476,10 +475,10 @@ end
# Arrays of references
function read_refs{T}(obj::JldDataset, ::Type{T}, dspace_id::HDF5.Hid, dsel_id::HDF5.Hid,
dims::@compat Tuple{Vararg{Int}})
refs = Array(HDF5ReferenceObj, dims)
refs = Array{HDF5ReferenceObj}(dims)
HDF5.h5d_read(obj.plain.id, HDF5.H5T_STD_REF_OBJ, dspace_id, dsel_id, HDF5.H5P_DEFAULT, refs)

out = Array(T, dims)
out = Array{T}(dims)
f = file(obj)
for i = 1:length(refs)
if refs[i] != HDF5.HDF5ReferenceObj_NULL
Expand Down Expand Up @@ -572,7 +571,7 @@ end
f = file(parent)
dtype = h5fieldtype(f, T, true)
buf = h5convert_array(f, data, dtype, wsession)
dims = convert(Array{HDF5.Hsize, 1}, [reverse(size(data))...])
dims = convert(Vector{HDF5.Hsize}, [reverse(size(data))...])
dspace = dataspace(data)
chunk = HDF5.heuristic_chunk(dtype, size(data))
dprop, dprop_close = dset_create_properties(parent, sizeof(buf),buf, chunk; kargs...)
Expand Down Expand Up @@ -605,7 +604,7 @@ end
function h5convert_array(f::JldFile, data::Array,
dtype::JldDatatype, wsession::JldWriteSession)
if dtype == JLD_REF_TYPE
refs = Array(HDF5ReferenceObj, length(data))
refs = Vector{HDF5ReferenceObj}(length(data))
for i = 1:length(data)
if isassigned(data, i)
refs[i] = write_ref(f, data[i], wsession)
Expand Down Expand Up @@ -633,7 +632,7 @@ function _h5convert_vals(f::JldFile, data::Array,
dtype::JldDatatype, wsession::JldWriteSession)
sz = HDF5.h5t_get_size(dtype)
n = length(data)
buf = Array(UInt8, sz*n)
buf = Vector{UInt8}(sz*n)
offset = pointer(buf)
for i = 1:n
h5convert!(offset, f, data[i], wsession)
Expand Down Expand Up @@ -705,7 +704,7 @@ end
dtype = h5type(f, T, true)
gen_h5convert(f, T)

buf = Array(UInt8, HDF5.h5t_get_size(dtype))
buf = Vector{UInt8}(HDF5.h5t_get_size(dtype))
h5convert!(pointer(buf), file(parent), s, wsession)

dspace = HDF5Dataspace(HDF5.h5s_create(HDF5.H5S_SCALAR))
Expand Down Expand Up @@ -821,8 +820,8 @@ end

function convert{K,V,T}(::Type{AssociativeWrapper{K,V,T}}, d::Associative)
n = length(d)
ks = Array(K, n)
vs = Array(V, n)
ks = Vector{K}(n)
vs = Vector{V}(n)
i = 0
for (k,v) in d
ks[i+=1] = k
Expand Down Expand Up @@ -1115,7 +1114,7 @@ function full_typename(io::IO, file::JldFile, jltype::DataType)
end
end
function full_typename(file::JldFile, x)
io = IOBuffer(Array(UInt8, 64), true, true)
io = IOBuffer(Vector{UInt8}(64), true, true)
truncate(io, 0)
full_typename(io, file, x)
String(take!(io))
Expand Down Expand Up @@ -1152,7 +1151,7 @@ end
macro save(filename, vars...)
if isempty(vars)
# Save all variables in the current module
writeexprs = Array(Expr, 0)
writeexprs = Vector{Expr}(0)
m = current_module()
for vname in names(m)
s = string(vname)
Expand All @@ -1164,7 +1163,7 @@ macro save(filename, vars...)
end
end
else
writeexprs = Array(Expr, length(vars))
writeexprs = Vector{Expr}(length(vars))
for i = 1:length(vars)
writeexprs[i] = :(write(f, $(string(vars[i])), $(esc(vars[i])), wsession))
end
Expand Down Expand Up @@ -1310,7 +1309,7 @@ export
translate,
truncate_module_path

const _runtime_properties = Array(HDF5.HDF5Properties, 1)
const _runtime_properties = Vector{HDF5.HDF5Properties}(1)
compact_properties() = _runtime_properties[1]

function __init__()
Expand Down
29 changes: 14 additions & 15 deletions src/JLD00.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function jldopen(filename::AbstractString, rd::Bool, wr::Bool, cr::Bool, tr::Boo
if sz < 512
error("File size indicates $filename cannot be a Julia data file")
end
magic = Array(UInt8, 512)
magic = Vector{UInt8}(512)
rawfid = open(filename, "r")
try
magic = read!(rawfid, magic)
Expand Down Expand Up @@ -447,7 +447,7 @@ function read(obj::JldDataset, T::DataType)
# Add the parameters
if exists(obj, "TypeParameters")
params = a_read(obj.plain, "TypeParameters")
p = Array(Any, length(params))
p = Vector{Any}(length(params))
for i = 1:length(params)
p[i] = eval(current_module(), parse(params[i]))
end
Expand Down Expand Up @@ -483,7 +483,7 @@ end
# Read an array of references
function getrefs{T}(obj::JldDataset, ::Type{T})
refs = read(obj.plain, Array{HDF5ReferenceObj})
out = Array(T, size(refs))
out = Array{T}(size(refs))
f = file(obj)
for i = 1:length(refs)
if refs[i] != HDF5.HDF5ReferenceObj_NULL
Expand Down Expand Up @@ -511,7 +511,7 @@ end
close(ref)
end
else
out = Array(T, size(refs))
out = Array{T}(size(refs))
for i = 1:length(refs)
ref = f[refs[i]]
try
Expand Down Expand Up @@ -643,7 +643,7 @@ end
grefname = name(gref)
try
# Write the items to the reference group
refs = Array(HDF5ReferenceObj, size(data)...)
refs = Array{HDF5ReferenceObj}(size(data))
# pad with zeros to keep in order
nd = ndigits(length(data))
z = "0"
Expand Down Expand Up @@ -690,9 +690,8 @@ end
return write_composite(parent, name, d)
end
n = length(d)
T = eltype(d)
ks = Array(T[1], n)
vs = Array(T[2], n)
ks = Vector{keytype(d)}(n)
vs = Vector{valtype(d)}(n)
i = 0
for (k,v) in d
ks[i+=1] = k
Expand Down Expand Up @@ -743,7 +742,7 @@ end
if !exists(gtypes, Tname)
# Write names to a dataset, so that other languages reading this file can
# at least create a sensible dict
nametype = Array(String, 2, length(n))
nametype = Matrix{String}(2, length(n))
t = T.types
for i = 1:length(n)
nametype[1, i] = string(n[i])
Expand All @@ -765,7 +764,7 @@ end
close(gtypes)
end
# Write the data
v = Array(Any, length(n))
v = Vector{Any}(length(n))
for i = 1:length(v)
if isdefined(s, n[i])
v[i] = getfield(s, n[i])
Expand Down Expand Up @@ -1027,7 +1026,7 @@ end
macro save(filename, vars...)
if isempty(vars)
# Save all variables in the current module
writeexprs = Array(Expr, 0)
writeexprs = Vector{Expr}(0)
m = current_module()
for vname in names(m)
s = string(vname)
Expand All @@ -1039,7 +1038,7 @@ macro save(filename, vars...)
end
end
else
writeexprs = Array(Expr, length(vars))
writeexprs = Vector{Expr}(length(vars))
for i = 1:length(vars)
writeexprs[i] = :(write(f, $(string(vars[i])), $(esc(vars[i]))))
end
Expand All @@ -1056,8 +1055,8 @@ macro load(filename, vars...)
filename = eval(current_module(), filename)
end
# Load all variables in the top level of the file
readexprs = Array(Expr, 0)
vars = Array(Expr, 0)
readexprs = Vector{Expr}(0)
vars = Vector{Expr}(0)
f = jldopen(filename)
nms = names(f)
for n in nms
Expand All @@ -1074,7 +1073,7 @@ macro load(filename, vars...)
:(close($f))),
Symbol[v.args[1] for v in vars]) # "unescape" vars
else
readexprs = Array(Expr, length(vars))
readexprs = Vector{Expr}(length(vars))
for i = 1:length(vars)
readexprs[i] = :($(esc(vars[i])) = read(f, $(string(vars[i]))))
end
Expand Down
2 changes: 1 addition & 1 deletion src/datafile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ read(f::Base.Callable, parent::DataFile, name::ASCIIString...) =
# Read every variable in the file
function read(f::DataFile)
vars = names(f)
vals = Array(Any, length(vars))
vals = Vector{Any}(length(vars))
for i = 1:length(vars)
vals[i] = read(f, vars[i])
end
Expand Down
8 changes: 4 additions & 4 deletions src/jld_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ end

# Get information about the HDF5 types corresponding to Julia types
function JldTypeInfo(parent::JldFile, types::TypesType, commit::Bool)
dtypes = Array(JldDatatype, length(types))
offsets = Array(Int, length(types))
dtypes = Vector{JldDatatype}(length(types))
offsets = Vector{Int}(length(types))
offset = 0
for i = 1:length(types)
dtype = dtypes[i] = h5fieldtype(parent, types[i], commit)
Expand Down Expand Up @@ -773,8 +773,8 @@ function reconstruct_type(parent::JldFile, dtype::HDF5Datatype, savedname::Abstr
else
# Figure out field names and types
nfields = HDF5.h5t_get_nmembers(dtype.id)
fieldnames = Array(Symbol, nfields)
fieldtypes = Array(Type, nfields)
fieldnames = Vector{Symbol}(nfields)
fieldtypes = Vector{Type}(nfields)
for i = 1:nfields
membername = HDF5.h5t_get_member_name(dtype.id, i-1)
idx = rsearchindex(membername, "_")
Expand Down
2 changes: 1 addition & 1 deletion test/custom_serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ JLD.readas(serdata::MyContainerSerializer) =
function JLD.writeas{T}(data::MyContainer{T})
ids = [obj.id for obj in data.objs]
n = length(data.objs)
vectors = Array(T, 5, n)
vectors = Matrix{T}(5, n)
for i = 1:n
vectors[:,i] = data.objs[i].data
end
Expand Down
10 changes: 5 additions & 5 deletions test/jldtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ typevar_lb = Vector{TypeVar(:U, Integer)}[[1]]
typevar_ub = Vector{TypeVar(:U, Int, Any)}[[1]]
typevar_lb_ub = Vector{TypeVar(:U, Int, Real)}[[1]]
end
undef = Array{Any}(1)
undefs = Array{Any}(2, 2)
undef = Vector{Any}(1)
undefs = Matrix{Any}(2, 2)
ms_undef = MyStruct(0)
# Unexported type:
cpus = Base.Sys.cpu_info()
Expand Down Expand Up @@ -196,17 +196,17 @@ end
padding_test = PaddingTest[PaddingTest(i, i) for i = 1:8]
# Empty arrays of various types and sizes
empty_arr_1 = Int[]
empty_arr_2 = Array(Int, 56, 0)
empty_arr_2 = Matrix{Int}(56, 0)
empty_arr_3 = Any[]
empty_arr_4 = Array{Any}(0, 97)
empty_arr_4 = Matrix{Any}(0, 97)
# Moderately big dataset (which will be mmapped)
bigdata = [1:10000;]
# BigFloats and BigInts
bigints = big(3).^(1:100)
bigfloats = big(3.2).^(1:100)
# None
none = Union{}
nonearr = Array(Union{}, 5)
nonearr = Vector{Union{}}(5)
# nothing/Void
scalar_nothing = nothing
vector_nothing = Union{Int,Void}[1,nothing]
Expand Down

0 comments on commit 0cb8489

Please sign in to comment.