Commit 159182ae authored by MischaD's avatar MischaD
Browse files

Bugfix

parent f172bfc8
......@@ -117,18 +117,15 @@ class Lattice:
raise UninitializedAttributeException("Weight Polynomials not give. Calculate them first!")
interval = sp.Interval(-oo, oo)
root = []
c_s_sq = sp.Symbol("c_s_sq")
for equation in self._weight_polynomials:
roots = list(sp.roots(equation, c_s_sq, filter="R").keys())
roots.sort()
if len(roots) == 0:
roots = equation.real_roots()
if not roots:
continue
roots = [roots[0] - 1] + roots + [roots[-1] + 1]
cur_interval = sp.EmptySet()
for i in range(len(roots) - 1):
mesh_point = (roots[i + 1] + roots[i])/2
if equation.subs(c_s_sq, mesh_point) < 0:
if equation.eval(mesh_point) < 0:
continue
# positive weights
if i == 0:
......@@ -138,6 +135,7 @@ class Lattice:
else:
cur_interval = sp.Union(cur_interval, sp.Interval(roots[i], roots[i+1]))
interval = interval.intersect(cur_interval)
pass
self._interval = interval
return interval
......@@ -220,7 +218,6 @@ class Lattice:
A = np.array(lhs)
b = fill_rhs(self._order, self._tensor_dimensions)
self._rhs = np.copy(b)
logger.info(b)
# --------------------------------------------------------------------------------------------------
......@@ -274,27 +271,24 @@ class Lattice:
tmp -= solution[i, j] * len(grand_total_list[i])
coefficients[j+1] = tmp
self._coefficients = coefficients
self._coefficients = np.array(coefficients)
# -------------------------------------------------- Prettify for sympy
weight_polynomials = []
c_s_sq = sp.Symbol("c_s_sq")
equation = 0
for j in range(len(coefficients)):
equation += approximate_ratio(coefficients[j]) * c_s_sq ** j
weight_polynomials.append(equation)
for i in range(len(grand_total_list)):
equation = 0
for j in range(solution_columns):
equation += approximate_ratio(solution[i, j]) * c_s_sq ** (j + 1)
weight_polynomials.append(equation)
coeffs = np.zeros((solution.shape[0] + 1, solution.shape[1] + 1))
coeffs[0, :] = coefficients[-1::-1]
coeffs[1:, :-1] = solution[:,-1::-1]
apporx_coeffs = [[approximate_ratio(x) for x in pol_coffs] for pol_coffs in coeffs]
weight_polynomials = [sp.Poly([approximate_ratio(x) for x in pol_coffs], c_s_sq) for pol_coffs in coeffs]
# -------------------------------------------------- Calculate Roots
self._weight_polynomials = weight_polynomials
self.calculate_valid_interval()
logger.info(self._interval.boundary)
if self._interval == sp.EmptySet():
return None
return []
weights = [x.subs(c_s_sq, self._interval.boundary.inf) for x in weight_polynomials]
return weights
......
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