diff options
| author | Sebastian Berg <sebastian@sipsolutions.net> | 2022-03-11 15:33:27 -0800 |
|---|---|---|
| committer | Sebastian Berg <sebastian@sipsolutions.net> | 2022-04-24 21:47:50 +0200 |
| commit | fd9c3efc2d7c0721e537bda2538d78995d14ec7c (patch) | |
| tree | 07b9e5ac984a36f6b02f6f8bc81ef8589aee0df5 /benchmarks | |
| parent | 732ed25e4a1e3802d82a976f9541f74548b13e6f (diff) | |
| download | numpy-fd9c3efc2d7c0721e537bda2538d78995d14ec7c.tar.gz | |
MAINT,ENH: Rewrite scalar math logic
This commit tries to redo the scalar math logic to take some more
care about subclasses, but most of all introduce logic to defer
to the `other` if `self` can be cast to it safely (i.e. it is
the correct promotion).
This makes things much faster and more reliable, since we now use
defer much less to `ufuncs` indirectly.
This ensures that integer overflows are reported more reliably.
Another major point about it, is that this reorganizes the coercion
of Python int, float, complex (and bool).
This should help a bit with switching to "weak" Python scalars.
This may just be a first step on a longer path...
Diffstat (limited to 'benchmarks')
| -rw-r--r-- | benchmarks/benchmarks/bench_scalar.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/benchmarks/benchmarks/bench_scalar.py b/benchmarks/benchmarks/bench_scalar.py index 219e48bed..2ad3ae670 100644 --- a/benchmarks/benchmarks/bench_scalar.py +++ b/benchmarks/benchmarks/bench_scalar.py @@ -10,6 +10,7 @@ class ScalarMath(Benchmark): param_names = ["type"] def setup(self, typename): self.num = np.dtype(typename).type(2) + self.int32 = np.int32(2) def time_addition(self, typename): n = self.num @@ -31,3 +32,14 @@ class ScalarMath(Benchmark): n = self.num res = abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(n)))))))))) + def time_add_int32_other(self, typename): + # Some mixed cases are fast, some are slow, this documents these + # differences. (When writing, it was fast if the type of the result + # is one of the inputs.) + int32 = self.int32 + other = self.num + int32 + other + int32 + other + int32 + other + int32 + other + int32 + other |
