{"record":{"id":"4458a9ff6e533ca3","repo":"keras-team/keras","slug":"diagonal-requires-input-tensor-with-static-rank","errorCode":null,"errorMessage":"`diagonal` requires input tensor with static rank.","messagePattern":"`diagonal` requires input tensor with static rank\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/openvino/numpy.py","lineNumber":1673,"sourceCode":"        cols = ov_opset.add(rng, k_const).output(0)\n    else:\n        neg_k_const = ov_opset.constant(-k_val, dtype=Type.i32).output(0)\n        rows = ov_opset.add(rng, neg_k_const).output(0)\n        cols = rng\n\n    rows_expanded = ov_opset.reshape(rows, [-1, 1], False).output(0)\n    cols_expanded = ov_opset.reshape(cols, [-1, 1], False).output(0)\n    indices = ov_opset.concat([rows_expanded, cols_expanded], 1).output(0)\n\n    result = ov_opset.scatter_nd_update(zeros_mat, indices, v_flat).output(0)\n    return OpenVINOKerasTensor(result)\n\n\ndef diagonal(x, offset=0, axis1=0, axis2=1):\n    x = get_ov_output(x)\n    rank = x.get_partial_shape().rank.get_length()\n    if rank is None:\n        raise ValueError(\"`diagonal` requires input tensor with static rank.\")\n    if rank < 2:\n        raise ValueError(\n            f\"diagonal requires input tensor with rank >= 2.Given rank: {rank}\"\n        )\n    axis1 = canonicalize_axis(axis1, rank)\n    axis2 = canonicalize_axis(axis2, rank)\n    if axis1 == axis2:\n        raise ValueError(\"`axis1` and `axis2` cannot be the same.\")\n\n    perm_order = [axis1, axis2] + [\n        i for i in range(rank) if i != axis1 and i != axis2\n    ]\n    perm_const = ov_opset.constant(perm_order, dtype=Type.i32).output(0)\n    x_transposed = ov_opset.transpose(x, perm_const)\n\n    # Build the (row, col) index pairs in the graph so the diagonalized axes\n    # may be dynamic.\n    zero = ov_opset.constant(0, Type.i32).output(0)","sourceCodeStart":1655,"sourceCodeEnd":1691,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/openvino/numpy.py#L1655-L1691","documentation":"Error \"`diagonal` requires input tensor with static rank.\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/backend/openvino/numpy.py:1673 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"}