Skip to content

Using CircularArrayBuffers for non-iterable data #12

@3rdCore

Description

@3rdCore

Hello, I have an issue regarding the latest updates of the package CircularArrayBuffers.jl

I am using the package ReinforcementLearning.jl to train a RL-based agent to make decisions on graphs. The trajectory is stored in a CircularArraySARTTrajectory object, in which environment states are stored in a CircularArrayBuffers.

In my case, my environment state is a custom class called DefaultTrajectoryState which is a non-tabular data. However, since the latest update of the package, CircularArrayBuffers expects the data to be iterable in order to be broadcasted for the case we want to push multiple states in the CircularArrayBuffers, which is not my case.
I getthe following error :
Got exception outside of a @test MethodError: no method matching iterate(::SeaPearl.DefaultTrajectoryState)

The error comes from the following function of CircularArrayBuffers.jl :

function Base.push!(cb::CircularArrayBuffer{T,N}, data) where {T,N}
    if cb.nframes == capacity(cb)
        cb.first = (cb.first == capacity(cb) ? 1 : cb.first + 1)
    else
        cb.nframes += 1
    end
    if N == 1
        i = _buffer_frame(cb, cb.nframes)
        if ndims(data) == 0
            cb.buffer[i:i] .= data[]
        else
            cb.buffer[i:i] .= data                    <----- ERROR
        end
    else
        cb.buffer[ntuple(_ -> (:), N - 1)..., _buffer_frame(cb, cb.nframes)] .= data
    end
    cb
end

It is designed "on purpose"? Knowing that should I consider encapsulating my state into a Vector containing one single element?

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