Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Stephan Seitz
pystencils
Commits
1c57a059
Commit
1c57a059
authored
Jan 18, 2020
by
Stephan Seitz
Browse files
Assert same length when performing vector assignment
parent
38da1c39
Pipeline
#21151
passed with stage
in 2 minutes and 25 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pystencils/assignment.py
View file @
1c57a059
...
...
@@ -26,7 +26,8 @@ if Assignment:
_old_new
=
sp
.
codegen
.
ast
.
Assignment
.
__new__
def
_Assignment__new__
(
cls
,
lhs
,
rhs
,
*
args
,
**
kwargs
):
if
isinstance
(
lhs
,
(
list
,
set
,
tuple
,
sp
.
Matrix
))
and
isinstance
(
rhs
,
(
list
,
set
,
tuple
,
sp
.
Matrix
)):
if
isinstance
(
lhs
,
(
list
,
tuple
,
sp
.
Matrix
))
and
isinstance
(
rhs
,
(
list
,
tuple
,
sp
.
Matrix
)):
assert
len
(
lhs
)
==
len
(
rhs
),
f
'
{
lhs
}
and
{
rhs
}
must have same length when performing vector assignment!'
return
tuple
(
_old_new
(
cls
,
a
,
b
,
*
args
,
**
kwargs
)
for
a
,
b
in
zip
(
lhs
,
rhs
))
return
_old_new
(
cls
,
lhs
,
rhs
,
*
args
,
**
kwargs
)
...
...
pystencils_tests/test_assignment_collection.py
View file @
1c57a059
import
pytest
import
sympy
as
sp
from
pystencils
import
Assignment
,
AssignmentCollection
...
...
@@ -52,6 +53,18 @@ def test_vector_assignments():
print
(
assignments
)
def
test_wrong_vector_assignments
():
"""From #17 (https://i10git.cs.fau.de/pycodegen/pystencils/issues/17)"""
import
pystencils
as
ps
import
sympy
as
sp
a
,
b
=
sp
.
symbols
(
"a b"
)
with
pytest
.
raises
(
AssertionError
,
match
=
r
'Matrix(.*) and Matrix(.*) must have same length when performing vector assignment!'
):
ps
.
Assignment
(
sp
.
Matrix
([
a
,
b
]),
sp
.
Matrix
([
1
,
2
,
3
]))
def
test_vector_assignment_collection
():
"""From #17 (https://i10git.cs.fau.de/pycodegen/pystencils/issues/17)"""
...
...
@@ -64,4 +77,3 @@ def test_vector_assignment_collection():
assignments
=
ps
.
AssignmentCollection
([
ps
.
Assignment
(
y
,
x
)])
print
(
assignments
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment