:github_url: https://github.com/pytorch/pytorch .. _program_listing_file_torch_csrc_api_include_torch_data_transforms_stack.h: Program Listing for File stack.h ================================ |exhale_lsh| :ref:`Return to documentation for file ` (``torch/csrc/api/include/torch/data/transforms/stack.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include #include #include #include #include namespace torch::data::transforms { template > struct Stack; template <> struct Stack> : public Collation> { Example<> apply_batch(std::vector> examples) override { std::vector data, targets; data.reserve(examples.size()); targets.reserve(examples.size()); for (auto& example : examples) { data.push_back(std::move(example.data)); targets.push_back(std::move(example.target)); } return {torch::stack(data), torch::stack(targets)}; } }; template <> struct Stack : public Collation> { TensorExample apply_batch(std::vector examples) override { std::vector data; data.reserve(examples.size()); for (auto& example : examples) { data.push_back(std::move(example.data)); } return torch::stack(data); } }; } // namespace torch::data::transforms