{"record":{"id":"5fc3c0e674c6d304","repo":"keras-team/keras","slug":"ldexp-exponent-must-be-an-integer-type-received-5fc3c0","errorCode":null,"errorMessage":"ldexp exponent must be an integer type. Received: x2 dtype={x2.dtype}","messagePattern":"ldexp exponent must be an integer type\\. Received: x2 dtype=(.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/numpy/numpy.py","lineNumber":877,"sourceCode":"    x2 = convert_to_tensor(x2)\n    dtype = dtypes.result_type(x1.dtype, x2.dtype)\n    return np.kron(x1, x2).astype(dtype)\n\n\ndef lcm(x1, x2):\n    x1 = convert_to_tensor(x1)\n    x2 = convert_to_tensor(x2)\n    dtype = dtypes.result_type(x1.dtype, x2.dtype)\n    return np.lcm(x1, x2).astype(dtype)\n\n\ndef ldexp(x1, x2):\n    x1 = convert_to_tensor(x1)\n    x2 = convert_to_tensor(x2)\n    dtype = dtypes.result_type(x1.dtype, x2.dtype, float)\n\n    if standardize_dtype(x2.dtype) not in dtypes.INT_TYPES:\n        raise TypeError(\n            f\"ldexp exponent must be an integer type. \"\n            f\"Received: x2 dtype={x2.dtype}\"\n        )\n    return np.ldexp(x1, x2).astype(dtype)\n\n\ndef less(x1, x2):\n    return np.less(x1, x2)\n\n\ndef less_equal(x1, x2):\n    return np.less_equal(x1, x2)\n\n\ndef linspace(\n    start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0\n):\n    axis = standardize_axis_for_numpy(axis)","sourceCodeStart":859,"sourceCodeEnd":895,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/numpy/numpy.py#L859-L895","documentation":"A dtype guard in the NumPy `ldexp` implementation (x1 * 2**x2). ldexp requires the exponent `x2` to be an integer array; if x2 arrives with a float dtype the underlying operation is undefined. The guard checks x2's dtype against the integer type list and, on failure, raises a TypeError reporting the offending dtype. Used by mixed-precision benchmark entry points (e.g. BERT/image classification benchmarks), so it typically fires when an exponent tensor was upcast to float32 by a mixed-precision policy.","triggerScenarios":"Thrown at keras/src/backend/numpy/numpy.py:877 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Cast the exponent to an integer dtype before calling ldexp: keras.ops.cast(x2, 'int32')","Compute x1 * 2**x2 with explicit power ops if a float exponent must be kept","Audit mixed-precision dtype policies that upcast all tensors to float and exempt integer-valued exponent inputs"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}