diff options
author | Sayed Adel <seiko@imavr.com> | 2022-12-08 16:58:53 +0200 |
---|---|---|
committer | Sayed Adel <seiko@imavr.com> | 2022-12-08 19:30:53 +0200 |
commit | bfa444d45c392678851f5c3dd5f8d3a02683447f (patch) | |
tree | ac31160f825b3eb07d9eee044bfc0bf8203e62be | |
parent | 0609a34aec0d2f4b0e404c84352dfb979baea3de (diff) | |
download | numpy-bfa444d45c392678851f5c3dd5f8d3a02683447f.tar.gz |
ENG, SIMD: Dispatch bool (invert, add, fmax, fmin...)
Following functions are defined by umath generator
to enable runtime dispatching without the need
to redefine them within dsipatch-able sources:
BOOL_invert, BOOL_add, BOOL_bitwise_and
BOOL_bitwise_or, BOOL_logical_xor
BOOL_bitwise_xor, BOOL_multiply
BOOL_maximum, BOOL_minimum, BOOL_fmax,
BOOL_fmin
-rw-r--r-- | numpy/core/code_generators/generate_umath.py | 65 | ||||
-rw-r--r-- | numpy/core/src/umath/loops.h.src | 31 |
2 files changed, 62 insertions, 34 deletions
diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py index 114c743e2..bf1a05ee4 100644 --- a/numpy/core/code_generators/generate_umath.py +++ b/numpy/core/code_generators/generate_umath.py @@ -246,7 +246,8 @@ chartoname = { 'P': 'OBJECT', } -noobj = '?bBhHiIlLqQefdgFDGmM' +no_obj_bool = 'bBhHiIlLqQefdgFDGmM' +noobj = '?' + no_obj_bool all = '?bBhHiIlLqQefdgFDGOmM' O = 'O' @@ -280,6 +281,7 @@ nocmplxO = nocmplx+O nocmplxP = nocmplx+P notimes_or_obj = bints + inexact nodatetime_or_obj = bints + inexact +no_bool_times_obj = ints + inexact # Find which code corresponds to int64. int64 = '' @@ -299,7 +301,9 @@ defdict = { Ufunc(2, 1, Zero, docstrings.get('numpy.core.umath.add'), 'PyUFunc_AdditionTypeResolver', - TD(notimes_or_obj, simd=[('avx2', ints)], dispatch=[('loops_arithm_fp', 'fdFD')]), + TD('?', cfunc_alias='logical_or', dispatch=[('loops_logical', '?')]), + TD(no_bool_times_obj, simd=[('avx2', ints)], + dispatch=[('loops_arithm_fp', 'fdFD')]), [TypeDescription('M', FullTypeDescr, 'Mm', 'M'), TypeDescription('m', FullTypeDescr, 'mm', 'm'), TypeDescription('M', FullTypeDescr, 'mM', 'M'), @@ -310,7 +314,8 @@ defdict = { Ufunc(2, 1, None, # Zero is only a unit to the right, not the left docstrings.get('numpy.core.umath.subtract'), 'PyUFunc_SubtractionTypeResolver', - TD(ints + inexact, simd=[('avx2', ints)], dispatch=[('loops_arithm_fp', 'fdFD')]), + TD(no_bool_times_obj, simd=[('avx2', ints)], + dispatch=[('loops_arithm_fp', 'fdFD')]), [TypeDescription('M', FullTypeDescr, 'Mm', 'M'), TypeDescription('m', FullTypeDescr, 'mm', 'm'), TypeDescription('M', FullTypeDescr, 'MM', 'm'), @@ -321,7 +326,10 @@ defdict = { Ufunc(2, 1, One, docstrings.get('numpy.core.umath.multiply'), 'PyUFunc_MultiplicationTypeResolver', - TD(notimes_or_obj, simd=[('avx2', ints)], dispatch=[('loops_arithm_fp', 'fdFD')]), + TD('?', cfunc_alias='logical_and', + dispatch=[('loops_logical', '?')]), + TD(no_bool_times_obj, simd=[('avx2', ints)], + dispatch=[('loops_arithm_fp', 'fdFD')]), [TypeDescription('m', FullTypeDescr, 'mq', 'm'), TypeDescription('m', FullTypeDescr, 'qm', 'm'), TypeDescription('m', FullTypeDescr, 'md', 'm'), @@ -412,8 +420,8 @@ defdict = { Ufunc(1, 1, None, docstrings.get('numpy.core.umath.absolute'), 'PyUFunc_AbsoluteTypeResolver', - TD(bints+flts+timedeltaonly, dispatch=[('loops_unary_fp', 'fd')]), - TD('?', dispatch=[('loops_logical', '?')]), + TD(bints+flts+timedeltaonly, dispatch=[('loops_unary_fp', 'fd'), + ('loops_logical', '?')]), TD(cmplx, simd=[('avx512f', cmplxvec)], out=('f', 'd', 'g')), TD(O, f='PyNumber_Absolute'), ), @@ -497,31 +505,33 @@ defdict = { Ufunc(2, 1, True_, docstrings.get('numpy.core.umath.logical_and'), 'PyUFunc_SimpleBinaryComparisonTypeResolver', - TD('?', dispatch=[('loops_logical', '?')]), - TD(nodatetime_or_obj, out='?', simd=[('avx2', ints)]), + TD(nodatetime_or_obj, out='?', simd=[('avx2', ints)], + dispatch=[('loops_logical', '?')]), TD(O, f='npy_ObjectLogicalAnd'), ), 'logical_not': Ufunc(1, 1, None, docstrings.get('numpy.core.umath.logical_not'), None, - TD('?', dispatch=[('loops_logical', '?')]), - TD(nodatetime_or_obj, out='?', simd=[('avx2', ints)]), + TD(nodatetime_or_obj, out='?', simd=[('avx2', ints)], + dispatch=[('loops_logical', '?')]), TD(O, f='npy_ObjectLogicalNot'), ), 'logical_or': Ufunc(2, 1, False_, docstrings.get('numpy.core.umath.logical_or'), 'PyUFunc_SimpleBinaryComparisonTypeResolver', - TD('?', dispatch=[('loops_logical', '?')]), - TD(nodatetime_or_obj, out='?', simd=[('avx2', ints)]), + TD(nodatetime_or_obj, out='?', simd=[('avx2', ints)], + dispatch=[('loops_logical', '?')]), TD(O, f='npy_ObjectLogicalOr'), ), 'logical_xor': Ufunc(2, 1, False_, docstrings.get('numpy.core.umath.logical_xor'), 'PyUFunc_SimpleBinaryComparisonTypeResolver', - TD(nodatetime_or_obj, out='?'), + TD('?', out='?', cfunc_alias='not_equal', + dispatch=[('loops_comparison', '?')]), + TD(no_bool_times_obj, out='?'), # TODO: using obj.logical_xor() seems pretty much useless: TD(P, f='logical_xor'), ), @@ -529,14 +539,17 @@ defdict = { Ufunc(2, 1, ReorderableNone, docstrings.get('numpy.core.umath.maximum'), 'PyUFunc_SimpleUniformOperationTypeResolver', - TD(noobj, dispatch=[('loops_minmax', ints+'fdg')]), + TD('?', cfunc_alias='logical_or', dispatch=[('loops_logical', '?')]), + TD(no_obj_bool, dispatch=[('loops_minmax', ints+'fdg')]), TD(O, f='npy_ObjectMax') ), 'minimum': Ufunc(2, 1, ReorderableNone, docstrings.get('numpy.core.umath.minimum'), 'PyUFunc_SimpleUniformOperationTypeResolver', - TD(noobj, dispatch=[('loops_minmax', ints+'fdg')]), + TD('?', cfunc_alias='logical_and', + dispatch=[('loops_logical', '?')]), + TD(no_obj_bool, dispatch=[('loops_minmax', ints+'fdg')]), TD(O, f='npy_ObjectMin') ), 'clip': @@ -550,14 +563,17 @@ defdict = { Ufunc(2, 1, ReorderableNone, docstrings.get('numpy.core.umath.fmax'), 'PyUFunc_SimpleUniformOperationTypeResolver', - TD(noobj, dispatch=[('loops_minmax', 'fdg')]), + TD('?', cfunc_alias='logical_or', dispatch=[('loops_logical', '?')]), + TD(no_obj_bool, dispatch=[('loops_minmax', 'fdg')]), TD(O, f='npy_ObjectMax') ), 'fmin': Ufunc(2, 1, ReorderableNone, docstrings.get('numpy.core.umath.fmin'), 'PyUFunc_SimpleUniformOperationTypeResolver', - TD(noobj, dispatch=[('loops_minmax', 'fdg')]), + TD('?', cfunc_alias='logical_and', + dispatch=[('loops_logical', '?')]), + TD(no_obj_bool, dispatch=[('loops_minmax', 'fdg')]), TD(O, f='npy_ObjectMin') ), 'logaddexp': @@ -576,28 +592,35 @@ defdict = { Ufunc(2, 1, AllOnes, docstrings.get('numpy.core.umath.bitwise_and'), None, - TD(bints, simd=[('avx2', ints)]), + TD('?', cfunc_alias='logical_and', + dispatch=[('loops_logical', '?')]), + TD(ints, simd=[('avx2', ints)]), TD(O, f='PyNumber_And'), ), 'bitwise_or': Ufunc(2, 1, Zero, docstrings.get('numpy.core.umath.bitwise_or'), None, - TD(bints, simd=[('avx2', ints)]), + TD('?', cfunc_alias='logical_or', dispatch=[('loops_logical', '?')]), + TD(ints, simd=[('avx2', ints)]), TD(O, f='PyNumber_Or'), ), 'bitwise_xor': Ufunc(2, 1, Zero, docstrings.get('numpy.core.umath.bitwise_xor'), None, - TD(bints, simd=[('avx2', ints)]), + TD('?', cfunc_alias='not_equal', + dispatch=[('loops_comparison', '?')]), + TD(ints, simd=[('avx2', ints)]), TD(O, f='PyNumber_Xor'), ), 'invert': Ufunc(1, 1, None, docstrings.get('numpy.core.umath.invert'), None, - TD(bints, simd=[('avx2', ints)]), + TD('?', cfunc_alias='logical_not', + dispatch=[('loops_logical', '?')]), + TD(ints, simd=[('avx2', ints)]), TD(O, f='PyNumber_Invert'), ), 'left_shift': diff --git a/numpy/core/src/umath/loops.h.src b/numpy/core/src/umath/loops.h.src index 2e0ba9c40..411d53e94 100644 --- a/numpy/core/src/umath/loops.h.src +++ b/numpy/core/src/umath/loops.h.src @@ -10,24 +10,29 @@ #define NPY_NO_EXPORT NPY_VISIBILITY_HIDDEN #endif -#define BOOL_invert BOOL_logical_not -#define BOOL_add BOOL_logical_or -#define BOOL_bitwise_and BOOL_logical_and -#define BOOL_bitwise_or BOOL_logical_or -#define BOOL_logical_xor BOOL_not_equal -#define BOOL_bitwise_xor BOOL_logical_xor -#define BOOL_multiply BOOL_logical_and -#define BOOL_maximum BOOL_logical_or -#define BOOL_minimum BOOL_logical_and -#define BOOL_fmax BOOL_maximum -#define BOOL_fmin BOOL_minimum - /* ***************************************************************************** ** BOOLEAN LOOPS ** ***************************************************************************** */ +/* + * Following functions are defined by umath generator + * to enable runtime dispatching without the need + * to redefine them within dsipatch-able sources. + */ +// #define BOOL_invert BOOL_logical_not +// #define BOOL_add BOOL_logical_or +// #define BOOL_bitwise_and BOOL_logical_and +// #define BOOL_bitwise_or BOOL_logical_or +// #define BOOL_logical_xor BOOL_not_equal +// #define BOOL_bitwise_xor BOOL_logical_xor +// #define BOOL_multiply BOOL_logical_and +// #define BOOL_maximum BOOL_logical_or +// #define BOOL_minimum BOOL_logical_and +// #define BOOL_fmax BOOL_maximum +// #define BOOL_fmin BOOL_minimum + #ifndef NPY_DISABLE_OPTIMIZATION #include "loops_comparison.dispatch.h" #endif @@ -207,7 +212,7 @@ NPY_NO_EXPORT void /**end repeat**/ - + #ifndef NPY_DISABLE_OPTIMIZATION #include "loops_unary.dispatch.h" #endif |