8000 ENH: Speedup ufunc.at when casting is not needed by mattip · Pull Request #22889 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Speedup ufunc.at when casting is not needed #22889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions benchmarks/benchmarks/bench_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ def time_broadcast(self):
self.d - self.e


class At(Benchmark):
def setup(self):
self.vals = np.random.rand(1_000_000)
self.idx = np.random.randint(1000, size=1_000_000).astype(np.intp)
self.res = np.zeros(1000, dtype=self.vals.dtype)

def time_sum_at(self):
np.add.at(self.res, self.idx, self.vals)


class UFunc(Benchmark):
params = [ufuncs]
param_names = ['ufunc']
Expand Down
1 change: 0 additions & 1 deletion numpy/core/src/umath/legacy_array_method.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ generic_wrapped_legacy_loop(PyArrayMethod_Context *NPY_UNUSED(context),
return 0;
}


/*
* Signal that the old type-resolution function must be used to resolve
* the descriptors (mainly/only used for datetimes due to the unit).
Expand Down
3 changes: 2 additions & 1 deletion numpy/core/src/umath/loops_arithm_fp.dispatch.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ run_binary_simd_@kind@_@TYPE@(char **args, npy_intp const *dimensions, npy_intp
* #TYPE = FLOAT, DOUBLE#
* #c = f, #
* #C = F, #
* #count = 4,2#
*/
/**begin repeat1
* Arithmetic
Expand All @@ -537,7 +538,7 @@ NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_@kind@)
*((@type@ *)iop1) = io1;
#endif
}
else if (!run_binary_simd_@kind@_@TYPE@(args, dimensions, steps)) {
else if (dimensions[0] < @count@ || !run_binary_simd_@kind@_@TYPE@(args, dimensions, steps)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy to add this, if @seiko2plus doesn't like it, we can follow up also.

BINARY_LOOP {
const @type@ in1 = *(@type@ *)ip1;
const @type@ in2 = *(@type@ *)ip2;
Expand Down
Loading
0