Skip to content

SubArrays cause an illegal naming error #161

@tyleransom

Description

@tyleransom

If I try to save a SubArray (created from the @views macro) to a MAT file, I get an illegal naming error. Consider the following MWE using MAT.jl v0.10.1:

using Random, MAT

Random.seed!(1234)
a = rand(5)
@show a
@show typeof(a)
@views a = a[[1,3,4,2,5]]
@show a
@show typeof(a)

matwrite("test.mat", Dict("a" => a))

This returns the following:

julia> include("MWE.jl")
a = [0.5908446386657102, 0.7667970365022592, 0.5662374165061859, 0.4600853424625171, 0.7940257103317943]
typeof(a) = Array{Float64,1}
a = [0.5908446386657102, 0.5662374165061859, 0.4600853424625171, 0.7667970365022592, 0.7940257103317943]
typeof(a) = SubArray{Float64,1,Array{Float64,1},Tuple{Array{Int64,1}},false}
ERROR: LoadError: Invalid variable name or key "1": variable names must start with a letter and contain only alphanumeric characters and underscore
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] check_valid_varname at /hpc/home/tmr17/.julia/packages/MAT/f523T/src/MAT_HDF5.jl:290 [inlined]
 [3] check_struct_keys(::Array{String,1}) at /hpc/home/tmr17/.julia/packages/MAT/f523T/src/MAT_HDF5.jl:507
 [4] m_write(::MAT.MAT_HDF5.MatlabHDF5File, ::HDF5.Group, ::String, ::Tuple{Array{Int64,1}}) at /hpc/home/tmr17/.julia/packages/MAT/f523T/src/MAT_HDF5.jl:533
 [5] m_write(::MAT.MAT_HDF5.MatlabHDF5File, ::HDF5.File, ::String, ::Array{String,1}, ::Array{Any,1}) at /hpc/home/tmr17/.julia/packages/MAT/f523T/src/MAT_HDF5.jl:518
 [6] m_write(::MAT.MAT_HDF5.MatlabHDF5File, ::HDF5.File, ::String, ::SubArray{Float64,1,Array{Float64,1},Tuple{Array{Int64,1}},false}) at /hpc/home/tmr17/.julia/packages/MAT/f523T/src/MAT_HDF5.jl:533
 [7] write(::MAT.MAT_HDF5.MatlabHDF5File, ::String, ::SubArray{Float64,1,Array{Float64,1},Tuple{Array{Int64,1}},false}) at /hpc/home/tmr17/.julia/packages/MAT/f523T/src/MAT_HDF5.jl:546
 [8] matwrite(::String, ::Dict{String,SubArray{Float64,1,Array{Float64,1},Tuple{Array{Int64,1}},false}}; compress::Bool) at /hpc/home/tmr17/.julia/packages/MAT/f523T/src/MAT.jl:157
 [9] matwrite(::String, ::Dict{String,SubArray{Float64,1,Array{Float64,1},Tuple{Array{Int64,1}},false}}) at /hpc/home/tmr17/.julia/packages/MAT/f523T/src/MAT.jl:148
 [10] top-level scope at /hpc/group/econ/tmr17/DropoutRR/Simulations/BackwardSimMay2020/MWE.jl:11
 [11] include(::String) at ./client.jl:439
 [12] top-level scope at REPL[1]:1
in expression starting at /hpc/group/econ/tmr17/DropoutRR/Simulations/BackwardSimMay2020/MWE.jl:11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions