Template Class SharedBatchDataset¶
Defined in File shared.h
Page Contents
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 newSharedBatchDataset
like you would astd::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 ashared_ptr
to theUnderlyingDataset
.
-
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.
-
using BatchType = typename UnderlyingDataset::BatchType¶