Skip to content

Commit d542ead

Browse files
authored
row/colsupport for OneElementMatrix (#200)
1 parent 13bd386 commit d542ead

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ArrayLayouts"
22
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
33
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "1.5.2"
4+
version = "1.5.3"
55

66
[deps]
77
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"

src/memorylayout.jl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,14 @@ rowsupport(_, A, k) = axes(A,2)
641641
"""
642642
rowsupport(A, k)
643643
644-
gives an iterator containing the possible non-zero entries in the k-th row of A.
644+
Return an iterator containing the column indices of the possible non-zero entries in the `k`-th row of `A`.
645645
"""
646646
rowsupport(A, k) = rowsupport(MemoryLayout(A), A, k)
647+
"""
648+
rowsupport(A)
649+
650+
Return an iterator containing the column indices of the possible non-zero entries in `A`.
651+
"""
647652
rowsupport(A) = rowsupport(A, axes(A,1))
648653

649654
colsupport(_, A, j) = axes(A,1)
@@ -652,9 +657,14 @@ colsupport(_, A, j) = axes(A,1)
652657
"""
653658
colsupport(A, j)
654659
655-
gives an iterator containing the possible non-zero entries in the j-th column of A.
660+
Return an iterator containing the row indices of the possible non-zero entries in the `j`-th column of `A`.
656661
"""
657662
colsupport(A, j) = colsupport(MemoryLayout(A), A, j)
663+
"""
664+
colsupport(A)
665+
666+
Return an iterator containing the row indices of the possible non-zero entries in `A`.
667+
"""
658668
colsupport(A) = colsupport(A, axes(A,2))
659669

660670
# TODO: generalise to other subarrays
@@ -668,6 +678,12 @@ colsupport(::ZerosLayout, A, _) = 1:0
668678

669679
colsupport(::UnknownLayout, A::OneElement{<:Any,1}, _) =
670680
intersect(axes(A,1), A.ind[1]:A.ind[1])
681+
function colsupport(::UnknownLayout, A::OneElement{<:Any,2}, j)
682+
intersect(axes(A,1), range(A.ind[1], length = Int(A.ind[2] j)))
683+
end
684+
function rowsupport(::UnknownLayout, A::OneElement{<:Any,2}, k)
685+
intersect(axes(A,2), range(A.ind[2], length = Int(A.ind[1] k)))
686+
end
671687

672688
rowsupport(::DiagonalLayout, _, k) = k
673689
colsupport(::DiagonalLayout, _, j) = j

src/muladd.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function default_blasmul!(α, A::AbstractMatrix, B::AbstractMatrix, β, C::Abstr
179179
jindsid = all(k -> rowsupport(B,rowsupport(A,k)) == r, colsupport(A))
180180

181181
if jindsid
182-
for j in rowsupport(B,rowsupport(A,1)), k in colsupport(A)
182+
for j in r, k in colsupport(A)
183183
_default_blasmul_loop!(α, A, B, β, C, k, j)
184184
end
185185
else

test/test_layouts.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,21 @@ struct FooNumber <: Number end
316316
@test isempty(rowsupport(Zeros(5,10), 2))
317317

318318
@testset "OneElement" begin
319-
for ind in (4, 20)
319+
@testset for ind in (4, 20)
320320
o = OneElement(2, ind, 10)
321321
@test sum(o) == sum(o[colsupport(o)])
322+
@test sum(o) == sum(o[colsupport(o),rowsupport(o)])
323+
end
324+
@testset for ind in ((3,4), (15,20))
325+
O = OneElement(2, ind, (10,10))
326+
@test isempty(colsupport(O,1))
327+
if ind[2] < size(O,2)
328+
@test colsupport(O,ind[2]) == ind[1]:ind[1]
329+
end
330+
if ind[1] < size(O,1)
331+
@test rowsupport(O,ind[1]) == ind[2]:ind[2]
332+
end
333+
@test sum(O) == sum(O[colsupport(O),rowsupport(O)])
322334
end
323335
end
324336

0 commit comments

Comments
 (0)