Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1925556b
提交
1925556b
authored
3月 25, 2015
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2674 from marondeau/master
Added support for __divmod__ and __rdivmod__, with a basic unit test.
上级
26f29455
0ae95f31
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
28 行增加
和
1 行删除
+28
-1
basic.py
theano/tensor/basic.py
+3
-0
test_basic.py
theano/tensor/tests/test_basic.py
+18
-1
var.py
theano/tensor/var.py
+7
-0
没有找到文件。
theano/tensor/basic.py
浏览文件 @
1925556b
...
@@ -2905,6 +2905,9 @@ def div_proxy(x, y):
...
@@ -2905,6 +2905,9 @@ def div_proxy(x, y):
as_tensor_variable
(
y
)
.
dtype
in
discrete_dtypes
))
as_tensor_variable
(
y
)
.
dtype
in
discrete_dtypes
))
return
f
(
x
,
y
)
return
f
(
x
,
y
)
def
divmod
(
x
,
y
):
"""elementvise divmod, using floor_div and mod_check"""
return
floor_div
(
x
,
y
),
mod_check
(
x
,
y
)
@_scal_elemwise_with_nfunc
(
'add'
,
2
,
1
)
@_scal_elemwise_with_nfunc
(
'add'
,
2
,
1
)
def
add
(
a
,
*
other_terms
):
def
add
(
a
,
*
other_terms
):
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
1925556b
...
@@ -6113,7 +6113,7 @@ def test_len():
...
@@ -6113,7 +6113,7 @@ def test_len():
def
test_mod
():
def
test_mod
():
"""
"""
We add this test as not all language and C implementation give the same
We add this test as not all language and C implementation give the same
sign
e
to the result. This check that the c_code of `Mod` is implemented
sign to the result. This check that the c_code of `Mod` is implemented
as Python. That is what we want.
as Python. That is what we want.
"""
"""
x
,
y
=
fscalars
(
'xy'
)
x
,
y
=
fscalars
(
'xy'
)
...
@@ -6126,6 +6126,23 @@ def test_mod():
...
@@ -6126,6 +6126,23 @@ def test_mod():
assert
fn
(
a
,
b
)
==
a
%
b
,
(
a
,)
assert
fn
(
a
,
b
)
==
a
%
b
,
(
a
,)
def
test_divmod
():
"""
Confirm that divmod is equivalent to the python version.
"""
x
,
y
=
fscalars
(
'xy'
)
d
,
r
=
divmod
(
x
,
y
)
fn
=
gof
.
DualLinker
()
.
accept
(
gof
.
FunctionGraph
([
x
,
y
],
[
d
,
r
]))
.
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
)
):
d_v
,
r_v
=
fn
(
a
,
b
)
d_vp
,
r_vp
=
divmod
(
a
,
b
)
assert
d_v
==
d_vp
and
r_v
==
r_vp
,
(
a
,)
def
test_mod_compile
():
def
test_mod_compile
():
"""
"""
This test generate an Elemwise of Composite as:
This test generate an Elemwise of Composite as:
...
...
theano/tensor/var.py
浏览文件 @
1925556b
...
@@ -190,6 +190,9 @@ class _tensor_py_operators:
...
@@ -190,6 +190,9 @@ class _tensor_py_operators:
except
(
NotImplementedError
,
AsTensorError
):
except
(
NotImplementedError
,
AsTensorError
):
return
NotImplemented
return
NotImplemented
def
__divmod__
(
self
,
other
):
return
theano
.
tensor
.
basic
.
divmod
(
self
,
other
)
def
__truediv__
(
self
,
other
):
def
__truediv__
(
self
,
other
):
return
theano
.
tensor
.
basic
.
true_div
(
self
,
other
)
return
theano
.
tensor
.
basic
.
true_div
(
self
,
other
)
...
@@ -235,6 +238,10 @@ class _tensor_py_operators:
...
@@ -235,6 +238,10 @@ class _tensor_py_operators:
def
__rmod__
(
self
,
other
):
def
__rmod__
(
self
,
other
):
return
theano
.
tensor
.
basic
.
mod
(
other
,
self
)
return
theano
.
tensor
.
basic
.
mod
(
other
,
self
)
def
__rdivmod__
(
self
,
other
):
return
theano
.
tensor
.
basic
.
divmod
(
other
,
self
)
def
__rpow__
(
self
,
other
):
def
__rpow__
(
self
,
other
):
return
theano
.
tensor
.
basic
.
pow
(
other
,
self
)
return
theano
.
tensor
.
basic
.
pow
(
other
,
self
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论