Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compat annotation for NaN handling in (l|r)mul! #30361

Merged
merged 4 commits into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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