Skip to content

Fail to create Dataloader for customized type #214

@yl4070

Description

@yl4070

I suppose that any object supports getobs and numobs should work. Recently, I ran into an error when creating Dataloader with a customized type. Not sure if I'm doing anything wrong here.

A Minimal example:

struct DD
	idx::Vector{Int32}
end
getobs(d::DD, i) = d.idx[i]
numobs(d::DD) = length(d.idx)

data = DD([1,2,3,4])
DataLoader(data)

This will return error:

MethodError: no method matching length(::Main.var"workspace#4".DD)

Stack trace:

1. numobs(::Type{…}, data::DD) [...show types...](http://localhost:1234/edit?id=ee1c16dc-f894-11f0-80b6-ab4c33f1313d#)
from 
observation.jl:57
2 .numobs
from 
SimpleTraits.jl:332
3. MLUtils.DataLoader(data::DD; buffer::Bool, parallel::Bool, shuffle::Bool, batchsize::Int64, partial::Bool, collate::Val{nothing}, rng::Random.TaskLocalRNG)
from 
dataloader.jl:167
4. MLUtils.DataLoader(data::DD)
from 
dataloader.jl:151

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions