Describe the bug
Backend.logsumexp is declared as logsumexp(self, a, axis=None, keepdims=False) and its docstring states that it follows the scipy.special.logsumexp API. NumPy (ot/backend.py:1342), Jax (:1782) and Torch (:2460) honour that signature, but:
CupyBackend.logsumexp (:2949) and TensorflowBackend.logsumexp (:3413) are declared (self, a, axis=None) and raise TypeError on keepdims=.
CupyBackend.logsumexp is a hand-rolled port of a 2021 SciPy snippet. cupyx.scipy.special.logsumexp(a, axis=None, b=None, keepdims=False, return_sign=False) now exists and is a drop-in, matching what the NumPy backend does with scipy.special.logsumexp.
tf.math.reduce_logsumexp already accepts keepdims=, so the TF gap is a one-word fix.
No current caller passes keepdims, so nothing is broken today — this is a latent API-conformance inconsistency, not a live bug. But it silently blocks backend-agnostic code from using keepdims, and test_backend.py only exercises nx.logsumexp(Mb) with no arguments, so the divergence is invisible to CI.
To Reproduce
- Call
ot.backend.TensorflowBackend().logsumexp(a, axis=0, keepdims=True) (or the equivalent on CupyBackend).
- Observe
TypeError: logsumexp() got an unexpected keyword argument 'keepdims'.
The same call succeeds on the NumPy, Jax and Torch backends.
Expected behavior
All backends should accept the same logsumexp(self, a, axis=None, keepdims=False) signature declared on the base Backend class, matching the scipy.special.logsumexp API the docstring already promises.
Environment
- Affects all environments; this is a static signature/API-conformance issue, not environment-specific.
Additional context
I plan to open a small PR fixing this (aligning Cupy on cupyx.scipy.special.logsumexp and adding keepdims to the Tensorflow backend), as a prerequisite for some N-D refactoring work in ot/bregman/_convolutional.py that needs a backend-agnostic logsumexp.
Describe the bug
Backend.logsumexpis declared aslogsumexp(self, a, axis=None, keepdims=False)and its docstring states that it follows thescipy.special.logsumexpAPI. NumPy (ot/backend.py:1342), Jax (:1782) and Torch (:2460) honour that signature, but:CupyBackend.logsumexp(:2949) andTensorflowBackend.logsumexp(:3413) are declared(self, a, axis=None)and raiseTypeErroronkeepdims=.CupyBackend.logsumexpis a hand-rolled port of a 2021 SciPy snippet.cupyx.scipy.special.logsumexp(a, axis=None, b=None, keepdims=False, return_sign=False)now exists and is a drop-in, matching what the NumPy backend does withscipy.special.logsumexp.tf.math.reduce_logsumexpalready acceptskeepdims=, so the TF gap is a one-word fix.No current caller passes
keepdims, so nothing is broken today — this is a latent API-conformance inconsistency, not a live bug. But it silently blocks backend-agnostic code from usingkeepdims, andtest_backend.pyonly exercisesnx.logsumexp(Mb)with no arguments, so the divergence is invisible to CI.To Reproduce
ot.backend.TensorflowBackend().logsumexp(a, axis=0, keepdims=True)(or the equivalent onCupyBackend).TypeError: logsumexp() got an unexpected keyword argument 'keepdims'.The same call succeeds on the NumPy, Jax and Torch backends.
Expected behavior
All backends should accept the same
logsumexp(self, a, axis=None, keepdims=False)signature declared on the baseBackendclass, matching thescipy.special.logsumexpAPI the docstring already promises.Environment
Additional context
I plan to open a small PR fixing this (aligning Cupy on
cupyx.scipy.special.logsumexpand addingkeepdimsto the Tensorflow backend), as a prerequisite for some N-D refactoring work inot/bregman/_convolutional.pythat needs a backend-agnosticlogsumexp.