Skip to content

Commit

Permalink
implement fillband! and call it from fillstored!(::AbstractTriangular)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Dec 13, 2017
1 parent 197ada2 commit 60f23df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,22 @@ function tril!(M::AbstractMatrix, k::Integer)
end
tril(M::Matrix, k::Integer) = tril!(copy(M), k)

"""
fillband!(A::AbstractMatrix, x, l, u)
Fill the band between diagonals `l` and `u` with the value `x`.
"""
function fillband!(A::AbstractMatrix{T}, x, l, u) where T
m, n = size(A)
xT = convert(T, x)
for j in 1:n
for i in max(1,j-u):min(m,j-l)
@inbounds A[i, j] = xT
end
end
return A
end

function diagind(m::Integer, n::Integer, k::Integer=0)
if !(-m <= k <= n)
throw(ArgumentError(string("requested diagonal, $k, must be at least $(-m) and ",
Expand Down
5 changes: 4 additions & 1 deletion base/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ end
scale!(A::Union{UpperTriangular,LowerTriangular}, c::Number) = scale!(A,A,c)
scale!(c::Number, A::Union{UpperTriangular,LowerTriangular}) = scale!(A,c)

fillstored!(A::AbstractTriangular, x) = (fill!(A.data, x); A)
fillstored!(A::LowerTriangular, x) = (fillband!(A.data, x, size(A,1), 0); A)
fillstored!(A::UnitLowerTriangular, x) = (fillband!(A.data, x, size(A,1), -1); A)
fillstored!(A::UpperTriangular, x) = (fillband!(A.data, x, 0, size(A,2)); A)
fillstored!(A::UnitUpperTriangular, x) = (fillband!(A.data, x, 1, size(A,2)); A)

# Binary operations
+(A::UpperTriangular, B::UpperTriangular) = UpperTriangular(A.data + B.data)
Expand Down

0 comments on commit 60f23df

Please sign in to comment.