:github_url: https://github.com/pytorch/pytorch .. _program_listing_file_torch_csrc_api_include_torch_data_datasets_shared.h: Program Listing for File shared.h ================================= |exhale_lsh| :ref:`Return to documentation for file ` (``torch/csrc/api/include/torch/data/datasets/shared.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include #include #include namespace torch::data::datasets { template class SharedBatchDataset : public BatchDataset< SharedBatchDataset, typename UnderlyingDataset::BatchType, typename UnderlyingDataset::BatchRequestType> { public: using BatchType = typename UnderlyingDataset::BatchType; using BatchRequestType = typename UnderlyingDataset::BatchRequestType; /* implicit */ SharedBatchDataset( std::shared_ptr shared_dataset) : dataset_(std::move(shared_dataset)) {} BatchType get_batch(BatchRequestType request) override { return dataset_->get_batch(std::move(request)); } std::optional size() const override { return dataset_->size(); } UnderlyingDataset& operator*() { return *dataset_; } const UnderlyingDataset& operator*() const { return *dataset_; } UnderlyingDataset* operator->() { return dataset_.get(); } const UnderlyingDataset* operator->() const { return dataset_.get(); } void reset() { dataset_->reset(); } private: std::shared_ptr dataset_; }; template SharedBatchDataset make_shared_dataset(Args&&... args) { return std::make_shared(std::forward(args)...); } } // namespace torch::data::datasets