ComponentArrays.jl icon indicating copy to clipboard operation
ComponentArrays.jl copied to clipboard

involuntary squeeze() with vector of vectors.

Open RainerHeintzmann opened this issue 1 year ago • 2 comments

For many applications one-dimensional vectors that are oriented in a certain direction are essential. However, when such vectors are wrapped in a ComponentArray, some mechanism seems to squeeze them when stored as a vector of vectors, such that they are now oriented along the first direction. This makes ComponentArray.jl unsuitable for broadcasting operations on its stored vectors.

julia> a= reshape([1,2,3],(1,3)); b=[a,a]; q = ComponentVector(;q = [1,2], qq=b, ww=[1 2;3 4]); size(q.qq[1])
(3,)
julia> size(b[1])
(1, 3)

RainerHeintzmann avatar Jul 26 '24 12:07 RainerHeintzmann

Seems like any Vector of n-dim array gets flattened

julia> cv = ComponentVector(; x = [ones(2,2), ones(2,2)])
ComponentVector{Float64}(x = SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}[[1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0]])

julia> size(cv.x[1])
(4,)
``

roflmaostc avatar Jul 26 '24 12:07 roflmaostc

I (unfortunately) also ran into this issue. My optimization problem is defined in terms of a variable number of matrices (hence stored as a Vector{Matrix{T}}). As a workaround, I could store dimensions and then reshape manually, but it would make life quite a bit easier if this would be transparent.

eprovst avatar Jan 28 '25 09:01 eprovst