-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Open
Labels
arrays[a, r, r, a, y, s][a, r, r, a, y, s]complexComplex numbersComplex numbersfeatureIndicates new feature / enhancement requestsIndicates new feature / enhancement requests
Description
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
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
julia/base/abstractarraymath.jl
Line 210 in cdd4ac5
| conj(A::AbstractArray) = broadcast_preserving_zero_d(conj, A) |
Is there any good why complex uses a different implementation?
Metadata
Metadata
Assignees
Labels
arrays[a, r, r, a, y, s][a, r, r, a, y, s]complexComplex numbersComplex numbersfeatureIndicates new feature / enhancement requestsIndicates new feature / enhancement requests