JuliaML / MLUtils.jl

Utilities and abstractions for Machine Learning tasks
MIT License
107 stars 20 forks source link

Add `firstindex(::AbstractDataContainer)` #164

Closed Pangoraw closed 1 year ago

Pangoraw commented 1 year ago

This enables the begin keyword when indexing an AbstractDataContainer. Note that end already worked when indexing because of lastindex(::AbstractDataContainer) is already implemented. For example:

julia> using MLDatasets

julia> mnist = MNIST()

julia> x, y = mnist[begin]
(features = Float32[0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0; … ; 0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0], targets = 5)
ToucheSir commented 1 year ago

Could you add a test? Maybe one that uses begin. Otherwise LGTM.

codecov-commenter commented 1 year ago

Codecov Report

Merging #164 (619ef01) into main (03f8fb1) will increase coverage by 0.01%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #164      +/-   ##
==========================================
+ Coverage   88.50%   88.51%   +0.01%     
==========================================
  Files          15       15              
  Lines         600      601       +1     
==========================================
+ Hits          531      532       +1     
  Misses         69       69              
Files Changed Coverage Δ
src/observation.jl 87.75% <100.00%> (+0.25%) :arrow_up: