Skip to content

Commit

Permalink
Add conj! for arrays of arrays (JuliaLang#53303)
Browse files Browse the repository at this point in the history
Apparently, `broadcast!(conj!, A, A)` is not allocation-free, so I
spelled it out, but perhaps there's a more elegant solution.
  • Loading branch information
dkarrasch committed Feb 13, 2024
1 parent d7b9ac8 commit ba34d89
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions base/abstractarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ julia> A
"""
conj!(A::AbstractArray{<:Number}) = (@inbounds broadcast!(conj, A, A); A)
conj!(x::AbstractArray{<:Real}) = x
conj!(A::AbstractArray) = (foreach(conj!, A); A)

"""
conj(A::AbstractArray)
Expand Down
7 changes: 6 additions & 1 deletion test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2612,7 +2612,7 @@ end
end

@testset "sign, conj[!], ~" begin
local A, B, C
local A, B, C, D, E
A = [-10,0,3]
B = [-10.0,0.0,3.0]
C = [1,im,0]
Expand All @@ -2629,6 +2629,11 @@ end
@test typeof(conj(A)) == Vector{Int}
@test typeof(conj(B)) == Vector{Float64}
@test typeof(conj(C)) == Vector{Complex{Int}}
D = [C copy(C); copy(C) copy(C)]
@test conj(D) == conj!(copy(D))
E = [D, copy(D)]
@test conj(E) == conj!(copy(E))
@test (@allocations conj!(E)) == 0

@test .~A == [9,-1,-4]
@test typeof(.~A) == Vector{Int}
Expand Down

0 comments on commit ba34d89

Please sign in to comment.