Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
31661605
提交
31661605
authored
7月 04, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix and make test run in floatX.
上级
e751d4f3
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
31 行增加
和
31 行删除
+31
-31
test_extra_ops.py
theano/tensor/tests/test_extra_ops.py
+31
-31
没有找到文件。
theano/tensor/tests/test_extra_ops.py
浏览文件 @
31661605
...
@@ -5,7 +5,7 @@ import theano
...
@@ -5,7 +5,7 @@ import theano
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
from
theano.tensor.extra_ops
import
*
from
theano.tensor.extra_ops
import
*
from
theano
import
tensor
as
T
from
theano
import
tensor
as
T
from
theano
import
tensor
,
function
,
scalar
from
theano
import
config
,
tensor
,
function
,
scalar
class
TestBinCountOp
(
utt
.
InferShapeTester
):
class
TestBinCountOp
(
utt
.
InferShapeTester
):
...
@@ -16,9 +16,9 @@ class TestBinCountOp(utt.InferShapeTester):
...
@@ -16,9 +16,9 @@ class TestBinCountOp(utt.InferShapeTester):
def
test_bincountOp
(
self
):
def
test_bincountOp
(
self
):
x
=
T
.
lvector
(
'x'
)
x
=
T
.
lvector
(
'x'
)
w
=
T
.
d
vector
(
'w'
)
w
=
T
.
vector
(
'w'
)
a
=
np
.
random
.
random_integers
(
50
,
size
=
(
25
))
a
=
np
.
random
.
random_integers
(
50
,
size
=
(
25
))
weights
=
np
.
random
.
random
((
25
,))
weights
=
np
.
random
.
random
((
25
,))
.
astype
(
config
.
floatX
)
f1
=
theano
.
function
([
x
],
bincount
(
x
))
f1
=
theano
.
function
([
x
],
bincount
(
x
))
f2
=
theano
.
function
([
x
,
w
],
bincount
(
x
,
weights
=
w
))
f2
=
theano
.
function
([
x
,
w
],
bincount
(
x
,
weights
=
w
))
...
@@ -38,7 +38,7 @@ class TestBinCountOp(utt.InferShapeTester):
...
@@ -38,7 +38,7 @@ class TestBinCountOp(utt.InferShapeTester):
[
np
.
random
.
random_integers
(
50
,
size
=
(
25
,))],
[
np
.
random
.
random_integers
(
50
,
size
=
(
25
,))],
self
.
op_class
)
self
.
op_class
)
weights
=
np
.
random
.
random
((
25
,))
weights
=
np
.
random
.
random
((
25
,))
.
astype
(
config
.
floatX
)
self
.
_compile_and_check
([
x
],
self
.
_compile_and_check
([
x
],
[
bincount
(
x
,
weights
=
weights
)],
[
bincount
(
x
,
weights
=
weights
)],
[
np
.
random
.
random_integers
(
50
,
size
=
(
25
,))],
[
np
.
random
.
random_integers
(
50
,
size
=
(
25
,))],
...
@@ -64,8 +64,8 @@ class TestDiffOp(utt.InferShapeTester):
...
@@ -64,8 +64,8 @@ class TestDiffOp(utt.InferShapeTester):
self
.
op
=
DiffOp
()
self
.
op
=
DiffOp
()
def
test_diffOp
(
self
):
def
test_diffOp
(
self
):
x
=
T
.
d
matrix
(
'x'
)
x
=
T
.
matrix
(
'x'
)
a
=
np
.
random
.
random
((
30
,
50
))
a
=
np
.
random
.
random
((
30
,
50
))
.
astype
(
config
.
floatX
)
f
=
theano
.
function
([
x
],
diff
(
x
))
f
=
theano
.
function
([
x
],
diff
(
x
))
assert
np
.
allclose
(
np
.
diff
(
a
),
f
(
a
))
assert
np
.
allclose
(
np
.
diff
(
a
),
f
(
a
))
...
@@ -76,8 +76,8 @@ class TestDiffOp(utt.InferShapeTester):
...
@@ -76,8 +76,8 @@ class TestDiffOp(utt.InferShapeTester):
assert
np
.
allclose
(
np
.
diff
(
a
,
n
=
k
,
axis
=
axis
),
g
(
a
))
assert
np
.
allclose
(
np
.
diff
(
a
,
n
=
k
,
axis
=
axis
),
g
(
a
))
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
x
=
T
.
d
matrix
(
'x'
)
x
=
T
.
matrix
(
'x'
)
a
=
np
.
random
.
random
((
30
,
50
))
a
=
np
.
random
.
random
((
30
,
50
))
.
astype
(
config
.
floatX
)
self
.
_compile_and_check
([
x
],
self
.
_compile_and_check
([
x
],
[
self
.
op
(
x
)],
[
self
.
op
(
x
)],
...
@@ -93,14 +93,14 @@ class TestDiffOp(utt.InferShapeTester):
...
@@ -93,14 +93,14 @@ class TestDiffOp(utt.InferShapeTester):
def
test_grad
(
self
):
def
test_grad
(
self
):
x
=
T
.
vector
(
'x'
)
x
=
T
.
vector
(
'x'
)
a
=
np
.
random
.
random
(
50
)
a
=
np
.
random
.
random
(
50
)
.
astype
(
config
.
floatX
)
gf
=
theano
.
function
([
x
],
T
.
grad
(
T
.
sum
(
diff
(
x
)),
x
))
gf
=
theano
.
function
([
x
],
T
.
grad
(
T
.
sum
(
diff
(
x
)),
x
))
utt
.
verify_grad
(
self
.
op
,
[
a
])
utt
.
verify_grad
(
self
.
op
,
[
a
])
for
k
in
range
(
TestDiffOp
.
nb
):
for
k
in
range
(
TestDiffOp
.
nb
):
dg
=
theano
.
function
([
x
],
T
.
grad
(
T
.
sum
(
diff
(
x
,
n
=
k
)),
x
))
dg
=
theano
.
function
([
x
],
T
.
grad
(
T
.
sum
(
diff
(
x
,
n
=
k
)),
x
))
utt
.
verify_grad
(
DiffOp
(
n
=
k
),
[
a
])
utt
.
verify_grad
(
DiffOp
(
n
=
k
),
[
a
]
,
eps
=
7e-3
)
class
TestSqueezeOp
(
utt
.
InferShapeTester
):
class
TestSqueezeOp
(
utt
.
InferShapeTester
):
...
@@ -110,27 +110,27 @@ class TestSqueezeOp(utt.InferShapeTester):
...
@@ -110,27 +110,27 @@ class TestSqueezeOp(utt.InferShapeTester):
self
.
op
=
SqueezeOp
(
out_nd
=
1
)
self
.
op
=
SqueezeOp
(
out_nd
=
1
)
def
test_squeezeOp
(
self
):
def
test_squeezeOp
(
self
):
x
=
T
.
d
matrix
(
'x'
)
x
=
T
.
matrix
(
'x'
)
a
=
np
.
random
.
random
((
1
,
50
))
a
=
np
.
random
.
random
((
1
,
50
))
.
astype
(
config
.
floatX
)
f
=
theano
.
function
([
x
],
squeeze
(
x
,
out_nd
=
1
))
f
=
theano
.
function
([
x
],
squeeze
(
x
,
out_nd
=
1
))
assert
np
.
allclose
(
np
.
squeeze
(
a
),
f
(
a
))
assert
np
.
allclose
(
np
.
squeeze
(
a
),
f
(
a
))
x
=
T
.
d
tensor4
(
'x'
)
x
=
T
.
tensor4
(
'x'
)
f
=
theano
.
function
([
x
],
squeeze
(
x
,
out_nd
=
2
))
f
=
theano
.
function
([
x
],
squeeze
(
x
,
out_nd
=
2
))
a
=
np
.
random
.
random
((
1
,
1
,
2
,
3
))
a
=
np
.
random
.
random
((
1
,
1
,
2
,
3
))
.
astype
(
config
.
floatX
)
assert
np
.
allclose
(
np
.
squeeze
(
a
),
f
(
a
))
assert
np
.
allclose
(
np
.
squeeze
(
a
),
f
(
a
))
a
=
np
.
random
.
random
((
1
,
2
,
2
,
1
))
a
=
np
.
random
.
random
((
1
,
2
,
2
,
1
))
.
astype
(
config
.
floatX
)
assert
np
.
allclose
(
np
.
squeeze
(
a
),
f
(
a
))
assert
np
.
allclose
(
np
.
squeeze
(
a
),
f
(
a
))
a
=
np
.
random
.
random
((
4
,
1
,
2
,
1
))
a
=
np
.
random
.
random
((
4
,
1
,
2
,
1
))
.
astype
(
config
.
floatX
)
assert
np
.
allclose
(
np
.
squeeze
(
a
),
f
(
a
))
assert
np
.
allclose
(
np
.
squeeze
(
a
),
f
(
a
))
def
test_grad
(
self
):
def
test_grad
(
self
):
x
=
T
.
d
tensor4
(
'x'
)
x
=
T
.
tensor4
(
'x'
)
a
=
np
.
random
.
random
((
1
,
1
,
3
,
4
))
a
=
np
.
random
.
random
((
1
,
1
,
3
,
4
))
.
astype
(
config
.
floatX
)
gf
=
theano
.
function
([
x
],
T
.
grad
(
T
.
sum
(
squeeze
(
x
,
out_nd
=
1
)),
x
))
gf
=
theano
.
function
([
x
],
T
.
grad
(
T
.
sum
(
squeeze
(
x
,
out_nd
=
1
)),
x
))
utt
.
verify_grad
(
SqueezeOp
(
out_nd
=
2
),
[
a
])
utt
.
verify_grad
(
SqueezeOp
(
out_nd
=
2
),
[
a
])
...
@@ -147,8 +147,8 @@ class TestRepeatOp(utt.InferShapeTester):
...
@@ -147,8 +147,8 @@ class TestRepeatOp(utt.InferShapeTester):
def
test_repeatOp
(
self
):
def
test_repeatOp
(
self
):
for
ndim
in
range
(
3
):
for
ndim
in
range
(
3
):
x
=
T
.
TensorType
(
theano
.
config
.
floatX
,
[
False
]
*
ndim
)()
x
=
T
.
TensorType
(
config
.
floatX
,
[
False
]
*
ndim
)()
a
=
np
.
random
.
random
((
10
,
)
*
ndim
)
a
=
np
.
random
.
random
((
10
,
)
*
ndim
)
.
astype
(
config
.
floatX
)
for
axis
in
self
.
_possible_axis
(
ndim
):
for
axis
in
self
.
_possible_axis
(
ndim
):
r_var
=
T
.
lscalar
()
r_var
=
T
.
lscalar
()
...
@@ -167,8 +167,8 @@ class TestRepeatOp(utt.InferShapeTester):
...
@@ -167,8 +167,8 @@ class TestRepeatOp(utt.InferShapeTester):
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
for
ndim
in
range
(
4
):
for
ndim
in
range
(
4
):
x
=
T
.
TensorType
(
theano
.
config
.
floatX
,
[
False
]
*
ndim
)()
x
=
T
.
TensorType
(
config
.
floatX
,
[
False
]
*
ndim
)()
a
=
np
.
random
.
random
((
10
,
)
*
ndim
)
a
=
np
.
random
.
random
((
10
,
)
*
ndim
)
.
astype
(
config
.
floatX
)
for
axis
in
self
.
_possible_axis
(
ndim
):
for
axis
in
self
.
_possible_axis
(
ndim
):
r_var
=
T
.
lscalar
()
r_var
=
T
.
lscalar
()
...
@@ -191,7 +191,7 @@ class TestRepeatOp(utt.InferShapeTester):
...
@@ -191,7 +191,7 @@ class TestRepeatOp(utt.InferShapeTester):
def
test_grad
(
self
):
def
test_grad
(
self
):
for
ndim
in
range
(
3
):
for
ndim
in
range
(
3
):
a
=
np
.
random
.
random
((
10
,
)
*
ndim
)
a
=
np
.
random
.
random
((
10
,
)
*
ndim
)
.
astype
(
config
.
floatX
)
for
axis
in
self
.
_possible_axis
(
ndim
):
for
axis
in
self
.
_possible_axis
(
ndim
):
utt
.
verify_grad
(
lambda
x
:
RepeatOp
(
axis
=
axis
)(
x
,
3
),
[
a
])
utt
.
verify_grad
(
lambda
x
:
RepeatOp
(
axis
=
axis
)(
x
,
3
),
[
a
])
...
@@ -240,23 +240,23 @@ class TestFillDiagonal(utt.InferShapeTester):
...
@@ -240,23 +240,23 @@ class TestFillDiagonal(utt.InferShapeTester):
self
.
op
=
fill_diagonal
self
.
op
=
fill_diagonal
def
test_perform
(
self
):
def
test_perform
(
self
):
x
=
tensor
.
d
matrix
()
x
=
tensor
.
matrix
()
y
=
tensor
.
d
scalar
()
y
=
tensor
.
scalar
()
f
=
function
([
x
,
y
],
fill_diagonal
(
x
,
y
))
f
=
function
([
x
,
y
],
fill_diagonal
(
x
,
y
))
for
shp
in
[(
8
,
8
),
(
5
,
8
),
(
8
,
5
)]:
for
shp
in
[(
8
,
8
),
(
5
,
8
),
(
8
,
5
)]:
a
=
numpy
.
random
.
rand
(
*
shp
)
a
=
numpy
.
random
.
rand
(
*
shp
)
.
astype
(
config
.
floatX
)
val
=
numpy
.
random
.
rand
(
)
val
=
numpy
.
cast
[
config
.
floatX
](
numpy
.
random
.
rand
()
)
out
=
f
(
a
,
val
)
out
=
f
(
a
,
val
)
# We can't use numpy.fill_diagonal as it is bugged.
# We can't use numpy.fill_diagonal as it is bugged.
assert
numpy
.
allclose
(
numpy
.
diag
(
out
),
val
)
assert
numpy
.
allclose
(
numpy
.
diag
(
out
),
val
)
assert
(
out
==
val
)
.
sum
()
==
min
(
a
.
shape
)
assert
(
out
==
val
)
.
sum
()
==
min
(
a
.
shape
)
# test for 3d tensor
# test for 3d tensor
a
=
numpy
.
random
.
rand
(
3
,
3
,
3
)
a
=
numpy
.
random
.
rand
(
3
,
3
,
3
)
.
astype
(
config
.
floatX
)
x
=
tensor
.
d
tensor3
()
x
=
tensor
.
tensor3
()
y
=
tensor
.
d
scalar
()
y
=
tensor
.
scalar
()
f
=
function
([
x
,
y
],
fill_diagonal
(
x
,
y
))
f
=
function
([
x
,
y
],
fill_diagonal
(
x
,
y
))
val
=
numpy
.
random
.
rand
()
+
10
val
=
numpy
.
cast
[
config
.
floatX
](
numpy
.
random
.
rand
()
+
10
)
out
=
f
(
a
,
val
)
out
=
f
(
a
,
val
)
# We can't use numpy.fill_diagonal as it is bugged.
# We can't use numpy.fill_diagonal as it is bugged.
assert
out
[
0
,
0
,
0
]
==
val
assert
out
[
0
,
0
,
0
]
==
val
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论