Skip to content

Multiplication by non-square matrix should drop labels #98

@marius311

Description

@marius311

On 0.10.7 I get:

julia> rand(2,3) * ComponentArray(x=[1,2,3])
2-element ComponentVector{Float64} with axis Axis(x = 1:3,):
 3.0820225302525293
 3.921995265502881

julia> [rand(2,3) * ComponentArray(x=[1,2,3])]
1-element Vector{ComponentVector{Float64, Vector{Float64}, Tuple{Axis{(x = 1:3,)}}}}:
Error showing value of type Vector{ComponentVector{Float64, Vector{Float64}, Tuple{Axis{(x = 1:3,)}}}}:
ERROR: BoundsError: attempt to access 2-element Vector{Float64} at index [1:3]

When you multipy a ComponentArray by a rectangular matrix, you've changed the dimensionality so it doesn't make sense to preserve the labels. Additionally, you end up with an object whose labels and actual length are inconsistent, which can lead to e.g. the printing error in the second line.

Afaict the solutions are 1) drop the labels for non-square matrices, although a side-effect is that by definition Matrix * ComponentVector is no longer type stable, or 2) drop the labels for both square and non-square matrices, in which case it can be type stable, and if the user wants labels they need to label the matrix explicilty and hence do ComponentMatrix * ComponentVector. Not sure which is the better choice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingurgentThis needs an immediate fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions