Commit 7df37e9f authored by Martin Bauer's avatar Martin Bauer
Browse files

Generation of packing kernels

parent 66023ebf
......@@ -111,6 +111,7 @@ class LinearEquationSystem:
self._matrix = sp.zeros(size, size + 1)
self.unknowns = unknowns
self.next_zero_row = 0
self._reduced = True
def copy(self):
"""Returns a copy of the equation system."""
......@@ -135,6 +136,7 @@ class LinearEquationSystem:
if rest.atoms(sp.Symbol):
raise ValueError("Not a linear equation in the unknowns")
self._matrix[zero_row_idx, -1] = -rest
self._reduced = False
def add_equations(self, linear_equations):
"""Add a sequence of equations. For details see `add_equation`. """
......@@ -148,18 +150,28 @@ class LinearEquationSystem:
self._matrix[self.next_zero_row, unknown_idx] = 1
self.next_zero_row += 1
self._reduced = False
def reduce(self):
"""Brings the system in reduced row echelon form."""
if self._reduced:
self._matrix = self._matrix.rref()[0]
self._reduced = True
def matrix(self):
"""Return a matrix that represents the equation system.
Has one column more than unknowns for the affine part."""
return self._matrix
def rank(self):
return self.next_zero_row
def solution_structure(self):
"""Returns either 'multiple', 'none' or 'single' to indicate how many solutions the system has."""
......@@ -198,4 +210,9 @@ class LinearEquationSystem:
if any(e != 0 for e in self._matrix.row(row_to_check)):
result -= 1
self.next_zero_row = result
\ No newline at end of file
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")
Markdown is supported
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