Rate this Page

Template Class SharedBatchDataset#

Inheritance Relationships#

Base Type#

  • public torch::data::datasets::BatchDataset< SharedBatchDataset< UnderlyingDataset >, UnderlyingDataset::BatchType, UnderlyingDataset::BatchRequestType > (Template Class BatchDataset)

Class Documentation#

template<typename UnderlyingDataset>
class SharedBatchDataset : public torch::data::datasets::BatchDataset<SharedBatchDataset<UnderlyingDataset>, UnderlyingDataset::BatchType, UnderlyingDataset::BatchRequestType>#

A dataset that wraps another dataset in a shared pointer and implements the BatchDataset API, delegating all calls to the shared instance.

This is useful when you want all worker threads in the dataloader to access the same dataset instance. The dataset must take care of synchronization and thread-safe access itself.

Use torch::data::datasets::make_shared_dataset() to create a new SharedBatchDataset like you would a std::shared_ptr.

Public Types

using BatchType = typename UnderlyingDataset::BatchType#
using BatchRequestType = typename UnderlyingDataset::BatchRequestType#

Public Functions

inline SharedBatchDataset(std::shared_ptr<UnderlyingDataset> shared_dataset)#

Constructs a new SharedBatchDataset from a shared_ptr to the UnderlyingDataset.

inline virtual BatchType get_batch(BatchRequestType request) override#

Calls get_batch on the underlying dataset.

inline virtual std::optional<size_t> size() const override#

Returns the size from the underlying dataset.

inline UnderlyingDataset &operator*()#

Accesses the underlying dataset.

inline const UnderlyingDataset &operator*() const#

Accesses the underlying dataset.

inline UnderlyingDataset *operator->()#

Accesses the underlying dataset.

inline const UnderlyingDataset *operator->() const#

Accesses the underlying dataset.

inline void reset()#

Calls reset() on the underlying dataset.