{"record":{"id":"69b37aec206664e7","repo":"jax-ml/jax","slug":"hankel-r-must-be-at-least-1-dimensional-got-a-sc","errorCode":null,"errorMessage":"hankel: r must be at least 1-dimensional, got a scalar.","messagePattern":"hankel: r must be at least 1-dimensional, got a scalar\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/linalg.py","lineNumber":2549,"sourceCode":"    >>> jax.scipy.linalg.hankel(c, r)\n    Array([[1, 2, 3, 4],\n           [2, 3, 4, 5],\n           [3, 4, 5, 6]], dtype=int32)\n\n    For N-dimensional ``c`` and/or ``r``, the result is a batch of Hankel matrices.\n  \"\"\"\n  if r is None:\n    check_arraylike(\"hankel\", c)\n    c = jnp.asarray(c)\n    r = jnp.zeros_like(c)\n  else:\n    check_arraylike(\"hankel\", c, r)\n    c = jnp.asarray(c)\n    r = jnp.asarray(r)\n  if c.ndim == 0:\n    raise ValueError(\"hankel: c must be at least 1-dimensional, got a scalar.\")\n  if r.ndim == 0:\n    raise ValueError(\"hankel: r must be at least 1-dimensional, got a scalar.\")\n\n  # Align batch ranks so jnp.vectorize doesn't need implicit rank promotion.\n  if c.ndim < r.ndim:\n    c = lax.expand_dims(c, range(r.ndim - c.ndim))\n  elif r.ndim < c.ndim:\n    r = lax.expand_dims(r, range(c.ndim - r.ndim))\n\n  return _hankel(c, r)\n\n@partial(jnp_vectorize.vectorize, signature=\"(m),(n)->(m,n)\")\ndef _hankel(c: Array, r: Array) -> Array:\n  ncols, = c.shape\n  nrows, = r.shape\n  if ncols == 0 or nrows == 0:\n    return jnp.empty((ncols, nrows), dtype=jnp.result_type(c, r))\n  v = jnp.concatenate((c, r[1:]))\n  return lax.conv_general_dilated_patches(\n      v.reshape((1, ncols + nrows - 1, 1)),","sourceCodeStart":2531,"sourceCodeEnd":2567,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/linalg.py#L2531-L2567","documentation":"The companion check to error 3390: the optional last-row argument r to hankel must also be at least 1-D. Since hankel(c, r) requires r explicitly to reach this branch, the ValueError fires only for explicitly passed scalar r.","triggerScenarios":"Calling hankel(c, 0) or hankel(c, jnp.asarray(2)) with a valid vector c but 0-d r.","commonSituations":"Passing a scalar 'fill' value for r by analogy with other APIs (e.g. toeplitz-style defaults); variables collapsed to scalars by earlier computation.","solutions":["Pass r as a 1-D array: hankel(c, [r0, r1, ...])","Use r=None (omitted) to let r default to zeros_like(c)","Validate r.ndim >= 1 when r is user-supplied"],"exampleFix":"# before\nH = hankel(c, 5)\n# after\nH = hankel(c, [5, 0, 0])","handlingStrategy":"validation","validationCode":"if r is not None:\n    r = jnp.asarray(r)\n    if r.ndim == 0:\n        r = r.reshape(1)\nH = hankel(c, r)","typeGuard":"def is_at_least_1d(x) -> bool:\n    return jnp.asarray(x).ndim >= 1","tryCatchPattern":"try:\n    hankel(c, r)\nexcept ValueError as e:\n    if 'r must be at least 1-dimensional' in str(e):\n        r = jnp.atleast_1d(r); hankel(c, r)\n    else: raise","preventionTips":["Omit r (pass None) to use the zeros default instead of a scalar fill","Document that r is a vector of row-tail values, not a fill constant","atleast_1d all optional sequence-like parameters"],"tags":["jax","hankel","input-validation","shape-error"],"backgroundTag":"expected-ndim-array","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}