JuliaML / MLUtils.jl

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

The `JoinedData` container seems to be missing a `getindex()` method for indices other than `Number` #177

Open gruberchr opened 1 month ago

gruberchr commented 1 month ago

A data container with joined data like e.g.

data = joinobs(1:5, 6:10)

can be accessed successfully via getobs(), if the observation index is a single value, i.e. is of type Number:

getobs(data, 6)

Instead, when accessing multiple observations at once, e.g., as follows

getobs(data, 4:6)

a MethodError is thrown with message no method matching isless(::UnitRange{Int64}, ::Int64) in obstransform.jl.

The getobs() function refers to the getindex() function in this case and currently there seems to be only this getindex() method for JoinedData containers, which is obviously restricted to single value indices.

A possible use case for accessing more than a single observation could be, for instance, the combination of the JoinedData container with a BatchView and batch-sizes larger than 1, as follows:

batched_data = BatchView(data; batchsize=3)

When accessing this batched data container, e.g., as follows

batched_data[2]

the same error is thrown because this expression finally calls getobs() here in the same way as in the example above.

I guess that at least the getindex() method for JoinedData containers should be restricted to indices of type Number. But it would also be nice if JoinedData containers supported other indexing types in the future.