Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
dfd047ef
提交
dfd047ef
authored
1月 01, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
1月 13, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Stop using a shared RNG state for test data generation
上级
1d28ac59
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
637 行增加
和
459 行删除
+637
-459
test_blas.py
tests/tensor/test_blas.py
+252
-210
test_math.py
tests/tensor/test_math.py
+161
-99
test_math_scipy.py
tests/tensor/test_math_scipy.py
+49
-32
utils.py
tests/tensor/utils.py
+175
-118
没有找到文件。
tests/tensor/test_blas.py
浏览文件 @
dfd047ef
...
@@ -126,10 +126,6 @@ class TestGemm:
...
@@ -126,10 +126,6 @@ class TestGemm:
assert
b
.
shape
==
()
assert
b
.
shape
==
()
return
b
*
z
+
a
*
np
.
dot
(
x
,
y
)
return
b
*
z
+
a
*
np
.
dot
(
x
,
y
)
@staticmethod
def
random
(
*
args
):
return
np
.
random
.
random
(
args
)
def
cmp
(
self
,
z_
,
a_
,
x_
,
y_
,
b_
):
def
cmp
(
self
,
z_
,
a_
,
x_
,
y_
,
b_
):
for
dtype
in
[
"float32"
,
"float64"
,
"complex64"
,
"complex128"
]:
for
dtype
in
[
"float32"
,
"float64"
,
"complex64"
,
"complex128"
]:
z
=
np
.
asarray
(
z_
,
dtype
=
dtype
)
z
=
np
.
asarray
(
z_
,
dtype
=
dtype
)
...
@@ -184,38 +180,48 @@ class TestGemm:
...
@@ -184,38 +180,48 @@ class TestGemm:
self
.
cmp
(
2.0
,
1.0
,
[
3
,
2
,
1.0
],
[[
1
],
[
2
],
[
3.0
]],
1.0
)
self
.
cmp
(
2.0
,
1.0
,
[
3
,
2
,
1.0
],
[[
1
],
[
2
],
[
3.0
]],
1.0
)
def
test_basic_4
(
self
):
def
test_basic_4
(
self
):
self
.
cmp
(
self
.
random
(
3
,
4
),
1.0
,
self
.
random
(
3
,
5
),
self
.
random
(
5
,
4
),
0.0
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
self
.
cmp
(
rng
.
random
((
3
,
4
)),
1.0
,
rng
.
random
((
3
,
5
)),
rng
.
random
((
5
,
4
)),
0.0
)
def
test_basic_5
(
self
):
def
test_basic_5
(
self
):
self
.
cmp
(
self
.
random
(
3
,
4
),
1.0
,
self
.
random
(
3
,
5
),
self
.
random
(
5
,
4
),
1.0
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
self
.
cmp
(
rng
.
random
((
3
,
4
)),
1.0
,
rng
.
random
((
3
,
5
)),
rng
.
random
((
5
,
4
)),
1.0
)
def
test_basic_6
(
self
):
def
test_basic_6
(
self
):
self
.
cmp
(
self
.
random
(
3
,
4
),
1.0
,
self
.
random
(
3
,
5
),
self
.
random
(
5
,
4
),
-
1.0
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
self
.
cmp
(
rng
.
random
((
3
,
4
)),
1.0
,
rng
.
random
((
3
,
5
)),
rng
.
random
((
5
,
4
)),
-
1.0
)
def
test_basic_7
(
self
):
def
test_basic_7
(
self
):
self
.
cmp
(
self
.
random
(
3
,
4
),
0.0
,
self
.
random
(
3
,
5
),
self
.
random
(
5
,
4
),
0.0
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
self
.
cmp
(
rng
.
random
((
3
,
4
)),
0.0
,
rng
.
random
((
3
,
5
)),
rng
.
random
((
5
,
4
)),
0.0
)
def
test_basic_8
(
self
):
def
test_basic_8
(
self
):
self
.
cmp
(
self
.
random
(
3
,
4
),
0.0
,
self
.
random
(
3
,
5
),
self
.
random
(
5
,
4
),
0.6
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
self
.
cmp
(
rng
.
random
((
3
,
4
)),
0.0
,
rng
.
random
((
3
,
5
)),
rng
.
random
((
5
,
4
)),
0.6
)
def
test_basic_9
(
self
):
def
test_basic_9
(
self
):
self
.
cmp
(
self
.
random
(
3
,
4
),
0.0
,
self
.
random
(
3
,
5
),
self
.
random
(
5
,
4
),
-
1.0
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
self
.
cmp
(
rng
.
random
((
3
,
4
)),
0.0
,
rng
.
random
((
3
,
5
)),
rng
.
random
((
5
,
4
)),
-
1.0
)
def
test_basic_10
(
self
):
def
test_basic_10
(
self
):
self
.
cmp
(
self
.
random
(
3
,
4
),
-
1.0
,
self
.
random
(
3
,
5
),
self
.
random
(
5
,
4
),
0.0
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
self
.
cmp
(
rng
.
random
((
3
,
4
)),
-
1.0
,
rng
.
random
((
3
,
5
)),
rng
.
random
((
5
,
4
)),
0.0
)
def
test_basic_11
(
self
):
def
test_basic_11
(
self
):
self
.
cmp
(
self
.
random
(
3
,
4
),
-
1.0
,
self
.
random
(
3
,
5
),
self
.
random
(
5
,
4
),
1.0
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
self
.
cmp
(
rng
.
random
((
3
,
4
)),
-
1.0
,
rng
.
random
((
3
,
5
)),
rng
.
random
((
5
,
4
)),
1.0
)
def
test_basic_12
(
self
):
def
test_basic_12
(
self
):
self
.
cmp
(
self
.
random
(
3
,
4
),
-
1.0
,
self
.
random
(
3
,
5
),
self
.
random
(
5
,
4
),
-
1.0
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
self
.
cmp
(
rng
.
random
((
3
,
4
)),
-
1.0
,
rng
.
random
((
3
,
5
)),
rng
.
random
((
5
,
4
)),
-
1.0
)
def
test_shape_0
(
self
):
def
test_shape_0
(
self
):
self
.
cmp
(
self
.
random
(
0
,
4
),
-
1.0
,
self
.
random
(
0
,
5
),
self
.
random
(
5
,
4
),
-
1.0
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
self
.
cmp
(
self
.
random
(
3
,
0
),
-
1.0
,
self
.
random
(
3
,
5
),
self
.
random
(
5
,
0
),
-
1.0
)
self
.
cmp
(
rng
.
random
((
0
,
4
)),
-
1.0
,
rng
.
random
((
0
,
5
)),
rng
.
random
((
5
,
4
)),
-
1.0
)
self
.
cmp
(
self
.
random
(
3
,
4
),
-
1.0
,
self
.
random
(
3
,
0
),
self
.
random
(
0
,
4
),
-
1.0
)
self
.
cmp
(
rng
.
random
((
3
,
0
)),
-
1.0
,
rng
.
random
((
3
,
5
)),
rng
.
random
((
5
,
0
)),
-
1.0
)
self
.
cmp
(
self
.
random
(
0
,
0
),
-
1.0
,
self
.
random
(
0
,
5
),
self
.
random
(
5
,
0
),
-
1.0
)
self
.
cmp
(
rng
.
random
((
3
,
4
)),
-
1.0
,
rng
.
random
((
3
,
0
)),
rng
.
random
((
0
,
4
)),
-
1.0
)
self
.
cmp
(
self
.
random
(
0
,
0
),
-
1.0
,
self
.
random
(
0
,
0
),
self
.
random
(
0
,
0
),
-
1.0
)
self
.
cmp
(
rng
.
random
((
0
,
0
)),
-
1.0
,
rng
.
random
((
0
,
5
)),
rng
.
random
((
5
,
0
)),
-
1.0
)
self
.
cmp
(
rng
.
random
((
0
,
0
)),
-
1.0
,
rng
.
random
((
0
,
0
)),
rng
.
random
((
0
,
0
)),
-
1.0
)
def
test_factorised_scalar
(
self
):
def
test_factorised_scalar
(
self
):
a
=
matrix
()
a
=
matrix
()
...
@@ -264,46 +270,54 @@ class TestGemm:
...
@@ -264,46 +270,54 @@ class TestGemm:
def
test_destroy_map0
(
self
):
def
test_destroy_map0
(
self
):
# test that only first input can be overwritten.
# test that only first input can be overwritten.
Z
=
as_tensor_variable
(
self
.
random
(
2
,
2
))
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
Z
=
as_tensor_variable
(
rng
.
random
((
2
,
2
)))
with
pytest
.
raises
(
InconsistencyError
,
match
=
Gemm
.
E_z_uniq
):
with
pytest
.
raises
(
InconsistencyError
,
match
=
Gemm
.
E_z_uniq
):
gemm_inplace
(
Z
,
1.0
,
Z
,
Z
,
1.0
)
gemm_inplace
(
Z
,
1.0
,
Z
,
Z
,
1.0
)
def
test_destroy_map1
(
self
):
def
test_destroy_map1
(
self
):
# test that only first input can be overwritten.
# test that only first input can be overwritten.
Z
=
as_tensor_variable
(
self
.
random
(
2
,
2
))
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
A
=
as_tensor_variable
(
self
.
random
(
2
,
2
))
Z
=
as_tensor_variable
(
rng
.
random
((
2
,
2
)))
A
=
as_tensor_variable
(
rng
.
random
((
2
,
2
)))
with
pytest
.
raises
(
InconsistencyError
,
match
=
Gemm
.
E_z_uniq
):
with
pytest
.
raises
(
InconsistencyError
,
match
=
Gemm
.
E_z_uniq
):
gemm_inplace
(
Z
,
1.0
,
A
,
inplace
.
transpose_inplace
(
Z
),
1.0
)
gemm_inplace
(
Z
,
1.0
,
A
,
inplace
.
transpose_inplace
(
Z
),
1.0
)
def
test_destroy_map2
(
self
):
def
test_destroy_map2
(
self
):
# test that only first input can be overwritten.
# test that only first input can be overwritten.
Z
=
as_tensor_variable
(
self
.
random
(
2
,
2
))
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
A
=
as_tensor_variable
(
self
.
random
(
2
,
2
))
Z
=
as_tensor_variable
(
rng
.
random
((
2
,
2
)))
A
=
as_tensor_variable
(
rng
.
random
((
2
,
2
)))
with
pytest
.
raises
(
InconsistencyError
,
match
=
Gemm
.
E_z_uniq
):
with
pytest
.
raises
(
InconsistencyError
,
match
=
Gemm
.
E_z_uniq
):
gemm_inplace
(
Z
,
1.0
,
inplace
.
transpose_inplace
(
Z
),
A
,
1.0
)
gemm_inplace
(
Z
,
1.0
,
inplace
.
transpose_inplace
(
Z
),
A
,
1.0
)
def
test_destroy_map3
(
self
):
def
test_destroy_map3
(
self
):
# test that only first input can be overwritten
# test that only first input can be overwritten
Z
=
as_tensor_variable
(
self
.
random
(
2
,
2
))
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
A
=
as_tensor_variable
(
self
.
random
(
2
,
2
))
Z
=
as_tensor_variable
(
rng
.
random
((
2
,
2
)))
A
=
as_tensor_variable
(
rng
.
random
((
2
,
2
)))
with
pytest
.
raises
(
InconsistencyError
,
match
=
Gemm
.
E_z_uniq
):
with
pytest
.
raises
(
InconsistencyError
,
match
=
Gemm
.
E_z_uniq
):
gemm_inplace
(
Z
,
1.0
,
Z
,
A
,
1.0
)
gemm_inplace
(
Z
,
1.0
,
Z
,
A
,
1.0
)
def
test_destroy_map4
(
self
):
def
test_destroy_map4
(
self
):
# test that dot args can be aliased
# test that dot args can be aliased
Z
=
shared
(
self
.
random
(
2
,
2
),
name
=
"Z"
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
A
=
shared
(
self
.
random
(
2
,
2
),
name
=
"A"
)
Z
=
shared
(
rng
.
random
((
2
,
2
)),
name
=
"Z"
)
A
=
shared
(
rng
.
random
((
2
,
2
)),
name
=
"A"
)
one
=
at
.
constant
(
1.0
)
.
astype
(
Z
.
dtype
)
one
=
at
.
constant
(
1.0
)
.
astype
(
Z
.
dtype
)
f
=
inplace_func
([],
gemm_inplace
(
Z
,
one
,
A
,
A
,
one
))
f
=
inplace_func
([],
gemm_inplace
(
Z
,
one
,
A
,
A
,
one
))
# TODO FIXME: This is a bad test
f
()
f
()
f
=
inplace_func
([],
gemm_inplace
(
Z
,
one
,
A
,
A
.
T
,
one
))
f
=
inplace_func
([],
gemm_inplace
(
Z
,
one
,
A
,
A
.
T
,
one
))
# TODO FIXME: This is a bad test
f
()
f
()
def
test_transposes
(
self
):
def
test_transposes
(
self
):
# three square matrices which are not contiguous
# three square matrices which are not contiguous
A
=
self
.
random
(
4
,
5
)[:,
:
4
]
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
B
=
self
.
random
(
4
,
5
)[:,
:
4
]
A
=
rng
.
random
((
4
,
5
))[:,
:
4
]
C
=
self
.
random
(
4
,
5
)[:,
:
4
]
B
=
rng
.
random
((
4
,
5
))[:,
:
4
]
C
=
rng
.
random
((
4
,
5
))[:,
:
4
]
def
t
(
z
,
x
,
y
,
a
=
1.0
,
b
=
0.0
,
l
=
"c|py"
,
dt
=
"float64"
):
def
t
(
z
,
x
,
y
,
a
=
1.0
,
b
=
0.0
,
l
=
"c|py"
,
dt
=
"float64"
):
z
,
a
,
x
,
y
,
b
=
[
_asarray
(
p
,
dtype
=
dt
)
for
p
in
(
z
,
a
,
x
,
y
,
b
)]
z
,
a
,
x
,
y
,
b
=
[
_asarray
(
p
,
dtype
=
dt
)
for
p
in
(
z
,
a
,
x
,
y
,
b
)]
...
@@ -359,9 +373,10 @@ class TestGemm:
...
@@ -359,9 +373,10 @@ class TestGemm:
def
test_non_contiguous
(
self
):
def
test_non_contiguous
(
self
):
# Like test_transposes but with matrices without any
# Like test_transposes but with matrices without any
# continuous dimension
# continuous dimension
A
=
self
.
random
(
4
,
4
,
3
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
B
=
self
.
random
(
4
,
4
,
3
)
A
=
rng
.
random
((
4
,
4
,
3
))
C
=
self
.
random
(
4
,
4
,
3
)
B
=
rng
.
random
((
4
,
4
,
3
))
C
=
rng
.
random
((
4
,
4
,
3
))
def
t
(
z
,
x
,
y
,
a
=
1.0
,
b
=
0.0
,
l
=
"c|py"
,
dt
=
"float64"
):
def
t
(
z
,
x
,
y
,
a
=
1.0
,
b
=
0.0
,
l
=
"c|py"
,
dt
=
"float64"
):
z
,
a
,
x
,
y
,
b
=
[
_asarray
(
p
,
dtype
=
dt
)
for
p
in
(
z
,
a
,
x
,
y
,
b
)]
z
,
a
,
x
,
y
,
b
=
[
_asarray
(
p
,
dtype
=
dt
)
for
p
in
(
z
,
a
,
x
,
y
,
b
)]
...
@@ -453,7 +468,7 @@ class TestGemmNoFlags:
...
@@ -453,7 +468,7 @@ class TestGemmNoFlags:
return
function
([
alpha
,
A
,
B
,
beta
,
C
],
self
.
gemm
(
C1
,
alpha
,
A1
,
B1
,
beta
))
return
function
([
alpha
,
A
,
B
,
beta
,
C
],
self
.
gemm
(
C1
,
alpha
,
A1
,
B1
,
beta
))
def
generate_value
(
self
,
dtype
,
width
,
height
,
to_transpose
,
to_slice
):
def
generate_value
(
self
,
dtype
,
width
,
height
,
to_transpose
,
to_slice
,
rng
):
if
to_slice
:
if
to_slice
:
if
to_transpose
:
if
to_transpose
:
shape
=
(
height
,
width
*
self
.
slice_step
)
shape
=
(
height
,
width
*
self
.
slice_step
)
...
@@ -464,10 +479,11 @@ class TestGemmNoFlags:
...
@@ -464,10 +479,11 @@ class TestGemmNoFlags:
shape
=
(
height
,
width
)
shape
=
(
height
,
width
)
else
:
else
:
shape
=
(
width
,
height
)
shape
=
(
width
,
height
)
return
np
.
random
.
random
(
shape
)
.
astype
(
dtype
)
return
rng
.
random
(
shape
)
.
astype
(
dtype
)
def
get_data
(
def
get_data
(
self
,
self
,
rng
,
dtype
,
dtype
,
alpha
,
alpha
,
beta
,
beta
,
...
@@ -478,9 +494,9 @@ class TestGemmNoFlags:
...
@@ -478,9 +494,9 @@ class TestGemmNoFlags:
slice_B
=
False
,
slice_B
=
False
,
slice_C
=
False
,
slice_C
=
False
,
):
):
A
=
self
.
generate_value
(
dtype
,
self
.
M
,
self
.
N
,
transpose_A
,
slice_A
)
A
=
self
.
generate_value
(
dtype
,
self
.
M
,
self
.
N
,
transpose_A
,
slice_A
,
rng
)
B
=
self
.
generate_value
(
dtype
,
self
.
N
,
self
.
K
,
transpose_B
,
slice_B
)
B
=
self
.
generate_value
(
dtype
,
self
.
N
,
self
.
K
,
transpose_B
,
slice_B
,
rng
)
C
=
self
.
generate_value
(
dtype
,
self
.
M
,
self
.
K
,
transpose_C
,
slice_C
)
C
=
self
.
generate_value
(
dtype
,
self
.
M
,
self
.
K
,
transpose_C
,
slice_C
,
rng
)
return
(
alpha
,
A
,
B
,
beta
,
C
)
return
(
alpha
,
A
,
B
,
beta
,
C
)
def
get_value
(
self
,
V
,
to_transpose
,
to_slice
):
def
get_value
(
self
,
V
,
to_transpose
,
to_slice
):
...
@@ -521,11 +537,13 @@ class TestGemmNoFlags:
...
@@ -521,11 +537,13 @@ class TestGemmNoFlags:
slice_A
,
slice_A
,
slice_B
,
slice_B
,
slice_C
,
slice_C
,
rng
,
):
):
f
=
self
.
get_function
(
f
=
self
.
get_function
(
dtype
,
transpose_A
,
transpose_B
,
transpose_C
,
slice_A
,
slice_B
,
slice_C
dtype
,
transpose_A
,
transpose_B
,
transpose_C
,
slice_A
,
slice_B
,
slice_C
)
)
values
=
self
.
get_data
(
values
=
self
.
get_data
(
rng
,
dtype
,
dtype
,
ALPHA
,
ALPHA
,
BETA
,
BETA
,
...
@@ -549,13 +567,14 @@ class TestGemmNoFlags:
...
@@ -549,13 +567,14 @@ class TestGemmNoFlags:
unittest_tools
.
assert_allclose
(
ref_val
,
z_val
)
unittest_tools
.
assert_allclose
(
ref_val
,
z_val
)
def
test_gemm
(
self
):
def
test_gemm
(
self
):
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
dtypes
=
(
"float32"
,
"float64"
)
dtypes
=
(
"float32"
,
"float64"
)
scalars
=
(
0
,
1
,
-
2
)
scalars
=
(
0
,
1
,
-
2
)
booleans
=
(
False
,
True
)
booleans
=
(
False
,
True
)
# dtype, alpha, beta, transA, transB, transC, sliceA, sliceB, sliceC
# dtype, alpha, beta, transA, transB, transC, sliceA, sliceB, sliceC
iterables
=
[
dtypes
]
+
([
scalars
]
*
2
)
+
([
booleans
]
*
6
)
iterables
=
[
dtypes
]
+
([
scalars
]
*
2
)
+
([
booleans
]
*
6
)
for
dtype
,
alpha
,
beta
,
tA
,
tB
,
tC
,
sA
,
sB
,
sC
in
product
(
*
iterables
):
for
dtype
,
alpha
,
beta
,
tA
,
tB
,
tC
,
sA
,
sB
,
sC
in
product
(
*
iterables
):
self
.
run_gemm
(
dtype
,
alpha
,
beta
,
tA
,
tB
,
tC
,
sA
,
sB
,
sC
)
self
.
run_gemm
(
dtype
,
alpha
,
beta
,
tA
,
tB
,
tC
,
sA
,
sB
,
sC
,
rng
)
def
test_res_is_a
():
def
test_res_is_a
():
...
@@ -1006,6 +1025,7 @@ def test_gemm_unrolled():
...
@@ -1006,6 +1025,7 @@ def test_gemm_unrolled():
# So the final graph should have 1 + 2* num_rounds dot variant op.
# So the final graph should have 1 + 2* num_rounds dot variant op.
assert
nb_dot
==
num_rounds
*
2
+
1
,
nb_dot
assert
nb_dot
==
num_rounds
*
2
+
1
,
nb_dot
# TODO FIXME: This is a bad test
unrolled_aesara
()
unrolled_aesara
()
...
@@ -1060,6 +1080,7 @@ def test_dot22():
...
@@ -1060,6 +1080,7 @@ def test_dot22():
def
cmp
(
a_shp
,
b_shp
):
def
cmp
(
a_shp
,
b_shp
):
av
=
rng
.
uniform
(
size
=
a_shp
)
.
astype
(
dtype1
)
av
=
rng
.
uniform
(
size
=
a_shp
)
.
astype
(
dtype1
)
bv
=
rng
.
uniform
(
size
=
b_shp
)
.
astype
(
dtype2
)
bv
=
rng
.
uniform
(
size
=
b_shp
)
.
astype
(
dtype2
)
# TODO FIXME: This is a bad test
f
(
av
,
bv
)
f
(
av
,
bv
)
cmp
((
3
,
4
),
(
4
,
5
))
cmp
((
3
,
4
),
(
4
,
5
))
...
@@ -1260,6 +1281,7 @@ def test_local_dot22_to_dot22scalar():
...
@@ -1260,6 +1281,7 @@ def test_local_dot22_to_dot22scalar():
node2
=
local_dot22_to_dot22scalar
.
transform
(
None
,
node
.
owner
)
node2
=
local_dot22_to_dot22scalar
.
transform
(
None
,
node
.
owner
)
assert
node2
assert
node2
f
=
function
([
x
,
y
,
z
,
m
,
r
,
A
],
node
,
mode
=
mode
,
on_unused_input
=
"ignore"
)
f
=
function
([
x
,
y
,
z
,
m
,
r
,
A
],
node
,
mode
=
mode
,
on_unused_input
=
"ignore"
)
# TODO FIXME: This is a bad test
f
(
0.1
,
0.2
,
0.3
,
[[
1
,
2
],
[
3
,
4
]],
[[
5
,
6
]],
[[
7
,
8
],
[
9
,
10
]])
f
(
0.1
,
0.2
,
0.3
,
[[
1
,
2
],
[
3
,
4
]],
[[
5
,
6
]],
[[
7
,
8
],
[
9
,
10
]])
...
@@ -1275,8 +1297,8 @@ def test_dot_w_self():
...
@@ -1275,8 +1297,8 @@ def test_dot_w_self():
grad_res
=
grad
(
mean
(
p
),
A
)
grad_res
=
grad
(
mean
(
p
),
A
)
f
=
function
([
B
],
p
,
updates
=
[(
A
,
A
-
grad_res
)])
f
=
function
([
B
],
p
,
updates
=
[(
A
,
A
-
grad_res
)])
# tests correctness in debugmode
# tests correctness in debugmode
# TODO FIXME: This is a bad test
f
(
np
.
asarray
([[
0
,
1
],
[
2
,
3
]],
dtype
=
config
.
floatX
))
f
(
np
.
asarray
([[
0
,
1
],
[
2
,
3
]],
dtype
=
config
.
floatX
))
...
@@ -1707,6 +1729,7 @@ class BaseGemv:
...
@@ -1707,6 +1729,7 @@ class BaseGemv:
assert
node
.
outputs
[
0
]
.
dtype
==
"float32"
assert
node
.
outputs
[
0
]
.
dtype
==
"float32"
assert
n_gemvs
==
1
,
n_gemvs
assert
n_gemvs
==
1
,
n_gemvs
self
.
assertFunctionContains1
(
f
,
self
.
gemv_inplace
)
self
.
assertFunctionContains1
(
f
,
self
.
gemv_inplace
)
# TODO FIXME: This is a bad test
f
(
alpha_v
)
f
(
alpha_v
)
...
@@ -1893,47 +1916,51 @@ class TestGer(unittest_tools.OptimizationTestMixin):
...
@@ -1893,47 +1916,51 @@ class TestGer(unittest_tools.OptimizationTestMixin):
)
)
def
test_outer
(
self
):
def
test_outer
(
self
):
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
f
=
self
.
function
([
self
.
x
,
self
.
y
],
outer
(
self
.
x
,
self
.
y
))
f
=
self
.
function
([
self
.
x
,
self
.
y
],
outer
(
self
.
x
,
self
.
y
))
self
.
assertFunctionContains
(
f
,
self
.
ger_destructive
)
self
.
assertFunctionContains
(
f
,
self
.
ger_destructive
)
# TODO FIXME: This is NOT a test.
# TODO FIXME: This is NOT a test.
f
(
f
(
np
.
random
.
random
((
5
))
.
astype
(
self
.
dtype
),
rng
.
random
((
5
))
.
astype
(
self
.
dtype
),
np
.
random
.
random
((
4
))
.
astype
(
self
.
dtype
),
rng
.
random
((
4
))
.
astype
(
self
.
dtype
),
)
)
def
test_A_plus_outer
(
self
):
def
test_A_plus_outer
(
self
):
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
f
=
self
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
self
.
A
+
outer
(
self
.
x
,
self
.
y
))
f
=
self
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
self
.
A
+
outer
(
self
.
x
,
self
.
y
))
self
.
assertFunctionContains
(
f
,
self
.
ger
)
self
.
assertFunctionContains
(
f
,
self
.
ger
)
# TODO FIXME: This is NOT a test.
# TODO FIXME: This is NOT a test.
f
(
f
(
np
.
random
.
random
((
5
,
4
))
.
astype
(
self
.
dtype
),
rng
.
random
((
5
,
4
))
.
astype
(
self
.
dtype
),
np
.
random
.
random
((
5
))
.
astype
(
self
.
dtype
),
rng
.
random
((
5
))
.
astype
(
self
.
dtype
),
np
.
random
.
random
((
4
))
.
astype
(
self
.
dtype
),
rng
.
random
((
4
))
.
astype
(
self
.
dtype
),
)
)
f
(
f
(
np
.
random
.
random
((
5
,
4
))
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
rng
.
random
((
5
,
4
))
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
np
.
random
.
random
((
5
))
.
astype
(
self
.
dtype
),
rng
.
random
((
5
))
.
astype
(
self
.
dtype
),
np
.
random
.
random
((
4
))
.
astype
(
self
.
dtype
),
rng
.
random
((
4
))
.
astype
(
self
.
dtype
),
)
)
def
test_A_plus_scaled_outer
(
self
):
def
test_A_plus_scaled_outer
(
self
):
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
f
=
self
.
function
(
f
=
self
.
function
(
[
self
.
A
,
self
.
x
,
self
.
y
],
self
.
A
+
0.1
*
outer
(
self
.
x
,
self
.
y
)
[
self
.
A
,
self
.
x
,
self
.
y
],
self
.
A
+
0.1
*
outer
(
self
.
x
,
self
.
y
)
)
)
self
.
assertFunctionContains
(
f
,
self
.
ger
)
self
.
assertFunctionContains
(
f
,
self
.
ger
)
# TODO FIXME: This is NOT a test.
# TODO FIXME: This is NOT a test.
f
(
f
(
np
.
random
.
random
((
5
,
4
))
.
astype
(
self
.
dtype
),
rng
.
random
((
5
,
4
))
.
astype
(
self
.
dtype
),
np
.
random
.
random
((
5
))
.
astype
(
self
.
dtype
),
rng
.
random
((
5
))
.
astype
(
self
.
dtype
),
np
.
random
.
random
((
4
))
.
astype
(
self
.
dtype
),
rng
.
random
((
4
))
.
astype
(
self
.
dtype
),
)
)
f
(
f
(
np
.
random
.
random
((
5
,
4
))
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
rng
.
random
((
5
,
4
))
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
np
.
random
.
random
((
5
))
.
astype
(
self
.
dtype
),
rng
.
random
((
5
))
.
astype
(
self
.
dtype
),
np
.
random
.
random
((
4
))
.
astype
(
self
.
dtype
),
rng
.
random
((
4
))
.
astype
(
self
.
dtype
),
)
)
def
test_scaled_A_plus_scaled_outer
(
self
):
def
test_scaled_A_plus_scaled_outer
(
self
):
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
f
=
self
.
function
(
f
=
self
.
function
(
[
self
.
A
,
self
.
x
,
self
.
y
],
[
self
.
A
,
self
.
x
,
self
.
y
],
np
.
asarray
(
0.2
,
self
.
dtype
)
*
self
.
A
np
.
asarray
(
0.2
,
self
.
dtype
)
*
self
.
A
...
@@ -1944,18 +1971,19 @@ class TestGer(unittest_tools.OptimizationTestMixin):
...
@@ -1944,18 +1971,19 @@ class TestGer(unittest_tools.OptimizationTestMixin):
self
.
assertFunctionContains
(
f
,
self
.
gemm
)
self
.
assertFunctionContains
(
f
,
self
.
gemm
)
# TODO FIXME: This is NOT a test.
# TODO FIXME: This is NOT a test.
f
(
f
(
np
.
random
.
random
((
5
,
4
))
.
astype
(
self
.
dtype
),
rng
.
random
((
5
,
4
))
.
astype
(
self
.
dtype
),
np
.
random
.
random
((
5
))
.
astype
(
self
.
dtype
),
rng
.
random
((
5
))
.
astype
(
self
.
dtype
),
np
.
random
.
random
((
4
))
.
astype
(
self
.
dtype
),
rng
.
random
((
4
))
.
astype
(
self
.
dtype
),
)
)
f
(
f
(
np
.
random
.
random
((
5
,
4
))
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
rng
.
random
((
5
,
4
))
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
np
.
random
.
random
((
5
))
.
astype
(
self
.
dtype
),
rng
.
random
((
5
))
.
astype
(
self
.
dtype
),
np
.
random
.
random
((
4
))
.
astype
(
self
.
dtype
),
rng
.
random
((
4
))
.
astype
(
self
.
dtype
),
)
)
def
given_dtype
(
self
,
dtype
,
M
,
N
):
def
given_dtype
(
self
,
dtype
,
M
,
N
):
# test corner case shape and dtype
# test corner case shape and dtype
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
f
=
self
.
function
(
f
=
self
.
function
(
[
self
.
A
,
self
.
x
,
self
.
y
],
self
.
A
+
0.1
*
outer
(
self
.
x
,
self
.
y
)
[
self
.
A
,
self
.
x
,
self
.
y
],
self
.
A
+
0.1
*
outer
(
self
.
x
,
self
.
y
)
...
@@ -1963,14 +1991,14 @@ class TestGer(unittest_tools.OptimizationTestMixin):
...
@@ -1963,14 +1991,14 @@ class TestGer(unittest_tools.OptimizationTestMixin):
self
.
assertFunctionContains
(
f
,
self
.
ger
)
self
.
assertFunctionContains
(
f
,
self
.
ger
)
# TODO FIXME: This is NOT a test.
# TODO FIXME: This is NOT a test.
f
(
f
(
np
.
random
.
random
((
M
,
N
))
.
astype
(
self
.
dtype
),
rng
.
random
((
M
,
N
))
.
astype
(
self
.
dtype
),
np
.
random
.
random
((
M
))
.
astype
(
self
.
dtype
),
rng
.
random
((
M
))
.
astype
(
self
.
dtype
),
np
.
random
.
random
((
N
))
.
astype
(
self
.
dtype
),
rng
.
random
((
N
))
.
astype
(
self
.
dtype
),
)
)
f
(
f
(
np
.
random
.
random
((
M
,
N
))
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
rng
.
random
((
M
,
N
))
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
np
.
random
.
random
((
M
))
.
astype
(
self
.
dtype
),
rng
.
random
((
M
))
.
astype
(
self
.
dtype
),
np
.
random
.
random
((
N
))
.
astype
(
self
.
dtype
),
rng
.
random
((
N
))
.
astype
(
self
.
dtype
),
)
)
def
test_f32_0_0
(
self
):
def
test_f32_0_0
(
self
):
...
@@ -2004,7 +2032,8 @@ class TestGer(unittest_tools.OptimizationTestMixin):
...
@@ -2004,7 +2032,8 @@ class TestGer(unittest_tools.OptimizationTestMixin):
return
self
.
given_dtype
(
"complex128"
,
1
,
9
)
return
self
.
given_dtype
(
"complex128"
,
1
,
9
)
def
test_inplace
(
self
):
def
test_inplace
(
self
):
A
=
shared
(
np
.
random
.
random
((
4
,
5
))
.
astype
(
self
.
dtype
))
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
A
=
shared
(
rng
.
random
((
4
,
5
))
.
astype
(
self
.
dtype
))
f
=
self
.
function
(
f
=
self
.
function
(
[
self
.
x
,
self
.
y
],
[
self
.
x
,
self
.
y
],
[],
[],
...
@@ -2015,16 +2044,16 @@ class TestGer(unittest_tools.OptimizationTestMixin):
...
@@ -2015,16 +2044,16 @@ class TestGer(unittest_tools.OptimizationTestMixin):
self
.
assertFunctionContains
(
f
,
self
.
ger_destructive
)
self
.
assertFunctionContains
(
f
,
self
.
ger_destructive
)
# TODO FIXME: This is NOT a test.
# TODO FIXME: This is NOT a test.
f
(
f
(
np
.
random
.
random
((
4
))
.
astype
(
self
.
dtype
),
rng
.
random
((
4
))
.
astype
(
self
.
dtype
),
np
.
random
.
random
((
5
))
.
astype
(
self
.
dtype
),
rng
.
random
((
5
))
.
astype
(
self
.
dtype
),
)
)
A
.
set_value
(
A
.
set_value
(
A
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)[::
-
1
,
::
-
1
],
borrow
=
True
A
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)[::
-
1
,
::
-
1
],
borrow
=
True
)
)
f
(
f
(
np
.
random
.
random
((
4
))
.
astype
(
self
.
dtype
),
rng
.
random
((
4
))
.
astype
(
self
.
dtype
),
np
.
random
.
random
((
5
))
.
astype
(
self
.
dtype
),
rng
.
random
((
5
))
.
astype
(
self
.
dtype
),
)
)
...
@@ -2032,15 +2061,14 @@ class TestBlasStrides:
...
@@ -2032,15 +2061,14 @@ class TestBlasStrides:
dtype
=
"float64"
dtype
=
"float64"
mode
=
aesara
.
compile
.
get_default_mode
()
mode
=
aesara
.
compile
.
get_default_mode
()
mode
=
mode
.
including
(
"fast_run"
)
.
excluding
(
"gpu"
,
"c_blas"
,
"scipy_blas"
)
mode
=
mode
.
including
(
"fast_run"
)
.
excluding
(
"gpu"
,
"c_blas"
,
"scipy_blas"
)
rng
=
np
.
random
.
default_rng
(
seed
=
unittest_tools
.
fetch_seed
())
def
random
(
self
,
*
shape
):
def
random
(
self
,
*
shape
,
rng
=
None
):
return
_asarray
(
self
.
rng
.
random
(
shape
),
dtype
=
self
.
dtype
)
return
_asarray
(
rng
.
random
(
shape
),
dtype
=
self
.
dtype
)
def
cmp_dot22
(
self
,
b_shp
,
c_shp
):
def
cmp_dot22
(
self
,
b_shp
,
c_shp
,
rng
):
av
=
np
.
zeros
((
0
,
0
),
dtype
=
self
.
dtype
)
av
=
np
.
zeros
((
0
,
0
),
dtype
=
self
.
dtype
)
bv
=
self
.
random
(
*
b_shp
)
bv
=
self
.
random
(
*
b_shp
,
rng
=
rng
)
cv
=
self
.
random
(
*
c_shp
)
cv
=
self
.
random
(
*
c_shp
,
rng
=
rng
)
a
=
shared
(
av
,
"a"
)
a
=
shared
(
av
,
"a"
)
b
=
shared
(
bv
,
"b"
)
b
=
shared
(
bv
,
"b"
)
...
@@ -2087,24 +2115,25 @@ class TestBlasStrides:
...
@@ -2087,24 +2115,25 @@ class TestBlasStrides:
assert
np
.
allclose
(
a
.
get_value
(),
a_n
)
assert
np
.
allclose
(
a
.
get_value
(),
a_n
)
def
test_dot22
(
self
):
def
test_dot22
(
self
):
self
.
cmp_dot22
((
3
,
4
),
(
4
,
5
))
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
self
.
cmp_dot22
((
1
,
4
),
(
4
,
5
))
self
.
cmp_dot22
((
3
,
4
),
(
4
,
5
),
rng
)
self
.
cmp_dot22
((
3
,
4
),
(
4
,
1
))
self
.
cmp_dot22
((
1
,
4
),
(
4
,
5
),
rng
)
self
.
cmp_dot22
((
3
,
1
),
(
1
,
1
))
self
.
cmp_dot22
((
3
,
4
),
(
4
,
1
),
rng
)
self
.
cmp_dot22
((
1
,
4
),
(
4
,
1
))
self
.
cmp_dot22
((
3
,
1
),
(
1
,
1
),
rng
)
self
.
cmp_dot22
((
3
,
1
),
(
1
,
5
))
self
.
cmp_dot22
((
1
,
4
),
(
4
,
1
),
rng
)
self
.
cmp_dot22
((
0
,
4
),
(
4
,
5
))
self
.
cmp_dot22
((
3
,
1
),
(
1
,
5
),
rng
)
self
.
cmp_dot22
((
0
,
4
),
(
4
,
1
))
self
.
cmp_dot22
((
0
,
4
),
(
4
,
5
),
rng
)
self
.
cmp_dot22
((
0
,
1
),
(
1
,
5
))
self
.
cmp_dot22
((
0
,
4
),
(
4
,
1
),
rng
)
self
.
cmp_dot22
((
3
,
4
),
(
4
,
0
))
self
.
cmp_dot22
((
0
,
1
),
(
1
,
5
),
rng
)
self
.
cmp_dot22
((
3
,
0
),
(
0
,
5
))
self
.
cmp_dot22
((
3
,
4
),
(
4
,
0
),
rng
)
self
.
cmp_dot22
((
0
,
4
),
(
4
,
0
))
self
.
cmp_dot22
((
3
,
0
),
(
0
,
5
),
rng
)
self
.
cmp_dot22
((
0
,
0
),
(
0
,
0
))
self
.
cmp_dot22
((
0
,
4
),
(
4
,
0
),
rng
)
self
.
cmp_dot22
((
0
,
0
),
(
0
,
0
),
rng
)
def
cmp_dot22scalar
(
self
,
b_shp
,
c_shp
):
def
cmp_dot22scalar
(
self
,
b_shp
,
c_shp
,
rng
):
av
=
np
.
zeros
((
0
,
0
),
dtype
=
self
.
dtype
)
av
=
np
.
zeros
((
0
,
0
),
dtype
=
self
.
dtype
)
bv
=
self
.
random
(
*
b_shp
)
bv
=
self
.
random
(
*
b_shp
,
rng
=
rng
)
cv
=
self
.
random
(
*
c_shp
)
cv
=
self
.
random
(
*
c_shp
,
rng
=
rng
)
l
=
np
.
float32
(
0.2
)
l
=
np
.
float32
(
0.2
)
a
=
shared
(
av
,
"a"
)
a
=
shared
(
av
,
"a"
)
...
@@ -2150,24 +2179,25 @@ class TestBlasStrides:
...
@@ -2150,24 +2179,25 @@ class TestBlasStrides:
assert
np
.
allclose
(
a
.
get_value
(),
a_n
)
assert
np
.
allclose
(
a
.
get_value
(),
a_n
)
def
test_dot22scalar
(
self
):
def
test_dot22scalar
(
self
):
self
.
cmp_dot22scalar
((
3
,
4
),
(
4
,
5
))
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
self
.
cmp_dot22scalar
((
1
,
4
),
(
4
,
5
))
self
.
cmp_dot22scalar
((
3
,
4
),
(
4
,
5
),
rng
)
self
.
cmp_dot22scalar
((
3
,
4
),
(
4
,
1
))
self
.
cmp_dot22scalar
((
1
,
4
),
(
4
,
5
),
rng
)
self
.
cmp_dot22scalar
((
3
,
1
),
(
1
,
1
))
self
.
cmp_dot22scalar
((
3
,
4
),
(
4
,
1
),
rng
)
self
.
cmp_dot22scalar
((
1
,
4
),
(
4
,
1
))
self
.
cmp_dot22scalar
((
3
,
1
),
(
1
,
1
),
rng
)
self
.
cmp_dot22scalar
((
3
,
1
),
(
1
,
5
))
self
.
cmp_dot22scalar
((
1
,
4
),
(
4
,
1
),
rng
)
self
.
cmp_dot22scalar
((
0
,
4
),
(
4
,
5
))
self
.
cmp_dot22scalar
((
3
,
1
),
(
1
,
5
),
rng
)
self
.
cmp_dot22scalar
((
0
,
4
),
(
4
,
1
))
self
.
cmp_dot22scalar
((
0
,
4
),
(
4
,
5
),
rng
)
self
.
cmp_dot22scalar
((
0
,
1
),
(
1
,
5
))
self
.
cmp_dot22scalar
((
0
,
4
),
(
4
,
1
),
rng
)
self
.
cmp_dot22scalar
((
3
,
4
),
(
4
,
0
))
self
.
cmp_dot22scalar
((
0
,
1
),
(
1
,
5
),
rng
)
self
.
cmp_dot22scalar
((
3
,
0
),
(
0
,
5
))
self
.
cmp_dot22scalar
((
3
,
4
),
(
4
,
0
),
rng
)
self
.
cmp_dot22scalar
((
0
,
4
),
(
4
,
0
))
self
.
cmp_dot22scalar
((
3
,
0
),
(
0
,
5
),
rng
)
self
.
cmp_dot22scalar
((
0
,
0
),
(
0
,
0
))
self
.
cmp_dot22scalar
((
0
,
4
),
(
4
,
0
),
rng
)
self
.
cmp_dot22scalar
((
0
,
0
),
(
0
,
0
),
rng
)
def
cmp_gemm
(
self
,
a_shp
,
b_shp
,
c_shp
):
av
=
self
.
random
(
*
a_shp
)
def
cmp_gemm
(
self
,
a_shp
,
b_shp
,
c_shp
,
rng
):
bv
=
self
.
random
(
*
b_shp
)
av
=
self
.
random
(
*
a_shp
,
rng
=
rng
)
cv
=
self
.
random
(
*
c_shp
)
bv
=
self
.
random
(
*
b_shp
,
rng
=
rng
)
cv
=
self
.
random
(
*
c_shp
,
rng
=
rng
)
l
=
np
.
float32
(
0.2
)
l
=
np
.
float32
(
0.2
)
a
=
shared
(
av
,
"a"
)
a
=
shared
(
av
,
"a"
)
...
@@ -2269,24 +2299,25 @@ class TestBlasStrides:
...
@@ -2269,24 +2299,25 @@ class TestBlasStrides:
assert
np
.
allclose
(
a_t
.
get_value
(),
at_n
)
assert
np
.
allclose
(
a_t
.
get_value
(),
at_n
)
def
test_gemm
(
self
):
def
test_gemm
(
self
):
self
.
cmp_gemm
((
3
,
5
),
(
3
,
4
),
(
4
,
5
))
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
self
.
cmp_gemm
((
1
,
5
),
(
1
,
4
),
(
4
,
5
))
self
.
cmp_gemm
((
3
,
5
),
(
3
,
4
),
(
4
,
5
),
rng
)
self
.
cmp_gemm
((
3
,
1
),
(
3
,
4
),
(
4
,
1
))
self
.
cmp_gemm
((
1
,
5
),
(
1
,
4
),
(
4
,
5
),
rng
)
self
.
cmp_gemm
((
3
,
1
),
(
3
,
1
),
(
1
,
1
))
self
.
cmp_gemm
((
3
,
1
),
(
3
,
4
),
(
4
,
1
),
rng
)
self
.
cmp_gemm
((
1
,
1
),
(
1
,
4
),
(
4
,
1
))
self
.
cmp_gemm
((
3
,
1
),
(
3
,
1
),
(
1
,
1
),
rng
)
self
.
cmp_gemm
((
3
,
5
),
(
3
,
1
),
(
1
,
5
))
self
.
cmp_gemm
((
1
,
1
),
(
1
,
4
),
(
4
,
1
),
rng
)
self
.
cmp_gemm
((
0
,
5
),
(
0
,
4
),
(
4
,
5
))
self
.
cmp_gemm
((
3
,
5
),
(
3
,
1
),
(
1
,
5
),
rng
)
self
.
cmp_gemm
((
0
,
1
),
(
0
,
4
),
(
4
,
1
))
self
.
cmp_gemm
((
0
,
5
),
(
0
,
4
),
(
4
,
5
),
rng
)
self
.
cmp_gemm
((
0
,
5
),
(
0
,
1
),
(
1
,
5
))
self
.
cmp_gemm
((
0
,
1
),
(
0
,
4
),
(
4
,
1
),
rng
)
self
.
cmp_gemm
((
3
,
0
),
(
3
,
4
),
(
4
,
0
))
self
.
cmp_gemm
((
0
,
5
),
(
0
,
1
),
(
1
,
5
),
rng
)
self
.
cmp_gemm
((
3
,
5
),
(
3
,
0
),
(
0
,
5
))
self
.
cmp_gemm
((
3
,
0
),
(
3
,
4
),
(
4
,
0
),
rng
)
self
.
cmp_gemm
((
0
,
0
),
(
0
,
4
),
(
4
,
0
))
self
.
cmp_gemm
((
3
,
5
),
(
3
,
0
),
(
0
,
5
),
rng
)
self
.
cmp_gemm
((
0
,
0
),
(
0
,
0
),
(
0
,
0
))
self
.
cmp_gemm
((
0
,
0
),
(
0
,
4
),
(
4
,
0
),
rng
)
self
.
cmp_gemm
((
0
,
0
),
(
0
,
0
),
(
0
,
0
),
rng
)
def
cmp_gemv
(
self
,
a_shp
,
b_shp
,
c_shp
):
av
=
self
.
random
(
a_shp
)
def
cmp_gemv
(
self
,
a_shp
,
b_shp
,
c_shp
,
rng
):
bv
=
self
.
random
(
*
b_shp
)
av
=
self
.
random
(
a_shp
,
rng
=
rng
)
cv
=
self
.
random
(
c_shp
)
bv
=
self
.
random
(
*
b_shp
,
rng
=
rng
)
cv
=
self
.
random
(
c_shp
,
rng
=
rng
)
l
=
np
.
float32
(
0.2
)
l
=
np
.
float32
(
0.2
)
a
=
shared
(
av
,
"a"
)
a
=
shared
(
av
,
"a"
)
...
@@ -2323,19 +2354,20 @@ class TestBlasStrides:
...
@@ -2323,19 +2354,20 @@ class TestBlasStrides:
assert
np
.
allclose
(
a
.
get_value
(),
a_n
),
(
a
.
get_value
(),
a_n
)
assert
np
.
allclose
(
a
.
get_value
(),
a_n
),
(
a
.
get_value
(),
a_n
)
def
test_gemv
(
self
):
def
test_gemv
(
self
):
self
.
cmp_gemv
(
3
,
(
3
,
5
),
5
)
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
self
.
cmp_gemv
(
1
,
(
1
,
5
),
5
)
self
.
cmp_gemv
(
3
,
(
3
,
5
),
5
,
rng
)
self
.
cmp_gemv
(
3
,
(
3
,
1
),
1
)
self
.
cmp_gemv
(
1
,
(
1
,
5
),
5
,
rng
)
self
.
cmp_gemv
(
0
,
(
0
,
5
),
5
)
self
.
cmp_gemv
(
3
,
(
3
,
1
),
1
,
rng
)
self
.
cmp_gemv
(
3
,
(
3
,
0
),
0
)
self
.
cmp_gemv
(
0
,
(
0
,
5
),
5
,
rng
)
self
.
cmp_gemv
(
0
,
(
0
,
1
),
1
)
self
.
cmp_gemv
(
3
,
(
3
,
0
),
0
,
rng
)
self
.
cmp_gemv
(
1
,
(
1
,
0
),
0
)
self
.
cmp_gemv
(
0
,
(
0
,
1
),
1
,
rng
)
self
.
cmp_gemv
(
0
,
(
0
,
0
),
0
)
self
.
cmp_gemv
(
1
,
(
1
,
0
),
0
,
rng
)
self
.
cmp_gemv
(
0
,
(
0
,
0
),
0
,
rng
)
def
cmp_ger
(
self
,
a_shp
,
b_shp
,
c_shp
):
av
=
self
.
random
(
*
a_shp
)
def
cmp_ger
(
self
,
a_shp
,
b_shp
,
c_shp
,
rng
):
bv
=
self
.
random
(
b_shp
)
av
=
self
.
random
(
*
a_shp
,
rng
=
rng
)
cv
=
self
.
random
(
c_shp
)
bv
=
self
.
random
(
b_shp
,
rng
=
rng
)
cv
=
self
.
random
(
c_shp
,
rng
=
rng
)
l
=
np
.
float32
(
0.2
)
l
=
np
.
float32
(
0.2
)
a
=
shared
(
av
,
"a"
)
a
=
shared
(
av
,
"a"
)
...
@@ -2379,14 +2411,15 @@ class TestBlasStrides:
...
@@ -2379,14 +2411,15 @@ class TestBlasStrides:
assert
np
.
allclose
(
a_t
.
get_value
(),
n_t
),
(
a_t
.
get_value
(),
n_t
)
assert
np
.
allclose
(
a_t
.
get_value
(),
n_t
),
(
a_t
.
get_value
(),
n_t
)
def
test_ger_strides
(
self
):
def
test_ger_strides
(
self
):
self
.
cmp_ger
((
3
,
5
),
3
,
5
)
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
self
.
cmp_ger
((
1
,
5
),
1
,
5
)
self
.
cmp_ger
((
3
,
5
),
3
,
5
,
rng
)
self
.
cmp_ger
((
3
,
1
),
3
,
1
)
self
.
cmp_ger
((
1
,
5
),
1
,
5
,
rng
)
self
.
cmp_ger
((
0
,
5
),
0
,
5
)
self
.
cmp_ger
((
3
,
1
),
3
,
1
,
rng
)
self
.
cmp_ger
((
3
,
0
),
3
,
0
)
self
.
cmp_ger
((
0
,
5
),
0
,
5
,
rng
)
self
.
cmp_ger
((
0
,
1
),
0
,
1
)
self
.
cmp_ger
((
3
,
0
),
3
,
0
,
rng
)
self
.
cmp_ger
((
1
,
0
),
1
,
0
)
self
.
cmp_ger
((
0
,
1
),
0
,
1
,
rng
)
self
.
cmp_ger
((
0
,
0
),
0
,
0
)
self
.
cmp_ger
((
1
,
0
),
1
,
0
,
rng
)
self
.
cmp_ger
((
0
,
0
),
0
,
0
,
rng
)
def
test_gemm_non_contiguous
(
self
):
def
test_gemm_non_contiguous
(
self
):
# test_gemm_non_contiguous: Test if GEMM works well with non-contiguous matrices.
# test_gemm_non_contiguous: Test if GEMM works well with non-contiguous matrices.
...
@@ -2409,32 +2442,35 @@ class TestBlasStrides:
...
@@ -2409,32 +2442,35 @@ class TestBlasStrides:
class
TestInferShape
(
unittest_tools
.
InferShapeTester
):
class
TestInferShape
(
unittest_tools
.
InferShapeTester
):
def
test_dot22
(
self
):
def
test_dot22
(
self
):
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
x
,
y
=
matrices
(
"xy"
)
x
,
y
=
matrices
(
"xy"
)
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
x
,
y
],
[
x
,
y
],
[
_dot22
(
x
,
y
)],
[
_dot22
(
x
,
y
)],
[
[
np
.
random
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
rng
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
np
.
random
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
),
rng
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
),
],
],
Dot22
,
Dot22
,
)
)
def
test_dot22scalar
(
self
):
def
test_dot22scalar
(
self
):
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
x
,
y
=
matrices
(
"xy"
)
x
,
y
=
matrices
(
"xy"
)
a
=
scalar
(
"a"
)
a
=
scalar
(
"a"
)
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
x
,
y
,
a
],
[
x
,
y
,
a
],
[
_dot22scalar
(
x
,
y
,
a
)],
[
_dot22scalar
(
x
,
y
,
a
)],
[
[
np
.
random
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
rng
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
np
.
random
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
),
rng
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
),
np
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
np
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
],
],
Dot22Scalar
,
Dot22Scalar
,
)
)
def
test_gemm
(
self
):
def
test_gemm
(
self
):
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
x
,
y
,
z
=
matrices
(
"xyz"
)
x
,
y
,
z
=
matrices
(
"xyz"
)
a
=
scalar
(
"a"
)
a
=
scalar
(
"a"
)
b
=
scalar
(
"b"
)
b
=
scalar
(
"b"
)
...
@@ -2442,16 +2478,17 @@ class TestInferShape(unittest_tools.InferShapeTester):
...
@@ -2442,16 +2478,17 @@ class TestInferShape(unittest_tools.InferShapeTester):
[
x
,
y
,
a
,
z
,
b
],
[
x
,
y
,
a
,
z
,
b
],
[
gemm
(
z
,
a
,
x
,
y
,
b
)],
[
gemm
(
z
,
a
,
x
,
y
,
b
)],
[
[
np
.
random
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
rng
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
np
.
random
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
),
rng
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
),
np
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
np
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
np
.
random
.
random
((
2
,
4
))
.
astype
(
config
.
floatX
),
rng
.
random
((
2
,
4
))
.
astype
(
config
.
floatX
),
np
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
np
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
],
],
Gemm
,
Gemm
,
)
)
def
test_gemv
(
self
):
def
test_gemv
(
self
):
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
A
=
matrix
(
"A"
)
A
=
matrix
(
"A"
)
x
,
y
=
vectors
(
"xy"
)
x
,
y
=
vectors
(
"xy"
)
a
=
scalar
(
"a"
)
a
=
scalar
(
"a"
)
...
@@ -2460,16 +2497,17 @@ class TestInferShape(unittest_tools.InferShapeTester):
...
@@ -2460,16 +2497,17 @@ class TestInferShape(unittest_tools.InferShapeTester):
[
y
,
a
,
A
,
x
,
b
],
[
y
,
a
,
A
,
x
,
b
],
[
gemv
(
y
,
a
,
A
,
x
,
b
)],
[
gemv
(
y
,
a
,
A
,
x
,
b
)],
[
[
np
.
random
.
random
((
2
,))
.
astype
(
config
.
floatX
),
rng
.
random
((
2
,))
.
astype
(
config
.
floatX
),
np
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
np
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
np
.
random
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
rng
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
np
.
random
.
random
((
3
,))
.
astype
(
config
.
floatX
),
rng
.
random
((
3
,))
.
astype
(
config
.
floatX
),
np
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
np
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
],
],
Gemv
,
Gemv
,
)
)
def
test_ger
(
self
):
def
test_ger
(
self
):
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
A
=
matrix
(
"A"
)
A
=
matrix
(
"A"
)
x
,
y
=
vectors
(
"xy"
)
x
,
y
=
vectors
(
"xy"
)
a
=
scalar
(
"a"
)
a
=
scalar
(
"a"
)
...
@@ -2477,15 +2515,16 @@ class TestInferShape(unittest_tools.InferShapeTester):
...
@@ -2477,15 +2515,16 @@ class TestInferShape(unittest_tools.InferShapeTester):
[
A
,
a
,
x
,
y
],
[
A
,
a
,
x
,
y
],
[
ger
(
A
,
a
,
x
,
y
)],
[
ger
(
A
,
a
,
x
,
y
)],
[
[
np
.
random
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
rng
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
np
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
np
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
np
.
random
.
random
((
2
,))
.
astype
(
config
.
floatX
),
rng
.
random
((
2
,))
.
astype
(
config
.
floatX
),
np
.
random
.
random
((
3
,))
.
astype
(
config
.
floatX
),
rng
.
random
((
3
,))
.
astype
(
config
.
floatX
),
],
],
Ger
,
Ger
,
)
)
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
TestBatchedDot
=
makeTester
(
TestBatchedDot
=
makeTester
(
name
=
"BatchedDotTester"
,
name
=
"BatchedDotTester"
,
op
=
batched_dot
,
op
=
batched_dot
,
...
@@ -2500,60 +2539,62 @@ TestBatchedDot = makeTester(
...
@@ -2500,60 +2539,62 @@ TestBatchedDot = makeTester(
),
),
checks
=
{},
checks
=
{},
grad
=
dict
(
grad
=
dict
(
correct1
=
(
random
(
3
,
5
,
7
),
random
(
3
,
7
,
5
)),
correct1
=
(
random
(
3
,
5
,
7
,
rng
=
rng
),
random
(
3
,
7
,
5
,
rng
=
rng
)),
correct2
=
(
random
(
3
,
5
,
7
),
random
(
3
,
7
,
9
)),
correct2
=
(
random
(
3
,
5
,
7
,
rng
=
rng
),
random
(
3
,
7
,
9
,
rng
=
rng
)),
correct3
=
(
random
(
3
,
5
,
7
),
random
(
3
,
7
)),
correct3
=
(
random
(
3
,
5
,
7
,
rng
=
rng
),
random
(
3
,
7
,
rng
=
rng
)),
correct4
=
(
random
(
3
,
5
),
random
(
3
,
5
,
7
)),
correct4
=
(
random
(
3
,
5
),
random
(
3
,
5
,
7
,
rng
=
rng
)),
correct5
=
(
random
(
3
),
random
(
3
,
5
,
7
)),
correct5
=
(
random
(
3
,
rng
=
rng
),
random
(
3
,
5
,
7
,
rng
=
rng
)),
correct6
=
(
random
(
3
,
5
),
random
(
3
)),
correct6
=
(
random
(
3
,
5
,
rng
=
rng
),
random
(
3
,
rng
=
rng
)),
correct7
=
(
random
(
3
,
5
),
random
(
3
,
5
)),
correct7
=
(
random
(
3
,
5
,
rng
=
rng
),
random
(
3
,
5
,
rng
=
rng
)),
correct8
=
(
random
(
3
),
random
(
3
)),
correct8
=
(
random
(
3
,
rng
=
rng
),
random
(
3
,
rng
=
rng
)),
correct9
=
(
random
(
3
,
5
,
7
,
11
),
random
(
3
)),
correct9
=
(
random
(
3
,
5
,
7
,
11
,
rng
=
rng
),
random
(
3
,
rng
=
rng
)),
correct10
=
(
random
(
3
,
2
,
6
,
5
),
random
(
3
,
5
)),
correct10
=
(
random
(
3
,
2
,
6
,
5
,
rng
=
rng
),
random
(
3
,
5
,
rng
=
rng
)),
correct11
=
(
random
(
3
,
2
,
6
,
5
),
random
(
3
,
5
,
7
)),
correct11
=
(
random
(
3
,
2
,
6
,
5
,
rng
=
rng
),
random
(
3
,
5
,
7
,
rng
=
rng
)),
correct12
=
(
random
(
3
,
2
,
6
,
5
),
random
(
3
,
7
,
5
,
8
)),
correct12
=
(
random
(
3
,
2
,
6
,
5
,
rng
=
rng
),
random
(
3
,
7
,
5
,
8
,
rng
=
rng
)),
mixed1
=
(
random
(
3
,
5
)
.
astype
(
"float32"
),
random
(
3
,
5
,
7
)),
mixed1
=
(
random
(
3
,
5
,
rng
=
rng
)
.
astype
(
"float32"
),
random
(
3
,
5
,
7
,
rng
=
rng
)),
mixed2
=
(
random
(
3
,
5
)
.
astype
(
"float64"
),
random
(
3
,
5
,
7
)),
mixed2
=
(
random
(
3
,
5
,
rng
=
rng
)
.
astype
(
"float64"
),
random
(
3
,
5
,
7
,
rng
=
rng
)),
),
),
good
=
dict
(
good
=
dict
(
correct1
=
(
random
(
3
,
5
,
7
),
random
(
3
,
7
,
5
)),
correct1
=
(
random
(
3
,
5
,
7
,
rng
=
rng
),
random
(
3
,
7
,
5
,
rng
=
rng
)),
correct2
=
(
random
(
3
,
5
,
7
),
random
(
3
,
7
,
9
)),
correct2
=
(
random
(
3
,
5
,
7
,
rng
=
rng
),
random
(
3
,
7
,
9
,
rng
=
rng
)),
correct3
=
(
random
(
3
,
5
,
7
),
random
(
3
,
7
)),
correct3
=
(
random
(
3
,
5
,
7
,
rng
=
rng
),
random
(
3
,
7
,
rng
=
rng
)),
correct4
=
(
random
(
3
,
5
),
random
(
3
,
5
,
7
)),
correct4
=
(
random
(
3
,
5
,
rng
=
rng
),
random
(
3
,
5
,
7
,
rng
=
rng
)),
correct5
=
(
random
(
3
),
random
(
3
,
5
,
7
)),
correct5
=
(
random
(
3
,
rng
=
rng
),
random
(
3
,
5
,
7
,
rng
=
rng
)),
correct6
=
(
random
(
3
,
5
),
random
(
3
)),
correct6
=
(
random
(
3
,
5
,
rng
=
rng
),
random
(
3
,
rng
=
rng
)),
correct7
=
(
random
(
3
,
5
),
random
(
3
,
5
)),
correct7
=
(
random
(
3
,
5
,
rng
=
rng
),
random
(
3
,
5
,
rng
=
rng
)),
correct8
=
(
random
(
3
),
random
(
3
)),
correct8
=
(
random
(
3
,
rng
=
rng
),
random
(
3
,
rng
=
rng
)),
correct9
=
(
random
(
3
,
5
,
7
,
11
),
random
(
3
)),
correct9
=
(
random
(
3
,
5
,
7
,
11
,
rng
=
rng
),
random
(
3
,
rng
=
rng
)),
correct10
=
(
random
(
3
,
7
,
11
,
5
),
random
(
3
,
5
)),
correct10
=
(
random
(
3
,
7
,
11
,
5
,
rng
=
rng
),
random
(
3
,
5
,
rng
=
rng
)),
correct11
=
(
random
(
3
,
7
,
11
,
5
),
random
(
3
,
5
,
13
)),
correct11
=
(
random
(
3
,
7
,
11
,
5
,
rng
=
rng
),
random
(
3
,
5
,
13
,
rng
=
rng
)),
correct12
=
(
random
(
3
,
7
,
11
,
5
),
random
(
3
,
13
,
5
,
17
)),
correct12
=
(
random
(
3
,
7
,
11
,
5
,
rng
=
rng
),
random
(
3
,
13
,
5
,
17
,
rng
=
rng
)),
mixed1
=
(
random
(
3
,
5
)
.
astype
(
"float32"
),
random
(
3
,
5
,
7
)),
mixed1
=
(
random
(
3
,
5
,
rng
=
rng
)
.
astype
(
"float32"
),
random
(
3
,
5
,
7
,
rng
=
rng
)),
mixed2
=
(
random
(
3
,
5
)
.
astype
(
"float64"
),
random
(
3
,
5
,
7
)),
mixed2
=
(
random
(
3
,
5
,
rng
=
rng
)
.
astype
(
"float64"
),
random
(
3
,
5
,
7
,
rng
=
rng
)),
),
),
bad_build
=
dict
(
bad_build
=
dict
(
no_batch_axis2
=
(
random
(),
random
(
3
,
5
)),
no_batch_axis3
=
(
random
(
3
,
5
),
random
())
no_batch_axis2
=
(
random
(
rng
=
rng
),
random
(
3
,
5
,
rng
=
rng
)),
no_batch_axis3
=
(
random
(
3
,
5
,
rng
=
rng
),
random
(
rng
=
rng
)),
),
),
bad_runtime
=
dict
(
bad_runtime
=
dict
(
batch_dim_mismatch1
=
(
random
(
2
,
5
,
7
),
random
(
3
,
7
,
9
)),
batch_dim_mismatch1
=
(
random
(
2
,
5
,
7
,
rng
=
rng
),
random
(
3
,
7
,
9
,
rng
=
rng
)),
batch_dim_mismatch2
=
(
random
(
3
,
5
,
7
),
random
(
2
,
7
,
9
)),
batch_dim_mismatch2
=
(
random
(
3
,
5
,
7
,
rng
=
rng
),
random
(
2
,
7
,
9
,
rng
=
rng
)),
batch_dim_mismatch3
=
(
random
(
3
),
random
(
5
)),
batch_dim_mismatch3
=
(
random
(
3
,
rng
=
rng
),
random
(
5
,
rng
=
rng
)),
bad_dim1
=
(
random
(
3
,
5
,
7
),
random
(
3
,
5
,
7
)),
bad_dim1
=
(
random
(
3
,
5
,
7
,
rng
=
rng
),
random
(
3
,
5
,
7
,
rng
=
rng
)),
bad_dim2
=
(
random
(
3
,
5
,
7
),
random
(
3
,
8
,
3
)),
bad_dim2
=
(
random
(
3
,
5
,
7
,
rng
=
rng
),
random
(
3
,
8
,
3
,
rng
=
rng
)),
bad_dim3
=
(
random
(
3
,
5
),
random
(
3
,
7
)),
bad_dim3
=
(
random
(
3
,
5
,
rng
=
rng
),
random
(
3
,
7
,
rng
=
rng
)),
bad_dim4
=
(
random
(
3
,
5
,
7
,
11
),
random
(
3
,
5
)),
bad_dim4
=
(
random
(
3
,
5
,
7
,
11
,
rng
=
rng
),
random
(
3
,
5
,
rng
=
rng
)),
bad_dim5
=
(
random
(
3
,
5
,
7
,
11
),
random
(
3
,
5
,
13
)),
bad_dim5
=
(
random
(
3
,
5
,
7
,
11
,
rng
=
rng
),
random
(
3
,
5
,
13
,
rng
=
rng
)),
bad_dim6
=
(
random
(
3
,
5
,
7
,
11
),
random
(
3
,
13
,
5
,
17
)),
bad_dim6
=
(
random
(
3
,
5
,
7
,
11
,
rng
=
rng
),
random
(
3
,
13
,
5
,
17
,
rng
=
rng
)),
),
),
)
)
def
test_batched_dot
():
def
test_batched_dot
():
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
first
=
tensor3
(
"first"
)
first
=
tensor3
(
"first"
)
second
=
tensor3
(
"second"
)
second
=
tensor3
(
"second"
)
output
=
batched_dot
(
first
,
second
)
output
=
batched_dot
(
first
,
second
)
first_val
=
np
.
random
.
random
((
10
,
10
,
20
))
.
astype
(
config
.
floatX
)
first_val
=
rng
.
random
((
10
,
10
,
20
))
.
astype
(
config
.
floatX
)
second_val
=
np
.
random
.
random
((
10
,
20
,
5
))
.
astype
(
config
.
floatX
)
second_val
=
rng
.
random
((
10
,
20
,
5
))
.
astype
(
config
.
floatX
)
result_fn
=
function
([
first
,
second
],
output
)
result_fn
=
function
([
first
,
second
],
output
)
result
=
result_fn
(
first_val
,
second_val
)
result
=
result_fn
(
first_val
,
second_val
)
assert
result
.
shape
[
0
]
==
first_val
.
shape
[
0
]
assert
result
.
shape
[
0
]
==
first_val
.
shape
[
0
]
...
@@ -2563,8 +2604,8 @@ def test_batched_dot():
...
@@ -2563,8 +2604,8 @@ def test_batched_dot():
first_mat
=
dmatrix
(
"first"
)
first_mat
=
dmatrix
(
"first"
)
second_mat
=
dmatrix
(
"second"
)
second_mat
=
dmatrix
(
"second"
)
output
=
batched_dot
(
first_mat
,
second_mat
)
output
=
batched_dot
(
first_mat
,
second_mat
)
first_mat_val
=
np
.
random
.
random
((
10
,
10
))
.
astype
(
config
.
floatX
)
first_mat_val
=
rng
.
random
((
10
,
10
))
.
astype
(
config
.
floatX
)
second_mat_val
=
np
.
random
.
random
((
10
,
10
))
.
astype
(
config
.
floatX
)
second_mat_val
=
rng
.
random
((
10
,
10
))
.
astype
(
config
.
floatX
)
result_fn
=
function
([
first_mat
,
second_mat
],
output
)
result_fn
=
function
([
first_mat
,
second_mat
],
output
)
result
=
result_fn
(
first_mat_val
,
second_mat_val
)
result
=
result_fn
(
first_mat_val
,
second_mat_val
)
...
@@ -2602,12 +2643,13 @@ def test_batched_dot_not_contiguous():
...
@@ -2602,12 +2643,13 @@ def test_batched_dot_not_contiguous():
def
test_batched_tensordot
():
def
test_batched_tensordot
():
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
first
=
tensor4
(
"first"
)
first
=
tensor4
(
"first"
)
second
=
tensor4
(
"second"
)
second
=
tensor4
(
"second"
)
axes
=
[[
1
,
2
],
[
3
,
1
]]
axes
=
[[
1
,
2
],
[
3
,
1
]]
output
=
batched_tensordot
(
first
,
second
,
axes
)
output
=
batched_tensordot
(
first
,
second
,
axes
)
first_val
=
np
.
random
.
random
((
8
,
10
,
20
,
3
))
.
astype
(
config
.
floatX
)
first_val
=
rng
.
random
((
8
,
10
,
20
,
3
))
.
astype
(
config
.
floatX
)
second_val
=
np
.
random
.
random
((
8
,
20
,
5
,
10
))
.
astype
(
config
.
floatX
)
second_val
=
rng
.
random
((
8
,
20
,
5
,
10
))
.
astype
(
config
.
floatX
)
result_fn
=
function
([
first
,
second
],
output
)
result_fn
=
function
([
first
,
second
],
output
)
result
=
result_fn
(
first_val
,
second_val
)
result
=
result_fn
(
first_val
,
second_val
)
assert
result
.
shape
[
0
]
==
first_val
.
shape
[
0
]
assert
result
.
shape
[
0
]
==
first_val
.
shape
[
0
]
...
@@ -2618,8 +2660,8 @@ def test_batched_tensordot():
...
@@ -2618,8 +2660,8 @@ def test_batched_tensordot():
second_mat
=
dmatrix
(
"second"
)
second_mat
=
dmatrix
(
"second"
)
axes
=
1
axes
=
1
output
=
batched_tensordot
(
first_mat
,
second_mat
,
axes
)
output
=
batched_tensordot
(
first_mat
,
second_mat
,
axes
)
first_mat_val
=
np
.
random
.
random
((
10
,
4
))
.
astype
(
config
.
floatX
)
first_mat_val
=
rng
.
random
((
10
,
4
))
.
astype
(
config
.
floatX
)
second_mat_val
=
np
.
random
.
random
((
10
,
4
))
.
astype
(
config
.
floatX
)
second_mat_val
=
rng
.
random
((
10
,
4
))
.
astype
(
config
.
floatX
)
result_fn
=
function
([
first_mat
,
second_mat
],
output
)
result_fn
=
function
([
first_mat
,
second_mat
],
output
)
result
=
result_fn
(
first_mat_val
,
second_mat_val
)
result
=
result_fn
(
first_mat_val
,
second_mat_val
)
assert
result
.
shape
[
0
]
==
first_mat_val
.
shape
[
0
]
assert
result
.
shape
[
0
]
==
first_mat_val
.
shape
[
0
]
...
...
tests/tensor/test_math.py
浏览文件 @
dfd047ef
...
@@ -195,17 +195,27 @@ else:
...
@@ -195,17 +195,27 @@ else:
mode_opt
=
get_default_mode
()
mode_opt
=
get_default_mode
()
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
TestAddBroadcast
=
makeBroadcastTester
(
TestAddBroadcast
=
makeBroadcastTester
(
op
=
add
,
op
=
add
,
expected
=
lambda
*
inputs
:
check_floatX
(
inputs
,
reduce
(
lambda
x
,
y
:
x
+
y
,
inputs
)),
expected
=
lambda
*
inputs
:
check_floatX
(
inputs
,
reduce
(
lambda
x
,
y
:
x
+
y
,
inputs
)),
good
=
dict
(
good
=
dict
(
three_inputs_same_shapes
=
(
random
(
2
,
3
),
random
(
2
,
3
),
random
(
2
,
3
)),
three_inputs_same_shapes
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
2
,
3
,
rng
=
rng
),
random
(
2
,
3
,
rng
=
rng
),
),
three_inputs_same_shapes_uint
=
(
three_inputs_same_shapes_uint
=
(
integers_uint32
(
2
,
3
),
integers_uint32
(
2
,
3
,
rng
=
rng
),
integers_uint32
(
2
,
3
),
integers_uint32
(
2
,
3
,
rng
=
rng
),
integers_uint32
(
2
,
3
),
integers_uint32
(
2
,
3
,
rng
=
rng
),
),
four_inputs_broadcast
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
1
,
3
,
rng
=
rng
),
random
(
2
,
1
,
rng
=
rng
),
random
(
1
,
1
,
rng
=
rng
),
),
),
four_inputs_broadcast
=
(
random
(
2
,
3
),
random
(
1
,
3
),
random
(
2
,
1
),
random
(
1
,
1
)),
**
_good_broadcast_binary_normal
,
**
_good_broadcast_binary_normal
,
),
),
bad_build
=
_bad_build_broadcast_binary_normal
,
bad_build
=
_bad_build_broadcast_binary_normal
,
...
@@ -254,19 +264,38 @@ TestMinimumBroadcast = makeBroadcastTester(
...
@@ -254,19 +264,38 @@ TestMinimumBroadcast = makeBroadcastTester(
grad
=
_grad_broadcast_binary_normal
,
grad
=
_grad_broadcast_binary_normal
,
)
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
TestMulBroadcast
=
makeBroadcastTester
(
TestMulBroadcast
=
makeBroadcastTester
(
op
=
mul
,
op
=
mul
,
expected
=
lambda
*
inputs
:
check_floatX
(
inputs
,
reduce
(
lambda
x
,
y
:
x
*
y
,
inputs
)),
expected
=
lambda
*
inputs
:
check_floatX
(
inputs
,
reduce
(
lambda
x
,
y
:
x
*
y
,
inputs
)),
good
=
dict
(
good
=
dict
(
three_inputs_same_shapes
=
(
random
(
2
,
3
),
random
(
2
,
3
),
random
(
2
,
3
)),
three_inputs_same_shapes
=
(
four_inputs_broadcast
=
(
random
(
2
,
3
),
random
(
1
,
3
),
random
(
2
,
1
),
random
(
1
,
1
)),
random
(
2
,
3
,
rng
=
rng
),
random
(
2
,
3
,
rng
=
rng
),
random
(
2
,
3
,
rng
=
rng
),
),
four_inputs_broadcast
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
1
,
3
,
rng
=
rng
),
random
(
2
,
1
,
rng
=
rng
),
random
(
1
,
1
,
rng
=
rng
),
),
**
_good_broadcast_binary_normal
,
**
_good_broadcast_binary_normal
,
),
),
bad_build
=
_bad_build_broadcast_binary_normal
,
bad_build
=
_bad_build_broadcast_binary_normal
,
bad_runtime
=
_bad_runtime_broadcast_binary_normal
,
bad_runtime
=
_bad_runtime_broadcast_binary_normal
,
grad
=
dict
(
grad
=
dict
(
three_inputs_same_shapes
=
(
random
(
2
,
3
),
random
(
2
,
3
),
random
(
2
,
3
)),
three_inputs_same_shapes
=
(
four_inputs_broadcast
=
(
random
(
2
,
3
),
random
(
1
,
3
),
random
(
2
,
1
),
random
(
1
,
1
)),
random
(
2
,
3
,
rng
=
rng
),
random
(
2
,
3
,
rng
=
rng
),
random
(
2
,
3
,
rng
=
rng
),
),
four_inputs_broadcast
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
1
,
3
,
rng
=
rng
),
random
(
2
,
1
,
rng
=
rng
),
random
(
1
,
1
,
rng
=
rng
),
),
**
_grad_broadcast_binary_normal
,
**
_grad_broadcast_binary_normal
,
),
),
)
)
...
@@ -291,17 +320,6 @@ _grad_broadcast_div_mod_normal = dict(
...
@@ -291,17 +320,6 @@ _grad_broadcast_div_mod_normal = dict(
np
.
array
([[
0.04506636
,
0.05725927
,
-
0.94947897
],
[
0.39868416
,
-
0.12655465
,
-
0.87068554
]]),
np
.
array
([[
0.04506636
,
0.05725927
,
-
0.94947897
],
[
0.39868416
,
-
0.12655465
,
-
0.87068554
]]),
np
.
array
([[
-
0.39040176
],
[
0.76164576
]])
np
.
array
([[
-
0.39040176
],
[
0.76164576
]])
),
),
# same_shapes=(random(2, 3), random((2, 3))),
# scalar=(random(2, 3), random((1, 1))),
# row=(random(2, 3), random((1, 3))),
# column=(random(2, 3), random((2, 1))),
# complex1=(random_complex(2, 3), randcomplex_nonzero((2, 3))),
# complex2=(random_complex(2, 3), random((2, 3))),
# complex3=(random(2, 3), randcomplex_nonzero((2, 3))),
# dtype_mixup_1=(random(2, 3), integers_nonzero(2, 3)),
# dtype_mixup_2=(integers_nonzero(2, 3), random((2, 3))),
# empty1=(np.asarray([]), np.asarray([1.])),
# empty2=(np.asarray([0]), np.asarray([])),
)
)
# fmt: on
# fmt: on
...
@@ -450,8 +468,9 @@ TestExpm1Broadcast = makeBroadcastTester(
...
@@ -450,8 +468,9 @@ TestExpm1Broadcast = makeBroadcastTester(
)
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_grad_broadcast_unary_positive
=
dict
(
_grad_broadcast_unary_positive
=
dict
(
normal
=
(
random_ranged
(
_eps
,
5
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
_eps
,
5
,
(
2
,
3
)
,
rng
=
rng
),),
)
)
TestLogBroadcast
=
makeBroadcastTester
(
TestLogBroadcast
=
makeBroadcastTester
(
...
@@ -489,8 +508,9 @@ TestSqrtBroadcast = makeBroadcastTester(
...
@@ -489,8 +508,9 @@ TestSqrtBroadcast = makeBroadcastTester(
grad
=
_grad_broadcast_unary_positive
,
grad
=
_grad_broadcast_unary_positive
,
)
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_grad_broadcast_unary_wide
=
dict
(
_grad_broadcast_unary_wide
=
dict
(
normal
=
(
random_ranged
(
-
1000
,
1000
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
-
1000
,
1000
,
(
2
,
3
)
,
rng
=
rng
),),
)
)
TestDeg2radBroadcast
=
makeBroadcastTester
(
TestDeg2radBroadcast
=
makeBroadcastTester
(
...
@@ -518,8 +538,9 @@ TestSinBroadcast = makeBroadcastTester(
...
@@ -518,8 +538,9 @@ TestSinBroadcast = makeBroadcastTester(
# The actual range is [-1, 1] but the numerical gradient is too
# The actual range is [-1, 1] but the numerical gradient is too
# unstable near those values
# unstable near those values
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_grad_broadcast_unary_arcsin
=
dict
(
_grad_broadcast_unary_arcsin
=
dict
(
normal
=
(
random_ranged
(
-
0.9
,
0.9
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
-
0.9
,
0.9
,
(
2
,
3
)
,
rng
=
rng
),),
)
)
TestArcsinBroadcast
=
makeBroadcastTester
(
TestArcsinBroadcast
=
makeBroadcastTester
(
...
@@ -552,9 +573,10 @@ TestArccosBroadcast = makeBroadcastTester(
...
@@ -552,9 +573,10 @@ TestArccosBroadcast = makeBroadcastTester(
)
)
# We do not want to test around the discontinuity.
# We do not want to test around the discontinuity.
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_grad_broadcast_unary_tan
=
dict
(
_grad_broadcast_unary_tan
=
dict
(
normal
=
(
random_ranged
(
-
1.5
,
1.5
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
-
1.5
,
1.5
,
(
2
,
3
)
,
rng
=
rng
),),
shifted
=
(
random_ranged
(
1.6
,
4.6
,
(
2
,
3
)),),
shifted
=
(
random_ranged
(
1.6
,
4.6
,
(
2
,
3
)
,
rng
=
rng
),),
)
)
TestTanBroadcast
=
makeBroadcastTester
(
TestTanBroadcast
=
makeBroadcastTester
(
...
@@ -571,11 +593,12 @@ TestArctanBroadcast = makeBroadcastTester(
...
@@ -571,11 +593,12 @@ TestArctanBroadcast = makeBroadcastTester(
grad
=
_grad_broadcast_unary_wide
,
grad
=
_grad_broadcast_unary_wide
,
)
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_grad_broadcast_binary_arctan2
=
dict
(
_grad_broadcast_binary_arctan2
=
dict
(
same_shapes
=
(
random
(
2
,
3
),
random
(
2
,
3
)),
same_shapes
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
2
,
3
,
rng
=
rng
)),
scalar
=
(
random
(
2
,
3
),
random
(
1
,
1
)),
scalar
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
1
,
1
,
rng
=
rng
)),
row
=
(
random
(
2
,
3
),
random
(
1
,
3
)),
row
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
1
,
3
,
rng
=
rng
)),
column
=
(
random
(
2
,
3
),
random
(
2
,
1
)),
column
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
2
,
1
,
rng
=
rng
)),
)
)
TestArctan2Broadcast
=
makeBroadcastTester
(
TestArctan2Broadcast
=
makeBroadcastTester
(
...
@@ -597,8 +620,9 @@ TestCoshBroadcast = makeBroadcastTester(
...
@@ -597,8 +620,9 @@ TestCoshBroadcast = makeBroadcastTester(
grad
=
_grad_broadcast_unary_normal
,
grad
=
_grad_broadcast_unary_normal
,
)
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_grad_broadcast_unary_arccosh
=
dict
(
_grad_broadcast_unary_arccosh
=
dict
(
normal
=
(
random_ranged
(
1
+
_eps
,
1000
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
1
+
_eps
,
1000
,
(
2
,
3
)
,
rng
=
rng
),),
)
)
TestArccoshBroadcast
=
makeBroadcastTester
(
TestArccoshBroadcast
=
makeBroadcastTester
(
...
@@ -634,8 +658,9 @@ TestTanhBroadcast = makeBroadcastTester(
...
@@ -634,8 +658,9 @@ TestTanhBroadcast = makeBroadcastTester(
grad
=
_grad_broadcast_unary_normal
,
grad
=
_grad_broadcast_unary_normal
,
)
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_grad_broadcast_unary_arctanh
=
dict
(
_grad_broadcast_unary_arctanh
=
dict
(
normal
=
(
random_ranged
(
-
1
+
_eps
,
1
-
_eps
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
-
1
+
_eps
,
1
-
_eps
,
(
2
,
3
)
,
rng
=
rng
),),
)
)
TestArctanhBroadcast
=
makeBroadcastTester
(
TestArctanhBroadcast
=
makeBroadcastTester
(
...
@@ -646,20 +671,21 @@ TestArctanhBroadcast = makeBroadcastTester(
...
@@ -646,20 +671,21 @@ TestArctanhBroadcast = makeBroadcastTester(
)
)
# Complex operations
# Complex operations
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_good_complex_from_polar
=
dict
(
_good_complex_from_polar
=
dict
(
same_shapes
=
(
np
.
abs
(
random
(
2
,
3
)),
random
(
2
,
3
)),
same_shapes
=
(
np
.
abs
(
random
(
2
,
3
,
rng
=
rng
)),
random
(
2
,
3
,
rng
=
rng
)),
not_same_dimensions
=
(
np
.
abs
(
random
(
2
,
2
)),
random
(
2
)),
not_same_dimensions
=
(
np
.
abs
(
random
(
2
,
2
,
rng
=
rng
)),
random
(
2
,
rng
=
rng
)),
scalar
=
(
np
.
abs
(
random
(
2
,
3
)),
random
(
1
,
1
)),
scalar
=
(
np
.
abs
(
random
(
2
,
3
,
rng
=
rng
)),
random
(
1
,
1
,
rng
=
rng
)),
row
=
(
np
.
abs
(
random
(
2
,
3
)),
random
(
1
,
3
)),
row
=
(
np
.
abs
(
random
(
2
,
3
,
rng
=
rng
)),
random
(
1
,
3
,
rng
=
rng
)),
column
=
(
np
.
abs
(
random
(
2
,
3
)),
random
(
2
,
1
)),
column
=
(
np
.
abs
(
random
(
2
,
3
,
rng
=
rng
)),
random
(
2
,
1
,
rng
=
rng
)),
integers
=
(
np
.
abs
(
integers
(
2
,
3
)),
integers
(
2
,
3
)),
integers
=
(
np
.
abs
(
integers
(
2
,
3
,
rng
=
rng
)),
integers
(
2
,
3
,
rng
=
rng
)),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([
1
],
dtype
=
config
.
floatX
)),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([
1
],
dtype
=
config
.
floatX
)),
)
)
_grad_complex_from_polar
=
dict
(
_grad_complex_from_polar
=
dict
(
same_shapes
=
(
np
.
abs
(
random
(
2
,
3
)),
random
(
2
,
3
)),
same_shapes
=
(
np
.
abs
(
random
(
2
,
3
,
rng
=
rng
)),
random
(
2
,
3
,
rng
=
rng
)),
scalar
=
(
np
.
abs
(
random
(
2
,
3
)),
random
(
1
,
1
)),
scalar
=
(
np
.
abs
(
random
(
2
,
3
,
rng
=
rng
)),
random
(
1
,
1
,
rng
=
rng
)),
row
=
(
np
.
abs
(
random
(
2
,
3
)),
random
(
1
,
3
)),
row
=
(
np
.
abs
(
random
(
2
,
3
,
rng
=
rng
)),
random
(
1
,
3
,
rng
=
rng
)),
column
=
(
np
.
abs
(
random
(
2
,
3
)),
random
(
2
,
1
)),
column
=
(
np
.
abs
(
random
(
2
,
3
,
rng
=
rng
)),
random
(
2
,
1
,
rng
=
rng
)),
)
)
TestComplexFromPolarBroadcast
=
makeBroadcastTester
(
TestComplexFromPolarBroadcast
=
makeBroadcastTester
(
...
@@ -673,31 +699,33 @@ TestConjBroadcast = makeBroadcastTester(
...
@@ -673,31 +699,33 @@ TestConjBroadcast = makeBroadcastTester(
)
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
TestDenseDot
=
makeTester
(
TestDenseDot
=
makeTester
(
name
=
"DenseDotTester"
,
name
=
"DenseDotTester"
,
op
=
dense_dot
,
op
=
dense_dot
,
expected
=
lambda
x
,
y
:
np
.
dot
(
x
,
y
),
expected
=
lambda
x
,
y
:
np
.
dot
(
x
,
y
),
checks
=
{},
checks
=
{},
good
=
dict
(
good
=
dict
(
correct1
=
(
random
(
5
,
7
),
random
(
7
,
5
)),
correct1
=
(
random
(
5
,
7
,
rng
=
rng
),
random
(
7
,
5
,
rng
=
rng
)),
correct2
=
(
random
(
5
,
7
),
random
(
7
,
9
)),
correct2
=
(
random
(
5
,
7
,
rng
=
rng
),
random
(
7
,
9
,
rng
=
rng
)),
correct3
=
(
random
(
5
,
7
),
random
(
7
)),
correct3
=
(
random
(
5
,
7
,
rng
=
rng
),
random
(
7
,
rng
=
rng
)),
correct4
=
(
random
(
5
),
random
(
5
,
7
)),
correct4
=
(
random
(
5
,
rng
=
rng
),
random
(
5
,
7
,
rng
=
rng
)),
mixed1
=
(
random
(
5
)
.
astype
(
"float32"
),
random
(
5
,
7
)),
mixed1
=
(
random
(
5
,
rng
=
rng
)
.
astype
(
"float32"
),
random
(
5
,
7
,
rng
=
rng
)),
mixed2
=
(
random
(
5
)
.
astype
(
"float64"
),
random
(
5
,
7
)),
mixed2
=
(
random
(
5
,
rng
=
rng
)
.
astype
(
"float64"
),
random
(
5
,
7
,
rng
=
rng
)),
complex1
=
(
random_complex
(
5
,
7
),
random_complex
(
7
)),
complex1
=
(
random_complex
(
5
,
7
,
rng
=
rng
),
random_complex
(
7
,
rng
=
rng
)),
complex2
=
(
random
(
5
,
7
),
random_complex
(
7
)),
complex2
=
(
random
(
5
,
7
,
rng
=
rng
),
random_complex
(
7
,
rng
=
rng
)),
complex3
=
(
random_complex
(
5
,
7
),
random
(
7
)),
complex3
=
(
random_complex
(
5
,
7
,
rng
=
rng
),
random
(
7
,
rng
=
rng
)),
empty1
=
(
empty1
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([],
dtype
=
config
.
floatX
),
),
),
empty2
=
(
random
(
5
,
0
),
random
(
0
,
2
)),
empty2
=
(
random
(
5
,
0
,
rng
=
rng
),
random
(
0
,
2
,
rng
=
rng
)),
empty3
=
(
random
(
0
,
5
),
random
(
5
,
0
)),
empty3
=
(
random
(
0
,
5
,
rng
=
rng
),
random
(
5
,
0
,
rng
=
rng
)),
),
),
bad_build
=
dict
(),
bad_build
=
dict
(),
bad_runtime
=
dict
(
bad_runtime
=
dict
(
bad1
=
(
random
(
5
,
7
),
random
(
5
,
7
)),
bad2
=
(
random
(
5
,
7
),
random
(
8
,
3
))
bad1
=
(
random
(
5
,
7
,
rng
=
rng
),
random
(
5
,
7
,
rng
=
rng
)),
bad2
=
(
random
(
5
,
7
,
rng
=
rng
),
random
(
8
,
3
,
rng
=
rng
)),
),
),
)
)
...
@@ -1301,49 +1329,50 @@ class TestMinMax:
...
@@ -1301,49 +1329,50 @@ class TestMinMax:
assert
np
.
all
(
i
)
assert
np
.
all
(
i
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
TestClip
=
makeTester
(
TestClip
=
makeTester
(
name
=
"ClipTester"
,
name
=
"ClipTester"
,
op
=
clip
,
op
=
clip
,
expected
=
lambda
x
,
y
,
z
:
np
.
clip
(
x
,
y
,
z
),
expected
=
lambda
x
,
y
,
z
:
np
.
clip
(
x
,
y
,
z
),
good
=
dict
(
good
=
dict
(
correct1
=
(
correct1
=
(
(
5
*
random
(
5
,
5
))
.
astype
(
"float32"
),
(
5
*
random
(
5
,
5
,
rng
=
rng
))
.
astype
(
"float32"
),
np
.
array
(
-
1
,
dtype
=
"float32"
),
np
.
array
(
-
1
,
dtype
=
"float32"
),
np
.
array
(
1
,
dtype
=
"float32"
),
np
.
array
(
1
,
dtype
=
"float32"
),
),
),
correct2
=
(
correct2
=
(
(
5
*
random
(
5
,
5
))
.
astype
(
"float64"
),
(
5
*
random
(
5
,
5
,
rng
=
rng
))
.
astype
(
"float64"
),
np
.
array
(
-
1
,
dtype
=
"float64"
),
np
.
array
(
-
1
,
dtype
=
"float64"
),
np
.
array
(
1
,
dtype
=
"float64"
),
np
.
array
(
1
,
dtype
=
"float64"
),
),
),
correct3
=
(
correct3
=
(
integers
(
5
,
5
)
.
astype
(
"int8"
),
integers
(
5
,
5
,
rng
=
rng
)
.
astype
(
"int8"
),
np
.
array
(
-
1
,
dtype
=
"int8"
),
np
.
array
(
-
1
,
dtype
=
"int8"
),
np
.
array
(
1
,
dtype
=
"int8"
),
np
.
array
(
1
,
dtype
=
"int8"
),
),
),
correct4
=
(
correct4
=
(
integers
(
5
,
5
)
.
astype
(
"int16"
),
integers
(
5
,
5
,
rng
=
rng
)
.
astype
(
"int16"
),
np
.
array
(
-
1
,
dtype
=
"int16"
),
np
.
array
(
-
1
,
dtype
=
"int16"
),
np
.
array
(
1
,
dtype
=
"int16"
),
np
.
array
(
1
,
dtype
=
"int16"
),
),
),
correct5
=
(
correct5
=
(
integers
(
5
,
5
)
.
astype
(
"int32"
),
integers
(
5
,
5
,
rng
=
rng
)
.
astype
(
"int32"
),
np
.
array
(
-
1
,
dtype
=
"int32"
),
np
.
array
(
-
1
,
dtype
=
"int32"
),
np
.
array
(
1
,
dtype
=
"int32"
),
np
.
array
(
1
,
dtype
=
"int32"
),
),
),
correct6
=
(
correct6
=
(
integers
(
5
,
5
)
.
astype
(
"int64"
),
integers
(
5
,
5
,
rng
=
rng
)
.
astype
(
"int64"
),
np
.
array
(
-
1
,
dtype
=
"int64"
),
np
.
array
(
-
1
,
dtype
=
"int64"
),
np
.
array
(
1
,
dtype
=
"int64"
),
np
.
array
(
1
,
dtype
=
"int64"
),
),
),
# min > max case moved below as numpy has changed
# min > max case moved below as numpy has changed
correct8
=
(
correct8
=
(
integers
(
0
,
5
)
.
astype
(
"uint8"
),
integers
(
0
,
5
,
rng
=
rng
)
.
astype
(
"uint8"
),
np
.
array
(
2
,
dtype
=
"uint8"
),
np
.
array
(
2
,
dtype
=
"uint8"
),
np
.
array
(
4
,
dtype
=
"uint8"
),
np
.
array
(
4
,
dtype
=
"uint8"
),
),
),
correct9
=
(
correct9
=
(
integers
(
0
,
5
)
.
astype
(
"uint16"
),
integers
(
0
,
5
,
rng
=
rng
)
.
astype
(
"uint16"
),
np
.
array
(
2
,
dtype
=
"uint16"
),
np
.
array
(
2
,
dtype
=
"uint16"
),
np
.
array
(
4
,
dtype
=
"uint16"
),
np
.
array
(
4
,
dtype
=
"uint16"
),
),
),
...
@@ -1360,7 +1389,7 @@ TestBackwardsClip = makeTester(
...
@@ -1360,7 +1389,7 @@ TestBackwardsClip = makeTester(
expected
=
lambda
x
,
y
,
z
:
np
.
where
(
x
<
y
,
y
,
np
.
minimum
(
x
,
z
)),
expected
=
lambda
x
,
y
,
z
:
np
.
where
(
x
<
y
,
y
,
np
.
minimum
(
x
,
z
)),
good
=
dict
(
good
=
dict
(
correct7
=
(
correct7
=
(
(
5
*
random
(
5
,
5
))
.
astype
(
"float64"
),
(
5
*
random
(
5
,
5
,
rng
=
rng
))
.
astype
(
"float64"
),
np
.
array
(
1
,
dtype
=
"float64"
),
np
.
array
(
1
,
dtype
=
"float64"
),
np
.
array
(
-
1
,
dtype
=
"float64"
),
np
.
array
(
-
1
,
dtype
=
"float64"
),
),
),
...
@@ -1744,10 +1773,12 @@ class TestAdd:
...
@@ -1744,10 +1773,12 @@ class TestAdd:
utt
.
verify_grad
(
add
,
[
random
(
3
),
np
.
asarray
([
3.0
])])
utt
.
verify_grad
(
add
,
[
random
(
3
),
np
.
asarray
([
3.0
])])
def
test_grad_row
(
self
):
def
test_grad_row
(
self
):
utt
.
verify_grad
(
add
,
[
random
(
3
,
5
),
random
(
1
,
5
)])
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
utt
.
verify_grad
(
add
,
[
random
(
3
,
5
,
rng
=
rng
),
random
(
1
,
5
,
rng
=
rng
)])
def
test_grad_col
(
self
):
def
test_grad_col
(
self
):
utt
.
verify_grad
(
add
,
[
random
(
3
,
5
),
random
(
3
,
1
)])
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
utt
.
verify_grad
(
add
,
[
random
(
3
,
5
,
rng
=
rng
),
random
(
3
,
1
,
rng
=
rng
)])
class
TestCeil
:
class
TestCeil
:
...
@@ -1876,11 +1907,12 @@ class TestDot:
...
@@ -1876,11 +1907,12 @@ class TestDot:
_dot
(
d3
,
d3
)
_dot
(
d3
,
d3
)
def
test_grad
(
self
):
def
test_grad
(
self
):
utt
.
verify_grad
(
dense_dot
,
[
random
(
2
,
3
),
random
(
3
,
2
)])
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
utt
.
verify_grad
(
dense_dot
,
[
random
(
2
),
random
(
2
,
3
)])
utt
.
verify_grad
(
dense_dot
,
[
random
(
2
,
3
,
rng
=
rng
),
random
(
3
,
2
,
rng
=
rng
)])
utt
.
verify_grad
(
dense_dot
,
[
random
(
3
,
2
),
random
(
2
)])
utt
.
verify_grad
(
dense_dot
,
[
random
(
2
,
rng
=
rng
),
random
(
2
,
3
,
rng
=
rng
)])
utt
.
verify_grad
(
dense_dot
,
[
random
(
2
),
random
(
2
)])
utt
.
verify_grad
(
dense_dot
,
[
random
(
3
,
2
,
rng
=
rng
),
random
(
2
,
rng
=
rng
)])
utt
.
verify_grad
(
dense_dot
,
[
random
(),
random
()])
utt
.
verify_grad
(
dense_dot
,
[
random
(
2
,
rng
=
rng
),
random
(
2
,
rng
=
rng
)])
utt
.
verify_grad
(
dense_dot
,
[
random
(
rng
=
rng
),
random
(
rng
=
rng
)])
# TODO: What about the broadcastable conditions in `Dot.grad`?
# TODO: What about the broadcastable conditions in `Dot.grad`?
def
test_broadcastable_patterns
(
self
):
def
test_broadcastable_patterns
(
self
):
...
@@ -1954,13 +1986,14 @@ class TestTensordot:
...
@@ -1954,13 +1986,14 @@ class TestTensordot:
def
test_basic
(
self
):
def
test_basic
(
self
):
# Test vector-vector
# Test vector-vector
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
avec
=
vector
()
avec
=
vector
()
bvec
=
vector
()
bvec
=
vector
()
axes
=
((
0
,),
(
0
,))
axes
=
((
0
,),
(
0
,))
c
=
tensordot
(
avec
,
bvec
,
axes
)
c
=
tensordot
(
avec
,
bvec
,
axes
)
f1
=
inplace_func
([
avec
,
bvec
],
c
)
f1
=
inplace_func
([
avec
,
bvec
],
c
)
aval
=
random
(
5
)
aval
=
random
(
5
,
rng
=
rng
)
bval
=
random
(
5
)
bval
=
random
(
5
,
rng
=
rng
)
out0
=
np
.
tensordot
(
aval
,
bval
,
axes
)
out0
=
np
.
tensordot
(
aval
,
bval
,
axes
)
out1
=
f1
(
aval
,
bval
)
out1
=
f1
(
aval
,
bval
)
utt
.
assert_allclose
(
out0
,
out1
)
utt
.
assert_allclose
(
out0
,
out1
)
...
@@ -1971,8 +2004,8 @@ class TestTensordot:
...
@@ -1971,8 +2004,8 @@ class TestTensordot:
axes
=
((
0
,),
(
1
,))
axes
=
((
0
,),
(
1
,))
c
=
tensordot
(
avec
,
bmat
,
axes
)
c
=
tensordot
(
avec
,
bmat
,
axes
)
f2
=
inplace_func
([
avec
,
bmat
],
c
)
f2
=
inplace_func
([
avec
,
bmat
],
c
)
aval
=
random
(
5
)
aval
=
random
(
5
,
rng
=
rng
)
bval
=
random
(
8
,
5
)
bval
=
random
(
8
,
5
,
rng
=
rng
)
utt
.
assert_allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f2
(
aval
,
bval
))
utt
.
assert_allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f2
(
aval
,
bval
))
utt
.
verify_grad
(
self
.
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
self
.
TensorDot
(
axes
),
[
aval
,
bval
])
...
@@ -1990,8 +2023,8 @@ class TestTensordot:
...
@@ -1990,8 +2023,8 @@ class TestTensordot:
]:
]:
c
=
tensordot
(
amat
,
bmat
,
axes
)
c
=
tensordot
(
amat
,
bmat
,
axes
)
f3
=
inplace_func
([
amat
,
bmat
],
c
)
f3
=
inplace_func
([
amat
,
bmat
],
c
)
aval
=
random
(
*
shps
[
0
])
aval
=
random
(
*
shps
[
0
]
,
rng
=
rng
)
bval
=
random
(
*
shps
[
1
])
bval
=
random
(
*
shps
[
1
]
,
rng
=
rng
)
utt
.
assert_allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f3
(
aval
,
bval
))
utt
.
assert_allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f3
(
aval
,
bval
))
utt
.
verify_grad
(
self
.
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
self
.
TensorDot
(
axes
),
[
aval
,
bval
])
...
@@ -2008,8 +2041,8 @@ class TestTensordot:
...
@@ -2008,8 +2041,8 @@ class TestTensordot:
atens
=
tensor4
()
atens
=
tensor4
()
c
=
tensordot
(
atens
,
bmat
,
axes
)
c
=
tensordot
(
atens
,
bmat
,
axes
)
f4
=
inplace_func
([
atens
,
bmat
],
c
)
f4
=
inplace_func
([
atens
,
bmat
],
c
)
aval
=
random
(
*
shps
[
0
])
aval
=
random
(
*
shps
[
0
]
,
rng
=
rng
)
bval
=
random
(
*
shps
[
1
])
bval
=
random
(
*
shps
[
1
]
,
rng
=
rng
)
utt
.
assert_allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f4
(
aval
,
bval
))
utt
.
assert_allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f4
(
aval
,
bval
))
utt
.
verify_grad
(
self
.
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
self
.
TensorDot
(
axes
),
[
aval
,
bval
])
...
@@ -2019,8 +2052,8 @@ class TestTensordot:
...
@@ -2019,8 +2052,8 @@ class TestTensordot:
axes
=
((
1
,
3
),
(
0
,
2
))
axes
=
((
1
,
3
),
(
0
,
2
))
c
=
tensordot
(
atens
,
btens
,
axes
)
c
=
tensordot
(
atens
,
btens
,
axes
)
f5
=
inplace_func
([
atens
,
btens
],
c
)
f5
=
inplace_func
([
atens
,
btens
],
c
)
aval
=
random
(
4
,
3
,
5
,
2
)
aval
=
random
(
4
,
3
,
5
,
2
,
rng
=
rng
)
bval
=
random
(
3
,
4
,
2
)
bval
=
random
(
3
,
4
,
2
,
rng
=
rng
)
utt
.
assert_allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f5
(
aval
,
bval
))
utt
.
assert_allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f5
(
aval
,
bval
))
utt
.
verify_grad
(
self
.
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
self
.
TensorDot
(
axes
),
[
aval
,
bval
])
...
@@ -2057,24 +2090,26 @@ class TestTensordot:
...
@@ -2057,24 +2090,26 @@ class TestTensordot:
def
test_weird_valid_axes
(
self
):
def
test_weird_valid_axes
(
self
):
# Test matrix-matrix
# Test matrix-matrix
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
amat
=
matrix
()
amat
=
matrix
()
bmat
=
matrix
()
bmat
=
matrix
()
for
axes
in
[
0
,
(
1
,
0
),
[
1
,
0
],
(
1
,
(
0
,)),
((
1
,),
0
),
([
1
],
[
0
]),
([],
[])]:
for
axes
in
[
0
,
(
1
,
0
),
[
1
,
0
],
(
1
,
(
0
,)),
((
1
,),
0
),
([
1
],
[
0
]),
([],
[])]:
c
=
tensordot
(
amat
,
bmat
,
axes
)
c
=
tensordot
(
amat
,
bmat
,
axes
)
f3
=
inplace_func
([
amat
,
bmat
],
c
)
f3
=
inplace_func
([
amat
,
bmat
],
c
)
aval
=
random
(
4
,
7
)
aval
=
random
(
4
,
7
,
rng
=
rng
)
bval
=
random
(
7
,
9
)
bval
=
random
(
7
,
9
,
rng
=
rng
)
utt
.
assert_allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f3
(
aval
,
bval
))
utt
.
assert_allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f3
(
aval
,
bval
))
utt
.
verify_grad
(
self
.
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
self
.
TensorDot
(
axes
),
[
aval
,
bval
])
def
test_scalar_axes
(
self
):
def
test_scalar_axes
(
self
):
# Test matrix-matrix
# Test matrix-matrix
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
amat
=
fmatrix
()
amat
=
fmatrix
()
bmat
=
dmatrix
()
bmat
=
dmatrix
()
# We let at float64 to test mix of float32 and float64.
# We let at float64 to test mix of float32 and float64.
axes
=
1
axes
=
1
aval
=
random
(
4
,
5
)
.
astype
(
"float32"
)
aval
=
random
(
4
,
5
,
rng
=
rng
)
.
astype
(
"float32"
)
bval
=
random
(
5
,
3
)
bval
=
random
(
5
,
3
,
rng
=
rng
)
c
=
tensordot
(
amat
,
bmat
,
axes
)
c
=
tensordot
(
amat
,
bmat
,
axes
)
f3
=
inplace_func
([
amat
,
bmat
],
c
)
f3
=
inplace_func
([
amat
,
bmat
],
c
)
assert
np
.
allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f3
(
aval
,
bval
))
assert
np
.
allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f3
(
aval
,
bval
))
...
@@ -2084,8 +2119,8 @@ class TestTensordot:
...
@@ -2084,8 +2119,8 @@ class TestTensordot:
amat
=
tensor3
()
amat
=
tensor3
()
bmat
=
tensor3
()
bmat
=
tensor3
()
axes
=
2
axes
=
2
aval
=
random
(
3
,
4
,
5
)
aval
=
random
(
3
,
4
,
5
,
rng
=
rng
)
bval
=
random
(
4
,
5
,
3
)
bval
=
random
(
4
,
5
,
3
,
rng
=
rng
)
c
=
tensordot
(
amat
,
bmat
,
axes
)
c
=
tensordot
(
amat
,
bmat
,
axes
)
f3
=
inplace_func
([
amat
,
bmat
],
c
)
f3
=
inplace_func
([
amat
,
bmat
],
c
)
assert
np
.
allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f3
(
aval
,
bval
))
assert
np
.
allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f3
(
aval
,
bval
))
...
@@ -2093,36 +2128,39 @@ class TestTensordot:
...
@@ -2093,36 +2128,39 @@ class TestTensordot:
def
test_scalar0
(
self
):
def
test_scalar0
(
self
):
# Test tensor-tensor
# Test tensor-tensor
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
amat
=
matrix
()
amat
=
matrix
()
bmat
=
matrix
()
bmat
=
matrix
()
axes
=
0
axes
=
0
aval
=
random
(
4
,
5
)
aval
=
random
(
4
,
5
,
rng
=
rng
)
bval
=
random
(
5
,
4
)
bval
=
random
(
5
,
4
,
rng
=
rng
)
c
=
tensordot
(
amat
,
bmat
,
axes
)
c
=
tensordot
(
amat
,
bmat
,
axes
)
f3
=
inplace_func
([
amat
,
bmat
],
c
)
f3
=
inplace_func
([
amat
,
bmat
],
c
)
assert
np
.
allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f3
(
aval
,
bval
))
assert
np
.
allclose
(
np
.
tensordot
(
aval
,
bval
,
axes
),
f3
(
aval
,
bval
))
utt
.
verify_grad
(
self
.
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
self
.
TensorDot
(
axes
),
[
aval
,
bval
])
def
test_broadcastable1
(
self
):
def
test_broadcastable1
(
self
):
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
x
=
TensorType
(
dtype
=
config
.
floatX
,
broadcastable
=
(
True
,
False
,
False
))(
"x"
)
x
=
TensorType
(
dtype
=
config
.
floatX
,
broadcastable
=
(
True
,
False
,
False
))(
"x"
)
y
=
tensor3
(
"y"
)
y
=
tensor3
(
"y"
)
z
=
tensordot
(
x
,
y
)
z
=
tensordot
(
x
,
y
)
assert
z
.
broadcastable
==
(
True
,
False
)
assert
z
.
broadcastable
==
(
True
,
False
)
f
=
inplace_func
([
x
,
y
],
z
)
f
=
inplace_func
([
x
,
y
],
z
)
xv
=
random
(
1
,
3
,
4
)
xv
=
random
(
1
,
3
,
4
,
rng
=
rng
)
yv
=
random
(
3
,
4
,
5
)
yv
=
random
(
3
,
4
,
5
,
rng
=
rng
)
zv
=
f
(
xv
,
yv
)
zv
=
f
(
xv
,
yv
)
assert
np
.
allclose
(
np
.
tensordot
(
xv
,
yv
),
zv
)
assert
np
.
allclose
(
np
.
tensordot
(
xv
,
yv
),
zv
)
def
test_broadcastable2
(
self
):
def
test_broadcastable2
(
self
):
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
x
=
TensorType
(
dtype
=
config
.
floatX
,
broadcastable
=
(
True
,
False
,
False
))(
"x"
)
x
=
TensorType
(
dtype
=
config
.
floatX
,
broadcastable
=
(
True
,
False
,
False
))(
"x"
)
y
=
tensor3
(
"y"
)
y
=
tensor3
(
"y"
)
axes
=
[[
2
,
1
],
[
0
,
1
]]
axes
=
[[
2
,
1
],
[
0
,
1
]]
z
=
tensordot
(
x
,
y
,
axes
=
axes
)
z
=
tensordot
(
x
,
y
,
axes
=
axes
)
assert
z
.
broadcastable
==
(
True
,
False
)
assert
z
.
broadcastable
==
(
True
,
False
)
f
=
inplace_func
([
x
,
y
],
z
)
f
=
inplace_func
([
x
,
y
],
z
)
xv
=
random
(
1
,
3
,
4
)
xv
=
random
(
1
,
3
,
4
,
rng
=
rng
)
yv
=
random
(
4
,
3
,
5
)
yv
=
random
(
4
,
3
,
5
,
rng
=
rng
)
zv
=
f
(
xv
,
yv
)
zv
=
f
(
xv
,
yv
)
assert
np
.
allclose
(
np
.
tensordot
(
xv
,
yv
,
axes
=
axes
),
zv
)
assert
np
.
allclose
(
np
.
tensordot
(
xv
,
yv
,
axes
=
axes
),
zv
)
...
@@ -2426,12 +2464,13 @@ class TestInferShape(utt.InferShapeTester):
...
@@ -2426,12 +2464,13 @@ class TestInferShape(utt.InferShapeTester):
def
test_Dot
(
self
):
def
test_Dot
(
self
):
# Dot
# Dot
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
# vec/vec
# vec/vec
advec
=
dvector
()
advec
=
dvector
()
bdvec
=
dvector
()
bdvec
=
dvector
()
advec_val
=
random
(
4
)
advec_val
=
random
(
4
,
rng
=
rng
)
bdvec_val
=
random
(
4
)
bdvec_val
=
random
(
4
,
rng
=
rng
)
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
advec
,
bdvec
],
[
advec
,
bdvec
],
[
Dot
()(
advec
,
bdvec
)],
[
Dot
()(
advec
,
bdvec
)],
...
@@ -2442,8 +2481,8 @@ class TestInferShape(utt.InferShapeTester):
...
@@ -2442,8 +2481,8 @@ class TestInferShape(utt.InferShapeTester):
# mat/mat
# mat/mat
admat
=
dmatrix
()
admat
=
dmatrix
()
bdmat
=
dmatrix
()
bdmat
=
dmatrix
()
admat_val
=
random
(
4
,
5
)
admat_val
=
random
(
4
,
5
,
rng
=
rng
)
bdmat_val
=
random
(
5
,
3
)
bdmat_val
=
random
(
5
,
3
,
rng
=
rng
)
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
admat
,
bdmat
],
[
admat
,
bdmat
],
[
Dot
()(
admat
,
bdmat
)],
[
Dot
()(
admat
,
bdmat
)],
...
@@ -2452,7 +2491,7 @@ class TestInferShape(utt.InferShapeTester):
...
@@ -2452,7 +2491,7 @@ class TestInferShape(utt.InferShapeTester):
)
)
# vec/mat
# vec/mat
bdmat_val
=
random
(
4
,
5
)
bdmat_val
=
random
(
4
,
5
,
rng
=
rng
)
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
advec
,
bdmat
],
[
advec
,
bdmat
],
[
Dot
()(
advec
,
bdmat
)],
[
Dot
()(
advec
,
bdmat
)],
...
@@ -2461,7 +2500,7 @@ class TestInferShape(utt.InferShapeTester):
...
@@ -2461,7 +2500,7 @@ class TestInferShape(utt.InferShapeTester):
)
)
# mat/vec
# mat/vec
admat_val
=
random
(
5
,
4
)
admat_val
=
random
(
5
,
4
,
rng
=
rng
)
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
admat
,
bdvec
],
[
admat
,
bdvec
],
[
Dot
()(
admat
,
bdvec
)],
[
Dot
()(
admat
,
bdvec
)],
...
@@ -2472,8 +2511,12 @@ class TestInferShape(utt.InferShapeTester):
...
@@ -2472,8 +2511,12 @@ class TestInferShape(utt.InferShapeTester):
class
TestTensorInstanceMethods
:
class
TestTensorInstanceMethods
:
def
setup_method
(
self
):
def
setup_method
(
self
):
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
self
.
vars
=
matrices
(
"X"
,
"Y"
)
self
.
vars
=
matrices
(
"X"
,
"Y"
)
self
.
vals
=
[
m
.
astype
(
config
.
floatX
)
for
m
in
[
random
(
2
,
2
),
random
(
2
,
2
)]]
self
.
vals
=
[
m
.
astype
(
config
.
floatX
)
for
m
in
[
random
(
2
,
2
,
rng
=
rng
),
random
(
2
,
2
,
rng
=
rng
)]
]
def
test_argmin
(
self
):
def
test_argmin
(
self
):
X
,
_
=
self
.
vars
X
,
_
=
self
.
vars
...
@@ -2833,6 +2876,7 @@ class TestSumProdReduceDtype:
...
@@ -2833,6 +2876,7 @@ class TestSumProdReduceDtype:
assert
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
self
.
op
)],
(
topo
,
dtype
)
assert
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
self
.
op
)],
(
topo
,
dtype
)
data
=
np
.
random
.
random
((
3
,
4
))
*
10
data
=
np
.
random
.
random
((
3
,
4
))
*
10
data
=
data
.
astype
(
dtype
)
data
=
data
.
astype
(
dtype
)
# TODO FIXME: This is a bad test
f
(
data
)
f
(
data
)
def
test_reduce_default_acc_dtype
(
self
):
def
test_reduce_default_acc_dtype
(
self
):
...
@@ -2864,6 +2908,7 @@ class TestSumProdReduceDtype:
...
@@ -2864,6 +2908,7 @@ class TestSumProdReduceDtype:
assert
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
self
.
op
)],
(
topo
,
dtype
)
assert
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
self
.
op
)],
(
topo
,
dtype
)
data
=
np
.
random
.
random
((
3
,
4
))
*
10
data
=
np
.
random
.
random
((
3
,
4
))
*
10
data
=
data
.
astype
(
dtype
)
data
=
data
.
astype
(
dtype
)
# TODO FIXME: This is a bad test
f
(
data
)
f
(
data
)
@pytest.mark.slow
@pytest.mark.slow
...
@@ -2905,10 +2950,12 @@ class TestSumProdReduceDtype:
...
@@ -2905,10 +2950,12 @@ class TestSumProdReduceDtype:
# or the overflow will be different between CPU and GPU,
# or the overflow will be different between CPU and GPU,
# and DebugMode will complain.
# and DebugMode will complain.
data
=
data
[
0
:
1
]
data
=
data
[
0
:
1
]
# TODO FIXME: This is a bad test
f
(
data
)
f
(
data
)
if
"complex"
in
input_dtype
:
if
"complex"
in
input_dtype
:
continue
continue
# Check that we can take the gradient
# Check that we can take the gradient
# TODO FIXME: This is a bad test
grad
(
var
.
sum
(),
x
,
disconnected_inputs
=
"ignore"
)
grad
(
var
.
sum
(),
x
,
disconnected_inputs
=
"ignore"
)
idx
+=
1
idx
+=
1
...
@@ -2943,6 +2990,7 @@ class TestSumProdReduceDtype:
...
@@ -2943,6 +2990,7 @@ class TestSumProdReduceDtype:
if
"complex"
in
input_dtype
:
if
"complex"
in
input_dtype
:
continue
continue
# Check that we can take the gradient
# Check that we can take the gradient
# TODO FIXME: This is a bad test
grad
(
var
.
sum
(),
x
,
disconnected_inputs
=
"ignore"
)
grad
(
var
.
sum
(),
x
,
disconnected_inputs
=
"ignore"
)
else
:
else
:
with
pytest
.
raises
(
TypeError
):
with
pytest
.
raises
(
TypeError
):
...
@@ -2981,6 +3029,7 @@ class TestMeanDtype:
...
@@ -2981,6 +3029,7 @@ class TestMeanDtype:
f
=
function
([
x
],
m
)
f
=
function
([
x
],
m
)
data
=
np
.
random
.
random
((
3
,
4
))
*
10
data
=
np
.
random
.
random
((
3
,
4
))
*
10
data
=
data
.
astype
(
dtype
)
data
=
data
.
astype
(
dtype
)
# TODO FIXME: This is a bad test
f
(
data
)
f
(
data
)
@pytest.mark.slow
@pytest.mark.slow
...
@@ -3013,6 +3062,7 @@ class TestMeanDtype:
...
@@ -3013,6 +3062,7 @@ class TestMeanDtype:
f
=
function
([
x
],
mean_var
)
f
=
function
([
x
],
mean_var
)
data
=
np
.
random
.
random
((
3
,
4
))
*
10
data
=
np
.
random
.
random
((
3
,
4
))
*
10
data
=
data
.
astype
(
input_dtype
)
data
=
data
.
astype
(
input_dtype
)
# TODO FIXME: This is a bad test
f
(
data
)
f
(
data
)
# Check that we can take the gradient, when implemented
# Check that we can take the gradient, when implemented
if
"complex"
in
mean_var
.
dtype
:
if
"complex"
in
mean_var
.
dtype
:
...
@@ -3090,6 +3140,7 @@ class TestProdWithoutZerosDtype:
...
@@ -3090,6 +3140,7 @@ class TestProdWithoutZerosDtype:
f
=
function
([
x
],
p
)
f
=
function
([
x
],
p
)
data
=
np
.
random
.
random
((
2
,
3
))
*
3
data
=
np
.
random
.
random
((
2
,
3
))
*
3
data
=
data
.
astype
(
dtype
)
data
=
data
.
astype
(
dtype
)
# TODO FIXME: This is a bad test
f
(
data
)
f
(
data
)
@pytest.mark.slow
@pytest.mark.slow
...
@@ -3111,6 +3162,7 @@ class TestProdWithoutZerosDtype:
...
@@ -3111,6 +3162,7 @@ class TestProdWithoutZerosDtype:
f
=
function
([
x
],
prod_woz_var
)
f
=
function
([
x
],
prod_woz_var
)
data
=
np
.
random
.
random
((
2
,
3
))
*
3
data
=
np
.
random
.
random
((
2
,
3
))
*
3
data
=
data
.
astype
(
input_dtype
)
data
=
data
.
astype
(
input_dtype
)
# TODO FIXME: This is a bad test
f
(
data
)
f
(
data
)
@pytest.mark.slow
@pytest.mark.slow
...
@@ -3138,6 +3190,7 @@ class TestProdWithoutZerosDtype:
...
@@ -3138,6 +3190,7 @@ class TestProdWithoutZerosDtype:
f
=
function
([
x
],
prod_woz_var
)
f
=
function
([
x
],
prod_woz_var
)
data
=
np
.
random
.
random
((
2
,
3
))
*
3
data
=
np
.
random
.
random
((
2
,
3
))
*
3
data
=
data
.
astype
(
input_dtype
)
data
=
data
.
astype
(
input_dtype
)
# TODO FIXME: This is a bad test
f
(
data
)
f
(
data
)
else
:
else
:
with
pytest
.
raises
(
TypeError
):
with
pytest
.
raises
(
TypeError
):
...
@@ -3151,36 +3204,42 @@ class TestSumMeanMaxMinArgMaxVarReduceAxes:
...
@@ -3151,36 +3204,42 @@ class TestSumMeanMaxMinArgMaxVarReduceAxes:
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
np
.
array
(
1
),
[
np
.
array
(
0
),
np
.
array
(
1
)]]
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
np
.
array
(
1
),
[
np
.
array
(
0
),
np
.
array
(
1
)]]
for
a
in
axes
:
for
a
in
axes
:
x
=
matrix
()
x
=
matrix
()
# TODO FIXME: This is a bad test
x
.
sum
(
a
)
x
.
sum
(
a
)
def
test_mean_axes
(
self
):
def
test_mean_axes
(
self
):
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
np
.
array
(
1
),
[
np
.
array
(
0
),
np
.
array
(
1
)]]
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
np
.
array
(
1
),
[
np
.
array
(
0
),
np
.
array
(
1
)]]
for
a
in
axes
:
for
a
in
axes
:
x
=
matrix
()
x
=
matrix
()
# TODO FIXME: This is a bad test
x
.
mean
(
a
)
x
.
mean
(
a
)
def
test_max_axes
(
self
):
def
test_max_axes
(
self
):
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
np
.
array
(
1
),
[
np
.
array
(
0
),
np
.
array
(
1
)]]
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
np
.
array
(
1
),
[
np
.
array
(
0
),
np
.
array
(
1
)]]
for
a
in
axes
:
for
a
in
axes
:
x
=
matrix
()
x
=
matrix
()
# TODO FIXME: This is a bad test
x
.
max
(
a
)
x
.
max
(
a
)
def
test_min_axes
(
self
):
def
test_min_axes
(
self
):
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
np
.
array
(
1
),
[
np
.
array
(
0
),
np
.
array
(
1
)]]
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
np
.
array
(
1
),
[
np
.
array
(
0
),
np
.
array
(
1
)]]
for
a
in
axes
:
for
a
in
axes
:
x
=
matrix
()
x
=
matrix
()
# TODO FIXME: This is a bad test
x
.
min
(
a
)
x
.
min
(
a
)
def
test_argmax_axes
(
self
):
def
test_argmax_axes
(
self
):
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
np
.
array
(
1
),
[
np
.
array
(
0
),
np
.
array
(
1
)]]
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
np
.
array
(
1
),
[
np
.
array
(
0
),
np
.
array
(
1
)]]
for
a
in
axes
:
for
a
in
axes
:
x
=
matrix
()
x
=
matrix
()
# TODO FIXME: This is a bad test
x
.
argmax
(
a
)
x
.
argmax
(
a
)
def
test_var_axes
(
self
):
def
test_var_axes
(
self
):
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
np
.
array
(
1
),
[
np
.
array
(
0
),
np
.
array
(
1
)]]
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
np
.
array
(
1
),
[
np
.
array
(
0
),
np
.
array
(
1
)]]
for
a
in
axes
:
for
a
in
axes
:
x
=
matrix
()
x
=
matrix
()
# TODO FIXME: This is a bad test
x
.
var
(
a
)
x
.
var
(
a
)
...
@@ -3212,12 +3271,12 @@ def test_clip_grad():
...
@@ -3212,12 +3271,12 @@ def test_clip_grad():
def
test_clip_grad_int
():
def
test_clip_grad_int
():
# FIXME: This is not a real test.
# test that integers don't crash clip gradient
# test that integers don't crash clip gradient
x
=
iscalar
()
x
=
iscalar
()
y
=
iscalar
()
y
=
iscalar
()
z
=
iscalar
()
z
=
iscalar
()
c
=
clip
(
x
,
y
,
z
)
c
=
clip
(
x
,
y
,
z
)
# TODO FIXME: This is a bad test
grad
(
c
,
[
x
,
y
,
z
])
grad
(
c
,
[
x
,
y
,
z
])
...
@@ -3265,8 +3324,11 @@ def test_tanh_grad_broadcast():
...
@@ -3265,8 +3324,11 @@ def test_tanh_grad_broadcast():
x
=
tensor
(
dtype
=
"float32"
,
broadcastable
=
(
True
,
False
,
False
,
False
))
x
=
tensor
(
dtype
=
"float32"
,
broadcastable
=
(
True
,
False
,
False
,
False
))
y
=
tensor
(
dtype
=
"float32"
,
broadcastable
=
(
True
,
True
,
False
,
False
))
y
=
tensor
(
dtype
=
"float32"
,
broadcastable
=
(
True
,
True
,
False
,
False
))
# TODO FIXME: This is a bad test
grad
(
tanh
(
x
)
.
sum
(),
x
)
grad
(
tanh
(
x
)
.
sum
(),
x
)
# TODO FIXME: This is a bad test
grad
(
tanh
(
x
+
y
)
.
sum
(),
y
)
grad
(
tanh
(
x
+
y
)
.
sum
(),
y
)
# TODO FIXME: This is a bad test
grad
(
tanh
(
x
+
y
)
.
sum
(),
[
x
,
y
])
grad
(
tanh
(
x
+
y
)
.
sum
(),
[
x
,
y
])
...
...
tests/tensor/test_math_scipy.py
浏览文件 @
dfd047ef
...
@@ -146,17 +146,18 @@ TestErfcinvBroadcast = makeBroadcastTester(
...
@@ -146,17 +146,18 @@ TestErfcinvBroadcast = makeBroadcastTester(
mode
=
mode_no_scipy
,
mode
=
mode_no_scipy
,
)
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_good_broadcast_unary_gammaln
=
dict
(
_good_broadcast_unary_gammaln
=
dict
(
normal
=
(
random_ranged
(
-
1
+
1e-2
,
10
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
-
1
+
1e-2
,
10
,
(
2
,
3
)
,
rng
=
rng
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
int
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
)),),
int
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
)
,
rng
=
rng
),),
uint8
=
(
integers_ranged
(
1
,
6
,
(
2
,
3
))
.
astype
(
"uint8"
),),
uint8
=
(
integers_ranged
(
1
,
6
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint8"
),),
uint16
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
))
.
astype
(
"uint16"
),),
uint16
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint16"
),),
uint64
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
))
.
astype
(
"uint64"
),),
uint64
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint64"
),),
)
)
_grad_broadcast_unary_gammaln
=
dict
(
_grad_broadcast_unary_gammaln
=
dict
(
# smaller range as our grad method does not estimate it well enough.
# smaller range as our grad method does not estimate it well enough.
normal
=
(
random_ranged
(
1e-1
,
8
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
1e-1
,
8
,
(
2
,
3
)
,
rng
=
rng
),),
)
)
TestGammaBroadcast
=
makeBroadcastTester
(
TestGammaBroadcast
=
makeBroadcastTester
(
...
@@ -193,12 +194,13 @@ TestGammalnInplaceBroadcast = makeBroadcastTester(
...
@@ -193,12 +194,13 @@ TestGammalnInplaceBroadcast = makeBroadcastTester(
inplace
=
True
,
inplace
=
True
,
)
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_good_broadcast_unary_psi
=
dict
(
_good_broadcast_unary_psi
=
dict
(
normal
=
(
random_ranged
(
1
,
10
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
1
,
10
,
(
2
,
3
)
,
rng
=
rng
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
int
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
)),),
int
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
)
,
rng
=
rng
),),
uint8
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
))
.
astype
(
"uint8"
),),
uint8
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint8"
),),
uint16
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
))
.
astype
(
"uint16"
),),
uint16
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint16"
),),
)
)
TestPsiBroadcast
=
makeBroadcastTester
(
TestPsiBroadcast
=
makeBroadcastTester
(
...
@@ -254,21 +256,28 @@ TestChi2SFInplaceBroadcast = makeBroadcastTester(
...
@@ -254,21 +256,28 @@ TestChi2SFInplaceBroadcast = makeBroadcastTester(
name
=
"Chi2SF"
,
name
=
"Chi2SF"
,
)
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_good_broadcast_binary_gamma
=
dict
(
_good_broadcast_binary_gamma
=
dict
(
normal
=
(
random_ranged
(
1e-2
,
10
,
(
2
,
3
)),
random_ranged
(
1e-2
,
10
,
(
2
,
3
))),
normal
=
(
random_ranged
(
1e-2
,
10
,
(
2
,
3
),
rng
=
rng
),
random_ranged
(
1e-2
,
10
,
(
2
,
3
),
rng
=
rng
),
),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([],
dtype
=
config
.
floatX
)),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([],
dtype
=
config
.
floatX
)),
int
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
)),
integers_ranged
(
1
,
10
,
(
2
,
3
))),
int
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
),
rng
=
rng
),
integers_ranged
(
1
,
10
,
(
2
,
3
),
rng
=
rng
),
),
uint8
=
(
uint8
=
(
integers_ranged
(
1
,
6
,
(
2
,
3
))
.
astype
(
"uint8"
),
integers_ranged
(
1
,
6
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint8"
),
integers_ranged
(
1
,
6
,
(
2
,
3
))
.
astype
(
"uint8"
),
integers_ranged
(
1
,
6
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint8"
),
),
),
uint16
=
(
uint16
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
))
.
astype
(
"uint16"
),
integers_ranged
(
1
,
10
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint16"
),
integers_ranged
(
1
,
10
,
(
2
,
3
))
.
astype
(
"uint16"
),
integers_ranged
(
1
,
10
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint16"
),
),
),
uint64
=
(
uint64
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
))
.
astype
(
"uint64"
),
integers_ranged
(
1
,
10
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint64"
),
integers_ranged
(
1
,
10
,
(
2
,
3
))
.
astype
(
"uint64"
),
integers_ranged
(
1
,
10
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint64"
),
),
),
)
)
...
@@ -397,12 +406,13 @@ TestGammaLInplaceBroadcast = makeBroadcastTester(
...
@@ -397,12 +406,13 @@ TestGammaLInplaceBroadcast = makeBroadcastTester(
inplace
=
True
,
inplace
=
True
,
)
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_good_broadcast_unary_bessel
=
dict
(
_good_broadcast_unary_bessel
=
dict
(
normal
=
(
random_ranged
(
-
10
,
10
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
-
10
,
10
,
(
2
,
3
)
,
rng
=
rng
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
int
=
(
integers_ranged
(
-
10
,
10
,
(
2
,
3
)),),
int
=
(
integers_ranged
(
-
10
,
10
,
(
2
,
3
)
,
rng
=
rng
),),
uint8
=
(
integers_ranged
(
0
,
10
,
(
2
,
3
))
.
astype
(
"uint8"
),),
uint8
=
(
integers_ranged
(
0
,
10
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint8"
),),
uint16
=
(
integers_ranged
(
0
,
10
,
(
2
,
3
))
.
astype
(
"uint16"
),),
uint16
=
(
integers_ranged
(
0
,
10
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint16"
),),
)
)
_grad_broadcast_unary_bessel
=
dict
(
_grad_broadcast_unary_bessel
=
dict
(
...
@@ -410,21 +420,27 @@ _grad_broadcast_unary_bessel = dict(
...
@@ -410,21 +420,27 @@ _grad_broadcast_unary_bessel = dict(
)
)
_good_broadcast_binary_bessel
=
dict
(
_good_broadcast_binary_bessel
=
dict
(
normal
=
(
random_ranged
(
-
5
,
5
,
(
2
,
3
)),
random_ranged
(
0
,
10
,
(
2
,
3
))),
normal
=
(
random_ranged
(
-
5
,
5
,
(
2
,
3
),
rng
=
rng
),
random_ranged
(
0
,
10
,
(
2
,
3
),
rng
=
rng
),
),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([],
dtype
=
config
.
floatX
)),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([],
dtype
=
config
.
floatX
)),
integers
=
(
integers_ranged
(
-
5
,
5
,
(
2
,
3
)),
integers_ranged
(
-
10
,
10
,
(
2
,
3
))),
integers
=
(
integers_ranged
(
-
5
,
5
,
(
2
,
3
),
rng
=
rng
),
integers_ranged
(
-
10
,
10
,
(
2
,
3
),
rng
=
rng
),
),
uint8
=
(
uint8
=
(
integers_ranged
(
0
,
5
,
(
2
,
3
))
.
astype
(
"uint8"
),
integers_ranged
(
0
,
5
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint8"
),
integers_ranged
(
0
,
10
,
(
2
,
3
))
.
astype
(
"uint8"
),
integers_ranged
(
0
,
10
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint8"
),
),
),
uint16
=
(
uint16
=
(
integers_ranged
(
0
,
5
,
(
2
,
3
))
.
astype
(
"uint16"
),
integers_ranged
(
0
,
5
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint16"
),
integers_ranged
(
0
,
10
,
(
2
,
3
))
.
astype
(
"uint16"
),
integers_ranged
(
0
,
10
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint16"
),
),
),
)
)
_grad_broadcast_binary_bessel
=
dict
(
_grad_broadcast_binary_bessel
=
dict
(
normal
=
(
random_ranged
(
1
,
5
,
(
2
,
3
)
),
random_ranged
(
0
,
10
,
(
2
,
3
)
))
normal
=
(
random_ranged
(
1
,
5
,
(
2
,
3
)
,
rng
=
rng
),
random_ranged
(
0
,
10
,
(
2
,
3
),
rng
=
rng
))
)
)
TestJ0Broadcast
=
makeBroadcastTester
(
TestJ0Broadcast
=
makeBroadcastTester
(
...
@@ -625,11 +641,12 @@ class TestSoftplus:
...
@@ -625,11 +641,12 @@ class TestSoftplus:
np
.
testing
.
assert_allclose
(
y_th
,
y_np
,
rtol
=
10e-10
)
np
.
testing
.
assert_allclose
(
y_th
,
y_np
,
rtol
=
10e-10
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_good_broadcast_unary_log1mexp
=
dict
(
_good_broadcast_unary_log1mexp
=
dict
(
normal
=
(
random_ranged
(
-
10.0
,
0
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
-
10.0
,
0
,
(
2
,
3
)
,
rng
=
rng
),),
float32
=
(
random_ranged
(
-
10.0
,
0
,
(
2
,
3
))
.
astype
(
"float32"
),),
float32
=
(
random_ranged
(
-
10.0
,
0
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"float32"
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
int
=
(
integers_ranged
(
-
10
,
-
1
,
(
2
,
3
)),),
int
=
(
integers_ranged
(
-
10
,
-
1
,
(
2
,
3
)
,
rng
=
rng
),),
)
)
_grad_broadcast_unary_log1mexp
=
dict
(
_grad_broadcast_unary_log1mexp
=
dict
(
...
...
tests/tensor/utils.py
浏览文件 @
dfd047ef
...
@@ -32,8 +32,6 @@ if config.floatX == "float32":
...
@@ -32,8 +32,6 @@ if config.floatX == "float32":
# This is probably caused by our way of computing the gradient error.
# This is probably caused by our way of computing the gradient error.
div_grad_rtol
=
0.025
div_grad_rtol
=
0.025
# Use a seeded random number generator so that unittests are deterministic
test_rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
# In order to check random values close to the boundaries when designing
# In order to check random values close to the boundaries when designing
# new tests, you can use utt.MockRandomState, for instance:
# new tests, you can use utt.MockRandomState, for instance:
# test_rng = MockRandomState(0)
# test_rng = MockRandomState(0)
...
@@ -247,15 +245,19 @@ def upcast_int8_nfunc(fn):
...
@@ -247,15 +245,19 @@ def upcast_int8_nfunc(fn):
return
ret
return
ret
def
random
(
*
shape
):
def
random
(
*
shape
,
rng
=
None
):
r
=
test_rng
.
random
(
shape
)
*
2
-
1
if
rng
is
None
:
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
r
=
rng
.
random
(
shape
)
*
2
-
1
return
np
.
asarray
(
r
,
dtype
=
config
.
floatX
)
return
np
.
asarray
(
r
,
dtype
=
config
.
floatX
)
def
random_nonzero
(
shape
,
eps
=
3e-4
):
def
random_nonzero
(
shape
,
eps
=
3e-4
,
rng
=
None
):
if
rng
is
None
:
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
# Like random, but the absolute value has to be at least eps
# Like random, but the absolute value has to be at least eps
# covers [0, 1)
# covers [0, 1)
r
=
np
.
asarray
(
test_
rng
.
random
(
shape
),
dtype
=
config
.
floatX
)
r
=
np
.
asarray
(
rng
.
random
(
shape
),
dtype
=
config
.
floatX
)
# covers [0, (1 - eps) / 2) U [(1 + eps) / 2, 1)
# covers [0, (1 - eps) / 2) U [(1 + eps) / 2, 1)
r
=
r
*
(
1
-
eps
)
+
eps
*
(
r
>=
0.5
)
r
=
r
*
(
1
-
eps
)
+
eps
*
(
r
>=
0.5
)
# covers [-1, -eps) U [eps, 1)
# covers [-1, -eps) U [eps, 1)
...
@@ -263,52 +265,68 @@ def random_nonzero(shape, eps=3e-4):
...
@@ -263,52 +265,68 @@ def random_nonzero(shape, eps=3e-4):
return
r
return
r
def
integers
(
*
shape
):
def
integers
(
*
shape
,
rng
=
None
):
return
test_rng
.
integers
(
-
5
,
6
,
shape
)
if
rng
is
None
:
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
return
rng
.
integers
(
-
5
,
6
,
shape
)
def
integers_uint32
(
*
shape
):
def
integers_uint32
(
*
shape
,
rng
=
None
):
return
np
.
array
(
test_rng
.
integers
(
5
,
size
=
shape
),
dtype
=
np
.
uint32
)
if
rng
is
None
:
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
return
np
.
array
(
rng
.
integers
(
5
,
size
=
shape
),
dtype
=
np
.
uint32
)
def
integers_uint16
(
*
shape
):
def
integers_uint16
(
*
shape
,
rng
=
None
):
return
np
.
array
(
test_rng
.
integers
(
5
,
size
=
shape
),
dtype
=
np
.
uint16
)
if
rng
is
None
:
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
return
np
.
array
(
rng
.
integers
(
5
,
size
=
shape
),
dtype
=
np
.
uint16
)
# XXX: this so-called complex random array as all-zero imaginary parts
# XXX: this so-called complex random array as all-zero imaginary parts
def
random_complex
(
*
shape
):
def
random_complex
(
*
shape
,
rng
=
None
):
r
=
np
.
asarray
(
test_rng
.
random
(
shape
),
dtype
=
config
.
floatX
)
if
rng
is
None
:
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
r
=
np
.
asarray
(
rng
.
random
(
shape
),
dtype
=
config
.
floatX
)
return
np
.
complex128
(
2
*
r
-
1
)
return
np
.
complex128
(
2
*
r
-
1
)
def
random_complex_nonzero
(
shape
,
eps
=
1e-4
):
def
random_complex_nonzero
(
shape
,
eps
=
1e-4
,
rng
=
None
):
return
np
.
complex128
(
random_nonzero
(
shape
,
eps
))
return
np
.
complex128
(
random_nonzero
(
shape
,
eps
,
rng
=
rng
))
def
integers_nonzero
(
*
shape
):
def
integers_nonzero
(
*
shape
,
rng
=
None
):
r
=
test_rng
.
integers
(
-
5
,
5
,
shape
)
if
rng
is
None
:
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
r
=
rng
.
integers
(
-
5
,
5
,
shape
)
return
r
+
(
r
==
0
)
*
5
return
r
+
(
r
==
0
)
*
5
def
random_ranged
(
min
,
max
,
shape
):
def
random_ranged
(
min
,
max
,
shape
,
rng
=
None
):
return
np
.
asarray
(
test_rng
.
random
(
shape
)
*
(
max
-
min
)
+
min
,
dtype
=
config
.
floatX
)
if
rng
is
None
:
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
return
np
.
asarray
(
rng
.
random
(
shape
)
*
(
max
-
min
)
+
min
,
dtype
=
config
.
floatX
)
def
integers_ranged
(
min
,
max
,
shape
):
def
integers_ranged
(
min
,
max
,
shape
,
rng
=
None
):
return
test_rng
.
integers
(
min
,
max
+
1
,
shape
)
if
rng
is
None
:
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
return
rng
.
integers
(
min
,
max
+
1
,
shape
)
def
random_complex128_ranged
(
min
,
max
,
shape
):
def
random_complex128_ranged
(
min
,
max
,
shape
,
rng
=
None
):
return
np
.
asarray
(
test_rng
.
random
(
shape
)
*
(
max
-
min
)
+
min
,
dtype
=
"complex128"
)
if
rng
is
None
:
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
return
np
.
asarray
(
rng
.
random
(
shape
)
*
(
max
-
min
)
+
min
,
dtype
=
"complex128"
)
def
random_of_dtype
(
shape
,
dtype
):
def
random_of_dtype
(
shape
,
dtype
,
rng
=
None
):
if
dtype
in
discrete_dtypes
:
if
dtype
in
discrete_dtypes
:
return
integers
(
*
shape
)
.
astype
(
dtype
)
return
integers
(
*
shape
,
rng
=
rng
)
.
astype
(
dtype
)
elif
dtype
in
float_dtypes
:
elif
dtype
in
float_dtypes
:
return
random
(
*
shape
)
.
astype
(
dtype
)
return
random
(
*
shape
,
rng
=
rng
)
.
astype
(
dtype
)
elif
dtype
in
complex_dtypes
:
elif
dtype
in
complex_dtypes
:
return
random_complex
(
*
shape
)
.
astype
(
dtype
)
return
random_complex
(
*
shape
,
rng
=
rng
)
.
astype
(
dtype
)
else
:
else
:
raise
TypeError
()
raise
TypeError
()
...
@@ -736,28 +754,30 @@ corner_case_grad = np.asarray(
...
@@ -736,28 +754,30 @@ corner_case_grad = np.asarray(
dtype
=
config
.
floatX
,
dtype
=
config
.
floatX
,
)
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_good_broadcast_unary_normal
=
dict
(
_good_broadcast_unary_normal
=
dict
(
normal
=
[
np
.
asarray
(
random_ranged
(
-
5
,
5
,
(
2
,
3
)),
dtype
=
config
.
floatX
)],
normal
=
[
np
.
asarray
(
random_ranged
(
-
5
,
5
,
(
2
,
3
)
,
rng
=
rng
),
dtype
=
config
.
floatX
)],
integers
=
[
integers_ranged
(
-
5
,
5
,
(
2
,
3
))],
integers
=
[
integers_ranged
(
-
5
,
5
,
(
2
,
3
)
,
rng
=
rng
)],
# not using -128 because np.allclose would return False
# not using -128 because np.allclose would return False
int8
=
[
np
.
arange
(
-
127
,
128
,
dtype
=
"int8"
)],
int8
=
[
np
.
arange
(
-
127
,
128
,
dtype
=
"int8"
)],
uint8
=
[
np
.
arange
(
0
,
255
,
dtype
=
"uint8"
)],
uint8
=
[
np
.
arange
(
0
,
255
,
dtype
=
"uint8"
)],
uint16
=
[
np
.
arange
(
0
,
65535
,
dtype
=
"uint16"
)],
uint16
=
[
np
.
arange
(
0
,
65535
,
dtype
=
"uint16"
)],
corner_case
=
[
corner_case
],
corner_case
=
[
corner_case
],
complex
=
[
random_complex
(
2
,
3
)],
complex
=
[
random_complex
(
2
,
3
,
rng
=
rng
)],
empty
=
[
np
.
asarray
([],
dtype
=
config
.
floatX
)],
empty
=
[
np
.
asarray
([],
dtype
=
config
.
floatX
)],
)
)
_grad_broadcast_unary_normal
=
dict
(
_grad_broadcast_unary_normal
=
dict
(
normal
=
[
np
.
asarray
(
random_ranged
(
-
5
,
5
,
(
2
,
3
)),
dtype
=
config
.
floatX
)],
normal
=
[
np
.
asarray
(
random_ranged
(
-
5
,
5
,
(
2
,
3
)
,
rng
=
rng
),
dtype
=
config
.
floatX
)],
corner_case
=
[
corner_case_grad
],
corner_case
=
[
corner_case_grad
],
# empty = [np.asarray([])] # XXX: should this be included?
# empty = [np.asarray([])] # XXX: should this be included?
)
)
_good_broadcast_unary_normal_float
=
dict
(
_good_broadcast_unary_normal_float
=
dict
(
normal
=
[
random_ranged
(
-
5
,
5
,
(
2
,
3
))],
normal
=
[
random_ranged
(
-
5
,
5
,
(
2
,
3
)
,
rng
=
rng
)],
corner_case
=
[
corner_case
],
corner_case
=
[
corner_case
],
complex
=
[
random_complex
(
2
,
3
)],
complex
=
[
random_complex
(
2
,
3
,
rng
=
rng
)],
empty
=
[
np
.
asarray
([],
dtype
=
config
.
floatX
)],
empty
=
[
np
.
asarray
([],
dtype
=
config
.
floatX
)],
)
)
...
@@ -766,47 +786,54 @@ _good_broadcast_unary_normal_float_no_complex = copymod(
...
@@ -766,47 +786,54 @@ _good_broadcast_unary_normal_float_no_complex = copymod(
)
)
_good_broadcast_unary_normal_float_no_complex_small_neg_range
=
dict
(
_good_broadcast_unary_normal_float_no_complex_small_neg_range
=
dict
(
normal
=
[
random_ranged
(
-
2
,
5
,
(
2
,
3
))],
normal
=
[
random_ranged
(
-
2
,
5
,
(
2
,
3
)
,
rng
=
rng
)],
corner_case
=
[
corner_case
],
corner_case
=
[
corner_case
],
empty
=
[
np
.
asarray
([],
dtype
=
config
.
floatX
)],
empty
=
[
np
.
asarray
([],
dtype
=
config
.
floatX
)],
)
)
_grad_broadcast_unary_normal_small_neg_range
=
dict
(
_grad_broadcast_unary_normal_small_neg_range
=
dict
(
normal
=
[
np
.
asarray
(
random_ranged
(
-
2
,
5
,
(
2
,
3
)),
dtype
=
config
.
floatX
)],
normal
=
[
np
.
asarray
(
random_ranged
(
-
2
,
5
,
(
2
,
3
)
,
rng
=
rng
),
dtype
=
config
.
floatX
)],
corner_case
=
[
corner_case_grad
],
corner_case
=
[
corner_case_grad
],
)
)
_grad_broadcast_unary_abs1_no_complex
=
dict
(
_grad_broadcast_unary_abs1_no_complex
=
dict
(
normal
=
[
normal
=
[
np
.
asarray
(
random_ranged
(
-
1
+
_eps
,
1
-
_eps
,
(
2
,
3
)),
dtype
=
config
.
floatX
)
np
.
asarray
(
random_ranged
(
-
1
+
_eps
,
1
-
_eps
,
(
2
,
3
),
rng
=
rng
),
dtype
=
config
.
floatX
)
],
],
)
)
_grad_broadcast_unary_0_2_no_complex
=
dict
(
_grad_broadcast_unary_0_2_no_complex
=
dict
(
# Don't go too close to 0 or 2 for tests in float32
# Don't go too close to 0 or 2 for tests in float32
normal
=
[
np
.
asarray
(
random_ranged
(
_eps
,
1
-
_eps
,
(
2
,
3
)),
dtype
=
config
.
floatX
)],
normal
=
[
np
.
asarray
(
random_ranged
(
_eps
,
1
-
_eps
,
(
2
,
3
),
rng
=
rng
),
dtype
=
config
.
floatX
)
],
)
)
# chi2sf takes two inputs, a value (x) and a degrees of freedom (k).
# chi2sf takes two inputs, a value (x) and a degrees of freedom (k).
# not sure how to deal with that here...
# not sure how to deal with that here...
_good_broadcast_unary_chi2sf
=
dict
(
_good_broadcast_unary_chi2sf
=
dict
(
normal
=
(
random_ranged
(
1
,
10
,
(
2
,
3
)),
np
.
asarray
(
1
,
dtype
=
config
.
floatX
)),
normal
=
(
random_ranged
(
1
,
10
,
(
2
,
3
)
,
rng
=
rng
),
np
.
asarray
(
1
,
dtype
=
config
.
floatX
)),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
(
1
,
dtype
=
config
.
floatX
)),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
(
1
,
dtype
=
config
.
floatX
)),
integers
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
)),
np
.
asarray
(
1
,
dtype
=
config
.
floatX
)),
integers
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
),
rng
=
rng
),
np
.
asarray
(
1
,
dtype
=
config
.
floatX
),
),
uint8
=
(
uint8
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
))
.
astype
(
"uint8"
),
integers_ranged
(
1
,
10
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint8"
),
np
.
asarray
(
1
,
dtype
=
config
.
floatX
),
np
.
asarray
(
1
,
dtype
=
config
.
floatX
),
),
),
uint16
=
(
uint16
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
))
.
astype
(
"uint16"
),
integers_ranged
(
1
,
10
,
(
2
,
3
)
,
rng
=
rng
)
.
astype
(
"uint16"
),
np
.
asarray
(
1
,
dtype
=
config
.
floatX
),
np
.
asarray
(
1
,
dtype
=
config
.
floatX
),
),
),
)
)
_good_broadcast_unary_normal_no_complex
=
dict
(
_good_broadcast_unary_normal_no_complex
=
dict
(
normal
=
[
np
.
asarray
(
random_ranged
(
-
5
,
5
,
(
2
,
3
)),
dtype
=
config
.
floatX
)],
normal
=
[
np
.
asarray
(
random_ranged
(
-
5
,
5
,
(
2
,
3
)
,
rng
=
rng
),
dtype
=
config
.
floatX
)],
integers
=
[
integers_ranged
(
-
5
,
5
,
(
2
,
3
))],
integers
=
[
integers_ranged
(
-
5
,
5
,
(
2
,
3
)
,
rng
=
rng
)],
int8
=
[
np
.
arange
(
-
127
,
128
,
dtype
=
"int8"
)],
int8
=
[
np
.
arange
(
-
127
,
128
,
dtype
=
"int8"
)],
uint8
=
[
np
.
arange
(
0
,
89
,
dtype
=
"uint8"
)],
uint8
=
[
np
.
arange
(
0
,
89
,
dtype
=
"uint8"
)],
uint16
=
[
np
.
arange
(
0
,
89
,
dtype
=
"uint16"
)],
uint16
=
[
np
.
arange
(
0
,
89
,
dtype
=
"uint16"
)],
...
@@ -818,14 +845,15 @@ _good_broadcast_unary_normal_no_complex = dict(
...
@@ -818,14 +845,15 @@ _good_broadcast_unary_normal_no_complex = dict(
_bad_build_broadcast_binary_normal
=
dict
()
_bad_build_broadcast_binary_normal
=
dict
()
_bad_runtime_broadcast_binary_normal
=
dict
(
_bad_runtime_broadcast_binary_normal
=
dict
(
bad_shapes
=
(
random
(
2
,
3
),
random
(
3
,
2
)),
bad_row
=
(
random
(
2
,
3
),
random
(
1
,
2
))
bad_shapes
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
3
,
2
,
rng
=
rng
)),
bad_row
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
1
,
2
,
rng
=
rng
)),
)
)
_grad_broadcast_binary_normal
=
dict
(
_grad_broadcast_binary_normal
=
dict
(
same_shapes
=
(
random
(
2
,
3
),
random
(
2
,
3
)),
same_shapes
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
2
,
3
,
rng
=
rng
)),
scalar
=
(
random
(
2
,
3
),
random
(
1
,
1
)),
scalar
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
1
,
1
,
rng
=
rng
)),
row
=
(
random
(
2
,
3
),
random
(
1
,
3
)),
row
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
1
,
3
,
rng
=
rng
)),
column
=
(
random
(
2
,
3
),
random
(
2
,
1
)),
column
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
2
,
1
,
rng
=
rng
)),
# This don't work as verify grad don't support that
# This don't work as verify grad don't support that
# empty=(np.asarray([]), np.asarray([1]))
# empty=(np.asarray([]), np.asarray([1]))
# complex1=(random_complex(2,3),random_complex(2,3)),
# complex1=(random_complex(2,3),random_complex(2,3)),
...
@@ -836,12 +864,12 @@ _grad_broadcast_binary_normal = dict(
...
@@ -836,12 +864,12 @@ _grad_broadcast_binary_normal = dict(
)
)
_good_reciprocal
=
dict
(
_good_reciprocal
=
dict
(
normal
=
[
5
*
random_nonzero
((
2
,
3
))],
normal
=
[
5
*
random_nonzero
((
2
,
3
)
,
rng
=
rng
)],
integers
=
[
integers_nonzero
(
2
,
3
)],
integers
=
[
integers_nonzero
(
2
,
3
,
rng
=
rng
)],
int8
=
[
np
.
array
(
list
(
range
(
-
127
,
0
))
+
list
(
range
(
1
,
127
)),
dtype
=
"int8"
)],
int8
=
[
np
.
array
(
list
(
range
(
-
127
,
0
))
+
list
(
range
(
1
,
127
)),
dtype
=
"int8"
)],
uint8
=
[
np
.
array
(
list
(
range
(
0
,
255
)),
dtype
=
"uint8"
)],
uint8
=
[
np
.
array
(
list
(
range
(
0
,
255
)),
dtype
=
"uint8"
)],
uint16
=
[
np
.
array
(
list
(
range
(
0
,
65535
)),
dtype
=
"uint16"
)],
uint16
=
[
np
.
array
(
list
(
range
(
0
,
65535
)),
dtype
=
"uint16"
)],
complex
=
[
random_complex_nonzero
((
2
,
3
))],
complex
=
[
random_complex_nonzero
((
2
,
3
)
,
rng
=
rng
)],
empty
=
[
np
.
asarray
([],
dtype
=
config
.
floatX
)],
empty
=
[
np
.
asarray
([],
dtype
=
config
.
floatX
)],
)
)
...
@@ -862,26 +890,47 @@ _bad_runtime_reciprocal = dict(
...
@@ -862,26 +890,47 @@ _bad_runtime_reciprocal = dict(
_good_broadcast_pow_normal_float
=
dict
(
_good_broadcast_pow_normal_float
=
dict
(
same_shapes
=
(
random_ranged
(
1
,
5
,
(
2
,
3
)),
random_ranged
(
-
3
,
3
,
(
2
,
3
))),
same_shapes
=
(
scalar
=
(
random_ranged
(
1
,
5
,
(
2
,
3
)),
random_ranged
(
-
3
,
3
,
(
1
,
1
))),
random_ranged
(
1
,
5
,
(
2
,
3
),
rng
=
rng
),
row
=
(
random_ranged
(
1
,
5
,
(
2
,
3
)),
random_ranged
(
-
3
,
3
,
(
1
,
3
))),
random_ranged
(
-
3
,
3
,
(
2
,
3
),
rng
=
rng
),
column
=
(
random_ranged
(
1
,
5
,
(
2
,
3
)),
random_ranged
(
-
3
,
3
,
(
2
,
1
))),
),
dtype_mixup
=
(
random_ranged
(
-
3
,
3
,
(
2
,
3
)),
integers_ranged
(
-
3
,
3
,
(
2
,
3
))),
scalar
=
(
complex1
=
(
random_complex
(
2
,
3
),
random_complex
(
2
,
3
)),
random_ranged
(
1
,
5
,
(
2
,
3
),
rng
=
rng
),
complex2
=
(
random_complex
(
2
,
3
),
random
(
2
,
3
)),
random_ranged
(
-
3
,
3
,
(
1
,
1
),
rng
=
rng
),
# complex3 = (random(2,3),random_complex(2,3)), # Inplace on the first element.
),
row
=
(
random_ranged
(
1
,
5
,
(
2
,
3
),
rng
=
rng
),
random_ranged
(
-
3
,
3
,
(
1
,
3
),
rng
=
rng
)),
column
=
(
random_ranged
(
1
,
5
,
(
2
,
3
),
rng
=
rng
),
random_ranged
(
-
3
,
3
,
(
2
,
1
),
rng
=
rng
),
),
dtype_mixup
=
(
random_ranged
(
-
3
,
3
,
(
2
,
3
),
rng
=
rng
),
integers_ranged
(
-
3
,
3
,
(
2
,
3
),
rng
=
rng
),
),
complex1
=
(
random_complex
(
2
,
3
,
rng
=
rng
),
random_complex
(
2
,
3
,
rng
=
rng
)),
complex2
=
(
random_complex
(
2
,
3
,
rng
=
rng
),
random
(
2
,
3
,
rng
=
rng
)),
# complex3 = (random(2, 3, rng=rng),random_complex(2, 3, rng=rng)), # Inplace on the first element.
empty1
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([
1
],
dtype
=
config
.
floatX
)),
empty1
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([
1
],
dtype
=
config
.
floatX
)),
empty2
=
(
np
.
asarray
([
0
],
dtype
=
config
.
floatX
),
np
.
asarray
([],
dtype
=
config
.
floatX
)),
empty2
=
(
np
.
asarray
([
0
],
dtype
=
config
.
floatX
),
np
.
asarray
([],
dtype
=
config
.
floatX
)),
empty3
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([],
dtype
=
config
.
floatX
)),
empty3
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([],
dtype
=
config
.
floatX
)),
)
)
_grad_broadcast_pow_normal
=
dict
(
_grad_broadcast_pow_normal
=
dict
(
same_shapes
=
(
random_ranged
(
1
,
5
,
(
2
,
3
)),
random_ranged
(
-
3
,
3
,
(
2
,
3
))),
same_shapes
=
(
scalar
=
(
random_ranged
(
1
,
5
,
(
2
,
3
)),
random_ranged
(
-
3
,
3
,
(
1
,
1
))),
random_ranged
(
1
,
5
,
(
2
,
3
),
rng
=
rng
),
row
=
(
random_ranged
(
1
,
5
,
(
2
,
3
)),
random_ranged
(
-
3
,
3
,
(
1
,
3
))),
random_ranged
(
-
3
,
3
,
(
2
,
3
),
rng
=
rng
),
column
=
(
random_ranged
(
1
,
5
,
(
2
,
3
)),
random_ranged
(
-
3
,
3
,
(
2
,
1
))),
),
# complex1 = (random_complex(2,3),random_complex(2,3)),
scalar
=
(
# complex2 = (random_complex(2,3),random(2,3)),
random_ranged
(
1
,
5
,
(
2
,
3
),
rng
=
rng
),
# complex3 = (random(2,3),random_complex(2,3)),
random_ranged
(
-
3
,
3
,
(
1
,
1
),
rng
=
rng
),
),
row
=
(
random_ranged
(
1
,
5
,
(
2
,
3
),
rng
=
rng
),
random_ranged
(
-
3
,
3
,
(
1
,
3
),
rng
=
rng
)),
column
=
(
random_ranged
(
1
,
5
,
(
2
,
3
),
rng
=
rng
),
random_ranged
(
-
3
,
3
,
(
2
,
1
),
rng
=
rng
),
),
# complex1 = (random_complex(2, 3, rng=rng), random_complex(2, 3, rng=rng)),
# complex2 = (random_complex(2, 3, rng=rng), random(2, 3, rng=rng)),
# complex3 = (random(2, 3, rng=rng), random_complex(2, 3, rng=rng)),
# empty1 = (np.asarray([]), np.asarray([1])),
# empty1 = (np.asarray([]), np.asarray([1])),
# empty2 = (np.asarray([0]), np.asarray([])),
# empty2 = (np.asarray([0]), np.asarray([])),
x_eq_zero
=
(
x_eq_zero
=
(
...
@@ -903,14 +952,16 @@ _good_broadcast_unary_normal_float_no_empty_no_complex = copymod(
...
@@ -903,14 +952,16 @@ _good_broadcast_unary_normal_float_no_empty_no_complex = copymod(
)
)
_grad_broadcast_unary_normal_no_complex
=
dict
(
_grad_broadcast_unary_normal_no_complex
=
dict
(
normal
=
[
np
.
asarray
(
random_ranged
(
-
5
,
5
,
(
2
,
3
)),
dtype
=
config
.
floatX
)],
normal
=
[
np
.
asarray
(
random_ranged
(
-
5
,
5
,
(
2
,
3
)
,
rng
=
rng
),
dtype
=
config
.
floatX
)],
corner_case
=
[
corner_case_grad
],
corner_case
=
[
corner_case_grad
],
)
)
# Avoid epsilon around integer values
# Avoid epsilon around integer values
_grad_broadcast_unary_normal_noint
=
dict
(
_grad_broadcast_unary_normal_noint
=
dict
(
normal
=
[
normal
=
[
(
random_ranged
(
_eps
,
1
-
_eps
,
(
2
,
3
))
+
integers
(
2
,
3
))
.
astype
(
config
.
floatX
)
(
random_ranged
(
_eps
,
1
-
_eps
,
(
2
,
3
),
rng
=
rng
)
+
integers
(
2
,
3
,
rng
=
rng
)
)
.
astype
(
config
.
floatX
)
]
]
)
)
...
@@ -919,12 +970,12 @@ _grad_broadcast_unary_normal_no_complex_no_corner_case = copymod(
...
@@ -919,12 +970,12 @@ _grad_broadcast_unary_normal_no_complex_no_corner_case = copymod(
)
)
_good_broadcast_binary_arctan2
=
dict
(
_good_broadcast_binary_arctan2
=
dict
(
same_shapes
=
(
random
(
2
,
3
),
random
(
2
,
3
)),
same_shapes
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
2
,
3
,
rng
=
rng
)),
not_same_dimensions
=
(
random
(
2
,
2
),
random
(
2
)),
not_same_dimensions
=
(
random
(
2
,
2
,
rng
=
rng
),
random
(
2
,
rng
=
rng
)),
scalar
=
(
random
(
2
,
3
),
random
(
1
,
1
)),
scalar
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
1
,
1
,
rng
=
rng
)),
row
=
(
random
(
2
,
3
),
random
(
1
,
3
)),
row
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
1
,
3
,
rng
=
rng
)),
column
=
(
random
(
2
,
3
),
random
(
2
,
1
)),
column
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
2
,
1
,
rng
=
rng
)),
integers
=
(
integers
(
2
,
3
),
integers
(
2
,
3
)),
integers
=
(
integers
(
2
,
3
,
rng
=
rng
),
integers
(
2
,
3
,
rng
=
rng
)),
int8
=
[
int8
=
[
np
.
arange
(
-
127
,
128
,
dtype
=
"int8"
),
np
.
arange
(
-
127
,
128
,
dtype
=
"int8"
),
np
.
arange
(
-
127
,
128
,
dtype
=
"int8"
)[:,
np
.
newaxis
],
np
.
arange
(
-
127
,
128
,
dtype
=
"int8"
)[:,
np
.
newaxis
],
...
@@ -937,26 +988,26 @@ _good_broadcast_binary_arctan2 = dict(
...
@@ -937,26 +988,26 @@ _good_broadcast_binary_arctan2 = dict(
np
.
arange
(
0
,
128
,
dtype
=
"uint16"
),
np
.
arange
(
0
,
128
,
dtype
=
"uint16"
),
np
.
arange
(
0
,
128
,
dtype
=
"uint16"
)[:,
np
.
newaxis
],
np
.
arange
(
0
,
128
,
dtype
=
"uint16"
)[:,
np
.
newaxis
],
],
],
dtype_mixup_1
=
(
random
(
2
,
3
),
integers
(
2
,
3
)),
dtype_mixup_1
=
(
random
(
2
,
3
,
rng
=
rng
),
integers
(
2
,
3
,
rng
=
rng
)),
dtype_mixup_2
=
(
integers
(
2
,
3
),
random
(
2
,
3
)),
dtype_mixup_2
=
(
integers
(
2
,
3
,
rng
=
rng
),
random
(
2
,
3
,
rng
=
rng
)),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([
1
],
dtype
=
config
.
floatX
)),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([
1
],
dtype
=
config
.
floatX
)),
)
)
_good_broadcast_unary_arccosh
=
dict
(
_good_broadcast_unary_arccosh
=
dict
(
normal
=
(
random_ranged
(
1
,
1000
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
1
,
1000
,
(
2
,
3
)
,
rng
=
rng
),),
integers
=
(
integers_ranged
(
1
,
1000
,
(
2
,
3
)),),
integers
=
(
integers_ranged
(
1
,
1000
,
(
2
,
3
)
,
rng
=
rng
),),
uint8
=
[
np
.
arange
(
1
,
256
,
dtype
=
"uint8"
)],
uint8
=
[
np
.
arange
(
1
,
256
,
dtype
=
"uint8"
)],
complex
=
(
random_complex128_ranged
(
1
,
1000
,
(
2
,
3
)),),
complex
=
(
random_complex128_ranged
(
1
,
1000
,
(
2
,
3
)
,
rng
=
rng
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
)
)
_good_broadcast_unary_arctanh
=
dict
(
_good_broadcast_unary_arctanh
=
dict
(
normal
=
(
random_ranged
(
-
1
+
_eps
,
1
-
_eps
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
-
1
+
_eps
,
1
-
_eps
,
(
2
,
3
)
,
rng
=
rng
),),
integers
=
(
integers_ranged
(
-
1
+
_eps
,
1
-
_eps
,
(
2
,
3
)),),
integers
=
(
integers_ranged
(
-
1
+
_eps
,
1
-
_eps
,
(
2
,
3
)
,
rng
=
rng
),),
int8
=
[
np
.
arange
(
0
,
1
,
dtype
=
"int8"
)],
int8
=
[
np
.
arange
(
0
,
1
,
dtype
=
"int8"
)],
uint8
=
[
np
.
arange
(
0
,
1
,
dtype
=
"uint8"
)],
uint8
=
[
np
.
arange
(
0
,
1
,
dtype
=
"uint8"
)],
uint16
=
[
np
.
arange
(
0
,
1
,
dtype
=
"uint16"
)],
uint16
=
[
np
.
arange
(
0
,
1
,
dtype
=
"uint16"
)],
complex
=
(
random_complex128_ranged
(
-
1
+
_eps
,
1
-
_eps
,
(
2
,
3
)),),
complex
=
(
random_complex128_ranged
(
-
1
+
_eps
,
1
-
_eps
,
(
2
,
3
)
,
rng
=
rng
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
)
)
...
@@ -966,10 +1017,10 @@ del _good_broadcast_unary_normal_abs["complex"]
...
@@ -966,10 +1017,10 @@ del _good_broadcast_unary_normal_abs["complex"]
_good_broadcast_unary_positive
=
dict
(
_good_broadcast_unary_positive
=
dict
(
normal
=
(
random_ranged
(
0.001
,
5
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
0.001
,
5
,
(
2
,
3
)
,
rng
=
rng
),),
integers
=
(
integers_ranged
(
1
,
5
,
(
2
,
3
)),),
integers
=
(
integers_ranged
(
1
,
5
,
(
2
,
3
)
,
rng
=
rng
),),
uint8
=
[
np
.
arange
(
1
,
256
,
dtype
=
"uint8"
)],
uint8
=
[
np
.
arange
(
1
,
256
,
dtype
=
"uint8"
)],
complex
=
(
random_complex128_ranged
(
1
,
5
,
(
2
,
3
)),),
complex
=
(
random_complex128_ranged
(
1
,
5
,
(
2
,
3
)
,
rng
=
rng
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
)
)
...
@@ -978,23 +1029,23 @@ _good_broadcast_unary_positive_float = copymod(
...
@@ -978,23 +1029,23 @@ _good_broadcast_unary_positive_float = copymod(
)
)
_good_broadcast_unary_tan
=
dict
(
_good_broadcast_unary_tan
=
dict
(
normal
=
(
random_ranged
(
-
3.14
,
3.14
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
-
3.14
,
3.14
,
(
2
,
3
)
,
rng
=
rng
),),
shifted
=
(
random_ranged
(
3.15
,
6.28
,
(
2
,
3
)),),
shifted
=
(
random_ranged
(
3.15
,
6.28
,
(
2
,
3
)
,
rng
=
rng
),),
integers
=
(
integers_ranged
(
-
3
,
3
,
(
2
,
3
)),),
integers
=
(
integers_ranged
(
-
3
,
3
,
(
2
,
3
)
,
rng
=
rng
),),
int8
=
[
np
.
arange
(
-
3
,
4
,
dtype
=
"int8"
)],
int8
=
[
np
.
arange
(
-
3
,
4
,
dtype
=
"int8"
)],
uint8
=
[
np
.
arange
(
0
,
4
,
dtype
=
"uint8"
)],
uint8
=
[
np
.
arange
(
0
,
4
,
dtype
=
"uint8"
)],
uint16
=
[
np
.
arange
(
0
,
4
,
dtype
=
"uint16"
)],
uint16
=
[
np
.
arange
(
0
,
4
,
dtype
=
"uint16"
)],
complex
=
(
random_complex128_ranged
(
-
3.14
,
3.14
,
(
2
,
3
)),),
complex
=
(
random_complex128_ranged
(
-
3.14
,
3.14
,
(
2
,
3
)
,
rng
=
rng
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
)
)
_good_broadcast_unary_wide
=
dict
(
_good_broadcast_unary_wide
=
dict
(
normal
=
(
random_ranged
(
-
1000
,
1000
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
-
1000
,
1000
,
(
2
,
3
)
,
rng
=
rng
),),
integers
=
(
integers_ranged
(
-
1000
,
1000
,
(
2
,
3
)),),
integers
=
(
integers_ranged
(
-
1000
,
1000
,
(
2
,
3
)
,
rng
=
rng
),),
int8
=
[
np
.
arange
(
-
127
,
128
,
dtype
=
"int8"
)],
int8
=
[
np
.
arange
(
-
127
,
128
,
dtype
=
"int8"
)],
uint8
=
[
np
.
arange
(
0
,
255
,
dtype
=
"uint8"
)],
uint8
=
[
np
.
arange
(
0
,
255
,
dtype
=
"uint8"
)],
uint16
=
[
np
.
arange
(
0
,
65535
,
dtype
=
"uint16"
)],
uint16
=
[
np
.
arange
(
0
,
65535
,
dtype
=
"uint16"
)],
complex
=
(
random_complex128_ranged
(
-
1000
,
1000
,
(
2
,
3
)),),
complex
=
(
random_complex128_ranged
(
-
1000
,
1000
,
(
2
,
3
)
,
rng
=
rng
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
)
)
_good_broadcast_unary_wide_float
=
copymod
(
_good_broadcast_unary_wide_float
=
copymod
(
...
@@ -1002,34 +1053,40 @@ _good_broadcast_unary_wide_float = copymod(
...
@@ -1002,34 +1053,40 @@ _good_broadcast_unary_wide_float = copymod(
)
)
_good_broadcast_binary_normal
=
dict
(
_good_broadcast_binary_normal
=
dict
(
same_shapes
=
(
random
(
2
,
3
),
random
(
2
,
3
)),
same_shapes
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
2
,
3
,
rng
=
rng
)),
not_same_dimensions
=
(
random
(
2
,
2
),
random
(
2
)),
not_same_dimensions
=
(
random
(
2
,
2
,
rng
=
rng
),
random
(
2
,
rng
=
rng
)),
scalar
=
(
random
(
2
,
3
),
random
(
1
,
1
)),
scalar
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
1
,
1
,
rng
=
rng
)),
row
=
(
random
(
2
,
3
),
random
(
1
,
3
)),
row
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
1
,
3
,
rng
=
rng
)),
column
=
(
random
(
2
,
3
),
random
(
2
,
1
)),
column
=
(
random
(
2
,
3
,
rng
=
rng
),
random
(
2
,
1
,
rng
=
rng
)),
integers
=
(
integers
(
2
,
3
),
integers
(
2
,
3
)),
integers
=
(
integers
(
2
,
3
,
rng
=
rng
),
integers
(
2
,
3
,
rng
=
rng
)),
uint32
=
(
integers_uint32
(
2
,
3
),
integers_uint32
(
2
,
3
)),
uint32
=
(
integers_uint32
(
2
,
3
,
rng
=
rng
),
integers_uint32
(
2
,
3
,
rng
=
rng
)),
uint16
=
(
integers_uint16
(
2
,
3
),
integers_uint16
(
2
,
3
)),
uint16
=
(
integers_uint16
(
2
,
3
,
rng
=
rng
),
integers_uint16
(
2
,
3
,
rng
=
rng
)),
dtype_mixup_1
=
(
random
(
2
,
3
),
integers
(
2
,
3
)),
dtype_mixup_1
=
(
random
(
2
,
3
,
rng
=
rng
),
integers
(
2
,
3
,
rng
=
rng
)),
dtype_mixup_2
=
(
integers
(
2
,
3
),
random
(
2
,
3
)),
dtype_mixup_2
=
(
integers
(
2
,
3
,
rng
=
rng
),
random
(
2
,
3
,
rng
=
rng
)),
complex1
=
(
random_complex
(
2
,
3
),
random_complex
(
2
,
3
)),
complex1
=
(
random_complex
(
2
,
3
,
rng
=
rng
),
random_complex
(
2
,
3
,
rng
=
rng
)),
complex2
=
(
random_complex
(
2
,
3
),
random
(
2
,
3
)),
complex2
=
(
random_complex
(
2
,
3
,
rng
=
rng
),
random
(
2
,
3
,
rng
=
rng
)),
# Disabled as we test the case where we reuse the same output as the
# Disabled as we test the case where we reuse the same output as the
# first inputs.
# first inputs.
# complex3=(random(2,
3),random_complex(2,3
)),
# complex3=(random(2,
3, rng=rng), random_complex(2, 3, rng=rng
)),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([
1
],
dtype
=
config
.
floatX
)),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([
1
],
dtype
=
config
.
floatX
)),
)
)
_good_broadcast_div_mod_normal_float_no_complex
=
dict
(
_good_broadcast_div_mod_normal_float_no_complex
=
dict
(
same_shapes
=
(
random
(
2
,
3
),
random_nonzero
((
2
,
3
))),
same_shapes
=
(
random
(
2
,
3
,
rng
=
rng
),
random_nonzero
((
2
,
3
),
rng
=
rng
)),
scalar
=
(
random
(
2
,
3
),
random_nonzero
((
1
,
1
))),
scalar
=
(
random
(
2
,
3
,
rng
=
rng
),
random_nonzero
((
1
,
1
),
rng
=
rng
)),
row
=
(
random
(
2
,
3
),
random_nonzero
((
1
,
3
))),
row
=
(
random
(
2
,
3
,
rng
=
rng
),
random_nonzero
((
1
,
3
),
rng
=
rng
)),
column
=
(
random
(
2
,
3
),
random_nonzero
((
2
,
1
))),
column
=
(
random
(
2
,
3
,
rng
=
rng
),
random_nonzero
((
2
,
1
),
rng
=
rng
)),
dtype_mixup_1
=
(
random
(
2
,
3
),
integers_nonzero
(
2
,
3
)),
dtype_mixup_1
=
(
random
(
2
,
3
,
rng
=
rng
),
integers_nonzero
(
2
,
3
,
rng
=
rng
)),
dtype_mixup_2
=
(
integers_nonzero
(
2
,
3
),
random_nonzero
((
2
,
3
))),
dtype_mixup_2
=
(
integers_nonzero
(
2
,
3
,
rng
=
rng
),
random_nonzero
((
2
,
3
),
rng
=
rng
)),
integer
=
(
integers
(
2
,
3
),
integers_nonzero
(
2
,
3
)),
integer
=
(
integers
(
2
,
3
,
rng
=
rng
),
integers_nonzero
(
2
,
3
,
rng
=
rng
)),
uint8
=
(
integers
(
2
,
3
)
.
astype
(
"uint8"
),
integers_nonzero
(
2
,
3
)
.
astype
(
"uint8"
)),
uint8
=
(
uint16
=
(
integers
(
2
,
3
)
.
astype
(
"uint16"
),
integers_nonzero
(
2
,
3
)
.
astype
(
"uint16"
)),
integers
(
2
,
3
,
rng
=
rng
)
.
astype
(
"uint8"
),
integers_nonzero
(
2
,
3
,
rng
=
rng
)
.
astype
(
"uint8"
),
),
uint16
=
(
integers
(
2
,
3
,
rng
=
rng
)
.
astype
(
"uint16"
),
integers_nonzero
(
2
,
3
,
rng
=
rng
)
.
astype
(
"uint16"
),
),
int8
=
[
int8
=
[
np
.
tile
(
np
.
arange
(
-
127
,
128
,
dtype
=
"int8"
),
[
254
,
1
])
.
T
,
np
.
tile
(
np
.
arange
(
-
127
,
128
,
dtype
=
"int8"
),
[
254
,
1
])
.
T
,
np
.
tile
(
np
.
tile
(
...
@@ -1052,12 +1109,12 @@ _good_broadcast_div_mod_normal_float = copymod(
...
@@ -1052,12 +1109,12 @@ _good_broadcast_div_mod_normal_float = copymod(
)
)
_good_broadcast_unary_arcsin
=
dict
(
_good_broadcast_unary_arcsin
=
dict
(
normal
=
(
random_ranged
(
-
1
,
1
,
(
2
,
3
)),),
normal
=
(
random_ranged
(
-
1
,
1
,
(
2
,
3
)
,
rng
=
rng
),),
integers
=
(
integers_ranged
(
-
1
,
1
,
(
2
,
3
)),),
integers
=
(
integers_ranged
(
-
1
,
1
,
(
2
,
3
)
,
rng
=
rng
),),
int8
=
[
np
.
arange
(
-
1
,
2
,
dtype
=
"int8"
)],
int8
=
[
np
.
arange
(
-
1
,
2
,
dtype
=
"int8"
)],
uint8
=
[
np
.
arange
(
0
,
2
,
dtype
=
"uint8"
)],
uint8
=
[
np
.
arange
(
0
,
2
,
dtype
=
"uint8"
)],
uint16
=
[
np
.
arange
(
0
,
2
,
dtype
=
"uint16"
)],
uint16
=
[
np
.
arange
(
0
,
2
,
dtype
=
"uint16"
)],
complex
=
(
random_complex128_ranged
(
-
1
,
1
,
(
2
,
3
)),),
complex
=
(
random_complex128_ranged
(
-
1
,
1
,
(
2
,
3
)
,
rng
=
rng
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),),
)
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论