Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
572a14a1
提交
572a14a1
authored
3月 02, 2018
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a map of values_approx functions from cpu to gpu.
上级
757b4d59
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
66 行增加
和
30 行删除
+66
-30
basic_ops.py
theano/gpuarray/basic_ops.py
+5
-3
type.py
theano/gpuarray/type.py
+61
-27
没有找到文件。
theano/gpuarray/basic_ops.py
浏览文件 @
572a14a1
...
...
@@ -30,7 +30,7 @@ except ImportError:
pass
from
.type
import
(
GpuArrayType
,
GpuArrayConstant
,
gpu_context_type
,
get_context
,
ContextNotDefined
)
get_context
,
ContextNotDefined
,
EQ_MAP
)
from
.fp16_help
import
write_w
...
...
@@ -581,7 +581,8 @@ class HostFromGpu(Op):
# Keep the special comparison if there is one.
values_eq_approx
=
getattr
(
x
.
tag
,
'values_eq_approx'
,
None
)
if
values_eq_approx
:
out_var
.
tag
.
values_eq_approx
=
values_eq_approx
out_var
.
tag
.
values_eq_approx
=
EQ_MAP
.
get
(
values_eq_approx
,
values_eq_approx
)
return
Apply
(
self
,
[
x
],
[
out_var
])
def
perform
(
self
,
node
,
inp
,
out
):
...
...
@@ -674,7 +675,8 @@ class GpuFromHost(Op):
# Keep the special comparison if there is one.
values_eq_approx
=
getattr
(
x
.
tag
,
'values_eq_approx'
,
None
)
if
values_eq_approx
:
out_var
.
tag
.
values_eq_approx
=
values_eq_approx
out_var
.
tag
.
values_eq_approx
=
EQ_MAP
.
get
(
values_eq_approx
,
values_eq_approx
)
return
Apply
(
self
,
[
x
],
[
out_var
])
def
get_params
(
self
,
node
):
...
...
theano/gpuarray/type.py
浏览文件 @
572a14a1
...
...
@@ -360,33 +360,8 @@ class GpuArrayType(Type):
def
values_eq_approx
(
a
,
b
,
allow_remove_inf
=
False
,
allow_remove_nan
=
False
,
rtol
=
None
,
atol
=
None
):
if
a
.
shape
!=
b
.
shape
or
a
.
dtype
!=
b
.
dtype
:
return
False
if
str
(
a
.
dtype
)
in
theano
.
tensor
.
discrete_dtypes
:
return
GpuArrayType
.
values_eq
(
a
,
b
)
else
:
if
allow_remove_inf
or
allow_remove_nan
:
raise
NotImplementedError
(
"GpuArrayType.values_eq_approx() don't implemented the"
" allow_remove_inf and allow_remove_nan parameter"
)
atol_
,
rtol_
=
theano
.
tensor
.
basic
.
_get_atol_rtol
(
a
,
b
)
if
rtol
is
not
None
:
rtol_
=
rtol
if
atol
is
not
None
:
atol_
=
atol
res
=
elemwise2
(
a
,
''
,
b
,
a
,
odtype
=
np
.
dtype
(
'bool'
),
op_tmpl
=
"res = (fabs(a - b) <"
"(
%(atol_)
s +
%(rtol_)
s * fabs(b)))"
%
locals
())
ret
=
np
.
asarray
(
res
)
.
all
()
if
ret
:
return
True
# maybe the trouble is that there are NaNs
an
=
np
.
asarray
(
a
)
bn
=
np
.
asarray
(
b
)
return
tensor
.
TensorType
.
values_eq_approx
(
an
,
bn
,
allow_remove_inf
=
allow_remove_inf
,
allow_remove_nan
=
allow_remove_nan
,
rtol
=
rtol
,
atol
=
atol
)
return
values_eq_approx
(
a
,
b
,
allow_remove_inf
,
allow_remove_nan
,
rtol
,
atol
)
@staticmethod
def
may_share_memory
(
a
,
b
):
...
...
@@ -542,6 +517,65 @@ class GpuArrayType(Type):
return
(
2
,
ver
[
0
])
def
values_eq_approx
(
a
,
b
,
allow_remove_inf
=
False
,
allow_remove_nan
=
False
,
rtol
=
None
,
atol
=
None
):
if
a
.
shape
!=
b
.
shape
or
a
.
dtype
!=
b
.
dtype
:
return
False
if
str
(
a
.
dtype
)
in
theano
.
tensor
.
discrete_dtypes
:
return
GpuArrayType
.
values_eq
(
a
,
b
)
else
:
if
allow_remove_inf
or
allow_remove_nan
:
raise
NotImplementedError
(
"GpuArrayType.values_eq_approx() don't implemented the"
" allow_remove_inf and allow_remove_nan parameter"
)
atol_
,
rtol_
=
theano
.
tensor
.
basic
.
_get_atol_rtol
(
a
,
b
)
if
rtol
is
not
None
:
rtol_
=
rtol
if
atol
is
not
None
:
atol_
=
atol
res
=
elemwise2
(
a
,
''
,
b
,
a
,
odtype
=
np
.
dtype
(
'bool'
),
op_tmpl
=
"res = (fabs(a - b) <"
"(
%(atol_)
s +
%(rtol_)
s * fabs(b)))"
%
locals
())
ret
=
np
.
asarray
(
res
)
.
all
()
if
ret
:
return
True
# maybe the trouble is that there are NaNs
an
=
np
.
asarray
(
a
)
bn
=
np
.
asarray
(
b
)
return
tensor
.
TensorType
.
values_eq_approx
(
an
,
bn
,
allow_remove_inf
=
allow_remove_inf
,
allow_remove_nan
=
allow_remove_nan
,
rtol
=
rtol
,
atol
=
atol
)
def
values_eq_approx_remove_inf
(
a
,
b
):
return
values_eq_approx
(
a
,
b
,
True
)
def
values_eq_approx_remove_nan
(
a
,
b
):
return
values_eq_approx
(
a
,
b
,
False
,
True
)
def
values_eq_approx_remove_inf_nan
(
a
,
b
):
return
values_eq_approx
(
a
,
b
,
True
,
True
)
# This is to map ndarray-specific versions of these functions to the GPU.
EQ_MAP
=
{
theano
.
tensor
.
type
.
values_eq_approx
:
values_eq_approx
,
theano
.
tensor
.
type
.
values_eq_approx_remove_inf
:
values_eq_approx_remove_inf
,
theano
.
tensor
.
type
.
values_eq_approx_remove_nan
:
values_eq_approx_remove_nan
,
theano
.
tensor
.
type
.
values_eq_approx_remove_inf_nan
:
values_eq_approx_remove_inf_nan
,
}
# Add a reverse map too.
EQ_MAP
.
update
((
v
,
k
for
k
,
v
in
EQ_MAP
.
items
()))
class
_operators
(
_tensor_py_operators
):
def
_as_TensorVariable
(
self
):
from
.basic_ops
import
host_from_gpu
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论