Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
de366285
提交
de366285
authored
1月 26, 2017
作者:
Benjamin Scellier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
file theano/gpuarray/type.py
上级
8d809317
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
21 行增加
和
21 行删除
+21
-21
type.py
theano/gpuarray/type.py
+21
-21
没有找到文件。
theano/gpuarray/type.py
浏览文件 @
de366285
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
six.moves.copyreg
as
copyreg
import
six.moves.copyreg
as
copyreg
from
six
import
iteritems
from
six
import
iteritems
import
warnings
import
warnings
...
@@ -226,7 +226,7 @@ class GpuArrayType(Type):
...
@@ -226,7 +226,7 @@ class GpuArrayType(Type):
converted_data
=
theano
.
_asarray
(
data
,
self
.
dtype
)
converted_data
=
theano
.
_asarray
(
data
,
self
.
dtype
)
# We use the `values_eq` static function from TensorType
# We use the `values_eq` static function from TensorType
# to handle NaN values.
# to handle NaN values.
if
TensorType
.
values_eq
(
n
umpy
.
asarray
(
data
),
if
TensorType
.
values_eq
(
n
p
.
asarray
(
data
),
converted_data
,
converted_data
,
force_same_dtype
=
False
):
force_same_dtype
=
False
):
data
=
converted_data
data
=
converted_data
...
@@ -293,18 +293,18 @@ class GpuArrayType(Type):
...
@@ -293,18 +293,18 @@ class GpuArrayType(Type):
return
False
return
False
if
force_same_dtype
and
a
.
typecode
!=
b
.
typecode
:
if
force_same_dtype
and
a
.
typecode
!=
b
.
typecode
:
return
False
return
False
a_eq_b
=
n
umpy
.
asarray
(
compare
(
a
,
'=='
,
b
))
a_eq_b
=
n
p
.
asarray
(
compare
(
a
,
'=='
,
b
))
if
a_eq_b
.
all
():
if
a_eq_b
.
all
():
return
True
return
True
# maybe the trouble is that there are NaNs
# maybe the trouble is that there are NaNs
a
=
n
umpy
.
asarray
(
a
)
a
=
n
p
.
asarray
(
a
)
b
=
n
umpy
.
asarray
(
b
)
b
=
n
p
.
asarray
(
b
)
a_missing
=
n
umpy
.
isnan
(
a
)
a_missing
=
n
p
.
isnan
(
a
)
if
a_missing
.
any
():
if
a_missing
.
any
():
b_missing
=
n
umpy
.
isnan
(
b
)
b_missing
=
n
p
.
isnan
(
b
)
return
n
umpy
.
all
(
a_eq_b
+
(
a_missing
==
b_missing
))
return
n
p
.
all
(
a_eq_b
+
(
a_missing
==
b_missing
))
else
:
else
:
return
False
return
False
...
@@ -326,16 +326,16 @@ class GpuArrayType(Type):
...
@@ -326,16 +326,16 @@ class GpuArrayType(Type):
rtol_
=
rtol
rtol_
=
rtol
if
atol
is
not
None
:
if
atol
is
not
None
:
atol_
=
atol
atol_
=
atol
res
=
elemwise2
(
a
,
''
,
b
,
a
,
odtype
=
n
umpy
.
dtype
(
'bool'
),
res
=
elemwise2
(
a
,
''
,
b
,
a
,
odtype
=
n
p
.
dtype
(
'bool'
),
op_tmpl
=
"res = (fabs(a - b) <"
op_tmpl
=
"res = (fabs(a - b) <"
"(
%(atol_)
s +
%(rtol_)
s * fabs(b)))"
%
"(
%(atol_)
s +
%(rtol_)
s * fabs(b)))"
%
locals
())
locals
())
ret
=
n
umpy
.
asarray
(
res
)
.
all
()
ret
=
n
p
.
asarray
(
res
)
.
all
()
if
ret
:
if
ret
:
return
True
return
True
# maybe the trouble is that there are NaNs
# maybe the trouble is that there are NaNs
an
=
n
umpy
.
asarray
(
a
)
an
=
n
p
.
asarray
(
a
)
bn
=
n
umpy
.
asarray
(
b
)
bn
=
n
p
.
asarray
(
b
)
return
tensor
.
TensorType
.
values_eq_approx
(
return
tensor
.
TensorType
.
values_eq_approx
(
an
,
bn
,
allow_remove_inf
=
allow_remove_inf
,
an
,
bn
,
allow_remove_inf
=
allow_remove_inf
,
allow_remove_nan
=
allow_remove_nan
,
rtol
=
rtol
,
atol
=
atol
)
allow_remove_nan
=
allow_remove_nan
,
rtol
=
rtol
,
atol
=
atol
)
...
@@ -408,9 +408,9 @@ class GpuArrayType(Type):
...
@@ -408,9 +408,9 @@ class GpuArrayType(Type):
def
get_size
(
self
,
shape_info
):
def
get_size
(
self
,
shape_info
):
if
shape_info
:
if
shape_info
:
return
n
umpy
.
prod
(
shape_info
)
*
numpy
.
dtype
(
self
.
dtype
)
.
itemsize
return
n
p
.
prod
(
shape_info
)
*
np
.
dtype
(
self
.
dtype
)
.
itemsize
else
:
else
:
return
n
umpy
.
dtype
(
self
.
dtype
)
.
itemsize
return
n
p
.
dtype
(
self
.
dtype
)
.
itemsize
def
c_declare
(
self
,
name
,
sub
,
check_input
=
True
):
def
c_declare
(
self
,
name
,
sub
,
check_input
=
True
):
return
"""
return
"""
...
@@ -470,7 +470,7 @@ class GpuArrayType(Type):
...
@@ -470,7 +470,7 @@ class GpuArrayType(Type):
'<gpuarray_api.h>'
]
'<gpuarray_api.h>'
]
def
c_header_dirs
(
self
):
def
c_header_dirs
(
self
):
return
[
pygpu
.
get_include
(),
n
umpy
.
get_include
()]
return
[
pygpu
.
get_include
(),
n
p
.
get_include
()]
def
c_libraries
(
self
):
def
c_libraries
(
self
):
return
[
'gpuarray'
]
return
[
'gpuarray'
]
...
@@ -509,7 +509,7 @@ class GpuArrayVariable(_operators, Variable):
...
@@ -509,7 +509,7 @@ class GpuArrayVariable(_operators, Variable):
# override the default
# override the default
def
__repr_test_value__
(
self
):
def
__repr_test_value__
(
self
):
return
repr
(
n
umpy
.
array
(
theano
.
gof
.
op
.
get_test_value
(
self
)))
return
repr
(
n
p
.
array
(
theano
.
gof
.
op
.
get_test_value
(
self
)))
GpuArrayType
.
Variable
=
GpuArrayVariable
GpuArrayType
.
Variable
=
GpuArrayVariable
...
@@ -534,13 +534,13 @@ class GpuArrayConstant(_operators, Constant):
...
@@ -534,13 +534,13 @@ class GpuArrayConstant(_operators, Constant):
"""
"""
def
signature
(
self
):
def
signature
(
self
):
return
GpuArraySignature
((
self
.
type
,
n
umpy
.
asarray
(
self
.
data
)))
return
GpuArraySignature
((
self
.
type
,
n
p
.
asarray
(
self
.
data
)))
def
__str__
(
self
):
def
__str__
(
self
):
if
self
.
name
is
not
None
:
if
self
.
name
is
not
None
:
return
self
.
name
return
self
.
name
try
:
try
:
np_data
=
n
umpy
.
asarray
(
self
.
data
)
np_data
=
n
p
.
asarray
(
self
.
data
)
except
gpuarray
.
GpuArrayException
:
except
gpuarray
.
GpuArrayException
:
np_data
=
self
.
data
np_data
=
self
.
data
return
"GpuArrayConstant{
%
s}"
%
np_data
return
"GpuArrayConstant{
%
s}"
%
np_data
...
@@ -568,7 +568,7 @@ class GpuArraySharedVariable(_operators, SharedVariable):
...
@@ -568,7 +568,7 @@ class GpuArraySharedVariable(_operators, SharedVariable):
else
:
else
:
return
self
.
container
.
value
.
copy
()
return
self
.
container
.
value
.
copy
()
else
:
else
:
return
n
umpy
.
asarray
(
self
.
container
.
value
)
return
n
p
.
asarray
(
self
.
container
.
value
)
def
set_value
(
self
,
value
,
borrow
=
False
):
def
set_value
(
self
,
value
,
borrow
=
False
):
if
isinstance
(
value
,
pygpu
.
gpuarray
.
GpuArray
):
if
isinstance
(
value
,
pygpu
.
gpuarray
.
GpuArray
):
...
@@ -601,7 +601,7 @@ def gpuarray_shared_constructor(value, name=None, strict=False,
...
@@ -601,7 +601,7 @@ def gpuarray_shared_constructor(value, name=None, strict=False,
if
target
==
'gpu'
or
target
==
'cpu'
:
if
target
==
'gpu'
or
target
==
'cpu'
:
raise
TypeError
(
'not for me'
)
raise
TypeError
(
'not for me'
)
if
not
isinstance
(
value
,
(
n
umpy
.
ndarray
,
pygpu
.
gpuarray
.
GpuArray
)):
if
not
isinstance
(
value
,
(
n
p
.
ndarray
,
pygpu
.
gpuarray
.
GpuArray
)):
raise
TypeError
(
'ndarray or GpuArray required'
)
raise
TypeError
(
'ndarray or GpuArray required'
)
if
target
is
notset
:
if
target
is
notset
:
...
@@ -809,7 +809,7 @@ copyreg.constructor(GpuArray_unpickler)
...
@@ -809,7 +809,7 @@ copyreg.constructor(GpuArray_unpickler)
def
GpuArray_pickler
(
cnda
):
def
GpuArray_pickler
(
cnda
):
ctx_name
=
_name_for_ctx
(
cnda
.
context
)
ctx_name
=
_name_for_ctx
(
cnda
.
context
)
return
(
GpuArray_unpickler
,
(
n
umpy
.
asarray
(
cnda
),
ctx_name
))
return
(
GpuArray_unpickler
,
(
n
p
.
asarray
(
cnda
),
ctx_name
))
# In case pygpu is not imported.
# In case pygpu is not imported.
if
pygpu
is
not
None
:
if
pygpu
is
not
None
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论