Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sebastian Bindgen
pystencils
Commits
1c57a059
Commit
1c57a059
authored
5 years ago
by
Stephan Seitz
Browse files
Options
Downloads
Patches
Plain Diff
Assert same length when performing vector assignment
parent
38da1c39
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/assignment.py
+2
-1
2 additions, 1 deletion
pystencils/assignment.py
pystencils_tests/test_assignment_collection.py
+13
-1
13 additions, 1 deletion
pystencils_tests/test_assignment_collection.py
with
15 additions
and
2 deletions
pystencils/assignment.py
+
2
−
1
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
)
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_assignment_collection.py
+
13
−
1
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment