Skip to content

Commit

Permalink
row/colsupport for OneElementMatrix (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub authored Feb 1, 2024
1 parent 13bd386 commit d542ead
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ArrayLayouts"
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
authors = ["Sheehan Olver <[email protected]>"]
version = "1.5.2"
version = "1.5.3"

[deps]
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Expand Down
20 changes: 18 additions & 2 deletions src/memorylayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,14 @@ rowsupport(_, A, k) = axes(A,2)
"""
rowsupport(A, k)
gives an iterator containing the possible non-zero entries in the k-th row of A.
Return an iterator containing the column indices of the possible non-zero entries in the `k`-th row of `A`.
"""
rowsupport(A, k) = rowsupport(MemoryLayout(A), A, k)
"""
rowsupport(A)
Return an iterator containing the column indices of the possible non-zero entries in `A`.
"""
rowsupport(A) = rowsupport(A, axes(A,1))

colsupport(_, A, j) = axes(A,1)
Expand All @@ -652,9 +657,14 @@ colsupport(_, A, j) = axes(A,1)
"""
colsupport(A, j)
gives an iterator containing the possible non-zero entries in the j-th column of A.
Return an iterator containing the row indices of the possible non-zero entries in the `j`-th column of `A`.
"""
colsupport(A, j) = colsupport(MemoryLayout(A), A, j)
"""
colsupport(A)
Return an iterator containing the row indices of the possible non-zero entries in `A`.
"""
colsupport(A) = colsupport(A, axes(A,2))

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

colsupport(::UnknownLayout, A::OneElement{<:Any,1}, _) =
intersect(axes(A,1), A.ind[1]:A.ind[1])
function colsupport(::UnknownLayout, A::OneElement{<:Any,2}, j)
intersect(axes(A,1), range(A.ind[1], length = Int(A.ind[2] j)))
end
function rowsupport(::UnknownLayout, A::OneElement{<:Any,2}, k)
intersect(axes(A,2), range(A.ind[2], length = Int(A.ind[1] k)))
end

rowsupport(::DiagonalLayout, _, k) = k
colsupport(::DiagonalLayout, _, j) = j
Expand Down
2 changes: 1 addition & 1 deletion src/muladd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function default_blasmul!(α, A::AbstractMatrix, B::AbstractMatrix, β, C::Abstr
jindsid = all(k -> rowsupport(B,rowsupport(A,k)) == r, colsupport(A))

if jindsid
for j in rowsupport(B,rowsupport(A,1)), k in colsupport(A)
for j in r, k in colsupport(A)
_default_blasmul_loop!(α, A, B, β, C, k, j)
end
else
Expand Down
14 changes: 13 additions & 1 deletion test/test_layouts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,21 @@ struct FooNumber <: Number end
@test isempty(rowsupport(Zeros(5,10), 2))

@testset "OneElement" begin
for ind in (4, 20)
@testset for ind in (4, 20)
o = OneElement(2, ind, 10)
@test sum(o) == sum(o[colsupport(o)])
@test sum(o) == sum(o[colsupport(o),rowsupport(o)])
end
@testset for ind in ((3,4), (15,20))
O = OneElement(2, ind, (10,10))
@test isempty(colsupport(O,1))
if ind[2] < size(O,2)
@test colsupport(O,ind[2]) == ind[1]:ind[1]
end
if ind[1] < size(O,1)
@test rowsupport(O,ind[1]) == ind[2]:ind[2]
end
@test sum(O) == sum(O[colsupport(O),rowsupport(O)])
end
end

Expand Down

2 comments on commit d542ead

@jishnub
Copy link
Member Author

@jishnub jishnub commented on d542ead Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/100023

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.5.3 -m "<description of version>" d542ead007d4226740ef1b9c6f4ffb14623cd76f
git push origin v1.5.3

Please sign in to comment.