Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3a5e8260
提交
3a5e8260
authored
6月 30, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
a test where we generate an Elemwise composite with a mod that don't compile and…
a test where we generate an Elemwise composite with a mod that don't compile and commit the fix at the same time.
上级
526689e5
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
33 行增加
和
5 行删除
+33
-5
basic.py
theano/scalar/basic.py
+18
-5
test_basic.py
theano/tensor/tests/test_basic.py
+15
-0
没有找到文件。
theano/scalar/basic.py
浏览文件 @
3a5e8260
...
@@ -953,7 +953,11 @@ class Mod(BinaryScalarOp):
...
@@ -953,7 +953,11 @@ class Mod(BinaryScalarOp):
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
x
%
y
return
x
%
y
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
4
,)
return
(
5
,)
def
c_support_code
(
self
):
#We use a macro as python use % as a special string caractere.
return
"#define THEANO_MACRO_MOD(x,y) (x
%
y)"
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
"""
"""
...
@@ -962,10 +966,10 @@ class Mod(BinaryScalarOp):
...
@@ -962,10 +966,10 @@ class Mod(BinaryScalarOp):
#raise NotImplementedError("Unlike Python, C's modulo returns negative modulo on negative dividend (to implement)")
#raise NotImplementedError("Unlike Python, C's modulo returns negative modulo on negative dividend (to implement)")
t
=
node
.
inputs
[
0
]
.
type
.
upcast
(
*
[
i
.
type
for
i
in
node
.
inputs
[
1
:]])
t
=
node
.
inputs
[
0
]
.
type
.
upcast
(
*
[
i
.
type
for
i
in
node
.
inputs
[
1
:]])
if
t
in
int_types
or
t
in
[
'uint8'
,
'int8'
,
'uint16'
,
'int16'
,
'uint32'
,
'int32'
,
'uint64'
,
'int64'
]:
if
t
in
int_types
or
t
in
[
'uint8'
,
'int8'
,
'uint16'
,
'int16'
,
'uint32'
,
'int32'
,
'uint64'
,
'int64'
]:
x_mod_y
=
"
(
%(x)
s
%%
%(y)
s)"
%
locals
()
x_mod_y
=
"
THEANO_MACRO_MOD(
%(x)
s,
%(y)
s)"
%
locals
()
x_mod_ymm
=
"
(-
%(x)
s
%%
-%(y)
s)"
%
locals
()
x_mod_ymm
=
"
THEANO_MACRO_MOD(-
%(x)
s,
-
%(y)
s)"
%
locals
()
x_mod_ypm
=
"
(
%(x)
s
%%
-%(y)
s)"
%
locals
()
x_mod_ypm
=
"
THEANO_MACRO_MOD(
%(x)
s,
-
%(y)
s)"
%
locals
()
x_mod_ymp
=
"
(-
%(x)
s
%%
%(y)
s)"
%
locals
()
x_mod_ymp
=
"
THEANO_MACRO_MOD(-
%(x)
s,
%(y)
s)"
%
locals
()
elif
t
in
float_types
or
t
in
[
'float32'
,
'float64'
]:
elif
t
in
float_types
or
t
in
[
'float32'
,
'float64'
]:
x_mod_y
=
"fmod(
%(x)
s,
%(y)
s)"
%
locals
()
x_mod_y
=
"fmod(
%(x)
s,
%(y)
s)"
%
locals
()
x_mod_ymm
=
"fmod(-
%(x)
s,-
%(y)
s)"
%
locals
()
x_mod_ymm
=
"fmod(-
%(x)
s,-
%(y)
s)"
%
locals
()
...
@@ -1773,6 +1777,15 @@ class Composite(ScalarOp):
...
@@ -1773,6 +1777,15 @@ class Composite(ScalarOp):
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
1
,)
+
tuple
([
x
.
op
.
c_code_cache_version
()
for
x
in
self
.
env
.
toposort
()])
return
(
1
,)
+
tuple
([
x
.
op
.
c_code_cache_version
()
for
x
in
self
.
env
.
toposort
()])
def
c_support_code
(
self
):
str
=
""
for
node
in
self
.
env
.
toposort
():
try
:
str
+=
node
.
op
.
c_support_code
()
+
"
\n
"
except
gof
.
utils
.
MethodNotDefined
:
pass
return
str
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
if
self
is
other
:
return
True
if
self
is
other
:
return
True
if
not
isinstance
(
other
,
self
.
__class__
):
return
False
if
not
isinstance
(
other
,
self
.
__class__
):
return
False
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
3a5e8260
...
@@ -2676,6 +2676,21 @@ def test_mod():
...
@@ -2676,6 +2676,21 @@ def test_mod():
):
):
assert
fn
(
a
,
b
)
==
a
%
b
,
(
a
,)
assert
fn
(
a
,
b
)
==
a
%
b
,
(
a
,)
def
test_mod_compile
():
"""
This test generate an Elemwise of Composite as:
Elemwise{Composite{Composite{Composite{Composite{mod,EQ},Switch},mul},add}}
The c_code generated is not compiling as of 30 June 2010. I fix the compilation in the same commit.
"""
x
=
tensor
.
vector
()
y
=
tensor
.
vector
()
shape
=
x
.
shape
out
=
tensor
.
switch
(
tensor
.
eq
(
3
%
x
.
shape
[
0
],
0
),
y
,
y
[:
-
1
])
f
=
theano
.
function
([
x
,
y
],
out
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
if
1
:
if
1
:
unittest
.
main
()
unittest
.
main
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论