Skip to content
Snippets Groups Projects
Commit 7f6bb130 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

move c-intdiv implementations to pystencils.utils

parent 6be4b5af
No related branches found
No related tags found
1 merge request!394Extend symbolic language support
Pipeline #67257 passed
...@@ -636,7 +636,7 @@ class PsIntDiv(PsBinOp, PsIntOpTrait): ...@@ -636,7 +636,7 @@ class PsIntDiv(PsBinOp, PsIntOpTrait):
@property @property
def python_operator(self) -> Callable[[Any, Any], Any]: def python_operator(self) -> Callable[[Any, Any], Any]:
from .util import c_intdiv from ...utils import c_intdiv
return c_intdiv return c_intdiv
...@@ -646,7 +646,7 @@ class PsRem(PsBinOp, PsIntOpTrait): ...@@ -646,7 +646,7 @@ class PsRem(PsBinOp, PsIntOpTrait):
@property @property
def python_operator(self) -> Callable[[Any, Any], Any]: def python_operator(self) -> Callable[[Any, Any], Any]:
from .util import c_rem from ...utils import c_rem
return c_rem return c_rem
......
...@@ -36,14 +36,3 @@ class AstEqWrapper: ...@@ -36,14 +36,3 @@ class AstEqWrapper:
# TODO: consider replacing this with smth. more performant # TODO: consider replacing this with smth. more performant
# TODO: Check that repr is implemented by all AST nodes # TODO: Check that repr is implemented by all AST nodes
return hash(repr(self._node)) return hash(repr(self._node))
def c_intdiv(num, denom):
"""C-style integer division"""
return int(num / denom)
def c_rem(num, denom):
"""C-style integer remainder"""
div = c_intdiv(num, denom)
return num - div * denom
...@@ -316,7 +316,7 @@ class EliminateConstants: ...@@ -316,7 +316,7 @@ class EliminateConstants:
) )
elif isinstance(expr, PsDiv): elif isinstance(expr, PsDiv):
if is_int: if is_int:
from ..ast.util import c_intdiv from ...utils import c_intdiv
folded = PsConstant(c_intdiv(v1, v2), dtype) folded = PsConstant(c_intdiv(v1, v2), dtype)
elif isinstance(dtype, PsIeeeFloatType): elif isinstance(dtype, PsIeeeFloatType):
folded = PsConstant(v1 / v2, dtype) folded = PsConstant(v1 / v2, dtype)
......
...@@ -48,15 +48,16 @@ class int_div(IntegerFunctionTwoArgsMixIn): ...@@ -48,15 +48,16 @@ class int_div(IntegerFunctionTwoArgsMixIn):
"""C-style round-to-zero integer division""" """C-style round-to-zero integer division"""
def _eval_op(self, arg1, arg2): def _eval_op(self, arg1, arg2):
return int(arg1 / arg2) from ..utils import c_intdiv
return c_intdiv(arg1, arg2)
class int_rem(IntegerFunctionTwoArgsMixIn): class int_rem(IntegerFunctionTwoArgsMixIn):
"""C-style round-to-zero integer remainder""" """C-style round-to-zero integer remainder"""
def _eval_op(self, arg1, arg2): def _eval_op(self, arg1, arg2):
div = int(arg1 / arg2) from ..utils import c_rem
return arg1 - div * arg2 return c_rem(arg1, arg2)
# noinspection PyPep8Naming # noinspection PyPep8Naming
......
...@@ -250,3 +250,14 @@ class ContextVar: ...@@ -250,3 +250,14 @@ class ContextVar:
def get(self): def get(self):
return self.stack[-1] return self.stack[-1]
def c_intdiv(num, denom):
"""C-style integer division"""
return int(num / denom)
def c_rem(num, denom):
"""C-style integer remainder"""
div = c_intdiv(num, denom)
return num - div * denom
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment