Skip to content

Commit

Permalink
fix abs of complex number (#239)
Browse files Browse the repository at this point in the history
* fix abs of complex number

* Update complex.jl

* Update complex.jl
  • Loading branch information
Pangoraw authored Nov 7, 2024
1 parent 06f2c36 commit c4d0b50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/TracedRNumber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ for (jlop, hloop) in (
(:(Base.sqrt), :sqrt),
)
@eval function $(jlop)(@nospecialize(lhs::TracedRNumber{T})) where {T}
return TracedRNumber{T}(
OutTy = $(hloop === :abs) ? real(T) : T
return TracedRNumber{OutTy}(
(), MLIR.IR.result(MLIR.Dialects.stablehlo.$hloop(lhs.mlir_data), 1)
)
end
Expand Down
6 changes: 6 additions & 0 deletions test/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,9 @@ end
@test @jit(imag(x_concrete)) == imag(x)
end
end

@testset "abs: $T" for T in (Float32, ComplexF32)
x = randn(T, 10)
x_concrete = Reactant.to_rarray(x)
@test @jit(abs.(x_concrete)) abs.(x)
end

0 comments on commit c4d0b50

Please sign in to comment.