C++ API Reference
This reference is generated from the curated envpool/core headers used by
the Add New Environment into EnvPool integration guide. It is meant to make the C++ extension
surface available on Read the Docs alongside the narrative guide.
Core Data Structures
-
class Array
Subclassed by TArray< Dtype >
Public Functions
-
Array() = default
-
template<class Deleter>
inline Array(const ShapeSpec &spec, char *data, Deleter &&deleter) Constructor an
Arrayof shape defined byspec, withdataas pointer to its raw memory. Array does not own the memory.
-
inline explicit Array(const ShapeSpec &spec)
Constructor an
Arrayof shape defined byspec. This constructor allocates and owns the memory.
-
template<typename ...Index>
inline Array operator()(Index... index) const Take multidimensional index into the Array.
The returned view does not extend this Array’s storage lifetime. Callers must keep the backing Array alive while using it.
-
inline Array operator[](int index) const
Index operator of array, takes the index along the first axis.
-
inline Array Slice(std::size_t start, std::size_t end) const
Take a slice at the first axis of the Array.
The returned view does not extend this Array’s storage lifetime. Callers must keep the backing Array alive while using it.
-
template<typename T, std::enable_if_t<!std::is_same_v<T, Array>, bool> = true>
inline void operator=(const T &value) const Assign to this Array a scalar value. This Array needs to have a scalar shape.
-
template<typename T>
inline void Fill(const T &value) const Fills this array with a scalar value of type T.
-
template<typename T>
inline void Assign(const T *buff, std::size_t sz) const Copy the memory starting at
raw.first, toraw.first + raw.secondto the memory of this Array.
-
inline std::size_t Shape(std::size_t dim) const
Size of axis
dim.
-
inline const std::vector<std::size_t> &Shape() const
Shape
-
inline void *Data() const
Pointer to the raw memory.
-
inline Array Truncate(std::size_t end) const
Truncate the Array. Return a new Array that shares the same memory location but with a truncated shape.
-
inline void Zero() const
-
Array() = default
-
template<typename Dtype>
class TArray : public Array Public Functions
-
TArray() = default
-
template<typename A, std::enable_if_t<std::is_same_v<std::decay_t<A>, Array>, bool> = true>
inline explicit TArray(A &&array)
-
template<typename ...Index>
inline TArray operator()(Index... index) const Take multidimensional index into the Array.
-
inline TArray operator[](int index) const
Index operator of array, takes the index along the first axis.
-
inline TArray Slice(std::size_t start, std::size_t end) const
Take a slice at the first axis of the Array.
-
template<typename T, std::enable_if_t<!std::is_same_v<T, TArray>, bool> = true>
inline void operator=(const T &value) const Assign a scalar value.
-
template<typename T>
inline void Fill(const T &value) const Fills this array with a scalar value of type T.
-
inline void Assign(const Dtype *buff, std::size_t sz) const
Copy the memory starting at
raw.first, toraw.first + raw.secondto the memory of this Array.
-
TArray() = default
-
template<typename D>
class Spec : public ShapeSpec -
Public Functions
-
inline explicit Spec(std::vector<int> &&shape)
-
inline explicit Spec(const std::vector<int> &shape)
-
inline Spec(std::vector<int> &&shape, std::tuple<std::vector<dtype>, std::vector<dtype>> &&elementwise_bounds)
-
inline explicit Spec(std::vector<int> &&shape)
The compile-time dictionary helpers used by these types still live in
envpool/core/dict.h and are referenced throughout Add New Environment into EnvPool.
Pool Implementations
-
template<typename EnvSpec>
class EnvPool Template subclass of EnvPool, to be overridden by the real EnvPool.
Subclassed by PyEnvPool< EnvPool >
Public Types
-
template<typename Env>
class AsyncEnvPool : public EnvPool<Env::Spec> Async EnvPool
batch-action -> action buffer queue -> threadpool -> state buffer queue
ThreadPool is tailored with EnvPool, so here we don’t use the existing third_party ThreadPool (which is really slow).
Public Types
-
using ActionSlice = typename ActionBufferQueue::ActionSlice
Public Functions
-
inline ~AsyncEnvPool() override
-
using ActionSlice = typename ActionBufferQueue::ActionSlice
Python Binding Helpers
-
template<typename EnvSpec>
class PyEnvSpec : public EnvSpec<EnvFns> Public Types
Public Static Attributes
-
template<typename EnvPool>
class PyEnvPool : public EnvPool<EnvSpec> Template subclass of EnvPool, to be overridden by the real EnvPool.
Public Functions
-
inline py::tuple Xla()
Get XLA functions.
-
inline void PySend(const std::vector<py::array> &action)
py api
-
inline std::vector<py::array> PyRecv()
py api
-
inline void PyReset(const py::array &env_ids)
py api
-
inline py::array PyRender(const py::array &env_ids, int width, int height, int camera_id)
-
inline py::tuple Xla()