jax-ml/jax · error · ValueError

at least one array or dtype is required

Error message

at least one array or dtype is required

What it means

result_type computes a promoted dtype from its arguments, so at least one is required. Called with zero arguments there is nothing to promote, and the error is raised before the promotion lattice is consulted.

Solutions

  1. Guard the call: if not args: use a sensible default such as jnp.float32
  2. Require at least one argument in your wrapper and raise your own descriptive error
  3. Pass jnp.result_type(*arrays) only after checking len(arrays) > 0

Example fix

# before
dt = jnp.result_type(*dtypes_list)  # crashes when empty

# after
dt = jnp.result_type(*dtypes_list) if dtypes_list else jnp.float32
Defensive patterns

Strategy: validation

Validate before calling

if not args:
    args = [jnp.float32]  # or raise your own error
dt = jnp.result_type(*args)

Type guard

def has_result_type_args(args) -> bool:
    return len(args) > 0

Prevention

When it happens

Trigger: jnp.result_type() with zero args, typically from *args forwarding: jnp.result_type(*dtypes) where dtypes is an empty list.

Common situations: Generic wrapper functions that forward a variable-length list of arrays/dtypes which can be empty; refactors where a previously required argument became optional.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/785dce8eacfd3ff4. Report an issue: GitHub.

Appendix: source

Thrown at jax/_src/dtypes.py:1097

@overload
def result_type(*args: Any, return_weak_type_flag: Literal[False] = False) -> DType: ...

@overload
def result_type(*args: Any, return_weak_type_flag: bool = False) -> DType | tuple[DType, bool]: ...

@export
def result_type(*args: Any, return_weak_type_flag: bool = False) -> DType | tuple[DType, bool]:
  """Convenience function to apply JAX argument dtype promotion.

  Args:
    return_weak_type_flag : if True, then return a ``(dtype, weak_type)`` tuple.
      If False, just return `dtype`

  Returns:
    dtype or (dtype, weak_type) depending on the value of the ``return_weak_type`` argument.
  """
  if len(args) == 0:
    raise ValueError("at least one array or dtype is required")
  dtype: DType | ExtendedDType
  dtype, weak_type = lattice_result_type(*(default_float_dtype() if arg is None else arg for arg in args))
  if weak_type:
    dtype = default_types['f' if dtype in _custom_float_dtypes else dtype.kind]()
  return (dtype, weak_type) if return_weak_type_flag else dtype

def check_and_canonicalize_user_dtype(
    dtype, fun_name=None, *, allow_non_jax_dtypes: bool = False
) -> DType:
  """Checks validity of a user-provided dtype, and returns its canonical form.

  For Python scalar types this function returns the corresponding default dtype.
  """
  if dtype is None:
    raise ValueError("dtype must be specified.")
  if isinstance(dtype, Array):
    raise ValueError("Passing an array as a dtype argument is no longer "
                     "supported; instead of dtype=arr use dtype=arr.dtype.")

View on GitHub (pinned to 1e1c6a8fc0)