Difficulty writing into array (unsure if intentional)
ParadaCarleton opened this issue Β· comments
Carlos Parada commented
Trying to write into an array gives an error when one of the arrays has a trailing singleton dimension:
julia> table(:, :total) .= sum(pointwise([:loo_score, :naive_score, :overfit]); dims=1)'
ERROR: DimensionMismatch("cannot broadcast array to have fewer dimensions")
Where table(:, :total)
and sum(pointwise([:loo_score, :naive_score, :overfit]); dims=1)'
return:
1-dimensional KeyedArray(NamedDimsArray(...)) with keys:
β criterion β 3-element Vector{Symbol}
And data, 3-element view(::Matrix{Float64}, :, 1) with eltype Float64:
(:loo_score) 2.5e-323
(:naive_score) 5.0e-323
(:overfit) 7.4e-323
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
β statistic β 3-element Vector{Symbol}
β data β 1-element OneTo{Int}
And data, 3Γ1 adjoint(::Matrix{Float64}) with eltype Float64:
(1)
(:loo_score) 69.38414329944844
(:naive_score) 218.93276111448398
(:overfit) 149.54861781503556
This can be left (which would be consistent with Base), or trailing singleton dimensions could be fixed for ease-of-use.
Michael Abbott commented
This is also fixed in Base, where 1.6 had
julia> rand(3) .= ones(1,3)'
ERROR: DimensionMismatch("cannot broadcast array to have fewer dimensions")
now 1.7 has this:
julia> rand(3) .= ones(1,3)'
3-element Vector{Float64}:
1.0
1.0
1.0
julia> wrapdims(rand(3)) .= wrapdims(ones(1,3))'
ERROR: DimensionMismatch("destination axes (Base.OneTo(3),) are not compatible with source axes (Base.OneTo(3), Base.OneTo(1))")
I think your example would also hit the second error here, on 1.7. This one should certainly be fixed here.