{"record":{"id":"1365bc78d3372285","repo":"keras-team/keras","slug":"last-dimension-of-inputs-to-cdist-must-match-1365bc","errorCode":null,"errorMessage":"Last dimension of inputs to `cdist` must match","messagePattern":"Last dimension of inputs to `cdist` must match","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/tensorflow/math.py","lineNumber":99,"sourceCode":"        result = tf.math.in_top_k(targets, predictions, k)\n        return tf.reshape(result, original_shape)\n    return tf.math.in_top_k(targets, predictions, k)\n\n\ndef logsumexp(x, axis=None, keepdims=False):\n    return tf.math.reduce_logsumexp(x, axis=axis, keepdims=keepdims)\n\n\ndef cdist(x, y):\n    x = convert_to_tensor(x)\n    y = convert_to_tensor(y)\n    dtype = dtypes.result_type(x.dtype, y.dtype, float)\n    x = cast(x, dtype)\n    y = cast(y, dtype)\n    if x.shape.rank < 2 or y.shape.rank < 2:\n        raise ValueError(\"`cdist` inputs must have rank >= 2\")\n    if x.shape[-1] != y.shape[-1]:\n        raise ValueError(\"Last dimension of inputs to `cdist` must match\")\n    diff = tf.expand_dims(x, -2) - tf.expand_dims(y, -3)\n    return tf.sqrt(tf.reduce_sum(tf.square(diff), axis=-1))\n\n\ndef extract_sequences(x, sequence_length, sequence_stride):\n    return tf.signal.frame(\n        x,\n        frame_length=sequence_length,\n        frame_step=sequence_stride,\n        axis=-1,\n        pad_end=False,\n    )\n\n\ndef _get_complex_tensor_from_tuple(x):\n    if not isinstance(x, (tuple, list)) or len(x) != 2:\n        raise ValueError(\n            \"Input `x` should be a tuple of two tensors - real and imaginary.\"","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/tensorflow/math.py#L81-L117","documentation":"Error \"Last dimension of inputs to `cdist` must match\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/backend/tensorflow/math.py:99 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}