Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Add integer min/max 2 argument functions to C (pyccel#1239)
Browse files Browse the repository at this point in the history
* Add min/max for 2 integer arguments
* Activate tests that were skipped in C
* Allow error reporting via Pyccel errors
* Update version to 1.7.0
  • Loading branch information
EmilyBourne authored Nov 22, 2022
1 parent 8ca23f0 commit 7c15bb3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 31 deletions.
3 changes: 2 additions & 1 deletion ci_tools/coverage_analysis_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def allow_untested_error_calls(untested):
for f,line_nums in untested.items():
with open(f, encoding="utf-8") as filename:
f_lines = filename.readlines()
lines = [i for i in line_nums if not f_lines[i-1].strip().startswith('raise ')]
untested_lines = [f_lines[i-1].strip() for i in line_nums]
lines = [l for l in untested_lines if not (l.startswith('raise ') or l.startswith('errors.report(') or l.startswith('return errors.report('))]
if len(lines):
reduced_untested[f] = lines

Expand Down
20 changes: 18 additions & 2 deletions pyccel/codegen/printing/ccode.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,16 @@ def _print_PythonMin(self, expr):
self.add_import(c_imports['math'])
return "fmin({}, {})".format(self._print(arg[0]),
self._print(arg[1]))
elif arg.dtype is NativeInteger() and len(arg) == 2:
arg1 = self.scope.get_temporary_variable(NativeInteger())
arg2 = self.scope.get_temporary_variable(NativeInteger())
assign1 = Assign(arg1, arg[0])
assign2 = Assign(arg2, arg[1])
self._additional_code += self._print(assign1)
self._additional_code += self._print(assign2)
return f"({arg1} < {arg2} ? {arg1} : {arg2})"
else:
return errors.report("min in C is only supported for 2 float arguments", symbol=expr,
return errors.report("min in C is only supported for 2 scalar arguments", symbol=expr,
severity='fatal')

def _print_PythonMax(self, expr):
Expand All @@ -508,8 +516,16 @@ def _print_PythonMax(self, expr):
self.add_import(c_imports['math'])
return "fmax({}, {})".format(self._print(arg[0]),
self._print(arg[1]))
elif arg.dtype is NativeInteger() and len(arg) == 2:
arg1 = self.scope.get_temporary_variable(NativeInteger())
arg2 = self.scope.get_temporary_variable(NativeInteger())
assign1 = Assign(arg1, arg[0])
assign2 = Assign(arg2, arg[1])
self._additional_code += self._print(assign1)
self._additional_code += self._print(assign2)
return f"({arg1} > {arg2} ? {arg1} : {arg2})"
else:
return errors.report("max in C is only supported for 2 float arguments", symbol=expr,
return errors.report("max in C is only supported for 2 scalar arguments", symbol=expr,
severity='fatal')

def _print_SysExit(self, expr):
Expand Down
2 changes: 1 addition & 1 deletion pyccel/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
Module specifying the current version string for pyccel
"""
__version__ = "1.6.1"
__version__ = "1.7.0"
27 changes: 0 additions & 27 deletions tests/epyccel/test_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ def f1(x):
assert f1(rand_zero) == f2(rand_zero)
assert f1(0j + 0) == f2(0j + 0)

@pytest.mark.parametrize( 'language', (
pytest.param("fortran", marks = pytest.mark.fortran),
pytest.param("c", marks = [
pytest.mark.skip(reason="min not implemented in C for integers"),
pytest.mark.c]
),
pytest.param("python", marks = pytest.mark.python)
)
)
def test_min_2_args_i(language):
@types('int','int')
def f(x, y):
Expand All @@ -88,15 +79,6 @@ def f(x, y):

assert epyc_f(*int_args) == f(*int_args)

@pytest.mark.parametrize( 'language', (
pytest.param("fortran", marks = pytest.mark.fortran),
pytest.param("c", marks = [
pytest.mark.skip(reason="min not implemented in C for integers"),
pytest.mark.c]
),
pytest.param("python", marks = pytest.mark.python)
)
)
def test_min_2_args_i_adhoc(language):
def f(x:int):
return min(x, 0)
Expand Down Expand Up @@ -197,15 +179,6 @@ def f(x, y, z):
assert epyc_f(*int_args) == f(*int_args)
assert epyc_f(*float_args) == f(*float_args)

@pytest.mark.parametrize( 'language', (
pytest.param("fortran", marks = pytest.mark.fortran),
pytest.param("c", marks = [
pytest.mark.skip(reason="max not implemented in C for integers"),
pytest.mark.c]
),
pytest.param("python", marks = pytest.mark.python)
)
)
def test_max_2_args_i(language):
@types('int','int')
def f(x, y):
Expand Down

0 comments on commit 7c15bb3

Please sign in to comment.