Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
10 changes: 10 additions & 0 deletions src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
"""
function triu(M::AbstractMatrix, k::Integer = 0)
d = similar(M)
if !haszero(eltype(M))
# since the zero would need to be evaluated from the elements,
# we copy the array to avoid undefined references in triu!
copy!(d, M)
end
A = triu!(d,k)
if iszero(k)
copytrito!(A, M, 'U')
Expand Down Expand Up @@ -509,6 +514,11 @@
"""
function tril(M::AbstractMatrix,k::Integer=0)
d = similar(M)
if !haszero(eltype(M))
# since the zero would need to be evaluated from the elements,
# we copy the array to avoid undefined references in tril!
copy!(d, M)

Check warning on line 520 in src/generic.jl

View check run for this annotation

Codecov / codecov/patch

src/generic.jl#L520

Added line #L520 was not covered by tests
end
A = tril!(d,k)
if iszero(k)
copytrito!(A, M, 'L')
Expand Down
9 changes: 9 additions & 0 deletions test/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1408,4 +1408,13 @@ end
@test 2^A == 2^Matrix(A)
end

@testset "triu/tril for block matrices" begin
O = ones(2,2)
Z = zero(O)
M = fill(O, 3, 3)
res = fill(Z, size(M))
res[1,2] = res[1,3] = res[2,3] = O
@test triu(GenericArray(M),1) == res
end

end # module TestDense