Skip to content

Commit b0dbf4b

Browse files
jishnubdlfivefifty
andauthored
issymmetric/ishermitian for OneElement (#380)
* issymmetric/ishermitian for OneElement * Test for block matrices * fix tests --------- Co-authored-by: Sheehan Olver <[email protected]>
1 parent 90ef3ce commit b0dbf4b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/oneelement.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ function triu(A::OneElementMatrix, k::Integer=0)
387387
OneElement(nzband < k ? zero(A.val) : A.val, A.ind, axes(A))
388388
end
389389

390+
391+
# issymmetric
392+
issymmetric(O::OneElement) = axes(O,1) == axes(O,2) && isdiag(O) && issymmetric(getindex_value(O))
393+
ishermitian(O::OneElement) = axes(O,1) == axes(O,2) && isdiag(O) && ishermitian(getindex_value(O))
394+
390395
# diag
391396
function diag(O::OneElementMatrix, k::Integer=0)
392397
Base.require_one_based_indexing(O)

test/runtests.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,6 +2708,23 @@ end
27082708
@test repr(B) == "OneElement(2, (1, 2), (Base.IdentityUnitRange(1:1), Base.IdentityUnitRange(2:2)))"
27092709
end
27102710

2711+
@testset "issymmetric/ishermitian" begin
2712+
for el in (2, 3+0im, 4+5im, SMatrix{2,2}(1:4), SMatrix{2,3}(1:6)), size in [(3,3), (3,4)]
2713+
O = OneElement(el, (2,2), size)
2714+
A = Array(O)
2715+
@test issymmetric(O) == issymmetric(A)
2716+
@test ishermitian(O) == ishermitian(A)
2717+
O = OneElement(el, (1,2), size)
2718+
A = Array(O)
2719+
@test issymmetric(O) == issymmetric(A)
2720+
@test ishermitian(O) == ishermitian(A)
2721+
O = OneElement(el, (5,5), size)
2722+
A = Array(O)
2723+
@test issymmetric(O) == issymmetric(A)
2724+
@test ishermitian(O) == ishermitian(A)
2725+
end
2726+
end
2727+
27112728
@testset "unique" begin
27122729
@testset for n in 1:3
27132730
O = OneElement(5, 2, n)

0 commit comments

Comments
 (0)