Skip to content

[LinearAlgebra] zero(::ArrayWrapper) should forward to the parent #1050

Open
@MasonProtter

Description

@MasonProtter

So for the various array wrapper types like Symmetric, Hermitian, and Adjoint, we currently don't have a specialized zero method, but instead fall back to the AbstractArray definition which works in terms of similar. That means that e.g. this gives a MMatrix:

julia> using StaticArrays

julia> zero(Symmetric(SA[1 2; 3 4]))
2×2 Symmetric{Int64, MMatrix{2, 2, Int64, 4}} with indices SOneTo(2)×SOneTo(2):
 0  0
 0  0

I think though for these wrapper types, we should be able to define zero (and maybe some other functions?) like

for func in [:zero, #=Any others?=#]
    for Wrapper in [:Symmetric, :Hermitian, :Adjoint, #=Any others?=#]
       @eval Base.:($func)(M::$Wrapper) = $Wrapper($func(parent(M)))
    end
end

to avoid falling back to similar where possible, and make sure that custom methods like zero(::SMatrix) end up getting called instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions