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

Deprecate scale! in favor of mul!, mul1!, and mul2! #25701

Merged
merged 5 commits into from
Jan 24, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
Define scaling of triagular matrix from the right and the left
  • Loading branch information
andreasnoack committed Jan 24, 2018
commit d0ce71a52c9771e3d73090a9ae007d9f4f0a8366
69 changes: 61 additions & 8 deletions stdlib/LinearAlgebra/src/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,32 +400,85 @@ function copyto!(A::T, B::T) where T<:Union{LowerTriangular,UnitLowerTriangular}
return A
end

function mul!(A::UpperTriangular, B::Union{UpperTriangular,UnitUpperTriangular}, c::Number)
function mul!(A::UpperTriangular, B::UpperTriangular, c::Number)
n = checksquare(B)
for j = 1:n
if isa(B, UnitUpperTriangular)
@inbounds A[j,j] = c
for i = 1:j
@inbounds A[i,j] = B[i,j] * c
end
for i = 1:(isa(B, UnitUpperTriangular) ? j-1 : j)
end
return A
end
function mul!(A::UpperTriangular, c::Number, B::UpperTriangular)
n = checksquare(B)
for j = 1:n
for i = 1:j
@inbounds A[i,j] = c * B[i,j]
end
end
return A
end
function mul!(A::LowerTriangular, B::Union{LowerTriangular,UnitLowerTriangular}, c::Number)
function mul!(A::UpperTriangular, B::UnitUpperTriangular, c::Number)
n = checksquare(B)
for j = 1:n
@inbounds A[j,j] = c
for i = 1:(j - 1)
@inbounds A[i,j] = B[i,j] * c
end
end
return A
end
function mul!(A::UpperTriangular, c::Number, B::UnitUpperTriangular)
n = checksquare(B)
for j = 1:n
@inbounds A[j,j] = c
for i = 1:(j - 1)
@inbounds A[i,j] = c * B[i,j]
end
end
return A
end
function mul!(A::LowerTriangular, B::LowerTriangular, c::Number)
n = checksquare(B)
for j = 1:n
for i = j:n
@inbounds A[i,j] = B[i,j] * c
end
end
return A
end
function mul!(A::LowerTriangular, c::Number, B::LowerTriangular)
n = checksquare(B)
for j = 1:n
for i = j:n
@inbounds A[i,j] = c * B[i,j]
end
end
return A
end
function mul!(A::LowerTriangular, B::UnitLowerTriangular, c::Number)
n = checksquare(B)
for j = 1:n
if isa(B, UnitLowerTriangular)
@inbounds A[j,j] = c
for i = (j + 1):n
@inbounds A[i,j] = B[i,j] * c
end
for i = (isa(B, UnitLowerTriangular) ? j+1 : j):n
end
return A
end
function mul!(A::LowerTriangular, c::Number, B::UnitLowerTriangular)
n = checksquare(B)
for j = 1:n
@inbounds A[j,j] = c
for i = (j + 1):n
@inbounds A[i,j] = c * B[i,j]
end
end
return A
end

mul1!(A::Union{UpperTriangular,LowerTriangular}, c::Number) = mul!(A, A, c)
mul2!(c::Number, A::Union{UpperTriangular,LowerTriangular}) = mul1!(A', c')'
mul2!(c::Number, A::Union{UpperTriangular,LowerTriangular}) = mul!(A, c, A)

fillstored!(A::LowerTriangular, x) = (fillband!(A.data, x, 1-size(A,1), 0); A)
fillstored!(A::UnitLowerTriangular, x) = (fillband!(A.data, x, 1-size(A,1), -1); A)
Expand Down