Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b6316e83
提交
b6316e83
authored
10月 08, 2025
作者:
Virgile Andreani
提交者:
Virgile Andreani
10月 09, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Apply rule RUF043
上级
e27a43a0
显示空白字符变更
内嵌
并排
正在显示
22 个修改的文件
包含
59 行增加
和
57 行删除
+59
-57
test_builders.py
tests/compile/test_builders.py
+1
-1
test_compute_test_value.py
tests/graph/test_compute_test_value.py
+1
-1
test_fg.py
tests/graph/test_fg.py
+12
-12
test_random.py
tests/link/numba/test_random.py
+1
-1
test_elemwise.py
tests/link/pytorch/test_elemwise.py
+2
-2
test_extra_ops.py
tests/link/pytorch/test_extra_ops.py
+2
-2
test_vm.py
tests/link/test_vm.py
+3
-3
test_type.py
tests/sparse/test_type.py
+1
-1
test_op.py
tests/tensor/random/test_op.py
+2
-2
test_utils.py
tests/tensor/random/test_utils.py
+2
-2
test_basic.py
tests/tensor/rewriting/test_basic.py
+1
-1
test_basic.py
tests/tensor/test_basic.py
+9
-9
test_extra_ops.py
tests/tensor/test_extra_ops.py
+1
-1
test_math.py
tests/tensor/test_math.py
+1
-1
test_shape.py
tests/tensor/test_shape.py
+5
-5
test_slinalg.py
tests/tensor/test_slinalg.py
+1
-1
test_subtensor.py
tests/tensor/test_subtensor.py
+3
-3
test_type.py
tests/tensor/test_type.py
+1
-1
test_config.py
tests/test_config.py
+4
-2
test_ifelse.py
tests/test_ifelse.py
+2
-2
test_indexing.py
tests/xtensor/test_indexing.py
+1
-1
test_shape.py
tests/xtensor/test_shape.py
+3
-3
没有找到文件。
tests/compile/test_builders.py
浏览文件 @
b6316e83
...
...
@@ -45,7 +45,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
def
test_valid_input
(
self
):
x
,
y
,
z
=
matrices
(
"xyz"
)
with
pytest
.
raises
(
ValueError
,
match
=
"Expected at least.*"
):
with
pytest
.
raises
(
ValueError
,
match
=
r
"Expected at least.*"
):
OpFromGraph
([
x
],
[
x
])()
with
pytest
.
raises
(
ValueError
,
match
=
r"Expected 1 input\(s\)"
):
...
...
tests/graph/test_compute_test_value.py
浏览文件 @
b6316e83
...
...
@@ -264,7 +264,7 @@ class TestComputeTestValue:
fn
=
fx
,
outputs_info
=
pt
.
ones_like
(
A
.
T
),
non_sequences
=
A
,
n_steps
=
k
)
with
pytest
.
raises
(
ValueError
,
match
=
"^could not broadcast input"
):
with
pytest
.
raises
(
ValueError
,
match
=
r
"^could not broadcast input"
):
pytensor
.
scan
(
fn
=
fx
,
outputs_info
=
pt
.
ones_like
(
A
.
T
),
non_sequences
=
A
,
n_steps
=
k
)
...
...
tests/graph/test_fg.py
浏览文件 @
b6316e83
...
...
@@ -62,8 +62,8 @@ class TestFunctionGraph:
with
pytest
.
raises
(
ValueError
,
match
=
(
"One of the provided inputs is the output of an already existing node. "
"If that is okay, either discard that input's owner or use graph
.clone
."
"One of the provided inputs is the output of an already existing node
\\
. "
"If that is okay, either discard that input's owner or use graph
\\
.clone
\\
."
),
):
var3
=
op1
(
var1
)
...
...
@@ -208,7 +208,7 @@ class TestFunctionGraph:
assert
var5
in
fg
.
variables
assert
var5
.
owner
in
fg
.
apply_nodes
with
pytest
.
raises
(
TypeError
,
match
=
"Computation graph contains.*"
):
with
pytest
.
raises
(
TypeError
,
match
=
r
"Computation graph contains.*"
):
from
pytensor.graph.null_type
import
NullType
fg
.
import_var
(
NullType
()(),
"testing"
)
...
...
@@ -265,7 +265,7 @@ class TestFunctionGraph:
assert
var6
.
tag
.
test_value
.
shape
!=
var4
.
tag
.
test_value
.
shape
with
pytest
.
raises
(
AssertionError
,
match
=
"The replacement.*"
):
with
pytest
.
raises
(
AssertionError
,
match
=
r
"The replacement.*"
):
fg
.
replace
(
var4
,
var6
)
def
test_replace
(
self
):
...
...
@@ -342,12 +342,12 @@ class TestFunctionGraph:
var5
=
op3
(
var4
,
var2
,
var2
)
fg
=
FunctionGraph
([
var1
,
var2
],
[
var3
,
var5
],
clone
=
False
)
with
pytest
.
raises
(
Exception
,
match
=
"The following nodes are .*"
):
with
pytest
.
raises
(
Exception
,
match
=
r
"The following nodes are .*"
):
fg
.
apply_nodes
.
remove
(
var5
.
owner
)
fg
.
check_integrity
()
with
pytest
.
raises
(
Exception
,
match
=
"Inconsistent clients.*"
):
with
pytest
.
raises
(
Exception
,
match
=
r
"Inconsistent clients.*"
):
fg
.
apply_nodes
.
add
(
var5
.
owner
)
fg
.
remove_client
(
var2
,
(
var5
.
owner
,
1
))
...
...
@@ -355,14 +355,14 @@ class TestFunctionGraph:
fg
.
add_client
(
var2
,
(
var5
.
owner
,
1
))
with
pytest
.
raises
(
Exception
,
match
=
"The following variables are.*"
):
with
pytest
.
raises
(
Exception
,
match
=
r
"The following variables are.*"
):
fg
.
variables
.
remove
(
var4
)
fg
.
check_integrity
()
fg
.
variables
.
add
(
var4
)
with
pytest
.
raises
(
Exception
,
match
=
"Undeclared input.*"
):
with
pytest
.
raises
(
Exception
,
match
=
r
"Undeclared input.*"
):
var6
=
MyVariable2
(
"var6"
)
fg
.
clients
[
var6
]
=
[(
var5
.
owner
,
3
)]
fg
.
variables
.
add
(
var6
)
...
...
@@ -376,26 +376,26 @@ class TestFunctionGraph:
# TODO: What if the index value is greater than 1? It will throw an
# `IndexError`, but that doesn't sound like anything we'd want.
out_node
=
Output
(
idx
=
1
)
.
make_node
(
var4
)
with
pytest
.
raises
(
Exception
,
match
=
"Inconsistent clients list.*"
):
with
pytest
.
raises
(
Exception
,
match
=
r
"Inconsistent clients list.*"
):
fg
.
add_client
(
var4
,
(
out_node
,
0
))
fg
.
check_integrity
()
fg
.
remove_client
(
var4
,
(
out_node
,
0
))
with
pytest
.
raises
(
TypeError
,
match
=
"The first entry of.*"
):
with
pytest
.
raises
(
TypeError
,
match
=
r
"The first entry of.*"
):
fg
.
add_client
(
var4
,
(
None
,
0
))
var7
=
op1
(
var4
)
with
pytest
.
raises
(
Exception
,
match
=
"Client not in FunctionGraph.*"
):
with
pytest
.
raises
(
Exception
,
match
=
r
"Client not in FunctionGraph.*"
):
fg
.
add_client
(
var4
,
(
var7
.
owner
,
0
))
fg
.
check_integrity
()
fg
.
remove_client
(
var4
,
(
var7
.
owner
,
0
))
with
pytest
.
raises
(
Exception
,
match
=
"Inconsistent clients list.*"
):
with
pytest
.
raises
(
Exception
,
match
=
r
"Inconsistent clients list.*"
):
fg
.
add_client
(
var4
,
(
var3
.
owner
,
0
))
fg
.
check_integrity
()
...
...
tests/link/numba/test_random.py
浏览文件 @
b6316e83
...
...
@@ -662,7 +662,7 @@ def test_unaligned_RandomVariable(rv_op, dist_args, base_size, cdf_name, params_
(
10
,
4
),
pytest
.
raises
(
ValueError
,
match
=
"Vectorized input 0 has an incompatible shape in axis 1."
,
match
=
"Vectorized input 0 has an incompatible shape in axis 1
\\
."
,
),
),
],
...
...
tests/link/pytorch/test_elemwise.py
浏览文件 @
b6316e83
...
...
@@ -108,7 +108,7 @@ def test_softmax(axis, dtype):
if
dtype
==
"int64"
:
with
pytest
.
raises
(
NotImplementedError
,
match
=
"Pytorch Softmax is not currently implemented for non-float types."
,
match
=
"Pytorch Softmax is not currently implemented for non-float types
\\
."
,
):
compare_pytorch_and_py
([
x
],
[
out
],
[
test_input
])
else
:
...
...
@@ -125,7 +125,7 @@ def test_logsoftmax(axis, dtype):
if
dtype
==
"int64"
:
with
pytest
.
raises
(
NotImplementedError
,
match
=
"Pytorch LogSoftmax is not currently implemented for non-float types."
,
match
=
"Pytorch LogSoftmax is not currently implemented for non-float types
\\
."
,
):
compare_pytorch_and_py
([
x
],
[
out
],
[
test_input
])
else
:
...
...
tests/link/pytorch/test_extra_ops.py
浏览文件 @
b6316e83
...
...
@@ -24,9 +24,9 @@ def test_pytorch_CumOp(axis, dtype):
# Create the output variable
if
isinstance
(
axis
,
tuple
):
with
pytest
.
raises
(
TypeError
,
match
=
"axis must be an integer or None."
):
with
pytest
.
raises
(
TypeError
,
match
=
"axis must be an integer or None
\\
."
):
out
=
pt
.
cumsum
(
a
,
axis
=
axis
)
with
pytest
.
raises
(
TypeError
,
match
=
"axis must be an integer or None."
):
with
pytest
.
raises
(
TypeError
,
match
=
"axis must be an integer or None
\\
."
):
out
=
pt
.
cumprod
(
a
,
axis
=
axis
)
else
:
out
=
pt
.
cumsum
(
a
,
axis
=
axis
)
...
...
tests/link/test_vm.py
浏览文件 @
b6316e83
...
...
@@ -421,7 +421,7 @@ def test_VMLinker_exception():
z
=
BadOp
()(
a
)
with
pytest
.
raises
(
Exception
,
match
=
".*Apply node that caused the error.*"
):
with
pytest
.
raises
(
Exception
,
match
=
r
".*Apply node that caused the error.*"
):
function
([
a
],
z
,
mode
=
Mode
(
optimizer
=
None
,
linker
=
linker
))
...
...
@@ -433,7 +433,7 @@ def test_VM_exception():
a
=
scalar
()
fg
=
FunctionGraph
(
outputs
=
[
SomeOp
()(
a
)])
with
pytest
.
raises
(
ValueError
,
match
=
"`nodes` and `thunks`.*"
):
with
pytest
.
raises
(
ValueError
,
match
=
r
"`nodes` and `thunks`.*"
):
SomeVM
(
fg
,
fg
.
apply_nodes
,
[],
[])
...
...
@@ -453,7 +453,7 @@ def test_Loop_exception():
thunks
=
[
node
.
op
.
make_thunk
(
node
,
storage_map
,
compute_map
,
[])
for
node
in
nodes
]
with
pytest
.
raises
(
ValueError
,
match
=
"`nodes`, `thunks` and `post_thunk_clear`.*"
):
with
pytest
.
raises
(
ValueError
,
match
=
r
"`nodes`, `thunks` and `post_thunk_clear`.*"
):
Loop
(
fg
,
fg
.
apply_nodes
,
...
...
tests/sparse/test_type.py
浏览文件 @
b6316e83
...
...
@@ -79,5 +79,5 @@ def test_SparseTensorType_filter():
x_res
=
z
.
type
.
filter
(
x
.
astype
(
"float32"
),
allow_downcast
=
True
)
assert
x_res
.
dtype
==
"float64"
with
pytest
.
raises
(
TypeError
,
match
=
".*dtype but got.*"
):
with
pytest
.
raises
(
TypeError
,
match
=
r
".*dtype but got.*"
):
w
.
type
.
filter
(
x
)
tests/tensor/random/test_op.py
浏览文件 @
b6316e83
...
...
@@ -32,7 +32,7 @@ def test_RandomVariable_basics(strict_test_value_flags):
assert
str_res
==
'normal_rv{"(),()->()"}'
# `ndims_params` should be a `Sequence` type
with
pytest
.
raises
(
TypeError
,
match
=
"^Parameter ndims_params*"
):
with
pytest
.
raises
(
TypeError
,
match
=
r
"^Parameter ndims_params*"
):
RandomVariable
(
"normal"
,
0
,
...
...
@@ -42,7 +42,7 @@ def test_RandomVariable_basics(strict_test_value_flags):
)
# `size` should be a `Sequence` type
with
pytest
.
raises
(
TypeError
,
match
=
"^Parameter size*"
):
with
pytest
.
raises
(
TypeError
,
match
=
r
"^Parameter size*"
):
RandomVariable
(
"normal"
,
0
,
...
...
tests/tensor/random/test_utils.py
浏览文件 @
b6316e83
...
...
@@ -284,7 +284,7 @@ class TestSharedRandomStream:
def
test_supp_shape_from_ref_param_shape
():
with
pytest
.
raises
(
ValueError
,
match
=
"^ndim_supp*"
):
with
pytest
.
raises
(
ValueError
,
match
=
r
"^ndim_supp*"
):
supp_shape_from_ref_param_shape
(
ndim_supp
=
0
,
dist_params
=
(
np
.
array
([
1
,
2
]),
0
),
...
...
@@ -306,7 +306,7 @@ def test_supp_shape_from_ref_param_shape():
)
assert
res
==
(
2
,)
with
pytest
.
raises
(
ValueError
,
match
=
"^Reference parameter*"
):
with
pytest
.
raises
(
ValueError
,
match
=
r
"^Reference parameter*"
):
supp_shape_from_ref_param_shape
(
ndim_supp
=
1
,
dist_params
=
(
np
.
array
(
1
),),
...
...
tests/tensor/rewriting/test_basic.py
浏览文件 @
b6316e83
...
...
@@ -298,7 +298,7 @@ class TestLocalCanonicalizeAlloc:
# Error raised by SpecifyShape that is introduced due to static shape inference
with
pytest
.
raises
(
AssertionError
,
match
=
"SpecifyShape: dim 0 of input has shape 3, expected 6."
,
match
=
"SpecifyShape: dim 0 of input has shape 3, expected 6
\\
."
,
):
f
()
else
:
...
...
tests/tensor/test_basic.py
浏览文件 @
b6316e83
...
...
@@ -589,7 +589,7 @@ class TestAsTensorVariable:
def
test_ndim_incompatible
(
self
):
x
=
TensorType
(
config
.
floatX
,
shape
=
(
1
,
None
))(
"x"
)
with
pytest
.
raises
(
ValueError
,
match
=
"^Tensor of type.*"
):
with
pytest
.
raises
(
ValueError
,
match
=
r
"^Tensor of type.*"
):
as_tensor_variable
(
x
,
ndim
=
0
)
def
test_bool
(
self
):
...
...
@@ -898,7 +898,7 @@ class TestAlloc:
def
test_infer_static_shape
():
with
pytest
.
raises
(
TypeError
,
match
=
"^Shapes must be scalar integers.*"
):
with
pytest
.
raises
(
TypeError
,
match
=
r
"^Shapes must be scalar integers.*"
):
infer_static_shape
([
constant
(
1.0
)])
with
(
...
...
@@ -907,7 +907,7 @@ def test_infer_static_shape():
):
infer_static_shape
([
dscalar
(
"x"
)])
with
pytest
.
raises
(
ValueError
,
match
=
".*could not be cast to have 0 dimensions"
):
with
pytest
.
raises
(
ValueError
,
match
=
r
".*could not be cast to have 0 dimensions"
):
infer_static_shape
((
as_tensor_variable
([[
1
,
2
]]),))
constant_size
=
constant
([
1
])
...
...
@@ -1269,7 +1269,7 @@ def test_get_vector_length():
as_tensor_variable
([
1
,
2
],
ndim
=
1
),
as_tensor_variable
([
3
,
4
],
ndim
=
1
),
)
with
pytest
.
raises
(
ValueError
,
match
=
"^Length of .*"
):
with
pytest
.
raises
(
ValueError
,
match
=
r
"^Length of .*"
):
get_vector_length
(
z
)
# Test `MakeVector`s
...
...
@@ -1329,13 +1329,13 @@ class TestJoinAndSplit:
return
variables
def
test_input_validation
(
self
):
with
pytest
.
raises
(
TypeError
,
match
=
".*integer.*"
):
with
pytest
.
raises
(
TypeError
,
match
=
r
".*integer.*"
):
Split
(
2
)(
matrix
(),
dscalar
(),
[
1
,
1
])
with
pytest
.
raises
(
TypeError
,
match
=
".*integer.*"
):
with
pytest
.
raises
(
TypeError
,
match
=
r
".*integer.*"
):
Split
(
2
)(
matrix
(),
ivector
(),
[
1
,
1
])
with
pytest
.
raises
(
TypeError
,
match
=
".*integer.*"
):
with
pytest
.
raises
(
TypeError
,
match
=
r
".*integer.*"
):
join
(
dscalar
(),
matrix
(),
matrix
())
def
test_join_scalar
(
self
):
...
...
@@ -3131,7 +3131,7 @@ def test_default():
assert
f
(
None
,
2
)
==
2
assert
f
(
1
,
None
)
==
1
with
pytest
.
raises
(
TypeError
,
match
=
".*compatible types.*"
):
with
pytest
.
raises
(
TypeError
,
match
=
r
".*compatible types.*"
):
default
(
x
,
vector
())
...
...
@@ -3622,7 +3622,7 @@ class TestDiag:
@pytest.mark.parametrize
(
"inp"
,
(
scalar
,
tensor3
))
def
test_diag_invalid_input_ndim
(
self
,
inp
):
x
=
inp
()
with
pytest
.
raises
(
ValueError
,
match
=
"Input must be 1- or 2-d."
):
with
pytest
.
raises
(
ValueError
,
match
=
"Input must be 1- or 2-d
\\
."
):
diag
(
x
)
...
...
tests/tensor/test_extra_ops.py
浏览文件 @
b6316e83
...
...
@@ -1374,7 +1374,7 @@ def test_concat_with_broadcast():
with
pytest
.
raises
(
TypeError
,
match
=
"Only tensors with the same number of dimensions can be concatenated."
,
match
=
"Only tensors with the same number of dimensions can be concatenated
\\
."
,
):
a
=
pt
.
tensor
(
"a"
,
shape
=
(
1
,
3
,
5
))
b
=
pt
.
tensor
(
"b"
,
shape
=
(
3
,
5
))
...
...
tests/tensor/test_math.py
浏览文件 @
b6316e83
...
...
@@ -1462,7 +1462,7 @@ class TestMinMax:
def
test_MaxAndArgmax_deprecated
():
with
pytest
.
raises
(
AttributeError
,
match
=
"The class `MaxandArgmax` has been deprecated
. Call `Max` and `Argmax` seperately as an alternative
."
,
match
=
"The class `MaxandArgmax` has been deprecated
\\
. Call `Max` and `Argmax` seperately as an alternative
\\
."
,
):
pytensor
.
tensor
.
math
.
MaxAndArgmax
...
...
tests/tensor/test_shape.py
浏览文件 @
b6316e83
...
...
@@ -495,14 +495,14 @@ class TestSpecifyShape(utt.InferShapeTester):
f
=
pytensor
.
function
([
x
,
shape
],
y
,
mode
=
Mode
(
"py"
))
assert
f
([
1
],
(
1
,))
==
[
1
]
with
pytest
.
raises
(
AssertionError
,
match
=
"SpecifyShape:.*"
):
with
pytest
.
raises
(
AssertionError
,
match
=
r
"SpecifyShape:.*"
):
assert
f
([
1
],
(
2
,))
==
[
1
]
x
=
matrix
()
y
=
specify_shape
(
x
,
(
None
,
2
))
f
=
pytensor
.
function
([
x
],
y
,
mode
=
Mode
(
"py"
))
assert
f
(
np
.
zeros
((
3
,
2
),
dtype
=
config
.
floatX
))
.
shape
==
(
3
,
2
)
with
pytest
.
raises
(
AssertionError
,
match
=
"SpecifyShape:.*"
):
with
pytest
.
raises
(
AssertionError
,
match
=
r
"SpecifyShape:.*"
):
assert
f
(
np
.
zeros
((
3
,
3
),
dtype
=
config
.
floatX
))
def
test_bad_shape
(
self
):
...
...
@@ -516,7 +516,7 @@ class TestSpecifyShape(utt.InferShapeTester):
assert
np
.
array_equal
(
f
(
xval
),
xval
)
xval
=
np
.
random
.
random
(
3
)
.
astype
(
config
.
floatX
)
with
pytest
.
raises
(
AssertionError
,
match
=
"SpecifyShape:.*"
):
with
pytest
.
raises
(
AssertionError
,
match
=
r
"SpecifyShape:.*"
):
f
(
xval
)
assert
isinstance
(
...
...
@@ -540,14 +540,14 @@ class TestSpecifyShape(utt.InferShapeTester):
for
shape_
in
[(
4
,
3
),
(
2
,
8
)]:
xval
=
np
.
random
.
random
(
shape_
)
.
astype
(
config
.
floatX
)
with
pytest
.
raises
(
AssertionError
,
match
=
"SpecifyShape:.*"
):
with
pytest
.
raises
(
AssertionError
,
match
=
r
"SpecifyShape:.*"
):
f
(
xval
)
s
=
iscalar
(
"s"
)
f
=
pytensor
.
function
([
x
,
s
],
specify_shape
(
x
,
None
,
s
),
mode
=
self
.
mode
)
x_val
=
np
.
zeros
((
3
,
2
),
dtype
=
config
.
floatX
)
assert
f
(
x_val
,
2
)
.
shape
==
(
3
,
2
)
with
pytest
.
raises
(
AssertionError
,
match
=
"SpecifyShape:.*"
):
with
pytest
.
raises
(
AssertionError
,
match
=
r
"SpecifyShape:.*"
):
f
(
xval
,
3
)
def
test_infer_shape
(
self
):
...
...
tests/tensor/test_slinalg.py
浏览文件 @
b6316e83
...
...
@@ -240,7 +240,7 @@ class TestSolveBase:
def
test_solve_raises_on_invalid_assume_a
():
with
pytest
.
raises
(
ValueError
,
match
=
"Invalid assume_a: test. It must be one of"
):
with
pytest
.
raises
(
ValueError
,
match
=
"Invalid assume_a: test
\\
. It must be one of"
):
Solve
(
assume_a
=
"test"
,
b_ndim
=
2
)
...
...
tests/tensor/test_subtensor.py
浏览文件 @
b6316e83
...
...
@@ -1364,12 +1364,12 @@ class TestSubtensor(utt.OptimizationTestMixin):
f
(
np
.
ones
((
20
,
5
)))
# Fine
with
pytest
.
raises
(
ValueError
,
match
=
"Runtime broadcasting not allowed. AdvancedIncSubtensor1 was asked"
,
match
=
"Runtime broadcasting not allowed
\\
. AdvancedIncSubtensor1 was asked"
,
):
f
(
np
.
ones
((
1
,
5
)))
with
pytest
.
raises
(
ValueError
,
match
=
"Runtime broadcasting not allowed. AdvancedIncSubtensor1 was asked"
,
match
=
"Runtime broadcasting not allowed
\\
. AdvancedIncSubtensor1 was asked"
,
):
f
(
np
.
ones
((
20
,
1
)))
...
...
@@ -2903,7 +2903,7 @@ def test_get_vector_length():
assert
get_vector_length
(
lvector
()[
1
:
1
])
==
0
assert
get_vector_length
(
lvector
()[
-
1
:
-
1
:
3
])
==
0
with
pytest
.
raises
(
ValueError
,
match
=
"^Length of .*"
):
with
pytest
.
raises
(
ValueError
,
match
=
r
"^Length of .*"
):
get_vector_length
(
x
[
lscalar
()
:])
...
...
tests/tensor/test_type.py
浏览文件 @
b6316e83
...
...
@@ -115,7 +115,7 @@ def test_filter_variable():
with
pytest
.
raises
(
TypeError
):
test_type
.
filter
(
np
.
empty
((
0
,
1
),
dtype
=
config
.
floatX
))
with
pytest
.
raises
(
TypeError
,
match
=
".*not aligned.*"
):
with
pytest
.
raises
(
TypeError
,
match
=
r
".*not aligned.*"
):
test_val
=
np
.
empty
((
1
,
2
),
dtype
=
config
.
floatX
)
test_val
.
flags
.
aligned
=
False
test_type
.
filter
(
test_val
)
...
...
tests/test_config.py
浏览文件 @
b6316e83
...
...
@@ -150,7 +150,9 @@ class TestConfigTypes:
cp
.
_apply
(
"cuda123"
)
with
pytest
.
raises
(
ValueError
,
match
=
"It was removed from PyTensor"
):
cp
.
_apply
(
"gpu123"
)
with
pytest
.
raises
(
ValueError
,
match
=
'Valid options start with one of "cpu".'
):
with
pytest
.
raises
(
ValueError
,
match
=
'Valid options start with one of "cpu"
\\
.'
):
cp
.
_apply
(
"notadevice"
)
assert
str
(
cp
)
==
"unnamed (cpu)"
...
...
@@ -247,7 +249,7 @@ def test_config_pickling():
)
with
pytest
.
raises
(
AttributeError
,
match
=
"Can't (pickle|get) local object 'test_config_pickling.<locals>
.<lambda>'"
,
match
=
r"Can't (pickle|get) local object 'test_config_pickling\.<locals>\
.<lambda>'"
,
):
pickle
.
dump
(
root
,
io
.
BytesIO
())
...
...
tests/test_ifelse.py
浏览文件 @
b6316e83
...
...
@@ -335,9 +335,9 @@ class TestIfelse(utt.OptimizationTestMixin):
z
=
matrix
(
"csr"
,
dtype
=
self
.
dtype
,
name
=
"z"
)
cond
=
iscalar
(
"cond"
)
with
pytest
.
raises
(
TypeError
,
match
=
".*do not match."
):
with
pytest
.
raises
(
TypeError
,
match
=
r
".*do not match."
):
ifelse
(
cond
,
x
,
y
)
with
pytest
.
raises
(
TypeError
,
match
=
".*do not match."
):
with
pytest
.
raises
(
TypeError
,
match
=
r
".*do not match."
):
ifelse
(
cond
,
y
,
x
)
with
pytest
.
raises
(
TypeError
):
ifelse
(
cond
,
x
,
z
)
...
...
tests/xtensor/test_indexing.py
浏览文件 @
b6316e83
...
...
@@ -411,7 +411,7 @@ def test_adv_index_update(mode, idx_dtype):
else
:
with
pytest
.
raises
(
IndexError
,
match
=
"Boolean indexer should be unlabeled or on the same dimension to the indexed array."
,
match
=
"Boolean indexer should be unlabeled or on the same dimension to the indexed array
\\
."
,
):
getattr
(
x
[
idx
.
rename
(
a
=
"b"
),
:
3
],
mode
)(
y
)
vectorized_update
=
x
...
...
tests/xtensor/test_shape.py
浏览文件 @
b6316e83
...
...
@@ -349,11 +349,11 @@ def test_squeeze_errors():
# Non-existent dimension
x1
=
xtensor
(
"x1"
,
dims
=
(
"city"
,
"country"
),
shape
=
(
3
,
1
))
with
pytest
.
raises
(
ValueError
,
match
=
"Dimension .* not found"
):
with
pytest
.
raises
(
ValueError
,
match
=
r
"Dimension .* not found"
):
x1
.
squeeze
(
"time"
)
# Dimension size > 1
with
pytest
.
raises
(
ValueError
,
match
=
"has static size .* not 1"
):
with
pytest
.
raises
(
ValueError
,
match
=
r
"has static size .* not 1"
):
x1
.
squeeze
(
"city"
)
# Symbolic shape: dim is not 1 at runtime → should raise
...
...
@@ -579,7 +579,7 @@ class TestBroadcast:
y
=
xtensor
(
"y"
,
dims
=
(
"c"
,
"d"
),
shape
=
(
5
,
6
))
z
=
xtensor
(
"z"
,
dims
=
(
"b"
,
"d"
),
shape
=
(
4
,
7
))
with
pytest
.
raises
(
ValueError
,
match
=
"Dimension .* has conflicting shapes"
):
with
pytest
.
raises
(
ValueError
,
match
=
r
"Dimension .* has conflicting shapes"
):
broadcast
(
x
,
y
,
z
)
def
test_broadcast_no_input
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论