Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1ff4b9d3
提交
1ff4b9d3
authored
6月 02, 2021
作者:
kc611
提交者:
Brandon T. Willard
6月 25, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor tests.tensor to use NumPy Generator
上级
8044a412
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
30 个修改的文件
包含
154 行增加
和
157 行删除
+154
-157
speed_test_conv.py
tests/tensor/nnet/speed_test_conv.py
+5
-5
test_abstract_conv.py
tests/tensor/nnet/test_abstract_conv.py
+15
-15
test_basic.py
tests/tensor/nnet/test_basic.py
+0
-0
test_batchnorm.py
tests/tensor/nnet/test_batchnorm.py
+54
-55
test_blocksparse.py
tests/tensor/nnet/test_blocksparse.py
+1
-1
test_basic.py
tests/tensor/random/test_basic.py
+3
-3
test_opt.py
tests/tensor/random/test_opt.py
+5
-5
test_conv.py
tests/tensor/signal/test_conv.py
+0
-3
test_pool.py
tests/tensor/signal/test_pool.py
+0
-0
test_basic.py
tests/tensor/test_basic.py
+0
-0
test_basic_opt.py
tests/tensor/test_basic_opt.py
+0
-0
test_blas.py
tests/tensor/test_blas.py
+0
-0
test_blas_c.py
tests/tensor/test_blas_c.py
+4
-7
test_complex.py
tests/tensor/test_complex.py
+25
-20
test_elemwise.py
tests/tensor/test_elemwise.py
+5
-8
test_extra_ops.py
tests/tensor/test_extra_ops.py
+27
-27
test_fourier.py
tests/tensor/test_fourier.py
+10
-8
test_math.py
tests/tensor/test_math.py
+0
-0
test_math_opt.py
tests/tensor/test_math_opt.py
+0
-0
test_math_scipy.py
tests/tensor/test_math_scipy.py
+0
-0
test_mlp.py
tests/tensor/test_mlp.py
+0
-0
test_nlinalg.py
tests/tensor/test_nlinalg.py
+0
-0
test_opt_uncanonicalize.py
tests/tensor/test_opt_uncanonicalize.py
+0
-0
test_shape.py
tests/tensor/test_shape.py
+0
-0
test_sharedvar.py
tests/tensor/test_sharedvar.py
+0
-0
test_slinalg.py
tests/tensor/test_slinalg.py
+0
-0
test_sort.py
tests/tensor/test_sort.py
+0
-0
test_subtensor.py
tests/tensor/test_subtensor.py
+0
-0
test_xlogx.py
tests/tensor/test_xlogx.py
+0
-0
utils.py
tests/tensor/utils.py
+0
-0
没有找到文件。
tests/tensor/nnet/speed_test_conv.py
浏览文件 @
1ff4b9d3
...
@@ -37,7 +37,7 @@ def flip(kern, kshp):
...
@@ -37,7 +37,7 @@ def flip(kern, kshp):
return
flip
return
flip
global_rng
=
np
.
random
.
RandomState
(
3423489
)
global_rng
=
np
.
random
.
default_rng
(
3423489
)
dmatrix4
=
TensorType
(
"float64"
,
(
False
,
False
,
False
,
False
))
dmatrix4
=
TensorType
(
"float64"
,
(
False
,
False
,
False
,
False
))
...
@@ -64,7 +64,7 @@ def exec_multilayer_conv_nnet_old(
...
@@ -64,7 +64,7 @@ def exec_multilayer_conv_nnet_old(
img
=
dmatrix
()
img
=
dmatrix
()
# build actual input images
# build actual input images
imgval
=
global_rng
.
rand
(
bsize
,
imshp
[
0
],
imshp
[
1
],
imshp
[
2
]
)
imgval
=
global_rng
.
rand
om
((
bsize
,
imshp
[
0
],
imshp
[
1
],
imshp
[
2
])
)
a
=
dmatrix
()
a
=
dmatrix
()
kerns
=
[
a
for
i
in
nkerns
]
kerns
=
[
a
for
i
in
nkerns
]
...
@@ -82,7 +82,7 @@ def exec_multilayer_conv_nnet_old(
...
@@ -82,7 +82,7 @@ def exec_multilayer_conv_nnet_old(
print
(
conv_mode
,
ss
,
n_layer
,
kshp
,
nkern
)
print
(
conv_mode
,
ss
,
n_layer
,
kshp
,
nkern
)
# actual values
# actual values
w
=
global_rng
.
random
_sample
(
np
.
r_
[
nkern
,
imshp
[
0
],
kshp
]
)
w
=
global_rng
.
random
((
np
.
r_
[
nkern
,
imshp
[
0
],
kshp
])
)
w_flip
=
flip
(
w
,
kshp
)
.
reshape
(
w
.
shape
)
w_flip
=
flip
(
w
,
kshp
)
.
reshape
(
w
.
shape
)
# manual implementation
# manual implementation
...
@@ -193,7 +193,7 @@ def exec_multilayer_conv_nnet(
...
@@ -193,7 +193,7 @@ def exec_multilayer_conv_nnet(
img
=
dmatrix
()
img
=
dmatrix
()
# build actual input images
# build actual input images
imgval
=
global_rng
.
rand
(
bsize
,
imshp
[
0
],
imshp
[
1
],
imshp
[
2
]
)
imgval
=
global_rng
.
rand
om
((
bsize
,
imshp
[
0
],
imshp
[
1
],
imshp
[
2
])
)
a
=
dmatrix
()
a
=
dmatrix
()
kerns
=
[
a
for
i
in
nkerns
]
kerns
=
[
a
for
i
in
nkerns
]
...
@@ -211,7 +211,7 @@ def exec_multilayer_conv_nnet(
...
@@ -211,7 +211,7 @@ def exec_multilayer_conv_nnet(
print
(
conv_mode
,
ss
,
n_layer
,
kshp
,
nkern
)
print
(
conv_mode
,
ss
,
n_layer
,
kshp
,
nkern
)
# actual values
# actual values
w
=
global_rng
.
random
_sample
(
np
.
r_
[
nkern
,
imshp
[
0
],
kshp
]
)
w
=
global_rng
.
random
((
np
.
r_
[
nkern
,
imshp
[
0
],
kshp
])
)
w_flip
=
flip
(
w
,
kshp
)
.
reshape
(
w
.
shape
)
w_flip
=
flip
(
w
,
kshp
)
.
reshape
(
w
.
shape
)
outshp
=
np
.
hstack
(
outshp
=
np
.
hstack
(
...
...
tests/tensor/nnet/test_abstract_conv.py
浏览文件 @
1ff4b9d3
...
@@ -1903,7 +1903,7 @@ class TestConv2dTranspose:
...
@@ -1903,7 +1903,7 @@ class TestConv2dTranspose:
)
)
class
TestConv2dGrads
:
class
TestConv2dGrads
:
def
setup_method
(
self
):
def
setup_method
(
self
):
self
.
random_stream
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
self
.
random_stream
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
self
.
inputs_shapes
=
[(
8
,
1
,
12
,
12
),
(
1
,
1
,
5
,
5
),
(
1
,
1
,
5
,
6
),
(
1
,
1
,
6
,
6
)]
self
.
inputs_shapes
=
[(
8
,
1
,
12
,
12
),
(
1
,
1
,
5
,
5
),
(
1
,
1
,
5
,
6
),
(
1
,
1
,
6
,
6
)]
self
.
filters_shapes
=
[(
5
,
1
,
2
,
2
),
(
1
,
1
,
3
,
3
)]
self
.
filters_shapes
=
[(
5
,
1
,
2
,
2
),
(
1
,
1
,
3
,
3
)]
...
@@ -1928,12 +1928,12 @@ class TestConv2dGrads:
...
@@ -1928,12 +1928,12 @@ class TestConv2dGrads:
for
bm
in
self
.
border_modes
:
for
bm
in
self
.
border_modes
:
for
ss
in
self
.
subsamples
:
for
ss
in
self
.
subsamples
:
for
ff
in
self
.
filter_flip
:
for
ff
in
self
.
filter_flip
:
input_val
=
self
.
random_stream
.
random_sample
(
in_shape
)
.
astype
(
input_val
=
self
.
random_stream
.
random
(
in_shape
)
.
astype
(
config
.
floatX
)
filter_val
=
self
.
random_stream
.
random
(
fltr_shape
)
.
astype
(
config
.
floatX
config
.
floatX
)
)
filter_val
=
self
.
random_stream
.
random_sample
(
fltr_shape
)
.
astype
(
config
.
floatX
)
out_grad_shape
=
(
out_grad_shape
=
(
aesara
.
tensor
.
nnet
.
abstract_conv
.
get_conv_output_shape
(
aesara
.
tensor
.
nnet
.
abstract_conv
.
get_conv_output_shape
(
image_shape
=
in_shape
,
image_shape
=
in_shape
,
...
@@ -1942,9 +1942,9 @@ class TestConv2dGrads:
...
@@ -1942,9 +1942,9 @@ class TestConv2dGrads:
subsample
=
ss
,
subsample
=
ss
,
)
)
)
)
out_grad_val
=
self
.
random_stream
.
random
_sampl
e
(
out_grad_val
=
self
.
random_stream
.
random
(
out_grad_shape
)
.
astyp
e
(
out_grad_shape
config
.
floatX
)
.
astype
(
config
.
floatX
)
)
conv_out
=
aesara
.
tensor
.
nnet
.
conv2d
(
conv_out
=
aesara
.
tensor
.
nnet
.
conv2d
(
self
.
x
,
self
.
x
,
filters
=
self
.
w
,
filters
=
self
.
w
,
...
@@ -1994,12 +1994,12 @@ class TestConv2dGrads:
...
@@ -1994,12 +1994,12 @@ class TestConv2dGrads:
for
bm
in
self
.
border_modes
:
for
bm
in
self
.
border_modes
:
for
ss
in
self
.
subsamples
:
for
ss
in
self
.
subsamples
:
for
ff
in
self
.
filter_flip
:
for
ff
in
self
.
filter_flip
:
input_val
=
self
.
random_stream
.
random_sample
(
in_shape
)
.
astype
(
input_val
=
self
.
random_stream
.
random
(
in_shape
)
.
astype
(
config
.
floatX
)
filter_val
=
self
.
random_stream
.
random
(
fltr_shape
)
.
astype
(
config
.
floatX
config
.
floatX
)
)
filter_val
=
self
.
random_stream
.
random_sample
(
fltr_shape
)
.
astype
(
config
.
floatX
)
out_grad_shape
=
(
out_grad_shape
=
(
aesara
.
tensor
.
nnet
.
abstract_conv
.
get_conv_output_shape
(
aesara
.
tensor
.
nnet
.
abstract_conv
.
get_conv_output_shape
(
image_shape
=
in_shape
,
image_shape
=
in_shape
,
...
@@ -2008,9 +2008,9 @@ class TestConv2dGrads:
...
@@ -2008,9 +2008,9 @@ class TestConv2dGrads:
subsample
=
ss
,
subsample
=
ss
,
)
)
)
)
out_grad_val
=
self
.
random_stream
.
random
_sampl
e
(
out_grad_val
=
self
.
random_stream
.
random
(
out_grad_shape
)
.
astyp
e
(
out_grad_shape
config
.
floatX
)
.
astype
(
config
.
floatX
)
)
conv_out
=
aesara
.
tensor
.
nnet
.
conv2d
(
conv_out
=
aesara
.
tensor
.
nnet
.
conv2d
(
self
.
x
,
self
.
x
,
filters
=
self
.
w
,
filters
=
self
.
w
,
...
...
tests/tensor/nnet/test_basic.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/nnet/test_batchnorm.py
浏览文件 @
1ff4b9d3
...
@@ -28,12 +28,12 @@ def test_BNComposite():
...
@@ -28,12 +28,12 @@ def test_BNComposite():
n
=
(
x
-
M
)
/
V
n
=
(
x
-
M
)
/
V
return
n
*
G
+
B
return
n
*
G
+
B
np
.
random
.
seed
(
1234
)
rng
=
np
.
random
.
default_rng
(
1234
)
X
=
1
+
np
.
random
.
random
([
10
,
20
])
.
astype
(
"float32"
)
X
=
1
+
rng
.
random
([
10
,
20
])
.
astype
(
"float32"
)
B
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
B
=
1
+
rng
.
random
([
20
])
.
astype
(
"float32"
)
G
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
G
=
1
+
rng
.
random
([
20
])
.
astype
(
"float32"
)
M
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
M
=
1
+
rng
.
random
([
20
])
.
astype
(
"float32"
)
V
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
V
=
1
+
rng
.
random
([
20
])
.
astype
(
"float32"
)
x
=
matrix
(
"x"
)
x
=
matrix
(
"x"
)
b
=
vector
(
"b"
)
b
=
vector
(
"b"
)
...
@@ -41,11 +41,11 @@ def test_BNComposite():
...
@@ -41,11 +41,11 @@ def test_BNComposite():
m
=
vector
(
"m"
)
m
=
vector
(
"m"
)
v
=
vector
(
"v"
)
v
=
vector
(
"v"
)
x
.
tag
.
test_value
=
np
.
random
.
rand
(
2
,
2
)
.
astype
(
aesara
.
config
.
floatX
)
x
.
tag
.
test_value
=
rng
.
random
((
2
,
2
)
)
.
astype
(
aesara
.
config
.
floatX
)
b
.
tag
.
test_value
=
np
.
random
.
rand
(
2
)
.
astype
(
aesara
.
config
.
floatX
)
b
.
tag
.
test_value
=
rng
.
random
((
2
)
)
.
astype
(
aesara
.
config
.
floatX
)
g
.
tag
.
test_value
=
np
.
random
.
rand
(
2
)
.
astype
(
aesara
.
config
.
floatX
)
g
.
tag
.
test_value
=
rng
.
random
((
2
)
)
.
astype
(
aesara
.
config
.
floatX
)
m
.
tag
.
test_value
=
np
.
random
.
rand
(
2
)
.
astype
(
aesara
.
config
.
floatX
)
m
.
tag
.
test_value
=
rng
.
random
((
2
)
)
.
astype
(
aesara
.
config
.
floatX
)
v
.
tag
.
test_value
=
np
.
random
.
rand
(
2
)
.
astype
(
aesara
.
config
.
floatX
)
v
.
tag
.
test_value
=
rng
.
random
((
2
)
)
.
astype
(
aesara
.
config
.
floatX
)
bn_ref_op
=
bn_ref
(
x
,
g
,
b
,
m
,
v
)
bn_ref_op
=
bn_ref
(
x
,
g
,
b
,
m
,
v
)
f_ref
=
aesara
.
function
([
x
,
b
,
g
,
m
,
v
],
[
bn_ref_op
])
f_ref
=
aesara
.
function
([
x
,
b
,
g
,
m
,
v
],
[
bn_ref_op
])
...
@@ -62,12 +62,12 @@ def test_batch_normalization():
...
@@ -62,12 +62,12 @@ def test_batch_normalization():
n
=
(
x
-
M
)
/
V
n
=
(
x
-
M
)
/
V
return
n
*
G
+
B
return
n
*
G
+
B
np
.
random
.
seed
(
1234
)
rng
=
np
.
random
.
default_rng
(
1234
)
X
=
1
+
np
.
random
.
random
([
10
,
20
])
.
astype
(
"float32"
)
X
=
1
+
rng
.
random
([
10
,
20
])
.
astype
(
"float32"
)
B
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
B
=
1
+
rng
.
random
([
20
])
.
astype
(
"float32"
)
G
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
G
=
1
+
rng
.
random
([
20
])
.
astype
(
"float32"
)
M
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
M
=
1
+
rng
.
random
([
20
])
.
astype
(
"float32"
)
V
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
V
=
1
+
rng
.
random
([
20
])
.
astype
(
"float32"
)
x
=
matrix
(
"x"
)
x
=
matrix
(
"x"
)
b
=
vector
(
"b"
)
b
=
vector
(
"b"
)
...
@@ -124,12 +124,12 @@ def test_bn_feature_maps():
...
@@ -124,12 +124,12 @@ def test_bn_feature_maps():
n
=
(
x
-
M
)
/
V
n
=
(
x
-
M
)
/
V
return
n
*
G
+
B
return
n
*
G
+
B
np
.
random
.
seed
(
1234
)
rng
=
np
.
random
.
default_rng
(
1234
)
X
=
1
+
np
.
random
.
random
([
2
,
3
,
4
,
4
])
.
astype
(
"float32"
)
X
=
1
+
rng
.
random
([
2
,
3
,
4
,
4
])
.
astype
(
"float32"
)
B
=
1
+
np
.
random
.
random
([
3
])
.
astype
(
"float32"
)
B
=
1
+
rng
.
random
([
3
])
.
astype
(
"float32"
)
G
=
1
+
np
.
random
.
random
([
3
])
.
astype
(
"float32"
)
G
=
1
+
rng
.
random
([
3
])
.
astype
(
"float32"
)
M
=
1
+
np
.
random
.
random
([
3
])
.
astype
(
"float32"
)
M
=
1
+
rng
.
random
([
3
])
.
astype
(
"float32"
)
V
=
1
+
np
.
random
.
random
([
3
])
.
astype
(
"float32"
)
V
=
1
+
rng
.
random
([
3
])
.
astype
(
"float32"
)
x
=
tensor4
(
"x"
)
x
=
tensor4
(
"x"
)
b
=
vector
(
"b"
)
b
=
vector
(
"b"
)
...
@@ -175,7 +175,6 @@ def test_bn_feature_maps():
...
@@ -175,7 +175,6 @@ def test_bn_feature_maps():
@pytest.mark.slow
@pytest.mark.slow
def
test_batch_normalization_train
():
def
test_batch_normalization_train
():
utt
.
seed_rng
()
for
axes
in
(
"per-activation"
,
"spatial"
,
(
1
,
2
,
3
,
4
)):
for
axes
in
(
"per-activation"
,
"spatial"
,
(
1
,
2
,
3
,
4
)):
for
vartype
in
(
tensor5
,
tensor3
,
vector
):
for
vartype
in
(
tensor5
,
tensor3
,
vector
):
...
@@ -320,19 +319,18 @@ def test_batch_normalization_train():
...
@@ -320,19 +319,18 @@ def test_batch_normalization_train():
param_shape
=
tuple
(
param_shape
=
tuple
(
1
if
d
in
axes2
else
s
for
d
,
s
in
enumerate
(
data_shape
)
1
if
d
in
axes2
else
s
for
d
,
s
in
enumerate
(
data_shape
)
)
)
X
=
4
+
3
*
np
.
random
.
randn
(
*
data_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Dy
=
-
1
+
2
*
np
.
random
.
randn
(
*
data_shape
)
.
astype
(
aesara
.
config
.
floatX
)
rng
=
np
.
random
.
default_rng
(
1234
)
Scale
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Bias
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
X
=
4
+
3
*
rng
.
random
(
data_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Running_mean
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
Dy
=
-
1
+
2
*
rng
.
random
(
data_shape
)
.
astype
(
aesara
.
config
.
floatX
)
aesara
.
config
.
floatX
Scale
=
rng
.
random
(
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
)
Bias
=
rng
.
random
(
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Running_var
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Running_mean
=
rng
.
random
(
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Dx
=
4
+
3
*
np
.
random
.
randn
(
*
data_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Running_var
=
rng
.
random
(
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Dscale
=
-
1
+
2
*
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
Dx
=
4
+
3
*
rng
.
random
(
data_shape
)
.
astype
(
aesara
.
config
.
floatX
)
aesara
.
config
.
floatX
Dscale
=
-
1
+
2
*
rng
.
random
(
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
)
Dbias
=
rng
.
random
(
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Dbias
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
outputs
=
f
(
outputs
=
f
(
X
,
Scale
,
Bias
,
Running_mean
,
Running_var
,
Dy
,
Dx
,
Dscale
,
Dbias
X
,
Scale
,
Bias
,
Running_mean
,
Running_var
,
Dy
,
Dx
,
Dscale
,
Dbias
...
@@ -361,7 +359,6 @@ def test_batch_normalization_train():
...
@@ -361,7 +359,6 @@ def test_batch_normalization_train():
@pytest.mark.slow
@pytest.mark.slow
def
test_batch_normalization_train_grad_grad
():
def
test_batch_normalization_train_grad_grad
():
utt
.
seed_rng
()
for
axes
in
(
"per-activation"
,
"spatial"
,
(
1
,
2
,
3
,
4
)):
for
axes
in
(
"per-activation"
,
"spatial"
,
(
1
,
2
,
3
,
4
)):
for
vartype
in
(
tensor5
,
tensor4
,
tensor3
,
matrix
,
vector
):
for
vartype
in
(
tensor5
,
tensor4
,
tensor3
,
matrix
,
vector
):
...
@@ -407,12 +404,13 @@ def test_batch_normalization_train_grad_grad():
...
@@ -407,12 +404,13 @@ def test_batch_normalization_train_grad_grad():
param_shape
=
tuple
(
param_shape
=
tuple
(
1
if
d
in
axes
else
s
for
d
,
s
in
enumerate
(
data_shape
)
1
if
d
in
axes
else
s
for
d
,
s
in
enumerate
(
data_shape
)
)
)
rng
=
np
.
random
.
default_rng
(
1234
)
# force float64 for sufficient numerical stability
# force float64 for sufficient numerical stability
x_val
=
4
+
3
*
np
.
random
.
randn
(
*
data_shape
)
.
astype
(
"float64"
)
x_val
=
4
+
3
*
rng
.
random
(
data_shape
)
.
astype
(
"float64"
)
dy_val
=
-
1
+
2
*
np
.
random
.
randn
(
*
data_shape
)
.
astype
(
"float64"
)
dy_val
=
-
1
+
2
*
rng
.
random
(
data_shape
)
.
astype
(
"float64"
)
scale_val
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
"float64"
)
scale_val
=
rng
.
random
(
param_shape
)
.
astype
(
"float64"
)
x_mean_val
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
"float64"
)
x_mean_val
=
rng
.
random
(
param_shape
)
.
astype
(
"float64"
)
x_invstd_val
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
"float64"
)
x_invstd_val
=
rng
.
random
(
param_shape
)
.
astype
(
"float64"
)
utt
.
verify_grad
(
utt
.
verify_grad
(
bn_grad_wrt_inputs_f
,
bn_grad_wrt_inputs_f
,
...
@@ -432,7 +430,6 @@ def test_batch_normalization_train_grad_grad():
...
@@ -432,7 +430,6 @@ def test_batch_normalization_train_grad_grad():
def
test_batch_normalization_train_without_running_averages
():
def
test_batch_normalization_train_without_running_averages
():
# compile and run batch_normalization_train without running averages
# compile and run batch_normalization_train without running averages
utt
.
seed_rng
()
x
,
scale
,
bias
,
dy
=
(
x
,
scale
,
bias
,
dy
=
(
tensor4
(
"x"
),
tensor4
(
"x"
),
...
@@ -466,10 +463,11 @@ def test_batch_normalization_train_without_running_averages():
...
@@ -466,10 +463,11 @@ def test_batch_normalization_train_without_running_averages():
]
]
)
)
# run
# run
X
=
4
+
3
*
np
.
random
.
randn
(
*
data_shape
)
.
astype
(
aesara
.
config
.
floatX
)
rng
=
np
.
random
.
default_rng
(
1234
)
Dy
=
-
1
+
2
*
np
.
random
.
randn
(
*
data_shape
)
.
astype
(
aesara
.
config
.
floatX
)
X
=
4
+
3
*
rng
.
random
(
data_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Scale
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Dy
=
-
1
+
2
*
rng
.
random
(
data_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Bias
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Scale
=
rng
.
random
(
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Bias
=
rng
.
random
(
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
f
(
X
,
Scale
,
Bias
,
Dy
)
f
(
X
,
Scale
,
Bias
,
Dy
)
...
@@ -565,7 +563,7 @@ def test_batch_normalization_train_broadcast():
...
@@ -565,7 +563,7 @@ def test_batch_normalization_train_broadcast():
assert
len
(
nodes
)
==
1
assert
len
(
nodes
)
==
1
assert
isinstance
(
nodes
[
0
]
.
op
,
aesara
.
compile
.
DeepCopyOp
)
assert
isinstance
(
nodes
[
0
]
.
op
,
aesara
.
compile
.
DeepCopyOp
)
inputs
=
[
inputs
=
[
np
.
asarray
(
np
.
random
.
rand
(
*
((
4
,)
*
n
)),
x
.
dtype
)
np
.
asarray
(
np
.
random
.
rand
om
(
((
4
,)
*
n
)),
x
.
dtype
)
for
n
in
[
for
n
in
[
x
.
ndim
,
x
.
ndim
,
scale
.
ndim
,
scale
.
ndim
,
...
@@ -641,12 +639,13 @@ def test_batch_normalization_test():
...
@@ -641,12 +639,13 @@ def test_batch_normalization_test():
param_shape
=
tuple
(
param_shape
=
tuple
(
1
if
d
in
axes2
else
s
for
d
,
s
in
enumerate
(
data_shape
)
1
if
d
in
axes2
else
s
for
d
,
s
in
enumerate
(
data_shape
)
)
)
X
=
4
+
3
*
np
.
random
.
randn
(
*
data_shape
)
.
astype
(
aesara
.
config
.
floatX
)
rng
=
np
.
random
.
default_rng
(
1234
)
Dy
=
-
1
+
2
*
np
.
random
.
randn
(
*
data_shape
)
.
astype
(
aesara
.
config
.
floatX
)
X
=
4
+
3
*
rng
.
random
(
data_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Scale
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Dy
=
-
1
+
2
*
rng
.
random
(
data_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Bias
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Scale
=
rng
.
random
(
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Mean
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Bias
=
rng
.
random
(
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Var
=
np
.
random
.
rand
(
*
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Mean
=
rng
.
random
(
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
Var
=
rng
.
random
(
param_shape
)
.
astype
(
aesara
.
config
.
floatX
)
outputs
=
f
(
X
,
Scale
,
Bias
,
Mean
,
Var
,
Dy
)
outputs
=
f
(
X
,
Scale
,
Bias
,
Mean
,
Var
,
Dy
)
# compare outputs
# compare outputs
utt
.
assert_allclose
(
outputs
[
0
],
outputs
[
1
])
# out
utt
.
assert_allclose
(
outputs
[
0
],
outputs
[
1
])
# out
...
...
tests/tensor/nnet/test_blocksparse.py
浏览文件 @
1ff4b9d3
...
@@ -20,7 +20,7 @@ from aesara.tensor.type import fmatrix, ftensor3, ftensor4, imatrix
...
@@ -20,7 +20,7 @@ from aesara.tensor.type import fmatrix, ftensor3, ftensor4, imatrix
class
TestBlockSparseGemvAndOuter
(
utt
.
InferShapeTester
):
class
TestBlockSparseGemvAndOuter
(
utt
.
InferShapeTester
):
def
setup_method
(
self
):
def
setup_method
(
self
):
utt
.
seed_rng
()
mode
=
None
mode
=
None
if
aesara
.
config
.
mode
==
"FAST_COMPILE"
:
if
aesara
.
config
.
mode
==
"FAST_COMPILE"
:
mode
=
"FAST_RUN"
mode
=
"FAST_RUN"
...
...
tests/tensor/random/test_basic.py
浏览文件 @
1ff4b9d3
...
@@ -437,7 +437,7 @@ def test_dirichlet_samples():
...
@@ -437,7 +437,7 @@ def test_dirichlet_samples():
assert
res
.
shape
==
(
2
,
3
)
assert
res
.
shape
==
(
2
,
3
)
assert
all
(
np
.
all
(
r
[
i
]
>
np
.
delete
(
r
,
[
i
]))
for
r
in
res
)
assert
all
(
np
.
all
(
r
[
i
]
>
np
.
delete
(
r
,
[
i
]))
for
r
in
res
)
rng_state
=
np
.
random
.
RandomState
(
np
.
random
.
MT19937
(
np
.
random
.
SeedSequence
(
1234
)))
rng_state
=
np
.
random
.
Generator
(
np
.
random
.
MT19937
(
np
.
random
.
SeedSequence
(
1234
)))
alphas
=
np
.
array
([[
1000
,
1
,
1
],
[
1
,
1000
,
1
],
[
1
,
1
,
1000
]],
dtype
=
config
.
floatX
)
alphas
=
np
.
array
([[
1000
,
1
,
1
],
[
1
,
1000
,
1
],
[
1
,
1
,
1000
]],
dtype
=
config
.
floatX
)
...
@@ -661,7 +661,7 @@ def test_multinomial_samples():
...
@@ -661,7 +661,7 @@ def test_multinomial_samples():
)
)
rng_state
=
shared
(
rng_state
=
shared
(
np
.
random
.
RandomState
(
np
.
random
.
MT19937
(
np
.
random
.
SeedSequence
(
1234
)))
np
.
random
.
Generator
(
np
.
random
.
MT19937
(
np
.
random
.
SeedSequence
(
1234
)))
)
)
test_M
=
np
.
array
([
10
,
20
],
dtype
=
"int64"
)
test_M
=
np
.
array
([
10
,
20
],
dtype
=
"int64"
)
...
@@ -678,7 +678,7 @@ def test_multinomial_samples():
...
@@ -678,7 +678,7 @@ def test_multinomial_samples():
def
test_categorical_samples
():
def
test_categorical_samples
():
rng_state
=
np
.
random
.
RandomState
(
np
.
random
.
MT19937
(
np
.
random
.
SeedSequence
(
1234
)))
rng_state
=
np
.
random
.
Generator
(
np
.
random
.
MT19937
(
np
.
random
.
SeedSequence
(
1234
)))
assert
categorical
.
rng_fn
(
rng_state
,
np
.
array
([
1.0
/
3.0
]
*
3
),
size
=
10
)
.
shape
==
(
assert
categorical
.
rng_fn
(
rng_state
,
np
.
array
([
1.0
/
3.0
]
*
3
),
size
=
10
)
.
shape
==
(
10
,
10
,
...
...
tests/tensor/random/test_opt.py
浏览文件 @
1ff4b9d3
...
@@ -129,7 +129,7 @@ def test_inplace_optimization():
...
@@ -129,7 +129,7 @@ def test_inplace_optimization():
],
],
)
)
def
test_local_rv_size_lift
(
dist_op
,
dist_params
,
size
):
def
test_local_rv_size_lift
(
dist_op
,
dist_params
,
size
):
rng
=
shared
(
np
.
random
.
RandomState
(
1233532
),
borrow
=
False
)
rng
=
shared
(
np
.
random
.
default_rng
(
1233532
),
borrow
=
False
)
new_out
,
f_inputs
,
dist_st
,
f_opt
=
apply_local_opt_to_rv
(
new_out
,
f_inputs
,
dist_st
,
f_opt
=
apply_local_opt_to_rv
(
local_rv_size_lift
,
local_rv_size_lift
,
...
@@ -284,7 +284,7 @@ def test_local_rv_size_lift(dist_op, dist_params, size):
...
@@ -284,7 +284,7 @@ def test_local_rv_size_lift(dist_op, dist_params, size):
@config.change_flags
(
compute_test_value_opt
=
"raise"
,
compute_test_value
=
"raise"
)
@config.change_flags
(
compute_test_value_opt
=
"raise"
,
compute_test_value
=
"raise"
)
def
test_DimShuffle_lift
(
ds_order
,
lifted
,
dist_op
,
dist_params
,
size
,
rtol
):
def
test_DimShuffle_lift
(
ds_order
,
lifted
,
dist_op
,
dist_params
,
size
,
rtol
):
rng
=
shared
(
np
.
random
.
RandomState
(
1233532
),
borrow
=
False
)
rng
=
shared
(
np
.
random
.
default_rng
(
1233532
),
borrow
=
False
)
new_out
,
f_inputs
,
dist_st
,
f_opt
=
apply_local_opt_to_rv
(
new_out
,
f_inputs
,
dist_st
,
f_opt
=
apply_local_opt_to_rv
(
local_dimshuffle_rv_lift
,
local_dimshuffle_rv_lift
,
...
@@ -400,7 +400,7 @@ def test_DimShuffle_lift(ds_order, lifted, dist_op, dist_params, size, rtol):
...
@@ -400,7 +400,7 @@ def test_DimShuffle_lift(ds_order, lifted, dist_op, dist_params, size, rtol):
def
test_Subtensor_lift
(
indices
,
lifted
,
dist_op
,
dist_params
,
size
):
def
test_Subtensor_lift
(
indices
,
lifted
,
dist_op
,
dist_params
,
size
):
from
aesara.tensor.subtensor
import
as_index_constant
from
aesara.tensor.subtensor
import
as_index_constant
rng
=
shared
(
np
.
random
.
RandomState
(
1233532
),
borrow
=
False
)
rng
=
shared
(
np
.
random
.
default_rng
(
1233532
),
borrow
=
False
)
indices_aet
=
()
indices_aet
=
()
for
i
in
indices
:
for
i
in
indices
:
...
@@ -445,7 +445,7 @@ def test_Subtensor_lift(indices, lifted, dist_op, dist_params, size):
...
@@ -445,7 +445,7 @@ def test_Subtensor_lift(indices, lifted, dist_op, dist_params, size):
def
test_Subtensor_lift_restrictions
():
def
test_Subtensor_lift_restrictions
():
rng
=
shared
(
np
.
random
.
RandomState
(
1233532
),
borrow
=
False
)
rng
=
shared
(
np
.
random
.
default_rng
(
1233532
),
borrow
=
False
)
std
=
vector
(
"std"
)
std
=
vector
(
"std"
)
std
.
tag
.
test_value
=
np
.
array
([
1e-5
,
2e-5
,
3e-5
],
dtype
=
config
.
floatX
)
std
.
tag
.
test_value
=
np
.
array
([
1e-5
,
2e-5
,
3e-5
],
dtype
=
config
.
floatX
)
...
@@ -477,7 +477,7 @@ def test_Subtensor_lift_restrictions():
...
@@ -477,7 +477,7 @@ def test_Subtensor_lift_restrictions():
def
test_Dimshuffle_lift_restrictions
():
def
test_Dimshuffle_lift_restrictions
():
rng
=
shared
(
np
.
random
.
RandomState
(
1233532
),
borrow
=
False
)
rng
=
shared
(
np
.
random
.
default_rng
(
1233532
),
borrow
=
False
)
x
=
normal
(
aet
.
arange
(
2
)
.
reshape
((
2
,)),
100
,
size
=
(
2
,
2
,
2
),
rng
=
rng
)
x
=
normal
(
aet
.
arange
(
2
)
.
reshape
((
2
,)),
100
,
size
=
(
2
,
2
,
2
),
rng
=
rng
)
y
=
x
.
dimshuffle
(
1
,
0
,
2
)
y
=
x
.
dimshuffle
(
1
,
0
,
2
)
...
...
tests/tensor/signal/test_conv.py
浏览文件 @
1ff4b9d3
...
@@ -12,9 +12,6 @@ _ = pytest.importorskip("scipy.signal")
...
@@ -12,9 +12,6 @@ _ = pytest.importorskip("scipy.signal")
class
TestSignalConv2D
:
class
TestSignalConv2D
:
def
setup_method
(
self
):
utt
.
seed_rng
()
def
validate
(
self
,
image_shape
,
filter_shape
,
out_dim
,
verify_grad
=
True
):
def
validate
(
self
,
image_shape
,
filter_shape
,
out_dim
,
verify_grad
=
True
):
image_dim
=
len
(
image_shape
)
image_dim
=
len
(
image_shape
)
...
...
tests/tensor/signal/test_pool.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/test_basic.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/test_basic_opt.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/test_blas.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/test_blas_c.py
浏览文件 @
1ff4b9d3
...
@@ -202,7 +202,7 @@ class TestCGemv(OptimizationTestMixin):
...
@@ -202,7 +202,7 @@ class TestCGemv(OptimizationTestMixin):
def
t_gemv1
(
self
,
m_shp
):
def
t_gemv1
(
self
,
m_shp
):
""" test vector2 + dot(matrix, vector1) """
""" test vector2 + dot(matrix, vector1) """
rng
=
np
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
v1
=
aesara
.
shared
(
np
.
array
(
rng
.
uniform
(
size
=
(
m_shp
[
1
],)),
dtype
=
"float32"
))
v1
=
aesara
.
shared
(
np
.
array
(
rng
.
uniform
(
size
=
(
m_shp
[
1
],)),
dtype
=
"float32"
))
v2_orig
=
np
.
array
(
rng
.
uniform
(
size
=
(
m_shp
[
0
],)),
dtype
=
"float32"
)
v2_orig
=
np
.
array
(
rng
.
uniform
(
size
=
(
m_shp
[
0
],)),
dtype
=
"float32"
)
v2
=
aesara
.
shared
(
v2_orig
)
v2
=
aesara
.
shared
(
v2_orig
)
...
@@ -278,9 +278,9 @@ class TestCGemv(OptimizationTestMixin):
...
@@ -278,9 +278,9 @@ class TestCGemv(OptimizationTestMixin):
f
=
aesara
.
function
(
f
=
aesara
.
function
(
[
x
,
y
,
z
],
[
aet
.
dot
(
y
,
x
),
aet
.
dot
(
z
,
x
)],
mode
=
mode_blas_opt
[
x
,
y
,
z
],
[
aet
.
dot
(
y
,
x
),
aet
.
dot
(
z
,
x
)],
mode
=
mode_blas_opt
)
)
vx
=
np
.
random
.
rand
(
3
,
3
)
vx
=
np
.
random
.
rand
om
((
3
,
3
)
)
vy
=
np
.
random
.
rand
(
3
)
vy
=
np
.
random
.
rand
om
((
3
)
)
vz
=
np
.
random
.
rand
(
3
)
vz
=
np
.
random
.
rand
om
((
3
)
)
out
=
f
(
vx
,
vy
,
vz
)
out
=
f
(
vx
,
vy
,
vz
)
assert
np
.
allclose
(
out
[
0
],
np
.
dot
(
vy
,
vx
))
assert
np
.
allclose
(
out
[
0
],
np
.
dot
(
vy
,
vx
))
assert
np
.
allclose
(
out
[
1
],
np
.
dot
(
vz
,
vx
))
assert
np
.
allclose
(
out
[
1
],
np
.
dot
(
vz
,
vx
))
...
@@ -317,9 +317,6 @@ class TestCGemvNoFlags:
...
@@ -317,9 +317,6 @@ class TestCGemvNoFlags:
N
=
5
N
=
5
slice_step
=
3
slice_step
=
3
def
setup_method
(
self
):
unittest_tools
.
seed_rng
()
def
get_function
(
self
,
dtype
,
transpose_A
=
False
,
slice_tensors
=
False
):
def
get_function
(
self
,
dtype
,
transpose_A
=
False
,
slice_tensors
=
False
):
alpha
=
scalar
(
dtype
=
dtype
)
alpha
=
scalar
(
dtype
=
dtype
)
beta
=
scalar
(
dtype
=
dtype
)
beta
=
scalar
(
dtype
=
dtype
)
...
...
tests/tensor/test_complex.py
浏览文件 @
1ff4b9d3
...
@@ -12,20 +12,25 @@ from tests import unittest_tools as utt
...
@@ -12,20 +12,25 @@ from tests import unittest_tools as utt
class
TestRealImag
:
class
TestRealImag
:
def
test_basic
(
self
):
def
test_basic
(
self
):
x
=
zvector
()
x
=
zvector
()
rng
=
np
.
random
.
RandomState
(
23
)
rng
=
np
.
random
.
default_rng
(
23
)
xval
=
np
.
asarray
(
list
(
np
.
complex
(
rng
.
randn
(),
rng
.
randn
())
for
i
in
range
(
10
)))
xval
=
np
.
asarray
(
list
(
np
.
complex
(
rng
.
standard_normal
(),
rng
.
standard_normal
())
for
i
in
range
(
10
)
)
)
assert
np
.
all
(
xval
.
real
==
aesara
.
function
([
x
],
real
(
x
))(
xval
))
assert
np
.
all
(
xval
.
real
==
aesara
.
function
([
x
],
real
(
x
))(
xval
))
assert
np
.
all
(
xval
.
imag
==
aesara
.
function
([
x
],
imag
(
x
))(
xval
))
assert
np
.
all
(
xval
.
imag
==
aesara
.
function
([
x
],
imag
(
x
))(
xval
))
def
test_on_real_input
(
self
):
def
test_on_real_input
(
self
):
x
=
dvector
()
x
=
dvector
()
rng
=
np
.
random
.
RandomState
(
23
)
rng
=
np
.
random
.
default_rng
(
23
)
xval
=
rng
.
randn
(
10
)
xval
=
rng
.
standard_normal
((
10
)
)
np
.
all
(
0
==
aesara
.
function
([
x
],
imag
(
x
))(
xval
))
np
.
all
(
0
==
aesara
.
function
([
x
],
imag
(
x
))(
xval
))
np
.
all
(
xval
==
aesara
.
function
([
x
],
real
(
x
))(
xval
))
np
.
all
(
xval
==
aesara
.
function
([
x
],
real
(
x
))(
xval
))
x
=
imatrix
()
x
=
imatrix
()
xval
=
np
.
asarray
(
rng
.
randn
(
3
,
3
)
*
100
,
dtype
=
"int32"
)
xval
=
np
.
asarray
(
rng
.
standard_normal
((
3
,
3
)
)
*
100
,
dtype
=
"int32"
)
np
.
all
(
0
==
aesara
.
function
([
x
],
imag
(
x
))(
xval
))
np
.
all
(
0
==
aesara
.
function
([
x
],
imag
(
x
))(
xval
))
np
.
all
(
xval
==
aesara
.
function
([
x
],
real
(
x
))(
xval
))
np
.
all
(
xval
==
aesara
.
function
([
x
],
real
(
x
))(
xval
))
...
@@ -35,7 +40,7 @@ class TestRealImag:
...
@@ -35,7 +40,7 @@ class TestRealImag:
cast
(
x
,
"int32"
)
cast
(
x
,
"int32"
)
def
test_complex
(
self
):
def
test_complex
(
self
):
rng
=
np
.
random
.
RandomState
(
2333
)
rng
=
np
.
random
.
default_rng
(
2333
)
m
=
fmatrix
()
m
=
fmatrix
()
c
=
complex
(
m
[
0
],
m
[
1
])
c
=
complex
(
m
[
0
],
m
[
1
])
assert
c
.
type
==
cvector
assert
c
.
type
==
cvector
...
@@ -44,7 +49,7 @@ class TestRealImag:
...
@@ -44,7 +49,7 @@ class TestRealImag:
assert
i
.
type
==
fvector
assert
i
.
type
==
fvector
f
=
aesara
.
function
([
m
],
[
r
,
i
])
f
=
aesara
.
function
([
m
],
[
r
,
i
])
mval
=
np
.
asarray
(
rng
.
randn
(
2
,
5
),
dtype
=
"float32"
)
mval
=
np
.
asarray
(
rng
.
standard_normal
((
2
,
5
)
),
dtype
=
"float32"
)
rval
,
ival
=
f
(
mval
)
rval
,
ival
=
f
(
mval
)
assert
np
.
all
(
rval
==
mval
[
0
]),
(
rval
,
mval
[
0
])
assert
np
.
all
(
rval
==
mval
[
0
]),
(
rval
,
mval
[
0
])
assert
np
.
all
(
ival
==
mval
[
1
]),
(
ival
,
mval
[
1
])
assert
np
.
all
(
ival
==
mval
[
1
]),
(
ival
,
mval
[
1
])
...
@@ -55,8 +60,8 @@ class TestRealImag:
...
@@ -55,8 +60,8 @@ class TestRealImag:
c
=
complex
(
m
[
0
],
m
[
1
])
c
=
complex
(
m
[
0
],
m
[
1
])
return
0.5
*
real
(
c
)
+
0.9
*
imag
(
c
)
return
0.5
*
real
(
c
)
+
0.9
*
imag
(
c
)
rng
=
np
.
random
.
RandomState
(
9333
)
rng
=
np
.
random
.
default_rng
(
9333
)
mval
=
np
.
asarray
(
rng
.
randn
(
2
,
5
))
mval
=
np
.
asarray
(
rng
.
standard_normal
((
2
,
5
)
))
utt
.
verify_grad
(
f
,
[
mval
])
utt
.
verify_grad
(
f
,
[
mval
])
@pytest.mark.skip
(
reason
=
"Complex grads not enabled, see #178"
)
@pytest.mark.skip
(
reason
=
"Complex grads not enabled, see #178"
)
...
@@ -65,8 +70,8 @@ class TestRealImag:
...
@@ -65,8 +70,8 @@ class TestRealImag:
ac
=
complex
(
a
[
0
],
a
[
1
])
ac
=
complex
(
a
[
0
],
a
[
1
])
return
abs
((
ac
)
**
2
)
.
sum
()
return
abs
((
ac
)
**
2
)
.
sum
()
rng
=
np
.
random
.
RandomState
(
9333
)
rng
=
np
.
random
.
default_rng
(
9333
)
aval
=
np
.
asarray
(
rng
.
randn
(
2
,
5
))
aval
=
np
.
asarray
(
rng
.
standard_normal
((
2
,
5
)
))
try
:
try
:
utt
.
verify_grad
(
f
,
[
aval
])
utt
.
verify_grad
(
f
,
[
aval
])
except
GradientError
as
e
:
except
GradientError
as
e
:
...
@@ -80,8 +85,8 @@ class TestRealImag:
...
@@ -80,8 +85,8 @@ class TestRealImag:
ac
=
complex
(
a
[
0
],
a
[
1
])
ac
=
complex
(
a
[
0
],
a
[
1
])
return
abs
(
ac
)
.
sum
()
return
abs
(
ac
)
.
sum
()
rng
=
np
.
random
.
RandomState
(
9333
)
rng
=
np
.
random
.
default_rng
(
9333
)
aval
=
np
.
asarray
(
rng
.
randn
(
2
,
5
))
aval
=
np
.
asarray
(
rng
.
standard_normal
((
2
,
5
)
))
try
:
try
:
utt
.
verify_grad
(
f
,
[
aval
])
utt
.
verify_grad
(
f
,
[
aval
])
except
GradientError
as
e
:
except
GradientError
as
e
:
...
@@ -95,9 +100,9 @@ class TestRealImag:
...
@@ -95,9 +100,9 @@ class TestRealImag:
ac
=
complex
(
a
[
0
],
a
[
1
])
ac
=
complex
(
a
[
0
],
a
[
1
])
return
abs
((
ac
*
b
)
**
2
)
.
sum
()
return
abs
((
ac
*
b
)
**
2
)
.
sum
()
rng
=
np
.
random
.
RandomState
(
9333
)
rng
=
np
.
random
.
default_rng
(
9333
)
aval
=
np
.
asarray
(
rng
.
randn
(
2
,
5
))
aval
=
np
.
asarray
(
rng
.
standard_normal
((
2
,
5
)
))
bval
=
rng
.
randn
(
5
)
bval
=
rng
.
standard_normal
((
5
)
)
try
:
try
:
utt
.
verify_grad
(
f
,
[
aval
,
bval
])
utt
.
verify_grad
(
f
,
[
aval
,
bval
])
except
GradientError
as
e
:
except
GradientError
as
e
:
...
@@ -111,8 +116,8 @@ class TestRealImag:
...
@@ -111,8 +116,8 @@ class TestRealImag:
c
=
complex_from_polar
(
abs
(
m
[
0
]),
m
[
1
])
c
=
complex_from_polar
(
abs
(
m
[
0
]),
m
[
1
])
return
0.5
*
real
(
c
)
+
0.9
*
imag
(
c
)
return
0.5
*
real
(
c
)
+
0.9
*
imag
(
c
)
rng
=
np
.
random
.
RandomState
(
9333
)
rng
=
np
.
random
.
default_rng
(
9333
)
mval
=
np
.
asarray
(
rng
.
randn
(
2
,
5
))
mval
=
np
.
asarray
(
rng
.
standard_normal
((
2
,
5
)
))
utt
.
verify_grad
(
f
,
[
mval
])
utt
.
verify_grad
(
f
,
[
mval
])
@pytest.mark.skip
(
reason
=
"Complex grads not enabled, see #178"
)
@pytest.mark.skip
(
reason
=
"Complex grads not enabled, see #178"
)
...
@@ -121,6 +126,6 @@ class TestRealImag:
...
@@ -121,6 +126,6 @@ class TestRealImag:
c
=
complex
(
m
[
0
],
m
[
1
])
c
=
complex
(
m
[
0
],
m
[
1
])
return
0.5
*
abs
(
c
)
return
0.5
*
abs
(
c
)
rng
=
np
.
random
.
RandomState
(
9333
)
rng
=
np
.
random
.
default_rng
(
9333
)
mval
=
np
.
asarray
(
rng
.
randn
(
2
,
5
))
mval
=
np
.
asarray
(
rng
.
standard_normal
((
2
,
5
)
))
utt
.
verify_grad
(
f
,
[
mval
])
utt
.
verify_grad
(
f
,
[
mval
])
tests/tensor/test_elemwise.py
浏览文件 @
1ff4b9d3
...
@@ -135,13 +135,10 @@ class TestBroadcast:
...
@@ -135,13 +135,10 @@ class TestBroadcast:
linkers
=
[
PerformLinker
,
CLinker
]
linkers
=
[
PerformLinker
,
CLinker
]
def
rand_val
(
self
,
shp
):
def
rand_val
(
self
,
shp
):
return
np
.
asarray
(
np
.
random
.
rand
(
*
shp
),
dtype
=
aesara
.
config
.
floatX
)
return
np
.
asarray
(
np
.
random
.
rand
om
(
shp
),
dtype
=
aesara
.
config
.
floatX
)
def
rand_cval
(
self
,
shp
):
def
rand_cval
(
self
,
shp
):
return
np
.
asarray
(
np
.
random
.
rand
(
*
shp
),
dtype
=
aesara
.
config
.
floatX
)
return
np
.
asarray
(
np
.
random
.
random
(
shp
),
dtype
=
aesara
.
config
.
floatX
)
def
setup_method
(
self
):
unittest_tools
.
seed_rng
()
def
with_linker
(
self
,
linker
,
op
,
type
,
rand_val
):
def
with_linker
(
self
,
linker
,
op
,
type
,
rand_val
):
for
xsh
,
ysh
in
[
for
xsh
,
ysh
in
[
...
@@ -356,7 +353,7 @@ class TestCAReduce(unittest_tools.InferShapeTester):
...
@@ -356,7 +353,7 @@ class TestCAReduce(unittest_tools.InferShapeTester):
tosum
=
list
(
range
(
len
(
xsh
)))
tosum
=
list
(
range
(
len
(
xsh
)))
f
=
aesara
.
function
([
x
],
e
,
mode
=
mode
)
f
=
aesara
.
function
([
x
],
e
,
mode
=
mode
)
xv
=
np
.
asarray
(
np
.
random
.
rand
(
*
xsh
))
xv
=
np
.
asarray
(
np
.
random
.
rand
om
(
xsh
))
if
dtype
not
in
discrete_dtypes
:
if
dtype
not
in
discrete_dtypes
:
xv
=
np
.
asarray
(
xv
,
dtype
=
dtype
)
xv
=
np
.
asarray
(
xv
,
dtype
=
dtype
)
...
@@ -561,7 +558,7 @@ class TestCAReduce(unittest_tools.InferShapeTester):
...
@@ -561,7 +558,7 @@ class TestCAReduce(unittest_tools.InferShapeTester):
x
=
pre_scalar_op
(
x
)
x
=
pre_scalar_op
(
x
)
if
tosum
is
None
:
if
tosum
is
None
:
tosum
=
list
(
range
(
len
(
xsh
)))
tosum
=
list
(
range
(
len
(
xsh
)))
xv
=
np
.
asarray
(
np
.
random
.
rand
(
*
xsh
),
dtype
=
dtype
)
xv
=
np
.
asarray
(
np
.
random
.
rand
om
(
xsh
),
dtype
=
dtype
)
d
=
{}
d
=
{}
if
pre_scalar_op
is
not
None
:
if
pre_scalar_op
is
not
None
:
xv
=
x
.
eval
({
x
.
owner
.
inputs
[
0
]:
xv
})
xv
=
x
.
eval
({
x
.
owner
.
inputs
[
0
]:
xv
})
...
@@ -578,7 +575,7 @@ class TestCAReduce(unittest_tools.InferShapeTester):
...
@@ -578,7 +575,7 @@ class TestCAReduce(unittest_tools.InferShapeTester):
class
TestBitOpReduceGrad
:
class
TestBitOpReduceGrad
:
def
setup_method
(
self
):
def
setup_method
(
self
):
self
.
rng
=
np
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
self
.
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
def
test_all_grad
(
self
):
def
test_all_grad
(
self
):
x
=
bmatrix
(
"x"
)
x
=
bmatrix
(
"x"
)
...
...
tests/tensor/test_extra_ops.py
浏览文件 @
1ff4b9d3
...
@@ -69,7 +69,7 @@ from tests import unittest_tools as utt
...
@@ -69,7 +69,7 @@ from tests import unittest_tools as utt
def
test_cpu_contiguous
():
def
test_cpu_contiguous
():
a
=
fmatrix
(
"a"
)
a
=
fmatrix
(
"a"
)
i
=
iscalar
(
"i"
)
i
=
iscalar
(
"i"
)
a_val
=
np
.
asarray
(
np
.
random
.
rand
(
4
,
5
),
dtype
=
"float32"
)
a_val
=
np
.
asarray
(
np
.
random
.
rand
om
((
4
,
5
)
),
dtype
=
"float32"
)
f
=
aesara
.
function
([
a
,
i
],
cpu_contiguous
(
a
.
reshape
((
5
,
4
))[::
i
]))
f
=
aesara
.
function
([
a
,
i
],
cpu_contiguous
(
a
.
reshape
((
5
,
4
))[::
i
]))
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
any
([
isinstance
(
node
.
op
,
CpuContiguous
)
for
node
in
topo
])
assert
any
([
isinstance
(
node
.
op
,
CpuContiguous
)
for
node
in
topo
])
...
@@ -78,7 +78,7 @@ def test_cpu_contiguous():
...
@@ -78,7 +78,7 @@ def test_cpu_contiguous():
assert
f
(
a_val
,
3
)
.
flags
[
"C_CONTIGUOUS"
]
assert
f
(
a_val
,
3
)
.
flags
[
"C_CONTIGUOUS"
]
# Test the grad:
# Test the grad:
utt
.
verify_grad
(
cpu_contiguous
,
[
np
.
random
.
rand
(
5
,
7
,
2
)])
utt
.
verify_grad
(
cpu_contiguous
,
[
np
.
random
.
rand
om
((
5
,
7
,
2
)
)])
class
TestSearchsortedOp
(
utt
.
InferShapeTester
):
class
TestSearchsortedOp
(
utt
.
InferShapeTester
):
...
@@ -89,9 +89,9 @@ class TestSearchsortedOp(utt.InferShapeTester):
...
@@ -89,9 +89,9 @@ class TestSearchsortedOp(utt.InferShapeTester):
self
.
x
=
vector
(
"x"
)
self
.
x
=
vector
(
"x"
)
self
.
v
=
tensor3
(
"v"
)
self
.
v
=
tensor3
(
"v"
)
self
.
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
self
.
a
=
30
*
np
.
random
.
random
(
50
)
.
astype
(
config
.
floatX
)
self
.
a
=
30
*
self
.
rng
.
random
(
50
)
.
astype
(
config
.
floatX
)
self
.
b
=
30
*
np
.
random
.
random
((
8
,
10
,
5
))
.
astype
(
config
.
floatX
)
self
.
b
=
30
*
self
.
rng
.
random
((
8
,
10
,
5
))
.
astype
(
config
.
floatX
)
self
.
idx_sorted
=
np
.
argsort
(
self
.
a
)
.
astype
(
"int32"
)
self
.
idx_sorted
=
np
.
argsort
(
self
.
a
)
.
astype
(
"int32"
)
def
test_searchsortedOp_on_sorted_input
(
self
):
def
test_searchsortedOp_on_sorted_input
(
self
):
...
@@ -185,7 +185,7 @@ class TestSearchsortedOp(utt.InferShapeTester):
...
@@ -185,7 +185,7 @@ class TestSearchsortedOp(utt.InferShapeTester):
)
)
def
test_grad
(
self
):
def
test_grad
(
self
):
utt
.
verify_grad
(
self
.
op
,
[
self
.
a
[
self
.
idx_sorted
],
self
.
b
])
utt
.
verify_grad
(
self
.
op
,
[
self
.
a
[
self
.
idx_sorted
],
self
.
b
]
,
rng
=
self
.
rng
)
class
TestCumOp
(
utt
.
InferShapeTester
):
class
TestCumOp
(
utt
.
InferShapeTester
):
...
@@ -591,7 +591,7 @@ class TestBartlett(utt.InferShapeTester):
...
@@ -591,7 +591,7 @@ class TestBartlett(utt.InferShapeTester):
class
TestFillDiagonal
(
utt
.
InferShapeTester
):
class
TestFillDiagonal
(
utt
.
InferShapeTester
):
rng
=
np
.
random
.
RandomState
(
43
)
rng
=
np
.
random
.
default_rng
(
43
)
def
setup_method
(
self
):
def
setup_method
(
self
):
super
()
.
setup_method
()
super
()
.
setup_method
()
...
@@ -603,19 +603,19 @@ class TestFillDiagonal(utt.InferShapeTester):
...
@@ -603,19 +603,19 @@ class TestFillDiagonal(utt.InferShapeTester):
y
=
scalar
()
y
=
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
=
np
.
random
.
rand
(
*
shp
)
.
astype
(
config
.
floatX
)
a
=
np
.
random
.
rand
om
(
shp
)
.
astype
(
config
.
floatX
)
val
=
np
.
cast
[
config
.
floatX
](
np
.
random
.
rand
())
val
=
np
.
cast
[
config
.
floatX
](
np
.
random
.
rand
om
())
out
=
f
(
a
,
val
)
out
=
f
(
a
,
val
)
# We can't use np.fill_diagonal as it is bugged.
# We can't use np.fill_diagonal as it is bugged.
assert
np
.
allclose
(
np
.
diag
(
out
),
val
)
assert
np
.
allclose
(
np
.
diag
(
out
),
val
)
assert
(
out
==
val
)
.
sum
()
==
min
(
a
.
shape
)
assert
(
out
==
val
)
.
sum
()
==
min
(
a
.
shape
)
# test for 3dtt
# test for 3dtt
a
=
np
.
random
.
rand
(
3
,
3
,
3
)
.
astype
(
config
.
floatX
)
a
=
np
.
random
.
rand
om
((
3
,
3
,
3
)
)
.
astype
(
config
.
floatX
)
x
=
tensor3
()
x
=
tensor3
()
y
=
scalar
()
y
=
scalar
()
f
=
function
([
x
,
y
],
fill_diagonal
(
x
,
y
))
f
=
function
([
x
,
y
],
fill_diagonal
(
x
,
y
))
val
=
np
.
cast
[
config
.
floatX
](
np
.
random
.
rand
()
+
10
)
val
=
np
.
cast
[
config
.
floatX
](
np
.
random
.
rand
om
()
+
10
)
out
=
f
(
a
,
val
)
out
=
f
(
a
,
val
)
# We can't use np.fill_diagonal as it is bugged.
# We can't use np.fill_diagonal as it is bugged.
assert
out
[
0
,
0
,
0
]
==
val
assert
out
[
0
,
0
,
0
]
==
val
...
@@ -627,13 +627,13 @@ class TestFillDiagonal(utt.InferShapeTester):
...
@@ -627,13 +627,13 @@ class TestFillDiagonal(utt.InferShapeTester):
def
test_gradient
(
self
):
def
test_gradient
(
self
):
utt
.
verify_grad
(
utt
.
verify_grad
(
fill_diagonal
,
fill_diagonal
,
[
np
.
random
.
rand
(
5
,
8
),
np
.
random
.
rand
()],
[
np
.
random
.
rand
om
((
5
,
8
)),
np
.
random
.
random
()],
n_tests
=
1
,
n_tests
=
1
,
rng
=
TestFillDiagonal
.
rng
,
rng
=
TestFillDiagonal
.
rng
,
)
)
utt
.
verify_grad
(
utt
.
verify_grad
(
fill_diagonal
,
fill_diagonal
,
[
np
.
random
.
rand
(
8
,
5
),
np
.
random
.
rand
()],
[
np
.
random
.
rand
om
((
8
,
5
)),
np
.
random
.
random
()],
n_tests
=
1
,
n_tests
=
1
,
rng
=
TestFillDiagonal
.
rng
,
rng
=
TestFillDiagonal
.
rng
,
)
)
...
@@ -645,14 +645,14 @@ class TestFillDiagonal(utt.InferShapeTester):
...
@@ -645,14 +645,14 @@ class TestFillDiagonal(utt.InferShapeTester):
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
x
,
y
],
[
x
,
y
],
[
self
.
op
(
x
,
y
)],
[
self
.
op
(
x
,
y
)],
[
np
.
random
.
rand
(
8
,
5
),
np
.
random
.
rand
()],
[
np
.
random
.
rand
om
((
8
,
5
)),
np
.
random
.
random
()],
self
.
op_class
,
self
.
op_class
,
)
)
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
z
,
y
],
[
z
,
y
],
[
self
.
op
(
z
,
y
)],
[
self
.
op
(
z
,
y
)],
# must be square when nd>2
# must be square when nd>2
[
np
.
random
.
rand
(
8
,
8
,
8
),
np
.
random
.
rand
()],
[
np
.
random
.
rand
om
((
8
,
8
,
8
)),
np
.
random
.
random
()],
self
.
op_class
,
self
.
op_class
,
warn
=
False
,
warn
=
False
,
)
)
...
@@ -660,7 +660,7 @@ class TestFillDiagonal(utt.InferShapeTester):
...
@@ -660,7 +660,7 @@ class TestFillDiagonal(utt.InferShapeTester):
class
TestFillDiagonalOffset
(
utt
.
InferShapeTester
):
class
TestFillDiagonalOffset
(
utt
.
InferShapeTester
):
rng
=
np
.
random
.
RandomState
(
43
)
rng
=
np
.
random
.
default_rng
(
43
)
def
setup_method
(
self
):
def
setup_method
(
self
):
super
()
.
setup_method
()
super
()
.
setup_method
()
...
@@ -675,8 +675,8 @@ class TestFillDiagonalOffset(utt.InferShapeTester):
...
@@ -675,8 +675,8 @@ class TestFillDiagonalOffset(utt.InferShapeTester):
f
=
function
([
x
,
y
,
z
],
fill_diagonal_offset
(
x
,
y
,
z
))
f
=
function
([
x
,
y
,
z
],
fill_diagonal_offset
(
x
,
y
,
z
))
for
test_offset
in
(
-
5
,
-
4
,
-
1
,
0
,
1
,
4
,
5
):
for
test_offset
in
(
-
5
,
-
4
,
-
1
,
0
,
1
,
4
,
5
):
for
shp
in
[(
8
,
8
),
(
5
,
8
),
(
8
,
5
),
(
5
,
5
)]:
for
shp
in
[(
8
,
8
),
(
5
,
8
),
(
8
,
5
),
(
5
,
5
)]:
a
=
np
.
random
.
rand
(
*
shp
)
.
astype
(
config
.
floatX
)
a
=
np
.
random
.
rand
om
(
shp
)
.
astype
(
config
.
floatX
)
val
=
np
.
cast
[
config
.
floatX
](
np
.
random
.
rand
())
val
=
np
.
cast
[
config
.
floatX
](
np
.
random
.
rand
om
())
out
=
f
(
a
,
val
,
test_offset
)
out
=
f
(
a
,
val
,
test_offset
)
# We can't use np.fill_diagonal as it is bugged.
# We can't use np.fill_diagonal as it is bugged.
assert
np
.
allclose
(
np
.
diag
(
out
,
test_offset
),
val
)
assert
np
.
allclose
(
np
.
diag
(
out
,
test_offset
),
val
)
...
@@ -697,19 +697,19 @@ class TestFillDiagonalOffset(utt.InferShapeTester):
...
@@ -697,19 +697,19 @@ class TestFillDiagonalOffset(utt.InferShapeTester):
utt
.
verify_grad
(
utt
.
verify_grad
(
fill_diagonal_with_fix_offset
,
fill_diagonal_with_fix_offset
,
[
np
.
random
.
rand
(
5
,
8
),
np
.
random
.
rand
()],
[
np
.
random
.
rand
om
((
5
,
8
)),
np
.
random
.
random
()],
n_tests
=
1
,
n_tests
=
1
,
rng
=
TestFillDiagonalOffset
.
rng
,
rng
=
TestFillDiagonalOffset
.
rng
,
)
)
utt
.
verify_grad
(
utt
.
verify_grad
(
fill_diagonal_with_fix_offset
,
fill_diagonal_with_fix_offset
,
[
np
.
random
.
rand
(
8
,
5
),
np
.
random
.
rand
()],
[
np
.
random
.
rand
om
((
8
,
5
)),
np
.
random
.
random
()],
n_tests
=
1
,
n_tests
=
1
,
rng
=
TestFillDiagonalOffset
.
rng
,
rng
=
TestFillDiagonalOffset
.
rng
,
)
)
utt
.
verify_grad
(
utt
.
verify_grad
(
fill_diagonal_with_fix_offset
,
fill_diagonal_with_fix_offset
,
[
np
.
random
.
rand
(
5
,
5
),
np
.
random
.
rand
()],
[
np
.
random
.
rand
om
((
5
,
5
)),
np
.
random
.
random
()],
n_tests
=
1
,
n_tests
=
1
,
rng
=
TestFillDiagonalOffset
.
rng
,
rng
=
TestFillDiagonalOffset
.
rng
,
)
)
...
@@ -722,13 +722,13 @@ class TestFillDiagonalOffset(utt.InferShapeTester):
...
@@ -722,13 +722,13 @@ class TestFillDiagonalOffset(utt.InferShapeTester):
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
x
,
y
,
z
],
[
x
,
y
,
z
],
[
self
.
op
(
x
,
y
,
z
)],
[
self
.
op
(
x
,
y
,
z
)],
[
np
.
random
.
rand
(
8
,
5
),
np
.
random
.
rand
(),
test_offset
],
[
np
.
random
.
rand
om
((
8
,
5
)),
np
.
random
.
random
(),
test_offset
],
self
.
op_class
,
self
.
op_class
,
)
)
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
x
,
y
,
z
],
[
x
,
y
,
z
],
[
self
.
op
(
x
,
y
,
z
)],
[
self
.
op
(
x
,
y
,
z
)],
[
np
.
random
.
rand
(
5
,
8
),
np
.
random
.
rand
(),
test_offset
],
[
np
.
random
.
rand
om
((
5
,
8
)),
np
.
random
.
random
(),
test_offset
],
self
.
op_class
,
self
.
op_class
,
)
)
...
@@ -1096,7 +1096,7 @@ def test_broadcast_shape():
...
@@ -1096,7 +1096,7 @@ def test_broadcast_shape():
class
TestBroadcastTo
(
utt
.
InferShapeTester
):
class
TestBroadcastTo
(
utt
.
InferShapeTester
):
rng
=
np
.
random
.
RandomState
(
43
)
rng
=
np
.
random
.
default_rng
(
43
)
def
setup_method
(
self
):
def
setup_method
(
self
):
super
()
.
setup_method
()
super
()
.
setup_method
()
...
@@ -1134,7 +1134,7 @@ class TestBroadcastTo(utt.InferShapeTester):
...
@@ -1134,7 +1134,7 @@ class TestBroadcastTo(utt.InferShapeTester):
def
test_gradient
(
self
,
fn
,
input_dims
):
def
test_gradient
(
self
,
fn
,
input_dims
):
utt
.
verify_grad
(
utt
.
verify_grad
(
fn
,
fn
,
[
np
.
random
.
rand
(
*
input_dims
)
.
astype
(
config
.
floatX
)],
[
np
.
random
.
rand
om
(
input_dims
)
.
astype
(
config
.
floatX
)],
n_tests
=
1
,
n_tests
=
1
,
rng
=
self
.
rng
,
rng
=
self
.
rng
,
)
)
...
@@ -1147,7 +1147,7 @@ class TestBroadcastTo(utt.InferShapeTester):
...
@@ -1147,7 +1147,7 @@ class TestBroadcastTo(utt.InferShapeTester):
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
a
]
+
shape
,
[
a
]
+
shape
,
[
out
],
[
out
],
[
np
.
random
.
rand
(
2
,
1
,
3
)
.
astype
(
config
.
floatX
),
2
,
1
,
3
],
[
np
.
random
.
rand
om
((
2
,
1
,
3
)
)
.
astype
(
config
.
floatX
),
2
,
1
,
3
],
self
.
op_class
,
self
.
op_class
,
)
)
...
@@ -1156,7 +1156,7 @@ class TestBroadcastTo(utt.InferShapeTester):
...
@@ -1156,7 +1156,7 @@ class TestBroadcastTo(utt.InferShapeTester):
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
a
]
+
shape
,
[
a
]
+
shape
,
[
self
.
op
(
a
,
shape
)],
[
self
.
op
(
a
,
shape
)],
[
np
.
random
.
rand
(
2
,
1
,
3
)
.
astype
(
config
.
floatX
),
6
,
2
,
5
,
3
],
[
np
.
random
.
rand
om
((
2
,
1
,
3
)
)
.
astype
(
config
.
floatX
),
6
,
2
,
5
,
3
],
self
.
op_class
,
self
.
op_class
,
)
)
...
...
tests/tensor/test_fourier.py
浏览文件 @
1ff4b9d3
...
@@ -9,7 +9,7 @@ from tests import unittest_tools as utt
...
@@ -9,7 +9,7 @@ from tests import unittest_tools as utt
class
TestFourier
(
utt
.
InferShapeTester
):
class
TestFourier
(
utt
.
InferShapeTester
):
rng
=
np
.
random
.
RandomState
(
43
)
rng
=
np
.
random
.
default_rng
(
43
)
def
setup_method
(
self
):
def
setup_method
(
self
):
super
()
.
setup_method
()
super
()
.
setup_method
()
...
@@ -19,13 +19,13 @@ class TestFourier(utt.InferShapeTester):
...
@@ -19,13 +19,13 @@ class TestFourier(utt.InferShapeTester):
def
test_perform
(
self
):
def
test_perform
(
self
):
a
=
dmatrix
()
a
=
dmatrix
()
f
=
aesara
.
function
([
a
],
self
.
op
(
a
,
n
=
10
,
axis
=
0
))
f
=
aesara
.
function
([
a
],
self
.
op
(
a
,
n
=
10
,
axis
=
0
))
a
=
np
.
random
.
rand
(
8
,
6
)
a
=
np
.
random
.
rand
om
((
8
,
6
)
)
assert
np
.
allclose
(
f
(
a
),
np
.
fft
.
fft
(
a
,
10
,
0
))
assert
np
.
allclose
(
f
(
a
),
np
.
fft
.
fft
(
a
,
10
,
0
))
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
a
=
dvector
()
a
=
dvector
()
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
a
],
[
self
.
op
(
a
,
16
,
0
)],
[
np
.
random
.
rand
(
12
)],
self
.
op_class
[
a
],
[
self
.
op
(
a
,
16
,
0
)],
[
np
.
random
.
rand
om
((
12
)
)],
self
.
op_class
)
)
a
=
dmatrix
()
a
=
dmatrix
()
for
var
in
[
for
var
in
[
...
@@ -34,7 +34,9 @@ class TestFourier(utt.InferShapeTester):
...
@@ -34,7 +34,9 @@ class TestFourier(utt.InferShapeTester):
self
.
op
(
a
,
16
,
None
),
self
.
op
(
a
,
16
,
None
),
self
.
op
(
a
,
None
,
None
),
self
.
op
(
a
,
None
,
None
),
]:
]:
self
.
_compile_and_check
([
a
],
[
var
],
[
np
.
random
.
rand
(
12
,
4
)],
self
.
op_class
)
self
.
_compile_and_check
(
[
a
],
[
var
],
[
np
.
random
.
random
((
12
,
4
))],
self
.
op_class
)
b
=
iscalar
()
b
=
iscalar
()
for
var
in
[
self
.
op
(
a
,
16
,
b
),
self
.
op
(
a
,
None
,
b
)]:
for
var
in
[
self
.
op
(
a
,
16
,
b
),
self
.
op
(
a
,
None
,
b
)]:
self
.
_compile_and_check
(
self
.
_compile_and_check
(
...
@@ -56,10 +58,10 @@ class TestFourier(utt.InferShapeTester):
...
@@ -56,10 +58,10 @@ class TestFourier(utt.InferShapeTester):
return
self
.
op
(
a
,
4
,
0
)
return
self
.
op
(
a
,
4
,
0
)
pts
=
[
pts
=
[
np
.
random
.
rand
(
5
,
2
,
4
,
3
),
np
.
random
.
rand
om
((
5
,
2
,
4
,
3
)
),
np
.
random
.
rand
(
2
,
3
,
4
),
np
.
random
.
rand
om
((
2
,
3
,
4
)
),
np
.
random
.
rand
(
2
,
5
),
np
.
random
.
rand
om
((
2
,
5
)
),
np
.
random
.
rand
(
5
),
np
.
random
.
rand
om
((
5
)
),
]
]
for
fft_test
in
[
fft_test1
,
fft_test2
,
fft_test3
,
fft_test4
]:
for
fft_test
in
[
fft_test1
,
fft_test2
,
fft_test3
,
fft_test4
]:
for
pt
in
pts
:
for
pt
in
pts
:
...
...
tests/tensor/test_math.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/test_math_opt.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/test_math_scipy.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/test_mlp.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/test_nlinalg.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/test_opt_uncanonicalize.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/test_shape.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/test_sharedvar.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/test_slinalg.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/test_sort.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/test_subtensor.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/test_xlogx.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
tests/tensor/utils.py
浏览文件 @
1ff4b9d3
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论