Skip to content

Commit

Permalink
Add rmul!
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed May 17, 2018
1 parent bd30333 commit 1d7d7cf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ Currently, the `@compat` macro supports the following syntaxes:

* `Compat.qr` takes `pivot` as a `Val` _instance_ and keyword argument `full` ([#22475], [#24279]).

* `Compat.rmul!` provides a subset of the functionality of `LinearAlgebra.rmul!` for
use with Julia 0.6 ([#25701], [#25812]).

## Renaming

* `Display` is now `AbstractDisplay` ([#24831]).
Expand Down Expand Up @@ -607,10 +610,12 @@ includes this fix. Find the minimum version from there.
[#25647]: https://github.com/JuliaLang/julia/issues/25647
[#25654]: https://github.com/JuliaLang/julia/issues/25654
[#25662]: https://github.com/JuliaLang/julia/issues/25662
[#25701]: https://github.com/JuliaLang/julia/issues/25701
[#25705]: https://github.com/JuliaLang/julia/issues/25705
[#25706]: https://github.com/JuliaLang/julia/issues/25706
[#25738]: https://github.com/JuliaLang/julia/issues/25738
[#25780]: https://github.com/JuliaLang/julia/issues/25780
[#25812]: https://github.com/JuliaLang/julia/issues/25812
[#25819]: https://github.com/JuliaLang/julia/issues/25819
[#25873]: https://github.com/JuliaLang/julia/issues/25873
[#25896]: https://github.com/JuliaLang/julia/issues/25896
Expand Down
25 changes: 25 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,31 @@ else
using LinearAlgebra: qr
end

# rmul! (NOTE: Purposefully not exported)
if VERSION < v"0.7.0-DEV.3563" # scale! not deprecated
if VERSION >= v"0.7.0-DEV.3449" # LinearAlgebra in the stdlib
using LinearAlgebra: UnitUpperTriangular, UnitLowerTriangular, scale!
else
using Base.LinAlg: UnitUpperTriangular, UnitLowerTriangular, scale!
end
const Triangle = Union{UpperTriangular, UnitUpperTriangular,
LowerTriangular, UnitLowerTriangular}
if VERSION < v"0.7.0-DEV.3204" # A_mul_B! not deprecated
rmul!(A::AbstractMatrix, B::Triangle) = A_mul_B!(A, A, B)
else
rmul!(A::AbstractMatrix, B::Triangle) = mul!(A, A, B)
end
rmul!(A::AbstractArray, s::Number) = scale!(A, s)
rmul!(A::AbstractMatrix, D::Diagonal) = scale!(A, D.diag)
rmul!(A::Diagonal, B::Diagonal) = Diagonal(A.diag .*= B.diag)
rmul!(A::Triangle, B::Diagonal) = typeof(A)(rmul!(A.data, B))
elseif v"0.7.0-DEV.3563" <= VERSION < v"0.7.0-DEV.3665" # scale! -> mul1!
using LinearAlgebra: mul1!
const rmul! = mul1!
elseif VERSION >= v"0.7.0-DEV.3665" # mul1! -> rmul!
using LinearAlgebra: rmul!
end

# https://github.com/JuliaLang/julia/pull/27077
@static if VERSION < v"0.7.0-DEV.5087"
export isletter
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,14 @@ let A = [1 2; 1 2; 1 2]
@test f[1] * [f[2]; [0 0]] A[:,f[3]]
end

let A = [1 2; 3 4]
@test rmul!(A, 2) == [2 4; 6 8]
@test rmul!(A, Diagonal([1, 2])) == [2 8; 6 16]
@test rmul!(A, UpperTriangular([2 2; 3 3])) == [4 28; 12 60]
@test rmul!(LowerTriangular(A), Diagonal([1, 2])) == LowerTriangular([4 0; 12 120])
@test rmul!(Diagonal(A), Diagonal([2, 1])) == Diagonal([8, 120])
end

# 0.7.0-DEV.5087
@test isletter('a')
@test isletter('β')
Expand Down

0 comments on commit 1d7d7cf

Please sign in to comment.