Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
NiuTrans.Tensor
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
8
Issues
8
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
NiuTrans
NiuTrans.Tensor
Commits
befa4b18
Commit
befa4b18
authored
Sep 16, 2019
by
liyinqiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Limit some XTensor functions with const.
parent
8fc25f38
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
34 行增加
和
34 行删除
+34
-34
source/tensor/XTensor.cpp
+17
-17
source/tensor/XTensor.h
+17
-17
没有找到文件。
source/tensor/XTensor.cpp
查看文件 @
befa4b18
...
@@ -714,7 +714,7 @@ int XTensor::GetSize() const
...
@@ -714,7 +714,7 @@ int XTensor::GetSize() const
}
}
/* get the size of the memory space used */
/* get the size of the memory space used */
int
XTensor
::
GetDataSizeInChar
()
int
XTensor
::
GetDataSizeInChar
()
const
{
{
if
(
isSparse
){
if
(
isSparse
){
int
num
=
int
(
unitNum
*
denseRatio
+
1
);
int
num
=
int
(
unitNum
*
denseRatio
+
1
);
...
@@ -732,7 +732,7 @@ get unit size in terms of "dataType"
...
@@ -732,7 +732,7 @@ get unit size in terms of "dataType"
>> myDataType - type of unit
>> myDataType - type of unit
<< return - unit size
<< return - unit size
*/
*/
int
XTensor
::
GetUnitSize
(
TENSOR_DATA_TYPE
myDataType
)
int
XTensor
::
GetUnitSize
(
TENSOR_DATA_TYPE
myDataType
)
const
{
{
if
(
myDataType
==
X_INT
)
if
(
myDataType
==
X_INT
)
return
sizeof
(
int
);
return
sizeof
(
int
);
...
@@ -752,7 +752,7 @@ get offset (2D)
...
@@ -752,7 +752,7 @@ get offset (2D)
>> row - index of demension 0
>> row - index of demension 0
>> col - index of demension 1
>> col - index of demension 1
*/
*/
MTYPE
XTensor
::
GetOffset2D
(
int
row
,
int
col
)
MTYPE
XTensor
::
GetOffset2D
(
int
row
,
int
col
)
const
{
{
CheckNTErrors
(
order
==
2
,
"Cannot get a 2d cell for a tensor whose order is not 2!"
);
CheckNTErrors
(
order
==
2
,
"Cannot get a 2d cell for a tensor whose order is not 2!"
);
CheckNTErrors
(
row
>=
0
&&
row
<
dimSize
[
0
],
"dimension 0 is out of range!"
);
CheckNTErrors
(
row
>=
0
&&
row
<
dimSize
[
0
],
"dimension 0 is out of range!"
);
...
@@ -767,7 +767,7 @@ get offset (3D)
...
@@ -767,7 +767,7 @@ get offset (3D)
>> d1 - index of demension 1
>> d1 - index of demension 1
>> d2 - index of demension 2
>> d2 - index of demension 2
*/
*/
MTYPE
XTensor
::
GetOffset3D
(
int
d0
,
int
d1
,
int
d2
)
MTYPE
XTensor
::
GetOffset3D
(
int
d0
,
int
d1
,
int
d2
)
const
{
{
CheckNTErrors
(
order
==
3
,
"Cannot get a 3d cell for a tensor whose order is not 2!"
);
CheckNTErrors
(
order
==
3
,
"Cannot get a 3d cell for a tensor whose order is not 2!"
);
CheckNTErrors
(
d0
>=
0
&&
d0
<
dimSize
[
0
],
"dimension 0 is out of range!"
);
CheckNTErrors
(
d0
>=
0
&&
d0
<
dimSize
[
0
],
"dimension 0 is out of range!"
);
...
@@ -982,7 +982,7 @@ void XTensor::SetDataBatchedWithValues(MTYPE * offsets, void * values, int num)
...
@@ -982,7 +982,7 @@ void XTensor::SetDataBatchedWithValues(MTYPE * offsets, void * values, int num)
>> num - number of data items
>> num - number of data items
>> beg - where we start this in the data array of the tensor
>> beg - where we start this in the data array of the tensor
*/
*/
bool
XTensor
::
CheckData
(
const
void
*
d
,
int
num
,
int
beg
)
bool
XTensor
::
CheckData
(
const
void
*
d
,
int
num
,
int
beg
)
const
{
{
if
(
data
==
NULL
||
d
==
NULL
)
if
(
data
==
NULL
||
d
==
NULL
)
return
false
;
return
false
;
...
@@ -1026,7 +1026,7 @@ bool IsFloatEqual(DTYPE a, DTYPE b, float absError, float relError)
...
@@ -1026,7 +1026,7 @@ bool IsFloatEqual(DTYPE a, DTYPE b, float absError, float relError)
}
}
/* check whether the data array is the same as the "answer" */
/* check whether the data array is the same as the "answer" */
bool
XTensor
::
CheckData
(
const
void
*
d
,
int
num
,
float
tolerance
,
int
beg
)
bool
XTensor
::
CheckData
(
const
void
*
d
,
int
num
,
float
tolerance
,
int
beg
)
const
{
{
if
(
data
==
NULL
||
d
==
NULL
)
if
(
data
==
NULL
||
d
==
NULL
)
return
false
;
return
false
;
...
@@ -1102,7 +1102,7 @@ get the value of a cell with the index
...
@@ -1102,7 +1102,7 @@ get the value of a cell with the index
>> size - size of the index
>> size - size of the index
<< return - cell value
<< return - cell value
*/
*/
DTYPE
XTensor
::
Get
(
int
index
[],
int
size
)
DTYPE
XTensor
::
Get
(
int
index
[],
int
size
)
const
{
{
CheckNTErrors
(
dataType
==
DEFAULT_DTYPE
,
"The tensor is not in the default type."
);
CheckNTErrors
(
dataType
==
DEFAULT_DTYPE
,
"The tensor is not in the default type."
);
...
@@ -1114,7 +1114,7 @@ get the value of a cell with its offset
...
@@ -1114,7 +1114,7 @@ get the value of a cell with its offset
>> offset - offset in the array
>> offset - offset in the array
<< return - cell value
<< return - cell value
*/
*/
DTYPE
XTensor
::
Get
(
int
offset
)
DTYPE
XTensor
::
Get
(
int
offset
)
const
{
{
CheckNTErrors
(
dataType
==
DEFAULT_DTYPE
,
"The tensor is not in the default type."
);
CheckNTErrors
(
dataType
==
DEFAULT_DTYPE
,
"The tensor is not in the default type."
);
CheckNTErrors
(
offset
>=
0
&&
offset
<
unitNum
,
"Invalid index!"
);
CheckNTErrors
(
offset
>=
0
&&
offset
<
unitNum
,
"Invalid index!"
);
...
@@ -1166,7 +1166,7 @@ get the value of a cell in a 1d tensor in default type
...
@@ -1166,7 +1166,7 @@ get the value of a cell in a 1d tensor in default type
>> i - idex
>> i - idex
<< return - value of cell(i) in float
<< return - value of cell(i) in float
*/
*/
DTYPE
XTensor
::
Get1D
(
int
i
)
DTYPE
XTensor
::
Get1D
(
int
i
)
const
{
{
CheckNTErrors
((
order
==
1
),
"Cannot get a 2d cell for a tensor whose order is not 2!"
);
CheckNTErrors
((
order
==
1
),
"Cannot get a 2d cell for a tensor whose order is not 2!"
);
CheckNTErrors
((
i
>=
0
&&
i
<
dimSize
[
0
]),
"dimension 0 is out of range!"
);
CheckNTErrors
((
i
>=
0
&&
i
<
dimSize
[
0
]),
"dimension 0 is out of range!"
);
...
@@ -1203,7 +1203,7 @@ get the value of a cell in a 3d tensor
...
@@ -1203,7 +1203,7 @@ get the value of a cell in a 3d tensor
>> d1 - index of dimension 1
>> d1 - index of dimension 1
>> d2 - index of dimension 2
>> d2 - index of dimension 2
*/
*/
DTYPE
XTensor
::
Get3D
(
int
d0
,
int
d1
,
int
d2
)
DTYPE
XTensor
::
Get3D
(
int
d0
,
int
d1
,
int
d2
)
const
{
{
CheckNTErrors
((
order
==
3
),
"Cannot get a 2d cell for a tensor whose order is not 2!"
);
CheckNTErrors
((
order
==
3
),
"Cannot get a 2d cell for a tensor whose order is not 2!"
);
CheckNTErrors
((
d0
>=
0
&&
d0
<
dimSize
[
0
]),
"dimension 0 is out of range!"
);
CheckNTErrors
((
d0
>=
0
&&
d0
<
dimSize
[
0
]),
"dimension 0 is out of range!"
);
...
@@ -1221,7 +1221,7 @@ DTYPE XTensor::Get3D(int d0, int d1, int d2)
...
@@ -1221,7 +1221,7 @@ DTYPE XTensor::Get3D(int d0, int d1, int d2)
get the int value of a cell by its offset
get the int value of a cell by its offset
>> offset - offset of the item
>> offset - offset of the item
*/
*/
int
XTensor
::
GetInt
(
int
offset
)
int
XTensor
::
GetInt
(
int
offset
)
const
{
{
CheckNTErrors
(
dataType
==
X_INT
,
"The tensor is not in the integer type."
);
CheckNTErrors
(
dataType
==
X_INT
,
"The tensor is not in the integer type."
);
CheckNTErrors
(
offset
>=
0
&&
offset
<
unitNum
,
"Invalid index!"
);
CheckNTErrors
(
offset
>=
0
&&
offset
<
unitNum
,
"Invalid index!"
);
...
@@ -1238,7 +1238,7 @@ get the value of a cell in a 1d tensor in int type
...
@@ -1238,7 +1238,7 @@ get the value of a cell in a 1d tensor in int type
>> i - index
>> i - index
<< return - value of cell(i) in int
<< return - value of cell(i) in int
*/
*/
int
XTensor
::
Get1DInt
(
int
i
)
int
XTensor
::
Get1DInt
(
int
i
)
const
{
{
CheckNTErrors
(
order
==
1
,
"Cannot get a 2d cell for a tensor whose order is not 2!"
);
CheckNTErrors
(
order
==
1
,
"Cannot get a 2d cell for a tensor whose order is not 2!"
);
CheckNTErrors
(
i
>=
0
&&
i
<
dimSize
[
0
],
"dimension 0 is out of range!"
);
CheckNTErrors
(
i
>=
0
&&
i
<
dimSize
[
0
],
"dimension 0 is out of range!"
);
...
@@ -1256,7 +1256,7 @@ get the value of a cell in a 2d tensor in int type
...
@@ -1256,7 +1256,7 @@ get the value of a cell in a 2d tensor in int type
>> mi - column index
>> mi - column index
<< return - value of cell(ni, mi) in int
<< return - value of cell(ni, mi) in int
*/
*/
int
XTensor
::
Get2DInt
(
int
ni
,
int
mi
)
int
XTensor
::
Get2DInt
(
int
ni
,
int
mi
)
const
{
{
CheckNTErrors
(
order
==
2
,
"Cannot get a 2d cell for a tensor whose order is not 2!"
);
CheckNTErrors
(
order
==
2
,
"Cannot get a 2d cell for a tensor whose order is not 2!"
);
CheckNTErrors
(
ni
>=
0
&&
ni
<
dimSize
[
0
],
"dimension 0 is out of range!"
);
CheckNTErrors
(
ni
>=
0
&&
ni
<
dimSize
[
0
],
"dimension 0 is out of range!"
);
...
@@ -1276,7 +1276,7 @@ get the value of a cell in a 3d tensor in int type
...
@@ -1276,7 +1276,7 @@ get the value of a cell in a 3d tensor in int type
>> d2 - index of dimension 2
>> d2 - index of dimension 2
<< return - value of cell(d0, d1, d2) in int
<< return - value of cell(d0, d1, d2) in int
*/
*/
int
XTensor
::
Get3DInt
(
int
d0
,
int
d1
,
int
d2
)
int
XTensor
::
Get3DInt
(
int
d0
,
int
d1
,
int
d2
)
const
{
{
CheckNTErrors
(
order
==
3
,
"Cannot get a 2d cell for a tensor whose order is not 2!"
);
CheckNTErrors
(
order
==
3
,
"Cannot get a 2d cell for a tensor whose order is not 2!"
);
CheckNTErrors
(
d0
>=
0
&&
d0
<
dimSize
[
0
],
"dimension 0 is out of range!"
);
CheckNTErrors
(
d0
>=
0
&&
d0
<
dimSize
[
0
],
"dimension 0 is out of range!"
);
...
@@ -1295,7 +1295,7 @@ get the value of a cell in the sparse tensor
...
@@ -1295,7 +1295,7 @@ get the value of a cell in the sparse tensor
>> i - i-th tuple in the tuple list of the sparse tensor
>> i - i-th tuple in the tuple list of the sparse tensor
<< return - value of the tuple
<< return - value of the tuple
*/
*/
DTYPE
XTensor
::
GetInSparse
(
int
i
)
DTYPE
XTensor
::
GetInSparse
(
int
i
)
const
{
{
CheckNTErrors
(
i
>=
0
&&
i
<
unitNum
,
"Index is out of range!"
);
CheckNTErrors
(
i
>=
0
&&
i
<
unitNum
,
"Index is out of range!"
);
CheckNTErrors
(
dataType
==
DEFAULT_DTYPE
,
"The tensor is not in default type."
);
CheckNTErrors
(
dataType
==
DEFAULT_DTYPE
,
"The tensor is not in default type."
);
...
@@ -1311,7 +1311,7 @@ get the key value of a tuple in a sparse tensor
...
@@ -1311,7 +1311,7 @@ get the key value of a tuple in a sparse tensor
>> i - i-th tuple in the tuple list of the sparse tensor
>> i - i-th tuple in the tuple list of the sparse tensor
<< return - key of the tuple
<< return - key of the tuple
*/
*/
int
XTensor
::
GetKeyInSparse
(
int
i
)
int
XTensor
::
GetKeyInSparse
(
int
i
)
const
{
{
CheckNTErrors
(
i
>=
0
&&
i
<
unitNum
,
"Index is out of range!"
);
CheckNTErrors
(
i
>=
0
&&
i
<
unitNum
,
"Index is out of range!"
);
CheckNTErrors
(
dataType
==
DEFAULT_DTYPE
,
"The tensor is not in default type."
);
CheckNTErrors
(
dataType
==
DEFAULT_DTYPE
,
"The tensor is not in default type."
);
...
@@ -1524,7 +1524,7 @@ increase the value of a cell in a 2d tensor
...
@@ -1524,7 +1524,7 @@ increase the value of a cell in a 2d tensor
}
}
/* get the number of non-zero elements (in a sparse tensor) */
/* get the number of non-zero elements (in a sparse tensor) */
int
XTensor
::
GetNonzeroSize
()
int
XTensor
::
GetNonzeroSize
()
const
{
{
if
(
!
isSparse
){
if
(
!
isSparse
){
XPRINT
(
1
,
stderr
,
"WARNING! Counting non-zero elements in a dense tensor might be slow!
\n
"
);
XPRINT
(
1
,
stderr
,
"WARNING! Counting non-zero elements in a dense tensor might be slow!
\n
"
);
...
...
source/tensor/XTensor.h
查看文件 @
befa4b18
...
@@ -287,16 +287,16 @@ public:
...
@@ -287,16 +287,16 @@ public:
int
GetSize
()
const
;
int
GetSize
()
const
;
/* get size of the memory used */
/* get size of the memory used */
int
GetDataSizeInChar
();
int
GetDataSizeInChar
()
const
;
/* get unit size in terms of "dataType" */
/* get unit size in terms of "dataType" */
int
GetUnitSize
(
TENSOR_DATA_TYPE
myDataType
);
int
GetUnitSize
(
TENSOR_DATA_TYPE
myDataType
)
const
;
/* get offset (2D) */
/* get offset (2D) */
MTYPE
GetOffset2D
(
int
row
,
int
col
);
MTYPE
GetOffset2D
(
int
row
,
int
col
)
const
;
/* get offset (3D) */
/* get offset (3D) */
MTYPE
GetOffset3D
(
int
d0
,
int
d1
,
int
d2
);
MTYPE
GetOffset3D
(
int
d0
,
int
d1
,
int
d2
)
const
;
/* a tensor with all entries of 0 */
/* a tensor with all entries of 0 */
void
SetZeroAll
(
XStream
*
stream
=
NULL
);
void
SetZeroAll
(
XStream
*
stream
=
NULL
);
...
@@ -320,10 +320,10 @@ public:
...
@@ -320,10 +320,10 @@ public:
void
SetDataBatchedWithValues
(
MTYPE
*
offsets
,
void
*
values
,
int
num
);
void
SetDataBatchedWithValues
(
MTYPE
*
offsets
,
void
*
values
,
int
num
);
/* check whether the data array is the same as the answer */
/* check whether the data array is the same as the answer */
bool
CheckData
(
const
void
*
answer
,
int
num
,
int
beg
=
0
);
bool
CheckData
(
const
void
*
answer
,
int
num
,
int
beg
=
0
)
const
;
/* check whether the data array is the same as the answer */
/* check whether the data array is the same as the answer */
bool
CheckData
(
const
void
*
answer
,
int
num
,
float
tolerance
,
int
beg
=
0
);
bool
CheckData
(
const
void
*
answer
,
int
num
,
float
tolerance
,
int
beg
=
0
)
const
;
/* set the pointer to "data" */
/* set the pointer to "data" */
void
SetDataPointer
();
void
SetDataPointer
();
...
@@ -332,40 +332,40 @@ public:
...
@@ -332,40 +332,40 @@ public:
void
SetAscendingOrder
(
int
dim
);
void
SetAscendingOrder
(
int
dim
);
/* get the value of a cell with the index */
/* get the value of a cell with the index */
DTYPE
Get
(
int
index
[],
int
size
=
-
1
);
DTYPE
Get
(
int
index
[],
int
size
=
-
1
)
const
;
/* get the value of a cell with the offset */
/* get the value of a cell with the offset */
DTYPE
Get
(
int
offset
);
DTYPE
Get
(
int
offset
)
const
;
/* get the pointer to a cell */
/* get the pointer to a cell */
void
*
GetCell
(
int
index
[],
int
size
=
-
1
)
const
;
void
*
GetCell
(
int
index
[],
int
size
=
-
1
)
const
;
/* get the default type value of a cell in a 1d tensor */
/* get the default type value of a cell in a 1d tensor */
DTYPE
Get1D
(
int
i
);
DTYPE
Get1D
(
int
i
)
const
;
/* get the default type value of a cell in a 2d tensor */
/* get the default type value of a cell in a 2d tensor */
DTYPE
Get2D
(
int
ni
,
int
mi
)
const
;
DTYPE
Get2D
(
int
ni
,
int
mi
)
const
;
/* get the default type value of a cell in a 3d tensor */
/* get the default type value of a cell in a 3d tensor */
DTYPE
Get3D
(
int
d0
,
int
d1
,
int
d2
);
DTYPE
Get3D
(
int
d0
,
int
d1
,
int
d2
)
const
;
/* get the int value of a cell by its offset */
/* get the int value of a cell by its offset */
int
GetInt
(
int
offset
);
int
GetInt
(
int
offset
)
const
;
/* get the int value of a cell in a 1d tensor */
/* get the int value of a cell in a 1d tensor */
int
Get1DInt
(
int
i
);
int
Get1DInt
(
int
i
)
const
;
/* get the int value of a cell in a 2d tensor */
/* get the int value of a cell in a 2d tensor */
int
Get2DInt
(
int
ni
,
int
mi
);
int
Get2DInt
(
int
ni
,
int
mi
)
const
;
/* get the int value of a cell in a 3d tensor */
/* get the int value of a cell in a 3d tensor */
int
Get3DInt
(
int
d0
,
int
d1
,
int
d2
);
int
Get3DInt
(
int
d0
,
int
d1
,
int
d2
)
const
;
/* get the value of a cell in a sparse tensor */
/* get the value of a cell in a sparse tensor */
DTYPE
GetInSparse
(
int
i
);
DTYPE
GetInSparse
(
int
i
)
const
;
/* get the key value of a tuple in a sparse tensor */
/* get the key value of a tuple in a sparse tensor */
int
GetKeyInSparse
(
int
i
);
int
GetKeyInSparse
(
int
i
)
const
;
/* set the value of a cell */
/* set the value of a cell */
bool
Set
(
DTYPE
value
,
int
index
[],
int
size
=
-
1
);
bool
Set
(
DTYPE
value
,
int
index
[],
int
size
=
-
1
);
...
@@ -401,7 +401,7 @@ public:
...
@@ -401,7 +401,7 @@ public:
bool
Add2D
(
DTYPE
value
,
int
ni
,
int
mi
);
bool
Add2D
(
DTYPE
value
,
int
ni
,
int
mi
);
/* get the number of non-zero elements (in a sparse tensor) */
/* get the number of non-zero elements (in a sparse tensor) */
int
GetNonzeroSize
();
int
GetNonzeroSize
()
const
;
/* set the tensor as "temporary" */
/* set the tensor as "temporary" */
void
SetTMPFlag
(
bool
myIsTmp
=
true
);
void
SetTMPFlag
(
bool
myIsTmp
=
true
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论