{"record":{"id":"5ff67086ad436334","repo":"jax-ml/jax","slug":"the-limits-of-integration-in-integrate-box-1d-must","errorCode":null,"errorMessage":"the limits of integration in integrate_box_1d must be scalars","messagePattern":"the limits of integration in integrate_box_1d must be scalars","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/stats/kde.py","lineNumber":164,"sourceCode":"\n    if mean.shape != (self.d,):\n      raise ValueError(f\"mean does not have dimension {self.d}\")\n    if cov.shape != (self.d, self.d):\n      raise ValueError(f\"covariance does not have dimension {self.d}\")\n\n    chol = linalg.cho_factor(self.covariance + cov)\n    norm = jnp.sqrt(2 * np.pi)**self.d * jnp.prod(jnp.diag(chol[0]))\n    norm = 1.0 / norm\n    return _gaussian_kernel_convolve(chol, norm, self.dataset, self.weights,\n                                     mean)\n\n  @api.jit\n  def integrate_box_1d(self, low, high):\n    \"\"\"Integrate the distribution over the given limits.\"\"\"\n    if self.d != 1:\n      raise ValueError(\"integrate_box_1d() only handles 1D pdfs\")\n    if np.ndim(low) != 0 or np.ndim(high) != 0:\n      raise ValueError(\n          \"the limits of integration in integrate_box_1d must be scalars\")\n    sigma = jnp.squeeze(jnp.sqrt(self.covariance))\n    low = jnp.squeeze((low - self.dataset) / sigma)\n    high = jnp.squeeze((high - self.dataset) / sigma)\n    return jnp.sum(self.weights * (special.ndtr(high) - special.ndtr(low)))\n\n  def integrate_kde(self, other):\n    \"\"\"Integrate the product of two Gaussian KDE distributions.\"\"\"\n    if other.d != self.d:\n      raise ValueError(\"KDEs are not the same dimensionality\")\n\n    chol = linalg.cho_factor(self.covariance + other.covariance)\n    norm = jnp.sqrt(2 * np.pi)**self.d * jnp.prod(jnp.diag(chol[0]))\n    norm = 1.0 / norm\n\n    sm, lg = (self, other) if self.n < other.n else (other, self)\n    result = api.vmap(partial(_gaussian_kernel_convolve, chol, norm, lg.dataset,\n                              lg.weights),","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/stats/kde.py#L146-L182","documentation":"integrate_box_1d requires low and high to be scalar (np.ndim == 0). Passing arrays, lists, or length-1 arrays as integration limits raises this error, since the method computes elementwise (low - dataset)/sigma and needs a single pair of bounds.","triggerScenarios":"kde.integrate_box_1d(jnp.array([0.0]), 1.0), or passing arrays of bounds hoping for batched integrals.","commonSituations":"Limits coming from a config array or a previous computation that returns shape (1,) tensors; trying to vectorize box integrals over many interval pairs.","solutions":["Extract scalars: float(low), float(high), or low.item() if tracing is not required","Use jax.vmap over scalar-bound calls for many intervals","Squeeze shape-(1,) bounds with jnp.squeeze before calling"],"exampleFix":"// before\np = kde.integrate_box_1d(bounds[0], bounds[1])  # bounds[i].shape == (1,)\n// after\np = kde.integrate_box_1d(jnp.squeeze(bounds[0]), jnp.squeeze(bounds[1]))","handlingStrategy":"validation","validationCode":"import numpy as np\nassert np.ndim(low) == 0 and np.ndim(high) == 0","typeGuard":"def scalar_bounds(low, high) -> bool:\n    return np.ndim(low) == 0 and np.ndim(high) == 0","tryCatchPattern":null,"preventionTips":["Squeeze shape-(1,) tensors from upstream math","Use vmap over scalar-bound calls for many intervals","Keep integration bounds as Python floats in config"],"tags":["jax","scipy","kde","scalar-validation"],"backgroundTag":"invalid-argument-shape","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}