Skip to content
Snippets Groups Projects

Clarify semantics of fancy integer division functions.

Merged Daniel Bauer requested to merge hyteg/pystencils:bauerd/fancy-int-div into v2.0-dev
1 unresolved thread

Closes #88 (closed).

The goal of these functions is to provide fast, fp-free functions for semi-complicated semantics on positive integers (The old implementation did not behave sensibly for negative input). This MR clarifies the names and docstrings of the fancy integer divisions to make it clear that negative input is not always expected. Furthermore, the implementation is changed such that no remainders or conditionals must be evaluated.

The old names are still available but issue deprecation warnings.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • 140 129
    141 def __new__(cls, integer, divisor):
    142 if is_integer_sequence((integer, divisor)):
    143 return integer // divisor if integer % divisor == 0 else (integer // divisor) + 1
    144 else:
    145 return super().__new__(cls, integer, divisor)
    130 def _eval_op(self, arg1, arg2):
    131 from ..utils import c_intdiv
    146 132
    147 # TODO: Implement this in FreezeExpressions
    148 # def to_c(self, print_func):
    149 # dtype = collate_types((get_type_of_expression(self.args[0]), get_type_of_expression(self.args[1])))
    150 # assert dtype.is_int()
    151 # code = "( ({0}) % ({1}) == 0 ? ({dtype})({0}) / ({dtype})({1}) : ( ({dtype})({0}) / ({dtype})({1}) ) +1 )"
    152 # return code.format(print_func(self.args[0]), print_func(self.args[1]), dtype=dtype)
    133 return sp.sympify(c_intdiv(arg1 + arg2 - 1, arg2))
  • Frederik Hennig
  • Daniel Bauer added 2 commits

    added 2 commits

    • 7cd4de2f - implement eval for fancy integer divisions
    • b441b41d - change implementation defined to unspecified

    Compare with previous version

  • Frederik Hennig approved this merge request

    approved this merge request

  • mentioned in commit eb02fcab

  • Please register or sign in to reply
    Loading