Skip to content
Snippets Groups Projects
Commit 7df37e9f authored by Martin Bauer's avatar Martin Bauer
Browse files

Generation of packing kernels

parent 66023ebf
Branches
Tags
No related merge requests found
...@@ -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")
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment