Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
10702c05
提交
10702c05
authored
1月 21, 2008
作者:
olivier@olivier-desktop
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bla
上级
de75d2c1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
115 行增加
和
2 行删除
+115
-2
core.py
core.py
+66
-2
omega.h
omega.h
+49
-0
没有找到文件。
core.py
浏览文件 @
10702c05
...
...
@@ -177,12 +177,41 @@ class omega_op(gof.PythonOp):
def
grad
(
*
args
):
return
UNDEFINED
def
__create_c_code
(
self
):
behavior
=
self
.
c_impl
(
self
.
inputs
,
self
.
outputs
)
(
inames
,
onames
),
_1
,
_2
,
_3
=
inspect
.
getargspec
(
self
.
c_impl
)
struct
=
"""
struct _omega_
%(name)
s {
_omega_
%(name)
s() {}
void extract(void) {
}
void execute(void) {
%(code)
s
}
void sync(void) {
}
};
"""
%
self
.
__class__
.
__name__
,
behavior
def
c_alloc
(
self
):
raise
Exception
(
"Cannot allocate output arrays for this Op."
)
def
c_impl
(
inputs
,
outputs
):
raise
NotImplementedError
()
def
c_thunk
(
self
):
self
.
c_alloc
()
if
self
.
c_module
:
a
else
:
def
c_perform
(
self
):
pass
self
.
c_thunk
()()
def
scalar_switch
(
normal_f
,
scalar_f
,
scalar_f_reverse
=
None
):
def
f
(
x
,
y
):
...
...
@@ -272,8 +301,43 @@ def tensor_scalar_op(impl):
return
ret
# @omega_op
# def add((x, y), (z, )):
# def grad(gz):
# return gz
# def c_alloc():
# return numpy.ndarray(x.shape, dtype = x.dtype)
# c_impl = """
# for (int i = 0; i < z.ncols; i++) {
# for (int j = 0; j < z.nrows; j++) {
# z(i, j) = x(i, j) + y(i, j);
# }
# }
# """
## Addition ##
class
add
(
omega_op
):
impl
=
assert_same_shapes
(
numpy
.
ndarray
.
__add__
)
def
grad
(
x
,
y
,
gz
):
return
gz
def
alloc
(
x
,
y
):
return
numpy
.
ndarray
(
x
.
shape
,
dtype
=
x
.
dtype
)
def
c_impl
(
x
,
y
,
z
):
return
"""
for (int i = 0; i < z.ncols; i++) {
for (int j = 0; j < z.nrows; j++) {
z(i, j) = x(i, j) + y(i, j);
}
}
"""
class
proto_add_elemwise
(
omega_op
):
def
grad
(
x
,
y
,
gz
):
return
gz
...
...
omega.h
0 → 100644
浏览文件 @
10702c05
#ifndef _OMEGA_H
#define _OMEGA_H
//#include whatever defines PyArrayObject
template
<
typename
T
>
struct
TMat_t
{
T
*
__restrict__
d
;
/**< pointer to element (0,0) */
size_t
M
;
/**< number of rows */
size_t
N
;
/**< number of columns */
size_t
m
;
/**< row stride */
size_t
n
;
/**< column stride */
bool
invalid
;
/** null */
TMat_t
(
const
PyArrayObject
*
o
)
:
d
((
double
*
)
o
->
data
),
M
((
o
->
nd
==
2
)
?
o
->
dimensions
[
0
]
:
0
),
N
((
o
->
nd
==
2
)
?
o
->
dimensions
[
1
]
:
0
),
m
((
o
->
nd
==
2
)
?
o
->
strides
[
0
]
/
sizeof
(
double
)
:
0
),
n
((
o
->
nd
==
2
)
?
o
->
strides
[
1
]
/
sizeof
(
double
)
:
0
),
invalid
((
o
->
nd
!=
2
)
||
(
o
->
descr
->
elsize
!=
sizeof
(
T
)))
{
}
/** unsafe element access */
const
T
&
operator
()(
size_t
i
,
size_t
j
)
const
{
return
d
[
i
*
m
+
j
*
n
];
}
/** unsafe element access */
T
&
operator
()(
size_t
i
,
size_t
j
)
{
return
d
[
i
*
m
+
j
*
n
];
}
/** safe element access */
const
T
&
at
(
size_t
i
,
size_t
j
)
const
{
return
d
[
assert
((
i
<
M
)
&&
(
j
<
N
)),
i
*
m
+
j
*
n
];
}
/** safe element access */
T
&
at
(
size_t
i
,
size_t
j
)
{
return
d
[
assert
((
i
<
M
)
&&
(
j
<
N
)),
i
*
m
+
j
*
n
];
}
};
#endif
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论