Skip to content

Commit

Permalink
Add Reciprocal
Browse files Browse the repository at this point in the history
  • Loading branch information
luyahan committed May 7, 2024
1 parent 4a04c66 commit b94d506
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 271 deletions.
2 changes: 1 addition & 1 deletion numpy/_core/code_generators/generate_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ def english_upper(s):
docstrings.get('numpy._core.umath.rint'),
None,
TD('e', f='rint', astype={'e': 'f'}),
TD(inexactvec, dispatch=[('loop_unary_fp', 'fd')]),
TD(inexactvec, dispatch=[('loops_unary_fp', 'fd')]),
TD('fdg' + cmplx, f='rint'),
TD(P, f='rint'),
),
Expand Down
15 changes: 3 additions & 12 deletions numpy/_core/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ if use_highway
# required for hwy::Abort symbol
'src/highway/hwy/abort.cc',
'src/highway/hwy/per_target.cc',
'src/highway/hwy/targets.cc'
'src/highway/hwy/targets.cc',
'src/highway/hwy/print.cc'
],
cpp_args: '-DTOOLCHAIN_MISS_ASM_HWCAP_H',
include_directories: ['src/highway'],
Expand Down Expand Up @@ -969,17 +970,7 @@ foreach gen_mtargets : [
],
[
'loops_unary_fp.dispatch.h',
src_file.process('src/umath/loops_unary_fp.dispatch.c.src'),
[
SSE42, SSE2,
VSX2,
ASIMD, NEON,
VXE, VX
]
],
[
'loop_unary_fp.dispatch.h',
'src/umath/loop_unary_fp.dispatch.cpp',
'src/umath/loops_unary_fp.dispatch.cpp',
[
SSE42, SSE2,
VSX2,
Expand Down
1 change: 0 additions & 1 deletion numpy/_core/src/umath/loops.h.src
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ NPY_CPU_DISPATCH_DECLARE(NPY_NO_EXPORT void @TYPE@_@kind@,
*/
#ifndef NPY_DISABLE_OPTIMIZATION
#include "loops_unary_fp.dispatch.h"
#include "loop_unary_fp.dispatch.h"
#endif
/**begin repeat
* #TYPE = FLOAT, DOUBLE#
Expand Down
255 changes: 0 additions & 255 deletions numpy/_core/src/umath/loops_unary_fp.dispatch.c.src

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@ namespace hn = hwy::HWY_NAMESPACE;
hn::ScatterIndex(x, d, output_array + i * sdst, store_index); \
} \
if (remainder) { \
const auto in = hn::GatherIndexN(d, input_array + full * ssrc, \
hn::Vec<hn::ScalableTag<T>> in; \
if (IS_RECIP) { \
auto one = hn::Set(d, 1); \
in = hn::GatherIndexNOr(one, d, input_array + full * ssrc, \
load_index, remainder); \
} else { \
in = hn::GatherIndexN(d, input_array + full * ssrc, \
load_index, remainder); \
} \
auto x = FUNC(in); \
hn::ScatterIndexN(x, d, output_array + full * sdst, store_index, \
remainder); \
Expand All @@ -100,6 +107,7 @@ namespace hn = hwy::HWY_NAMESPACE;
}

#define Square(x) hn::Mul(x, x)
#define Reciprocal(x) hn::Div(hn::Set(d, T(1.0)), x)
//ceil, trunc, sqrt, square,
SUPER(Rint, hn::Round, false)
SUPER(Floor, hn::Floor, false)
Expand All @@ -108,6 +116,7 @@ SUPER(Trunc, hn::Trunc, false)
SUPER(Sqrt, hn::Sqrt, false)
SUPER(Square, Square, false)
SUPER(Absolute, hn::Abs, false)
SUPER(Reciprocal, Reciprocal, true)

extern "C" {
NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(DOUBLE_rint)
Expand Down Expand Up @@ -195,4 +204,16 @@ NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(FLOAT_absolute)
SuperAbsolute<npy_float>(args, dimensions, steps);
npy_clear_floatstatus_barrier((char*)dimensions);
}

NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(DOUBLE_reciprocal)
(char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(func))
{
SuperReciprocal<npy_double>(args, dimensions, steps);
}

NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(FLOAT_reciprocal)
(char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(func))
{
SuperReciprocal<npy_float>(args, dimensions, steps);
}
}

0 comments on commit b94d506

Please sign in to comment.