{"record":{"id":"6b956971ad56d56a","repo":"jax-ml/jax","slug":"len-strides-len-strides-expected-mat-ndim","errorCode":null,"errorMessage":"len(strides) = {len(strides)}; expected {mat.ndim}","messagePattern":"len\\(strides\\) = (.+?); expected (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/sparse/bcoo.py","lineNumber":1986,"sourceCode":"      indices of each slice\n    strides: (not implemented) sequence of integers of length `mat.ndim` specifying\n      the stride for each slice\n\n  Returns:\n    out: BCOO array containing the slice.\n  \"\"\"\n  if not isinstance(mat, BCOO):\n    raise TypeError(f\"bcoo_slice: input should be BCOO array, got type(mat)={type(mat)}\")\n  start_indices = [operator.index(i) for i in start_indices]\n  limit_indices = [operator.index(i) for i in limit_indices]\n  if strides is not None:\n    strides = [operator.index(i) for i in strides]\n  else:\n    strides = [1] * mat.ndim\n  if len(start_indices) != len(limit_indices) != len(strides) != mat.ndim:\n    raise ValueError(f\"bcoo_slice: indices must have size mat.ndim={mat.ndim}\")\n  if len(strides) != mat.ndim:\n    raise ValueError(f\"len(strides) = {len(strides)}; expected {mat.ndim}\")\n  if any(s <= 0 for s in strides):\n    raise ValueError(f\"strides must be a sequence of positive integers; got {strides}\")\n\n  if not all(0 <= start <= end <= size\n             for start, end, size in safe_zip(start_indices, limit_indices, mat.shape)):\n    raise ValueError(f\"bcoo_slice: invalid indices. Got {start_indices=}, \"\n                     f\"{limit_indices=} and shape={mat.shape}\")\n\n  start_batch, start_sparse, start_dense = split_list(start_indices, [mat.n_batch, mat.n_sparse])\n  end_batch, end_sparse, end_dense = split_list(limit_indices, [mat.n_batch, mat.n_sparse])\n  stride_batch, stride_sparse, stride_dense = split_list(strides, [mat.n_batch, mat.n_sparse])\n\n  data_slices = []\n  index_slices = []\n  for i, (start, end, stride) in enumerate(zip(start_batch, end_batch, stride_batch)):\n    data_slices.append(slice(None) if mat.data.shape[i] != mat.shape[i] else slice(start, end, stride))\n    index_slices.append(slice(None) if mat.indices.shape[i] != mat.shape[i] else slice(start, end, stride))\n  data_slices.append(slice(None))","sourceCodeStart":1968,"sourceCodeEnd":2004,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/sparse/bcoo.py#L1968-L2004","documentation":"A secondary check in bcoo_slice that explicitly verifies len(strides) == mat.ndim after the earlier chained-comparison check. It fires when the strides sequence length doesn't match the array rank, typically when strides was passed explicitly with the wrong number of entries.","triggerScenarios":"Passing strides=[1] (or any list) whose length differs from mat.ndim to bcoo_slice, e.g. strides=(2,) for a 2-D BCOO array.","commonSituations":"Copying strides from code written for a different-rank array; assuming strides apply only to dense dimensions; off-by-one when constructing strides tuples.","solutions":["Supply a strides sequence with exactly mat.ndim entries","Omit strides entirely (pass None) to use unit strides everywhere","Generate strides as [1] * mat.ndim or tuple(s if i in stride_dims else 1 for ...)"],"exampleFix":"# before\nbcoo_slice(mat, (0, 0), (8, 8), strides=(2,))\n# after\nbcoo_slice(mat, (0, 0), (8, 8), strides=(2, 1))","handlingStrategy":"validation","validationCode":"if strides is not None and len(strides) != mat.ndim:\n    raise ValueError(f'strides rank {len(strides)} != mat.ndim {mat.ndim}')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate strides with [1] * mat.ndim then override specific axes","Never copy strides tuples across arrays of different rank"],"tags":["jax","sparse","bcoo","strides","validation"],"backgroundTag":"stride-length-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}