Skip to content

Commit 9e9e1f0

Browse files
committed
Add layout_getindex
1 parent 1307bb9 commit 9e9e1f0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/abstractsparsearrayinterface.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ function DerivableInterfaces.combine_interface_rule(
129129
return interface2
130130
end
131131

132+
# using ArrayLayouts getindex: this is a bit cumbersome because there already is a way to make that work focussed on types
133+
# but here we want to focus on interfaces.
134+
# eg: ArrayLayouts.@layoutgetindex ArrayType
135+
# TODO: decide if we need the interface approach,
136+
for (Tr, Tc) in Iterators.product(
137+
Iterators.repeated((:Colon, :AbstractUnitRange, :AbstractVector, :Integer), 2)...
138+
)
139+
@eval begin
140+
@interface ::AbstractSparseArrayInterface function Base.getindex(
141+
A::AbstractMatrix, kr::$Tr, jr::$Tc
142+
)
143+
Base.@inline # needed to make boundschecks work
144+
return ArrayLayouts.layout_getindex(A, kr, jr)
145+
end
146+
end
147+
end
148+
132149
to_vec(x) = vec(collect(x))
133150
to_vec(x::AbstractArray) = vec(x)
134151

0 commit comments

Comments
 (0)