Skip to content

axes(bc::Broadcasted) isnt used in the materialize/instantiate #59432

@kunzaatko

Description

@kunzaatko

The method axes(x) is documented under the broadcasting interface.

Note

It would be nice if the documentation was better. It does not specify when axes is used and it is not definitely specified what the argument type is. (i.e. that it should be <: Broadcasted)

However the method is not used for determining the broadcasting axes. Instead Broadcast.combine_axes is used.

julia/base/broadcast.jl

Lines 312 to 314 in 1269be6

if bc.axes isa Nothing # Not done via dispatch to make it easier to extend instantiate(::Broadcasted{Style})
axes = combine_axes(bc.args...)
else

What is the purpose of axes? (This method

julia/base/broadcast.jl

Lines 238 to 244 in 1269be6

@inline Base.axes(bc::Broadcasted) = _axes(bc, bc.axes)
_axes(::Broadcasted, axes::Tuple) = axes
@inline _axes(bc::Broadcasted, ::Nothing) = combine_axes(bc.args...)
_axes(bc::Broadcasted{<:AbstractArrayStyle{0}}, ::Nothing) = ()
@inline Base.axes(bc::Broadcasted{<:Any, <:NTuple{N}}, d::Integer) where N =
d <= N ? axes(bc)[d] : OneTo(1)
)

Is it used anywhere in the broadcasting pipeline? Shouldn't the combine_axes be axes for the user to be able to specify it?

Anyway, it should be better documented in either case...

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]broadcastApplying a function over a collectioniterationInvolves iteration or the iteration protocol

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions