{"record":{"id":"c02e5c8bb3cfdc62","repo":"jax-ml/jax","slug":"transpose-permutation-must-be-a-tuple-list-ndarray-c02e5c","errorCode":null,"errorMessage":"transpose permutation must be a tuple/list/ndarray, got {type(permutation)}.","messagePattern":"transpose permutation must be a tuple/list/ndarray, got (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/experimental/sparse/bcoo.py","lineNumber":537,"sourceCode":"  Returns:\n    A BCOO-format array.\n  \"\"\"\n  buffers = _bcoo_transpose(mat.data, mat.indices, permutation=permutation, spinfo=mat._info)\n  out_shape = tuple(mat.shape[p] for p in permutation)\n  return BCOO(buffers, shape=out_shape, unique_indices=mat.unique_indices)\n\ndef _bcoo_transpose(data: Array, indices: Array, *,\n                    permutation: Sequence[int], spinfo: SparseInfo) -> tuple[Array, Array]:\n  permutation = tuple(permutation)\n  if permutation == tuple(range(len(spinfo.shape))):\n    return data, indices\n  else:\n    return bcoo_transpose_p.bind(data, indices, permutation=permutation,\n                                 spinfo=spinfo)\n\ndef _validate_permutation(data, indices, permutation, shape):\n  if not isinstance(permutation, (tuple, list, np.ndarray)):\n    raise TypeError(f\"transpose permutation must be a tuple/list/ndarray, got {type(permutation)}.\")\n  if tuple(sorted(permutation)) != tuple(range(len(shape))):\n    raise TypeError(\"transpose permutation isn't a permutation of operand dimensions, \"\n                    f\"got permutation {permutation} for shape {shape}.\")\n  n_batch, n_sparse, n_dense, _ = _validate_bcoo(data, indices, shape)\n  batch_perm = permutation[:n_batch]\n  sparse_perm = [p - n_batch for p in permutation[n_batch: n_batch + n_sparse]]\n  dense_perm = [p - n_sparse - n_batch for p in permutation[n_batch + n_sparse:]]\n  if n_batch and tuple(sorted(batch_perm)) != tuple(range(n_batch)):\n    raise NotImplementedError(\"transpose permutation cannot permute batch axes with non-batch axes; \"\n                              f\"got permutation {permutation}, with {n_batch=}.\")\n  if n_dense and tuple(sorted(dense_perm)) != tuple(range(n_dense)):\n    raise NotImplementedError(\"transpose permutation cannot permute dense axes with non-dense axes; \"\n                              f\"got permutation {permutation}, with {n_dense=}.\")\n  return batch_perm, sparse_perm, dense_perm\n\n@bcoo_transpose_p.def_impl\ndef _bcoo_transpose_impl(data, indices, *, permutation: Sequence[int], spinfo: SparseInfo):\n  batch_perm, sparse_perm, dense_perm = _validate_permutation(data, indices, permutation, spinfo.shape)","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/sparse/bcoo.py#L519-L555","documentation":"BCOO transpose (and reshape, which uses transpose internally) requires the permutation as a tuple, list, or numpy array. Passing another type (int, jax array, generator) raises TypeError.","triggerScenarios":"Calling bcoo.transpose(perm) or sparsified jnp.transpose with perm given as a JAX DeviceArray, an int, or another iterable type.","commonSituations":"Passing a jnp.array permutation computed under jit instead of tuple(perm); forgetting to unpack a single int as a tuple.","solutions":["Convert: perm = tuple(perm) (or np.asarray) before calling transpose","Avoid passing jax arrays as static metadata to sparse ops"],"exampleFix":"// before\nperm = jnp.array([1, 0])\nout = bcoo.transpose(perm)\n// after\nperm = (1, 0)\nout = bcoo.transpose(perm)","handlingStrategy":"type-guard","validationCode":"if not isinstance(perm, (tuple, list)):\n    perm = tuple(perm.tolist() if hasattr(perm, 'tolist') else perm)","typeGuard":"def is_valid_perm_type(p) -> bool:\n    return isinstance(p, (tuple, list)) or type(p).__module__ == 'numpy'","tryCatchPattern":null,"preventionTips":["Convert jnp arrays to tuples before passing as permutation metadata","Never pass DeviceArrays as static arguments to sparse primitives"],"tags":["jax","sparse","bcoo","transpose","type-check"],"backgroundTag":"wrong-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}