Skip to content

Backend.logsumexp: keepdims missing from Cupy and Tensorflow backends; Cupy reimplements cupyx.scipy.special.logsumexp #867

Description

@tvercaut

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

  1. Call ot.backend.TensorflowBackend().logsumexp(a, axis=0, keepdims=True) (or the equivalent on CupyBackend).
  2. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions