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
Model registry
Operate
Environments
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
pycodegen
pystencils
Commits
7df37e9f
Commit
7df37e9f
authored
6 years ago
by
Martin Bauer
Browse files
Options
Downloads
Patches
Plain Diff
Generation of packing kernels
parent
66023ebf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils.py
+18
-1
18 additions, 1 deletion
utils.py
with
18 additions
and
1 deletion
utils.py
+
18
−
1
View file @
7df37e9f
...
@@ -111,6 +111,7 @@ class LinearEquationSystem:
...
@@ -111,6 +111,7 @@ class LinearEquationSystem:
self
.
_matrix
=
sp
.
zeros
(
size
,
size
+
1
)
self
.
_matrix
=
sp
.
zeros
(
size
,
size
+
1
)
self
.
unknowns
=
unknowns
self
.
unknowns
=
unknowns
self
.
next_zero_row
=
0
self
.
next_zero_row
=
0
self
.
_reduced
=
True
def
copy
(
self
):
def
copy
(
self
):
"""
Returns a copy of the equation system.
"""
"""
Returns a copy of the equation system.
"""
...
@@ -135,6 +136,7 @@ class LinearEquationSystem:
...
@@ -135,6 +136,7 @@ class LinearEquationSystem:
if
rest
.
atoms
(
sp
.
Symbol
):
if
rest
.
atoms
(
sp
.
Symbol
):
raise
ValueError
(
"
Not a linear equation in the unknowns
"
)
raise
ValueError
(
"
Not a linear equation in the unknowns
"
)
self
.
_matrix
[
zero_row_idx
,
-
1
]
=
-
rest
self
.
_matrix
[
zero_row_idx
,
-
1
]
=
-
rest
self
.
_reduced
=
False
def
add_equations
(
self
,
linear_equations
):
def
add_equations
(
self
,
linear_equations
):
"""
Add a sequence of equations. For details see `add_equation`.
"""
"""
Add a sequence of equations. For details see `add_equation`.
"""
...
@@ -148,18 +150,28 @@ class LinearEquationSystem:
...
@@ -148,18 +150,28 @@ class LinearEquationSystem:
self
.
_resize_if_necessary
()
self
.
_resize_if_necessary
()
self
.
_matrix
[
self
.
next_zero_row
,
unknown_idx
]
=
1
self
.
_matrix
[
self
.
next_zero_row
,
unknown_idx
]
=
1
self
.
next_zero_row
+=
1
self
.
next_zero_row
+=
1
self
.
_reduced
=
False
def
reduce
(
self
):
def
reduce
(
self
):
"""
Brings the system in reduced row echelon form.
"""
"""
Brings the system in reduced row echelon form.
"""
if
self
.
_reduced
:
return
self
.
_matrix
=
self
.
_matrix
.
rref
()[
0
]
self
.
_matrix
=
self
.
_matrix
.
rref
()[
0
]
self
.
_update_next_zero_row
()
self
.
_update_next_zero_row
()
self
.
_reduced
=
True
@property
@property
def
matrix
(
self
):
def
matrix
(
self
):
"""
Return a matrix that represents the equation system.
"""
Return a matrix that represents the equation system.
Has one column more than unknowns for the affine part.
"""
Has one column more than unknowns for the affine part.
"""
self
.
reduce
()
return
self
.
_matrix
return
self
.
_matrix
@property
def
rank
(
self
):
self
.
reduce
()
return
self
.
next_zero_row
def
solution_structure
(
self
):
def
solution_structure
(
self
):
"""
Returns either
'
multiple
'
,
'
none
'
or
'
single
'
to indicate how many solutions the system has.
"""
"""
Returns either
'
multiple
'
,
'
none
'
or
'
single
'
to indicate how many solutions the system has.
"""
self
.
reduce
()
self
.
reduce
()
...
@@ -198,4 +210,9 @@ class LinearEquationSystem:
...
@@ -198,4 +210,9 @@ class LinearEquationSystem:
if
any
(
e
!=
0
for
e
in
self
.
_matrix
.
row
(
row_to_check
)):
if
any
(
e
!=
0
for
e
in
self
.
_matrix
.
row
(
row_to_check
)):
break
break
result
-=
1
result
-=
1
self
.
next_zero_row
=
result
self
.
next_zero_row
=
result
\ No newline at end of file
def
find_unique_solutions_with_zeros
(
system
:
LinearEquationSystem
):
if
not
system
.
solution_structure
()
!=
'
multiple
'
:
raise
ValueError
(
"
Function works only for underdetermined systems
"
)
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