Skip to content

Commit

Permalink
Add firstindex(::AbstractDataContainer)
Browse files Browse the repository at this point in the history
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
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)
```
  • Loading branch information
Pangoraw committed Aug 23, 2023
1 parent 03f8fb1 commit 710a5eb
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/observation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Base.size(x::AbstractDataContainer) = (numobs(x),)
Base.iterate(x::AbstractDataContainer, state = 1) =
(state > numobs(x)) ? nothing : (getobs(x, state), state + 1)
Base.lastindex(x::AbstractDataContainer) = numobs(x)
Base.firstindex(::AbstractDataContainer) = 1

# --------------------------------------------------------------------
# Arrays
Expand Down

0 comments on commit 710a5eb

Please sign in to comment.