Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
NiuTrans.Tensor
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
杨迪
NiuTrans.Tensor
Commits
137df5d9
Commit
137df5d9
authored
Mar 12, 2020
by
liyinqiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge with HU Chi branch.
1. Offer global setting for enableGrad. 2. Update XList. 3. Minor error fixed.
parent
b3dfbdcd
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
33 行增加
和
53 行删除
+33
-53
source/tensor/XCall.h
+20
-17
source/tensor/XList.cpp
+2
-22
source/tensor/XList.h
+11
-14
source/tensor/XTensor.cpp
+0
-0
没有找到文件。
source/tensor/XCall.h
查看文件 @
137df5d9
...
...
@@ -26,6 +26,9 @@
namespace
nts
{
// namespace nts(NiuTrans.Tensor)
/* default settings */
#define X_ENABLE_GRAD false
/*
* we define the "new and delete" functions below
*/
...
...
@@ -38,13 +41,13 @@ void InitTensorV2(XTensor * tensor,
/* initialize a dense XTensor */
void
InitTensor
(
XTensor
*
tensor
,
const
int
myOrder
,
const
int
*
myDimSize
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* initialize a scalar V2 */
void
InitTensor0DV2
(
XTensor
*
tensor
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
XMem
*
myMem
=
NULL
);
/* initialize a scalar */
void
InitTensor0D
(
XTensor
*
tensor
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
void
InitTensor0D
(
XTensor
*
tensor
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* initialize a dense vector V2 */
void
InitTensor1DV2
(
XTensor
*
tensor
,
const
int
num
,
...
...
@@ -52,7 +55,7 @@ void InitTensor1DV2(XTensor * tensor, const int num,
/* initialize a dense vector */
void
InitTensor1D
(
XTensor
*
tensor
,
const
int
num
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* initialize a dense matrix V2 */
void
InitTensor2DV2
(
XTensor
*
tensor
,
const
int
rowNum
,
const
int
colNum
,
...
...
@@ -60,7 +63,7 @@ void InitTensor2DV2(XTensor * tensor, const int rowNum, const int colNum,
/* initialize a dense matrix */
void
InitTensor2D
(
XTensor
*
tensor
,
const
int
rowNum
,
const
int
colNum
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* initialize a dense 3d tensor V2 */
void
InitTensor3DV2
(
XTensor
*
tensor
,
const
int
d0
,
const
int
d1
,
const
int
d2
,
...
...
@@ -68,7 +71,7 @@ void InitTensor3DV2(XTensor * tensor, const int d0, const int d1, const int d2,
/* initialize a dense 3d tensor */
void
InitTensor3D
(
XTensor
*
tensor
,
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* initialize a dense 4d tensor V2 */
void
InitTensor4DV2
(
XTensor
*
tensor
,
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
...
...
@@ -76,7 +79,7 @@ void InitTensor4DV2(XTensor * tensor, const int d0, const int d1, const int d2,
/* initialize a dense 4d tensor */
void
InitTensor4D
(
XTensor
*
tensor
,
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* initialize a dense 5d tensor V2 */
void
InitTensor5DV2
(
XTensor
*
tensor
,
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
int
d4
,
...
...
@@ -84,7 +87,7 @@ void InitTensor5DV2(XTensor * tensor, const int d0, const int d1, const int d2,
/* initialize a dense 5d tensor */
void
InitTensor5D
(
XTensor
*
tensor
,
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
int
d4
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* initialize a tensor with a reference tensor V2 */
void
InitTensorV2
(
XTensor
*
tensor
,
const
XTensor
*
reference
);
...
...
@@ -104,7 +107,7 @@ XTensor * NewTensorV2(const int myOrder, const int * myDimSize, const TENSOR_DAT
/* generate a dense XTensor */
XTensor
*
NewTensor
(
const
int
myOrder
,
const
int
*
myDimSize
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* generate a XTensor which allocates data on the buffer V2 */
XTensor
*
NewTensorBufV2
(
const
int
myOrder
,
const
int
*
myDimSize
,
...
...
@@ -113,26 +116,26 @@ XTensor * NewTensorBufV2(const int myOrder, const int * myDimSize,
/* generate a dense XTensor which allocates data on the buffer */
XTensor
*
NewTensorBuf
(
const
int
myOrder
,
const
int
*
myDimSize
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* generate a XTensor which allocates data on the buffer V2 */
XTensor
*
NewTensorBufV2
(
const
XTensor
*
reference
,
int
devID
,
XMem
*
myMem
);
/* generate a XTensor which allocates data on the buffer */
XTensor
*
NewTensorBuf
(
const
XTensor
*
reference
,
int
devID
,
const
bool
isEnableGrad
=
true
);
XTensor
*
NewTensorBuf
(
const
XTensor
*
reference
,
int
devID
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* generate a scalar V2 */
XTensor
*
NewTensor0DV2
(
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
XMem
*
myMem
=
NULL
);
/* generate a scalar */
XTensor
*
NewTensor0D
(
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
XTensor
*
NewTensor0D
(
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* generate a dense vector V2 */
XTensor
*
NewTensor1DV2
(
const
int
num
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
XMem
*
myMem
=
NULL
);
/* generate a dense vector */
XTensor
*
NewTensor1D
(
const
int
num
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
XTensor
*
NewTensor1D
(
const
int
num
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* generate a dense matrix V2 */
XTensor
*
NewTensor2DV2
(
const
int
rowNum
,
const
int
colNum
,
...
...
@@ -142,7 +145,7 @@ XTensor * NewTensor2DV2(const int rowNum, const int colNum,
/* generate a dense matrix */
XTensor
*
NewTensor2D
(
const
int
rowNum
,
const
int
colNum
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* generate a dense 3d tensor V2 */
XTensor
*
NewTensor3DV2
(
const
int
d0
,
const
int
d1
,
const
int
d2
,
...
...
@@ -152,7 +155,7 @@ XTensor * NewTensor3DV2(const int d0, const int d1, const int d2,
/* generate a dense 3d tensor */
XTensor
*
NewTensor3D
(
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* generate a dense 4d tensor V2 */
XTensor
*
NewTensor4DV2
(
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
...
...
@@ -162,7 +165,7 @@ XTensor * NewTensor4DV2(const int d0, const int d1, const int d2, const int d3,
/* generate a dense 4d tensor */
XTensor
*
NewTensor4D
(
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* generate a dense 5d tensor V2 */
XTensor
*
NewTensor5DV2
(
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
int
d4
,
...
...
@@ -172,10 +175,10 @@ XTensor * NewTensor5DV2(const int d0, const int d1, const int d2, const int d3,
/* generate a dense 5d tensor */
XTensor
*
NewTensor5D
(
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
int
d4
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* generate a dense vector by range */
XTensor
*
NewTensorRange
(
int
lower
,
int
upper
,
int
step
,
const
TENSOR_DATA_TYPE
myDataType
=
X_INT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
XTensor
*
NewTensorRange
(
int
lower
,
int
upper
,
int
step
,
const
TENSOR_DATA_TYPE
myDataType
=
X_INT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
X_ENABLE_GRAD
);
/* generate a copy of XTensor (with a reference to a given tensor) */
XTensor
*
NewTensor
(
const
XTensor
*
a
,
bool
isFilledData
=
true
);
...
...
source/tensor/XList.cpp
查看文件 @
137df5d9
...
...
@@ -249,26 +249,6 @@ inline int TensorListBase<T>::FindFirst(const T& item)
return
-
1
;
}
template
<>
inline
int
TensorListBase
<
Example
>::
FindFirst
(
const
Example
&
item
)
{
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
if
(
item
.
id
==
items
[
i
].
id
)
return
i
;
}
return
-
1
;
}
template
<>
inline
int
TensorListBase
<
Result
>::
FindFirst
(
const
Result
&
item
)
{
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
if
(
item
.
id
==
items
[
i
].
id
)
return
i
;
}
return
-
1
;
}
/* clear the data array */
template
<
typename
T
>
void
TensorListBase
<
T
>::
Clear
()
...
...
@@ -383,8 +363,7 @@ template struct TensorListBase<long>;
template
struct
TensorListBase
<
float
>
;
template
struct
TensorListBase
<
short
>
;
template
struct
TensorListBase
<
XTensor
*>
;
template
struct
TensorListBase
<
Result
>
;
template
struct
TensorListBase
<
Example
>
;
template
struct
TensorListBase
<
uint64_t
>
;
template
struct
TensorListBase
<
void
*>
;
}
/* end of the nts (NiuTrans.Tensor) namespace */
\ No newline at end of file
source/tensor/XList.h
查看文件 @
137df5d9
...
...
@@ -26,6 +26,8 @@
#include "XMem.h"
#include "XGlobal.h"
#include <cstdint>
#ifndef __TensorList_H__
#define __TensorList_H__
...
...
@@ -118,7 +120,14 @@ public:
void
Shuffle
(
int
nround
=
10
,
int
beg
=
-
1
,
int
len
=
0
);
/* short */
T
&
operator
[]
(
int
i
)
{
return
GetItem
(
i
);
};
T
&
operator
[]
(
int
i
)
{
CheckNTErrors
(
i
>=
-
count
&&
i
<
count
,
"Index of a list item is out of scope!"
);
CheckNTErrors
(
count
>
0
,
"Cannt index the item in an empty list!"
);
if
(
i
<
0
)
return
items
[
count
+
i
];
else
return
items
[
i
];
};
T
&
Get
(
int
i
)
{
return
GetItem
(
i
);
};
void
Set
(
int
i
,
T
item
)
{
SetItem
(
i
,
item
);
};
};
...
...
@@ -132,19 +141,7 @@ typedef TensorListBase<char*> StrList;
typedef
TensorListBase
<
long
>
LongList
;
typedef
TensorListBase
<
float
>
FloatList
;
typedef
TensorListBase
<
short
>
ShortList
;
struct
Example
{
int
id
;
IntList
data
;
};
struct
Result
{
int
id
;
IntList
data
;
};
typedef
TensorListBase
<
Result
>
ResultList
;
typedef
TensorListBase
<
Example
>
ExampleList
;
typedef
TensorListBase
<
uint64_t
>
UInt64List
;
typedef
TensorListBase
<
XTensor
*>
TensorList
;
}
/* end of the nts (NiuTrans.Tensor) namespace */
...
...
source/tensor/XTensor.cpp
查看文件 @
137df5d9
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论