Skip to content
Snippets Groups Projects
Commit faba3cc4 authored by Markus Holzer's avatar Markus Holzer
Browse files

Changed layout for many summands

parent 6718973d
Branches
No related tags found
No related merge requests found
Pipeline #30356 passed
...@@ -609,6 +609,20 @@ class VectorizedCustomSympyPrinter(CustomSympyPrinter): ...@@ -609,6 +609,20 @@ class VectorizedCustomSympyPrinter(CustomSympyPrinter):
return result return result
def _print_Add(self, expr, order=None): def _print_Add(self, expr, order=None):
def visit(summands):
if len(summands) == 2:
sign = summands[0].sign * summands[1].sign
func = self.instruction_set['-'] if sign == -1 else self.instruction_set['+']
return func.format(summands[0].term, summands[1].term)
else:
elements = len(summands) // 2
if len(summands[:elements]) < 2:
func = self.instruction_set['-'] if summands[0].sign == -1 else self.instruction_set['+']
return func.format(summands[0].term, visit(summands[elements:]))
else:
func = self.instruction_set['+']
return func.format(visit(summands[:elements]), visit(summands[elements:]))
result = self._scalarFallback('_print_Add', expr) result = self._scalarFallback('_print_Add', expr)
if result: if result:
return result return result
...@@ -628,10 +642,13 @@ class VectorizedCustomSympyPrinter(CustomSympyPrinter): ...@@ -628,10 +642,13 @@ class VectorizedCustomSympyPrinter(CustomSympyPrinter):
summands.insert(0, self.SummandInfo(1, "0")) summands.insert(0, self.SummandInfo(1, "0"))
assert len(summands) >= 2 assert len(summands) >= 2
processed = summands[0].term if len(summands) < 10:
for summand in summands[1:]: processed = summands[0].term
func = self.instruction_set['-'] if summand.sign == -1 else self.instruction_set['+'] for summand in summands[1:]:
processed = func.format(processed, summand.term) func = self.instruction_set['-'] if summand.sign == -1 else self.instruction_set['+']
processed = func.format(processed, summand.term)
else:
processed = visit(summands)
return processed return processed
def _print_Pow(self, expr): def _print_Pow(self, expr):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment