Skip to content

abstractarray.jl docs confusion: “storagetype might be a type or a function.” #37226

Closed
@ron-wolf

Description

In the documentation for similar(), the following is written:

julia/base/abstractarray.jl

Lines 711 to 715 in 1c9c241

similar(storagetype, axes)
Create an uninitialized mutable array analogous to that specified by
`storagetype`, but with `axes` specified by the last
argument. `storagetype` might be a type or a function.

What does it mean for storagetype to be a function? I have tried to find a method for similar() that accepts a function for its first argument, but to no avail:

julia> methods(similar, (Any, NTuple))
# 6 methods for generic function "similar":
[1] similar(a::Array{T,N} where N, dims::Tuple{Vararg{Int64,N}}) where {T, N} in Base at array.jl:381
[2] similar(B::BitArray, dims::Tuple{Vararg{Int64,N}} where N) in Base at bitarray.jl:370
[3] similar(S::SharedArrays.SharedArray, dims::Tuple{Vararg{Int64,N}} where N) in SharedArrays at /Users/Ron/Applications/Julia-1.5.app/Contents/Resources/julia/share/julia/stdlib/v1.5/SharedArrays/src/SharedArrays.jl:564
[4] similar(a::AbstractArray{T,N} where N, dims::Tuple) where T in Base at abstractarray.jl:630
[5] similar(::Type{T}, dims::Tuple{Vararg{Int64,N}} where N) where T<:AbstractArray in Base at abstractarray.jl:675
[6] similar(::Type{T}, shape::Tuple{Union{Integer, Base.OneTo},Vararg{Union{Integer, Base.OneTo},N} where N}) where T<:AbstractArray in Base at abstractarray.jl:674

julia> methods(similar, (Any, Vararg{AbstractRange,N} where N))
# 11 methods for generic function "similar":
[] # methods with empty varargs elided
[4] similar(B::BitArray, dims::Int64...) in Base at bitarray.jl:369
[]
[8] similar(A::Test.GenericArray, s::Integer...) in Test at /Users/Ron/Applications/Julia-1.5.app/Contents/Resources/julia/share/julia/stdlib/v1.5/Test/src/Test.jl:1654
[]
[10] similar(a::AbstractArray{T,N} where N, dims::Union{Integer, AbstractUnitRange}...) where T in Base at abstractarray.jl:631
[11] similar(::Type{T}, dims::Union{Integer, AbstractUnitRange}...) where T<:AbstractArray in Base at abstractarray.jl:673

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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