Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@
## 2026-08-04 - Matrix-vector reductions for MMLE quadrature nodes
**Learning:** In the NumPy MMLE reference fallback, expressions such as `(resid * nodes[None, :]).sum(axis=1)` materialize an item-by-node intermediate array. The mathematically equivalent matrix-vector product `resid @ nodes` avoids that broadcast temporary and can use the configured NumPy linear-algebra backend. Runtime gains depend on matrix shape, memory layout, BLAS implementation, and threading, so no universal percentage improvement should be claimed without a reproducible benchmark.
**Action:** Prefer a matrix-vector product for equivalent quadrature-node reductions when dtype, shape, and numerical parity are preserved. Keep Rust as the primary production path, retain the NumPy implementation as a tested reference fallback, and benchmark representative workloads before making quantitative performance claims.

## 2024-08-09 - Avoid einsum for large multi-dimensional tensor broadcasting in MMLE Expected Counts
**Learning:** In MMLE E-steps (`_e_step` and `_accumulate_expected_counts` in `marginal.py`), using `np.einsum("pi,piqx->pqx", ...)` or `np.einsum("pi,piqx->iqx", ...)` over advanced-indexed large 4D tensors (e.g. allocating `(Ps, I, Qt, Nx)`) creates enormous memory allocation and massive loop execution overhead for large N and J. Even with `optimize=True`, `einsum` cannot bypass the intermediate O(N*J*D) object broadcast.
**Action:** Do not use `np.einsum` for accumulating expectations. Instead, slice by the categorical dimension (e.g., `factor_id = d`), mask valid items and subjects, flatten the multidimensional arrays to 2D using `.reshape(-1, Qt*Nx)`, and perform high-performance dense BLAS matrix multiplication (`@`). This transforms a 1.5s+ operation into an ~0.02s operation (a 90x+ speedup) with no loss of precision.
Loading
Loading