jax-ml/jax · error · TypeError

mulhi requires integer inputs, got {dtype}

Error message

mulhi requires integer inputs, got {dtype}

What it means

jax.lax_reference.mulhi (the NumPy reference implementation of multiply-high) only accepts integer dtypes. Passing floats or other types raises TypeError.

Source

Thrown at jax/_src/lax_reference.py:118

bitwise_or = np.bitwise_or
bitwise_xor = np.bitwise_xor

add = np.add
sub = np.subtract

def mul(x, y, /, *, out_dtype=None):
  if out_dtype is not None:
    x = np.astype(x, out_dtype)
    y = np.astype(y, out_dtype)
  return np.multiply(x, y)


def mulhi(x, y):
  x = np.asarray(x)
  y = np.asarray(y)
  dtype = x.dtype
  if not np.issubdtype(dtype, np.integer):
    raise TypeError(f'mulhi requires integer inputs, got {dtype}')
  if dtype != y.dtype:
    raise TypeError(
        f'mulhi operands must have the same dtype, got {dtype} and {y.dtype}'
    )
  info = np.iinfo(dtype)
  bits = info.bits
  is_signed = np.issubdtype(dtype, np.signedinteger)
  # For 64-bit inputs, use Python object dtype for arbitrary precision.
  if bits == 64:
    widen_dtype = np.dtype(object)
  else:
    widen_bits = bits * 2
    widen_dtype = np.dtype(f'{"i" if is_signed else "u"}{widen_bits // 8}')
  prod = x.astype(widen_dtype) * y.astype(widen_dtype)
  return (prod >> bits).astype(dtype)


def div(lhs, rhs):

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Cast inputs to an integer dtype: x.astype(np.int32)
  2. Prevent implicit promotion to float upstream (e.g. division producing floats)

Example fix

# before
lax_reference.mulhi(1.5, 2.0)
# after
lax_reference.mulhi(np.int32(3), np.int32(7))
Defensive patterns

Strategy: type-guard

Validate before calling

assert np.issubdtype(np.asarray(x).dtype, np.integer)

Type guard

def is_int(x): return np.issubdtype(np.asarray(x).dtype, np.integer)

Prevention

When it happens

Trigger: Calling lax_reference.mulhi(np.float32(1.0), np.float32(2.0)) or any non-integer input.

Common situations: Using mulhi for fixed-point arithmetic with accidentally promoted float arrays; testing against the reference implementation with default float jnp arrays.

Related errors


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