willow-ahrens / Finch.jl

Sparse tensors in Julia and more! Datastructure-driven array programing language.
http://willowahrens.io/Finch.jl/
MIT License
157 stars 15 forks source link

Kbd-index-extension #479

Closed kylebd99 closed 5 months ago

kylebd99 commented 5 months ago

This PR adds a minimal form of lazy indexing to allow for empty dimensions.

codecov[bot] commented 5 months ago

Codecov Report

Attention: Patch coverage is 92.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 76.33%. Comparing base (65cfaf7) to head (d054a7e).

Files Patch % Lines
src/interface/lazy.jl 91.66% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #479 +/- ## ========================================== + Coverage 76.27% 76.33% +0.06% ========================================== Files 92 92 Lines 8842 8866 +24 ========================================== + Hits 6744 6768 +24 Misses 2098 2098 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

willow-ahrens commented 5 months ago

Looks good to me! Could you also add an eager version for Tensor and SwizzleArray? I think the specialization is something like Base.getindex(tns::Tensor, idxs::Vararg{<:Union{Colon, Nothing}}) = compute(lazy(tns)[idxs...])

kylebd99 commented 5 months ago

What's the intended behavior for eager? It seems like the :/nothing construct is primarily meant for expressing lazy computation.

willow-ahrens commented 5 months ago

I think it would just eagerly insert a length-1 dimension? I was asking mostly because all of the constructs usually have an eager counterpart. Though no worries if you'd rather not add it here, we can skip it for now and add it later.

kylebd99 commented 5 months ago

Hmm for the moment, I might leave it. I think implementing this would require adjusting the swizzle array code as well to allow for new dimensions to be inserted. Currently, it looks like it assumes that the permutation is the same number of dimensions as the tensor.