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
c2865de7
Commit
c2865de7
authored
Jul 05, 2018
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new code for XLink
parent
34c56119
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
159 行增加
和
11 行删除
+159
-11
source/XLink.cpp
+110
-2
source/XLink.h
+49
-9
没有找到文件。
source/XLink.cpp
查看文件 @
c2865de7
...
...
@@ -16,15 +16,123 @@
*/
/*
* some public functions are defined here
* $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2018-07-04
*
*/
#include <stdio.h>
#include "XLink.h"
namespace
nts
{
// namespace nts(NiuTrans.Tensor)
int
XLink
::
paramSize
=
64
;
/* constuctor */
XLink
::
XLink
()
{
head
=
NULL
;
tails
=
NULL
;
params
=
NULL
;
tailNum
=
0
;
paramNum
=
0
;
type
[
0
]
=
0
;
}
/* deconstructor */
XLink
::~
XLink
()
{
delete
[]
tails
;
delete
[]
(
char
*
)
params
;
}
/* reset it */
void
XLink
::
Reset
()
{
delete
[]
tails
;
delete
[]
(
char
*
)
params
;
head
=
NULL
;
tails
=
NULL
;
params
=
NULL
;
tailNum
=
0
;
paramNum
=
0
;
type
[
0
]
=
0
;
}
/*
set edge type name
>> typeName - type name in string
*/
void
XLink
::
SetType
(
const
char
*
typeName
)
{
strcpy
(
type
,
typeName
);
}
/*
set head
>> h - pointer to the head tensor
*/
void
XLink
::
SetHead
(
XTensor
*
h
)
{
head
=
h
;
}
/*
add a tail
>> t - pointer to the tail tensor
*/
void
XLink
::
AddTail
(
XTensor
*
t
)
{
XTensor
**
ts
=
tails
;
tails
=
new
XTensor
*
[
tailNum
+
1
];
memcpy
(
tails
,
ts
,
sizeof
(
XTensor
*
)
*
tailNum
);
tails
[
tailNum
++
]
=
t
;
delete
[]
ts
;
}
/*
add two tails in one time
>> t1 - pointer to the tail tensor
>> t2 - pointer to another tail tensor
*/
void
XLink
::
AddTwoTails
(
XTensor
*
t1
,
XTensor
*
t2
)
{
XTensor
**
ts
=
tails
;
tails
=
new
XTensor
*
[
tailNum
+
2
];
memcpy
(
tails
,
ts
,
sizeof
(
XTensor
*
)
*
tailNum
);
tails
[
tailNum
++
]
=
t1
;
tails
[
tailNum
++
]
=
t2
;
delete
[]
ts
;
}
/*
add an integer parameter
>> param - parameter in integer
*/
void
XLink
::
AddParamInt
(
int
param
)
{
void
*
ps
=
params
;
params
=
new
char
[
paramNum
+
1
];
memcpy
(
params
,
ps
,
paramNum
*
paramSize
);
int
*
p
=
(
int
*
)((
char
*
)
params
+
paramNum
*
paramSize
);
*
p
=
param
;
paramNum
++
;
delete
[]
(
char
*
)
ps
;
}
/*
add a float parameter
>> param - parameter in float
*/
void
XLink
::
AddParamFloat
(
float
param
)
{
void
*
ps
=
params
;
params
=
new
char
[
paramNum
+
1
];
memcpy
(
params
,
ps
,
paramNum
*
paramSize
);
float
*
p
=
(
float
*
)((
char
*
)
params
+
paramNum
*
paramSize
);
*
p
=
param
;
paramNum
++
;
delete
[]
(
char
*
)
ps
;
}
}
// namespace nts(NiuTrans.Tensor)
source/XLink.h
查看文件 @
c2865de7
...
...
@@ -16,9 +16,7 @@
*/
/*
* some public functions are defined here
* $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2018-07-04
*
*/
#include <stdio.h>
...
...
@@ -33,6 +31,8 @@ namespace nts{ // namespace nts(NiuTrans.Tensor)
/* cross reference */
struct
XTensor
;
#define MAX_OP_NAME_LENGTH 16
/*
This defines the link among tensors in networks. XLink can be
cast as a hyperedge in a graph. when we compute on tensors, we actually create a
...
...
@@ -51,16 +51,55 @@ for a, we also have a edge c -> a in the reverse order (in a view of acyclic dir
struct
XLink
{
/* head of the hyperedge */
XTensor
*
head
;
/* tails of the hyperedge ∂*/
XTensor
*
tails
[];
XTensor
*
head
;
/* tails of the hyperedge */
XTensor
**
tails
;
/* number of tails */
int
tailNum
;
/* parameters used. e.g., c = a * b * \alpha
scalar \alpha is the parameter */
void
*
params
;
/* number of parameters */
int
paramNum
;
/* size of each parameter */
static
int
paramSize
;
/* name of the hyperedge type. e.g., sum, mul ... */
char
type
[
MAX_OP_NAME_LENGTH
];
XLink
(){};
/* constuctor */
XLink
();
~
XLink
(){};
/* deconstructor */
~
XLink
();
/* reset it */
void
Reset
();
/* set edge type name */
void
SetType
(
const
char
*
typeName
);
/* set head */
void
SetHead
(
XTensor
*
h
);
/* add a tail */
void
AddTail
(
XTensor
*
t
);
/* add two tails in one time */
void
AddTwoTails
(
XTensor
*
t1
,
XTensor
*
t2
);
/* add a integer parameter */
void
AddParamInt
(
int
param
);
/* add a integer parameter */
void
AddParamFloat
(
float
param
);
};
}
// namespace nts(NiuTrans.Tensor)
#endif // __XLINK_H__
#endif // __XLINK_H__
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论