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
Emmay
NiuTrans.Tensor
Commits
59a7030a
Commit
59a7030a
authored
Jul 13, 2018
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net visit code
parent
d49fb9b1
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
81 行增加
和
1 行删除
+81
-1
source/network/XNet.cpp
+55
-0
source/network/XNet.h
+22
-1
source/tensor/XTensor.cpp
+1
-0
source/tensor/XTensor.h
+3
-0
没有找到文件。
source/network/XNet.cpp
查看文件 @
59a7030a
...
...
@@ -23,6 +23,23 @@
namespace
nts
{
unsigned
unsigned
int
netIDGlobal
=
0
;
MUTEX_HANDLE
netMutex
;
/* generate a network id */
unsigned
int
MakeNetID
()
{
if
(
tensorIDGlobal
==
0
)
MUTEX_INIT
(
netMutex
);
MUTEX_LOCK
(
netMutex
);
netIDGlobal
+=
3
;
unsigned
int
id
=
netIDGlobal
;
MUTEX_UNLOCK
(
netMutex
);
return
id
;
}
/* constructor */
XNet
::
XNet
()
{
...
...
@@ -34,6 +51,15 @@ XNet::~XNet()
{
}
/* clear the network */
void
XNet
::
Clear
()
{
nodes
.
Clear
();
gradNodes
.
Clear
();
outputs
.
Clear
();
inputs
.
Clear
();
}
/*
backward propagation to obtain gradient wrt. the loss/error function
>> root - root node (output) of the network
...
...
@@ -86,4 +112,32 @@ void XNet::Traverse(XList &roots)
nodes
.
Clear
();
}
/*
depth-first search given a node (Tarjan's algorithm for topological ordering)
>> node - the node to visit (mark 0:unvisited, 1:visiting, 2:done)
>> orders - topological order of the nodes
>> code - code of the network
*/
void
XNet
::
TarjanVisit
(
XTensor
*
node
,
XList
&
orders
,
const
unsigned
int
code
)
{
if
(
node
==
NULL
)
return
;
if
(
node
->
visitMark
==
code
+
1
){
ShowNTErrors
(
"There is a circle in the network
\n
"
);
}
else
if
(
node
->
visitMark
<=
code
||
node
->
visitMark
>
code
+
2
){
node
->
visitMark
=
code
+
1
;
XLink
&
income
=
node
->
income
;
for
(
int
i
=
0
;
i
<
income
.
tailNum
;
i
++
){
XTensor
*
child
=
income
.
tails
[
i
];
if
(
child
==
NULL
)
continue
;
TarjanVisit
(
child
,
orders
,
code
);
}
node
->
visitMark
=
code
+
2
;
orders
.
Add
(
node
);
}
}
}
\ No newline at end of file
source/network/XNet.h
查看文件 @
59a7030a
...
...
@@ -32,15 +32,27 @@ namespace nts{
/* management of tensor net (or graph) */
struct
XNet
{
/* tensor nodes of the net (in order) */
/* tensor nodes of the net
work
(in order) */
XList
nodes
;
/* tensor nodes to keep gradient for output (e.g., SGD)*/
XList
gradNodes
;
/* output nodes of the network */
XList
outputs
;
/* input nodes of the network */
XList
inputs
;
/* constructor */
XNet
();
/* de-constructor */
~
XNet
();
/* clear the network */
void
Clear
();
/* backward propagation to obtain gradient wrt. the loss/error function */
void
Backward
(
XTensor
&
root
,
XTensor
&
gold
=
NULLTensor
,
LOSS_FUNCTION_NAME
loss
=
NOLOSS
);
...
...
@@ -55,8 +67,16 @@ struct XNet
/* traverse the net and find the topological order by
depth-first search (Tarjan's algorithm) */
void
Traverse
(
XList
&
roots
);
/* depth-first search given a node (Tarjan's algorithm for topological ordering) */
void
TarjanVisit
(
XTensor
*
node
,
XList
&
orders
,
const
unsigned
int
code
);
};
/* we make a unique id for every tensor */
extern
unsigned
int
netIDGlobal
;
extern
MUTEX_HANDLE
netMutex
;
extern
unsigned
int
MakeNetID
();
}
#endif
\ No newline at end of file
source/tensor/XTensor.cpp
查看文件 @
59a7030a
...
...
@@ -237,6 +237,7 @@ void XTensor::Init()
memset
(
isAllValued
,
0
,
sizeof
(
bool
)
*
MAX_TENSOR_DIM_NUM
);
isInit
=
false
;
isTmp
=
false
;
visitMark
=
0
;
}
/* delete data arrays */
...
...
source/tensor/XTensor.h
查看文件 @
59a7030a
...
...
@@ -138,6 +138,9 @@ public:
/* indicates whether the tensor is created temporarily */
bool
isTmp
;
/* mark for traversing the gragh */
int
visitMark
;
/*
the link used to form networks. Note that when we compute on tensors, we actually create a
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论