Skip to content

Should LinearAlgebra.fzero be declared public? #993

Open
@jishnub

Description

@jishnub

https://github.com/JuliaLang/julia/blob/5e4669c7403c301985f35d2c8754b184cd73ab05/stdlib/LinearAlgebra/src/structuredbroadcast.jl#L142-L151

This method is useful in general, as it allows custom types to hook into the structure-preserving broadcast mechanism without having to define their own methods for each function. As an example:

julia> using FillArrays, LinearAlgebra

julia> Diagonal(1:4) .+ Zeros(4,4)
4×4 Matrix{Float64}:
 1.0  0.0  0.0  0.0
 0.0  2.0  0.0  0.0
 0.0  0.0  3.0  0.0
 0.0  0.0  0.0  4.0

julia> LinearAlgebra.fzero(x::Zeros) = zero(eltype(x))

julia> Diagonal(1:4) .+ Zeros(4,4)
4×4 Diagonal{Float64, Vector{Float64}}:
 1.0            
     2.0        
         3.0    
             4.0

Perhaps this could also be done through an isstructuredmatrix trait that is made public.

cc: @dlfivefifty @dkarrasch

Metadata

Metadata

Assignees

No one assigned

    Labels

    broadcastApplying a function over a collection

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions