From beb92d1bd718f4562a9f5cfc1357f9a9c5374655 Mon Sep 17 00:00:00 2001 From: eclipsycn Date: Mon, 30 Jul 2018 12:45:25 +0800 Subject: [PATCH] mulop annotation --- .../kernel/central-arm-func/mul_arm_func.h | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/operators/kernel/central-arm-func/mul_arm_func.h b/src/operators/kernel/central-arm-func/mul_arm_func.h index 9dfb1f48a5..38cefe68bd 100644 --- a/src/operators/kernel/central-arm-func/mul_arm_func.h +++ b/src/operators/kernel/central-arm-func/mul_arm_func.h @@ -19,6 +19,39 @@ limitations under the License. */ namespace paddle_mobile { namespace operators { +// 1、如果x,y维度都是2维, +// x = [[1,2], y = [[5,6], +// [3,4]] [7,8]] +// 运算结果为正常矩阵相乘。结果 out = [[1*5+2*7,1*6+2*8],[3*5+4*7, 3*6+4*8]] +// +// 2、如果x的维度大于2或者y的维度大于2,x的维度(2,3,4) ,y的维度(4,1,2) +// x = [[[1,2,3,4], +// [2,3,4,5], +// [3,4,5,6]], +// [[1,2,3,4], +// [2,3,4,5], +// [3,4,5,6]]] +// y = [[[1,2]], +// [[3,4]], +// [[5,6]], +// [[7,8]]] +// 那么就需要借助x_num_col_dims和y_num_col_dims将x和y的维度转换为2维 +// 从模型中读到参数,x_num_col_dims = 2,y_num_col_dims = 1,左开右闭 +// (1) 将x = (2,3,4)的index [0,x_num_col_dims)部分2,3相乘,得到6, +// [x_num_col_dims,x.size())部分4相乘,得到4, +// 将Tensor x的dims重写成(6,4) +// (2) 将y = (4,1,2)的index [0,y_num_col_dims)部分4相乘,得到4, +// [y_num_col_dims,y.xize())部分1,2相乘,得到2, +// 将Tensor y的dims重写成(4,2) +// 并不影响x,y在内存中的分布。 +// x = [[1,2,3,4], y = [[1,2], +// [2,3,4,5], [3,4], +// [3,4,5,6], 矩阵乘法 [5,6], +// [1,2,3,4], [7,8]] +// [2,3,4,5], +// [3,4,5,6]] +// 结果x(6行4列)乘y(4行2列),按1中矩阵相乘,结果out(6行2列)保存在out里。 + template void MulCompute(const MulParam ¶m) { const Tensor *input_x = param.InputX(); -- GitLab