Skip to content

Commit

Permalink
Add compat annotation for NaN handling in (l|r)mul! (#30361)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf authored and fredrikekre committed Dec 12, 2018
1 parent 8965a81 commit 797ddbb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
28 changes: 26 additions & 2 deletions stdlib/LinearAlgebra/src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ mul!(C::AbstractArray, X::AbstractArray, s::Number) = generic_mul!(C, s, X)
"""
rmul!(A::AbstractArray, b::Number)
Scale an array `A` by a scalar `b` overwriting `A` in-place.
Scale an array `A` by a scalar `b` overwriting `A` in-place. Use
[`lmul!`](@ref) to multiply scalar from left. The scaling operation
respects the semantics of the multiplication [`*`](@ref) between an
element of `A` and `b`. In particular, this also applies to
multiplication involving non-finite numbers such as `NaN` and `±Inf`.
!!! compat "Julia 1.1"
Prior to Julia 1.1, `NaN` and `±Inf` entries in `A` were treated
inconsistently.
# Examples
```jldoctest
Expand All @@ -44,6 +52,10 @@ julia> rmul!(A, 2)
2×2 Array{Int64,2}:
2 4
6 8
julia> rmul!([NaN], 0.0)
1-element Array{Float64,1}:
NaN
```
"""
function rmul!(X::AbstractArray, s::Number)
Expand All @@ -57,7 +69,15 @@ end
"""
lmul!(a::Number, B::AbstractArray)
Scale an array `B` by a scalar `a` overwriting `B` in-place.
Scale an array `B` by a scalar `a` overwriting `B` in-place. Use
[`rmul!`](@ref) to multiply scalar from right. The scaling operation
respects the semantics of the multiplication [`*`](@ref) between `a`
and an element of `B`. In particular, this also applies to
multiplication involving non-finite numbers such as `NaN` and `±Inf`.
!!! compat "Julia 1.1"
Prior to Julia 1.1, `NaN` and `±Inf` entries in `B` were treated
inconsistently.
# Examples
```jldoctest
Expand All @@ -70,6 +90,10 @@ julia> lmul!(2, B)
2×2 Array{Int64,2}:
2 4
6 8
julia> lmul!(0.0, [Inf])
1-element Array{Float64,1}:
NaN
```
"""
function lmul!(s::Number, X::AbstractArray)
Expand Down
12 changes: 12 additions & 0 deletions stdlib/LinearAlgebra/test/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,16 @@ end
@test LinearAlgebra.peakflops() > 0
end

@testset "NaN handling: Issue 28972" begin
@test all(isnan, rmul!([NaN], 0.0))
@test all(isnan, rmul!(Any[NaN], 0.0))
@test all(isnan, lmul!(0.0, [NaN]))
@test all(isnan, lmul!(0.0, Any[NaN]))

@test all(!isnan, rmul!([NaN], false))
@test all(!isnan, rmul!(Any[NaN], false))
@test all(!isnan, lmul!(false, [NaN]))
@test all(!isnan, lmul!(false, Any[NaN]))
end

end # module TestGeneric

0 comments on commit 797ddbb

Please sign in to comment.