{"record":{"id":"4dd4096ba7ead619","repo":"jax-ml/jax","slug":"strides-must-be-a-sequence-of-positive-integers-g","errorCode":null,"errorMessage":"strides must be a sequence of positive integers; got {strides}","messagePattern":"strides must be a sequence of positive integers; got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/sparse/bcoo.py","lineNumber":1988,"sourceCode":"      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))\n  index_slices.extend([slice(None), slice(None)])\n  for i, (start, end, stride) in enumerate(zip(start_dense, end_dense, stride_dense)):","sourceCodeStart":1970,"sourceCodeEnd":2006,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/sparse/bcoo.py#L1970-L2006","documentation":"bcoo_slice only supports strided slicing with strictly positive integer strides; any stride <= 0 raises ValueError because negative or zero strides are not implemented for the BCOO representation (unlike dense lax.slice with jax sometimes allowing negative semantics elsewhere).","triggerScenarios":"Passing a strides sequence containing 0 or a negative number, e.g. strides=(0, 1) or strides=(-1, 1), to bcoo_slice.","commonSituations":"Porting NumPy slice syntax with step=-1 (reversal) to BCOO; passing 0 expecting 'no stride along this axis'; computing strides from user input without sanitization.","solutions":["Replace non-positive strides with 1 (or the intended positive step)","For reversal, flip the array via BCOO dense round-trip or sparse reversal utilities, not negative strides","Validate/clip strides before calling bcoo_slice"],"exampleFix":"# before\nbcoo_slice(mat, (0, 0), (8, 8), strides=(-1, 2))\n# after\nbcoo_slice(mat, (0, 0), (8, 8), strides=(1, 2))","handlingStrategy":"validation","validationCode":"strides = strides or [1] * mat.ndim\nif any(s <= 0 for s in strides):\n    strides = [max(1, s) for s in strides]  # or raise early with context","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember BCOO slicing has no negative-stride (reversal) support","Sanitize user-supplied step values before calling bcoo_slice"],"tags":["jax","sparse","bcoo","strides","positive-value-required"],"backgroundTag":"negative-or-zero-stride","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}