1 #include "caffe2/operators/tile_op.h" 5 REGISTER_CPU_OPERATOR(Tile, TileOp<CPUContext>);
6 REGISTER_CPU_OPERATOR(TileGradient, TileGradientOp<float, CPUContext>);
11 .TensorInferenceFunction(
12 [](
const OperatorDef& def,
const vector<TensorShape>& in) {
13 vector<TensorShape> out(1);
14 out[0] = TensorShape(in[0]);
15 ArgumentHelper helper(def);
17 auto tiles = helper.GetSingleArgument<int32_t>(
"tiles", 1);
18 auto axis = helper.GetSingleArgument<int32_t>(
"axis", 0);
22 out[0].set_unknown_shape(
true);
24 const auto canonical_axis =
25 canonical_axis_index_(axis, out[0].dims().size());
27 canonical_axis, out[0].dims().Get(canonical_axis) * tiles);
32 Constructs a tensor by tiling a given tensor along a specified axis. 34 This operation creates a new tensor by replicating the input tensor 'tiles' 35 times along dimension 'axis'. The output tensor's 'axis'th dimension has 36 input.dims(axis) * tiles elements, and the values of input are replicated 37 'tiles' times along the 'axis'th dimension. 38 For example, tiling [[a b c d]] by tile=2, axis=0 produces 39 [[a b c d], [a b c d]]. 41 .Arg("tiles",
"Number of replicas")
42 .Arg(
"axis",
"Axis to replicate along")
43 .Input(0,
"data",
"The input tensor.")
44 .Input(1,
"tiles",
"(optional) Number of replicas (overrides argument)")
45 .Input(2,
"axis",
"(optional) Axis to replicate along (overrides argument)")
49 "Tensor that will contain input replicated along the given axis.")
50 .InheritOnnxSchema(
"Tile");
52 OPERATOR_SCHEMA(TileGradient).NumInputs(1, 3).NumOutputs(1);
55 using GradientMakerBase::GradientMakerBase;
56 vector<OperatorDef> GetGradientDefs()
override {
59 vector<std::string> g_inputs({GO(0)});
60 if (Def().input_size() > 1) {
61 g_inputs.push_back(I(1));
63 if (Def().input_size() > 2) {
64 g_inputs.push_back(I(2));
67 "TileGradient",
"", g_inputs, vector<string>{GI(0)});
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
static vector< OperatorDef > SingleGradientDef(const Args &...args)
a helper function to allow one to create one single operator def, which is usually the case for many ...