{"record":{"id":"598efed0be00ede8","repo":"jax-ml/jax","slug":"arguments-to-jax-numpy-lcm-must-be-integers","errorCode":null,"errorMessage":"Arguments to jax.numpy.lcm must be integers.","messagePattern":"Arguments to jax\\.numpy\\.lcm must be integers\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":8909,"sourceCode":"    Array inputs:\n\n    >>> x1 = jnp.array([12, 18, 24])\n    >>> x2 = jnp.array([5, 10, 15])\n    >>> jnp.lcm(x1, x2)\n    Array([ 60,  90, 120], dtype=int32)\n\n    Broadcasting:\n\n    >>> x1 = jnp.array([12])\n    >>> x2 = jnp.array([6, 9, 12])\n    >>> jnp.lcm(x1, x2)\n    Array([12, 36, 12], dtype=int32)\n  \"\"\"\n  x1, x2 = util.ensure_arraylike(\"lcm\", x1, x2)\n  x1, x2 = util.promote_dtypes(x1, x2)\n  x1, x2 = ufuncs.abs(x1), ufuncs.abs(x2)\n  if not issubdtype(x1.dtype, np.integer):\n    raise ValueError(\"Arguments to jax.numpy.lcm must be integers.\")\n  d = gcd(x1, x2)\n  return where(d == 0, lax._const(d, 0),\n               ufuncs.multiply(x1, ufuncs.floor_divide(x2, d)))\n\n\n@export\ndef extract(condition: ArrayLike, arr: ArrayLike,\n            *, size: int | None = None, fill_value: ArrayLike = 0) -> Array:\n  \"\"\"Return the elements of an array that satisfy a condition.\n\n  JAX implementation of :func:`numpy.extract`.\n\n  Args:\n    condition: array of conditions. Will be converted to boolean and flattened to 1D.\n    arr: array of values to extract. Will be flattened to 1D.\n    size: optional static size for output. Must be specified in order for ``extract``\n      to be compatible with JAX transformations like :func:`~jax.jit` or :func:`~jax.vmap`.\n    fill_value: if ``size`` is specified, fill padded entries with this value (default: 0).","sourceCodeStart":8891,"sourceCodeEnd":8927,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L8891-L8927","documentation":"jax.numpy.lcm computes the least common multiple and, like gcd, requires both promoted arguments to have an integer dtype. After ensure_arraylike and promote_dtypes (and abs), it validates issubdtype(x1.dtype, np.integer) and raises ValueError if the promoted dtype is not integral.","triggerScenarios":"Calling jnp.lcm on float arrays or mixed int/float inputs, e.g. jnp.lcm(np.array([2.0]), np.array([3])) — promotion gives float64 and the check fails.","commonSituations":"Feeding results of float arithmetic or float-loaded datasets into lcm; assuming JAX auto-truncates floats like Python's math.lcm does not.","solutions":["Cast both arguments to an integer dtype: jnp.lcm(x1.astype(int), x2.astype(int))","Fix upstream code that produces float values where integers were intended","Validate dtypes with jnp.issubdtype before calling"],"exampleFix":"// before\njnp.lcm(4.0, 6.0)  # ValueError\n// after\njnp.lcm(jnp.array(4.0, dtype=jnp.int32), jnp.array(6.0, dtype=jnp.int32))","handlingStrategy":"validation","validationCode":"x1 = jnp.asarray(x1).astype(jnp.int32)\nx2 = jnp.asarray(x2).astype(jnp.int32)\njnp.lcm(x1, x2)","typeGuard":"def is_integer_array(x) -> bool:\n    return jnp.issubdtype(jnp.asarray(x).dtype, jnp.integer)","tryCatchPattern":null,"preventionTips":["Cast lcm operands to int explicitly","Avoid mixing float scalars with int arrays","Use jnp.result_type to predict promotion outcomes"],"tags":["jax","numpy","dtype-validation","integer-required"],"backgroundTag":"dtype-validation-failed","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}