Skip to content

feat/intensity alignment - #414

Merged
lpatiny merged 9 commits into
mainfrom
feat/intensity-alignment
Sep 10, 2026
Merged

feat/intensity alignment#414
lpatiny merged 9 commits into
mainfrom
feat/intensity-alignment

Conversation

@lpatiny

@lpatiny lpatiny commented Sep 10, 2026

Copy link
Copy Markdown
Member
  • feat: add xysFilter
  • feat: add xyArrayMaxY
  • feat: add xyArrayAlignByIntensity
  • feat: add isLittleEndian
  • feat: add xGetSortOrder and xGetApproximateSortOrder
  • feat: add xDoubleTypedArrayLength
  • feat: add xyArrayAlignByIntensity and xyArrayMergeByIntensity
  • chore: add a benchmark for the shapes xGetSortOrder can order
  • perf: order xySortX and xyObjectSortX through xGetSortOrder

lpatiny and others added 9 commits September 9, 2026 16:39
Radix sort over the bits of each double, so the cost is a fixed number of
linear passes instead of n log n comparisons. Measured against a comparator
sort of an index array (benchmark.js, minSamples 30, random doubles, ns per
element, node 26):

          n   comparator   xGetSortOrder   xGetApproximateSortOrder
         50         69.8     78.8 (0.9x)                46.3 (1.5x)
       1000        122.5     25.4 (4.8x)                13.9 (8.8x)
     100000        230.9     24.0 (9.6x)                 9.3 (24.8x)
    1000000        290.4     23.0 (12.6x)                9.6 (30.3x)

xGetSortOrder keys on all 64 bits and orders exactly, NaN, infinities,
subnormals and the two zeros included. xGetApproximateSortOrder keys on the
high word only, halving the passes, and orders to 20 bits of relative
precision. The digit is 8 bits below 65536 values and 16 above, which keeps
the O(radix) counting pass from dominating short arrays.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A typed array cannot be resized, so a buffer of unknown size has to allocate a
longer one and copy into it. Doubling keeps the total cost of filling it linear,
and an empty array becomes one element long so that doubling makes progress.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Align and merge centroided spectra around the most intense peaks: the strongest
peak of the whole set opens a slot and takes every peak within delta of it, the
strongest of the rest opens the next, and so on. A slot therefore never grows
wider than 2 * delta, where a chain of close neighbours can. Merge keeps only the
common peaks, so it scales where the dense alignment matrix does not.

mergeSortedXY picks its strategy from the number of spectra: a binary heap costs
O(log k) per point, ordering the concatenated points costs the same whatever k is,
and the two meet at thirty spectra (benchmark/mergeSortedXY.ts, 2M points,
ns per point):

  spectra      heap   sorting
        5      13.6      23.2
       15      21.1      23.8
       30      25.9      23.9
      100      33.1      21.7
     1000      55.3      22.1
     5000      67.8      23.4

30000 spectra of 1000 peaks merge into 7141 slots in 2.1s.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
node 26 / bun 1.3, ns per point at n = 1M: permuting x and y 555 -> 29,
ordering points 445 -> 28, the nth largest y 70 -> 24, sorted values 70 -> 20.
ns per point on node, from n = 1000 to n = 1M: xySortX 118 -> 41 and
555 -> 29, xyObjectSortX 102 -> 42 and 445 -> 28. Below 256 values the
comparator still wins, so it stays.
@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.67%. Comparing base (bd7a5ca) to head (502f73e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #414      +/-   ##
==========================================
+ Coverage   97.45%   97.67%   +0.22%     
==========================================
  Files         216      229      +13     
  Lines        4362     4784     +422     
  Branches     1102     1168      +66     
==========================================
+ Hits         4251     4673     +422     
  Misses        108      108              
  Partials        3        3              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lpatiny
lpatiny merged commit 9c744b6 into main Sep 10, 2026
10 checks passed
@lpatiny
lpatiny deleted the feat/intensity-alignment branch September 10, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant