{"record":{"id":"73035ec3d301cc94","repo":"jax-ml/jax","slug":"sparse-rule-for-primitive-is-not-implemented","errorCode":null,"errorMessage":"sparse rule for {primitive} is not implemented.","messagePattern":"sparse rule for (.+?) is not implemented\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/experimental/sparse/transform.py","lineNumber":132,"sourceCode":"  lax.cos_p,\n  lax.cosh_p,\n  lax.eq_p,\n  lax.exp_p,\n  lax.ge_p,\n  lax.gt_p,\n  lax.le_p,\n  lax.lt_p,\n  lax.log_p,\n  lax.ne_p,\n  lax.xor_p\n]\n\ndef _raise_unimplemented_primitive(primitive):\n  if primitive in _densifying_primitives:\n    raise NotImplementedError(f\"sparse rule for {primitive} is not implemented because it \"\n                              \"would result in dense output. If this is your intent, use \"\n                              \"sparse.todense() to convert your arguments to dense matrices.\")\n  raise NotImplementedError(f\"sparse rule for {primitive} is not implemented.\")\n\n\nArray = Any\nArrayOrSparse = Any\n\n\nclass SparsifyEnv:\n  \"\"\"Environment for sparse jaxpr evaluation.\n\n  The environment is essentially a collection of buffers and/or tracers\n  that may be shared between one or more SparsifyValue objects, which\n  represent sparse or dense arrays via indices into the list of buffers.\n  \"\"\"\n  _buffers : list[Array]\n\n  def __init__(self, bufs=()):\n    self._buffers = list(bufs)\n","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/sparse/transform.py#L114-L150","documentation":"A LAX primitive used inside a jax.experimental.sparse.sparsify function has no registered sparse rule at all (it is not in the densifying list either), so sparsify cannot evaluate it on sparse values.","triggerScenarios":"Calling an exotic lax primitive (no sparse rule registered) on sparse operands inside a @sparse.sparsify function.","commonSituations":"Using newer/less-common lax ops (e.g. some trig/hyperbolic variants, sort ops) on sparse matrices under sparsify; version drift where a primitive lacks a rule.","solutions":["Materialize the operand with sparse.todense() before the primitive","Check the jax.experimental.sparse.transform.sparse_rules_bcoo/bcsr registries for supported ops","Raise a feature request / use dense computation for that portion"],"exampleFix":"// before\n@sparse.sparsify\ndef f(M):\n  return some_lax_op(M)\n// after\n@sparse.sparsify\ndef f(M):\n  return some_lax_op(sparse.todense(M))","handlingStrategy":"fallback","validationCode":"from jax.experimental.sparse.transform import sparse_rules_bcoo\nassert prim in sparse_rules_bcoo, f'{prim} has no sparse rule'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check the sparse_rules_bcoo/bcsr registries for op coverage","Fall back to dense computation for unsupported primitives"],"tags":["jax","sparse","sparsify","not-implemented","lax"],"backgroundTag":"sparse-autodiff-unsupported-op","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}