Skip to content

Commit

Permalink
Fix JuliaLang#10739, implement isdiag method
Browse files Browse the repository at this point in the history
  • Loading branch information
garrison authored and Viral B. Shah committed Apr 27, 2015
1 parent 102e840 commit b7f0c03
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ export
givens,
hessfact!,
hessfact,
isdiag,
ishermitian,
isposdef!,
isposdef,
Expand Down
1 change: 1 addition & 0 deletions base/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export
gradient,
hessfact,
hessfact!,
isdiag,
ishermitian,
isposdef,
isposdef!,
Expand Down
3 changes: 3 additions & 0 deletions base/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,11 @@ function istril(A::AbstractMatrix)
return true
end

isdiag(A::AbstractMatrix) = istril(A) && istriu(A)

istriu(x::Number) = true
istril(x::Number) = true
isdiag(x::Number) = true

linreg{T<:Number}(X::StridedVecOrMat{T}, y::Vector{T}) = [ones(T, size(X,1)) X] \ y

Expand Down
4 changes: 4 additions & 0 deletions doc/stdlib/linalg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,10 @@ Linear algebra functions in Julia are largely implemented by calling functions f

Test whether a matrix is upper triangular.

.. function:: isdiag(A) -> Bool

Test whether a matrix is diagonal.

.. function:: ishermitian(A) -> Bool

Test whether a matrix is Hermitian.
Expand Down
11 changes: 11 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,17 @@ end
@test_throws ArgumentError flipdim(1:10, -1)
@test isequal(flipdim(Array(Int,0,0),1), Array(Int,0,0)) # issue #5872

# isdiag, istril, istriu
@test isdiag(3)
@test istril(4)
@test istriu(5)
@test !isdiag([1 2; 3 4])
@test !istril([1 2; 3 4])
@test !istriu([1 2; 3 4])
@test isdiag([1 0; 0 4])
@test istril([1 0; 3 4])
@test istriu([1 2; 0 4])

# issue 4228
A = [[i i; i i] for i=1:2]
@test cumsum(A) == Any[[1 1; 1 1], [3 3; 3 3]]
Expand Down
4 changes: 2 additions & 2 deletions test/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ for relty in (Float32, Float64, BigFloat), elty in (relty, Complex{relty})
end
end

#Issue 10742
# Issue 10742 and similar
let A = Bidiagonal([1,2,3], [0,0], true)
@test istril(A)
@test isdiag(A)
end

6 changes: 5 additions & 1 deletion test/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
end
end

# Issue 10742
# Issue 10742 and similar
@test istril(UpperTriangular(diagm([1,2,3,4])))
@test istriu(LowerTriangular(diagm([1,2,3,4])))
@test isdiag(UpperTriangular(diagm([1,2,3,4])))
@test isdiag(LowerTriangular(diagm([1,2,3,4])))
@test !isdiag(UpperTriangular(rand(4, 4)))
@test !isdiag(LowerTriangular(rand(4, 4)))

0 comments on commit b7f0c03

Please sign in to comment.