{"record":{"id":"d6b90390568bad48","repo":"keras-team/keras","slug":"last-dimension-of-inputs-to-cdist-must-match-d6b903","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/numpy/math.py","lineNumber":116,"sourceCode":"\ndef logsumexp(x, axis=None, keepdims=False):\n    x = convert_to_tensor(x)\n    dtype = dtypes.result_type(x.dtype, float)\n    return scipy.special.logsumexp(x, axis=axis, keepdims=keepdims).astype(\n        dtype\n    )\n\n\ndef cdist(x, y):\n    x = np.asarray(x)\n    y = np.asarray(y)\n    dtype = dtypes.result_type(x.dtype, y.dtype, float)\n    x = x.astype(dtype)\n    y = y.astype(dtype)\n    if x.ndim < 2 or y.ndim < 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 = x[..., :, None, :] - y[..., None, :, :]\n    return np.sqrt(np.sum(diff * diff, axis=-1))\n\n\ndef extract_sequences(x, sequence_length, sequence_stride):\n    *batch_shape, _ = x.shape\n    batch_shape = list(batch_shape)\n    shape = x.shape[:-1] + (\n        (x.shape[-1] - (sequence_length - sequence_stride)) // sequence_stride,\n        sequence_length,\n    )\n    strides = x.strides[:-1] + (\n        sequence_stride * x.strides[-1],\n        x.strides[-1],\n    )\n    x = np.lib.stride_tricks.as_strided(x, shape=shape, strides=strides)\n    return np.reshape(x, (*batch_shape, *x.shape[-2:]))\n","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/numpy/math.py#L98-L134","documentation":"Error \"Last dimension of inputs to `cdist` must match\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/backend/numpy/math.py:116 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"}