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
2bb37f15
Commit
2bb37f15
authored
Apr 08, 2019
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more methods of accessing tensor entries and creating tensors
parent
9619384f
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
43 行增加
和
3 行删除
+43
-3
source/tensor/XTensor.cpp
+37
-3
source/tensor/XTensor.h
+6
-0
没有找到文件。
source/tensor/XTensor.cpp
查看文件 @
2bb37f15
...
...
@@ -1020,12 +1020,29 @@ get the value of a cell with the index
*/
DTYPE
XTensor
::
Get
(
int
index
[],
int
size
)
{
CheckNTErrors
(
(
dataType
==
DEFAULT_DTYPE
),
"The tensor is not in
default type."
);
CheckNTErrors
(
dataType
==
DEFAULT_DTYPE
,
"The tensor is not in the
default type."
);
return
ToCPU
(
devID
,
GetCell
(
index
,
size
));
}
/*
get the value of a cell with the offset
>> offset - offset in the array
<< return - cell value
*/
DTYPE
XTensor
::
Get
(
int
offset
)
{
CheckNTErrors
(
dataType
==
DEFAULT_DTYPE
,
"The tensor is not in the default type."
);
CheckNTErrors
(
offset
>=
0
&&
offset
<
unitNum
,
"Invalid index!"
);
CheckNTErrors
(
data
!=
NULL
,
"Cannot use an uninitialized tensor!"
);
CheckNTErrors
(
denseRatio
==
1.0
F
,
"Only dense tensors are supported in Get(offset)."
);
DTYPE
*
address
=
(
DTYPE
*
)
data
+
offset
;
return
ToCPU
(
devID
,
address
);
}
/*
get the pointer to a cell
>> index - index of each dimension
>> size - size of index
...
...
@@ -1122,12 +1139,14 @@ get the int value of a cell by its offset
*/
int
XTensor
::
GetInt
(
int
offset
)
{
CheckNTErrors
(
dataType
==
X_INT
,
"The tensor is not in the integer type."
);
CheckNTErrors
(
offset
>=
0
&&
offset
<
unitNum
,
"Invalid index!"
);
CheckNTErrors
(
data
!=
NULL
,
"Cannot use an uninitialized tensor!"
);
CheckNTErrors
(
denseRatio
==
1.0
F
,
"Only dense tensors are supported in Get(offset)."
);
int
*
value
=
(
int
*
)
data
+
offset
;
int
*
address
=
(
int
*
)
data
+
offset
;
return
ToCPUInt
(
devID
,
value
);
return
ToCPUInt
(
devID
,
address
);
}
/*
...
...
@@ -2190,6 +2209,21 @@ void InitTensor(XTensor * tensor, const XTensor * reference)
reference
->
devID
,
reference
->
mem
);
}
/*
initialize a tensor on the CPU with a reference tensor
>> tensor - the tensor we intend to initialize
>> reference - the reference tensor
*/
void
InitTensorOnCPU
(
XTensor
*
tensor
,
const
XTensor
*
reference
)
{
if
(
reference
->
order
<
0
)
return
;
InitTensor
(
tensor
,
reference
->
order
,
reference
->
dimSize
,
reference
->
dataType
,
reference
->
denseRatio
,
-
1
);
}
/* generate a XTensor with no initialization */
XTensor
*
NewTensor
()
{
...
...
source/tensor/XTensor.h
查看文件 @
2bb37f15
...
...
@@ -319,6 +319,9 @@ public:
/* get the value of a cell with the index */
DTYPE
Get
(
int
index
[],
int
size
=
-
1
);
/* get the value of a cell with the offset */
DTYPE
Get
(
int
offset
);
/* get the pointer to a cell */
void
*
GetCell
(
int
index
[],
int
size
=
-
1
)
const
;
...
...
@@ -462,6 +465,9 @@ void InitTensor5D(XTensor * tensor, const int d0, const int d1, const int d2, co
/* initialize a tensor with a reference tensor */
void
InitTensor
(
XTensor
*
tensor
,
const
XTensor
*
reference
);
/* initialize a tensor on the CPU with a reference tensor */
void
InitTensorOnCPU
(
XTensor
*
tensor
,
const
XTensor
*
reference
);
/* generate a XTensor with no initialization */
XTensor
*
NewTensor
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论