Skip to content

Cannot sum(abs2,x) if x is a 2-dimensional ComponentArray #25

@metanoid

Description

@metanoid

Adapted from documentation:

using ComponentArrays
c = (a=2, b=[1, 2]);
x = ComponentArray(a=1, b=[2, 1, 4], c=c)
x2 = x .* x'
good = sum(abs2, x)
bad = sum(abs2, x2) # fails here
workaround = sum(abs2, getdata(x2)) # succeeds

The fact that the 1-dimensional version works without getdata, but the 2-dimensional form needs it is what tripped me up. Would be nice if the error could be handled automatically, but if not, the workaround is fine.

Error message:
ERROR: MethodError: no method matching abs2(::SubArray{Float64,0,Array{Float64,2},Tuple{Int64,Int64},true})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions