From a7c86f83f10474a713143ebbd44f486bab189ca6 Mon Sep 17 00:00:00 2001 From: Martin Bauer <martin.bauer@fau.de> Date: Fri, 15 Mar 2019 11:10:47 +0100 Subject: [PATCH] Benchmark for phase field kernels --- backends/cbackend.py | 8 ++++++-- datahandling/datahandling_interface.py | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/backends/cbackend.py b/backends/cbackend.py index 67f2552..f3336be 100644 --- a/backends/cbackend.py +++ b/backends/cbackend.py @@ -333,7 +333,7 @@ class VectorizedCustomSympyPrinter(CustomSympyPrinter): if self.instruction_set['rsqrt']: return self.instruction_set['rsqrt'].format(self._print(expr.args[0])) else: - return "({})".format(self._print(1 / sp.sqrt(expr.args[0]))) + return "({})".format(self.doprint(1 / sp.sqrt(expr.args[0]))) return super(VectorizedCustomSympyPrinter, self)._print_Function(expr) def _print_And(self, expr): @@ -391,6 +391,8 @@ class VectorizedCustomSympyPrinter(CustomSympyPrinter): if result: return result + one = self.instruction_set['makeVec'].format(1.0) + if expr.exp.is_integer and expr.exp.is_number and 0 < expr.exp < 8: return "(" + self._print(sp.Mul(*[expr.base] * expr.exp, evaluate=False)) + ")" elif expr.exp == -1: @@ -398,8 +400,10 @@ class VectorizedCustomSympyPrinter(CustomSympyPrinter): return self.instruction_set['/'].format(one, self._print(expr.base)) elif expr.exp == 0.5: return self.instruction_set['sqrt'].format(self._print(expr.base)) + elif expr.exp == -0.5: + root = self.instruction_set['sqrt'].format(self._print(expr.base)) + return self.instruction_set['/'].format(one, root) elif expr.exp.is_integer and expr.exp.is_number and - 8 < expr.exp < 0: - one = self.instruction_set['makeVec'].format(1.0) return self.instruction_set['/'].format(one, self._print(sp.Mul(*[expr.base] * (-expr.exp), evaluate=False))) else: diff --git a/datahandling/datahandling_interface.py b/datahandling/datahandling_interface.py index b9e81c7..da2108b 100644 --- a/datahandling/datahandling_interface.py +++ b/datahandling/datahandling_interface.py @@ -1,6 +1,6 @@ import numpy as np from abc import ABC, abstractmethod -from typing import Optional, Callable, Sequence, Iterable, Tuple, Dict +from typing import Optional, Callable, Sequence, Iterable, Tuple, Dict, Union from pystencils.field import Field @@ -32,7 +32,7 @@ class DataHandling(ABC): """Returns tuple of booleans for x,y,(z) directions with True if domain is periodic in that direction.""" @abstractmethod - def add_array(self, name: str, values_per_cell: int = 1, dtype=np.float64, + def add_array(self, name: str, values_per_cell, dtype=np.float64, latex_name: Optional[str] = None, ghost_layers: Optional[int] = None, layout: Optional[str] = None, cpu: bool = True, gpu: Optional[bool] = None, alignment=False) -> Field: """Adds a (possibly distributed) array to the handling that can be accessed using the given name. @@ -239,7 +239,7 @@ class DataHandling(ABC): # ------------------------------- Data access and modification ----------------------------------------------------- - def fill(self, array_name: str, val, value_idx: Optional[Tuple[int, ...]] = None, + def fill(self, array_name: str, val, value_idx: Optional[Union[int, Tuple[int, ...]]] = None, slice_obj=None, ghost_layers=False, inner_ghost_layers=False) -> None: """Sets all cells to the same value. -- GitLab