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
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@
## 2026-07-13 - Array.from mapping optimization
**Learning:** Using `Array.from({ length: N }).map(...)` creates an intermediate array of `undefined` values which requires memory allocation and garbage collection, adding O(N) unnecessary overhead in frequently re-rendered UI components.
**Action:** Use `Array.from({ length: N }, (_, index) => ...)` to map elements directly during array creation, avoiding intermediate allocations.
## 2024-05-20 - [Performance Optimization] Vectorizing diagonal patch extraction in Checkerboard Novelty Kernel
**Learning:** When performing windowed operations strictly along the diagonal of large matrices in Python/NumPy, using Python array slicing loops incurs linear time constant overhead due to inner loop array allocation and summation.
**Action:** Use sub-matrix diagonal vectorization (`numpy.lib.stride_tricks.sliding_window_view` coupled with `np.diagonal` and `np.einsum`) instead of nested Python loops to shift heavy computations to fast C-level operations.
32 changes: 3 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,11 @@ def _checkerboard_novelty_reference(
kernel[half:, half:] = 1.0

# Sum each checkerboard offset across all valid diagonal windows at once.
valid = novelty[half : n - half]
for di in range(-half, half):
for dj in range(-half, half):
value = kernel[di + half, dj + half]
diagonal = np.diagonal(ssm[half + di : n - half + di, half + dj : n - half + dj])
if value > 0:
valid += diagonal
else:
valid -= diagonal
# Uses sliding_window_view and einsum to avoid nested python loops and
# minimize array allocation overhead.
windows = np.lib.stride_tricks.sliding_window_view(ssm, (kernel_size, kernel_size))
diag_windows = np.diagonal(windows, axis1=0, axis2=1)[:, :, : n - 2 * half]
novelty[half : n - half] = np.einsum("ijk,ij->k", diag_windows, kernel)

# Normalize by peak absolute magnitude, preserving sign.
max_val = np.max(np.abs(novelty))
Expand Down
Loading