Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2b6f019a
提交
2b6f019a
authored
11月 04, 2011
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: strict filtering broken after deepcopy
上级
840176c8
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
34 行增加
和
9 行删除
+34
-9
safe_asarray.py
theano/misc/safe_asarray.py
+8
-0
basic.py
theano/tensor/basic.py
+15
-9
test_misc.py
theano/tensor/tests/test_misc.py
+11
-0
没有找到文件。
theano/misc/safe_asarray.py
浏览文件 @
2b6f019a
...
@@ -8,6 +8,14 @@ import numpy
...
@@ -8,6 +8,14 @@ import numpy
import
theano
import
theano
def
dtype_eq
(
a
,
b
):
"""Returns true iff numpy.dtype objects `a` and `b` match for the purposes
of theano code generators.
"""
return
a
==
b
and
a
.
num
==
b
.
num
def
_asarray
(
a
,
dtype
,
order
=
None
):
def
_asarray
(
a
,
dtype
,
order
=
None
):
"""Convert the input to a Numpy array.
"""Convert the input to a Numpy array.
...
...
theano/tensor/basic.py
浏览文件 @
2b6f019a
...
@@ -15,8 +15,6 @@ import numpy, theano
...
@@ -15,8 +15,6 @@ import numpy, theano
from
theano
import
gof
from
theano
import
gof
from
theano.gof
import
Apply
,
Constant
,
Op
,
Type
,
Value
,
Variable
from
theano.gof
import
Apply
,
Constant
,
Op
,
Type
,
Value
,
Variable
import
elemwise
import
elemwise
from
theano
import
scalar
as
scal
from
theano
import
scalar
as
scal
from
theano.gof.python25
import
partial
,
any
,
all
from
theano.gof.python25
import
partial
,
any
,
all
...
@@ -544,21 +542,29 @@ class TensorType(Type):
...
@@ -544,21 +542,29 @@ class TensorType(Type):
'Expected an array-like object, but found a Variable: '
'Expected an array-like object, but found a Variable: '
'maybe you are trying to call a function on a (possibly '
'maybe you are trying to call a function on a (possibly '
'shared) variable instead of a numeric array?'
)
'shared) variable instead of a numeric array?'
)
if
(
type
(
data
)
is
numpy
.
ndarray
)
and
(
data
.
dtype
is
self
.
numpy_dtype
):
dtype_eq
=
theano
.
misc
.
safe_asarray
.
dtype_eq
if
((
type
(
data
)
is
numpy
.
ndarray
)
and
dtype_eq
(
data
.
dtype
,
self
.
numpy_dtype
)):
pass
# fall through to ndim check
pass
# fall through to ndim check
elif
strict
:
elif
strict
:
# If any of the two conditions above was not met,
# If any of the two conditions above was not met,
# we raise a meaningful TypeError.
# we raise a meaningful TypeError.
if
not
(
type
(
data
)
is
numpy
.
ndarray
):
if
not
(
type
(
data
)
is
numpy
.
ndarray
):
raise
TypeError
(
"
%
s expected a ndarray object."
%
self
,
data
,
type
(
data
))
raise
TypeError
(
"
%
s expected a ndarray object."
%
self
,
if
not
(
data
.
dtype
is
self
.
numpy_dtype
):
data
,
type
(
data
))
raise
TypeError
(
"
%
s expected a ndarray object with dtype =
%
s (got
%
s)."
%
(
self
,
self
.
numpy_dtype
,
data
.
dtype
))
if
not
dtype_eq
(
data
.
dtype
,
self
.
numpy_dtype
):
assert
False
,
"This point in the program should never be reached."
raise
TypeError
((
"
%
s expected a ndarray object with "
"dtype =
%
s (got
%
s)."
)
%
(
self
,
self
.
numpy_dtype
,
data
.
dtype
))
assert
False
,
"This point should never be reached."
else
:
else
:
if
allow_downcast
:
if
allow_downcast
:
# Convert to self.dtype, regardless of the type of data
# Convert to self.dtype, regardless of the type of data
data
=
theano
.
_asarray
(
data
,
dtype
=
self
.
dtype
)
#TODO - consider to pad shape with ones
data
=
theano
.
_asarray
(
data
,
dtype
=
self
.
dtype
)
# to make it consistent with self.broadcastable... like vector->row type thing
# TODO: consider to pad shape with ones to make it consistent
# with self.broadcastable... like vector->row type thing
else
:
else
:
if
isinstance
(
data
,
numpy
.
ndarray
):
if
isinstance
(
data
,
numpy
.
ndarray
):
# Check if self.dtype can accurately represent data
# Check if self.dtype can accurately represent data
...
...
theano/tensor/tests/test_misc.py
浏览文件 @
2b6f019a
...
@@ -71,3 +71,14 @@ def test_bug_2009_07_17_borrowed_output():
...
@@ -71,3 +71,14 @@ def test_bug_2009_07_17_borrowed_output():
assert
id_z
!=
id_other
assert
id_z
!=
id_other
# Just to be 100% sure, ensure that z was not altered.
# Just to be 100% sure, ensure that z was not altered.
assert
(
z
==
z_backup
)
.
all
()
assert
(
z
==
z_backup
)
.
all
()
def
test_deepcopied_type_filter
():
a
=
copy
.
deepcopy
(
tensor
.
matrix
())
# The following should run cleanly.
# As of commit 731e2d2fa68487733320d341d08b454a50c90d12
# it was failing.
a
.
type
.
filter
(
numpy
.
ones
((
2
,
2
),
dtype
=
a
.
dtype
),
strict
=
True
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论