{"record":{"id":"58fefff7c610fb82","repo":"jax-ml/jax","slug":"out-dtype-should-be-an-integer-type-got-out-dtyp","errorCode":null,"errorMessage":"out_dtype should be an integer type; got {out_dtype}","messagePattern":"out_dtype should be an integer type; got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/hijax.py","lineNumber":97,"sourceCode":"      raise ValueError(\n          \"dtypes of sorted_arr and query must match; got \"\n          f\"{sorted_arr_aval.dtype} and {query_aval.dtype}\"\n      )\n    if side not in [\"left\", \"right\"]:\n      raise ValueError(\n          f\"invalid argument side={side!r}, expected 'left' or 'right'\"\n      )\n    if method not in self.valid_methods:\n      raise ValueError(\n          f\"invalid argument {method=}, expected one of {list(self.valid_methods)}\"\n      )\n    if sorted_arr_aval.shape[:batch_dims] != query_aval.shape[:batch_dims]:\n      raise ValueError(\n          \"batch dimension sizes must match; got\"\n          f\" {sorted_arr_aval.shape[:batch_dims]} != {query_aval.shape[:batch_dims]}\"\n      )\n    if not dtypes.issubdtype(out_dtype, np.integer):\n      raise ValueError(f\"out_dtype should be an integer type; got {out_dtype}\")\n    # Attempt this here to catch overflow errors early.\n    out_dtype.type(sorted_arr_aval.shape[dimension])\n    self.in_avals = (sorted_arr_aval, query_aval)\n    self.out_aval = core.typeof(api.eval_shape(\n      functools.partial(_searchsorted_impl,\n        dimension=dimension, batch_dims=batch_dims, side=side,\n        dtype=out_dtype, method=method),\n        sorted_arr_aval, query_aval))\n    self.params = dict(\n      side=side,\n      dimension=dimension,\n      batch_dims=batch_dims,\n      method=method,\n    )\n    super().__init__()\n\n  def expand(self, sorted_arr: ArrayLike, query: ArrayLike) -> Array:  # pyrefly: ignore[bad-override]\n    return _searchsorted_impl(","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/hijax.py#L79-L115","documentation":"Raised by the SearchSorted HiJAX primitive when the requested output dtype for the returned indices is not an integer type. Search results are indices, so out_dtype must satisfy dtypes.issubdtype(out_dtype, np.integer).","triggerScenarios":"Calling searchsorted with out_dtype='float32', np.float64, or a non-dtype object that resolves to a floating type.","commonSituations":"Copy-pasting a dtype parameter from a nearby array-creation call; attempting to get 'positions' as floats instead of indices.","solutions":["Use an integer dtype such as 'int32' (the usual default) or 'int64'","If you need float positions, get integer indices first and cast the result afterwards"],"exampleFix":"# before\nidx = searchsorted(a, v, out_dtype=jnp.float32)\n# after\nidx = searchsorted(a, v, out_dtype=jnp.int32).astype(jnp.float32)","handlingStrategy":"validation","validationCode":"import numpy as np\nfrom jax._src import dtypes\nassert dtypes.issubdtype(np.dtype(out_dtype), np.integer)","typeGuard":"def is_int_dtype(d) -> bool:\n    import numpy as np\n    from jax._src import dtypes\n    return dtypes.issubdtype(np.dtype(d), np.integer)","tryCatchPattern":null,"preventionTips":["Reserve dtype params of index-returning functions for int32/int64","Cast outputs after the call if floats are needed"],"tags":["jax","dtype","searchsorted","argument-validation"],"backgroundTag":"invalid-dtype-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}