JuliaLang / JuliaLang/LinearAlgebra.jl

Should `LinearAlgebra.fzero` be declared public?

Open
#993 3 comments 0 reactions 0 assignees View on GitHub
broadcast
Dominant language
Julia
Stars
77
Forks
65
Avg merge
3d 23h
Merged PRs (30d)
10

Description

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
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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with stdlib/LinearAlgebra/src/structuredbroadcast.jl, especially the fzero method at lines 142–151, and review how custom types hook into structure-preserving broadcast. Compare making LinearAlgebra.fzero public with exposing an isstructuredmatrix trait, using the FillArrays example as a behavior check. Done means the public extension point is chosen and documented or tested consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.