keras-team/keras · error · ValueError

Last dimension of inputs to `cdist` must match

Error message

Last dimension of inputs to `cdist` must match

What it means

Error "Last dimension of inputs to `cdist` must match" thrown in keras-team/keras.

Source

Thrown at keras/src/backend/tensorflow/math.py:99

        result = tf.math.in_top_k(targets, predictions, k)
        return tf.reshape(result, original_shape)
    return tf.math.in_top_k(targets, predictions, k)


def logsumexp(x, axis=None, keepdims=False):
    return tf.math.reduce_logsumexp(x, axis=axis, keepdims=keepdims)


def cdist(x, y):
    x = convert_to_tensor(x)
    y = convert_to_tensor(y)
    dtype = dtypes.result_type(x.dtype, y.dtype, float)
    x = cast(x, dtype)
    y = cast(y, dtype)
    if x.shape.rank < 2 or y.shape.rank < 2:
        raise ValueError("`cdist` inputs must have rank >= 2")
    if x.shape[-1] != y.shape[-1]:
        raise ValueError("Last dimension of inputs to `cdist` must match")
    diff = tf.expand_dims(x, -2) - tf.expand_dims(y, -3)
    return tf.sqrt(tf.reduce_sum(tf.square(diff), axis=-1))


def extract_sequences(x, sequence_length, sequence_stride):
    return tf.signal.frame(
        x,
        frame_length=sequence_length,
        frame_step=sequence_stride,
        axis=-1,
        pad_end=False,
    )


def _get_complex_tensor_from_tuple(x):
    if not isinstance(x, (tuple, list)) or len(x) != 2:
        raise ValueError(
            "Input `x` should be a tuple of two tensors - real and imaginary."

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/backend/tensorflow/math.py:99 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/1365bc78d3372285. Report an issue: GitHub.