10 .TensorInferenceFunction([](
const OperatorDef& def,
13 out[0].set_data_type(
in[0].data_type());
37Matrix multiplication $Y = A * B$, where `A` has size (M x K), `B` has size
38(K x N), and `Y` will have a size (M x N). To transpose `A` or `B` before
39multiplication, pass 1 to the `trans_a` and/or `trans_b` arguments, which
40separate the first and second dimensions of the respective matrices using
45- https://github.com/pytorch/pytorch/blob/master/caffe2/operators/matmul_op.cc
49<summary> <b>Example</b> </summary>
54workspace.ResetWorkspace()
56op = core.CreateOperator(
62workspace.FeedBlob("A", np.random.randint(10, size=(3,3)).astype(np.float32))
63workspace.FeedBlob("B", np.random.randint(10, size=(3,3)).astype(np.float32))
64print("A:", workspace.FetchBlob("A"))
65print("B:", workspace.FetchBlob("B"))
66workspace.RunOperatorOnce(op)
67print("Y:", workspace.FetchBlob("Y"))
90 "*(type: Tensor`<float>`)* 2D matrix of size (M x K).")
94 "*(type: Tensor`<float>`)* 2D matrix of size (K x N).")
98 "*(type: Tensor`<float>`)* 2D matrix of size (M x N).")
101 "*(type: int; default: 1)* Exclusive axis that divides the first and "
102 "second dimension of matrix `A`.")
105 "*(type: int; default: 1)* Exclusive axis that divides the first and "
106 "second dimension of matrix `B`.")
109 "*(type: int; default: 0)* Pass 1 to transpose `A` before multiplication and "
110 "after the dimension adjustment using `axis_a`.")
113 "*(type: int; default: 0)* Pass 1 to transpose `B` before multiplication and "
114 "after the dimension adjustment using `axis_b`.");
143 return vector<OperatorDef>{
147 vector<string>{
I(1),
GO(0),
I(0)},
148 vector<string>{
GI(0)},
149 vector<Argument>{MakeArgument<int>(
"trans_a", 1),
150 MakeArgument<int>(
"trans_b", 1),
151 MakeArgument<int>(
"axis_a",
axis_b)}),
155 vector<string>{
GO(0),
I(0),
I(1)},
156 vector<string>{
GI(1)},
157 vector<Argument>{MakeArgument<int>(
"trans_a", 1),
158 MakeArgument<int>(
"trans_b", 1),
159 MakeArgument<int>(
"axis_b",
axis_a)})};
163 return vector<OperatorDef>{
167 vector<string>{
I(1),
GO(0),
I(0)},
168 vector<string>{
GI(0)},
169 vector<Argument>{MakeArgument<int>(
"trans_b", 1),
170 MakeArgument<int>(
"axis_a",
axis_b)}),
174 vector<string>{
I(0),
GO(0),
I(1)},
175 vector<string>{
GI(1)},
176 vector<Argument>{MakeArgument<int>(
"axis_a",
axis_a)})};
182 return vector<OperatorDef>{
186 vector<string>{
GO(0),
I(1),
I(0)},
187 vector<string>{
GI(0)},
188 vector<Argument>{MakeArgument<int>(
"axis_b",
axis_b)}),
192 vector<string>{
GO(0),
I(0),
I(1)},
193 vector<string>{
GI(1)},
194 vector<Argument>{MakeArgument<int>(
"trans_a", 1),
195 MakeArgument<int>(
"axis_b",
axis_a)})};
199 return vector<OperatorDef>{
203 vector<string>{
GO(0),
I(1),
I(0)},
204 vector<string>{
GI(0)},
205 vector<Argument>{MakeArgument<int>(
"trans_b", 1),
206 MakeArgument<int>(
"axis_b",
axis_b)}),
210 vector<string>{
I(0),
GO(0),
I(1)},
211 vector<string>{
GI(1)},
212 vector<Argument>{MakeArgument<int>(
"trans_a", 1),
213 MakeArgument<int>(
"axis_a",
axis_a)})};
A helper class to index into arguments.
static bool HasArgument(const Def &def, const string &name)
static T GetSingleArgument(const Def &def, const string &name, const T &default_value)
bool CopyArguments() const override
vector< OperatorDef > GetGradientDefs() override
const OperatorDef & Def() const
GradientMakerBase(const OperatorDef &def, const vector< GradientWrapper > &g_output)
int canonical_axis_index_(int axis_index, int ndims)
int64_t size_to_dim_(int k, IntArrayRef dims)
int64_t size_from_dim_(int k, IntArrayRef dims)
Return product of all dimensions starting from k.
Copyright (c) 2016-present, Facebook, Inc.
REGISTER_CPU_OPERATOR(ATen, ATenOp< CPUContext >)
C10_EXPORT const Argument & GetArgument(const OperatorDef &def, const string &name)
return vector< TensorShape >
we first initialize the output tensor to all and then do accumulation Any further calls to the The input tensor that has to be accumulated to the output tensor If the output size is not the same as input size
const vector< TensorShape > & in
ArgumentHelper arg_helper(def)
vector< int64_t > GetDimsVector(const TensorShape &shape)
*and produces a single output tensor *expanded *The op also takes an argument *dims *with a list of dimensions for where to add the single dimensional entries If the same blob is provided as input and the operation is copy free This is the exact inverse operation of *Squeeze *Github dims
SparseLengths8BitsRowwiseOp< CPUContext, 0, 1 >::LENGTHS SetDoc(R"DOC(
Variation of SparseLengthsMean operator, where DATA is
stored using 8bits. DATA was quantized with 8Bit row-wise
quantization (see doc to FloatToRowwiseQuantized8Bits operator). To
restore DATA from 8Bit, we use additional input that stores scales
and biases.
)DOC") .Input(0
REGISTER_GRADIENT(CTC, GetCTCGradient)
OperatorDef CreateOperatorDef(const string &type, const string &name, const IterableInputs &inputs, const IterableOutputs &outputs, const IterableArgs &args, const DeviceOption &device_option=DeviceOption(), const string &engine="")
CAFFE_ENFORCE(dims.front() >=0, "Dimension ids must be non-negative.")