summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2023-02-10 00:47:35 +0200
committerGitHub <noreply@github.com>2023-02-10 00:47:35 +0200
commitbe52f19259d47cd27095e186a7974710c60169ee (patch)
treebdf3541337a996dd4068c5c45f7035dde124b44f /numpy/core/src
parent85166f1cd98dc35783828c9a1606c10b289cc344 (diff)
parentb862e4f4ec4b5d02b30a2f1b2ec9d1c9478b9977 (diff)
downloadnumpy-be52f19259d47cd27095e186a7974710c60169ee.tar.gz
Merge pull request #23181 from mhvk/ufunc-at-complex-add-subtract-multiply
ENH: enable fast indexed loops for complex add, subtract, multiply
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/umath/loops.c.src42
-rw-r--r--numpy/core/src/umath/loops.h.src3
-rw-r--r--numpy/core/src/umath/loops_arithm_fp.dispatch.c.src27
3 files changed, 72 insertions, 0 deletions
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src
index d445fd700..5684f26a5 100644
--- a/numpy/core/src/umath/loops.c.src
+++ b/numpy/core/src/umath/loops.c.src
@@ -2131,6 +2131,26 @@ NPY_NO_EXPORT void
}
}
}
+
+NPY_NO_EXPORT int @TYPE@_@kind@_indexed
+(PyArrayMethod_Context *NPY_UNUSED(context), char * const*args, npy_intp const *dimensions, npy_intp const *steps, NpyAuxData *NPY_UNUSED(func))
+{
+ char *ip1 = args[0];
+ char *indx = args[1];
+ char *value = args[2];
+ npy_intp is1 = steps[0], isindex = steps[1], isb = steps[2];
+ npy_intp n = dimensions[0];
+ npy_intp i;
+ @ftype@ *indexed;
+ for(i = 0; i < n; i++, indx += isindex, value += isb) {
+ indexed = (@ftype@ *)(ip1 + is1 * *(npy_intp *)indx);
+ const @ftype@ b_r = ((@ftype@ *)value)[0];
+ const @ftype@ b_i = ((@ftype@ *)value)[1];
+ indexed[0] @OP@= b_r;
+ indexed[1] @OP@= b_i;
+ }
+ return 0;
+}
/**end repeat1**/
NPY_NO_EXPORT void
@@ -2145,6 +2165,28 @@ NPY_NO_EXPORT void
((@ftype@ *)op1)[1] = in1r*in2i + in1i*in2r;
}
}
+
+NPY_NO_EXPORT int @TYPE@_multiply_indexed
+(PyArrayMethod_Context *NPY_UNUSED(context), char * const*args, npy_intp const *dimensions, npy_intp const *steps, NpyAuxData *NPY_UNUSED(func))
+{
+ char *ip1 = args[0];
+ char *indx = args[1];
+ char *value = args[2];
+ npy_intp is1 = steps[0], isindex = steps[1], isb = steps[2];
+ npy_intp n = dimensions[0];
+ npy_intp i;
+ @ftype@ *indexed;
+ for(i = 0; i < n; i++, indx += isindex, value += isb) {
+ indexed = (@ftype@ *)(ip1 + is1 * *(npy_intp *)indx);
+ const @ftype@ a_r = indexed[0];
+ const @ftype@ a_i = indexed[1];
+ const @ftype@ b_r = ((@ftype@ *)value)[0];
+ const @ftype@ b_i = ((@ftype@ *)value)[1];
+ indexed[0] = a_r*b_r - a_i*b_i;
+ indexed[1] = a_r*b_i + a_i*b_r;
+ }
+ return 0;
+}
#endif // !SIMD
NPY_NO_EXPORT void
diff --git a/numpy/core/src/umath/loops.h.src b/numpy/core/src/umath/loops.h.src
index f773d94bc..e393b8310 100644
--- a/numpy/core/src/umath/loops.h.src
+++ b/numpy/core/src/umath/loops.h.src
@@ -615,6 +615,9 @@ NPY_CPU_DISPATCH_DECLARE(NPY_NO_EXPORT void @TYPE@_@kind@,
*/
NPY_NO_EXPORT void
C@TYPE@_@kind@(char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(func));
+
+NPY_NO_EXPORT int
+C@TYPE@_@kind@_indexed(PyArrayMethod_Context *NPY_UNUSED(context), char *const *args, npy_intp const *dimensions, npy_intp const *steps, NpyAuxData *NPY_UNUSED(func));
/**end repeat1**/
NPY_NO_EXPORT void
diff --git a/numpy/core/src/umath/loops_arithm_fp.dispatch.c.src b/numpy/core/src/umath/loops_arithm_fp.dispatch.c.src
index 71f30ad56..67cf1b367 100644
--- a/numpy/core/src/umath/loops_arithm_fp.dispatch.c.src
+++ b/numpy/core/src/umath/loops_arithm_fp.dispatch.c.src
@@ -551,6 +551,33 @@ loop_scalar:
#endif
}
}
+
+NPY_NO_EXPORT int NPY_CPU_DISPATCH_CURFX(@TYPE@_@kind@_indexed)
+(PyArrayMethod_Context *NPY_UNUSED(context), char * const*args, npy_intp const *dimensions, npy_intp const *steps, NpyAuxData *NPY_UNUSED(func))
+{
+ char *ip1 = args[0];
+ char *indx = args[1];
+ char *value = args[2];
+ npy_intp is1 = steps[0], isindex = steps[1], isb = steps[2];
+ npy_intp n = dimensions[0];
+ npy_intp i;
+ @ftype@ *indexed;
+ for(i = 0; i < n; i++, indx += isindex, value += isb) {
+ indexed = (@ftype@ *)(ip1 + is1 * *(npy_intp *)indx);
+ const @ftype@ b_r = ((@ftype@ *)value)[0];
+ const @ftype@ b_i = ((@ftype@ *)value)[1];
+ #if @is_mul@
+ const @ftype@ a_r = indexed[0];
+ const @ftype@ a_i = indexed[1];
+ indexed[0] = a_r*b_r - a_i*b_i;
+ indexed[1] = a_r*b_i + a_i*b_r;
+ #else
+ indexed[0] @OP@= b_r;
+ indexed[1] @OP@= b_i;
+ #endif
+ }
+ return 0;
+}
/**end repeat1**/
/**begin repeat1