Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a53ccd27
提交
a53ccd27
authored
10月 19, 2009
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implemented the c_code for the scalar mod op. It correctly implement the python…
implemented the c_code for the scalar mod op. It correctly implement the python semantic of mod on x86.
上级
8ec730aa
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
41 行增加
和
5 行删除
+41
-5
basic.py
theano/scalar/basic.py
+24
-1
test_basic.py
theano/scalar/tests/test_basic.py
+13
-0
test_opt.py
theano/tensor/tests/test_opt.py
+4
-4
没有找到文件。
theano/scalar/basic.py
浏览文件 @
a53ccd27
...
...
@@ -752,7 +752,30 @@ class Mod(BinaryScalarOp):
def
impl
(
self
,
x
,
y
):
return
x
%
y
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
raise
NotImplementedError
(
"Unlike Python, C's modulo returns negative modulo on negative dividend (to implement)"
)
"""
We want the result to have the same sign as python, not the other implementaiton of mod.
"""
#raise NotImplementedError("Unlike Python, C's modulo returns negative modulo on negative dividend (to implement)")
return
"""
if (
%(x)
s == 0 ||
%(y)
s == 0) {
if (
%(y)
s == 0)
%(z)
s =
%(x)
s
%% %(y)
s;
%(z)
s = 0;
}
//was #if @neg@, I suspect @neg@ to be platform dependant.
//should be true under X86, but could be false for other architecture!
#if 1
else if ((
%(x)
s > 0) == (
%(y)
s > 0)) {
%(z)
s =
%(x)
s
%% %(y)
s;
}
else { /* handled like Python does */
%(z)
s =
%(x)
s
%% %(y)
s;
if (
%(z)
s)
%(z)
s +=
%(y)
s;
}
#else
else
%(z)
s =
%(x)
s
%% %(y)
s;
#endif
"""
%
locals
()
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
return
None
,
None
mod
=
Mod
(
upcast_out
,
name
=
'mod'
)
...
...
theano/scalar/tests/test_basic.py
浏览文件 @
a53ccd27
...
...
@@ -31,6 +31,19 @@ class test_ScalarOps(unittest.TestCase):
fn
=
gof
.
DualLinker
()
.
accept
(
g
)
.
make_function
()
assert
fn
(
1.0
,
2.0
)
==
1.5
def
test_mod
(
self
):
"""
We add this test as not all language and C implementation give the same
signe to the result. This check that the c_code of `Mod` is implemented
as Python. That is what we want.
"""
x
,
y
=
ints
(
'xy'
)
fn
=
gof
.
DualLinker
()
.
accept
(
Env
([
x
,
y
],
[
x
%
y
]))
.
make_function
()
for
a
,
b
in
((
0
,
1
),
(
1
,
1
),
(
0
,
-
1
),
(
1
,
-
1
),
(
-
1
,
-
1
),
(
1
,
2
),
(
-
1
,
2
),
(
1
,
-
2
),
(
-
1
,
-
2
),
(
5
,
3
),
(
-
5
,
3
),
(
5
,
-
3
),
(
-
5
,
-
3
)
):
self
.
failUnless
(
fn
(
a
,
b
)
==
a
%
b
,
(
a
,))
class
test_composite
(
unittest
.
TestCase
):
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
a53ccd27
...
...
@@ -874,12 +874,12 @@ class test_fusion(unittest.TestCase):
(
fx
+
fy
+
theano
.
tensor
.
exp
(
fz
),(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
fxv
+
fyv
+
numpy
.
exp
(
fzv
),
'float32'
),
#35
(
fx
-
fy
-
fz
,(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
fxv
-
fyv
-
fzv
,
'float32'
),
(
fx
-
(
fy
/
fz
),(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
fxv
-
(
fyv
/
fzv
),
'float32'
),
(
fx
-
(
fy
%
fz
),(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
2
,
fxv
-
(
fyv
%
fzv
),
'float32'
),
#TODO: c_code not implemented for %
(
fx
-
(
fy
%
fz
),(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
2
,
fxv
-
(
fyv
%
fzv
),
'float32'
),
(
fx
-
(
fy
>
fz
),(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
fxv
-
(
fyv
>
fzv
),
'float32'
),
(
fx
-
(
fy
>=
fz
),(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
fxv
-
(
fyv
>=
fzv
),
'float32'
),
(
fx
-
(
fy
>=
fz
),(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
fxv
-
(
fyv
>=
fzv
),
'float32'
),
#40
(
fx
-
(
fy
<
fz
),(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
fxv
-
(
fyv
<
fzv
),
'float32'
),
(
fx
-
(
fy
<=
fz
),(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
fxv
-
(
fyv
<=
fzv
),
'float32'
),
#
(fx-(fy==fz),(fx,fy,fz),(fxv,fyv,fzv),1,fxv-(fyv==fzv),'float32'),#TODO: bugged
(
fx
-
(
fy
<=
fz
),(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
fxv
-
(
fyv
<=
fzv
),
'float32'
),
#TODO: bugged on the gpu
(
fx
-
(
fy
==
fz
),(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
fxv
-
(
fyv
==
fzv
),
'float32'
),
#TODO: bugged
(
fx
-
(
fy
!=
fz
),(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
fxv
-
(
fyv
!=
fzv
),
'float32'
),
(
fx
-
fy
+
tan
(
fz
),(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
fxv
-
fyv
+
numpy
.
tan
(
fzv
),
'float32'
),
(
fx
-
fy
+
tanh
(
fz
),(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
fxv
-
fyv
+
numpy
.
tanh
(
fzv
),
'float32'
),
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论