Hi All,

In https://github.com/numpy/numpy/pull/12801, Tyler has been trying to use
the new `where` argument for reductions to implement `nansum`, etc., using
simplifications that boil down to `np.sum(..., where=~isnan(...))`.

A problem that occurs is that `np.sum` will use a `.sum` method if that is
present, and for matrix, the `.sum` method does not take a `where`
argument. Since the `where` argument has been introduced only recently,
similar problems may happen for array mimics that implement their own
`.sum` method.

The question now is what to do, with options being:
1. Let's stick with the existing implementation; the speed-up is not that
great anyway.
2. Use try/except around the new implementation and use the old one if it
fails.
3. As (2), but emit a deprecation warning. This will help array mimics, but
not matrix (unless someone makes a PR; would we even accept it?);
4. Use the new implementation. `matrix` should be gone anyway and array
mimics can either update their `.sum()` method or override `np.nansum` with
`__array_function__`.

Personally, I'd prefer (4), but realize that (3) is probably the more safer
approach, even if it is really annoying to still be taking into account
matrix deficiencies.

All the best,

Marten

p.s. One could also avoid the `.sum()` override altogether by doing
`np.add.reduce(..., where=...)`, but this would probably break just as much.
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion

Reply via email to