{"record":{"id":"27053fdd562bae39","repo":"jax-ml/jax","slug":"points-have-dimension-dataset-has-dimension","errorCode":null,"errorMessage":"points have dimension {}, dataset has dimension {}","messagePattern":"points have dimension (.+?), dataset has dimension (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/stats/kde.py","lineNumber":242,"sourceCode":"        \"only 1D box integrations are supported; use `integrate_box_1d`\")\n\n  def set_bandwidth(self, bw_method=None):\n    \"\"\"This method is not implemented in the JAX interface.\"\"\"\n    del bw_method\n    raise NotImplementedError(\n        \"dynamically changing the bandwidth method is not supported\")\n\n  def _reshape_points(self, points):\n    if dtypes.issubdtype(lax.dtype(points), np.complexfloating):\n      raise NotImplementedError(\n          \"gaussian_kde does not support complex coordinates\")\n    points = jnp.atleast_2d(points)\n    d, m = points.shape\n    if d != self.d:\n      if d == 1 and m == self.d:\n        points = jnp.reshape(points, (self.d, 1))\n      else:\n        raise ValueError(\n            \"points have dimension {}, dataset has dimension {}\".format(\n                d, self.d))\n    return points\n\n\ndef _gaussian_kernel_convolve(chol, norm, target, weights, mean):\n  diff = target - mean[:, None]\n  alpha = linalg.cho_solve(chol, diff)\n  arg = 0.5 * jnp.sum(diff * alpha, axis=0)\n  return norm * jnp.sum(jnp.exp(-arg) * weights)\n\n\n@api.jit(static_argnums=0)\ndef _gaussian_kernel_eval(in_log, points, values, xi, precision):\n  points, values, xi, precision = promote_dtypes_inexact(\n      points, values, xi, precision)\n  d = points.shape[1]\n","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/stats/kde.py#L224-L260","documentation":"When evaluating a gaussian_kde, points are atleast_2d'd and their leading dimension must equal the KDE dimensionality self.d. A convenience case reshapes a single point given as a d-length row vector; any other mismatch (e.g. m points supplied as (m, d) instead of (d, m)) raises this error.","triggerScenarios":"Calling kde.evaluate(X) with X.shape == (n_points, d) instead of (d, n_points); passing a single point of shape (d,) is fine, but (n_points,) with n_points != d fails.","commonSituations":"Feeding machine-learning-style (samples, features) arrays directly; the KDE stores dataset as (d, n) via atleast_2d so users must transpose their points.","solutions":["Transpose the query points: kde.evaluate(X.T)","For a single point pass a flat d-vector: kde.evaluate(p) with p.shape == (d,)","Check d with kde.d and shape points accordingly"],"exampleFix":"// before\n dens = kde.evaluate(X)  # X.shape == (N, d)\n// after\ndens = kde.evaluate(X.T)  # (d, N)","handlingStrategy":"validation","validationCode":"pts = jnp.asarray(points)\nif pts.ndim == 2 and pts.shape[0] != kde.d:\n    pts = pts.T  # assume (N, d) input\nassert pts.shape[0] == kde.d","typeGuard":"def points_oriented_for_kde(points, kde) -> bool:\n    p = jnp.atleast_2d(jnp.asarray(points))\n    return p.shape[0] == kde.d or (p.shape[0] == 1 and p.shape[1] == kde.d)","tryCatchPattern":null,"preventionTips":["Standardize on (d, N) layout for KDE queries","Transpose ML-style (N, d) arrays at the boundary","Write a small evaluate wrapper that fixes orientation"],"tags":["jax","scipy","kde","shape-validation","dimension-mismatch"],"backgroundTag":"invalid-array-shape","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}