jax-ml/jax · error · NotImplementedError

`type` argument of array.view() is not supported.

Error message

`type` argument of array.view() is not supported.

What it means

NumPy's ndarray.view accepts a `type` argument (Python buffer/exposed type) for object views; JAX arrays are not buffers and only support dtype-based views, so any non-None type raises NotImplementedError. Only dtype=None or a dtype is accepted.

Source

Thrown at jax/_src/numpy/array_methods.py:591

  However, there are no guarantees about the results of any expression involving
  a view such as this: ``jnp.array([1, 2, 3], dtype=jnp.int8).view(jnp.bool_)``.
  In particular, the results may change between JAX releases and depending on
  the platform. To safely convert such an array to a boolean array, compare it
  with `0`::

    >>> jnp.array([1, 2, 0], dtype=jnp.int8) != 0
    Array([ True,  True, False], dtype=bool)

  Args:
    dtype: An optional output dtype. If not specified, the output dtype is the
      same as the input dtype.
    type: Not implemented; accepted for NumPy compatibility.
  Returns:
    The array, viewed as the new dtype. Unlike NumPy, the array may or may not
    be a copy of the input array.
  """
  if type is not None:
    raise NotImplementedError("`type` argument of array.view() is not supported.")

  if dtype is None:
    return self

  dtype = dtypes.check_and_canonicalize_user_dtype(dtype, "view")

  nbits_in = dtypes.itemsize_bits(self.dtype)
  nbits_out = dtypes.itemsize_bits(dtype)

  if self.ndim == 0:
    if nbits_in != nbits_out:
      raise ValueError("view() of a 0d array is only supported if the itemsize is unchanged.")
    return _view(lax.expand_dims(self, (0,)), dtype).squeeze()

  if (self.shape[-1] * nbits_in) % nbits_out != 0:
    raise ValueError("When changing to a larger dtype, its size must be a divisor "
                     "of the total size in bytes of the last axis of the array.")

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Remove the type argument and pass a dtype instead: arr.view(jnp.float32)
  2. If a zero-copy buffer is needed, use np.asarray(jax_array) first and call view on the NumPy array

Example fix

# before
arr.view(type=np.uint8)

# after
arr.view(jnp.uint8)
Defensive patterns

Strategy: validation

Validate before calling

def view(a, dtype=None, type=None):
    if type is not None:
        raise TypeError('JAX view() does not accept type=')
    return a.view(dtype)

Prevention

When it happens

Trigger: Calling `arr.view(type=some_type)` with type not None, e.g. `arr.view(type=np.ndarray)` or legacy code using view(type=...).

Common situations: Old NumPy code or tutorials using the three-argument form of view; interop wrappers that forward **kwargs to view.

Related errors


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