You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On slack it was pointed out that you can't write a binary file to a slice of an Array:
julia> x =rand(3, 3)
3×3 Array{Float64,2}:0.8998220.04397460.9611340.7488550.06870370.2382230.7740790.006397370.224812
julia>open("test.bin", "w") do io
write(io, [1.0, 2.0, 3.0])
end;
julia>open("test.bin", "r") do io
read!(io, x[:,3])
end3-element Array{Float64,1}:1.02.03.0
julia> x
3×3 Array{Float64,2}:0.8998220.04397460.9611340.7488550.06870370.2382230.7740790.006397370.224812
That's of course because the slice creates a copy, so it would be great if we could call read!(io, @view x[:,3]), but the signature of read! doesn't accept it.
Would it make sense to loosen the signature of read! to be something like
read!(s::IO, a::Union{Array{T}, SubArray{T,N,<:Array{T}} where N}) where T
? In this way we could do:
julia>open("test.bin", "r") do io
read!(io, @view x[:,3])
end3-element view(::Array{Float64,2}, :, 3) with eltype Float64:1.02.03.0
julia> x
3×3 Array{Float64,2}:0.8998220.04397461.00.7488550.06870372.00.7740790.006397373.0
Are there perhaps other functions that could benefit from similar loosening?
The text was updated successfully, but these errors were encountered:
On slack it was pointed out that you can't write a binary file to a slice of an Array:
That's of course because the slice creates a copy, so it would be great if we could call
read!(io, @view x[:,3])
, but the signature ofread!
doesn't accept it.Would it make sense to loosen the signature of
read!
to be something like? In this way we could do:
Are there perhaps other functions that could benefit from similar loosening?
The text was updated successfully, but these errors were encountered: