Commit 41ad8407 authored by scoder's avatar scoder Committed by GitHub

Merge pull request #1648 from da-woods/cmplx_abs

Now uses specialised functions for complex abs
parents 503a62cb 56b054b5
...@@ -95,27 +95,27 @@ builtin_function_table = [ ...@@ -95,27 +95,27 @@ builtin_function_table = [
is_strict_signature = True), is_strict_signature = True),
BuiltinFunction('abs', "f", "f", "fabsf", BuiltinFunction('abs', "f", "f", "fabsf",
is_strict_signature = True), is_strict_signature = True),
BuiltinFunction('abs', None, None, "__Pyx_abs_int", ] + list(
utility_code = UtilityCode.load("abs_int", "Builtins.c"), # uses getattr to get PyrexTypes.c_uint_type etc to allow easy iteration over a list
BuiltinFunction('abs', None, None, "__Pyx_abs_{0}".format(t),
utility_code = UtilityCode.load("abs_{0}".format(t), "Builtins.c"),
func_type = PyrexTypes.CFuncType( func_type = PyrexTypes.CFuncType(
PyrexTypes.c_uint_type, [ getattr(PyrexTypes,"c_u{0}_type".format(t)), [
PyrexTypes.CFuncTypeArg("arg", PyrexTypes.c_int_type, None) PyrexTypes.CFuncTypeArg("arg", getattr(PyrexTypes,"c_{0}_type".format(t)), None)
], ],
is_strict_signature = True)), is_strict_signature = True, nogil=True))
BuiltinFunction('abs', None, None, "__Pyx_abs_long", for t in ("int", "long", "longlong")
utility_code = UtilityCode.load("abs_long", "Builtins.c"), ) + list(
BuiltinFunction('abs', None, None, "__Pyx_c_abs{0}".format(t.funcsuffix),
func_type = PyrexTypes.CFuncType( func_type = PyrexTypes.CFuncType(
PyrexTypes.c_ulong_type, [ t.real_type, [
PyrexTypes.CFuncTypeArg("arg", PyrexTypes.c_long_type, None) PyrexTypes.CFuncTypeArg("arg", t, None)
], ],
is_strict_signature = True)), is_strict_signature = True, nogil=True))
BuiltinFunction('abs', None, None, "__Pyx_abs_longlong", for t in (PyrexTypes.c_float_complex_type,
utility_code = UtilityCode.load("abs_longlong", "Builtins.c"), PyrexTypes.c_double_complex_type,
func_type = PyrexTypes.CFuncType( PyrexTypes.c_longdouble_complex_type)
PyrexTypes.c_ulonglong_type, [ ) + [
PyrexTypes.CFuncTypeArg("arg", PyrexTypes.c_longlong_type, None)
],
is_strict_signature = True)),
BuiltinFunction('abs', "O", "O", "PyNumber_Absolute"), BuiltinFunction('abs', "O", "O", "PyNumber_Absolute"),
#('all', "", "", ""), #('all', "", "", ""),
#('any', "", "", ""), #('any', "", "", ""),
......
...@@ -120,3 +120,14 @@ def float_abs(float a): ...@@ -120,3 +120,14 @@ def float_abs(float a):
5.5 5.5
""" """
return abs(a) return abs(a)
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']",
"//ReturnStatNode//NameNode[@entry.cname = '__Pyx_c_abs_double']")
def complex_abs(complex a):
"""
>>> complex_abs(-5j)
5.0
>>> complex_abs(-5.5j)
5.5
"""
return abs(a)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment