Program Listing for File pooling.h¶
↰ Return to documentation for file (torch/csrc/api/include/torch/nn/modules/pooling.h
)
#pragma once
#include <torch/expanding_array.h>
#include <torch/nn/cloneable.h>
#include <torch/nn/functional/pooling.h>
#include <torch/nn/modules/common.h>
#include <torch/nn/options/pooling.h>
#include <torch/csrc/Export.h>
namespace torch {
namespace nn {
template <size_t D, typename Derived>
class TORCH_API AvgPoolImpl : public torch::nn::Cloneable<Derived> {
public:
AvgPoolImpl(ExpandingArray<D> kernel_size)
: AvgPoolImpl(AvgPoolOptions<D>(kernel_size)) {}
explicit AvgPoolImpl(const AvgPoolOptions<D>& options_);
void reset() override;
void pretty_print(std::ostream& stream) const override;
AvgPoolOptions<D> options;
};
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AvgPool1d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API AvgPool1dImpl : public AvgPoolImpl<1, AvgPool1dImpl> {
public:
using AvgPoolImpl<1, AvgPool1dImpl>::AvgPoolImpl;
Tensor forward(const Tensor& input);
};
TORCH_MODULE(AvgPool1d);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AvgPool2d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API AvgPool2dImpl : public AvgPoolImpl<2, AvgPool2dImpl> {
public:
using AvgPoolImpl<2, AvgPool2dImpl>::AvgPoolImpl;
Tensor forward(const Tensor& input);
};
TORCH_MODULE(AvgPool2d);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AvgPool3d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API AvgPool3dImpl : public AvgPoolImpl<3, AvgPool3dImpl> {
public:
using AvgPoolImpl<3, AvgPool3dImpl>::AvgPoolImpl;
Tensor forward(const Tensor& input);
};
TORCH_MODULE(AvgPool3d);
// ============================================================================
template <size_t D, typename Derived>
class TORCH_API MaxPoolImpl : public torch::nn::Cloneable<Derived> {
public:
MaxPoolImpl(ExpandingArray<D> kernel_size)
: MaxPoolImpl(MaxPoolOptions<D>(kernel_size)) {}
explicit MaxPoolImpl(const MaxPoolOptions<D>& options_);
void reset() override;
void pretty_print(std::ostream& stream) const override;
MaxPoolOptions<D> options;
};
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MaxPool1d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API MaxPool1dImpl : public MaxPoolImpl<1, MaxPool1dImpl> {
public:
using MaxPoolImpl<1, MaxPool1dImpl>::MaxPoolImpl;
Tensor forward(const Tensor& input);
std::tuple<Tensor, Tensor> forward_with_indices(const Tensor& input);
};
TORCH_MODULE(MaxPool1d);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MaxPool2d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API MaxPool2dImpl : public MaxPoolImpl<2, MaxPool2dImpl> {
public:
using MaxPoolImpl<2, MaxPool2dImpl>::MaxPoolImpl;
Tensor forward(const Tensor& input);
std::tuple<Tensor, Tensor> forward_with_indices(const Tensor& input);
};
TORCH_MODULE(MaxPool2d);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MaxPool3d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API MaxPool3dImpl : public MaxPoolImpl<3, MaxPool3dImpl> {
public:
using MaxPoolImpl<3, MaxPool3dImpl>::MaxPoolImpl;
Tensor forward(const Tensor& input);
std::tuple<Tensor, Tensor> forward_with_indices(const Tensor& input);
};
TORCH_MODULE(MaxPool3d);
// ============================================================================
template <size_t D, typename output_size_t, typename Derived>
class TORCH_API AdaptiveMaxPoolImpl : public torch::nn::Cloneable<Derived> {
public:
AdaptiveMaxPoolImpl(output_size_t output_size)
: AdaptiveMaxPoolImpl(
AdaptiveMaxPoolOptions<output_size_t>(output_size)) {}
explicit AdaptiveMaxPoolImpl(
const AdaptiveMaxPoolOptions<output_size_t>& options_)
: options(options_) {}
void reset() override{};
void pretty_print(std::ostream& stream) const override {
stream << "torch::nn::AdaptiveMaxPool" << D << "d"
<< "(output_size=" << options.output_size() << ")";
}
AdaptiveMaxPoolOptions<output_size_t> options;
};
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ AdaptiveMaxPool1d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API AdaptiveMaxPool1dImpl
: public AdaptiveMaxPoolImpl<1, ExpandingArray<1>, AdaptiveMaxPool1dImpl> {
public:
using AdaptiveMaxPoolImpl<1, ExpandingArray<1>, AdaptiveMaxPool1dImpl>::
AdaptiveMaxPoolImpl;
Tensor forward(const Tensor& input);
std::tuple<Tensor, Tensor> forward_with_indices(const Tensor& input);
};
TORCH_MODULE(AdaptiveMaxPool1d);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AdaptiveMaxPool2d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API AdaptiveMaxPool2dImpl : public AdaptiveMaxPoolImpl<
2,
ExpandingArrayWithOptionalElem<2>,
AdaptiveMaxPool2dImpl> {
public:
using AdaptiveMaxPoolImpl<
2,
ExpandingArrayWithOptionalElem<2>,
AdaptiveMaxPool2dImpl>::AdaptiveMaxPoolImpl;
Tensor forward(const Tensor& input);
std::tuple<Tensor, Tensor> forward_with_indices(const Tensor& input);
};
TORCH_MODULE(AdaptiveMaxPool2d);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AdaptiveMaxPool3d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API AdaptiveMaxPool3dImpl : public AdaptiveMaxPoolImpl<
3,
ExpandingArrayWithOptionalElem<3>,
AdaptiveMaxPool3dImpl> {
public:
using AdaptiveMaxPoolImpl<
3,
ExpandingArrayWithOptionalElem<3>,
AdaptiveMaxPool3dImpl>::AdaptiveMaxPoolImpl;
Tensor forward(const Tensor& input);
std::tuple<Tensor, Tensor> forward_with_indices(const Tensor& input);
};
TORCH_MODULE(AdaptiveMaxPool3d);
// ============================================================================
template <size_t D, typename output_size_t, typename Derived>
class TORCH_API AdaptiveAvgPoolImpl : public torch::nn::Cloneable<Derived> {
public:
AdaptiveAvgPoolImpl(output_size_t output_size)
: AdaptiveAvgPoolImpl(
AdaptiveAvgPoolOptions<output_size_t>(output_size)) {}
explicit AdaptiveAvgPoolImpl(
const AdaptiveAvgPoolOptions<output_size_t>& options_)
: options(options_) {}
void reset() override {}
void pretty_print(std::ostream& stream) const override {
stream << "torch::nn::AdaptiveAvgPool" << D << "d"
<< "(output_size=" << options.output_size() << ")";
}
AdaptiveAvgPoolOptions<output_size_t> options;
};
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ AdaptiveAvgPool1d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API AdaptiveAvgPool1dImpl
: public AdaptiveAvgPoolImpl<1, ExpandingArray<1>, AdaptiveAvgPool1dImpl> {
public:
using AdaptiveAvgPoolImpl<1, ExpandingArray<1>, AdaptiveAvgPool1dImpl>::
AdaptiveAvgPoolImpl;
Tensor forward(const Tensor& input);
};
TORCH_MODULE(AdaptiveAvgPool1d);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ AdaptiveAvgPool2d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API AdaptiveAvgPool2dImpl : public AdaptiveAvgPoolImpl<
2,
ExpandingArrayWithOptionalElem<2>,
AdaptiveAvgPool2dImpl> {
public:
using AdaptiveAvgPoolImpl<
2,
ExpandingArrayWithOptionalElem<2>,
AdaptiveAvgPool2dImpl>::AdaptiveAvgPoolImpl;
Tensor forward(const Tensor& input);
};
TORCH_MODULE(AdaptiveAvgPool2d);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ AdaptiveAvgPool3d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API AdaptiveAvgPool3dImpl : public AdaptiveAvgPoolImpl<
3,
ExpandingArrayWithOptionalElem<3>,
AdaptiveAvgPool3dImpl> {
public:
using AdaptiveAvgPoolImpl<
3,
ExpandingArrayWithOptionalElem<3>,
AdaptiveAvgPool3dImpl>::AdaptiveAvgPoolImpl;
Tensor forward(const Tensor& input);
};
TORCH_MODULE(AdaptiveAvgPool3d);
// ============================================================================
template <size_t D, typename Derived>
class TORCH_API MaxUnpoolImpl : public torch::nn::Cloneable<Derived> {
public:
MaxUnpoolImpl(ExpandingArray<D> kernel_size)
: MaxUnpoolImpl(MaxUnpoolOptions<D>(kernel_size)) {}
explicit MaxUnpoolImpl(const MaxUnpoolOptions<D>& options_);
void reset() override;
void pretty_print(std::ostream& stream) const override;
MaxUnpoolOptions<D> options;
};
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MaxUnpool1d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API MaxUnpool1dImpl : public MaxUnpoolImpl<1, MaxUnpool1dImpl> {
public:
using MaxUnpoolImpl<1, MaxUnpool1dImpl>::MaxUnpoolImpl;
Tensor forward(
const Tensor& input,
const Tensor& indices,
const c10::optional<std::vector<int64_t>>& output_size = c10::nullopt);
protected:
FORWARD_HAS_DEFAULT_ARGS({2, AnyValue(c10::optional<std::vector<int64_t>>())})
};
TORCH_MODULE(MaxUnpool1d);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MaxUnpool2d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API MaxUnpool2dImpl : public MaxUnpoolImpl<2, MaxUnpool2dImpl> {
public:
using MaxUnpoolImpl<2, MaxUnpool2dImpl>::MaxUnpoolImpl;
Tensor forward(
const Tensor& input,
const Tensor& indices,
const c10::optional<std::vector<int64_t>>& output_size = c10::nullopt);
protected:
FORWARD_HAS_DEFAULT_ARGS({2, AnyValue(c10::optional<std::vector<int64_t>>())})
};
TORCH_MODULE(MaxUnpool2d);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MaxUnpool3d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API MaxUnpool3dImpl : public MaxUnpoolImpl<3, MaxUnpool3dImpl> {
public:
using MaxUnpoolImpl<3, MaxUnpool3dImpl>::MaxUnpoolImpl;
Tensor forward(
const Tensor& input,
const Tensor& indices,
const c10::optional<std::vector<int64_t>>& output_size = c10::nullopt);
protected:
FORWARD_HAS_DEFAULT_ARGS({2, AnyValue(c10::optional<std::vector<int64_t>>())})
};
TORCH_MODULE(MaxUnpool3d);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FractionalMaxPool2d
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API FractionalMaxPool2dImpl
: public torch::nn::Cloneable<FractionalMaxPool2dImpl> {
public:
FractionalMaxPool2dImpl(ExpandingArray<2> kernel_size)
: FractionalMaxPool2dImpl(FractionalMaxPool2dOptions(kernel_size)) {}
explicit FractionalMaxPool2dImpl(FractionalMaxPool2dOptions options_);
void reset() override;
void pretty_print(std::ostream& stream) const override;
Tensor forward(const Tensor& input);
std::tuple<Tensor, Tensor> forward_with_indices(const Tensor& input);
FractionalMaxPool2dOptions options;
Tensor _random_samples;
};
TORCH_MODULE(FractionalMaxPool2d);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FractionalMaxPool3d
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API FractionalMaxPool3dImpl
: public torch::nn::Cloneable<FractionalMaxPool3dImpl> {
public:
FractionalMaxPool3dImpl(ExpandingArray<3> kernel_size)
: FractionalMaxPool3dImpl(FractionalMaxPool3dOptions(kernel_size)) {}
explicit FractionalMaxPool3dImpl(FractionalMaxPool3dOptions options_);
void reset() override;
void pretty_print(std::ostream& stream) const override;
Tensor forward(const Tensor& input);
std::tuple<Tensor, Tensor> forward_with_indices(const Tensor& input);
FractionalMaxPool3dOptions options;
Tensor _random_samples;
};
TORCH_MODULE(FractionalMaxPool3d);
// ============================================================================
template <size_t D, typename Derived>
class TORCH_API LPPoolImpl : public torch::nn::Cloneable<Derived> {
public:
LPPoolImpl(double norm_type, ExpandingArray<D> kernel_size)
: LPPoolImpl(LPPoolOptions<D>(norm_type, kernel_size)) {}
explicit LPPoolImpl(const LPPoolOptions<D>& options_);
void reset() override;
void pretty_print(std::ostream& stream) const override;
LPPoolOptions<D> options;
};
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LPPool1d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API LPPool1dImpl : public LPPoolImpl<1, LPPool1dImpl> {
public:
using LPPoolImpl<1, LPPool1dImpl>::LPPoolImpl;
Tensor forward(const Tensor& input);
};
TORCH_MODULE(LPPool1d);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LPPool2d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API LPPool2dImpl : public LPPoolImpl<2, LPPool2dImpl> {
public:
using LPPoolImpl<2, LPPool2dImpl>::LPPoolImpl;
Tensor forward(const Tensor& input);
};
TORCH_MODULE(LPPool2d);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LPPool3d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TORCH_API LPPool3dImpl : public LPPoolImpl<3, LPPool3dImpl> {
public:
using LPPoolImpl<3, LPPool3dImpl>::LPPoolImpl;
Tensor forward(const Tensor& input);
};
TORCH_MODULE(LPPool3d);
} // namespace nn
} // namespace torch