Skip to content

Commit

Permalink
mul!(α, A, x, β, y) -> mul!(y, A, x, a, b) in SparseArrays.jl (#23919) (
Browse files Browse the repository at this point in the history
#26117)

* mul!(α, A, x, β, y) -> mul!(y, A, x, a, b) (#23919)

* missing )
  • Loading branch information
dlfivefifty authored and andreasnoack committed Feb 24, 2018
1 parent 2174801 commit e4b6677
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
16 changes: 8 additions & 8 deletions stdlib/SparseArrays/src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ using LinearAlgebra: Adjoint, Transpose
@deprecate A_mul_B!(C::StridedVecOrMat, A::SparseMatrixCSC, B::StridedVecOrMat) mul!(C, A, B)
@deprecate Ac_mul_B!(C::StridedVecOrMat, A::SparseMatrixCSC, B::StridedVecOrMat) mul!(C, adjoint(A), B)
@deprecate At_mul_B!(C::StridedVecOrMat, A::SparseMatrixCSC, B::StridedVecOrMat) mul!(C, transpose(A), B)
@deprecate A_mul_B!::Number, A::SparseMatrixCSC, B::StridedVecOrMat, β::Number, C::StridedVecOrMat) mul!(α, A, B, β, C)
@deprecate A_mul_B!::Number, A::SparseMatrixCSC, B::StridedVecOrMat, β::Number, C::StridedVecOrMat) mul!(C, A, B, α, β)
@deprecate A_mul_B(A::SparseMatrixCSC{TA,S}, x::StridedVector{Tx}) where {TA,S,Tx} (*)(A, x)
@deprecate A_mul_B(A::SparseMatrixCSC{TA,S}, B::StridedMatrix{Tx}) where {TA,S,Tx} (*)(A, B)
@deprecate Ac_mul_B!::Number, A::SparseMatrixCSC, B::StridedVecOrMat, β::Number, C::StridedVecOrMat) mul!(α, adjoint(A), B, β, C)
@deprecate Ac_mul_B!::Number, A::SparseMatrixCSC, B::StridedVecOrMat, β::Number, C::StridedVecOrMat) mul!(C, adjoint(A), B, α, β)
@deprecate Ac_mul_B(A::SparseMatrixCSC{TA,S}, x::StridedVector{Tx}) where {TA,S,Tx} (*)(adjoint(A), x)
@deprecate Ac_mul_B(A::SparseMatrixCSC{TA,S}, B::StridedMatrix{Tx}) where {TA,S,Tx} (*)(adjoint(A), B)
@deprecate At_mul_B!::Number, A::SparseMatrixCSC, B::StridedVecOrMat, β::Number, C::StridedVecOrMat) mul!(α, transpose(A), B, β, C)
@deprecate At_mul_B!::Number, A::SparseMatrixCSC, B::StridedVecOrMat, β::Number, C::StridedVecOrMat) mul!(C, transpose(A), B, α, β)
@deprecate At_mul_B(A::SparseMatrixCSC{TA,S}, x::StridedVector{Tx}) where {TA,S,Tx} (*)(transpose(A), x)
@deprecate At_mul_B(A::SparseMatrixCSC{TA,S}, B::StridedMatrix{Tx}) where {TA,S,Tx} (*)(transpose(A), B)
@deprecate A_mul_Bt(A::SparseMatrixCSC{TvA,TiA}, B::SparseMatrixCSC{TvB,TiB}) where {TvA,TiA,TvB,TiB} (*)(A, transpose(B))
Expand Down Expand Up @@ -197,16 +197,16 @@ end
using LinearAlgebra: Adjoint, Transpose
@deprecate Ac_mul_B(A::SparseMatrixCSC, x::AbstractSparseVector) (*)(adjoint(A), x)
@deprecate At_mul_B(A::SparseMatrixCSC, x::AbstractSparseVector) (*)(transpose(A), x)
@deprecate Ac_mul_B!::Number, A::SparseMatrixCSC, x::AbstractSparseVector, β::Number, y::StridedVector) mul!(α, adjoint(A), x, β, y)
@deprecate Ac_mul_B!::Number, A::SparseMatrixCSC, x::AbstractSparseVector, β::Number, y::StridedVector) mul!(y, adjoint(A), x, α, β)
@deprecate Ac_mul_B!(y::StridedVector{Ty}, A::SparseMatrixCSC, x::AbstractSparseVector{Tx}) where {Tx,Ty} mul!(y, adjoint(A), x)
@deprecate At_mul_B!::Number, A::SparseMatrixCSC, x::AbstractSparseVector, β::Number, y::StridedVector) mul!(α, transpose(A), x, β, y)
@deprecate At_mul_B!::Number, A::SparseMatrixCSC, x::AbstractSparseVector, β::Number, y::StridedVector) mul!(y, transpose(A), x, α, β)
@deprecate At_mul_B!(y::StridedVector{Ty}, A::SparseMatrixCSC, x::AbstractSparseVector{Tx}) where {Tx,Ty} mul!(y, transpose(A), x)
@deprecate A_mul_B!::Number, A::SparseMatrixCSC, x::AbstractSparseVector, β::Number, y::StridedVector) mul!(α, A, x, β, y)
@deprecate A_mul_B!::Number, A::SparseMatrixCSC, x::AbstractSparseVector, β::Number, y::StridedVector) mul!(y, A, x, α, β)
@deprecate A_mul_B!(y::StridedVector{Ty}, A::SparseMatrixCSC, x::AbstractSparseVector{Tx}) where {Tx,Ty} mul!(y, A, x)
@deprecate At_mul_B!::Number, A::StridedMatrix, x::AbstractSparseVector, β::Number, y::StridedVector) mul!(α, transpose(A), x, β, y)
@deprecate At_mul_B!::Number, A::StridedMatrix, x::AbstractSparseVector, β::Number, y::StridedVector) mul!(y, transpose(A), x, α, β)
@deprecate At_mul_B!(y::StridedVector{Ty}, A::StridedMatrix, x::AbstractSparseVector{Tx}) where {Tx,Ty} mul!(y, transpose(A), x)
@deprecate At_mul_B(A::StridedMatrix{Ta}, x::AbstractSparseVector{Tx}) where {Ta,Tx} (*)(transpose(A), x)
@deprecate A_mul_B!::Number, A::StridedMatrix, x::AbstractSparseVector, β::Number, y::StridedVector) mul!(α, A, x, β, y)
@deprecate A_mul_B!::Number, A::StridedMatrix, x::AbstractSparseVector, β::Number, y::StridedVector) mul!(y, A, x, α, β)
@deprecate A_mul_B!(y::StridedVector{Ty}, A::StridedMatrix, x::AbstractSparseVector{Tx}) where {Tx,Ty} mul!(y, A, x)

# methods involving RowVector from base/sparse/linalg.jl, to deprecate
Expand Down
24 changes: 12 additions & 12 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!(α::Number, A::SparseMatrixCSC, B::StridedVecOrMat, β::Number, C::StridedVecOrMat)
function mul!(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 @@ -49,11 +49,11 @@ function mul!(α::Number, A::SparseMatrixCSC, B::StridedVecOrMat, β::Number, C:
C
end
*(A::SparseMatrixCSC{TA,S}, x::StridedVector{Tx}) where {TA,S,Tx} =
(T = promote_type(TA, Tx); mul!(one(T), A, x, zero(T), similar(x, T, A.m)))
(T = promote_type(TA, Tx); mul!(similar(x, T, A.m), A, x, one(T), zero(T)))
*(A::SparseMatrixCSC{TA,S}, B::StridedMatrix{Tx}) where {TA,S,Tx} =
(T = promote_type(TA, Tx); mul!(one(T), A, B, zero(T), similar(B, T, (A.m, size(B, 2)))))
(T = promote_type(TA, Tx); mul!(similar(B, T, (A.m, size(B, 2))), A, B, one(T), zero(T)))

function mul!(α::Number, adjA::Adjoint{<:Any,<:SparseMatrixCSC}, B::StridedVecOrMat, β::Number, C::StridedVecOrMat)
function mul!(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 @@ -75,11 +75,11 @@ function mul!(α::Number, adjA::Adjoint{<:Any,<:SparseMatrixCSC}, B::StridedVecO
C
end
*(adjA::Adjoint{<:Any,<:SparseMatrixCSC{TA,S}}, x::StridedVector{Tx}) where {TA,S,Tx} =
(A = adjA.parent; T = promote_type(TA, Tx); mul!(one(T), adjoint(A), x, zero(T), similar(x, T, A.n)))
(A = adjA.parent; T = promote_type(TA, Tx); mul!(similar(x, T, A.n), adjoint(A), x, one(T), zero(T)))
*(adjA::Adjoint{<:Any,<:SparseMatrixCSC{TA,S}}, B::StridedMatrix{Tx}) where {TA,S,Tx} =
(A = adjA.parent; T = promote_type(TA, Tx); mul!(one(T), adjoint(A), B, zero(T), similar(B, T, (A.n, size(B, 2)))))
(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!(α::Number, transA::Transpose{<:Any,<:SparseMatrixCSC}, B::StridedVecOrMat, β::Number, C::StridedVecOrMat)
function mul!(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 All @@ -101,18 +101,18 @@ function mul!(α::Number, transA::Transpose{<:Any,<:SparseMatrixCSC}, B::Strided
C
end
*(transA::Transpose{<:Any,<:SparseMatrixCSC{TA,S}}, x::StridedVector{Tx}) where {TA,S,Tx} =
(A = transA.parent; T = promote_type(TA, Tx); mul!(one(T), transpose(A), x, zero(T), similar(x, T, A.n)))
(A = transA.parent; T = promote_type(TA, Tx); mul!(similar(x, T, A.n), transpose(A), x, one(T), zero(T)))
*(transA::Transpose{<:Any,<:SparseMatrixCSC{TA,S}}, B::StridedMatrix{Tx}) where {TA,S,Tx} =
(A = transA.parent; T = promote_type(TA, Tx); mul!(one(T), transpose(A), B, zero(T), similar(B, T, (A.n, size(B, 2)))))
(A = transA.parent; T = promote_type(TA, Tx); mul!(similar(B, T, (A.n, size(B, 2))), transpose(A), B, one(T), zero(T)))

# For compatibility with dense multiplication API. Should be deleted when dense multiplication
# API is updated to follow BLAS API.
mul!(C::StridedVecOrMat, A::SparseMatrixCSC, B::StridedVecOrMat) =
mul!(one(eltype(B)), A, B, zero(eltype(C)), C)
mul!(C, A, B, one(eltype(B)), zero(eltype(C)))
mul!(C::StridedVecOrMat, adjA::Adjoint{<:Any,<:SparseMatrixCSC}, B::StridedVecOrMat) =
(A = adjA.parent; mul!(one(eltype(B)), adjoint(A), B, zero(eltype(C)), C))
(A = adjA.parent; mul!(C, adjoint(A), B, one(eltype(B)), zero(eltype(C))))
mul!(C::StridedVecOrMat, transA::Transpose{<:Any,<:SparseMatrixCSC}, B::StridedVecOrMat) =
(A = transA.parent; mul!(one(eltype(B)), transpose(A), B, zero(eltype(C)), C))
(A = transA.parent; mul!(C, transpose(A), B, one(eltype(B)), zero(eltype(C))))

function (*)(X::StridedMatrix{TX}, A::SparseMatrixCSC{TvA,TiA}) where {TX,TvA,TiA}
mX, nX = size(X)
Expand Down
28 changes: 14 additions & 14 deletions stdlib/SparseArrays/src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1581,9 +1581,9 @@ function (*)(A::StridedMatrix{Ta}, x::AbstractSparseVector{Tx}) where {Ta,Tx}
end

mul!(y::AbstractVector{Ty}, A::StridedMatrix, x::AbstractSparseVector{Tx}) where {Tx,Ty} =
mul!(one(Tx), A, x, zero(Ty), y)
mul!(y, A, x, one(Tx), zero(Ty))

function mul!(α::Number, A::StridedMatrix, x::AbstractSparseVector, β::Number, y::AbstractVector)
function mul!(y::AbstractVector, A::StridedMatrix, x::AbstractSparseVector, α::Number, β::Number)
m, n = size(A)
length(x) == n && length(y) == m || throw(DimensionMismatch())
m == 0 && return y
Expand Down Expand Up @@ -1619,9 +1619,9 @@ function *(transA::Transpose{<:Any,<:StridedMatrix{Ta}}, x::AbstractSparseVector
end

mul!(y::AbstractVector{Ty}, transA::Transpose{<:Any,<:StridedMatrix}, x::AbstractSparseVector{Tx}) where {Tx,Ty} =
(A = transA.parent; mul!(one(Tx), transpose(A), x, zero(Ty), y))
(A = transA.parent; mul!(y, transpose(A), x, one(Tx), zero(Ty)))

function mul!(α::Number, transA::Transpose{<:Any,<:StridedMatrix}, x::AbstractSparseVector, β::Number, y::AbstractVector)
function mul!(y::AbstractVector, transA::Transpose{<:Any,<:StridedMatrix}, x::AbstractSparseVector, α::Number, β::Number)
A = transA.parent
m, n = size(A)
length(x) == m && length(y) == n || throw(DimensionMismatch())
Expand Down Expand Up @@ -1678,9 +1678,9 @@ end
# * and mul!

mul!(y::AbstractVector{Ty}, A::SparseMatrixCSC, x::AbstractSparseVector{Tx}) where {Tx,Ty} =
mul!(one(Tx), A, x, zero(Ty), y)
mul!(y, A, x, one(Tx), zero(Ty))

function mul!(α::Number, A::SparseMatrixCSC, x::AbstractSparseVector, β::Number, y::AbstractVector)
function mul!(y::AbstractVector, A::SparseMatrixCSC, x::AbstractSparseVector, α::Number, β::Number)
m, n = size(A)
length(x) == n && length(y) == m || throw(DimensionMismatch())
m == 0 && return y
Expand Down Expand Up @@ -1711,20 +1711,20 @@ end
# * and *(Tranpose(A), B)

mul!(y::AbstractVector{Ty}, transA::Transpose{<:Any,<:SparseMatrixCSC}, x::AbstractSparseVector{Tx}) where {Tx,Ty} =
(A = transA.parent; mul!(one(Tx), transpose(A), x, zero(Ty), y))
(A = transA.parent; mul!(y, transpose(A), x, one(Tx), zero(Ty)))

mul!(α::Number, transA::Transpose{<:Any,<:SparseMatrixCSC}, x::AbstractSparseVector, β::Number, y::AbstractVector) =
(A = transA.parent; _At_or_Ac_mul_B!(*, α, A, x, β, y))
mul!(y::AbstractVector, transA::Transpose{<:Any,<:SparseMatrixCSC}, x::AbstractSparseVector, α::Number, β::Number) =
(A = transA.parent; _At_or_Ac_mul_B!(*, y, A, x, α, β))

mul!(y::AbstractVector{Ty}, adjA::Adjoint{<:Any,<:SparseMatrixCSC}, x::AbstractSparseVector{Tx}) where {Tx,Ty} =
(A = adjA.parent; mul!(one(Tx), adjoint(A), x, zero(Ty), y))
(A = adjA.parent; mul!(y, adjoint(A), x, one(Tx), zero(Ty)))

mul!(α::Number, adjA::Adjoint{<:Any,<:SparseMatrixCSC}, x::AbstractSparseVector, β::Number, y::AbstractVector) =
(A = adjA.parent; _At_or_Ac_mul_B!(dot, α, A, x, β, y))
mul!(y::AbstractVector, adjA::Adjoint{<:Any,<:SparseMatrixCSC}, x::AbstractSparseVector, α::Number, β::Number) =
(A = adjA.parent; _At_or_Ac_mul_B!(dot, y, A, x, α, β))

function _At_or_Ac_mul_B!(tfun::Function,
α::Number, A::SparseMatrixCSC, x::AbstractSparseVector,
β::Number, y::AbstractVector)
y::AbstractVector, A::SparseMatrixCSC, x::AbstractSparseVector,
α::Number, β::Number)
m, n = size(A)
length(x) == m && length(y) == n || throw(DimensionMismatch())
n == 0 && return y
Expand Down
10 changes: 5 additions & 5 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!(α, A, x, β, y) === y
@test mul!(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!(α, transpose(A), x, β, y) === y
@test mul!(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!(α, A, x, β, y) === y
@test mul!(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!(α, transpose(A), x, β, y) === y
@test mul!(y, transpose(A), x, α, β) === y
@test y rr
end
y = SparseArrays.densemv(A, x; trans='T')
Expand Down Expand Up @@ -1269,4 +1269,4 @@ end
end
end

end # module
end # module

0 comments on commit e4b6677

Please sign in to comment.