Skip to content

Commit d2cb2d0

Browse files
committed
Add layout_getindex
1 parent 1307bb9 commit d2cb2d0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/abstractsparsearrayinterface.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ 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+
Tr === Tc === :Integer && continue
140+
@eval begin
141+
@interface ::AbstractSparseArrayInterface function Base.getindex(
142+
A::AbstractMatrix, kr::$Tr, jr::$Tc
143+
)
144+
Base.@inline # needed to make boundschecks work
145+
return ArrayLayouts.layout_getindex(A, kr, jr)
146+
end
147+
end
148+
end
149+
132150
to_vec(x) = vec(collect(x))
133151
to_vec(x::AbstractArray) = vec(x)
134152

0 commit comments

Comments
 (0)