{"record":{"id":"321adf78f0808668","repo":"jax-ml/jax","slug":"sparse-format-sparse-format-r-not-recognized-mu","errorCode":null,"errorMessage":"sparse_format={sparse_format!r} not recognized; must be one of {list(formats.keys())}","messagePattern":"sparse_format=(.+?) not recognized; must be one of (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/sparse/api.py","lineNumber":134,"sourceCode":"    _todense_impl, multiple_results=False))\n\n\ndef empty(shape: Sequence[int], dtype: DTypeLike | None=None, index_dtype: DTypeLike = 'int32',\n          sparse_format: str = 'bcoo', **kwds) -> JAXSparse:\n  \"\"\"Create an empty sparse array.\n\n  Args:\n    shape: sequence of integers giving the array shape.\n    dtype: (optional) dtype of the array.\n    index_dtype: (optional) dtype of the index arrays.\n    format: string specifying the matrix format (e.g. ['bcoo']).\n    **kwds: additional keywords passed to the format-specific _empty constructor.\n  Returns:\n    mat: empty sparse matrix.\n  \"\"\"\n  formats = {'bcsr': BCSR, 'bcoo': BCOO, 'coo': COO, 'csr': CSR, 'csc': CSC}\n  if sparse_format not in formats:\n    raise ValueError(f\"sparse_format={sparse_format!r} not recognized; \"\n                     f\"must be one of {list(formats.keys())}\")\n  cls = formats[sparse_format]\n  return cls._empty(tuple(shape), dtype=dtype, index_dtype=index_dtype, **kwds)\n\n\ndef eye(N: int, M: int | None = None, k: int = 0, dtype: DTypeLike | None = None,\n        index_dtype: DTypeLike = 'int32', sparse_format: str = 'bcoo', **kwds) -> JAXSparse:\n  \"\"\"Create 2D sparse identity matrix.\n\n  Args:\n    N: int. Number of rows in the output.\n    M: int, optional. Number of columns in the output. If None, defaults to `N`.\n    k: int, optional. Index of the diagonal: 0 (the default) refers to the main\n       diagonal, a positive value refers to an upper diagonal, and a negative value\n       to a lower diagonal.\n    dtype: data-type, optional. Data-type of the returned array.\n    index_dtype: (optional) dtype of the index arrays.\n    format: string specifying the matrix format (e.g. ['bcoo']).","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/sparse/api.py#L116-L152","documentation":"jax.experimental.sparse.empty accepts sparse_format only from a fixed set: 'bcsr','bcoo','coo','csr','csc'. Passing any other string (or wrong case, or a class) raises ValueError listing valid options.","triggerScenarios":"Calling jax.sparse.empty(shape, sparse_format='BCOO'), sparse_format='dia', sparse_format=BCOO (a class instead of string), or a typo like 'cos'.","commonSituations":"Assuming format names from scipy.sparse (e.g. 'lil','dia') exist in JAX; passing the class object; case mismatch.","solutions":["Use one of the exact lowercase strings: 'bcsr','bcoo','coo','csr','csc'","If you have a class, pass its name: sparse_format=BCOO.__name__.lower() or dispatch via a format map yourself"],"exampleFix":"// before\nm = sparse.empty((4,4), sparse_format='lil')\n// after\nm = sparse.empty((4,4), sparse_format='coo')","handlingStrategy":"validation","validationCode":"VALID = {'bcsr','bcoo','coo','csr','csc'}\nassert sparse_format.lower() in VALID, f'unknown format {sparse_format}'","typeGuard":"def is_valid_sparse_format(fmt: str) -> bool:\n    return fmt.lower() in {'bcsr','bcoo','coo','csr','csc'}","tryCatchPattern":"try:\n    m = sparse.empty(shape, sparse_format=fmt)\nexcept ValueError as e:\n    fmt = 'coo'; m = sparse.empty(shape, sparse_format=fmt)","preventionTips":["Use lowercase format strings from the docs","Keep format names in one constant in your codebase"],"tags":["jax","sparse","argument-validation","format-string"],"backgroundTag":"invalid-argument-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}