JuliaIO / BSON.jl

Other
158 stars 39 forks source link

MultiDim Arrays stored in a BSON file saved on 64-bit not loads on 32-bit system #60

Closed Ayushk4 closed 4 years ago

Ayushk4 commented 4 years ago

This is somewhat similar to #41 .

Here's an MWE - Assume using BSON and using BSON:@save

julia> a = ones(Float32, 2, 2)
2×2 Array{Float32,2}:
 1.0  1.0
 1.0  1.0

julia> @save "saved_on_64bit.bson" a

On a 32-bit system @test BSON.load("saved_on_64bit.bson")[:a] == ones(Float32, 2, 2) gives the following stack trace https://gist.github.com/Ayushk4/2376db8679caa5e9f70c13abe89c981e

This was narrowed down to https://github.com/JuliaIO/BSON.jl/blob/a58c88a14e07d0beed8f56edb79e5cbea7078e00/src/extensions.jl#L80

This seems to be happening because on a 64-bit reshape(ones(Float32, 1, 4), 2, 2) works whereas the following doesn't. Similarly, Int64 doesn't work on 32-bit-

julia> reshape(ones(Float32, 1, 4), Int32(2), Int32(2))
ERROR: MethodError: no method matching reshape(::Array{Float32,2}, ::Int32, ::Int32)

It can be fixed by changing the line to reshape(reinterpret_(d[:type], d[:data]), map(normalize_typeparams, d[:size])...) :.

Versions - BSON v0.2.4 Julia 1.3

Came here from JuliaText/TextAnalysis.jl#180

Ayushk4 commented 4 years ago

I would be happy to send a PR fixing this and adding the tests. The Appveyor script seems to be outdated (Julia 0.6 (?) ), I can update that as well also adding x86 to it.