Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4a8ccb6d
提交
4a8ccb6d
authored
2月 13, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
2月 13, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename _tt suffix to _aet
上级
9ac485c5
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
153 行增加
和
142 行删除
+153
-142
assert_op.py
aesara/assert_op.py
+3
-3
jax_dispatch.py
aesara/link/jax/jax_dispatch.py
+2
-2
test_jax.py
tests/link/test_jax.py
+0
-0
test_basic.py
tests/tensor/random/test_basic.py
+40
-37
test_opt.py
tests/tensor/random/test_opt.py
+33
-33
test_basic.py
tests/tensor/test_basic.py
+8
-8
test_extra_ops.py
tests/tensor/test_extra_ops.py
+64
-56
test_math.py
tests/tensor/test_math.py
+3
-3
没有找到文件。
aesara/assert_op.py
浏览文件 @
4a8ccb6d
...
...
@@ -24,9 +24,9 @@ class Assert(COp):
Examples
--------
>>> import aesara
>>>
T = aesara.tensor
>>> x =
T
.vector('x')
>>> assert_op =
T
.opt.Assert()
>>>
import aesara.tensor as aet
>>> x =
aet
.vector('x')
>>> assert_op =
aet
.opt.Assert()
>>> func = aesara.function([x], assert_op(x, x.size<2))
"""
...
...
aesara/link/jax/jax_dispatch.py
浏览文件 @
4a8ccb6d
...
...
@@ -419,7 +419,7 @@ def jax_funcify_Composite(op):
@jax_funcify.register
(
Scan
)
def
jax_funcify_Scan
(
op
):
inner_fg
=
FunctionGraph
(
op
.
inputs
,
op
.
outputs
)
jax_
t
t_inner_func
=
jax_funcify
(
inner_fg
)
jax_
ae
t_inner_func
=
jax_funcify
(
inner_fg
)
def
scan
(
*
outer_inputs
):
scan_args
=
ScanArgs
(
...
...
@@ -538,7 +538,7 @@ def jax_funcify_Scan(op):
def
jax_inner_func
(
carry
,
x
):
inner_args
=
jax_args_to_inner_scan
(
op
,
carry
,
x
)
inner_scan_outs
=
[
fn
(
*
inner_args
)
for
fn
in
jax_
t
t_inner_func
]
inner_scan_outs
=
[
fn
(
*
inner_args
)
for
fn
in
jax_
ae
t_inner_func
]
new_carry
=
inner_scan_outs_to_jax_outs
(
op
,
carry
,
inner_scan_outs
)
return
new_carry
,
inner_scan_outs
...
...
tests/link/test_jax.py
浏览文件 @
4a8ccb6d
差异被折叠。
点击展开。
tests/tensor/random/test_basic.py
浏览文件 @
4a8ccb6d
...
...
@@ -104,23 +104,26 @@ def test_beta_samples():
def
test_normal_infer_shape
():
M_
t
t
=
iscalar
(
"M"
)
M_
t
t
.
tag
.
test_value
=
3
sd_
t
t
=
scalar
(
"sd"
)
sd_
t
t
.
tag
.
test_value
=
np
.
array
(
1.0
,
dtype
=
config
.
floatX
)
M_
ae
t
=
iscalar
(
"M"
)
M_
ae
t
.
tag
.
test_value
=
3
sd_
ae
t
=
scalar
(
"sd"
)
sd_
ae
t
.
tag
.
test_value
=
np
.
array
(
1.0
,
dtype
=
config
.
floatX
)
test_params
=
[
([
aet
.
as_tensor_variable
(
np
.
array
(
1.0
,
dtype
=
config
.
floatX
)),
sd_tt
],
None
),
([
aet
.
as_tensor_variable
(
np
.
array
(
1.0
,
dtype
=
config
.
floatX
)),
sd_tt
],
(
M_tt
,)),
([
aet
.
as_tensor_variable
(
np
.
array
(
1.0
,
dtype
=
config
.
floatX
)),
sd_aet
],
None
),
(
[
aet
.
as_tensor_variable
(
np
.
array
(
1.0
,
dtype
=
config
.
floatX
)),
sd_
t
t
],
(
2
,
M_tt
),
[
aet
.
as_tensor_variable
(
np
.
array
(
1.0
,
dtype
=
config
.
floatX
)),
sd_
ae
t
],
(
M_aet
,
),
),
([
aet
.
zeros
((
M_tt
,)),
sd_tt
],
None
),
([
aet
.
zeros
((
M_tt
,)),
sd_tt
],
(
M_tt
,)),
([
aet
.
zeros
((
M_tt
,)),
sd_tt
],
(
2
,
M_tt
)),
([
aet
.
zeros
((
M_tt
,)),
aet
.
ones
((
M_tt
,))],
None
),
([
aet
.
zeros
((
M_tt
,)),
aet
.
ones
((
M_tt
,))],
(
2
,
M_tt
)),
(
[
aet
.
as_tensor_variable
(
np
.
array
(
1.0
,
dtype
=
config
.
floatX
)),
sd_aet
],
(
2
,
M_aet
),
),
([
aet
.
zeros
((
M_aet
,)),
sd_aet
],
None
),
([
aet
.
zeros
((
M_aet
,)),
sd_aet
],
(
M_aet
,)),
([
aet
.
zeros
((
M_aet
,)),
sd_aet
],
(
2
,
M_aet
)),
([
aet
.
zeros
((
M_aet
,)),
aet
.
ones
((
M_aet
,))],
None
),
([
aet
.
zeros
((
M_aet
,)),
aet
.
ones
((
M_aet
,))],
(
2
,
M_aet
)),
(
[
np
.
array
([[
-
1
,
20
],
[
300
,
-
4000
]],
dtype
=
config
.
floatX
),
...
...
@@ -140,12 +143,12 @@ def test_normal_infer_shape():
def
test_normal_ShapeFeature
():
M_
t
t
=
iscalar
(
"M"
)
M_
t
t
.
tag
.
test_value
=
3
sd_
t
t
=
scalar
(
"sd"
)
sd_
t
t
.
tag
.
test_value
=
np
.
array
(
1.0
,
dtype
=
config
.
floatX
)
M_
ae
t
=
iscalar
(
"M"
)
M_
ae
t
.
tag
.
test_value
=
3
sd_
ae
t
=
scalar
(
"sd"
)
sd_
ae
t
.
tag
.
test_value
=
np
.
array
(
1.0
,
dtype
=
config
.
floatX
)
d_rv
=
normal
(
aet
.
ones
((
M_
tt
,)),
sd_tt
,
size
=
(
2
,
M_t
t
))
d_rv
=
normal
(
aet
.
ones
((
M_
aet
,)),
sd_aet
,
size
=
(
2
,
M_ae
t
))
d_rv
.
tag
.
test_value
fg
=
FunctionGraph
(
...
...
@@ -294,10 +297,10 @@ def test_mvnormal_samples():
def
test_mvnormal_ShapeFeature
():
M_
t
t
=
iscalar
(
"M"
)
M_
t
t
.
tag
.
test_value
=
2
M_
ae
t
=
iscalar
(
"M"
)
M_
ae
t
.
tag
.
test_value
=
2
d_rv
=
multivariate_normal
(
aet
.
ones
((
M_
tt
,)),
aet
.
eye
(
M_t
t
),
size
=
2
)
d_rv
=
multivariate_normal
(
aet
.
ones
((
M_
aet
,)),
aet
.
eye
(
M_ae
t
),
size
=
2
)
fg
=
FunctionGraph
(
[
i
for
i
in
graph_inputs
([
d_rv
])
if
not
isinstance
(
i
,
Constant
)],
...
...
@@ -309,7 +312,7 @@ def test_mvnormal_ShapeFeature():
s1
,
s2
=
fg
.
shape_feature
.
shape_of
[
d_rv
]
assert
get_test_value
(
s1
)
==
2
assert
M_
t
t
in
graph_inputs
([
s2
])
assert
M_
ae
t
in
graph_inputs
([
s2
])
# Test broadcasted shapes
mean
=
tensor
(
config
.
floatX
,
[
True
,
False
])
...
...
@@ -369,16 +372,16 @@ def test_dirichlet_samples():
def
test_dirichlet_infer_shape
():
M_
t
t
=
iscalar
(
"M"
)
M_
t
t
.
tag
.
test_value
=
3
M_
ae
t
=
iscalar
(
"M"
)
M_
ae
t
.
tag
.
test_value
=
3
test_params
=
[
([
aet
.
ones
((
M_
t
t
,))],
None
),
([
aet
.
ones
((
M_
tt
,))],
(
M_t
t
+
1
,)),
([
aet
.
ones
((
M_
tt
,))],
(
2
,
M_t
t
)),
([
aet
.
ones
((
M_
tt
,
M_t
t
+
1
))],
None
),
([
aet
.
ones
((
M_
tt
,
M_tt
+
1
))],
(
M_t
t
+
2
,)),
([
aet
.
ones
((
M_
tt
,
M_tt
+
1
))],
(
2
,
M_tt
+
2
,
M_t
t
+
3
)),
([
aet
.
ones
((
M_
ae
t
,))],
None
),
([
aet
.
ones
((
M_
aet
,))],
(
M_ae
t
+
1
,)),
([
aet
.
ones
((
M_
aet
,))],
(
2
,
M_ae
t
)),
([
aet
.
ones
((
M_
aet
,
M_ae
t
+
1
))],
None
),
([
aet
.
ones
((
M_
aet
,
M_aet
+
1
))],
(
M_ae
t
+
2
,)),
([
aet
.
ones
((
M_
aet
,
M_aet
+
1
))],
(
2
,
M_aet
+
2
,
M_ae
t
+
3
)),
]
for
args
,
size
in
test_params
:
rv
=
dirichlet
(
*
args
,
size
=
size
)
...
...
@@ -388,12 +391,12 @@ def test_dirichlet_infer_shape():
def
test_dirichlet_ShapeFeature
():
"""Make sure `RandomVariable.infer_shape` works with `ShapeFeature`."""
M_
t
t
=
iscalar
(
"M"
)
M_
t
t
.
tag
.
test_value
=
2
N_
t
t
=
iscalar
(
"N"
)
N_
t
t
.
tag
.
test_value
=
3
M_
ae
t
=
iscalar
(
"M"
)
M_
ae
t
.
tag
.
test_value
=
2
N_
ae
t
=
iscalar
(
"N"
)
N_
ae
t
.
tag
.
test_value
=
3
d_rv
=
dirichlet
(
aet
.
ones
((
M_
tt
,
N_t
t
)),
name
=
"Gamma"
)
d_rv
=
dirichlet
(
aet
.
ones
((
M_
aet
,
N_ae
t
)),
name
=
"Gamma"
)
fg
=
FunctionGraph
(
[
i
for
i
in
graph_inputs
([
d_rv
])
if
not
isinstance
(
i
,
Constant
)],
...
...
@@ -404,8 +407,8 @@ def test_dirichlet_ShapeFeature():
s1
,
s2
=
fg
.
shape_feature
.
shape_of
[
d_rv
]
assert
M_
t
t
in
graph_inputs
([
s1
])
assert
N_
t
t
in
graph_inputs
([
s2
])
assert
M_
ae
t
in
graph_inputs
([
s1
])
assert
N_
ae
t
in
graph_inputs
([
s2
])
def
test_poisson_samples
():
...
...
tests/tensor/random/test_opt.py
浏览文件 @
4a8ccb6d
...
...
@@ -56,17 +56,17 @@ def test_inplace_optimization():
def
check_shape_lifted_rv
(
rv
,
params
,
size
,
rng
):
aet_params
=
[]
for
p
in
params
:
p_
t
t
=
aet
.
as_tensor
(
p
)
p_
tt
=
p_t
t
.
type
()
p_
t
t
.
tag
.
test_value
=
p
aet_params
.
append
(
p_
t
t
)
p_
ae
t
=
aet
.
as_tensor
(
p
)
p_
aet
=
p_ae
t
.
type
()
p_
ae
t
.
tag
.
test_value
=
p
aet_params
.
append
(
p_
ae
t
)
aet_size
=
[]
for
s
in
size
:
s_
t
t
=
aet
.
as_tensor
(
s
)
s_
tt
=
s_t
t
.
type
()
s_
t
t
.
tag
.
test_value
=
s
aet_size
.
append
(
s_
t
t
)
s_
ae
t
=
aet
.
as_tensor
(
s
)
s_
aet
=
s_ae
t
.
type
()
s_
ae
t
.
tag
.
test_value
=
s
aet_size
.
append
(
s_
ae
t
)
rv
=
rv
(
*
aet_params
,
size
=
aet_size
,
rng
=
rng
)
rv_lifted
=
lift_rv_shapes
(
rv
.
owner
)
...
...
@@ -243,22 +243,22 @@ def test_DimShuffle_lift(ds_order, lifted, dist_op, dist_params, size, rtol):
rng
=
shared
(
np
.
random
.
RandomState
(
1233532
),
borrow
=
False
)
dist_params_
t
t
=
[]
dist_params_
ae
t
=
[]
for
p
in
dist_params
:
p_
t
t
=
aet
.
as_tensor
(
p
)
.
type
()
p_
t
t
.
tag
.
test_value
=
p
dist_params_
tt
.
append
(
p_t
t
)
p_
ae
t
=
aet
.
as_tensor
(
p
)
.
type
()
p_
ae
t
.
tag
.
test_value
=
p
dist_params_
aet
.
append
(
p_ae
t
)
size_
t
t
=
[]
size_
ae
t
=
[]
for
s
in
size
:
s_
t
t
=
iscalar
()
s_
t
t
.
tag
.
test_value
=
s
size_
tt
.
append
(
s_t
t
)
s_
ae
t
=
iscalar
()
s_
ae
t
.
tag
.
test_value
=
s
size_
aet
.
append
(
s_ae
t
)
dist_st
=
dist_op
(
*
dist_params_
tt
,
size
=
size_t
t
,
rng
=
rng
)
.
dimshuffle
(
ds_order
)
dist_st
=
dist_op
(
*
dist_params_
aet
,
size
=
size_ae
t
,
rng
=
rng
)
.
dimshuffle
(
ds_order
)
f_inputs
=
[
p
for
p
in
dist_params_
tt
+
size_t
t
if
not
isinstance
(
p
,
(
slice
,
Constant
))
p
for
p
in
dist_params_
aet
+
size_ae
t
if
not
isinstance
(
p
,
(
slice
,
Constant
))
]
mode
=
Mode
(
...
...
@@ -379,32 +379,32 @@ def test_Subtensor_lift(indices, lifted, dist_op, dist_params, size):
rng
=
shared
(
np
.
random
.
RandomState
(
1233532
),
borrow
=
False
)
dist_params_
t
t
=
[]
dist_params_
ae
t
=
[]
for
p
in
dist_params
:
p_
t
t
=
aet
.
as_tensor
(
p
)
.
type
()
p_
t
t
.
tag
.
test_value
=
p
dist_params_
tt
.
append
(
p_t
t
)
p_
ae
t
=
aet
.
as_tensor
(
p
)
.
type
()
p_
ae
t
.
tag
.
test_value
=
p
dist_params_
aet
.
append
(
p_ae
t
)
size_
t
t
=
[]
size_
ae
t
=
[]
for
s
in
size
:
s_
t
t
=
iscalar
()
s_
t
t
.
tag
.
test_value
=
s
size_
tt
.
append
(
s_t
t
)
s_
ae
t
=
iscalar
()
s_
ae
t
.
tag
.
test_value
=
s
size_
aet
.
append
(
s_ae
t
)
from
aesara.tensor.subtensor
import
as_index_constant
indices_
t
t
=
()
indices_
ae
t
=
()
for
i
in
indices
:
i_
t
t
=
as_index_constant
(
i
)
if
not
isinstance
(
i_
t
t
,
slice
):
i_
t
t
.
tag
.
test_value
=
i
indices_
tt
+=
(
i_t
t
,)
i_
ae
t
=
as_index_constant
(
i
)
if
not
isinstance
(
i_
ae
t
,
slice
):
i_
ae
t
.
tag
.
test_value
=
i
indices_
aet
+=
(
i_ae
t
,)
dist_st
=
dist_op
(
*
dist_params_
tt
,
size
=
size_tt
,
rng
=
rng
)[
indices_t
t
]
dist_st
=
dist_op
(
*
dist_params_
aet
,
size
=
size_aet
,
rng
=
rng
)[
indices_ae
t
]
f_inputs
=
[
p
for
p
in
dist_params_
tt
+
size_tt
+
list
(
indices_t
t
)
for
p
in
dist_params_
aet
+
size_aet
+
list
(
indices_ae
t
)
if
not
isinstance
(
p
,
(
slice
,
Constant
))
]
...
...
tests/tensor/test_basic.py
浏览文件 @
4a8ccb6d
...
...
@@ -728,11 +728,11 @@ class TestNonzero:
m_symb
=
tensor
(
dtype
=
m
.
dtype
,
broadcastable
=
(
False
,)
*
m
.
ndim
)
m_symb
.
tag
.
test_value
=
m
res_tuple_
t
t
=
nonzero
(
m_symb
,
return_matrix
=
False
)
res_matrix_
t
t
=
nonzero
(
m_symb
,
return_matrix
=
True
)
res_tuple_
ae
t
=
nonzero
(
m_symb
,
return_matrix
=
False
)
res_matrix_
ae
t
=
nonzero
(
m_symb
,
return_matrix
=
True
)
res_tuple
=
tuple
(
r
.
tag
.
test_value
for
r
in
res_tuple_
t
t
)
res_matrix
=
res_matrix_
t
t
.
tag
.
test_value
res_tuple
=
tuple
(
r
.
tag
.
test_value
for
r
in
res_tuple_
ae
t
)
res_matrix
=
res_matrix_
ae
t
.
tag
.
test_value
assert
np
.
allclose
(
res_matrix
,
np
.
vstack
(
np
.
nonzero
(
m
)))
...
...
@@ -757,9 +757,9 @@ class TestNonzero:
m_symb
=
tensor
(
dtype
=
m
.
dtype
,
broadcastable
=
(
False
,)
*
m
.
ndim
)
m_symb
.
tag
.
test_value
=
m
res_
t
t
=
flatnonzero
(
m_symb
)
res_
ae
t
=
flatnonzero
(
m_symb
)
result
=
res_
t
t
.
tag
.
test_value
result
=
res_
ae
t
.
tag
.
test_value
assert
np
.
allclose
(
result
,
np
.
flatnonzero
(
m
))
rand0d
=
np
.
empty
(())
...
...
@@ -780,9 +780,9 @@ class TestNonzero:
m_symb
=
tensor
(
dtype
=
m
.
dtype
,
broadcastable
=
(
False
,)
*
m
.
ndim
)
m_symb
.
tag
.
test_value
=
m
res_
t
t
=
nonzero_values
(
m_symb
)
res_
ae
t
=
nonzero_values
(
m_symb
)
result
=
res_
t
t
.
tag
.
test_value
result
=
res_
ae
t
.
tag
.
test_value
assert
np
.
allclose
(
result
,
m
[
np
.
nonzero
(
m
)])
rand0d
=
np
.
empty
(())
...
...
tests/tensor/test_extra_ops.py
浏览文件 @
4a8ccb6d
...
...
@@ -1223,106 +1223,114 @@ def test_broadcast_shape():
x
=
np
.
array
([[
1
],
[
2
],
[
3
]])
y
=
np
.
array
([
4
,
5
,
6
])
b
=
np
.
broadcast
(
x
,
y
)
x_
t
t
=
aet
.
as_tensor_variable
(
x
)
y_
t
t
=
aet
.
as_tensor_variable
(
y
)
b_
tt
=
broadcast_shape
(
x_tt
,
y_t
t
)
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_
t
t
],
b
.
shape
)
x_
ae
t
=
aet
.
as_tensor_variable
(
x
)
y_
ae
t
=
aet
.
as_tensor_variable
(
y
)
b_
aet
=
broadcast_shape
(
x_aet
,
y_ae
t
)
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_
ae
t
],
b
.
shape
)
# Now, we try again using shapes as the inputs
#
# This case also confirms that a broadcast dimension will
# broadcast against a non-broadcast dimension when they're
# both symbolic (i.e. we couldn't obtain constant values).
b_
t
t
=
broadcast_shape
(
shape_tuple
(
x_
t
t
,
use_bcast
=
False
),
shape_tuple
(
y_
t
t
,
use_bcast
=
False
),
b_
ae
t
=
broadcast_shape
(
shape_tuple
(
x_
ae
t
,
use_bcast
=
False
),
shape_tuple
(
y_
ae
t
,
use_bcast
=
False
),
arrays_are_shapes
=
True
,
)
assert
any
(
isinstance
(
node
.
op
,
Assert
)
for
node
in
applys_between
([
x_
tt
,
y_tt
],
b_t
t
)
isinstance
(
node
.
op
,
Assert
)
for
node
in
applys_between
([
x_
aet
,
y_aet
],
b_ae
t
)
)
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_tt
],
b
.
shape
)
b_tt
=
broadcast_shape
(
shape_tuple
(
x_tt
),
shape_tuple
(
y_tt
),
arrays_are_shapes
=
True
)
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_tt
],
b
.
shape
)
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_aet
],
b
.
shape
)
b_aet
=
broadcast_shape
(
shape_tuple
(
x_aet
),
shape_tuple
(
y_aet
),
arrays_are_shapes
=
True
)
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_aet
],
b
.
shape
)
# These are all constants, so there shouldn't be any asserts in the
# resulting graph.
assert
not
any
(
isinstance
(
node
.
op
,
Assert
)
for
node
in
applys_between
([
x_
tt
,
y_tt
],
b_t
t
)
isinstance
(
node
.
op
,
Assert
)
for
node
in
applys_between
([
x_
aet
,
y_aet
],
b_ae
t
)
)
x
=
np
.
array
([
1
,
2
,
3
])
y
=
np
.
array
([
4
,
5
,
6
])
b
=
np
.
broadcast
(
x
,
y
)
x_tt
=
aet
.
as_tensor_variable
(
x
)
y_tt
=
aet
.
as_tensor_variable
(
y
)
b_tt
=
broadcast_shape
(
x_tt
,
y_tt
)
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_tt
],
b
.
shape
)
b_tt
=
broadcast_shape
(
shape_tuple
(
x_tt
),
shape_tuple
(
y_tt
),
arrays_are_shapes
=
True
)
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_tt
],
b
.
shape
)
x_aet
=
aet
.
as_tensor_variable
(
x
)
y_aet
=
aet
.
as_tensor_variable
(
y
)
b_aet
=
broadcast_shape
(
x_aet
,
y_aet
)
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_aet
],
b
.
shape
)
b_aet
=
broadcast_shape
(
shape_tuple
(
x_aet
),
shape_tuple
(
y_aet
),
arrays_are_shapes
=
True
)
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_aet
],
b
.
shape
)
# TODO: This will work when/if we use a more sophisticated `is_same_graph`
# implementation.
# assert not any(
# isinstance(node.op, Assert)
# for node in graph_ops([x_
tt, y_tt], b_t
t)
# for node in graph_ops([x_
aet, y_aet], b_ae
t)
# )
x
=
np
.
empty
((
1
,
2
,
3
))
y
=
np
.
array
(
1
)
b
=
np
.
broadcast
(
x
,
y
)
x_
t
t
=
aet
.
as_tensor_variable
(
x
)
y_
t
t
=
aet
.
as_tensor_variable
(
y
)
b_
tt
=
broadcast_shape
(
x_tt
,
y_t
t
)
assert
b_
t
t
[
0
]
.
value
==
1
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_
t
t
],
b
.
shape
)
x_
ae
t
=
aet
.
as_tensor_variable
(
x
)
y_
ae
t
=
aet
.
as_tensor_variable
(
y
)
b_
aet
=
broadcast_shape
(
x_aet
,
y_ae
t
)
assert
b_
ae
t
[
0
]
.
value
==
1
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_
ae
t
],
b
.
shape
)
assert
not
any
(
isinstance
(
node
.
op
,
Assert
)
for
node
in
applys_between
([
x_
tt
,
y_tt
],
b_t
t
)
isinstance
(
node
.
op
,
Assert
)
for
node
in
applys_between
([
x_
aet
,
y_aet
],
b_ae
t
)
)
b_tt
=
broadcast_shape
(
shape_tuple
(
x_tt
),
shape_tuple
(
y_tt
),
arrays_are_shapes
=
True
)
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_tt
],
b
.
shape
)
b_aet
=
broadcast_shape
(
shape_tuple
(
x_aet
),
shape_tuple
(
y_aet
),
arrays_are_shapes
=
True
)
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_aet
],
b
.
shape
)
x
=
np
.
empty
((
2
,
1
,
3
))
y
=
np
.
empty
((
2
,
1
,
1
))
b
=
np
.
broadcast
(
x
,
y
)
x_
t
t
=
aet
.
as_tensor_variable
(
x
)
y_
t
t
=
aet
.
as_tensor_variable
(
y
)
b_
tt
=
broadcast_shape
(
x_tt
,
y_t
t
)
assert
b_
t
t
[
1
]
.
value
==
1
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_
t
t
],
b
.
shape
)
x_
ae
t
=
aet
.
as_tensor_variable
(
x
)
y_
ae
t
=
aet
.
as_tensor_variable
(
y
)
b_
aet
=
broadcast_shape
(
x_aet
,
y_ae
t
)
assert
b_
ae
t
[
1
]
.
value
==
1
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_
ae
t
],
b
.
shape
)
# TODO: This will work when/if we use a more sophisticated `is_same_graph`
# implementation.
# assert not any(
# isinstance(node.op, Assert)
# for node in graph_ops([x_
tt, y_tt], b_t
t)
# for node in graph_ops([x_
aet, y_aet], b_ae
t)
# )
b_tt
=
broadcast_shape
(
shape_tuple
(
x_tt
),
shape_tuple
(
y_tt
),
arrays_are_shapes
=
True
)
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_tt
],
b
.
shape
)
x1_shp_tt
=
iscalar
(
"x1"
)
x2_shp_tt
=
iscalar
(
"x2"
)
y1_shp_tt
=
iscalar
(
"y1"
)
x_shapes
=
(
1
,
x1_shp_tt
,
x2_shp_tt
)
x_tt
=
aet
.
ones
(
x_shapes
)
y_shapes
=
(
y1_shp_tt
,
1
,
x2_shp_tt
)
y_tt
=
aet
.
ones
(
y_shapes
)
b_tt
=
broadcast_shape
(
x_tt
,
y_tt
)
b_aet
=
broadcast_shape
(
shape_tuple
(
x_aet
),
shape_tuple
(
y_aet
),
arrays_are_shapes
=
True
)
assert
np
.
array_equal
([
z
.
eval
()
for
z
in
b_aet
],
b
.
shape
)
x1_shp_aet
=
iscalar
(
"x1"
)
x2_shp_aet
=
iscalar
(
"x2"
)
y1_shp_aet
=
iscalar
(
"y1"
)
x_shapes
=
(
1
,
x1_shp_aet
,
x2_shp_aet
)
x_aet
=
aet
.
ones
(
x_shapes
)
y_shapes
=
(
y1_shp_aet
,
1
,
x2_shp_aet
)
y_aet
=
aet
.
ones
(
y_shapes
)
b_aet
=
broadcast_shape
(
x_aet
,
y_aet
)
# TODO: This will work when/if we use a more sophisticated `is_same_graph`
# implementation.
# assert not any(
# isinstance(node.op, Assert)
# for node in graph_ops([x_
tt, y_tt], b_t
t)
# for node in graph_ops([x_
aet, y_aet], b_ae
t)
# )
res
=
aet
.
as_tensor
(
b_
t
t
)
.
eval
(
res
=
aet
.
as_tensor
(
b_
ae
t
)
.
eval
(
{
x1_shp_
t
t
:
10
,
x2_shp_
t
t
:
4
,
y1_shp_
t
t
:
2
,
x1_shp_
ae
t
:
10
,
x2_shp_
ae
t
:
4
,
y1_shp_
ae
t
:
2
,
}
)
assert
np
.
array_equal
(
res
,
(
2
,
10
,
4
))
y_shapes
=
(
y1_shp_
tt
,
1
,
y1_shp_t
t
)
y_
t
t
=
aet
.
ones
(
y_shapes
)
b_
tt
=
broadcast_shape
(
x_tt
,
y_t
t
)
assert
isinstance
(
b_
t
t
[
-
1
]
.
owner
.
op
,
Assert
)
y_shapes
=
(
y1_shp_
aet
,
1
,
y1_shp_ae
t
)
y_
ae
t
=
aet
.
ones
(
y_shapes
)
b_
aet
=
broadcast_shape
(
x_aet
,
y_ae
t
)
assert
isinstance
(
b_
ae
t
[
-
1
]
.
owner
.
op
,
Assert
)
class
TestBroadcastTo
(
utt
.
InferShapeTester
):
...
...
@@ -1348,10 +1356,10 @@ class TestBroadcastTo(utt.InferShapeTester):
assert
bcast_res
.
broadcastable
==
(
False
,
True
)
bcast_np
=
np
.
broadcast_to
(
5
,
(
4
,
1
))
bcast_
t
t
=
bcast_res
.
get_test_value
()
bcast_
ae
t
=
bcast_res
.
get_test_value
()
assert
np
.
array_equal
(
bcast_
t
t
,
bcast_np
)
assert
np
.
shares_memory
(
bcast_
t
t
,
a
.
get_test_value
())
assert
np
.
array_equal
(
bcast_
ae
t
,
bcast_np
)
assert
np
.
shares_memory
(
bcast_
ae
t
,
a
.
get_test_value
())
@pytest.mark.parametrize
(
"fn,input_dims"
,
...
...
tests/tensor/test_math.py
浏览文件 @
4a8ccb6d
...
...
@@ -932,9 +932,9 @@ class TestMaxAndArgmax:
def
test_numpy_input
(
self
):
ar
=
np
.
array
([
1
,
2
,
3
])
max_
tt
,
argmax_t
t
=
max_and_argmax
(
ar
,
axis
=
None
)
assert
max_
t
t
.
eval
(),
3
assert
argmax_
t
t
.
eval
(),
2
max_
aet
,
argmax_ae
t
=
max_and_argmax
(
ar
,
axis
=
None
)
assert
max_
ae
t
.
eval
(),
3
assert
argmax_
ae
t
.
eval
(),
2
class
TestArgminArgmax
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论