Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5b935bc6
提交
5b935bc6
authored
8月 28, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
8月 28, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move Numba tensor_basic tests to test_tensor_basic
上级
96b10e3f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
395 行增加
和
377 行删除
+395
-377
test_basic.py
tests/link/numba/test_basic.py
+1
-377
test_tensor_basic.py
tests/link/numba/test_tensor_basic.py
+394
-0
没有找到文件。
tests/link/numba/test_basic.py
浏览文件 @
5b935bc6
...
@@ -9,7 +9,6 @@ import pytest
...
@@ -9,7 +9,6 @@ import pytest
import
aesara.scalar
as
aes
import
aesara.scalar
as
aes
import
aesara.scalar.math
as
aesm
import
aesara.scalar.math
as
aesm
import
aesara.tensor
as
at
import
aesara.tensor
as
at
import
aesara.tensor.basic
as
atb
import
aesara.tensor.math
as
aem
import
aesara.tensor.math
as
aem
from
aesara
import
config
,
shared
from
aesara
import
config
,
shared
from
aesara.compile.function
import
function
from
aesara.compile.function
import
function
...
@@ -29,7 +28,7 @@ from aesara.raise_op import assert_op
...
@@ -29,7 +28,7 @@ from aesara.raise_op import assert_op
from
aesara.tensor
import
blas
from
aesara.tensor
import
blas
from
aesara.tensor
import
subtensor
as
at_subtensor
from
aesara.tensor
import
subtensor
as
at_subtensor
from
aesara.tensor.elemwise
import
Elemwise
from
aesara.tensor.elemwise
import
Elemwise
from
aesara.tensor.shape
import
Reshape
,
Shape
,
Shape_i
,
SpecifyShape
,
Unbroadcast
from
aesara.tensor.shape
import
Reshape
,
Shape
,
Shape_i
,
SpecifyShape
class
MyType
(
Type
):
class
MyType
(
Type
):
...
@@ -501,111 +500,6 @@ def test_Shape(x, i):
...
@@ -501,111 +500,6 @@ def test_Shape(x, i):
compare_numba_and_py
(
g_fg
,
[])
compare_numba_and_py
(
g_fg
,
[])
@pytest.mark.parametrize
(
"v, shape"
,
[
(
0.0
,
(
2
,
3
)),
(
1.1
,
(
2
,
3
)),
(
set_test_value
(
at
.
scalar
(
"a"
),
np
.
array
(
10.0
,
dtype
=
config
.
floatX
)),
(
20
,)),
(
set_test_value
(
at
.
vector
(
"a"
),
np
.
ones
(
10
,
dtype
=
config
.
floatX
)),
(
20
,
10
)),
],
)
def
test_Alloc
(
v
,
shape
):
g
=
at
.
alloc
(
v
,
*
shape
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
(
numba_res
,)
=
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
assert
numba_res
.
shape
==
shape
def
test_AllocEmpty
():
x
=
at
.
empty
((
2
,
3
),
dtype
=
"float32"
)
x_fg
=
FunctionGraph
([],
[
x
])
# We cannot compare the values in the arrays, only the shapes and dtypes
compare_numba_and_py
(
x_fg
,
[],
assert_fn
=
compare_shape_dtype
)
@pytest.mark.parametrize
(
"v, offset"
,
[
(
set_test_value
(
at
.
vector
(),
np
.
arange
(
10
,
dtype
=
config
.
floatX
)),
0
),
(
set_test_value
(
at
.
vector
(),
np
.
arange
(
10
,
dtype
=
config
.
floatX
)),
1
),
(
set_test_value
(
at
.
vector
(),
np
.
arange
(
10
,
dtype
=
config
.
floatX
)),
-
1
),
],
)
def
test_AllocDiag
(
v
,
offset
):
g
=
atb
.
AllocDiag
(
offset
=
offset
)(
v
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
"v"
,
[
set_test_value
(
aes
.
float64
(),
np
.
array
(
1.0
,
dtype
=
"float64"
))]
)
def
test_TensorFromScalar
(
v
):
g
=
atb
.
TensorFromScalar
()(
v
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
"v"
,
[
set_test_value
(
at
.
scalar
(),
np
.
array
(
1.0
,
dtype
=
config
.
floatX
)),
],
)
def
test_ScalarFromTensor
(
v
):
g
=
atb
.
ScalarFromTensor
()(
v
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
def
test_Unbroadcast
():
v
=
set_test_value
(
at
.
row
(),
np
.
array
([[
1.0
,
2.0
]],
dtype
=
config
.
floatX
))
g
=
Unbroadcast
(
0
)(
v
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
@pytest.mark.parametrize
(
"v, shape, ndim"
,
"v, shape, ndim"
,
[
[
...
@@ -700,276 +594,6 @@ def test_ViewOp(v):
...
@@ -700,276 +594,6 @@ def test_ViewOp(v):
)
)
@pytest.mark.parametrize
(
"vals, dtype"
,
[
(
(
set_test_value
(
at
.
scalar
(),
np
.
array
(
1
,
dtype
=
config
.
floatX
)),
set_test_value
(
at
.
scalar
(),
np
.
array
(
2
,
dtype
=
config
.
floatX
)),
set_test_value
(
at
.
scalar
(),
np
.
array
(
3
,
dtype
=
config
.
floatX
)),
),
config
.
floatX
,
),
(
(
set_test_value
(
at
.
dscalar
(),
np
.
array
(
1
,
dtype
=
np
.
float64
)),
set_test_value
(
at
.
lscalar
(),
np
.
array
(
3
,
dtype
=
np
.
int32
)),
),
"float64"
,
),
(
(
set_test_value
(
at
.
iscalar
(),
np
.
array
(
1
,
dtype
=
np
.
int32
)),),
"float64"
,
),
(
(
set_test_value
(
at
.
scalar
(
dtype
=
bool
),
True
),),
bool
,
),
],
)
def
test_MakeVector
(
vals
,
dtype
):
g
=
atb
.
MakeVector
(
dtype
)(
*
vals
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
"start, stop, step, dtype"
,
[
(
set_test_value
(
at
.
lscalar
(),
np
.
array
(
1
)),
set_test_value
(
at
.
lscalar
(),
np
.
array
(
10
)),
set_test_value
(
at
.
lscalar
(),
np
.
array
(
3
)),
config
.
floatX
,
),
],
)
def
test_ARange
(
start
,
stop
,
step
,
dtype
):
g
=
atb
.
ARange
(
dtype
)(
start
,
stop
,
step
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
"vals, axis"
,
[
(
(
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
1
,
2
))
.
astype
(
config
.
floatX
)
),
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
1
,
2
))
.
astype
(
config
.
floatX
)
),
),
0
,
),
(
(
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
2
,
1
))
.
astype
(
config
.
floatX
)
),
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
3
,
1
))
.
astype
(
config
.
floatX
)
),
),
0
,
),
(
(
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
1
,
2
))
.
astype
(
config
.
floatX
)
),
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
1
,
2
))
.
astype
(
config
.
floatX
)
),
),
1
,
),
(
(
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
2
,
2
))
.
astype
(
config
.
floatX
)
),
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
2
,
1
))
.
astype
(
config
.
floatX
)
),
),
1
,
),
],
)
def
test_Join
(
vals
,
axis
):
g
=
at
.
join
(
axis
,
*
vals
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
def
test_Join_view
():
vals
=
(
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
2
,
2
))
.
astype
(
config
.
floatX
)),
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
2
,
2
))
.
astype
(
config
.
floatX
)),
)
g
=
atb
.
Join
(
view
=
1
)(
1
,
*
vals
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
with
pytest
.
raises
(
NotImplementedError
):
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
"n_splits, axis, values, sizes"
,
[
(
0
,
0
,
set_test_value
(
at
.
vector
(),
rng
.
normal
(
size
=
20
)
.
astype
(
config
.
floatX
)),
set_test_value
(
at
.
vector
(
dtype
=
"int64"
),
[]),
),
(
5
,
0
,
set_test_value
(
at
.
vector
(),
rng
.
normal
(
size
=
5
)
.
astype
(
config
.
floatX
)),
set_test_value
(
at
.
vector
(
dtype
=
"int64"
),
rng
.
multinomial
(
5
,
np
.
ones
(
5
)
/
5
)
),
),
(
5
,
0
,
set_test_value
(
at
.
vector
(),
rng
.
normal
(
size
=
10
)
.
astype
(
config
.
floatX
)),
set_test_value
(
at
.
vector
(
dtype
=
"int64"
),
rng
.
multinomial
(
10
,
np
.
ones
(
5
)
/
5
)
),
),
(
5
,
-
1
,
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
11
,
7
))
.
astype
(
config
.
floatX
)),
set_test_value
(
at
.
vector
(
dtype
=
"int64"
),
rng
.
multinomial
(
7
,
np
.
ones
(
5
)
/
5
)
),
),
(
5
,
-
2
,
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
11
,
7
))
.
astype
(
config
.
floatX
)),
set_test_value
(
at
.
vector
(
dtype
=
"int64"
),
rng
.
multinomial
(
11
,
np
.
ones
(
5
)
/
5
)
),
),
],
)
def
test_Split
(
n_splits
,
axis
,
values
,
sizes
):
g
=
at
.
split
(
values
,
sizes
,
n_splits
,
axis
=
axis
)
assert
len
(
g
)
==
n_splits
if
n_splits
==
0
:
return
g_fg
=
FunctionGraph
(
outputs
=
[
g
]
if
n_splits
==
1
else
g
)
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
"val, offset"
,
[
(
set_test_value
(
at
.
matrix
(),
np
.
arange
(
10
*
10
,
dtype
=
config
.
floatX
)
.
reshape
((
10
,
10
))
),
0
,
),
(
set_test_value
(
at
.
vector
(),
np
.
arange
(
10
,
dtype
=
config
.
floatX
)),
0
,
),
],
)
def
test_ExtractDiag
(
val
,
offset
):
g
=
at
.
diag
(
val
,
offset
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
"n, m, k, dtype"
,
[
(
set_test_value
(
at
.
lscalar
(),
np
.
array
(
1
,
dtype
=
np
.
int64
)),
None
,
0
,
None
),
(
set_test_value
(
at
.
lscalar
(),
np
.
array
(
1
,
dtype
=
np
.
int64
)),
set_test_value
(
at
.
lscalar
(),
np
.
array
(
2
,
dtype
=
np
.
int64
)),
0
,
"float32"
,
),
(
set_test_value
(
at
.
lscalar
(),
np
.
array
(
1
,
dtype
=
np
.
int64
)),
set_test_value
(
at
.
lscalar
(),
np
.
array
(
2
,
dtype
=
np
.
int64
)),
1
,
"int64"
,
),
],
)
def
test_Eye
(
n
,
m
,
k
,
dtype
):
g
=
at
.
eye
(
n
,
m
,
k
,
dtype
=
dtype
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
@pytest.mark.parametrize
(
"inputs, op, exc"
,
"inputs, op, exc"
,
[
[
...
...
tests/link/numba/test_tensor_basic.py
0 → 100644
浏览文件 @
5b935bc6
import
numpy
as
np
import
pytest
import
aesara.scalar
as
aes
import
aesara.tensor
as
at
import
aesara.tensor.basic
as
atb
from
aesara
import
config
from
aesara.compile.sharedvalue
import
SharedVariable
from
aesara.graph.basic
import
Constant
from
aesara.graph.fg
import
FunctionGraph
from
aesara.tensor.shape
import
Unbroadcast
from
tests.link.numba.test_basic
import
(
compare_numba_and_py
,
compare_shape_dtype
,
set_test_value
,
)
rng
=
np
.
random
.
default_rng
(
42849
)
@pytest.mark.parametrize
(
"v, shape"
,
[
(
0.0
,
(
2
,
3
)),
(
1.1
,
(
2
,
3
)),
(
set_test_value
(
at
.
scalar
(
"a"
),
np
.
array
(
10.0
,
dtype
=
config
.
floatX
)),
(
20
,)),
(
set_test_value
(
at
.
vector
(
"a"
),
np
.
ones
(
10
,
dtype
=
config
.
floatX
)),
(
20
,
10
)),
],
)
def
test_Alloc
(
v
,
shape
):
g
=
at
.
alloc
(
v
,
*
shape
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
(
numba_res
,)
=
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
assert
numba_res
.
shape
==
shape
def
test_AllocEmpty
():
x
=
at
.
empty
((
2
,
3
),
dtype
=
"float32"
)
x_fg
=
FunctionGraph
([],
[
x
])
# We cannot compare the values in the arrays, only the shapes and dtypes
compare_numba_and_py
(
x_fg
,
[],
assert_fn
=
compare_shape_dtype
)
@pytest.mark.parametrize
(
"v, offset"
,
[
(
set_test_value
(
at
.
vector
(),
np
.
arange
(
10
,
dtype
=
config
.
floatX
)),
0
),
(
set_test_value
(
at
.
vector
(),
np
.
arange
(
10
,
dtype
=
config
.
floatX
)),
1
),
(
set_test_value
(
at
.
vector
(),
np
.
arange
(
10
,
dtype
=
config
.
floatX
)),
-
1
),
],
)
def
test_AllocDiag
(
v
,
offset
):
g
=
atb
.
AllocDiag
(
offset
=
offset
)(
v
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
"v"
,
[
set_test_value
(
aes
.
float64
(),
np
.
array
(
1.0
,
dtype
=
"float64"
))]
)
def
test_TensorFromScalar
(
v
):
g
=
atb
.
TensorFromScalar
()(
v
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
"v"
,
[
set_test_value
(
at
.
scalar
(),
np
.
array
(
1.0
,
dtype
=
config
.
floatX
)),
],
)
def
test_ScalarFromTensor
(
v
):
g
=
atb
.
ScalarFromTensor
()(
v
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
def
test_Unbroadcast
():
v
=
set_test_value
(
at
.
row
(),
np
.
array
([[
1.0
,
2.0
]],
dtype
=
config
.
floatX
))
g
=
Unbroadcast
(
0
)(
v
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
"vals, dtype"
,
[
(
(
set_test_value
(
at
.
scalar
(),
np
.
array
(
1
,
dtype
=
config
.
floatX
)),
set_test_value
(
at
.
scalar
(),
np
.
array
(
2
,
dtype
=
config
.
floatX
)),
set_test_value
(
at
.
scalar
(),
np
.
array
(
3
,
dtype
=
config
.
floatX
)),
),
config
.
floatX
,
),
(
(
set_test_value
(
at
.
dscalar
(),
np
.
array
(
1
,
dtype
=
np
.
float64
)),
set_test_value
(
at
.
lscalar
(),
np
.
array
(
3
,
dtype
=
np
.
int32
)),
),
"float64"
,
),
(
(
set_test_value
(
at
.
iscalar
(),
np
.
array
(
1
,
dtype
=
np
.
int32
)),),
"float64"
,
),
(
(
set_test_value
(
at
.
scalar
(
dtype
=
bool
),
True
),),
bool
,
),
],
)
def
test_MakeVector
(
vals
,
dtype
):
g
=
atb
.
MakeVector
(
dtype
)(
*
vals
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
"start, stop, step, dtype"
,
[
(
set_test_value
(
at
.
lscalar
(),
np
.
array
(
1
)),
set_test_value
(
at
.
lscalar
(),
np
.
array
(
10
)),
set_test_value
(
at
.
lscalar
(),
np
.
array
(
3
)),
config
.
floatX
,
),
],
)
def
test_ARange
(
start
,
stop
,
step
,
dtype
):
g
=
atb
.
ARange
(
dtype
)(
start
,
stop
,
step
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
"vals, axis"
,
[
(
(
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
1
,
2
))
.
astype
(
config
.
floatX
)
),
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
1
,
2
))
.
astype
(
config
.
floatX
)
),
),
0
,
),
(
(
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
2
,
1
))
.
astype
(
config
.
floatX
)
),
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
3
,
1
))
.
astype
(
config
.
floatX
)
),
),
0
,
),
(
(
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
1
,
2
))
.
astype
(
config
.
floatX
)
),
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
1
,
2
))
.
astype
(
config
.
floatX
)
),
),
1
,
),
(
(
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
2
,
2
))
.
astype
(
config
.
floatX
)
),
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
2
,
1
))
.
astype
(
config
.
floatX
)
),
),
1
,
),
],
)
def
test_Join
(
vals
,
axis
):
g
=
at
.
join
(
axis
,
*
vals
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
def
test_Join_view
():
vals
=
(
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
2
,
2
))
.
astype
(
config
.
floatX
)),
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
2
,
2
))
.
astype
(
config
.
floatX
)),
)
g
=
atb
.
Join
(
view
=
1
)(
1
,
*
vals
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
with
pytest
.
raises
(
NotImplementedError
):
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
"n_splits, axis, values, sizes"
,
[
(
0
,
0
,
set_test_value
(
at
.
vector
(),
rng
.
normal
(
size
=
20
)
.
astype
(
config
.
floatX
)),
set_test_value
(
at
.
vector
(
dtype
=
"int64"
),
[]),
),
(
5
,
0
,
set_test_value
(
at
.
vector
(),
rng
.
normal
(
size
=
5
)
.
astype
(
config
.
floatX
)),
set_test_value
(
at
.
vector
(
dtype
=
"int64"
),
rng
.
multinomial
(
5
,
np
.
ones
(
5
)
/
5
)
),
),
(
5
,
0
,
set_test_value
(
at
.
vector
(),
rng
.
normal
(
size
=
10
)
.
astype
(
config
.
floatX
)),
set_test_value
(
at
.
vector
(
dtype
=
"int64"
),
rng
.
multinomial
(
10
,
np
.
ones
(
5
)
/
5
)
),
),
(
5
,
-
1
,
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
11
,
7
))
.
astype
(
config
.
floatX
)),
set_test_value
(
at
.
vector
(
dtype
=
"int64"
),
rng
.
multinomial
(
7
,
np
.
ones
(
5
)
/
5
)
),
),
(
5
,
-
2
,
set_test_value
(
at
.
matrix
(),
rng
.
normal
(
size
=
(
11
,
7
))
.
astype
(
config
.
floatX
)),
set_test_value
(
at
.
vector
(
dtype
=
"int64"
),
rng
.
multinomial
(
11
,
np
.
ones
(
5
)
/
5
)
),
),
],
)
def
test_Split
(
n_splits
,
axis
,
values
,
sizes
):
g
=
at
.
split
(
values
,
sizes
,
n_splits
,
axis
=
axis
)
assert
len
(
g
)
==
n_splits
if
n_splits
==
0
:
return
g_fg
=
FunctionGraph
(
outputs
=
[
g
]
if
n_splits
==
1
else
g
)
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
"val, offset"
,
[
(
set_test_value
(
at
.
matrix
(),
np
.
arange
(
10
*
10
,
dtype
=
config
.
floatX
)
.
reshape
((
10
,
10
))
),
0
,
),
(
set_test_value
(
at
.
vector
(),
np
.
arange
(
10
,
dtype
=
config
.
floatX
)),
0
,
),
],
)
def
test_ExtractDiag
(
val
,
offset
):
g
=
at
.
diag
(
val
,
offset
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
@pytest.mark.parametrize
(
"n, m, k, dtype"
,
[
(
set_test_value
(
at
.
lscalar
(),
np
.
array
(
1
,
dtype
=
np
.
int64
)),
None
,
0
,
None
),
(
set_test_value
(
at
.
lscalar
(),
np
.
array
(
1
,
dtype
=
np
.
int64
)),
set_test_value
(
at
.
lscalar
(),
np
.
array
(
2
,
dtype
=
np
.
int64
)),
0
,
"float32"
,
),
(
set_test_value
(
at
.
lscalar
(),
np
.
array
(
1
,
dtype
=
np
.
int64
)),
set_test_value
(
at
.
lscalar
(),
np
.
array
(
2
,
dtype
=
np
.
int64
)),
1
,
"int64"
,
),
],
)
def
test_Eye
(
n
,
m
,
k
,
dtype
):
g
=
at
.
eye
(
n
,
m
,
k
,
dtype
=
dtype
)
g_fg
=
FunctionGraph
(
outputs
=
[
g
])
compare_numba_and_py
(
g_fg
,
[
i
.
tag
.
test_value
for
i
in
g_fg
.
inputs
if
not
isinstance
(
i
,
(
SharedVariable
,
Constant
))
],
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论