Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cb371ba7
提交
cb371ba7
authored
5月 02, 2013
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1348 from nouiz/fixes
Small fixes
上级
ec3a90d4
a0344d4b
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
47 行增加
和
18 行删除
+47
-18
test_linalg.py
theano/sandbox/linalg/tests/test_linalg.py
+2
-0
basic.py
theano/tensor/basic.py
+10
-1
test_basic.py
theano/tensor/tests/test_basic.py
+35
-17
没有找到文件。
theano/sandbox/linalg/tests/test_linalg.py
浏览文件 @
cb371ba7
...
@@ -536,6 +536,8 @@ class test_Eigh_float32(test_Eigh):
...
@@ -536,6 +536,8 @@ class test_Eigh_float32(test_Eigh):
dtype
=
'float32'
dtype
=
'float32'
def
test_matrix_inverse_solve
():
def
test_matrix_inverse_solve
():
if
not
imported_scipy
:
raise
SkipTest
(
"Scipy needed for the Solve op."
)
A
=
theano
.
tensor
.
dmatrix
(
'A'
)
A
=
theano
.
tensor
.
dmatrix
(
'A'
)
b
=
theano
.
tensor
.
dmatrix
(
'b'
)
b
=
theano
.
tensor
.
dmatrix
(
'b'
)
node
=
matrix_inverse
(
A
)
.
dot
(
b
)
.
owner
node
=
matrix_inverse
(
A
)
.
dot
(
b
)
.
owner
...
...
theano/tensor/basic.py
浏览文件 @
cb371ba7
...
@@ -366,9 +366,14 @@ def constant_or_value(x, rtype, name=None, ndim=None, dtype=None):
...
@@ -366,9 +366,14 @@ def constant_or_value(x, rtype, name=None, ndim=None, dtype=None):
# Theano graph, because on Windows 64, all shapes are expressed
# Theano graph, because on Windows 64, all shapes are expressed
# with longs.
# with longs.
# If a long fits in int64, we convert it into an int64, like
# If a long fits in int64, we convert it into an int64, like
# numpy.asarray() does.
# numpy.asarray() does up to 1.7. NumPy 1.7.1 upcaset to int64
# if possible, but fallback to uint64 if int64 isn't possible but
# uint64 is. We always do as NumPy 1.7.1 here.
# If x is too big, an OverflowError will be raised by numpy.
# If x is too big, an OverflowError will be raised by numpy.
try
:
x_
=
theano
.
_asarray
(
x
,
dtype
=
'int64'
)
x_
=
theano
.
_asarray
(
x
,
dtype
=
'int64'
)
except
OverflowError
:
x_
=
theano
.
_asarray
(
x
,
dtype
=
'uint64'
)
elif
isinstance
(
x
,
numpy
.
ndarray
):
elif
isinstance
(
x
,
numpy
.
ndarray
):
x_
=
x
x_
=
x
# Currently we do not have a bool dtype in Theano.
# Currently we do not have a bool dtype in Theano.
...
@@ -377,6 +382,10 @@ def constant_or_value(x, rtype, name=None, ndim=None, dtype=None):
...
@@ -377,6 +382,10 @@ def constant_or_value(x, rtype, name=None, ndim=None, dtype=None):
if
x
.
dtype
==
'bool'
:
if
x
.
dtype
==
'bool'
:
x_
=
numpy
.
asarray
(
x_
,
dtype
=
'uint8'
)
x_
=
numpy
.
asarray
(
x_
,
dtype
=
'uint8'
)
else
:
else
:
# Here x is probably a list or a tuple. If it contain a long,
# we will behave like the current NumPy version: 1.7 and bellow,
# it will only work if the long fit in int64. For NumPy 1.7.1+,
# it will work if the long git in int64 or uint64.
x_
=
numpy
.
asarray
(
x
)
x_
=
numpy
.
asarray
(
x
)
assert
type
(
x_
)
==
numpy
.
ndarray
assert
type
(
x_
)
==
numpy
.
ndarray
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
cb371ba7
...
@@ -2016,7 +2016,6 @@ def test_identity():
...
@@ -2016,7 +2016,6 @@ def test_identity():
class
CastTester
(
unittest
.
TestCase
):
class
CastTester
(
unittest
.
TestCase
):
def
test_good_between_real_types
(
self
):
def
test_good_between_real_types
(
self
):
expected
=
lambda
x
,
y
:
x
.
astype
(
y
),
good
=
itertools
.
chain
(
good
=
itertools
.
chain
(
multi_dtype_cast_checks
((
2
,),
dtypes
=
REAL_DTYPES
),
multi_dtype_cast_checks
((
2
,),
dtypes
=
REAL_DTYPES
),
# Casts from foo to foo
# Casts from foo to foo
...
@@ -2029,6 +2028,10 @@ class CastTester(unittest.TestCase):
...
@@ -2029,6 +2028,10 @@ class CastTester(unittest.TestCase):
f
=
function
([
inp
],
out
)
f
=
function
([
inp
],
out
)
assert
f
(
obj
)
.
dtype
==
numpy
.
dtype
(
dtype
)
assert
f
(
obj
)
.
dtype
==
numpy
.
dtype
(
dtype
)
# Test astype too
out2
=
inp
.
astype
(
dtype
=
dtype
)
assert
out2
.
type
==
out
.
type
def
test_cast_from_real_to_complex
(
self
):
def
test_cast_from_real_to_complex
(
self
):
for
real_dtype
in
REAL_DTYPES
:
for
real_dtype
in
REAL_DTYPES
:
for
complex_dtype
in
COMPLEX_DTYPES
:
for
complex_dtype
in
COMPLEX_DTYPES
:
...
@@ -2313,7 +2316,6 @@ class T_max_and_argmax(unittest.TestCase):
...
@@ -2313,7 +2316,6 @@ class T_max_and_argmax(unittest.TestCase):
x
=
matrix
()
x
=
matrix
()
cost
=
argmax
(
x
,
axis
=
0
)
.
sum
()
cost
=
argmax
(
x
,
axis
=
0
)
.
sum
()
value_error_raised
=
False
gx
=
grad
(
cost
,
x
)
gx
=
grad
(
cost
,
x
)
val
=
tensor
.
get_scalar_constant_value
(
gx
)
val
=
tensor
.
get_scalar_constant_value
(
gx
)
assert
val
==
0.0
assert
val
==
0.0
...
@@ -2916,11 +2918,8 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -2916,11 +2918,8 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
oldlevel
=
_logger
.
level
oldlevel
=
_logger
.
level
_logger
.
setLevel
(
logging
.
CRITICAL
)
_logger
.
setLevel
(
logging
.
CRITICAL
)
try
:
try
:
try
:
self
.
assertRaises
(
IndexError
,
tval
=
self
.
eval_output_and_check
([
t
])
self
.
eval_output_and_check
,
[
t
])
assert
0
except
IndexError
,
e
:
pass
finally
:
finally
:
_logger
.
setLevel
(
oldlevel
)
_logger
.
setLevel
(
oldlevel
)
finally
:
finally
:
...
@@ -2928,16 +2927,13 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -2928,16 +2927,13 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
def
test2_err_bounds1
(
self
):
def
test2_err_bounds1
(
self
):
n
=
self
.
shared
((
numpy
.
ones
((
2
,
3
),
dtype
=
self
.
dtype
)
*
5
))
n
=
self
.
shared
((
numpy
.
ones
((
2
,
3
),
dtype
=
self
.
dtype
)
*
5
))
t
=
n
[
4
:
5
,
2
]
t
=
n
[
4
:
5
,
3
]
self
.
assertTrue
(
isinstance
(
t
.
owner
.
op
,
Subtensor
))
self
.
assertTrue
(
isinstance
(
t
.
owner
.
op
,
Subtensor
))
old_stderr
=
sys
.
stderr
old_stderr
=
sys
.
stderr
sys
.
stderr
=
StringIO
.
StringIO
()
sys
.
stderr
=
StringIO
.
StringIO
()
try
:
try
:
try
:
self
.
assertRaises
(
IndexError
,
tval
=
self
.
eval_output_and_check
([
t
])
self
.
eval_output_and_check
,
[
t
])
except
Exception
,
e
:
if
e
[
0
]
!=
'index out of bounds'
:
raise
finally
:
finally
:
sys
.
stderr
=
old_stderr
sys
.
stderr
=
old_stderr
...
@@ -4313,7 +4309,7 @@ class T_Join_and_Split(unittest.TestCase):
...
@@ -4313,7 +4309,7 @@ class T_Join_and_Split(unittest.TestCase):
assert
(
out
==
[
3
,
13
])
.
all
()
assert
(
out
==
[
3
,
13
])
.
all
()
if
theano
.
config
.
mode
!=
'FAST_COMPILE'
:
if
theano
.
config
.
mode
!=
'FAST_COMPILE'
:
for
node
in
f
.
maker
.
fgraph
.
toposort
()
:
for
node
in
topo
:
assert
not
isinstance
(
node
.
op
,
tensor
.
Join
)
assert
not
isinstance
(
node
.
op
,
tensor
.
Join
)
# Test hide error
# Test hide error
...
@@ -5161,7 +5157,6 @@ class T_reshape(unittest.TestCase):
...
@@ -5161,7 +5157,6 @@ class T_reshape(unittest.TestCase):
def
test_bad_shape
(
self
):
def
test_bad_shape
(
self
):
a
=
matrix
(
'a'
)
a
=
matrix
(
'a'
)
shapes
=
ivector
(
'shapes'
)
shapes
=
ivector
(
'shapes'
)
ndim
=
2
rng
=
numpy
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
a_val
=
rng
.
uniform
(
size
=
(
3
,
4
))
.
astype
(
config
.
floatX
)
a_val
=
rng
.
uniform
(
size
=
(
3
,
4
))
.
astype
(
config
.
floatX
)
...
@@ -5172,7 +5167,7 @@ class T_reshape(unittest.TestCase):
...
@@ -5172,7 +5167,7 @@ class T_reshape(unittest.TestCase):
f
=
function
([
a
,
shapes
],
z
.
shape
)
f
=
function
([
a
,
shapes
],
z
.
shape
)
self
.
assertRaises
(
ValueError
,
f
,
a_val
,
[
13
])
self
.
assertRaises
(
ValueError
,
f
,
a_val
,
[
13
])
#Test reshape to
1
dim
#Test reshape to
2
dim
r
=
a
.
reshape
(
shapes
,
ndim
=
2
)
r
=
a
.
reshape
(
shapes
,
ndim
=
2
)
z
=
zeros_like
(
r
)
z
=
zeros_like
(
r
)
...
@@ -6392,6 +6387,30 @@ class T_long_tensor(unittest.TestCase):
...
@@ -6392,6 +6387,30 @@ class T_long_tensor(unittest.TestCase):
def
test_too_big
(
self
):
def
test_too_big
(
self
):
val
=
2L
**
63
val
=
2L
**
63
#NumPy 1.7 this will raise an exception
#NumPy 1.7.1 this will work
try
:
cst
=
constant
(
val
)
assert
cst
.
value
==
val
assert
cst
.
dtype
==
"uint64"
except
OverflowError
:
pass
try
:
cst
=
constant
([
val
,
val
])
assert
cst
.
value
==
val
assert
cst
.
dtype
==
"uint64"
except
TypeError
:
pass
try
:
cst
=
constant
([[
val
,
val
]])
assert
cst
.
value
==
val
assert
cst
.
dtype
==
"uint64"
except
TypeError
:
pass
val
=
2L
**
64
# This fail for all NumPy version.
self
.
assertRaises
(
Exception
,
constant
,
val
)
self
.
assertRaises
(
Exception
,
constant
,
val
)
self
.
assertRaises
(
Exception
,
constant
,
[
val
,
val
])
self
.
assertRaises
(
Exception
,
constant
,
[
val
,
val
])
self
.
assertRaises
(
Exception
,
constant
,
[[
val
,
val
]])
self
.
assertRaises
(
Exception
,
constant
,
[[
val
,
val
]])
...
@@ -7055,7 +7074,6 @@ class TestInferShape(utt.InferShapeTester):
...
@@ -7055,7 +7074,6 @@ class TestInferShape(utt.InferShapeTester):
# ScalarFromTensor
# ScalarFromTensor
aiscal
=
iscalar
()
aiscal
=
iscalar
()
aconst
=
constant
(
45
)
self
.
_compile_and_check
([
aiscal
],
self
.
_compile_and_check
([
aiscal
],
[
TensorFromScalar
()(
ScalarFromTensor
()(
aiscal
))],
[
TensorFromScalar
()(
ScalarFromTensor
()(
aiscal
))],
[
45
],
ScalarFromTensor
,
[
45
],
ScalarFromTensor
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论