Skip to content

Commit

Permalink
Use addmul! in SparseArrays
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Nov 20, 2018
1 parent c33767b commit 39b9a39
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions stdlib/LinearAlgebra/src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Base: @deprecate, depwarn

@deprecate mul!(C, A, B, α, β) addmul!(C, A, B, α, β)
4 changes: 2 additions & 2 deletions stdlib/SparseArrays/src/SparseArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ using Base.Sort: Forward
using LinearAlgebra

import Base: +, -, *, \, /, &, |, xor, ==
import LinearAlgebra: mul!, ldiv!, rdiv!, cholesky, adjoint!, diag, eigen, dot,
issymmetric, istril, istriu, lu, tr, transpose!, tril!, triu!,
import LinearAlgebra: mul!, addmul!, ldiv!, rdiv!, cholesky, adjoint!, diag,
eigen, dot, issymmetric, istril, istriu, lu, tr, transpose!, tril!, triu!,
cond, diagm, factorize, ishermitian, norm, opnorm, lmul!, rmul!, tril, triu

import Base: @get!, acos, acosd, acot, acotd, acsch, asech, asin, asind, asinh,
Expand Down
6 changes: 3 additions & 3 deletions stdlib/SparseArrays/src/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ end

# In matrix-vector multiplication, the correct orientation of the vector is assumed.

function mul!(C::StridedVecOrMat, A::SparseMatrixCSC, B::StridedVecOrMat, α::Number, β::Number)
function addmul!(C::StridedVecOrMat, A::SparseMatrixCSC, B::StridedVecOrMat, α::Number, β::Number)
A.n == size(B, 1) || throw(DimensionMismatch())
A.m == size(C, 1) || throw(DimensionMismatch())
size(B, 2) == size(C, 2) || throw(DimensionMismatch())
Expand All @@ -53,7 +53,7 @@ end
*(A::SparseMatrixCSC{TA,S}, B::StridedMatrix{Tx}) where {TA,S,Tx} =
(T = promote_type(TA, Tx); mul!(similar(B, T, (A.m, size(B, 2))), A, B, one(T), zero(T)))

function mul!(C::StridedVecOrMat, adjA::Adjoint{<:Any,<:SparseMatrixCSC}, B::StridedVecOrMat, α::Number, β::Number)
function addmul!(C::StridedVecOrMat, adjA::Adjoint{<:Any,<:SparseMatrixCSC}, B::StridedVecOrMat, α::Number, β::Number)
A = adjA.parent
A.n == size(C, 1) || throw(DimensionMismatch())
A.m == size(B, 1) || throw(DimensionMismatch())
Expand All @@ -79,7 +79,7 @@ end
*(adjA::Adjoint{<:Any,<:SparseMatrixCSC{TA,S}}, B::StridedMatrix{Tx}) where {TA,S,Tx} =
(A = adjA.parent; T = promote_type(TA, Tx); mul!(similar(B, T, (A.n, size(B, 2))), adjoint(A), B, one(T), zero(T)))

function mul!(C::StridedVecOrMat, transA::Transpose{<:Any,<:SparseMatrixCSC}, B::StridedVecOrMat, α::Number, β::Number)
function addmul!(C::StridedVecOrMat, transA::Transpose{<:Any,<:SparseMatrixCSC}, B::StridedVecOrMat, α::Number, β::Number)
A = transA.parent
A.n == size(C, 1) || throw(DimensionMismatch())
A.m == size(B, 1) || throw(DimensionMismatch())
Expand Down
6 changes: 3 additions & 3 deletions stdlib/SparseArrays/src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ end
mul!(y::AbstractVector{Ty}, A::StridedMatrix, x::AbstractSparseVector{Tx}) where {Tx,Ty} =
mul!(y, A, x, one(Tx), zero(Ty))

function mul!(y::AbstractVector, A::StridedMatrix, x::AbstractSparseVector, α::Number, β::Number)
function addmul!(y::AbstractVector, A::StridedMatrix, x::AbstractSparseVector, α::Number, β::Number)
@assert !has_offset_axes(y, A, x)
m, n = size(A)
length(x) == n && length(y) == m || throw(DimensionMismatch())
Expand Down Expand Up @@ -1528,7 +1528,7 @@ end
mul!(y::AbstractVector{Ty}, transA::Transpose{<:Any,<:StridedMatrix}, x::AbstractSparseVector{Tx}) where {Tx,Ty} =
(A = transA.parent; mul!(y, transpose(A), x, one(Tx), zero(Ty)))

function mul!(y::AbstractVector, transA::Transpose{<:Any,<:StridedMatrix}, x::AbstractSparseVector, α::Number, β::Number)
function addmul!(y::AbstractVector, transA::Transpose{<:Any,<:StridedMatrix}, x::AbstractSparseVector, α::Number, β::Number)
A = transA.parent
@assert !has_offset_axes(y, A, x)
m, n = size(A)
Expand Down Expand Up @@ -1589,7 +1589,7 @@ end
mul!(y::AbstractVector{Ty}, A::SparseMatrixCSC, x::AbstractSparseVector{Tx}) where {Tx,Ty} =
mul!(y, A, x, one(Tx), zero(Ty))

function mul!(y::AbstractVector, A::SparseMatrixCSC, x::AbstractSparseVector, α::Number, β::Number)
function addmul!(y::AbstractVector, A::SparseMatrixCSC, x::AbstractSparseVector, α::Number, β::Number)
@assert !has_offset_axes(y, A, x)
m, n = size(A)
length(x) == n && length(y) == m || throw(DimensionMismatch())
Expand Down
8 changes: 4 additions & 4 deletions stdlib/SparseArrays/test/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ end
for α in [0.0, 1.0, 2.0], β in [0.0, 0.5, 1.0]
y = rand(9)
rr = α*A*xf + β*y
@test mul!(y, A, x, α, β) === y
@test addmul!(y, A, x, α, β) === y
@test y rr
end
y = A*x
Expand All @@ -835,7 +835,7 @@ end
for α in [0.0, 1.0, 2.0], β in [0.0, 0.5, 1.0]
y = rand(9)
rr = α*A'xf + β*y
@test mul!(y, transpose(A), x, α, β) === y
@test addmul!(y, transpose(A), x, α, β) === y
@test y rr
end
y = *(transpose(A), x)
Expand All @@ -850,7 +850,7 @@ end
for α in [0.0, 1.0, 2.0], β in [0.0, 0.5, 1.0]
y = rand(9)
rr = α*Af*xf + β*y
@test mul!(y, A, x, α, β) === y
@test addmul!(y, A, x, α, β) === y
@test y rr
end
y = SparseArrays.densemv(A, x)
Expand All @@ -864,7 +864,7 @@ end
for α in [0.0, 1.0, 2.0], β in [0.0, 0.5, 1.0]
y = rand(9)
rr = α*Af'xf + β*y
@test mul!(y, transpose(A), x, α, β) === y
@test addmul!(y, transpose(A), x, α, β) === y
@test y rr
end
y = SparseArrays.densemv(A, x; trans='T')
Expand Down

0 comments on commit 39b9a39

Please sign in to comment.