1 #include "caffe2/operators/expand_op.h" 7 #include <caffe2/utils/math.h> 11 REGISTER_CPU_OPERATOR(
14 TensorTypes<std::int32_t, std::int64_t, float, double>,
17 REGISTER_CPU_OPERATOR(
20 TensorTypes<std::int32_t, std::int64_t, float, double>,
23 OPERATOR_SCHEMA(Expand)
27 Broadcast the input tensor to a materialized new tensor using given shape. 28 Broadcast rule is similar to "numpy.array(input) * numpy.ones(shape)": 29 Dimensions are right alignment; 30 Two corresponding dimensions must have the same value, or one of them 32 In order to align with PyTorch's `expand`, `shape` is allowed to have entries 33 equal to -1, which means to preserve the size of the corresponding dimension 34 in `X` (so it's actually equivalent to equal to 1). 36 .Input(0, "X",
"(*Tensor`<NumericType>`*): input tensor")
37 .Input(1,
"shape",
"(*Tensor`<int>`*): expand shape")
38 .Output(0,
"Y",
"(*Tensor`<NumericType>`*): expanded tensor");
40 OPERATOR_SCHEMA(ExpandGradient).NumInputs(2).NumOutputs(1);
44 class GetExpandGradient final :
public GradientMakerBase {
45 using GradientMakerBase::GradientMakerBase;
46 std::vector<OperatorDef> GetGradientDefs()
override {
47 return SingleGradientDef(
50 std::vector<string>{GO(0), I(0)},
51 std::vector<string>{GI(0)});
57 REGISTER_GRADIENT(Expand, GetExpandGradient);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...