{"record":{"id":"0f745ed526c48884","repo":"jax-ml/jax","slug":"full-must-be-called-with-scalar-fill-value-got-fi","errorCode":null,"errorMessage":"full must be called with scalar fill_value, got fill_value.shape {}.","messagePattern":"full must be called with scalar fill_value, got fill_value\\.shape (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/lax.py","lineNumber":3622,"sourceCode":"\n\ndef full(shape: Shape, fill_value: ArrayLike, dtype: DTypeLike | None = None, *,\n         sharding: Sharding | None = None) -> Array:\n  \"\"\"Returns an array of `shape` filled with `fill_value`.\n\n  Args:\n    shape: sequence of integers, describing the shape of the output array.\n    fill_value: the value to fill the new array with.\n    dtype: the type of the output array, or `None`. If not `None`, `fill_value`\n      will be cast to `dtype`.\n    sharding: an optional sharding specification for the resulting array,\n      note, sharding will currently be ignored in jitted mode, this might change\n      in the future.\n  \"\"\"\n  shape = canonicalize_shape(shape)\n  if np.shape(fill_value):\n    msg = \"full must be called with scalar fill_value, got fill_value.shape {}.\"\n    raise TypeError(msg.format(np.shape(fill_value)))\n  if dtype is None:\n    weak_type = dtypes.is_weakly_typed(fill_value)\n    fill_dtype = _dtype(fill_value)\n  else:\n    if isinstance(dtype, dtypes.ExtendedDType):\n      return dtype._rules.full(shape, fill_value, dtype)\n    weak_type = False\n    fill_dtype = dtypes.check_and_canonicalize_user_dtype(dtype, \"full\")\n  fill_value = _convert_element_type(fill_value, fill_dtype, weak_type)\n  if (sharding is not None and\n      isinstance(fill_value, array.ArrayImpl) and sharding._is_concrete):\n    broadcast_shape = sharding.shard_shape(shape)\n    shard = broadcast(fill_value, broadcast_shape)\n    shard = shard.addressable_data(0)\n    return array.make_array_from_callback(\n        shape, sharding, lambda _: shard, dtype=fill_dtype)\n\n  if sharding is not None and not sharding._is_concrete:","sourceCodeStart":3604,"sourceCodeEnd":3640,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/lax.py#L3604-L3640","documentation":"jax.lax.full requires fill_value to be a scalar (a 0-d value). If np.shape(fill_value) is non-empty, JAX raises this TypeError because full broadcasts a single scalar into a shape, unlike numpy.full which accepts array fill values.","triggerScenarios":"Calling lax.full(shape, fill_value) (or lax.zeros/ones helpers built on it) with an array/tensor fill_value, e.g. lax.full((3,3), jnp.array([1,2])); also iota/eye-style helpers that route through full.","commonSituations":"Porting numpy code np.full(shape, some_array) to JAX; passing a computed vector (e.g. a per-channel constant) where a scalar was assumed; dynamically typed fill_value from user config.","solutions":["Pass a scalar fill_value: extract it with .item() or float(...) if it is a 1-element array","If you need an array broadcast into a shape, use jnp.broadcast_to(arr, shape) or jnp.where with a mask instead of lax.full","Wrap incoming values with jnp.asarray(fill_value).reshape(()) when they are guaranteed single-element"],"exampleFix":"// before\njulia = lax.full((3, 3), jnp.array([7.0]))\n// after\njulia = lax.full((3, 3), 7.0)\n# or broadcast an array:\n# arr = jnp.broadcast_to(jnp.array([7.0]), (3, 3))","handlingStrategy":"validation","validationCode":"import numpy as np\nif np.ndim(fill_value) != 0:\n    fill_value = np.asarray(fill_value).reshape(-1)[0]  # or raise\nout = lax.full(shape, fill_value)","typeGuard":"def is_scalar(v) -> bool:\n    return np.ndim(v) == 0","tryCatchPattern":null,"preventionTips":["Treat fill_value as scalar in APIs; document the constraint","Assert np.ndim(fill_value) == 0 in wrappers around lax.full","Use jnp.broadcast_to for array-valued fills"],"tags":["jax","lax","type-error","scalar-required","shape-validation"],"backgroundTag":"non-scalar-argument-rejected","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}