{"record":{"id":"34afcb16a515fa71","repo":"jax-ml/jax","slug":"pad-width-must-be-of-integral-type","errorCode":null,"errorMessage":"`pad_width` must be of integral type.","messagePattern":"`pad_width` must be of integral type\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":4344,"sourceCode":"    Pad a 1-dimensional array with a custom padding function:\n\n    >>> def custom_pad(row, pad_width, iaxis, kwargs):\n    ...   # row represents a 1D slice of the zero-padded array.\n    ...   before, after = pad_width\n    ...   before_value = kwargs.get('before_value', 0)\n    ...   after_value = kwargs.get('after_value', 0)\n    ...   row = row.at[:before].set(before_value)\n    ...   return row.at[len(row) - after:].set(after_value)\n    >>> x = jnp.array([2, 3, 4])\n    >>> jnp.pad(x, 2, custom_pad, before_value=-10, after_value=10)\n    Array([-10, -10,   2,   3,   4,  10,  10], dtype=int32)\n  \"\"\"\n\n  array = util.ensure_arraylike(\"pad\", array)\n  pad_width = _broadcast_to_pairs(pad_width, np.ndim(array), \"pad_width\")\n  if pad_width and not all(core.is_dim(p[0]) and core.is_dim(p[1])\n                           for p in pad_width):\n    raise TypeError('`pad_width` must be of integral type.')\n\n  if callable(mode):\n    return _pad_func(asarray(array), pad_width, mode, **kwargs)\n\n  allowed_kwargs = {\n      'empty': [], 'edge': [], 'wrap': [],\n      'constant': ['constant_values'],\n      'linear_ramp': ['end_values'],\n      'maximum': ['stat_length'],\n      'mean': ['stat_length'],\n      'median': ['stat_length'],\n      'minimum': ['stat_length'],\n      'reflect': ['reflect_type'],\n      'symmetric': ['reflect_type'],\n  }\n  try:\n    unsupported_kwargs = set(kwargs) - set(allowed_kwargs[mode])\n  except KeyError:","sourceCodeStart":4326,"sourceCodeEnd":4362,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L4326-L4362","documentation":"After normalization, each before/after entry of pad_width must be a valid dimension (Python/numpy integer scalar, tracing-safe Dim). Non-integral values such as floats, or non-scalar objects, raise TypeError.","triggerScenarios":"jnp.pad(x, (1.5, 2)) or pad_width computed with float arithmetic like (n * 0.1, 0).","commonSituations":"Computing pad widths with float division or from float config values; passing numpy float64 scalars.","solutions":["Coerce to int: jnp.pad(x, (int(w), 0))","Ensure width computations use integer arithmetic (// instead of /)"],"exampleFix":"// before\njnp.pad(x, (x.shape[0] / 2, 0))\n// after\njnp.pad(x, (x.shape[0] // 2, 0))","handlingStrategy":"validation","validationCode":"assert all(isinstance(v, (int, np.integer)) or core.is_dim(v) for p in pad_width for v in p)","typeGuard":"def int_pairs(pads):\n    return all(np.issubdtype(type(v), np.integer) for p in pads for v in p)","tryCatchPattern":null,"preventionTips":["Use // and int() for width math; never pass floats"],"tags":["jnp-pad","type-error","integral-type"],"backgroundTag":"wrong-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}