Skip to content
GitLab
Menu
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
6bff474a
Commit
6bff474a
authored
Aug 08, 2020
by
Markus Holzer
Browse files
Added test case for LinearEquationSystem
parent
b7a97729
Changes
2
Hide whitespace changes
Inline
Side-by-side
pystencils/utils.py
View file @
6bff474a
...
@@ -206,6 +206,7 @@ class LinearEquationSystem:
...
@@ -206,6 +206,7 @@ class LinearEquationSystem:
non_zero_rows
=
self
.
next_zero_row
non_zero_rows
=
self
.
next_zero_row
num_unknowns
=
len
(
self
.
unknowns
)
num_unknowns
=
len
(
self
.
unknowns
)
if
non_zero_rows
==
0
:
if
non_zero_rows
==
0
:
print
(
"test"
)
return
'multiple'
return
'multiple'
*
row_begin
,
left
,
right
=
self
.
_matrix
.
row
(
non_zero_rows
-
1
)
*
row_begin
,
left
,
right
=
self
.
_matrix
.
row
(
non_zero_rows
-
1
)
...
@@ -239,8 +240,3 @@ class LinearEquationSystem:
...
@@ -239,8 +240,3 @@ class LinearEquationSystem:
break
break
result
-=
1
result
-=
1
self
.
next_zero_row
=
result
self
.
next_zero_row
=
result
def
find_unique_solutions_with_zeros
(
system
:
LinearEquationSystem
):
if
not
system
.
solution_structure
()
!=
'multiple'
:
raise
ValueError
(
"Function works only for underdetermined systems"
)
pystencils_tests/test_utils.py
0 → 100644
View file @
6bff474a
import
sympy
as
sp
from
pystencils.utils
import
LinearEquationSystem
def
test_LinearEquationSystem
():
x
,
y
,
z
=
sp
.
symbols
(
"x, y, z"
)
les
=
LinearEquationSystem
([
x
,
y
,
z
])
les
.
add_equation
(
1
*
x
+
2
*
y
-
1
*
z
+
4
)
les
.
add_equation
(
2
*
x
+
1
*
y
+
1
*
z
-
2
)
les
.
add_equation
(
1
*
x
+
2
*
y
+
1
*
z
+
2
)
# usually reduce is not necessary since almost every function of LinearEquationSystem calls reduce beforehand
les
.
reduce
()
expected_matrix
=
sp
.
Matrix
([[
1
,
0
,
0
,
sp
.
Rational
(
5
,
3
)],
[
0
,
1
,
0
,
sp
.
Rational
(
-
7
,
3
)],
[
0
,
0
,
1
,
sp
.
Integer
(
1
)]])
assert
les
.
matrix
==
expected_matrix
assert
les
.
rank
==
3
sol
=
les
.
solution
()
assert
sol
[
x
]
==
sp
.
Rational
(
5
,
3
)
assert
sol
[
y
]
==
sp
.
Rational
(
-
7
,
3
)
assert
sol
[
z
]
==
sp
.
Integer
(
1
)
les
=
LinearEquationSystem
([
x
,
y
])
assert
les
.
solution_structure
()
==
'multiple'
les
.
add_equation
(
x
+
1
)
assert
les
.
solution_structure
()
==
'multiple'
les
.
add_equation
(
y
+
2
)
assert
les
.
solution_structure
()
==
'single'
les
.
add_equation
(
x
+
y
+
5
)
assert
les
.
solution_structure
()
==
'none'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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