keras-team/keras · error · ValueError

`axis1` and `axis2` cannot be the same.

Error message

`axis1` and `axis2` cannot be the same.

What it means

Error "`axis1` and `axis2` cannot be the same." thrown in keras-team/keras.

Source

Thrown at keras/src/backend/openvino/numpy.py:1681

    indices = ov_opset.concat([rows_expanded, cols_expanded], 1).output(0)

    result = ov_opset.scatter_nd_update(zeros_mat, indices, v_flat).output(0)
    return OpenVINOKerasTensor(result)


def diagonal(x, offset=0, axis1=0, axis2=1):
    x = get_ov_output(x)
    rank = x.get_partial_shape().rank.get_length()
    if rank is None:
        raise ValueError("`diagonal` requires input tensor with static rank.")
    if rank < 2:
        raise ValueError(
            f"diagonal requires input tensor with rank >= 2.Given rank: {rank}"
        )
    axis1 = canonicalize_axis(axis1, rank)
    axis2 = canonicalize_axis(axis2, rank)
    if axis1 == axis2:
        raise ValueError("`axis1` and `axis2` cannot be the same.")

    perm_order = [axis1, axis2] + [
        i for i in range(rank) if i != axis1 and i != axis2
    ]
    perm_const = ov_opset.constant(perm_order, dtype=Type.i32).output(0)
    x_transposed = ov_opset.transpose(x, perm_const)

    # Build the (row, col) index pairs in the graph so the diagonalized axes
    # may be dynamic.
    zero = ov_opset.constant(0, Type.i32).output(0)
    one = ov_opset.constant(1, Type.i32).output(0)
    offset_const = ov_opset.constant(
        offset if offset >= 0 else -offset, Type.i32
    ).output(0)
    t_shape = ov_opset.shape_of(x_transposed, Type.i32).output(0)
    N = ov_opset.gather(t_shape, zero, zero).output(0)
    M = ov_opset.gather(t_shape, one, zero).output(0)

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/backend/openvino/numpy.py:1681 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/b8a35bd29c32014c. Report an issue: GitHub.