Skip to content

complex errors on nested arrays #59462

@johroj

Description

@johroj

complex(::AbstractArray{T}) fails when zero(::Type{T}) is not defined. So it fails on for example nested arrays, i.e. complex([[1]]) throws. See

julia/base/complex.jl

Lines 1134 to 1139 in cdd4ac5

function complex(A::AbstractArray{T}) where T
if !isconcretetype(T)
error("`complex` not defined on abstractly-typed arrays; please convert to a more specific type")
end
convert(AbstractArray{typeof(complex(zero(T)))}, A)
end

It seems that real(::AbstractArray{T}), imag(::AbstractArray{T}) and conj(::AbstractArray{T}) uses broadcast_preserving_zero_d instead and this works as expected. See for example

conj(A::AbstractArray) = broadcast_preserving_zero_d(conj, A)

Is there any good why complex uses a different implementation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]complexComplex numbersfeatureIndicates new feature / enhancement requests

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions