Commit 0c396646 by liyinqiao

Fix the mistakes in manual and minor errors.

1. Fix the mistakes in manual.
2. Fix the minor errors in Normalize and ScaleAndShift functions.
parent 0223646a
......@@ -114,7 +114,7 @@ OK! Everything is good!
* 在所创建项目中需要引用XTensor.h、core里的CHeader.h和function里的FHeader.h这三个头文件:
* 通过XTensor.h可以获取我们需要操作的XTensor类。
* 通过core里的CHeader.h可以对Tensor进行一些张量运算。
* 通过core里的CHeader.h可以对XTensor进行一些张量运算。
* 通过function里的FHeader.h可以调用一些激活函数。
* 在所创建项目中使用命名空间nts。
......@@ -329,11 +329,11 @@ $$
张量除法的调用方式以及参数说明如下所示:
```cpp
void Div(const XTensor &a, const XTensor &b, XTensor &c, DTYPE alpha = 0.0, int leadingDim = 0);
void Div(const XTensor &a, const XTensor &b, XTensor &c, DTYPE alpha = 0.0, int leadingDim = 0)
void DivMe(XTensor &a, const XTensor &b, DTYPE alpha = 0.0, int leadingDim = 0);
void DivMe(XTensor &a, const XTensor &b, DTYPE alpha = 0.0, int leadingDim = 0)
XTensor Div(const XTensor &a, const XTensor &b, int leadingDim = 0)
XTensor Div(const XTensor &a, const XTensor &b, int leadingDim = 0)
```
Parameters:
......@@ -392,11 +392,11 @@ $$
张量屏蔽的调用方式以及参数说明如下所示:
```cpp
void Mask(const XTensor &a, const XTensor &mask, XTensor &c, DTYPE alpha = 0.0)
void Mask(const XTensor &a, const XTensor &mask, XTensor &c, DTYPE alpha = 0.0)
void MaskMe(XTensor &a, const XTensor &mask, DTYPE alpha = 0.0)
void MaskMe(XTensor &a, const XTensor &mask, DTYPE alpha = 0.0)
XTensor Mask(const XTensor &a, const XTensor &mask, XTensor &c, DTYPE alpha = 0.0)
XTensor Mask(const XTensor &a, const XTensor &mask, XTensor &c, DTYPE alpha = 0.0)
```
Parameters:
......@@ -420,7 +420,7 @@ $$
##### 矩阵乘法的调用
NiuTensor提供了矩阵乘法的计算操作,在NiuTensor/Tensor/core/arithmetic/MatrixMul.h中定义,函数定义为:
NiuTensor提供了矩阵乘法的计算操作,在NiuTensor/tensor/core/arithmetic/MatrixMul.h中定义,函数定义为:
$$
c_{i,j} = trans(a_i) * trans(b_j) * \alpha + c_{i,j} * \beta
......@@ -429,13 +429,13 @@ $$
矩阵乘法的调用方式以及参数说明如下所示:
```cpp
void MatrixMul(const XTensor &a, MATRIX_TRANS_TYPE transposedA, const XTensor &b, MATRIX_TRANS_TYPE transposedB, XTensor &c,DTYPE alpha = (DTYPE)1.0, DTYPE beta = 0, XPRunner * parallelRunner = NULL);
void MatrixMul(const XTensor &a, MATRIX_TRANS_TYPE transposedA, const XTensor &b, MATRIX_TRANS_TYPE transposedB, XTensor &c,DTYPE alpha = (DTYPE)1.0, DTYPE beta = 0, XPRunner * parallelRunner = NULL)
XTensor MatrixMul(const XTensor &a, MATRIX_TRANS_TYPE transposedA, const XTensor &b, MATRIX_TRANS_TYPE transposedB, DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL);
XTensor MatrixMul(const XTensor &a, MATRIX_TRANS_TYPE transposedA, const XTensor &b, MATRIX_TRANS_TYPE transposedB, DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL)
void MatrixMul(const XTensor &a, const XTensor &b, XTensor &c, DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL);
void MatrixMul(const XTensor &a, const XTensor &b, XTensor &c, DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL)
XTensor MatrixMul(const XTensor &a, const XTensor &b, DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL);
XTensor MatrixMul(const XTensor &a, const XTensor &b, DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL)
```
Parameters:
......@@ -460,7 +460,7 @@ t = MatrixMul(*s1, X_NOTRANS, *s2, X_NOTRANS);
矩阵乘法的的测试文件路径为:
NiuTensor/Tensor/test/TMatrixMul.cpp
NiuTensor/tensor/test/TMatrixMul.cpp
#### 矩阵Batch乘法(MatrixMulBatched)
......@@ -476,7 +476,7 @@ $$
##### 矩阵Batch乘法的调用
NiuTensor提供了矩阵Batch乘法的计算操作,在NiuTensor/Tensor/core/arithmetic/MatrixMulBatched.h中定义,函数定义为:
NiuTensor提供了矩阵Batch乘法的计算操作,在NiuTensor/tensor/core/arithmetic/MatrixMulBatched.h中定义,函数定义为:
$$
c_i = trans(a_i) * trans(b_i) * \alpha + c_m * \beta
......@@ -485,9 +485,9 @@ $$
矩阵Batch乘法的调用方式以及参数说明如下所示:
```cpp
XTensor MatrixMulBatched(const XTensor &a, MATRIX_TRANS_TYPE transposedA, const XTensor &b, MATRIX_TRANS_TYPE transposedB,DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL);
XTensor MatrixMulBatched(const XTensor &a, MATRIX_TRANS_TYPE transposedA, const XTensor &b, MATRIX_TRANS_TYPE transposedB,DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL)
XTensor MatrixMulBatched(const XTensor &a, const XTensor &b, DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL);
XTensor MatrixMulBatched(const XTensor &a, const XTensor &b, DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL)
```
Parameters:
......@@ -510,7 +510,7 @@ t = MatrixMulBatched(*s1, X_NOTRANS, *s2, X_NOTRANS);
矩阵Batch乘法的的测试文件路径为:
NiuTensor/Tensor/test/TMatrixMulBatched.cpp
NiuTensor/tensor/test/TMatrixMulBatched.cpp
#### 线性变换(MulAndShift)
......@@ -520,7 +520,7 @@ NiuTensor/Tensor/test/TMatrixMulBatched.cpp
##### 线性变换的调用
NiuTensor提供了张量线性变换的计算操作,在NiuTensor/Tensor/core/arithmetic/MulAndShift.h中定义,函数定义为:
NiuTensor提供了张量线性变换的计算操作,在NiuTensor/tensor/core/arithmetic/MulAndShift.h中定义,函数定义为:
$$
c = x * w + b
......@@ -529,9 +529,9 @@ $$
张量线性变换的调用方式以及参数说明如下所示:
```cpp
XTensor MulAndShift(const XTensor &x, MATRIX_TRANS_TYPE transposedX, const XTensor &w, MATRIX_TRANS_TYPE transposedW, const XTensor &b, DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL);
XTensor MulAndShift(const XTensor &x, MATRIX_TRANS_TYPE transposedX, const XTensor &w, MATRIX_TRANS_TYPE transposedW, const XTensor &b, DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL)
XTensor MulAndShift(const XTensor &x, const XTensor &w, const XTensor &b,DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL);
XTensor MulAndShift(const XTensor &x, const XTensor &w, const XTensor &b,DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL)
```
Parameters:
......@@ -558,7 +558,7 @@ $$
##### 张量点乘的调用
NiuTensor提供了张量点乘的计算操作,用来计算张量中元素点乘结果,该函数在NiuTensor/Tensor/core/arithmetic/Multiply.h中定义,计算方式为:
NiuTensor提供了张量点乘的计算操作,用来计算张量中元素点乘结果,该函数在NiuTensor/tensor/core/arithmetic/Multiply.h中定义,计算方式为:
$$
c_{i,j} = a_{i,j} * b_{i,j} + c_{i,j} * \alpha
......@@ -567,11 +567,11 @@ $$
张量点乘的调用方式以及参数说明如下所示:
```cpp
void Multiply(const XTensor &a, const XTensor &b, XTensor &c, DTYPE alpha = 0.0, int leadingDim = 0);
void Multiply(const XTensor &a, const XTensor &b, XTensor &c, DTYPE alpha = 0.0, int leadingDim = 0)
void MultiplyMe(XTensor &a, const XTensor &b, DTYPE alpha = 0.0, int leadingDim = 0);
void MultiplyMe(XTensor &a, const XTensor &b, DTYPE alpha = 0.0, int leadingDim = 0)
XTensor Multiply(const XTensor &a, const XTensor &b, DTYPE alpha = 0.0, int leadingDim = 0);
XTensor Multiply(const XTensor &a, const XTensor &b, DTYPE alpha = 0.0, int leadingDim = 0)
```
Parameters:
......@@ -593,7 +593,7 @@ t = Multiply(*s1, *s2, 0);
张量点乘的测试文件路径为:
NiuTensor/Tensor/test/TMultiply.cpp
NiuTensor/tensor/test/TMultiply.cpp
#### 减法(Sub)
......@@ -609,7 +609,7 @@ $$
##### 张量减法的调用
NiuTensor提供了张量减法的计算操作,在NiuTensor/Tensor/core/arithmetic/Sub.h中定义,该操作用来进行张量之间的按元素位置相减,并得到相减的结果张量,计算方式为:
NiuTensor提供了张量减法的计算操作,在NiuTensor/tensor/core/arithmetic/Sub.h中定义,该操作用来进行张量之间的按元素位置相减,并得到相减的结果张量,计算方式为:
$$
c = a - b * \beta
......@@ -619,7 +619,7 @@ $$
张量减法的调用方式以及参数说明如下所示:
```cpp
void Sub(const XTensor &a, const XTensor &b, XTensor &c, DTYPE beta = (DTYPE)1.0);
void Sub(const XTensor &a, const XTensor &b, XTensor &c, DTYPE beta = (DTYPE)1.0)
void SubMe(XTensor &a, const XTensor &b, DTYPE beta = (DTYPE)1.0)
......@@ -644,7 +644,7 @@ c = Sub(*a, *b);
张量减法的测试文件路径为:
NiuTensor/Tensor/test/TSub.cpp
NiuTensor/tensor/test/TSub.cpp
#### 加法(Sum)
......@@ -660,7 +660,7 @@ $$
##### 张量加法的调用
NiuTensor提供了张量加法的计算操作,在NiuTensor/Tensor/core/arithmetic中定义,该操作用来进行张量之间的按元素位置相加,并得到相加的结果张量,计算方式为:
NiuTensor提供了张量加法的计算操作,在NiuTensor/tensor/core/arithmetic中定义,该操作用来进行张量之间的按元素位置相加,并得到相加的结果张量,计算方式为:
$$
c = a + b * \beta
......@@ -671,11 +671,11 @@ $$
张量加法的调用方式以及参数说明如下所示:
```cpp
void Sum(const XTensor &a, const XTensor &b, XTensor &c, DTYPE beta = (DTYPE)1.0);
void Sum(const XTensor &a, const XTensor &b, XTensor &c, DTYPE beta = (DTYPE)1.0)
void SumMe(XTensor &a, const XTensor &b, DTYPE beta = (DTYPE)1.0);
void SumMe(XTensor &a, const XTensor &b, DTYPE beta = (DTYPE)1.0)
XTensor Sum(const XTensor &a, const XTensor &b, DTYPE beta = (DTYPE)1.0);
XTensor Sum(const XTensor &a, const XTensor &b, DTYPE beta = (DTYPE)1.0)
```
Parameters:
......@@ -696,7 +696,7 @@ c = Sum(*a, *b);
张量加法的测试文件路径为:
NiuTensor/Tensor/test/TSum.cpp
NiuTensor/tensor/test/TSum.cpp
### 张量存取(getandset)
......@@ -713,9 +713,9 @@ ConvertDataType的作用是将张量中每个元素的数据类型转换为另
NiuTensor提供了张量的ConvertDataType操作,调用方法及参数说明如下所示:
```cpp
void ConvertDataType(const XTensor & input, XTensor & output, TENSOR_DATA_TYPE dataType);
void ConvertDataType(const XTensor & input, XTensor & output, TENSOR_DATA_TYPE dataType)
XTensor ConvertDataType(const XTensor & input, TENSOR_DATA_TYPE dataType);
XTensor ConvertDataType(const XTensor & input, TENSOR_DATA_TYPE dataType)
```
Parameters:
......@@ -739,7 +739,7 @@ ConvertDataType(*a, *b, X_INT);
```
有关张量ConvertDataType的详细代码示例见:
NiuTensor/Tensor/test/TConvertDataType.cpp
NiuTensor/tensor/test/TConvertDataType.cpp
#### 选择(Select)
......@@ -806,7 +806,7 @@ t = SelectRange(*s, 2, 1, 3);
```
有关张量选择的详细代码示例见:
NiuTensor/Tensor/test/TSelect.cpp
NiuTensor/tensor/test/TSelect.cpp
#### SetData
......@@ -826,7 +826,7 @@ NiuTensor提供了张量的SetData操作,调用方法及参数说明如下所
设置张量中每个元素为模板T类型的值:
```cpp
template<class T>
void _SetDataFixed(XTensor * tensor, T value);
void _SetDataFixed(XTensor * tensor, T value)
```
Parameters:
......@@ -836,7 +836,7 @@ Parameters:
设置张量中部分元素为模板T类型的值(函数根据条件张量中非零元素的位置,将输入张量对应位置的值设置为特定值):
```cpp
template<class T>
void _SetDataFixedCond(XTensor* tensor, XTensor* condition, T value);
void _SetDataFixedCond(XTensor* tensor, XTensor* condition, T value)
```
Parameters:
......@@ -847,7 +847,7 @@ Parameters:
沿指定维度设置张量中部分元素为模板T类型的值:
```cpp
template<class T>
void _SetDataDim(XTensor * tensor, int beg, int len, int dim, T p);
void _SetDataDim(XTensor * tensor, int beg, int len, int dim, T p)
```
Parameters:
......@@ -859,7 +859,7 @@ Parameters:
沿指定维度设置张量中部分元素为其他张量元素值:
```cpp
void _SetDataIndexed(XTensor * source, XTensor * modify, int dim, int index);
void _SetDataIndexed(XTensor * source, XTensor * modify, int dim, int index)
```
Parameters:
......@@ -871,7 +871,7 @@ Parameters:
设置张量后两维为下三角矩阵并指定其元素值:
```cpp
void _SetDataLowTri(XTensor * tensor, DTYPE p, int shift);
void _SetDataLowTri(XTensor * tensor, DTYPE p, int shift)
```
Parameters:
......@@ -883,7 +883,7 @@ Parameters:
根据0-1之间的均匀分布随机设置张量值:
```cpp
void _SetDataRand(XTensor * tensor, int rNum, int cNum)
void _SetDataRand(XTensor * tensor, int rNum, int cNum)
```
* tensor(XTensor*) - 输入张量
......@@ -893,7 +893,7 @@ void _SetDataRand(XTensor * tensor, int rNum, int cNum);
根据指定界限内的均匀分布随机设置张量值
```cpp
void _SetDataRand(XTensor * tensor, DTYPE low, DTYPE upper)
void _SetDataRand(XTensor * tensor, DTYPE low, DTYPE upper)
```
* tensor(XTensor*) - 输入张量
* low(DTYPE) - 取值下限
......@@ -902,7 +902,7 @@ void _SetDataRand(XTensor * tensor, DTYPE low, DTYPE upper);
根据指定界限内的等距增长设置张量值
```cpp
void _SetDataRange(XTensor * tensor, DTYPE lower, DTYPE upper, DTYPE step);
void _SetDataRange(XTensor * tensor, DTYPE lower, DTYPE upper, DTYPE step)
```
* tensor(XTensor*) - 输入张量
......@@ -913,7 +913,7 @@ void _SetDataRange(XTensor * tensor, DTYPE lower, DTYPE upper, DTYPE step);
根据指定界限内的均匀分布随机设置张量值,同时对于高于界限的元素值将其置为指定值,低于界限的元素值将其置为0
```cpp
void _SetDataRandP(XTensor * tensor, DTYPE lower, DTYPE upper, DTYPE p, DTYPE value);
void _SetDataRandP(XTensor * tensor, DTYPE lower, DTYPE upper, DTYPE p, DTYPE value)
```
* tensor(XTensor*) - 输入张量
......@@ -942,27 +942,31 @@ SetDataRand(*s, 0.0, 1.0);
```
有关张量SetData的详细代码示例见:
NiuTensor/Tensor/test/TSetData.cpp
NiuTensor/tensor/test/TSetData.cpp
### 数学运算(math)
此部分包括各种非基本代数操作,包括:clip、exp等
此部分包括各种非基本代数操作,包括:一元操作(如Absolute、Exp、Log等)、二元操作(如Mod、Power、Scale等)以及其他复杂操作(如ScaleAndShift、Clip等)
#### 二元操作(Binary)
#### 一元操作(Unary)
##### 什么是张量的元操作?
##### 什么是张量的元操作?
张量的二元操作主要包括张量的求幂、偏移、放缩等可对多个张量进行操作的函数。
张量的一元操作主要包括张量的取绝对值(Absolute)、取指(Exp)、取对数(Log)等只需使用单个变量(张量或标量)进行操作的函数。
##### 张量二元操作的调用
##### 张量一元操作的调用
NiuTensor提供了一些关于张量的一元操作,主要包括Absolute、Ceil、Exp、Floor、IsNonZero、IsZero、Log、Negate、Round、Sign、Sqrt、Square、Sin、Cos、Tan,调用方法详见NiuTensor/tensor/core/math/Unary.h
#### 二元操作(Binary)
NiuTensor提供了一些关于张量的二元操作,主要包括Descale、Mod、Power、Scale、Shift,调用方法详见NiuTensor/Tensor/core/test/Binary.h
##### 什么是张量的二元操作?
##### 张量二元操作示例
张量的二元操作主要包括张量的取余(Mod)、求幂(Power)、放缩(Scale)等需要使用两个变量(张量或标量)进行操作的函数。
有关张量二元操作的详细代码示例见:
##### 张量二元操作的调用
NiuTensor/Tensor/test
NiuTensor提供了一些关于张量的二元操作,主要包括Descale、Mod、Power、Scale、Shift,调用方法详见NiuTensor/tensor/core/math/Binary.h
#### 张量裁剪(Clip)
......@@ -976,7 +980,7 @@ $$
\left(\begin{matrix} 2.0 & 2.0 & 2.0 & 3.0\\4.0 & 5.0 & 5.0 & 5.0\end{matrix}\right)
$$
#####
张量中原始元素值小于2的被设置为2,大于5的值被设置为5。
##### Clip调用
......@@ -1004,39 +1008,42 @@ b = Clip(*a, -1.0, 1.0);
```
有关Clip的详细代码示例见:
NiuTensor/Tensor/test/TClip.cpp
NiuTensor/tensor/test/TClip.cpp
#### Compare
##### 什么是Compare?
Compare的作用是比较张量
Compare的作用是对输入的两个张量中元素的值进行比较
##### Compare的调用
NiuTensor提供了一些关于张量的Compare操作,主要包括Equal、NotEqual、Max、Min,调用方法详见NiuTensor/Tensor/core/test/TCompare.h
NiuTensor提供了一些关于张量的Compare操作,主要包括Equal、NotEqual、Max、Min,调用方法详见NiuTensor/tensor/core/math/Compare.h
##### 张量Compare操作示例
有关张量Compare操作的详细代码示例见:
NiuTensor/Tensor/test/TCompare.cpp
NiuTensor/tensor/test/TCompare.cpp
#### 标准化(Normalize)
##### 什么是张量的标准化?
神经网络需要标准化处理(Normalize),这样做是为了弱化某些变量的值较大而对模型产生影响,Normalize函数定义为:
张量的标准化(Normalize)是神经网络中常用的操作,这样做是为了弱化某些变量的值较大而对模型产生影响,Normalize函数定义为:
>y = a * (x-mean)/sqrt(variance+\epsilon) + b
>
>其中a为缩放因子,b为偏置,mean为输入的均值,variance为方差,\epsilon为方差调节参数。
##### Normalize调用
NiuTensor提供了张量的Normalize操作,调用方法及参数说明如下所示:
```cpp
void NormalizeMe(XTensor & input, int dim, const XTensor & mean, const XTensor & var, const XTensor & a, const XTensor & b, DTYPE epsilon)
void Normalize(const XTensor &input, XTensor &output, int dim, const XTensor &mean, const XTensor &var, const XTensor &a, const XTensor &b, DTYPE epsilon)
void NormalizeMe(XTensor & input, int dim, const XTensor & mean, const XTensor & var, const XTensor & a, const XTensor & b, DTYPE epsilon)
XTensor Normalize(const XTensor &input, int dim, const XTensor &mean, const XTensor &var, const XTensor &a, const XTensor &b, DTYPE epsilon)
```
......@@ -1060,25 +1067,13 @@ t = Normalize(*s, 0, *mean, *var, *a, *b, 0.0F);
```
有关Normalize的详细代码示例见:
NiuTensor/Tensor/test/TNormalize.cpp
#### 幂运算(Power)
NiuTensor/tensor/test/TNormalize.cpp
##### 什么是张量的幂运算操作?
幂运算是一种关于幂的数学运算,张量的幂运算是将张量中的每个元素都进行幂运算从而得到新的张量,一个维度为$3 \times 2$的幂为2.0的张量幂运算过程如下所示:
$$
\left(\begin{matrix}1.0 & 2.0\\3.0 & 4.0\\5.0 & 6.0\end{matrix}\right) \rightarrow
\left(\begin{matrix}1.0 & 4.0\\9.0 & 16.0\\25.0 & 36.0\end{matrix}\right)
$$
#### 缩放和偏移(Scale and Shift)
#### 缩放和偏移(ScaleAndShift)
##### 什么是张量的缩放和偏移?
张量的缩放和偏移计算公式为:p = p * scale + shift,其中scale和shift分别为张量缩放和偏移的参数,一个$2 \times 4$的张量进行缩放和偏移的过程如下所示,缩放参数取2.0,偏移参数取0.5:
张量的缩放和偏移计算公式为:b = a * scale + shift,其中scale和shift分别为张量缩放和偏移的参数,一个$2 \times 4$的张量进行缩放和偏移的过程如下所示,缩放参数取2.0,偏移参数取0.5:
$$
\left(\begin{matrix}0.0 & 1.0 & 2.0 & 3.0\\4.0 & 5.0 & 6.0 & 7.0\end{matrix}\right) \rightarrow
......@@ -1095,7 +1090,7 @@ void ScaleAndShiftMe(XTensor & a, DTYPE scale, DTYPE shift = 0)
XTensor ScaleAndShift(const XTensor &a, DTYPE scale, DTYPE shift = 0)
```
张量的缩放和偏移操作结果为:p = p * scale + shift,其中scale和shift分别为张量的缩放和偏移参数,张量缩放和偏移操作的参数说明如下表所示:
张量的缩放和偏移操作结果为:b = a * scale + shift,其中scale和shift分别为张量的缩放和偏移参数,张量缩放和偏移操作的参数说明如下表所示:
Parameters:
......@@ -1109,27 +1104,11 @@ Parameters:
张量缩放和偏移示例代码如下,input为输入的待操作张量,scaleFactor为缩放参数,shiftFactor为偏移参数:
```cpp
/* call ScaleAndShift function */
t = ScaleAndShift(*s, scaleFactor, shiftFactor);
t = ScaleAndShift(*s, 2.0F, 0.5F);
```
有关张量缩放和偏移的详细代码示例见:
NiuTensor/Tensor/test/TScaleAndShift.cpp
#### 一元操作(Unary)
##### 什么是张量的一元操作?
张量的一元操作主要包括张量的取绝对值、取指、取对数等只需对单个张量进行操作的函数。
##### 张量一元操作的调用
NiuTensor提供了一些关于张量的一元操作,主要包括Absolute、Ceil、Exp、Floor、IsNonZero、IsZero、Log、Round、Sqrt、Square、Sin、Cos、Tan,调用方法详见NiuTensor/Tensor/core/test/Unary.h
##### 张量一元操作示例
有关张量一元操作的详细代码示例见:
NiuTensor/Tensor/test
NiuTensor/tensor/test/TScaleAndShift.cpp
### 数据移动(movement)
......@@ -1170,7 +1149,7 @@ t = CopyIndexed(*s, dim, srcIndex, indexSize, tgtIndex, copyNum);
```
有关CopyIndexed的详细代码示例见:
NiuTensor/Tensor/test/TCopyIndexed.cpp
NiuTensor/tensor/test/TCopyIndexed.cpp
#### 拷贝(CopyValues)
......@@ -1208,7 +1187,7 @@ t = CopyValues(*s);
```
有关张量拷贝的详细代码示例见:
NiuTensor/Tensor/test/TCopyValues.cpp
NiuTensor/tensor/test/TCopyValues.cpp
#### 聚合(Gather)
......@@ -1246,7 +1225,7 @@ t = Gather(*s, *index);
```
有关张量拷贝的详细代码示例见:
NiuTensor/Tensor/test/TGather.cpp
NiuTensor/tensor/test/TGather.cpp
#### 扩展(Spread)
......@@ -1293,7 +1272,7 @@ t = ReduceMax(*s, 1);
```
有关张量归约取最大值的详细代码示例见:
NiuTensor/Tensor/test/TReduceMax.cpp
NiuTensor/tensor/test/TReduceMax.cpp
#### 归约取均值(ReduceMean)
......@@ -1338,7 +1317,7 @@ t = ReduceMean(*s, 1);
有关张量归约取均值的详细代码示例见:
NiuTensor/Tensor/test/TReduceMean.cpp
NiuTensor/tensor/test/TReduceMean.cpp
#### 归约求和(ReduceSum)
......@@ -1391,7 +1370,7 @@ t2 = ReduceSum(*s, 1, *shift2);
```
有关张量归约求和的详细代码示例见:
NiuTensor/Tensor/test/TReduceSum.cpp
NiuTensor/tensor/test/TReduceSum.cpp
#### 归约求总和(ReduceSumAll)
......@@ -1427,7 +1406,7 @@ t = ReduceSumSquared(*s, 0, *shift);
```
有关张量归约求总和的详细代码示例见:
NiuTensor/Tensor/test/TReduceSumAll.cpp
NiuTensor/tensor/test/TReduceSumAll.cpp
#### 归约取平方和(ReduceSumSquared)
......@@ -1466,7 +1445,7 @@ t = ReduceSumSquared(*s, 0, *shift);
```
有关张量归约取平方和的详细代码示例见:
NiuTensor/Tensor/test/TReduceSumSquared.cpp
NiuTensor/tensor/test/TReduceSumSquared.cpp
#### 归约取方差(ReduceVariance)
......@@ -1505,7 +1484,7 @@ t = ReduceVariance(*s, 0, *mean);
```
有关张量归约取方差的详细代码示例见:
NiuTensor/Tensor/test/TReduceVariance.cpp
NiuTensor/tensor/test/TReduceVariance.cpp
### 形状转换(shape)
......@@ -1564,7 +1543,7 @@ t = Concatenate(*s1, *s2, 1);
```
有关张量级联的详细代码示例见:
NiuTensor/Tensor/test/TConcatenate.cpp
NiuTensor/tensor/test/TConcatenate.cpp
#### IsSameShaped
......@@ -1666,7 +1645,7 @@ t = Merge(*sList, 0);
有关张量合并的详细代码示例见:
NiuTensor/Tensor/test/TMerge.cpp
NiuTensor/tensor/test/TMerge.cpp
#### 变形(Reshape)
......@@ -1767,7 +1746,7 @@ Split(*s, tList, 1, 2);
有关张量切分的详细代码示例见:
NiuTensor/Tensor/test/TSplit.cpp
NiuTensor/tensor/test/TSplit.cpp
#### Squeeze
......@@ -1814,7 +1793,7 @@ t = Squeeze(*s);
有关张量Squeeze的详细代码示例见:
NiuTensor/Tensor/test/TSqueeze.cpp
NiuTensor/tensor/test/TSqueeze.cpp
#### 张量堆叠(Stack)
......@@ -1864,7 +1843,7 @@ t = Stack(*sList);
有关张量Stack的详细代码示例见:
NiuTensor/Tensor/test/TStack.cpp
NiuTensor/tensor/test/TStack.cpp
#### 张量维度转换(Transpose)
......@@ -1881,7 +1860,7 @@ $$
NiuTensor提供了张量的Transpose操作,调用方法及参数说明如下所示:
```cpp
XTensor Transpose(const XTensor &a, const int i, const int j);
XTensor Transpose(const XTensor &a, const int i, const int j)
```
Parameters:
......@@ -1902,7 +1881,7 @@ t2 = Transpose(*s, 2, 2);
有关张量Transpose的详细代码示例见:
NiuTensor/Tensor/test/TTranspose.cpp
NiuTensor/tensor/test/TTranspose.cpp
#### Unsqueeze
......@@ -1959,7 +1938,7 @@ t2 = Unsqueeze(*s, 2, 2);
有关张量Unsqueeze的详细代码示例见:
NiuTensor/Tensor/test/TUnsqueeze.cpp
NiuTensor/tensor/test/TUnsqueeze.cpp
### 排序操作(sort)
......@@ -2004,7 +1983,7 @@ Sort(*a, b, *index, 0)
有关Sort的详细代码示例见:
NiuTensor/Tensor/test/TSort.cpp
NiuTensor/tensor/test/TSort.cpp
#### TopK
......@@ -2052,7 +2031,7 @@ TopK(s, t, index, dim, k);
有关TopK的详细代码示例见:
NiuTensor/Tensor/test/TTopK.cpp
NiuTensor/tensor/test/TTopK.cpp
### 激活函数(function)
......@@ -2091,7 +2070,7 @@ y = Dropout(*x, dropProb);
有关Dropout的详细代码示例见:
NiuTensor/Tensor/test/TDropout.cpp
NiuTensor/tensor/test/TDropout.cpp
#### HardTanH
......@@ -2128,7 +2107,7 @@ y = HardTanH(*x);
有关HardTanH的详细代码示例见:
NiuTensor/Tensor/test/THardTanH.cpp
NiuTensor/tensor/test/THardTanH.cpp
#### Identity
......@@ -2163,7 +2142,7 @@ y = Identity(*x);
有关Identity的详细代码示例见:
NiuTensor/Tensor/test/TIdentity.cpp
NiuTensor/tensor/test/TIdentity.cpp
#### LogSoftmax
......@@ -2179,7 +2158,7 @@ NiuTensor提供了张量的LogSoftmax激活函数,调用方法及参数说明
```cpp
void LogSoftmax(const XTensor &x, XTensor &y, int leadDim)
XTensor LogSoftmax(const XTensor &x, int leadDim);
XTensor LogSoftmax(const XTensor &x, int leadDim)
```
Parameters:
......@@ -2199,7 +2178,7 @@ y = LogSoftmax(*x, 1);
有关LogSoftmax的详细代码示例见:
NiuTensor/Tensor/test/TLogSoftmax.cpp
NiuTensor/tensor/test/TLogSoftmax.cpp
#### Rectify
......@@ -2232,7 +2211,7 @@ y = Rectify(*x);
```
有关Rectify的详细代码示例见:
NiuTensor/Tensor/test/TRectify.cpp
NiuTensor/tensor/test/TRectify.cpp
#### Sigmoid
......@@ -2263,7 +2242,7 @@ y = Sigmoid(*x);
```
有关Sigmoid的详细代码示例见:
NiuTensor/Tensor/test/TSigmoid.cpp
NiuTensor/tensor/test/TSigmoid.cpp
#### Softmax
......@@ -2295,7 +2274,7 @@ y = Softmax(*x, 1);
```
有关Softmax的详细代码示例见:
NiuTensor/Tensor/test/TSoftmax.cpp
NiuTensor/tensor/test/TSoftmax.cpp
## 自动微分
......@@ -2325,7 +2304,7 @@ Parameters:
有关Backward的具体用法详见:
NiuTensor/Tensor/Sample中的具体示例
NiuTensor/tensor/Sample中的具体示例
## 高级技巧
......@@ -2377,7 +2356,7 @@ delete mem;
这里我们给出一个矩阵乘法的例子,首先定义张量维度的大小,然后初始化两个维度分别为2*3和3*2的矩阵,使用SetData()方法对矩阵进行赋值,最后计算两个矩阵相乘。
关于矩阵乘法的详细代码请见NiuTensor/Tensor/sample/mul/。
关于矩阵乘法的详细代码请见NiuTensor/tensor/sample/mul/。
```cpp
#include "mul.h"
......
......@@ -39,7 +39,7 @@ where a and b are the scalar and bias respectively, and \epsilon is the adjustme
>> dim - dimension alone which we generate the mean and variance
>> mean - the mean of the input
>> var - the variance of the input
>> a - the scalar
>> a - the scale
>> b - the bias
>> epsilon - a parameter
*/
......@@ -107,7 +107,7 @@ where a and b are the scalar and bias respectively, and \epsilon is the adjustme
>> dim - dimension alone which we generate the mean and variance
>> mean - the mean of the input
>> var - the variance of the input
>> a - the scalar
>> a - the scale
>> b - the bias
>> epsilon - a parameter
*/
......@@ -129,7 +129,7 @@ where a and b are the scalar and bias respectively, and \epsilon is the adjustme
>> dim - dimension alone which we generate the mean and variance
>> mean - the mean of the input
>> var - the variance of the input
>> a - the scalar
>> a - the scale
>> b - the bias
>> epsilon - a parameter
*/
......@@ -151,7 +151,7 @@ where a and b are the scalar and bias respectively, and \epsilon is the adjustme
>> dim - dimension alone which we generate the mean and variance
>> mean - the mean of the input
>> var - the variance of the input
>> a - the scalar
>> a - the scale
>> b - the bias
>> epsilon - a parameter
<< return - the result of normalized the data with normal distribution
......@@ -194,7 +194,7 @@ where a and b are the scalar and bias respectively, and \epsilon is the adjustme
>> dim - dimension alone which we generate the mean and variance
>> mean - the mean of the input
>> var - the variance of the input
>> a - the scalar
>> a - the scale
>> b - the bias
>> epsilon - a parameter
<< return - the result of normalized the data with normal distribution
......
......@@ -36,7 +36,7 @@ b = a * scale + shift
>> a - the input tensor
>> b - the output tensor
>> scale - the scaler factor
>> scale - the scale factor
>> shift - the shift factor
*/
void _ScaleAndShift(const XTensor * a, XTensor * b, DTYPE scale, DTYPE shift)
......@@ -113,7 +113,7 @@ keep the result in the input tensor a and return nothing
a = a * scale + shift
>> a - the input/output tensor
>> scale - the scaler factor
>> scale - the scale factor
>> shift - the shift factor
*/
void _ScaleAndShiftMe(XTensor * a, DTYPE scale, DTYPE shift)
......@@ -128,7 +128,7 @@ keep the result in the input tensor a and return nothing
a = a * scale + shift
>> a - the input/output tensor
>> scale - the scaler factor
>> scale - the scale factor
>> shift - the shift factor
*/
void ScaleAndShiftMe(XTensor& a, DTYPE scale, DTYPE shift)
......@@ -151,7 +151,7 @@ make a new tensor to keep the result and return it
b = a * scale + shift
>> a - the input tensor
>> scale - the scaler factor
>> scale - the scale factor
>> shift - the shift factor
<< return - the result of scaling and shifting all tensor entires
*/
......@@ -188,7 +188,7 @@ b = a * scale + shift
>> a - the input tensor
>> b - the output tensor
>> scale - the scaler factor
>> scale - the scale factor
>> shift - the shift factor
*/
void ScaleAndShift(const XTensor & a, XTensor & b, DTYPE scale, DTYPE shift)
......
......@@ -70,7 +70,7 @@ bool TestNormalize1()
for (int i = 0; i < varOrder; i++)
varUnitNum *= varDimSize[i];
/* a scalar tensor of size (2, 3) */
/* a scale tensor of size (2, 3) */
int aOrder = 2;
int * aDimSize = new int[aOrder];
aDimSize[0] = 2;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论