2022-09-29 10:29:24 +08:00
|
|
|
#pragma once
|
|
|
|
#include "core/operator.h"
|
|
|
|
|
|
|
|
namespace infini {
|
2023-02-13 22:48:20 +08:00
|
|
|
/**
|
|
|
|
* @brief Add data at the out side of a tensor.
|
|
|
|
*
|
|
|
|
*/
|
2022-09-29 10:29:24 +08:00
|
|
|
class PadObj : public OperatorObj {
|
|
|
|
// the number of start and end pad values for all dims.
|
|
|
|
vector<int> pads;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// pad for appointed axises,if axis is empty,then pad for all axises.
|
2023-02-13 22:48:20 +08:00
|
|
|
/**
|
|
|
|
* @brief Construct a new Pad object.
|
|
|
|
*
|
|
|
|
* @param graph The computation graph that this operator belongs to.
|
|
|
|
* @param input The input tensor.
|
|
|
|
* @param output The padded tensor.
|
|
|
|
* @param pads Add padding elements at the begining and end of each axis.
|
|
|
|
* Suppose that padding axes are [x1, x2, ...], then pads's format is
|
|
|
|
* [x1_begin, x2_begin, ..., x1_end, x2_end, ...]
|
2023-02-15 11:41:06 +08:00
|
|
|
* @param axes Pad for appointed axes. If axis is empty, pad for all axes.
|
2023-02-13 22:48:20 +08:00
|
|
|
*/
|
2022-09-29 10:29:24 +08:00
|
|
|
PadObj(GraphObj *graph, Tensor input, Tensor output,
|
2023-02-15 11:41:06 +08:00
|
|
|
const vector<int> &pads, const optional<vector<int>> &axes);
|
2023-02-12 18:27:52 +08:00
|
|
|
OP_CLONE(PadObj);
|
2022-09-29 10:29:24 +08:00
|
|
|
|
2023-11-23 13:11:50 +08:00
|
|
|
optional<vector<Shape>> inferShape(const TensorVec &inputs) override;
|
2022-09-29 10:29:24 +08:00
|
|
|
std::string toString() const override;
|
|
|
|
int numInputs() const override { return 1; }
|
|
|
|
int numOutputs() const override { return 1; }
|
2022-09-29 11:01:30 +08:00
|
|
|
Shape getPads() const { return pads; }
|
2022-09-29 10:29:24 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
vector<int> getWorkloadVector() const override;
|
|
|
|
vector<int> getOpAttrVector() const override;
|
|
|
|
};
|
2022-10-15 16:29:28 +08:00
|
|
|
} // namespace infini
|