diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d28011b..68d9c54 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,7 @@ jobs: - name: Install dev dependencies run: | python -m pip install --upgrade pip + pip install "numpy<2.5.0" pip install -e ".[dev]" - name: ruff check @@ -60,6 +61,7 @@ jobs: - name: Install package run: | python -m pip install --upgrade pip + pip install "numpy<2.5.0" pip install -e ".[dev]" - name: Run tests diff --git a/snapvec/_index.py b/snapvec/_index.py index fdc793e..b4c95f9 100644 --- a/snapvec/_index.py +++ b/snapvec/_index.py @@ -303,7 +303,8 @@ def add_batch(self, ids: list[Any], vectors: NDArray[np.float32]) -> None: reconstructed: NDArray[np.float32] = self._centroids[batch_idx] r_scaled: NDArray[np.float32] = scaled - reconstructed # sign(S·r_rot) = sign(S·r_scaled) — scale-invariant - S_r: NDArray[np.float32] = (self._S @ r_scaled.T).T + # Optimized: r_scaled @ S.T is faster and avoids intermediate F-contiguous views + S_r: NDArray[np.float32] = r_scaled @ self._S.T qjl_signs = np.sign(S_r).astype(np.int8) qjl_signs[qjl_signs == 0] = 1 # Store ‖r_rot‖ = ‖r_scaled‖/√pdim (unscaled space norm)