Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0c03f47d
提交
0c03f47d
authored
11月 04, 2011
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add ceil_int_div with associated tests.
上级
4c3aa369
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
42 行增加
和
17 行删除
+42
-17
basic.py
theano/tensor/basic.py
+8
-0
test_basic.py
theano/tensor/tests/test_basic.py
+34
-17
没有找到文件。
theano/tensor/basic.py
浏览文件 @
0c03f47d
...
...
@@ -2822,6 +2822,14 @@ def int_div(a, b):
"""elementwise integer-division"""
# see decorator for function body
def
ceil_intdiv
(
a
,
b
):
""" return ceil(a/b) when a and b are int """
# Is it faster to cast to float when this don't loose precission?
# return cast(cast(a, scalar.upcast(a, 'float32')) / b, scal.upcast(a, b))
return
int_div
(
a
,
b
)
+
neq
(
a
%
b
,
0
)
def
mod_check
(
x
,
y
):
"""Make sure we do not try to use complex numbers."""
if
(
as_tensor_variable
(
x
)
.
dtype
in
complex_dtypes
or
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
0c03f47d
...
...
@@ -541,31 +541,37 @@ MulInplaceTester = makeBroadcastTester(op = inplace.mul_inplace,
grad
=
_grad_broadcast_binary_normal
,
inplace
=
True
)
_good_broadcast_div_mod_normal_float_inplace
=
dict
(
same_shapes
=
(
rand
(
2
,
3
),
rand
(
2
,
3
)),
scalar
=
(
rand
(
2
,
3
),
rand
(
1
,
1
)),
row
=
(
rand
(
2
,
3
),
rand
(
1
,
3
)),
column
=
(
rand
(
2
,
3
),
rand
(
2
,
1
)),
dtype_mixup_1
=
(
rand
(
2
,
3
),
randint_nonzero
(
2
,
3
)),
dtype_mixup_2
=
(
randint_nonzero
(
2
,
3
),
rand
(
2
,
3
)),
#integers_positive = (randint_ranged(4, 10, (2, 3)), randint_ranged(1, 6, (2, 3))),
#integers_known_to_fail = (numpy.array(-1), numpy.array(5))
complex1
=
(
randcomplex
(
2
,
3
),
randcomplex
(
2
,
3
)),
complex2
=
(
randcomplex
(
2
,
3
),
rand
(
2
,
3
)),
#complex3 = (rand(2,3),randcomplex(2,3)),# Inplace on the first element. Must have the same type.
empty1
=
(
numpy
.
asarray
([]),
numpy
.
asarray
([
1
])),
#empty2 = (numpy.asarray([0]), numpy.asarray([])),
)
# We can't have both input as interger as we need the output
# to have the same dtype to work inplace.
_good_broadcast_div_mod_normal_float_no_complex
=
dict
(
same_shapes
=
(
rand
(
2
,
3
),
rand
(
2
,
3
)),
scalar
=
(
rand
(
2
,
3
),
rand
(
1
,
1
)),
row
=
(
rand
(
2
,
3
),
rand
(
1
,
3
)),
column
=
(
rand
(
2
,
3
),
rand
(
2
,
1
)),
dtype_mixup_1
=
(
rand
(
2
,
3
),
randint_nonzero
(
2
,
3
)),
dtype_mixup_2
=
(
randint_nonzero
(
2
,
3
),
rand
(
2
,
3
)),
#empty2=(numpy.asarray([0]), numpy.asarray([])),
)
_good_broadcast_div_mod_normal_float_inplace
=
dict
(
empty1
=
(
numpy
.
asarray
([]),
numpy
.
asarray
([
1
])),
complex1
=
(
randcomplex
(
2
,
3
),
randcomplex
(
2
,
3
)),
complex2
=
(
randcomplex
(
2
,
3
),
rand
(
2
,
3
)),
# Inplace on the first element. Must have the same type.
#complex3=(rand(2, 3) ,randcomplex(2, 3)),
**
_good_broadcast_div_mod_normal_float_no_complex
)
_good_broadcast_div_mod_normal_float
=
dict
(
empty2
=
(
numpy
.
asarray
([
0
]),
numpy
.
asarray
([])),
**
_good_broadcast_div_mod_normal_float_inplace
)
def
no_complex
(
d
):
"""Remove pairs from dictionary d when the value contains complex data."""
return
dict
((
k
,
v
)
for
k
,
v
in
d
.
iteritems
()
if
all
(
str
(
x
.
dtype
)
not
in
tensor
.
complex_dtypes
for
x
in
v
))
# 'No-complex' versions
.
_good_broadcast_div_mod_normal_float_no_complex
=
no_complex
(
# 'No-complex' versions
, with empty2
_good_broadcast_div_mod_normal_float_no_complex
2
=
no_complex
(
_good_broadcast_div_mod_normal_float
)
_good_broadcast_div_mod_normal_float_inplace_no_complex
=
no_complex
(
_good_broadcast_div_mod_normal_float_inplace
)
...
...
@@ -605,9 +611,20 @@ TrueDivInplaceTester = makeBroadcastTester(op = inplace.true_div_inplace,
grad_rtol
=
div_grad_rtol
,
inplace
=
True
)
CeilIntDivTester
=
makeBroadcastTester
(
op
=
tensor
.
ceil_intdiv
,
expected
=
lambda
x
,
y
:
check_floatX
((
x
,
y
),
(
x
//
y
)
+
((
x
%
y
)
!=
0
)),
good
=
_good_broadcast_div_mod_normal_float_no_complex
,
# As we implement this function with neq, the gradient returned is always 0.
# grad=_grad_broadcast_div_mod_normal,
# grad_rtol=div_grad_rtol,
)
ModTester
=
makeBroadcastTester
(
op
=
tensor
.
mod
,
expected
=
lambda
x
,
y
:
numpy
.
asarray
(
x
%
y
,
dtype
=
theano
.
scalar
.
basic
.
upcast
(
x
.
dtype
,
y
.
dtype
)),
good
=
_good_broadcast_div_mod_normal_float_no_complex
,
good
=
_good_broadcast_div_mod_normal_float_no_complex
2
,
# integers = (randint(2, 3), randint_nonzero(2, 3)),
# dtype_mixup_1 = (rand(2, 3), randint_nonzero(2, 3)),
# dtype_mixup_2 = (randint_nonzero(2, 3), rand(2, 3))),
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论