@wafertools/wafermap 0.37.0 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/CHANGELOG.md +81 -1
  2. package/README.md +20 -13
  3. package/dist/packages/canvas-adapter/chartPopulation.d.ts +8 -3
  4. package/dist/packages/canvas-adapter/chartPopulation.js +1 -1
  5. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +27 -17
  6. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/patCard.d.ts +2 -0
  8. package/dist/packages/canvas-adapter/charts/patCard.js +1 -1
  9. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +0 -7
  10. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  11. package/dist/packages/canvas-adapter/drilldown.d.ts +5 -0
  12. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  13. package/dist/packages/canvas-adapter/index.d.ts +1 -0
  14. package/dist/packages/canvas-adapter/index.js +1 -1
  15. package/dist/packages/canvas-adapter/insightsTab.d.ts +2 -0
  16. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  17. package/dist/packages/canvas-adapter/patMode.d.ts +27 -0
  18. package/dist/packages/canvas-adapter/patMode.js +1 -0
  19. package/dist/packages/canvas-adapter/pinnedTests.d.ts +10 -0
  20. package/dist/packages/canvas-adapter/pinnedTests.js +1 -0
  21. package/dist/packages/canvas-adapter/plotCard.d.ts +1 -1
  22. package/dist/packages/canvas-adapter/plotCard.js +1 -1
  23. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  24. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  25. package/dist/packages/canvas-adapter/summaryPanel.d.ts +3 -3
  26. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  27. package/dist/packages/canvas-adapter/toolbar.d.ts +7 -4
  28. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  29. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  30. package/dist/packages/canvas-adapter/userGuideHtml.js +72 -92
  31. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  32. package/dist/packages/canvas-adapter/version.js +1 -1
  33. package/dist/packages/canvas-adapter/viewSwitch.js +1 -1
  34. package/dist/packages/renderer/buildWaferMap.js +1 -1
  35. package/dist/packages/renderer/derivedTests/apply.d.ts +10 -0
  36. package/dist/packages/renderer/derivedTests/apply.js +1 -1
  37. package/dist/packages/renderer/derivedTests/check.d.ts +35 -0
  38. package/dist/packages/renderer/derivedTests/check.js +1 -0
  39. package/dist/packages/renderer/fmt.d.ts +5 -0
  40. package/dist/packages/renderer/fmt.js +1 -1
  41. package/dist/packages/renderer/index.d.ts +2 -0
  42. package/dist/packages/renderer/index.js +1 -1
  43. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  44. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  45. package/dist/packages/stats/chartCatalogue.js +1 -1
  46. package/dist/packages/stats/clusterDetection.js +1 -1
  47. package/dist/packages/stats/groupCompare.d.ts +1 -1
  48. package/dist/packages/stats/groupCompare.js +1 -1
  49. package/dist/packages/stats/pat.js +1 -1
  50. package/dist/packages/stats/plotData.d.ts +7 -0
  51. package/dist/packages/stats/plotData.js +1 -1
  52. package/dist/packages/stats/reportHtml.js +33 -29
  53. package/dist/packages/stats/synthesis.d.ts +1 -1
  54. package/dist/packages/stats/synthesis.js +1 -1
  55. package/package.json +16 -5
  56. package/dist/packages/canvas-adapter/patMaps.d.ts +0 -26
  57. package/dist/packages/canvas-adapter/patMaps.js +0 -1
@@ -72,7 +72,7 @@ export const USER_GUIDE_HTML=`<div class="wmap-guide">
72
72
  .wmap-guide-toc{display:none!important}
73
73
  }
74
74
  </style>
75
- <h1 id="wmap-wafer-map-user-guide">Wafer Map \u2014 User Guide<span class="wmap-guide-version" title="Built 2026-10-20T13:40:50.345Z">v0.37.0</span></h1>
75
+ <h1 id="wmap-wafer-map-user-guide">Wafer Map \u2014 User Guide<span class="wmap-guide-version" title="Built 2026-10-28T17:57:47.014Z">v0.38.0</span></h1>
76
76
  <p class="wmap-guide-online-link">This is a quick reference. <a href="https://wafertools.github.io/wafermap/user-guide/" target="_blank" rel="noopener">View the full illustrated guide online \u2197</a></p>
77
77
  <p>This guide describes the display and analysis features of the wafer map viewer.
78
78
  It is written for users who may be semiconductor test engineers, device engineers, and yield engineers
@@ -130,26 +130,26 @@ there; <strong>Reset orientation</strong> leaves it as it is.</p>
130
130
  <p>A no-data die is not a fail; it simply has no result recorded. Edge-excluded dies are shown dimmed and are
131
131
  not counted in yield calculations. Dies the filter drops are drawn faded and are counted nowhere: not in the legend, the
132
132
  yield, the Summary panel or the findings.</p>
133
- <h3 id="wmap-legend-and-colorbar">1.4 Legend and colorbar</h3>
133
+ <h3 id="wmap-legend-and-colour-bar">1.4 Legend and colour bar</h3>
134
134
  <p><strong>Bin modes</strong> show a discrete colour legend: one swatch per bin, with bin number
135
135
  and name if the application has supplied bin names. Passing bins are listed first,
136
136
  then failing bins from the most dies to the fewest \u2014 the same order as the Summary
137
137
  panel and reports.</p>
138
- <p><strong>Value mode</strong> shows a continuous colorbar: the colour scale runs from the minimum
139
- to maximum value, with units when available. The colorbar is informational only \u2014
138
+ <p><strong>Value mode</strong> shows a continuous colour bar: the colour scale runs from the minimum
139
+ to maximum value, with units when available. The colour bar is informational only \u2014
140
140
  clicking it has no effect. To switch to a pass/fail view, use the <strong>Limit pass/fail</strong>
141
141
  or <strong>Test pass/fail</strong> option in the Overlays menu (available when test limits are
142
142
  defined, or a recorded verdict exists, for the active test).</p>
143
- <p><strong>Limit pass/fail mode</strong> replaces the colorbar with a small legend: Pass,
143
+ <p><strong>Limit pass/fail mode</strong> replaces the colour bar with a small legend: Pass,
144
144
  Fail high, and Fail low swatches (only the categories that apply to the test&#39;s
145
145
  limits) with a die count beside each. This judges dies against the test&#39;s lower
146
146
  and upper test limits.</p>
147
- <p><strong>Test pass/fail mode</strong> replaces the colorbar with a <strong>Pass / Fail legend</strong> and die
147
+ <p><strong>Test pass/fail mode</strong> replaces the colour bar with a <strong>Pass / Fail legend</strong> and die
148
148
  counts, coloured by the tester&#39;s own <strong>recorded</strong> verdict for that test \u2014 not a
149
149
  limit judgement. A test with no measured value (a functional, go/no-go test)
150
150
  always displays this way; selecting it switches the map into Test pass/fail
151
151
  automatically, since there is nothing to plot on a gradient.</p>
152
- <p>Every map also shows a short <strong>title</strong> by the colorbar or legend naming what is
152
+ <p>Every map also shows a short <strong>title</strong> by the colour bar or legend naming what is
153
153
  displayed \u2014 the test name (and number, in limit pass/fail mode), the bin type, or the stacked
154
154
  wafer count.</p>
155
155
  <p>Clicking a bin swatch in the legend filters the display to that bin: every other bin is
@@ -207,6 +207,11 @@ application has loaded.</p>
207
207
  <td>Parametric heatmap \u2014 leakage, Idsat, Vth, etc.</td>
208
208
  </tr>
209
209
  <tr>
210
+ <td><strong>PAT verdict</strong></td>
211
+ <td>Part average testing verdict of the die (within, outlier, fails)</td>
212
+ <td>Where the PAT outliers are, wafer by wafer</td>
213
+ </tr>
214
+ <tr>
210
215
  <td><strong>Stacked Hard Bins</strong></td>
211
216
  <td>Hard bin occurrence counts aggregated across multiple wafers</td>
212
217
  <td>Lot-level yield patterns</td>
@@ -225,12 +230,12 @@ application has loaded.</p>
225
230
  <p>Stacked modes are only available on lot-stack maps (multiple wafers combined into
226
231
  one display). The panel identifies how many wafers were stacked and which
227
232
  aggregation method is active.</p>
228
- <h3 id="wmap-test-value-mode-colorbar-range-and-test-limits">Test Value mode \u2014 colorbar range and test limits</h3>
233
+ <h3 id="wmap-test-value-mode-colour-bar-range-and-test-limits">Test Value mode \u2014 colour bar range and test limits</h3>
229
234
  <p>When test limits are defined for the active test, two additional display options
230
235
  become available:</p>
231
236
  <ul>
232
- <li><strong>Colorbar range \u2014 Data / Limits</strong>: switches the colorbar scale between the
233
- actual data extent and the test limits. This affects only the colorbar&#39;s
237
+ <li><strong>Colour bar range \u2014 Data / Limits</strong>: switches the colour bar scale between the
238
+ actual data extent and the test limits. This affects only the colour bar&#39;s
234
239
  range, never how failing dies are shown. In <strong>both</strong> ranges every die is
235
240
  coloured by the gradient so you can read the value distribution, and dies
236
241
  outside the test limits are marked with a triangle \u2014 pointing <strong>down (\u25BD) for below the low limit</strong>, <strong>up (\u25B3)
@@ -244,7 +249,7 @@ in</strong>; zoom in and they appear.</li>
244
249
  a pass colour and dies outside them are highlighted \u2014 <strong>blue for below the
245
250
  low limit</strong>, <strong>red for above the high limit</strong>. Both flags apply
246
251
  independently; a die can be flagged on either or both limits. A Pass/Fail legend
247
- replaces the colorbar, listing each applicable category with its die count.</li>
252
+ replaces the colour bar, listing each applicable category with its die count.</li>
248
253
  </ul>
249
254
  <p>Some tests have no measured value at all \u2014 a continuity check or any other
250
255
  go/no-go test, where the only result is a recorded pass or fail. Selecting one
@@ -315,8 +320,8 @@ shows die tooltips \u2014 a separate thing from the toolbar, which is always pre
315
320
  </tr>
316
321
  <tr>
317
322
  <td><img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBmaWxsPSJub25lIiBzdHJva2U9IiMzNzQxNTEiIHN0cm9rZS13aWR0aD0iMS44IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjxwYXRoIGQ9Ik01IDQgTDUgMjAiLz48cGF0aCBkPSJNNSA0IEw4IDQiLz48cGF0aCBkPSJNNSAyMCBMOCAyMCIvPjxwYXRoIGQ9Ik0xOSA0IEwxOSAyMCIvPjxwYXRoIGQ9Ik0xOSA0IEwxNiA0Ii8+PHBhdGggZD0iTTE5IDIwIEwxNiAyMCIvPjxwYXRoIGQ9Ik01IDEyIEwxOSAxMiIgc3Ryb2tlLWRhc2hhcnJheT0iMyAyIi8+PC9zdmc+Cg==" width="20" height="20"></td>
318
- <td>Colorbar range</td>
319
- <td>Test Value mode with test limits only. Toggles the colorbar between the <strong>limit range</strong> (default \u2014 the colours mean the same thing on every wafer, so maps are comparable) and the <strong>data range</strong> (stretches the scale to the values actually present, which shows more contrast but is not comparable between wafers).</td>
323
+ <td>Colour bar range</td>
324
+ <td>Test Value mode with test limits only. Toggles the colour bar between the <strong>limit range</strong> (default \u2014 the colours mean the same thing on every wafer, so maps are comparable) and the <strong>data range</strong> (stretches the scale to the values actually present, which shows more contrast but is not comparable between wafers).</td>
320
325
  </tr>
321
326
  <tr>
322
327
  <td><img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBmaWxsPSJub25lIiBzdHJva2U9IiMzNzQxNTEiIHN0cm9rZS13aWR0aD0iMS44IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjciIHg9IjMiIHk9IjMiIHJ4PSIxIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iNyIgeD0iMyIgeT0iMTQiIHJ4PSIxIi8+PHBhdGggZD0iTTE0IDRoNyIvPjxwYXRoIGQ9Ik0xNCA5aDciLz48cGF0aCBkPSJNMTQgMTVoNyIvPjxwYXRoIGQ9Ik0xNCAyMGg3Ii8+PC9zdmc+Cg==" width="20" height="20"></td>
@@ -495,6 +500,10 @@ it as a file and send it to whoever supports this software.</p>
495
500
  <td><strong>Space (hold) + drag</strong></td>
496
501
  <td>Temporarily pan without leaving the current tool</td>
497
502
  </tr>
503
+ <tr>
504
+ <td><strong>1</strong> to <strong>5</strong>, <strong>0</strong></td>
505
+ <td>Over a gallery (or with focus in it) or on the Insights tab: set that many columns of cards; over a plot of panels: that plot&#39;s columns. <strong>0</strong> is Auto (same as the Columns control)</td>
506
+ </tr>
498
507
  </tbody></table>
499
508
  <h3 id="wmap-gallery">Gallery</h3>
500
509
  <p>The gallery control bar applies to all cards simultaneously.</p>
@@ -529,7 +538,7 @@ it as a file and send it to whoever supports this software.</p>
529
538
  <tr>
530
539
  <td><img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBmaWxsPSJub25lIiBzdHJva2U9IiMzNzQxNTEiIHN0cm9rZS13aWR0aD0iMS44IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPgogIDxyZWN0IHg9IjMiIHk9IjMiIHdpZHRoPSI0IiBoZWlnaHQ9IjE4IiByeD0iMSIvPgogIDxyZWN0IHg9IjEwIiB5PSIzIiB3aWR0aD0iNCIgaGVpZ2h0PSIxOCIgcng9IjEiLz4KICA8cmVjdCB4PSIxNyIgeT0iMyIgd2lkdGg9IjQiIGhlaWdodD0iMTgiIHJ4PSIxIi8+Cjwvc3ZnPgo=" width="20" height="20"></td>
531
540
  <td>Columns</td>
532
- <td>Sets the number of columns. <strong>Auto</strong> fits as many cards as stay readable; a number divides the full width between that many columns.</td>
541
+ <td>Sets the number of columns, or press <strong>1</strong> to <strong>5</strong>, or <strong>0</strong> for Auto, while the pointer is over the gallery or focus is in it. <strong>Auto</strong> fits as many cards as keep each die at least 6 px across, so a dense wafer gets a wider card and a window that cannot hold another column at that width keeps the columns it has; a number divides the full width between that many columns.</td>
533
542
  </tr>
534
543
  <tr>
535
544
  <td><img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBmaWxsPSJub25lIiBzdHJva2U9IiMzNzQxNTEiIHN0cm9rZS13aWR0aD0iMS44IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjxwYXRoIGQ9Ik01IDNhMiAyIDAgMCAwLTIgMiIvPjxwYXRoIGQ9Ik0xOSAzYTIgMiAwIDAgMSAyIDIiLz48cGF0aCBkPSJNMjEgMTlhMiAyIDAgMCAxLTIgMiIvPjxwYXRoIGQ9Ik01IDIxYTIgMiAwIDAgMS0yLTIiLz48cGF0aCBkPSJNOSAzaDEiLz48cGF0aCBkPSJNOSAyMWgxIi8+PHBhdGggZD0iTTE0IDNoMSIvPjxwYXRoIGQ9Ik0xNCAyMWgxIi8+PHBhdGggZD0iTTMgOXYxIi8+PHBhdGggZD0iTTIxIDl2MSIvPjxwYXRoIGQ9Ik0zIDE0djEiLz48cGF0aCBkPSJNMjEgMTR2MSIvPjwvc3ZnPgo=" width="20" height="20"></td>
@@ -558,7 +567,7 @@ it as a file and send it to whoever supports this software.</p>
558
567
  </tr>
559
568
  <tr>
560
569
  <td><img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBmaWxsPSJub25lIiBzdHJva2U9IiMzNzQxNTEiIHN0cm9rZS13aWR0aD0iMS44IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjxwYXRoIGQ9Ik01IDQgTDUgMjAiLz48cGF0aCBkPSJNNSA0IEw4IDQiLz48cGF0aCBkPSJNNSAyMCBMOCAyMCIvPjxwYXRoIGQ9Ik0xOSA0IEwxOSAyMCIvPjxwYXRoIGQ9Ik0xOSA0IEwxNiA0Ii8+PHBhdGggZD0iTTE5IDIwIEwxNiAyMCIvPjxwYXRoIGQ9Ik01IDEyIEwxOSAxMiIgc3Ryb2tlLWRhc2hhcnJheT0iMyAyIi8+PC9zdmc+Cg==" width="20" height="20"></td>
561
- <td>Colorbar range</td>
570
+ <td>Colour bar range</td>
562
571
  <td>Test Value mode with test limits only. Toggles all cards between the limit range and the data range. Leave it on the test limits when comparing wafers \u2014 the data range rescales per view.</td>
563
572
  </tr>
564
573
  <tr>
@@ -699,7 +708,11 @@ cluster, a scratch or an edge region on its own, or at one wafer out of a lot.</
699
708
  <ul>
700
709
  <li><strong>Selected dies</strong> \u2014 select some dies, then right-click on the map. Right-
701
710
  clicking a die that is <strong>not</strong> selected selects that die alone first;
702
- right-clicking a selected die, or empty space, keeps the selection.</li>
711
+ right-clicking a selected die, or empty space, keeps the selection. On a single map the menu&#39;s first row, <strong>Invert
712
+ selection</strong>, selects the dies that were not selected and deselects those that were. Below the charts of the selection,
713
+ <strong>Selection vs the rest of the wafer</strong> offers a <strong>Value histogram</strong> (one colour for each side, overlaid) and a <strong>Box plot</strong>
714
+ of the selected dies against the wafer&#39;s other dies, each side labelled with its die count. Partial and edge-excluded dies are
715
+ left out of both, and with fewer than 10 dies on a side the window says to read the spread rather than small differences.</li>
703
716
  <li><strong>Dies selected on several wafers of a gallery</strong> \u2014 by clicking a finding, or by selecting on more than one card.
704
717
  Right-click a selected die on any of those cards and the menu opens on every selected die, with a first row,
705
718
  <strong>Only this wafer</strong>, that narrows it to the dies selected on the card you clicked (and <strong>All selected</strong> to go back).</li>
@@ -1038,6 +1051,11 @@ toolbar. Choose <strong>Maps</strong> to return to the map; the switch stays whe
1038
1051
  sidebar (see <a href="#wmap-summary-panel" onclick="(function(e){e.preventDefault();var g=e.target.closest('.wmap-guide');var el=g&&g.querySelector('[id=\\'wmap-summary-panel\\']');if(el)el.scrollIntoView({behavior:'smooth'});})(event)">Summary panel</a>) \u2014 the two toggle independently, and opening one never
1039
1052
  hides the other&#39;s toolbar button, since Findings has nothing to highlight
1040
1053
  against once the map is replaced.</p>
1054
+ <p>The <a href="https://wafertools.github.io/wafermap/charts/">Chart reference</a> describes every chart, plot and table: what it
1055
+ shows, how to read it, when to reach for it and where to find it. This section covers how the tab works.</p>
1056
+ <p>The <strong>Columns</strong> control beside <strong>Group by</strong> and <strong>Show</strong>, or the keys <strong>1</strong> to <strong>5</strong> (and <strong>0</strong> for Auto), sets how many columns of
1057
+ cards every section of the tab uses. <strong>Auto</strong> fits as many as the width holds at 420 px or more; a number divides the width that many ways,
1058
+ and the choice stays while you move between the tabs.</p>
1041
1059
  <p>Any chart mark that stands for one wafer \u2014 a bar in <em>Yield by wafer</em>, a box in
1042
1060
  <em>Test value distribution</em>, a point in <em>Wafer-to-wafer trend</em> \u2014 can be
1043
1061
  right-clicked to chart that wafer on its own (see
@@ -1046,33 +1064,14 @@ right-clicked to chart that wafer on its own (see
1046
1064
  same numbers as tables (see <em>Data tables</em> below), and a <strong>My plots</strong> sub-tab for your
1047
1065
  own charts and sweeps (see <em>Plots</em> and <em>Sweep cards</em> below):</p>
1048
1066
  <ul>
1049
- <li><p><strong>Overview</strong> \u2014 a <strong>test pass rate</strong> chart showing which test fails most (and,
1050
- with &quot;Group by&quot; active, whether it fails more in one split than another). It
1051
- offers up to three ways of judging, whichever the data supports: <strong>Spec
1052
- limits</strong> (the value against its limits), <strong>Tester flag</strong> (the pass/fail the
1053
- tester itself recorded, which a parametric test carries whether or not limits
1054
- were exported), and <strong>Functional</strong> for pass/fail-only tests. The two
1055
- parametric views can disagree \u2014 guard bands and dynamic limits routinely cause
1056
- it \u2014 so the card reports how many dies the two judged differently rather than
1057
- picking one for you. The tests run down the left, worst first, each with its pass rate at the end; click a test&#39;s
1058
- bar for the dies that fail it. The card is the size of the others whatever the number of tests: more than fit
1059
- scroll, with the scrollbar at its right edge or the mouse wheel over the chart, under a pass-rate axis that stays put. With nothing to judge (no limits, no recorded verdicts) the card is left out. Alongside it, headline tiles stating the population (wafers, dies analysed,
1060
- and for a lot the mean wafer yield \u2014 an <em>unweighted</em> mean of each wafer&#39;s own
1061
- yield, not the die-weighted figure), a yield bar labelled with the pass bins
1062
- actually in use, each bar&#39;s yield at its end and the median of the bars as a line (with Group by on, one bar per
1063
- group, pooled as passing dies over judged dies; click a group&#39;s bar to see its wafers, <strong>Back</strong> to return), a
1064
- hard/soft bin pareto with its cumulative share (with Group by on, a bar per group in each bin, as each group&#39;s share
1065
- of its own dies, so groups of different sizes compare, or as counts), and
1066
- ring/quadrant regional yield, and with a reticle set a <strong>Reticle cell yield</strong> grid: the stepper field drawn as its cells (row 0 at
1067
- the bottom), each filled by the yield of that position pooled over every field on every wafer and labelled with it. Hover a cell
1068
- for its dies, click it to chart or tabulate them. A cell that is low in all of them points at the mask rather than the wafer.</p>
1069
- <p>With four or more wafers and wafer fields to compare (lot, split, date, probe card\u2026), <strong>What divides yield</strong> ranks
1070
- every field by how clearly its groups differ in yield and in the rate of each of the five most common fail bins. Each
1071
- wafer is one value, as in the split comparison, so n is wafers; rows are ranked by q (Welch&#39;s p adjusted for every
1072
- comparison in the table). A row names the worst and best groups with their mean over their wafers and the spread in
1073
- percentage points; <strong>Group by</strong> groups the whole tab by that field. A low q says the groups differ by more than
1074
- wafer-to-wafer noise, not why. The card also names fields it could not compare (every wafer its own value) and fields
1075
- that group the wafers identically, which no ranking can tell apart (a lot and its test date).</p>
1067
+ <li><p><strong>Overview</strong> \u2014 how the lot yielded: headline tiles stating the population, <a href="https://wafertools.github.io/wafermap/charts/#yield-by-wafer">Yield by wafer</a>, <a href="https://wafertools.github.io/wafermap/charts/#bin-pareto">Bin pareto</a>,
1068
+ <a href="https://wafertools.github.io/wafermap/charts/#pass-rate-by-test">Pass rate by test</a>, <a href="https://wafertools.github.io/wafermap/charts/#ring-yield">Ring yield</a> and <a href="https://wafertools.github.io/wafermap/charts/#quadrant-yield">Quadrant yield</a>, and with a reticle set
1069
+ <a href="https://wafertools.github.io/wafermap/charts/#reticle-cell-yield">Reticle cell yield</a>. With four or more wafers and wafer fields to compare, <a href="https://wafertools.github.io/wafermap/charts/#what-divides-yield">What divides yield</a>
1070
+ ranks the fields by how clearly their groups differ; <strong>Group by</strong> on its row groups the whole tab by that field. With
1071
+ Group by on, the yield bar and the pareto draw a bar per group (click a group&#39;s bar to see its wafers, <strong>Back</strong> to return). The
1072
+ pass-rate card offers up to three ways of judging, whichever the data supports: <strong>Spec limits</strong>, <strong>Tester flag</strong> and
1073
+ <strong>Functional</strong>; when the first two disagree it says how many dies they judged differently. The card is the size of the
1074
+ others whatever the number of tests: more than fit scroll. With nothing to judge it is left out.</p>
1076
1075
  </li>
1077
1076
  <li><p><strong>Worth a look</strong>, on the Overview below the yield, bin and region cards \u2014 the same items as
1078
1077
  <strong>What stands out</strong> beside the map, in the same order and words, each drawn as the chart that shows
@@ -1085,37 +1084,21 @@ names), and <strong>Show on map</strong> goes back to the map showing it as its
1085
1084
  open on that row. The rest follow on one &quot;Also&quot; line. It describes the whole lot, so while the Insights
1086
1085
  filter or <strong>Show</strong> narrows the population it says so instead of drawing cards.</p>
1087
1086
  </li>
1088
- <li><p><strong>Distributions</strong> \u2014 process capability (Cp/Cpk/Pp/Ppk for tests with both a
1089
- lower and upper limit \u2014 spec limits where given, otherwise test limits; tests
1090
- without both still appear, normalized
1091
- onto their own range and sorted by variability), a test-value box plot (one box per wafer down the left, or with
1092
- Group by on one per group: click a group&#39;s box to see its wafers, <strong>Back</strong> to return), a value histogram (all wafers,
1093
- one wafer, or one series per group), and a <strong>wafer-to-wafer trend</strong> \u2014 one point per wafer at its mean with a \xB11
1094
- standard deviation band, the mean of all wafers as a line (labelled the &quot;lot mean&quot; when they all come from one lot),
1095
- and the test&#39;s limits; drag across it to pick a run of wafers. The trend is always in slot order, deliberately: drift
1096
- across a cassette only reads in the physical sequence, so there is no sort control to destroy it, and it needs at
1097
- least two wafers. The box plot, histogram and trend are plots: each has the test picker and the axis settings
1098
- (<em>Axis includes limits</em>, <em>Clip outliers</em>, and which limits to draw), and a change in one reaches the others.
1099
- Clicking a capability box drives them onto that same test.</p>
1100
- <p>With <strong>Group by</strong> on, a <strong>Difference map</strong> at the foot of Distributions draws one group minus another at every die
1101
- position, as a wafer map: pick the two groups and a test (it follows the test the other panels show until you pick
1102
- one) or <em>Yield</em>. Each group&#39;s value at a position is its mean over the group&#39;s wafers there (for yield, the share
1103
- of them passing), as its stacked map would show it, and a position either group lacks is grey. The colours run
1104
- symmetrically from the largest negative difference to the largest positive, with zero in the middle. It is drawn on
1105
- the first wafer of the first group&#39;s geometry and orientation, so a die is where it is on every other map; the map
1106
- carries no wafer&#39;s identity, since it is none.</p>
1087
+ <li><p><strong>Distributions</strong> \u2014 how values spread: <a href="https://wafertools.github.io/wafermap/charts/#process-capability">Process capability</a>, the <a href="https://wafertools.github.io/wafermap/charts/#test-value-distribution">test-value box plot</a>
1088
+ (one box per wafer, or with Group by on one per group: click a group&#39;s box to see its wafers, <strong>Back</strong> to return), the
1089
+ <a href="https://wafertools.github.io/wafermap/charts/#value-histogram">value histogram</a> (all wafers, one wafer, or one series per group) and the
1090
+ <a href="https://wafertools.github.io/wafermap/charts/#wafer-to-wafer-trend">wafer-to-wafer trend</a>. The trend is always in slot order, deliberately: drift across a cassette only reads
1091
+ in the physical sequence, so there is no sort control to destroy it, and it needs at least two wafers; drag across it to pick a
1092
+ run of wafers. The box plot, histogram and trend are plots: each has the test picker and the axis settings (<em>Axis includes
1093
+ limits</em>, <em>Clip outliers</em>, and which limits to draw), and a change in one reaches the others. Clicking a capability box drives
1094
+ them onto that same test. In a lot with hundreds of tests, click the \u2606 at the end of a row in any test picker (or press <strong>P</strong> on
1095
+ the focused row) to <strong>pin</strong> that test: pinned tests are listed first, under a &quot;Pinned&quot; heading, in every picker.</p>
1107
1096
  <p>With <strong>Group by</strong> on (a split, a lot), the cards that compare the groups come first, under <strong>Comparing \u2026</strong>: the
1108
- <strong>Comparison by</strong> table and the difference map, then the cards for each test under <strong>Test by test</strong>. The table compares
1109
- every measured test across the groups, ranked so the tests that moved are at the top. Each wafer counts once, as the mean of its dies, because dies
1110
- on one wafer share its processing: counted die by die, a difference no bigger than one wafer&#39;s offset would look
1111
- certain. So n is the number of wafers, and with two or three a group, many differences honestly come out
1112
- inconclusive. For each test the table gives each group&#39;s mean, <strong>Welch p</strong> (Welch&#39;s ANOVA, or Welch&#39;s t for two
1113
- groups: do the means differ, without assuming equal spreads), <strong>Rank p</strong> (Kruskal\u2013Wallis, the same question on ranks,
1114
- which one odd wafer cannot drive; approximate with fewer than five wafers a group), <strong>q</strong> (Welch p adjusted for how
1115
- many tests were compared, Benjamini\u2013Hochberg; the table is sorted by it), and the <strong>largest shift</strong> in wafer-to-wafer
1116
- standard deviations and as a share of the limit window. Choose a <strong>Control</strong> (the process of record) and each other
1117
- group&#39;s cell adds its difference from the control with a Holm-adjusted p. Click a test to show it in the panels below.
1118
- <strong>Comparison CSV</strong> saves the table. <a href="#wmap-comparing-groups-of-wafers" onclick="(function(e){e.preventDefault();var g=e.target.closest('.wmap-guide');var el=g&&g.querySelector('[id=\\'wmap-comparing-groups-of-wafers\\']');if(el)el.scrollIntoView({behavior:'smooth'});})(event)">Comparing groups of wafers</a> explains each figure. Narrowing <strong>Show</strong> to one group leaves nothing to compare, so the table is not shown.</p>
1097
+ <a href="https://wafertools.github.io/wafermap/charts/#comparison-by-group">Comparison by</a> table and the <a href="https://wafertools.github.io/wafermap/charts/#difference-map">difference map</a> (pick the two groups and a test or <em>Yield</em>; it follows
1098
+ the test the other panels show until you pick one), then the cards for each test under <strong>Test by test</strong>. In the table,
1099
+ choose a <strong>Control</strong> and each other group&#39;s cell adds its difference from it; click a test to show it in the panels below;
1100
+ <strong>Comparison CSV</strong> saves the table. Narrowing <strong>Show</strong> to one group leaves nothing to compare, so the table is not shown.
1101
+ <a href="#wmap-comparing-groups-of-wafers" onclick="(function(e){e.preventDefault();var g=e.target.closest('.wmap-guide');var el=g&&g.querySelector('[id=\\'wmap-comparing-groups-of-wafers\\']');if(el)el.scrollIntoView({behavior:'smooth'});})(event)">Comparing groups of wafers</a> explains each figure.</p>
1119
1102
  <p>The box plot, histogram, trend and the Correlation tab&#39;s scatter draw the
1120
1103
  test&#39;s limits as dashed lines. A test can have two kinds: <strong>test limits</strong>
1121
1104
  (labelled <em>Lo limit</em> / <em>Hi limit</em>, short dashes) \u2014 what each die was judged
@@ -1143,19 +1126,13 @@ the visible range when some do. The box plot additionally has its own
1143
1126
  every plotted value is positive) \u2014 the histogram and trend charts do not
1144
1127
  offer one.</p>
1145
1128
  </li>
1146
- <li><p><strong>Correlation</strong> \u2014 a test-to-test correlation matrix and a die-level scatter
1147
- plot, both stating the sample size the coefficients are computed over.
1148
- <strong>Max tests</strong> (5 to 100, 20 by default) sets how many tests the matrix shows, and
1149
- <strong>Correlation CSV</strong> saves the matrix as a table.
1150
- Clicking a matrix cell drives the scatter plot onto that pair, where <code>r</code> and
1151
- <code>n</code> over every point drawn are printed (with Group by on, the colour is the group; filter the legend to look at one).
1152
- When the points pool several splits or lots, the scatter says so: a trend across them may be the groups&#39; offset
1153
- rather than the relationship. Hover a
1154
- point to see which wafer and die it is; <strong>click</strong> it to open that wafer on the
1155
- X test. <strong>Drag</strong> a rectangle over the plot to select the dies inside it \u2014 across
1156
- as many wafers as they fall on \u2014 and a menu opens with charts and tables of
1157
- just those dies (see <a href="#wmap-charting-dies-and-wafers" onclick="(function(e){e.preventDefault();var g=e.target.closest('.wmap-guide');var el=g&&g.querySelector('[id=\\'wmap-charting-dies-and-wafers\\']');if(el)el.scrollIntoView({behavior:'smooth'});})(event)">Charting dies and wafers</a>). The
1158
- selection stays ringed until you change the X or Y test or click empty space.</p>
1129
+ <li><p><strong>Correlation</strong> \u2014 the <a href="https://wafertools.github.io/wafermap/charts/#test-correlation-matrix">test correlation matrix</a> and a die-level <a href="https://wafertools.github.io/wafermap/charts/#test-scatter">scatter</a>, both
1130
+ stating the sample size the coefficients are computed over. <strong>Max tests</strong> (5 to 100, 20 by default) sets how many tests the
1131
+ matrix shows, and <strong>Correlation CSV</strong> saves it as a table. Clicking a matrix cell drives the scatter onto that pair. Hover a
1132
+ point to see which wafer and die it is; <strong>click</strong> it to open that wafer on the X test. <strong>Drag</strong> a rectangle over the plot to
1133
+ select the dies inside it \u2014 across as many wafers as they fall on \u2014 and a menu opens with charts and tables of just those dies
1134
+ (see <a href="#wmap-charting-dies-and-wafers" onclick="(function(e){e.preventDefault();var g=e.target.closest('.wmap-guide');var el=g&&g.querySelector('[id=\\'wmap-charting-dies-and-wafers\\']');if(el)el.scrollIntoView({behavior:'smooth'});})(event)">Charting dies and wafers</a>). The selection stays ringed until you change the X or Y test or
1135
+ click empty space.</p>
1159
1136
  </li>
1160
1137
  </ul>
1161
1138
  <p>In a gallery with more than one wafer, a <strong>Group by</strong> control appears whenever
@@ -1209,7 +1186,7 @@ onto that pair.</em></p>
1209
1186
  </tr>
1210
1187
  <tr>
1211
1188
  <td>A bar of the <strong>value histogram</strong> (with Group by on, a column of it)</td>
1212
- <td>the menu on the dies whose values fall in that bar, across the groups, or in the one group the legend has emphasised</td>
1189
+ <td>the menu on the dies whose values fall in that bar, across the groups, or in the one group <strong>Show</strong> has narrowed to (or the one a legend click has left showing)</td>
1213
1190
  </tr>
1214
1191
  <tr>
1215
1192
  <td>A level of a <strong>sweep</strong> curve</td>
@@ -1470,17 +1447,20 @@ and draws none. The limits are always the whole wafer&#39;s, even in a panel of
1470
1447
  The Overview shows the same verdicts as a <strong>Part average testing (PAT)</strong> card: for each wafer, the dies within the PAT
1471
1448
  limits, the outliers and the rate, the dies that fail anyway, and which tests the outliers are outside on. The Dies
1472
1449
  table (Data tab) has a <strong>PAT</strong> column, and <strong>PAT tests</strong> where there are outliers, in the CSV too; a selection that
1473
- is only part of a wafer has neither, since the limits belong to the whole wafer. <strong>Map the verdicts</strong> on the card opens a
1474
- gallery with a map of each wafer, its dies coloured by their PAT verdict (within the limits, outlier, fails anyway), so
1475
- the gallery&#39;s legend and value toggles show where the outliers are on each wafer. The maps state no yield: a verdict is
1476
- not a bin.</li>
1450
+ is only part of a wafer has neither, since the limits belong to the whole wafer. <strong>Map the verdicts</strong> on the card goes back to the
1451
+ maps coloured by PAT verdict, which is also the <strong>PAT verdict</strong> entry of the <strong>Plot mode</strong> menu on a map and on a
1452
+ gallery (offered when a test has both limits and a wafer has enough dies to set PAT limits from): within the limits
1453
+ in blue, outlier in amber, fails anyway in red, so the legend and value toggles show where the outliers are on each
1454
+ wafer. The dies keep their bins and measurements, so the tooltip shows them beside the verdict. With a filter on, the
1455
+ verdicts are judged over the dies the filter keeps, as on the card.</li>
1477
1456
  <li><strong>Panels</strong>: one small plot per value of a category field, laid out like the gallery&#39;s cards, on shared axes and
1478
1457
  colours with one legend and one statement above them. A wafer field (split, lot) gives each panel its whole wafers; a
1479
1458
  die field (ring, site, bin) the dies with that value from every wafer; <strong>Test</strong>, with several tests as the values,
1480
1459
  one test a panel. So &quot;one scatter per split&quot; or &quot;a histogram per ring&quot; is one plot. Rescaled values are measured over
1481
1460
  the whole population, so a panel is not re-centred on itself and panels compare. Each panel has its own expand button, and
1482
1461
  the plot&#39;s Save as PNG saves the whole grid. At most 24 panels; a field on the X axis or the colour cannot also make
1483
- the panels.</li>
1462
+ the panels. The <strong>Columns</strong> control above the panels, or the keys <strong>1</strong> to <strong>5</strong> (and <strong>0</strong> for Auto) while the pointer is
1463
+ over the plot, sets how many panels sit side by side; Auto fits as many as the width holds at 260 px or more.</li>
1484
1464
  <li><strong>Wafer-level comparison</strong> (box and bar of one measured test): when the categories or the colour are a wafer field
1485
1465
  such as split or lot, the line under the plot adds the comparison of those groups with each wafer as one value, as
1486
1466
  the Distributions table does: the wafers in each group, Welch p and rank p.</li>
@@ -1,3 +1,3 @@
1
- export declare const WMAP_VERSION = "0.37.0";
2
- export declare const WMAP_BUILD_TIME = "2026-10-20T13:45:09.045Z";
1
+ export declare const WMAP_VERSION = "0.38.0";
2
+ export declare const WMAP_BUILD_TIME = "2026-10-28T18:00:48.604Z";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- export const WMAP_VERSION="0.37.0",WMAP_BUILD_TIME="2026-10-20T13:45:09.045Z";
1
+ export const WMAP_VERSION="0.38.0",WMAP_BUILD_TIME="2026-10-28T18:00:48.604Z";
@@ -1 +1 @@
1
- import{CLR as s,FONT as m,RADIUS as w,SHADOW as f,SPACE as p,wireControlHover as A,wireTooltip as S}from"./toolbar.js";export function createViewSwitch(n,u,l,g){const i=n.createElement("div");i.setAttribute("role","tablist"),i.setAttribute("aria-label","View"),i.dataset.wmapViewSwitch="1",Object.assign(i.style,{order:"1",flexShrink:"0",display:"inline-flex",alignItems:"stretch",background:s.menuBg,border:`1px solid ${s.menuBorder}`,borderRadius:w.control,boxShadow:f.panel,overflow:"hidden"});const c=(t,e,h)=>{const r=n.createElement("button");return r.type="button",r.textContent=t,r.dataset.wmapView=e,r.setAttribute("role","tab"),Object.assign(r.style,{border:"none",cursor:"pointer",fontSize:m.body,padding:`${p.sm} ${p.lg}`,whiteSpace:"nowrap"}),A(r,"bare"),S(r,h),r.addEventListener("click",()=>{r.getAttribute("aria-selected")!=="true"&&g(e==="insights")}),r},a=c(u,"maps",l==="lot"?"The wafer maps":"The wafer map"),o=c("Insights","insights",`Charts and statistics for this ${l}`);i.append(a,o);const d=(t,e)=>{t.setAttribute("aria-selected",String(e)),t.dataset.on=String(e),t.tabIndex=e?0:-1,Object.assign(t.style,{background:e?s.bgActive:"transparent",color:e?s.iconActive:s.label,fontWeight:"600"})},b=t=>{d(a,!t),d(o,t)};return b(!1),i.addEventListener("keydown",t=>{if(t.key!=="ArrowLeft"&&t.key!=="ArrowRight")return;const e=n.activeElement===a?o:a;n.activeElement!==a&&n.activeElement!==o||(t.preventDefault(),e.focus(),e.click())}),{el:i,setInsightsOpen:b}}
1
+ import{CLR as o,FONT as w,RADIUS as l,SHADOW as f,SPACE as p,wireControlHover as A,wireTooltip as y}from"./toolbar.js";export function createViewSwitch(s,g,c,m){const n=s.createElement("div");n.setAttribute("role","tablist"),n.setAttribute("aria-label","View"),n.dataset.wmapViewSwitch="1",Object.assign(n.style,{order:"1",flexShrink:"0",display:"inline-flex",alignItems:"stretch",background:o.menuBg,border:`1px solid ${o.menuBorder}`,borderRadius:l.control,boxShadow:f.panel});const d=(t,e,h)=>{const r=s.createElement("button");return r.type="button",r.textContent=t,r.dataset.wmapView=e,r.setAttribute("role","tab"),Object.assign(r.style,{border:"none",cursor:"pointer",fontSize:w.body,padding:`${p.sm} ${p.lg}`,whiteSpace:"nowrap"}),A(r,"bare"),y(r,h),r.addEventListener("click",()=>{r.getAttribute("aria-selected")!=="true"&&m(e==="insights")}),r},i=d(g,"maps",c==="lot"?"The wafer maps":"The wafer map"),a=d("Insights","insights",`Charts and statistics for this ${c}`);i.style.borderRadius=`${l.control} 0 0 ${l.control}`,a.style.borderRadius=`0 ${l.control} ${l.control} 0`,n.append(i,a);const b=(t,e)=>{t.setAttribute("aria-selected",String(e)),t.dataset.on=String(e),t.tabIndex=e?0:-1,Object.assign(t.style,{background:e?o.bgActive:"transparent",color:e?o.iconActive:o.label,fontWeight:"600"})},u=t=>{b(i,!t),b(a,t)};return u(!1),n.addEventListener("keydown",t=>{if(t.key!=="ArrowLeft"&&t.key!=="ArrowRight")return;const e=s.activeElement===i?a:i;s.activeElement!==i&&s.activeElement!==a||(t.preventDefault(),e.focus(),e.click())}),{el:n,setInsightsOpen:u}}
@@ -1 +1 @@
1
- import{createWafer as Q}from"../core/wafer.js";import{isYieldEligibleDie as ve,getDieKey as X,hasPosition as W,positionKey as Se}from"../core/dies.js";import{applyOrientation as se,transformDies as Ce,clipDiesToWafer as ke}from"../core/transforms.js";import{generateDies as Oe}from"../core/dies.js";import{dieHasAnyTestData as Ae,dieLink as U,finaliseDie as z,linkDie as $e,recordedVerdict as Ne,recordedVerdictsReader as Re,tableFromRows as Fe,testValue as Z,testsPresent as Ee,VERDICT_FAIL as Te,VERDICT_NONE as We,VERDICT_PASS as Ie}from"../core/dieTable.js";import{isDieColumns as _e,linkColumns as Pe,linkRows as re,relink as oe}from"./columnarInput.js";import{affineRotation as Ve,affineMirror as Be,affineCompose as Le,affinePoint as Ye}from"../core/transforms.js";import{inferWaferFromXY as Xe}from"../core/inference/wafer.js";import{resolveGridPitch as Ke}from"../core/inference/pitch.js";import{assignGridIndices as je}from"../core/inference/grid.js";import{generateReticleGrid as He}from"../core/reticle.js";import{applyDerivedTests as Ue}from"./derivedTests/apply.js";import{isStdfBin as ze,isStdfCoord as ae,isStdfTestNumber as de,isStdfSite as Ge,STDF_BIN_MAX as qe,STDF_COORD_MAX as fe,STDF_TEST_NUM_MAX as Je,STDF_SITE_MAX as Qe}from"../core/stdf.js";import{hasAnyKey as Ze,maxOf as ee,minOf as le,modeOf as et}from"../core/utils.js";import{aggregateValues as ue,aggregateBinCounts as tt,stackHoldsMeasurements as nt,stackBinsAreData as it}from"../core/aggregates.js";import{normalizePassBins as ce}from"../core/passBins.js";import{defaultRingCount as te}from"../core/ringCount.js";import{applyValueFilter as st,mergeValueFilterTests as rt,valueFilterWarning as ot}from"./valueFilter.js";export function isParametricTest(n){return n?.testType!=="F"}export function isBuiltMap(n){return"wafer"in n&&"dies"in n&&"dataAxisFlip"in n}function at(n){const e=(i,a)=>({ringCount:i,ringCountWarning:{code:"analysis-option-corrected",severity:"warning",message:`ringCount=${String(n)} ${a} (using ${i}).`}});if(n===void 0)return{ringCount:te(),ringCountWarning:void 0};if(typeof n!="number"||!Number.isFinite(n))return e(te(),"is not a finite number");const t=Math.max(1,Math.round(n));return t===n?{ringCount:n,ringCountWarning:void 0}:e(t,"is not a whole number of at least 1")}function dt(n,e){const t=Array.isArray(n)?{}:n,i={hbin:0,sbin:0,siteNum:0,testValues:0,testPass:0};let a;const d=(u,C)=>{i[u]++,a??=`${u} ${JSON.stringify(C)}`},o={bins:0,positions:0,values:0,sites:0,orientation:0},r=new Set;let p=0;if(e){i.testValues+=e.wrongValues,i.testPass+=e.wrongVerdicts,e.example!==void 0&&(a??=e.example),o.values+=e.nonFinite;for(const u of e.badTestNumbers)r.add(u)}const h=u=>u==null?!0:typeof u!="number"?!1:Number.isNaN(u)?(p++,!1):ze(u)?!0:(o.bins++,!1);function l(u){const C=new Set,D=new Set;for(let S=0;S<u.length;S+=S<50?1:100){const N=u[S];if(!(N===null||typeof N!="object")){if(N.testValues&&typeof N.testValues=="object")for(const M of Object.keys(N.testValues))C.add(M);if(N.testPass&&typeof N.testPass=="object")for(const M of Object.keys(N.testPass))D.add(M)}}const g=[...C],b=[...D],k=S=>de(Number(S));for(const S of new Set([...g,...b]))k(S)||r.add(S);const R=g.map(k),v=b.map(k),T=g.map(Number),L=b.map(Number);let K;for(let S=0;S<u.length;S++){const N=u[S];if(N===null||typeof N!="object")continue;const M=N;let F;const $=()=>F??={...M};M.hbin!=null&&typeof M.hbin!="number"&&d("hbin",M.hbin),M.sbin!=null&&typeof M.sbin!="number"&&d("sbin",M.sbin),h(M.hbin)||($().hbin=void 0),h(M.sbin)||($().sbin=void 0);const Y=typeof M.x=="number"&&!ae(M.x),j=typeof M.y=="number"&&!ae(M.y);if(Y||j){o.positions+=(Y?1:0)+(j?1:0);const s=$();s.x=void 0,s.y=void 0}M.siteNum!=null&&typeof M.siteNum!="number"?(d("siteNum",M.siteNum),$().siteNum=void 0):typeof M.siteNum=="number"&&!Ge(M.siteNum)&&(o.sites++,$().siteNum=void 0);const P=M.testValues;if(P&&typeof P=="object"){let s;for(let x=0;x<g.length;x++){const A=g[x],O=P[T[x]];if(O!=null){if(!R[x]){s??={...P},delete s[A];continue}typeof O!="number"?(d("testValues",O),s??={...P},delete s[A]):Number.isFinite(O)||(o.values++,s??={...P},delete s[A])}}s&&($().testValues=s)}const I=M.testPass;if(I&&typeof I=="object"){let s;for(let x=0;x<b.length;x++){const A=b[x],O=I[L[x]];if(O!=null){if(!v[x]){s??={...I},delete s[A];continue}typeof O!="boolean"&&(d("testPass",O),s??={...I},delete s[A])}}s&&($().testPass=s)}F&&((K??=u.slice())[S]=F)}return K}const f={warnings:[]};if(Array.isArray(n))f.results=l(n);else{Array.isArray(t.results)&&(f.results=l(t.results)),Array.isArray(t.dies)&&(f.dies=l(t.dies));const u=t.lotStack?.results;if(Array.isArray(u)){const C=u.map(D=>Array.isArray(D)?l(D):void 0);C.some(Boolean)&&(f.stackResults=C.map((D,g)=>D??u[g]))}}if(Array.isArray(t.testDefs)){const u=t.testDefs,C=u.filter(D=>D==null||typeof D.testNumber!="number"||de(D.testNumber));for(const D of u)C.includes(D)||r.add(String(D.testNumber));C.length!==u.length&&(f.testDefs=C)}const y=t.waferConfig?.orientation;if(typeof y=="number"){const u=Number.isFinite(y)?(y%360+360)%360:NaN;u===0||u===90||u===180||u===270?f.orientation=u:(o.orientation++,f.orientation=0)}const m=(u,C,D=`${C}s`)=>`${u} ${u===1?C:D}`,c=[];if(i.hbin&&c.push(m(i.hbin,"hard bin")),i.sbin&&c.push(m(i.sbin,"soft bin")),i.siteNum&&c.push(m(i.siteNum,"site number")),i.testValues&&c.push(m(i.testValues,"test value")),i.testPass&&c.push(m(i.testPass,"pass/fail verdict")),c.length){const u=`buildWaferMap received ${c.join(", ")} of the wrong type (for example ${a}), treated as missing. Bins, sites and test values must be numbers and verdicts true/false \u2014 a bin of "1" is not pass bin 1 \u2014 so those dies have no bin, no site, no value or no verdict, and yield and every chart leave them out. Convert them with Number() (and verdicts to booleans) and rebuild.`;console.warn(`[wafermap] ${u}`),f.warnings.push({code:"input-values-not-numbers",message:u,severity:"error"})}const w=[];if(o.bins&&w.push(`${m(o.bins,"bin")} (legal: whole numbers 0\u2013${qe}) \u2014 those dies have no bin`),o.positions&&w.push(`${m(o.positions,"coordinate")} (legal: whole numbers \u2212${fe} to ${fe}) \u2014 those dies have no position`),r.size&&w.push(`${m(r.size,"test number")} (legal: whole numbers 0\u2013${Je}) \u2014 those tests are left out`),o.values&&w.push(`${m(o.values,"test value")} that ${o.values===1?"is":"are"} not finite \u2014 left out`),o.sites&&w.push(`${m(o.sites,"site number")} (legal: 0\u2013${Qe}) \u2014 those dies have no site`),o.orientation&&w.push("a waferConfig.orientation other than 0, 90, 180 or 270 \u2014 the map is built at 0"),w.length||p){const u=[];w.length&&u.push(`buildWaferMap received values outside the STDF V4 ranges, treated as missing: ${w.join("; ")}.`),p&&u.push(`${m(p,"bin was","bins were")} NaN and ${p===1?"is":"are"} treated as no bin.`);const C=u.join(" ");console.warn(`[wafermap] ${C}`),f.warnings.push({code:"input-values-outside-stdf",message:C,severity:"warning"})}return f}function pe(n){const e=(h,l)=>h!==null&&typeof h=="object"&&h[l]!==void 0,t=Array.isArray(n)?{}:n,i=[],a=(h,l,f)=>{h&&i.push(`\`${l}\` (now \`${f}\`)`)};a(e(t,"data"),"data","results"),a(e(t,"die"),"die","dieConfig"),a(e(t,"stack"),"stack","lotStack"),a(e(t.dieConfig,"origin"),"dieConfig.origin","dieConfig.coordinateOrigin"),a(e(t.waferConfig,"flat"),"waferConfig.flat","waferConfig.notch"),a(e(t.reticleConfig,"anchor"),"reticleConfig.anchor","reticleConfig.anchorDie"),a(e(t.lotStack,"aggr"),"lotStack.aggr","lotStack.method"),a(Array.isArray(t.testDefs)&&t.testDefs.some(h=>e(h,"index")&&!e(h,"testNumber")),"TestDef.index","TestDef.testNumber");const d=e(t.lotStack,"results")?t.lotStack.results:[],o=(Array.isArray(n)?[n]:[t.results,...Array.isArray(d)?d:[]]).filter(h=>Array.isArray(h));if(a(o.some(h=>h.slice(0,100).some(l=>e(l,"values"))),"values","testValues"),!i.length)return;const r=i.length>1,p=`buildWaferMap ignored ${i.join(", ")}: ${r?"these names were":"that name was"} removed in an earlier release, so what ${r?"they":"it"} described is not on this map. Rename and rebuild.`;return console.warn(`[wafermap] ${p}`),{code:"input-field-removed",message:p,severity:"error"}}function ft(n){if(n.results!==void 0||n.lotStack!==void 0)throw new Error("buildWaferMap: pass `layout`, `results` or `lotStack` \u2014 only one.");const e=n.waferConfig?.diameter,t=n.dieConfig?.width,i=n.dieConfig?.height;if(!(e>0&&t>0&&i>0))throw new Error("buildWaferMap: `layout` needs waferConfig.diameter and dieConfig.width and height, all positive.");const a=Q({diameter:e,notch:n.waferConfig?.notch,orientation:0}),d=ke(Oe(a,{width:t,height:i}),a,{width:t,height:i}).filter(l=>!l.partial),{flipX:o,flipY:r}=me(n.dieConfig,{type:"center"}),{layout:p,...h}=n;return{...h,results:d.map(l=>({x:o?-l.x:l.x,y:r?-l.y:l.y})),waferConfig:{...n.waferConfig,center:{x:0,y:0}},dieConfig:{...n.dieConfig,coordinateOrigin:{type:"center"}}}}function lt(n){if(!Array.isArray(n)&&"results"in n&&n.results!==void 0&&"lotStack"in n&&n.lotStack!==void 0)throw new Error("buildWaferMap: pass either `results` or `lotStack`, not both.");const e={wrongVerdicts:0,wrongValues:0,nonFinite:0,badTestNumbers:[]},t=!Array.isArray(n)&&_e(n.results)?{...n,results:Pe(n.results,e).records}:n,i=dt(t,e);return Array.isArray(t)?{results:ne(i.results??t),waferOpts:void 0,dieOpts:void 0,explicitDies:void 0,reticleOpts:void 0,lotStackOpts:void 0,passBins:ce(void 0),ringCount:te(),valueFilter:"validity",ringCountWarning:void 0,removedFieldWarning:pe(t),inputValueWarnings:i.warnings,standardDiameters:void 0,testDefs:void 0,hbinDefs:void 0,sbinDefs:void 0,metadataFields:void 0,derivedTests:void 0,retestPolicy:"last",edgeDieYieldMode:"exclude"}:{results:ne(i.results??t.results??[]),waferOpts:i.orientation===void 0||t.waferConfig===void 0?t.waferConfig:{...t.waferConfig,orientation:i.orientation},dieOpts:t.dieConfig,explicitDies:i.dies??t.dies,reticleOpts:t.reticleConfig,lotStackOpts:t.lotStack?{...t.lotStack,results:(i.stackResults??t.lotStack.results).map(ne)}:void 0,passBins:ce(t.passBins),valueFilter:t.valueFilter??"validity",...at(t.ringCount),removedFieldWarning:pe(t),inputValueWarnings:i.warnings,standardDiameters:t.standardDiameters,testDefs:(i.testDefs??t.testDefs)?.length?i.testDefs??t.testDefs:void 0,hbinDefs:t.hbinDefs,sbinDefs:t.sbinDefs,metadataFields:t.metadataFields,derivedTests:t.derivedTests?.length?t.derivedTests:void 0,retestPolicy:t.retestPolicy??"last",edgeDieYieldMode:t.edgeDieYieldMode??"exclude"}}function ne(n){return n.length>0&&U(n[0])!==void 0?n:re(n).records}function ut(n,e){return e?.coordinateOrigin?e.coordinateOrigin:{type:"center"}}function ct(n,e,t){if(e.type==="custom"&&e.offset)return{offsetX:e.offset.x,offsetY:e.offset.y};if(e.type!=="center"){let i=1/0,a=-1/0,d=1/0,o=-1/0;for(const r of n)r.x<i&&(i=r.x),r.x>a&&(a=r.x),r.y<d&&(d=r.y),r.y>o&&(o=r.y);return{offsetX:Math.round((a+i)/2),offsetY:Math.round((o+d)/2)}}return{offsetX:t.offsetX,offsetY:t.offsetY}}function pt(n,e){if(n.length<xe)return!1;const t=he(n),i=(a,d,o)=>{const r=o-d+1;return a<d-r||a>o+r};return i(Math.round(e.x),t.xMin,t.xMax)||i(Math.round(e.y),t.yMin,t.yMax)}function he(n){let e=1/0,t=-1/0,i=1/0,a=-1/0;for(const d of n){const o=Math.round(d.x),r=Math.round(d.y);o<e&&(e=o),o>t&&(t=o),r<i&&(i=r),r>a&&(a=r)}return{xMin:e,xMax:t,yMin:i,yMax:a}}const ht="The supplied wafer centre";function mt(n,e){const t=he(n);return`${ht} (${e.x}, ${e.y}) is far outside the probed dies (X ${t.xMin}\u2026${t.xMax}, Y ${t.yMin}\u2026${t.yMax}), so it was ignored and the centre was inferred from the dies. Used as given, it would draw a wafer many times the die extent with the dies in one corner. If it is the real centre, supply waferConfig.diameter as well.`}function gt(n,e,t,i,a,d){if(d)return{colMidX:(Math.round(d.x)-e)*i,colMidY:(Math.round(d.y)-t)*a,anchored:!0};if(n.length===0)return{colMidX:0,colMidY:0,anchored:!1};let o=1/0,r=-1/0,p=1/0,h=-1/0;for(const l of n){const f=Math.round(l.x)-e,y=Math.round(l.y)-t;f<o&&(o=f),f>r&&(r=f),y<p&&(p=y),y>h&&(h=y)}return{colMidX:(o+r)/2*i,colMidY:(p+h)/2*a,anchored:!1}}function yt(n,e,t){let i=1/0,a=-1/0,d=1/0,o=-1/0,r=0,p=0;for(const f of n){const y=Math.round(f.x)-e,m=Math.round(f.y)-t;r+=y,p+=m,y<i&&(i=y),y>a&&(a=y),m<d&&(d=m),m>o&&(o=m)}const h=n.length,l=(f,y,m)=>{const c=(m-y)/2;return c<=0?0:Math.abs(f/h-(y+m)/2)/c};return l(r,i,a)>.11||l(p,d,o)>.11}function me(n,e){let t=n?.xAxisDirection==="left",i=n?.yAxisDirection==="down";return(e.type==="UL"||e.type==="UR")&&(i=!0),(e.type==="LR"||e.type==="UR")&&(t=!0),{flipX:t,flipY:i}}function bt(n){const e={...n};return delete e.limitLow,delete e.limitHigh,delete e.limitLowInclusive,delete e.limitHighInclusive,delete e.specLow,delete e.specHigh,e}function wt(n,e){const{method:t,targetBin:i}=n,a=n.results.map(d=>d.filter(W));if(t==="mean"||t==="median"||t==="stddev"||t==="min"||t==="max"||t==="count"){const d=new Set((e??[]).filter(l=>!isParametricTest(l)).map(l=>l.testNumber)),o=new Set;for(const l of a)for(const f of Ee(l,"values"))d.has(f)||o.add(f);if(o.size===0)return ue(a,t);const r=[...o],p=r.map(l=>ue(a,t,l)),h=new Map;for(let l=0;l<r.length;l++){const f=r[l];for(const y of p[l]){const m=X(y);h.has(m)||h.set(m,{template:y,testValues:{}});const c=h.get(m),w=y.testValues?.[0];w!==void 0&&(c.testValues[f]=w)}}return[...h.values()].map(({template:l,testValues:f})=>({...l,testValues:Ze(f)?f:void 0}))}if(t==="countBin"||t==="percent"){if(i===void 0)return[];const d=tt(a,i,"hard");if(t==="countBin")return d;const o=a.length;return d.map(r=>({...r,testValues:{0:o>0?(r.testValues?.[0]??0)/o*100:0}}))}if(t==="mode"){const d=new Map;for(const r of a)for(const p of r){const h=X(p);d.has(h)||d.set(h,[]),d.get(h).push(p)}const o=[];for(const[r,p]of d){const h=r.split(","),l=Number(h[0]),f=Number(h[1]),y=p.map(c=>c.hbin).filter(c=>c!==void 0),m=et(y);m!==null&&o.push({x:l,y:f,hbin:m})}return o}return[]}export function computeCoverage(n){const e=n.filter(W),t=e.length,i=e.filter(d=>d.edgeExcluded).length,a=e.filter(d=>d.hbin!==void 0||d.sbin!==void 0||dieHasTestData(d)).length;return{filledDies:a,totalDies:t,edgeExcludedDies:i,unpositionedDies:n.length-e.length,ratio:t>0?a/t:0}}export function computeYield(n,e,t="exclude",i=!0){const a=new Set(e),o=n.filter(c=>!c.partial).filter(c=>c.edgeExcluded).length,r=n.filter(c=>c.partial).length;if(!i)return{passDies:0,failDies:0,edgeExcludedDies:o,partialDies:r,totalDies:0,yieldPercent:null,yieldPercentGross:null};let p=0,h=0,l=!1;for(const c of n){if(!ve(c))continue;const w=c.hbin??c.sbin;w!==void 0&&(l=!0,a.has(w)?p++:h++)}const f=p+h,y=l&&f>0?p/f*100:null;let m=null;if(t==="denominator-only"){const c=f+o;m=l&&c>0?p/c*100:null}return{passDies:p,failDies:h,edgeExcludedDies:o,partialDies:r,totalDies:f,yieldPercent:y,yieldPercentGross:m}}function ge(n,e,t,i,a,d=0,o=0,r=0,p=0,h=0,l=!1,f=!1){if(!n)return[];const y=n.anchorDie??{x:0,y:0},m=He(e,{width:n.width,height:n.height,diePitchX:i,diePitchY:a,anchorDie:{x:y.x-d,y:y.y-o},gridOrigin:{x:-r,y:-p}}),c=Le(Be(l,f,e.center.x,e.center.y),Ve(h,e.center.x,e.center.y));return m.filter(w=>{const u=w.width/2,C=w.height/2,D=[[w.x-u,w.y-C],[w.x+u,w.y-C],[w.x+u,w.y+C],[w.x-u,w.y+C]].map(([v,T])=>Ye(c,v,T)),g=le(D.map(v=>v.x)),b=ee(D.map(v=>v.x)),k=le(D.map(v=>v.y)),R=ee(D.map(v=>v.y));return t.some(v=>v.physX>=g&&v.physX<b&&v.physY>=k&&v.physY<R)})}function xt(n,e,t){const a=Math.max(0,e.radius-t)**2;return n.map(d=>{const o=d.physX-e.center.x,r=d.physY-e.center.y;return o*o+r*r>a?{...d,edgeExcluded:!0}:d})}const Dt=.2;function Mt(n){const e=new Set;for(const t of n){if(t.supersedes!==void 0||!W(t))return!1;const i=Se(t);if(e.has(i))return!1;e.add(i)}return!0}function vt(n,e,t){if(Mt(n))return{results:n.slice(),warning:void 0};const i=new Set(t);function a(g,b){if(e==="last")return!0;if(e==="first")return!1;const k=G(g.hbin),R=G(b.hbin);if(k===void 0||R===void 0)return!1;const v=i.has(k),T=i.has(R);return e==="best"?T!==v?T:R<k:T!==v?v:R>k}const d=(g,b)=>b.supersedes!==void 0||a(g,b),o=g=>{const b=g.partId===void 0?"":String(g.partId).trim();return b===""?void 0:b},r=n.filter(g=>!W(g)),p=new Map;for(const g of r){const b=o(g);b!==void 0&&p.set(b,(p.get(b)??0)+1)}const l=(r.length===0?0:Math.max(0,...p.values())/r.length)<=Dt,f=new Map,y=[],m=new Map;let c=0,w=0;for(const g of n){const b=o(g);let k;if(W(g)?k=`p:${X(g)}`:l&&b!==void 0?k=`i:${b}`:k=`u:${w++}`,g.supersedes==="partId"&&b!==void 0){const v=m.get(b);v!==void 0&&v!==k&&f.has(v)&&f.delete(v)}const R=f.get(k);R===void 0?(f.set(k,{winner:g,count:1}),y.push(k)):(R.count++,k.startsWith("i:")&&c++,d(R.winner,g)&&(R.winner=g)),b!==void 0&&m.set(b,k)}const u=[],C=[...y.filter(g=>g.startsWith("p:")),...y.filter(g=>!g.startsWith("p:"))];for(const g of C){const b=f.get(g);b!==void 0&&u.push(b.count>1?{...b.winner,retestCount:b.count}:b.winner)}const D=c>0?{code:"retests-by-part-id",severity:"info",message:`${c} record${c===1?"":"s"} with no position shared a part ID with an earlier record and ${c===1?"was":"were"} treated as a retest of it.`}:void 0;return{results:u,warning:D}}export function getDieTestValue(n,e){return Z(n,e)}export function getTestPassStatus(n,e,t){const i=Ne(n,e);return i!==void 0?i:t!==void 0&&!isParametricTest(t)?ye(Z(n,e)):void 0}function ye(n){return n===0||n===1?n===1:void 0}export function testPassStatusReader(n){const e=n.map(a=>a.testNumber),t=Re(e),i=n.map(a=>!isParametricTest(a));return function(d,o){t(d,o);for(let r=0;r<o.length;r++){if(o[r]!==We||!i[r])continue;const p=ye(Z(d,e[r]));p!==void 0&&(o[r]=p?Ie:Te)}return o}}export function dieHasTestData(n){return Ae(n)}function G(n){return n===void 0||Number.isNaN(n)?void 0:n}function q(n,e){const t={},i=G(e.hbin),a=G(e.sbin);i!==void 0&&(t.hbin=i),a!==void 0&&(t.sbin=a),e.retestCount!==void 0&&(t.retestCount=e.retestCount),e.siteNum!==void 0&&(t.siteNum=e.siteNum),e.partId!==void 0&&(t.partId=e.partId),e.metadata!==void 0&&(t.metadata=e.metadata);const d=U(e);return $e({...n,...t},d.table,d.row)}function be(n){return n.some(dieHasTestData)?"value":defaultBinMode([n])}export function defaultBinMode(n){const e=t=>n.some(i=>i.some(a=>t(a)!=null));return e(t=>t.hbin)?"hardBin":e(t=>t.sbin)?"softBin":"hardBin"}function we(n,e){return n.map(({code:t,message:i})=>({code:t,message:i,severity:t==="non-standard-diameter"||t==="diameter-exceeds-die-extent"||t==="implausible-center"?"warning":"error",confidence:e.wafer.confidence}))}const St="do not fit inside the supplied",Ct="Inferred wafer diameter",kt="The probed dies reach only",Ot=.75,xe=20;export const STANDARD_WAFER_DIAMETERS_MM=[100,125,150,200,300];const At=.02;function De(n,e){return e.reduce((t,i)=>Math.abs(i-n)<Math.abs(t-n)?i:t)}function $t(n,e){if(!e.length)return!0;const t=De(n,e);return Math.abs(t-n)/t<=At}function Nt(n){return n===void 0?STANDARD_WAFER_DIAMETERS_MM:n.filter(e=>Number.isFinite(e)&&e>0)}export function buildWaferMap(n){const e=lt(!Array.isArray(n)&&n.layout?ft(n):n),t=[];let i;if(e.valueFilter!=="none"&&e.testDefs){const s=e.valueFilter,x=(e.lotStackOpts?e.lotStackOpts.results:[e.results]).map(O=>{const _=O.length>0?U(O[0]):void 0;if(!_)return[];const E=st(_.table,e.testDefs,s);return E.tests.length>0&&oe(O,E.table),E.tests}),A=rt(x);if(A.length>0){i={mode:s,tests:A};const O=ot(s,A,e.testDefs);O&&t.push(O)}}if(e.derivedTests){const s=new Set(e.passBins),x=_=>{const E=_.length>0?U(_[0]):void 0,H=Ue(_,E?.table??Fe([]),e.testDefs,e.derivedTests,s);return E&&oe(_,H.table),H},O=(e.lotStackOpts?e.lotStackOpts.results:[e.results]).map(x);e.testDefs=O[0]?.testDefs??e.testDefs,t.push(...O[0]?.warnings??[])}e.lotStackOpts&&!nt(e.lotStackOpts.method)&&(e.testDefs=e.testDefs?.map(bt));const a=e.lotStackOpts?re(wt(e.lotStackOpts,e.testDefs)).records:e.results;for(let s=0;s<Math.min(5,a.length);s++){const x=a[s];if(typeof x.x=="string"||typeof x.y=="string")throw new TypeError("buildWaferMap: x and y must be numbers, received strings. Did you forget to cast CSV values? e.g. { x: +row.x, y: +row.y }")}for(const s of a)if(s.x==null!=(s.y==null))throw new TypeError(`buildWaferMap: die has only one of x/y set (x=${String(s.x)}, y=${String(s.y)}). A die must be either fully positioned (both x and y) or fully unpositioned (neither) \u2014 omit both to mark a die as having no reported position.`);const{results:d,warning:o}=vt(a,e.retestPolicy,e.passBins),r={wafer:{confidence:1,method:"provided"},diePitch:{confidence:1,units:"mm"},grid:{confidence:1}},p=[];if(e.explicitDies){let s=e.explicitDies.filter(W);const x=e.explicitDies.filter(B=>!W(B)),A=d.filter(W),O=d.filter(B=>!W(B));if(A.length>0){const B=new Map(A.map(V=>[X(V),V]));s=s.map(V=>{const ie=B.get(X(V));return ie?q(V,ie):V})}const _=e.waferOpts?.diameter??300,E=Q({diameter:_,notch:e.waferOpts?.notch,orientation:e.waferOpts?.orientation??0,metadata:e.waferOpts?.metadata,reticle:e.reticleOpts});E.orientation!==0&&(s=se(s,E)),s=s.map(z);const H=ge(e.reticleOpts,E,s,1,1,0,0,0,0,E.orientation),Me=O.map((B,V)=>z(q({id:`unpositioned_${V}`,width:s[0]?.width??1,height:s[0]?.height??1},B))),J=[...s,...x,...Me];return{wafer:E,dies:J,dataAxisFlip:{x:!1,y:!1},reticleConfig:e.reticleOpts,units:"mm",inference:r,warnings:[...e.removedFieldWarning?[e.removedFieldWarning]:[],...e.inputValueWarnings,...o?[o]:[],...we(p,r),...t,...e.ringCountWarning?[e.ringCountWarning]:[]],plotMode:be(d),metadata:E.metadata??null,isLotStack:!1,dataCoverage:computeCoverage(J),passBins:e.passBins,...i?{valueFilter:i}:{},ringCount:e.ringCount,yield:computeYield(J,e.passBins,e.edgeDieYieldMode),reticles:H,hbinDefs:e.hbinDefs,sbinDefs:e.sbinDefs,testDefs:e.testDefs,metadataFields:e.metadataFields}}const h=d.filter(W),l=d.filter(s=>!W(s)),f=h.map(s=>({x:s.x,y:s.y})),y=Ke(f,e.dieOpts,e.waferOpts?.diameter);r.diePitch={confidence:y.confidence,units:y.units};const{pitchX:m,pitchY:c}=y,w=y.units,u=ut(h,e.dieOpts),C=je(f);r.grid={confidence:C.confidence};const{offsetX:D,offsetY:g}=ct(f,u,C),{flipX:b,flipY:k}=me(e.dieOpts,u),R=e.waferOpts?.diameter===void 0&&e.waferOpts?.center!==void 0&&pt(f,e.waferOpts.center),v=R?void 0:e.waferOpts?.center;R&&p.push({code:"implausible-center",message:mt(f,e.waferOpts.center)});const{colMidX:T,colMidY:L,anchored:K}=gt(f,D,g,m,c,v);let S=e.waferOpts?.diameter;const N=f.map(s=>({x:(Math.round(s.x)-D)*m-T,y:(Math.round(s.y)-g)*c-L})),M=ee(N.map(({x:s,y:x})=>Math.hypot(Math.abs(s)+m/2,Math.abs(x)+c/2)));if(S===void 0)if(f.length>0)if(w==="mm"){const s=Xe(N,{minRadius:M});S=s.diameter,r.wafer={confidence:s.confidence,method:s.method};const x=Nt(e.standardDiameters);if(!$t(S,x)){const A=De(S,x);p.push({code:"non-standard-diameter",message:`${Ct} ${S.toFixed(1)} mm is not a standard wafer size (nearest is ${A} mm). The diameter was derived from the die extent, which assumes the probed grid reaches the wafer edge \u2014 a non-standard result usually means it does not, because the outer dies were never probed. Every die is then placed against a wafer that is too small, which moves dies between rings and changes ring and edge findings. Supply waferConfig.diameter.`})}}else S=M*2,r.wafer={confidence:y.confidence*.8,method:"extent"};else S=w==="mm"?300:30,r.wafer={confidence:0,method:"default"};if(!K&&f.length>0&&yt(f,D,g)&&(r.wafer.method="inferred-partial",p.push({code:"partial-coverage",message:"Wafer geometry was inferred from die positions alone. The data does not span a full symmetric wafer, so the inferred diameter and centre may be wrong and dies may be mis-positioned relative to the true wafer boundary. Supply waferConfig.diameter and waferConfig.center (the prober coordinate of the wafer centre) to position partial data correctly."})),e.waferOpts?.diameter!==void 0&&v===void 0&&M>0&&f.length>=xe){const s=M/(S/2);s<Ot&&p.push({code:"diameter-exceeds-die-extent",message:`${kt} ${(s*100).toFixed(0)}% of the ${S} mm wafer's radius. Either the diameter is larger than the real one, or this is a partial map covering only part of the wafer. Ring bands are equal-radius, so the outer rings are mostly or entirely empty and ring, quadrant and edge findings describe the assumed wafer rather than the probed area. Check waferConfig.diameter, or drop it and let the diameter be inferred from the die extent.`})}if(e.waferOpts?.diameter!==void 0){const s=e.dieOpts?.width!==void 0&&e.dieOpts?.height!==void 0;if(s&&M>S/2+1e-9){const x=N.filter(({x:A,y:O})=>Math.hypot(Math.abs(A)+m/2,Math.abs(O)+c/2)>S/2+1e-9).length;p.push({code:"geometry-conflict",message:`${x} of ${N.length} probed die positions ${St} ${S} mm wafer at the supplied die pitch of ${m} \xD7 ${c} mm. A die with test results is a real prober position and is always fully on the wafer, so one of the two supplied values must be wrong: containing these dies at this pitch would need a diameter of at least ${(M*2).toFixed(1)} mm. Check waferConfig.diameter and dieConfig.width/height against the real device.`})}}const F=Q({diameter:S,units:w,notch:e.waferOpts?.notch,orientation:e.waferOpts?.orientation??0,metadata:e.waferOpts?.metadata,reticle:e.reticleOpts});let $=h.map(s=>{const x=Math.round(s.x)-D,A=Math.round(s.y)-g,O={id:`${x}_${A}`,x,y:A,physX:x*m-T,physY:A*c-L,width:m,height:c,insideWafer:!0,partial:!1};return q(O,s)});(D!==0||g!==0)&&($=$.map(s=>({...s,x:s.x+D,y:s.y+g,id:`${s.x+D}_${s.y+g}`}))),$=se($,F),(b||k)&&($=Ce($,{flipX:b,flipY:k},F.center));const Y=[];e.waferOpts?.edgeExclusion&&e.waferOpts.edgeExclusion>0&&($=xt($,F,e.waferOpts.edgeExclusion),e.waferOpts.edgeExclusion>F.radius&&Y.push({code:"edge-exclusion-exceeds-radius",message:`edgeExclusion (${e.waferOpts.edgeExclusion}mm) exceeds the resolved wafer radius (${F.radius}mm) \u2014 the entire wafer is excluded.`,severity:"warning"})),$=$.map(z);const j=ge(e.reticleOpts,F,$,m,c,D,g,T,L,F.orientation,b,k),P=l.map((s,x)=>z(q({id:`unpositioned_${x}`,width:m,height:c},s))),I=[...$,...P];return{wafer:F,dies:I,dataAxisFlip:{x:b,y:k},reticleConfig:e.reticleOpts,units:w,inference:r,warnings:[...e.removedFieldWarning?[e.removedFieldWarning]:[],...e.inputValueWarnings,...o?[o]:[],...we(p,r),...Y,...t,...e.ringCountWarning?[e.ringCountWarning]:[]],plotMode:be(d),metadata:F.metadata??null,isLotStack:e.lotStackOpts!==void 0,dataCoverage:computeCoverage(I),passBins:e.passBins,...i?{valueFilter:i}:{},ringCount:e.ringCount,yield:computeYield(I,e.passBins,e.edgeDieYieldMode,it(e.lotStackOpts!==void 0,e.lotStackOpts?.method)),reticles:j,hbinDefs:e.hbinDefs,sbinDefs:e.sbinDefs,testDefs:e.testDefs,metadataFields:e.metadataFields,aggrMethod:e.lotStackOpts?.method,lotSize:e.lotStackOpts?.results.length}}
1
+ import{createWafer as Q}from"../core/wafer.js";import{isYieldEligibleDie as ve,getDieKey as X,hasPosition as I,positionKey as Se}from"../core/dies.js";import{applyOrientation as se,transformDies as Ce,clipDiesToWafer as ke}from"../core/transforms.js";import{generateDies as Oe}from"../core/dies.js";import{dieHasAnyTestData as Ae,dieLink as U,finaliseDie as z,linkDie as $e,recordedVerdict as Ne,recordedVerdictsReader as Re,tableFromRows as Ee,testValue as Z,testsPresent as Te,VERDICT_FAIL as Fe,VERDICT_NONE as Ie,VERDICT_PASS as We}from"../core/dieTable.js";import{isDieColumns as _e,linkColumns as Pe,linkRows as re,relink as oe}from"./columnarInput.js";import{affineRotation as Be,affineMirror as Ve,affineCompose as Le,affinePoint as Ye}from"../core/transforms.js";import{inferWaferFromXY as Xe}from"../core/inference/wafer.js";import{resolveGridPitch as Ke}from"../core/inference/pitch.js";import{assignGridIndices as je}from"../core/inference/grid.js";import{generateReticleGrid as He}from"../core/reticle.js";import{applyDerivedTests as Ue}from"./derivedTests/apply.js";import{isStdfBin as ze,isStdfCoord as ae,isStdfTestNumber as de,isStdfSite as Ge,STDF_BIN_MAX as qe,STDF_COORD_MAX as fe,STDF_TEST_NUM_MAX as Je,STDF_SITE_MAX as Qe}from"../core/stdf.js";import{hasAnyKey as Ze,maxOf as ee,minOf as le,modeOf as et}from"../core/utils.js";import{aggregateValues as ue,aggregateBinCounts as tt,stackHoldsMeasurements as nt,stackBinsAreData as it}from"../core/aggregates.js";import{normalizePassBins as ce}from"../core/passBins.js";import{defaultRingCount as te}from"../core/ringCount.js";import{applyValueFilter as st,mergeValueFilterTests as rt,valueFilterWarning as ot}from"./valueFilter.js";export function isParametricTest(n){return n?.testType!=="F"}export function isBuiltMap(n){return"wafer"in n&&"dies"in n&&"dataAxisFlip"in n}function at(n){const e=(i,a)=>({ringCount:i,ringCountWarning:{code:"analysis-option-corrected",severity:"warning",message:`ringCount=${String(n)} ${a} (using ${i}).`}});if(n===void 0)return{ringCount:te(),ringCountWarning:void 0};if(typeof n!="number"||!Number.isFinite(n))return e(te(),"is not a finite number");const t=Math.max(1,Math.round(n));return t===n?{ringCount:n,ringCountWarning:void 0}:e(t,"is not a whole number of at least 1")}function dt(n,e){const t=Array.isArray(n)?{}:n,i={hbin:0,sbin:0,siteNum:0,testValues:0,testPass:0};let a;const d=(u,C)=>{i[u]++,a??=`${u} ${JSON.stringify(C)}`},o={bins:0,positions:0,values:0,sites:0,orientation:0},r=new Set;let p=0;if(e){i.testValues+=e.wrongValues,i.testPass+=e.wrongVerdicts,e.example!==void 0&&(a??=e.example),o.values+=e.nonFinite;for(const u of e.badTestNumbers)r.add(u)}const h=u=>u==null?!0:typeof u!="number"?!1:Number.isNaN(u)?(p++,!1):ze(u)?!0:(o.bins++,!1);function l(u){const C=new Set,D=new Set;for(let S=0;S<u.length;S+=S<50?1:100){const N=u[S];if(!(N===null||typeof N!="object")){if(N.testValues&&typeof N.testValues=="object")for(const M of Object.keys(N.testValues))C.add(M);if(N.testPass&&typeof N.testPass=="object")for(const M of Object.keys(N.testPass))D.add(M)}}const g=[...C],b=[...D],k=S=>de(Number(S));for(const S of new Set([...g,...b]))k(S)||r.add(S);const R=g.map(k),v=b.map(k),F=g.map(Number),L=b.map(Number);let K;for(let S=0;S<u.length;S++){const N=u[S];if(N===null||typeof N!="object")continue;const M=N;let E;const $=()=>E??={...M};M.hbin!=null&&typeof M.hbin!="number"&&d("hbin",M.hbin),M.sbin!=null&&typeof M.sbin!="number"&&d("sbin",M.sbin),h(M.hbin)||($().hbin=void 0),h(M.sbin)||($().sbin=void 0);const Y=typeof M.x=="number"&&!ae(M.x),j=typeof M.y=="number"&&!ae(M.y);if(Y||j){o.positions+=(Y?1:0)+(j?1:0);const s=$();s.x=void 0,s.y=void 0}M.siteNum!=null&&typeof M.siteNum!="number"?(d("siteNum",M.siteNum),$().siteNum=void 0):typeof M.siteNum=="number"&&!Ge(M.siteNum)&&(o.sites++,$().siteNum=void 0);const P=M.testValues;if(P&&typeof P=="object"){let s;for(let x=0;x<g.length;x++){const A=g[x],O=P[F[x]];if(O!=null){if(!R[x]){s??={...P},delete s[A];continue}typeof O!="number"?(d("testValues",O),s??={...P},delete s[A]):Number.isFinite(O)||(o.values++,s??={...P},delete s[A])}}s&&($().testValues=s)}const W=M.testPass;if(W&&typeof W=="object"){let s;for(let x=0;x<b.length;x++){const A=b[x],O=W[L[x]];if(O!=null){if(!v[x]){s??={...W},delete s[A];continue}typeof O!="boolean"&&(d("testPass",O),s??={...W},delete s[A])}}s&&($().testPass=s)}E&&((K??=u.slice())[S]=E)}return K}const f={warnings:[]};if(Array.isArray(n))f.results=l(n);else{Array.isArray(t.results)&&(f.results=l(t.results)),Array.isArray(t.dies)&&(f.dies=l(t.dies));const u=t.lotStack?.results;if(Array.isArray(u)){const C=u.map(D=>Array.isArray(D)?l(D):void 0);C.some(Boolean)&&(f.stackResults=C.map((D,g)=>D??u[g]))}}if(Array.isArray(t.testDefs)){const u=t.testDefs,C=u.filter(D=>D==null||typeof D.testNumber!="number"||de(D.testNumber));for(const D of u)C.includes(D)||r.add(String(D.testNumber));C.length!==u.length&&(f.testDefs=C)}const y=t.waferConfig?.orientation;if(typeof y=="number"){const u=Number.isFinite(y)?(y%360+360)%360:NaN;u===0||u===90||u===180||u===270?f.orientation=u:(o.orientation++,f.orientation=0)}const m=(u,C,D=`${C}s`)=>`${u} ${u===1?C:D}`,c=[];if(i.hbin&&c.push(m(i.hbin,"hard bin")),i.sbin&&c.push(m(i.sbin,"soft bin")),i.siteNum&&c.push(m(i.siteNum,"site number")),i.testValues&&c.push(m(i.testValues,"test value")),i.testPass&&c.push(m(i.testPass,"pass/fail verdict")),c.length){const u=`buildWaferMap received ${c.join(", ")} of the wrong type (for example ${a}), treated as missing. Bins, sites and test values must be numbers and verdicts true/false \u2014 a bin of "1" is not pass bin 1 \u2014 so those dies have no bin, no site, no value or no verdict, and yield and every chart leave them out. Convert them with Number() (and verdicts to booleans) and rebuild.`;console.warn(`[wafermap] ${u}`),f.warnings.push({code:"input-values-not-numbers",message:u,severity:"error"})}const w=[];if(o.bins&&w.push(`${m(o.bins,"bin")} (legal: whole numbers 0\u2013${qe}) \u2014 those dies have no bin`),o.positions&&w.push(`${m(o.positions,"coordinate")} (legal: whole numbers \u2212${fe} to ${fe}) \u2014 those dies have no position`),r.size&&w.push(`${m(r.size,"test number")} (legal: whole numbers 0\u2013${Je}) \u2014 those tests are left out`),o.values&&w.push(`${m(o.values,"test value")} that ${o.values===1?"is":"are"} not finite \u2014 left out`),o.sites&&w.push(`${m(o.sites,"site number")} (legal: 0\u2013${Qe}) \u2014 those dies have no site`),o.orientation&&w.push("a waferConfig.orientation other than 0, 90, 180 or 270 \u2014 the map is built at 0"),w.length||p){const u=[];w.length&&u.push(`buildWaferMap received values outside the STDF V4 ranges, treated as missing: ${w.join("; ")}.`),p&&u.push(`${m(p,"bin was","bins were")} NaN and ${p===1?"is":"are"} treated as no bin.`);const C=u.join(" ");console.warn(`[wafermap] ${C}`),f.warnings.push({code:"input-values-outside-stdf",message:C,severity:"warning"})}return f}function pe(n){const e=(h,l)=>h!==null&&typeof h=="object"&&h[l]!==void 0,t=Array.isArray(n)?{}:n,i=[],a=(h,l,f)=>{h&&i.push(`\`${l}\` (now \`${f}\`)`)};a(e(t,"data"),"data","results"),a(e(t,"die"),"die","dieConfig"),a(e(t,"stack"),"stack","lotStack"),a(e(t.dieConfig,"origin"),"dieConfig.origin","dieConfig.coordinateOrigin"),a(e(t.waferConfig,"flat"),"waferConfig.flat","waferConfig.notch"),a(e(t.reticleConfig,"anchor"),"reticleConfig.anchor","reticleConfig.anchorDie"),a(e(t.lotStack,"aggr"),"lotStack.aggr","lotStack.method"),a(Array.isArray(t.testDefs)&&t.testDefs.some(h=>e(h,"index")&&!e(h,"testNumber")),"TestDef.index","TestDef.testNumber");const d=e(t.lotStack,"results")?t.lotStack.results:[],o=(Array.isArray(n)?[n]:[t.results,...Array.isArray(d)?d:[]]).filter(h=>Array.isArray(h));if(a(o.some(h=>h.slice(0,100).some(l=>e(l,"values"))),"values","testValues"),!i.length)return;const r=i.length>1,p=`buildWaferMap ignored ${i.join(", ")}: ${r?"these names were":"that name was"} removed in an earlier release, so what ${r?"they":"it"} described is not on this map. Rename and rebuild.`;return console.warn(`[wafermap] ${p}`),{code:"input-field-removed",message:p,severity:"error"}}function ft(n){if(n.results!==void 0||n.lotStack!==void 0)throw new Error("buildWaferMap: pass `layout`, `results` or `lotStack` \u2014 only one.");const e=n.waferConfig?.diameter,t=n.dieConfig?.width,i=n.dieConfig?.height;if(!(e>0&&t>0&&i>0))throw new Error("buildWaferMap: `layout` needs waferConfig.diameter and dieConfig.width and height, all positive.");const a=Q({diameter:e,notch:n.waferConfig?.notch,orientation:0}),d=ke(Oe(a,{width:t,height:i}),a,{width:t,height:i}).filter(l=>!l.partial),{flipX:o,flipY:r}=me(n.dieConfig,{type:"center"}),{layout:p,...h}=n;return{...h,results:d.map(l=>({x:o?-l.x:l.x,y:r?-l.y:l.y})),waferConfig:{...n.waferConfig,center:{x:0,y:0}},dieConfig:{...n.dieConfig,coordinateOrigin:{type:"center"}}}}function lt(n){if(!Array.isArray(n)&&"results"in n&&n.results!==void 0&&"lotStack"in n&&n.lotStack!==void 0)throw new Error("buildWaferMap: pass either `results` or `lotStack`, not both.");const e={wrongVerdicts:0,wrongValues:0,nonFinite:0,badTestNumbers:[]},t=!Array.isArray(n)&&_e(n.results)?{...n,results:Pe(n.results,e).records}:n,i=dt(t,e);return Array.isArray(t)?{results:ne(i.results??t),waferOpts:void 0,dieOpts:void 0,explicitDies:void 0,reticleOpts:void 0,lotStackOpts:void 0,passBins:ce(void 0),ringCount:te(),valueFilter:"validity",ringCountWarning:void 0,removedFieldWarning:pe(t),inputValueWarnings:i.warnings,standardDiameters:void 0,testDefs:void 0,hbinDefs:void 0,sbinDefs:void 0,metadataFields:void 0,derivedTests:void 0,retestPolicy:"last",edgeDieYieldMode:"exclude"}:{results:ne(i.results??t.results??[]),waferOpts:i.orientation===void 0||t.waferConfig===void 0?t.waferConfig:{...t.waferConfig,orientation:i.orientation},dieOpts:t.dieConfig,explicitDies:i.dies??t.dies,reticleOpts:t.reticleConfig,lotStackOpts:t.lotStack?{...t.lotStack,results:(i.stackResults??t.lotStack.results).map(ne)}:void 0,passBins:ce(t.passBins),valueFilter:t.valueFilter??"validity",...at(t.ringCount),removedFieldWarning:pe(t),inputValueWarnings:i.warnings,standardDiameters:t.standardDiameters,testDefs:(i.testDefs??t.testDefs)?.length?i.testDefs??t.testDefs:void 0,hbinDefs:t.hbinDefs,sbinDefs:t.sbinDefs,metadataFields:t.metadataFields,derivedTests:t.derivedTests?.length?t.derivedTests:void 0,retestPolicy:t.retestPolicy??"last",edgeDieYieldMode:t.edgeDieYieldMode??"exclude"}}function ne(n){return n.length>0&&U(n[0])!==void 0?n:re(n).records}function ut(n,e){return e?.coordinateOrigin?e.coordinateOrigin:{type:"center"}}function ct(n,e,t){if(e.type==="custom"&&e.offset)return{offsetX:e.offset.x,offsetY:e.offset.y};if(e.type!=="center"){let i=1/0,a=-1/0,d=1/0,o=-1/0;for(const r of n)r.x<i&&(i=r.x),r.x>a&&(a=r.x),r.y<d&&(d=r.y),r.y>o&&(o=r.y);return{offsetX:Math.round((a+i)/2),offsetY:Math.round((o+d)/2)}}return{offsetX:t.offsetX,offsetY:t.offsetY}}function pt(n,e){if(n.length<xe)return!1;const t=he(n),i=(a,d,o)=>{const r=o-d+1;return a<d-r||a>o+r};return i(Math.round(e.x),t.xMin,t.xMax)||i(Math.round(e.y),t.yMin,t.yMax)}function he(n){let e=1/0,t=-1/0,i=1/0,a=-1/0;for(const d of n){const o=Math.round(d.x),r=Math.round(d.y);o<e&&(e=o),o>t&&(t=o),r<i&&(i=r),r>a&&(a=r)}return{xMin:e,xMax:t,yMin:i,yMax:a}}const ht="The supplied wafer centre";function mt(n,e){const t=he(n);return`${ht} (${e.x}, ${e.y}) is far outside the tested dies (X ${t.xMin}\u2026${t.xMax}, Y ${t.yMin}\u2026${t.yMax}), so it was ignored and the centre was worked out from the dies. Used as given, it would draw a wafer many times the size of the dies, with all of them in one corner.`}const gt="If the supplied centre is correct, also supply waferConfig.diameter.";function yt(n,e,t,i,a,d){if(d)return{colMidX:(Math.round(d.x)-e)*i,colMidY:(Math.round(d.y)-t)*a,anchored:!0};if(n.length===0)return{colMidX:0,colMidY:0,anchored:!1};let o=1/0,r=-1/0,p=1/0,h=-1/0;for(const l of n){const f=Math.round(l.x)-e,y=Math.round(l.y)-t;f<o&&(o=f),f>r&&(r=f),y<p&&(p=y),y>h&&(h=y)}return{colMidX:(o+r)/2*i,colMidY:(p+h)/2*a,anchored:!1}}function bt(n,e,t){let i=1/0,a=-1/0,d=1/0,o=-1/0,r=0,p=0;for(const f of n){const y=Math.round(f.x)-e,m=Math.round(f.y)-t;r+=y,p+=m,y<i&&(i=y),y>a&&(a=y),m<d&&(d=m),m>o&&(o=m)}const h=n.length,l=(f,y,m)=>{const c=(m-y)/2;return c<=0?0:Math.abs(f/h-(y+m)/2)/c};return l(r,i,a)>.11||l(p,d,o)>.11}function me(n,e){let t=n?.xAxisDirection==="left",i=n?.yAxisDirection==="down";return(e.type==="UL"||e.type==="UR")&&(i=!0),(e.type==="LR"||e.type==="UR")&&(t=!0),{flipX:t,flipY:i}}function wt(n){const e={...n};return delete e.limitLow,delete e.limitHigh,delete e.limitLowInclusive,delete e.limitHighInclusive,delete e.specLow,delete e.specHigh,e}function xt(n,e){const{method:t,targetBin:i}=n,a=n.results.map(d=>d.filter(I));if(t==="mean"||t==="median"||t==="stddev"||t==="min"||t==="max"||t==="count"){const d=new Set((e??[]).filter(l=>!isParametricTest(l)).map(l=>l.testNumber)),o=new Set;for(const l of a)for(const f of Te(l,"values"))d.has(f)||o.add(f);if(o.size===0)return ue(a,t);const r=[...o],p=r.map(l=>ue(a,t,l)),h=new Map;for(let l=0;l<r.length;l++){const f=r[l];for(const y of p[l]){const m=X(y);h.has(m)||h.set(m,{template:y,testValues:{}});const c=h.get(m),w=y.testValues?.[0];w!==void 0&&(c.testValues[f]=w)}}return[...h.values()].map(({template:l,testValues:f})=>({...l,testValues:Ze(f)?f:void 0}))}if(t==="countBin"||t==="percent"){if(i===void 0)return[];const d=tt(a,i,"hard");if(t==="countBin")return d;const o=a.length;return d.map(r=>({...r,testValues:{0:o>0?(r.testValues?.[0]??0)/o*100:0}}))}if(t==="mode"){const d=new Map;for(const r of a)for(const p of r){const h=X(p);d.has(h)||d.set(h,[]),d.get(h).push(p)}const o=[];for(const[r,p]of d){const h=r.split(","),l=Number(h[0]),f=Number(h[1]),y=p.map(c=>c.hbin).filter(c=>c!==void 0),m=et(y);m!==null&&o.push({x:l,y:f,hbin:m})}return o}return[]}export function computeCoverage(n){const e=n.filter(I),t=e.length,i=e.filter(d=>d.edgeExcluded).length,a=e.filter(d=>d.hbin!==void 0||d.sbin!==void 0||dieHasTestData(d)).length;return{filledDies:a,totalDies:t,edgeExcludedDies:i,unpositionedDies:n.length-e.length,ratio:t>0?a/t:0}}export function computeYield(n,e,t="exclude",i=!0){const a=new Set(e),o=n.filter(c=>!c.partial).filter(c=>c.edgeExcluded&&!c.filteredOut).length,r=n.filter(c=>c.partial).length;if(!i)return{passDies:0,failDies:0,edgeExcludedDies:o,partialDies:r,totalDies:0,yieldPercent:null,yieldPercentGross:null};let p=0,h=0,l=!1;for(const c of n){if(!ve(c))continue;const w=c.hbin??c.sbin;w!==void 0&&(l=!0,a.has(w)?p++:h++)}const f=p+h,y=l&&f>0?p/f*100:null;let m=null;if(t==="denominator-only"){const c=f+o;m=l&&c>0?p/c*100:null}return{passDies:p,failDies:h,edgeExcludedDies:o,partialDies:r,totalDies:f,yieldPercent:y,yieldPercentGross:m}}function ge(n,e,t,i,a,d=0,o=0,r=0,p=0,h=0,l=!1,f=!1){if(!n)return[];const y=n.anchorDie??{x:0,y:0},m=He(e,{width:n.width,height:n.height,diePitchX:i,diePitchY:a,anchorDie:{x:y.x-d,y:y.y-o},gridOrigin:{x:-r,y:-p}}),c=Le(Ve(l,f,e.center.x,e.center.y),Be(h,e.center.x,e.center.y));return m.filter(w=>{const u=w.width/2,C=w.height/2,D=[[w.x-u,w.y-C],[w.x+u,w.y-C],[w.x+u,w.y+C],[w.x-u,w.y+C]].map(([v,F])=>Ye(c,v,F)),g=le(D.map(v=>v.x)),b=ee(D.map(v=>v.x)),k=le(D.map(v=>v.y)),R=ee(D.map(v=>v.y));return t.some(v=>v.physX>=g&&v.physX<b&&v.physY>=k&&v.physY<R)})}function Dt(n,e,t){const a=Math.max(0,e.radius-t)**2;return n.map(d=>{const o=d.physX-e.center.x,r=d.physY-e.center.y;return o*o+r*r>a?{...d,edgeExcluded:!0}:d})}const Mt=.2;function vt(n){const e=new Set;for(const t of n){if(t.supersedes!==void 0||!I(t))return!1;const i=Se(t);if(e.has(i))return!1;e.add(i)}return!0}function St(n,e,t){if(vt(n))return{results:n.slice(),warning:void 0};const i=new Set(t);function a(g,b){if(e==="last")return!0;if(e==="first")return!1;const k=G(g.hbin),R=G(b.hbin);if(k===void 0||R===void 0)return!1;const v=i.has(k),F=i.has(R);return e==="best"?F!==v?F:R<k:F!==v?v:R>k}const d=(g,b)=>b.supersedes!==void 0||a(g,b),o=g=>{const b=g.partId===void 0?"":String(g.partId).trim();return b===""?void 0:b},r=n.filter(g=>!I(g)),p=new Map;for(const g of r){const b=o(g);b!==void 0&&p.set(b,(p.get(b)??0)+1)}const l=(r.length===0?0:Math.max(0,...p.values())/r.length)<=Mt,f=new Map,y=[],m=new Map;let c=0,w=0;for(const g of n){const b=o(g);let k;if(I(g)?k=`p:${X(g)}`:l&&b!==void 0?k=`i:${b}`:k=`u:${w++}`,g.supersedes==="partId"&&b!==void 0){const v=m.get(b);v!==void 0&&v!==k&&f.has(v)&&f.delete(v)}const R=f.get(k);R===void 0?(f.set(k,{winner:g,count:1}),y.push(k)):(R.count++,k.startsWith("i:")&&c++,d(R.winner,g)&&(R.winner=g)),b!==void 0&&m.set(b,k)}const u=[],C=[...y.filter(g=>g.startsWith("p:")),...y.filter(g=>!g.startsWith("p:"))];for(const g of C){const b=f.get(g);b!==void 0&&u.push(b.count>1?{...b.winner,retestCount:b.count}:b.winner)}const D=c>0?{code:"retests-by-part-id",severity:"info",message:`${c} record${c===1?"":"s"} with no position shared a part ID with an earlier record and ${c===1?"was":"were"} treated as a retest of it.`}:void 0;return{results:u,warning:D}}export function getDieTestValue(n,e){return Z(n,e)}export function getTestPassStatus(n,e,t){const i=Ne(n,e);return i!==void 0?i:t!==void 0&&!isParametricTest(t)?ye(Z(n,e)):void 0}function ye(n){return n===0||n===1?n===1:void 0}export function testPassStatusReader(n){const e=n.map(a=>a.testNumber),t=Re(e),i=n.map(a=>!isParametricTest(a));return function(d,o){t(d,o);for(let r=0;r<o.length;r++){if(o[r]!==Ie||!i[r])continue;const p=ye(Z(d,e[r]));p!==void 0&&(o[r]=p?We:Fe)}return o}}export function dieHasTestData(n){return Ae(n)}function G(n){return n===void 0||Number.isNaN(n)?void 0:n}function q(n,e){const t={},i=G(e.hbin),a=G(e.sbin);i!==void 0&&(t.hbin=i),a!==void 0&&(t.sbin=a),e.retestCount!==void 0&&(t.retestCount=e.retestCount),e.siteNum!==void 0&&(t.siteNum=e.siteNum),e.partId!==void 0&&(t.partId=e.partId),e.metadata!==void 0&&(t.metadata=e.metadata);const d=U(e);return $e({...n,...t},d.table,d.row)}function be(n){return n.some(dieHasTestData)?"value":defaultBinMode([n])}export function defaultBinMode(n){const e=t=>n.some(i=>i.some(a=>t(a)!=null));return e(t=>t.hbin)?"hardBin":e(t=>t.sbin)?"softBin":"hardBin"}function we(n,e){return n.map(({code:t,message:i})=>({code:t,message:i,severity:t==="non-standard-diameter"||t==="diameter-exceeds-die-extent"||t==="implausible-center"?"warning":"error",confidence:e.wafer.confidence}))}const Ct="do not fit inside the supplied",kt="Inferred wafer diameter",Ot="The probed dies reach only",At=.75,xe=20;export const STANDARD_WAFER_DIAMETERS_MM=[100,125,150,200,300];const $t=.02;function De(n,e){return e.reduce((t,i)=>Math.abs(i-n)<Math.abs(t-n)?i:t)}function Nt(n,e){if(!e.length)return!0;const t=De(n,e);return Math.abs(t-n)/t<=$t}function Rt(n){return n===void 0?STANDARD_WAFER_DIAMETERS_MM:n.filter(e=>Number.isFinite(e)&&e>0)}export function buildWaferMap(n){const e=lt(!Array.isArray(n)&&n.layout?ft(n):n),t=[];let i;if(e.valueFilter!=="none"&&e.testDefs){const s=e.valueFilter,x=(e.lotStackOpts?e.lotStackOpts.results:[e.results]).map(O=>{const _=O.length>0?U(O[0]):void 0;if(!_)return[];const T=st(_.table,e.testDefs,s);return T.tests.length>0&&oe(O,T.table),T.tests}),A=rt(x);if(A.length>0){i={mode:s,tests:A};const O=ot(s,A,e.testDefs);O&&t.push(O)}}if(e.derivedTests){const s=new Set(e.passBins),x=_=>{const T=_.length>0?U(_[0]):void 0,H=Ue(_,T?.table??Ee([]),e.testDefs,e.derivedTests,s);return T&&oe(_,H.table),H},O=(e.lotStackOpts?e.lotStackOpts.results:[e.results]).map(x);e.testDefs=O[0]?.testDefs??e.testDefs,t.push(...O[0]?.warnings??[])}e.lotStackOpts&&!nt(e.lotStackOpts.method)&&(e.testDefs=e.testDefs?.map(wt));const a=e.lotStackOpts?re(xt(e.lotStackOpts,e.testDefs)).records:e.results;for(let s=0;s<Math.min(5,a.length);s++){const x=a[s];if(typeof x.x=="string"||typeof x.y=="string")throw new TypeError("buildWaferMap: x and y must be numbers, received strings. Did you forget to cast CSV values? e.g. { x: +row.x, y: +row.y }")}for(const s of a)if(s.x==null!=(s.y==null))throw new TypeError(`buildWaferMap: die has only one of x/y set (x=${String(s.x)}, y=${String(s.y)}). A die must be either fully positioned (both x and y) or fully unpositioned (neither) \u2014 omit both to mark a die as having no reported position.`);const{results:d,warning:o}=St(a,e.retestPolicy,e.passBins),r={wafer:{confidence:1,method:"provided"},diePitch:{confidence:1,units:"mm"},grid:{confidence:1}},p=[];if(e.explicitDies){let s=e.explicitDies.filter(I);const x=e.explicitDies.filter(V=>!I(V)),A=d.filter(I),O=d.filter(V=>!I(V));if(A.length>0){const V=new Map(A.map(B=>[X(B),B]));s=s.map(B=>{const ie=V.get(X(B));return ie?q(B,ie):B})}const _=e.waferOpts?.diameter??300,T=Q({diameter:_,notch:e.waferOpts?.notch,orientation:e.waferOpts?.orientation??0,metadata:e.waferOpts?.metadata,reticle:e.reticleOpts});T.orientation!==0&&(s=se(s,T)),s=s.map(z);const H=ge(e.reticleOpts,T,s,s[0]?.width??1,s[0]?.height??1,0,0,0,0,T.orientation),Me=O.map((V,B)=>z(q({id:`unpositioned_${B}`,width:s[0]?.width??1,height:s[0]?.height??1},V))),J=[...s,...x,...Me];return{wafer:T,dies:J,dataAxisFlip:{x:!1,y:!1},reticleConfig:e.reticleOpts,units:"mm",inference:r,warnings:[...e.removedFieldWarning?[e.removedFieldWarning]:[],...e.inputValueWarnings,...o?[o]:[],...we(p,r),...t,...e.ringCountWarning?[e.ringCountWarning]:[]],plotMode:be(d),metadata:T.metadata??null,isLotStack:!1,dataCoverage:computeCoverage(J),passBins:e.passBins,...i?{valueFilter:i}:{},ringCount:e.ringCount,yield:computeYield(J,e.passBins,e.edgeDieYieldMode),reticles:H,hbinDefs:e.hbinDefs,sbinDefs:e.sbinDefs,testDefs:e.testDefs,metadataFields:e.metadataFields}}const h=d.filter(I),l=d.filter(s=>!I(s)),f=h.map(s=>({x:s.x,y:s.y})),y=Ke(f,e.dieOpts,e.waferOpts?.diameter);r.diePitch={confidence:y.confidence,units:y.units};const{pitchX:m,pitchY:c}=y,w=y.units,u=ut(h,e.dieOpts),C=je(f);r.grid={confidence:C.confidence};const{offsetX:D,offsetY:g}=ct(f,u,C),{flipX:b,flipY:k}=me(e.dieOpts,u),R=e.waferOpts?.diameter===void 0&&e.waferOpts?.center!==void 0&&pt(f,e.waferOpts.center),v=R?void 0:e.waferOpts?.center;if(R){const s=mt(f,e.waferOpts.center);console.warn(`[wafermap] ${s} ${gt}`),p.push({code:"implausible-center",message:s})}const{colMidX:F,colMidY:L,anchored:K}=yt(f,D,g,m,c,v);let S=e.waferOpts?.diameter;const N=f.map(s=>({x:(Math.round(s.x)-D)*m-F,y:(Math.round(s.y)-g)*c-L})),M=ee(N.map(({x:s,y:x})=>Math.hypot(Math.abs(s)+m/2,Math.abs(x)+c/2)));if(S===void 0)if(f.length>0)if(w==="mm"){const s=Xe(N,{minRadius:M});S=s.diameter,r.wafer={confidence:s.confidence,method:s.method};const x=Rt(e.standardDiameters);if(!Nt(S,x)){const A=De(S,x);p.push({code:"non-standard-diameter",message:`${kt} ${S.toFixed(1)} mm is not a standard wafer size (nearest is ${A} mm). The diameter was derived from the die extent, which assumes the probed grid reaches the wafer edge \u2014 a non-standard result usually means it does not, because the outer dies were never probed. Every die is then placed against a wafer that is too small, which moves dies between rings and changes ring and edge findings. Supply waferConfig.diameter.`})}}else S=M*2,r.wafer={confidence:y.confidence*.8,method:"extent"};else S=w==="mm"?300:30,r.wafer={confidence:0,method:"default"};if(!K&&f.length>0&&bt(f,D,g)&&(r.wafer.method="inferred-partial",p.push({code:"partial-coverage",message:"Wafer geometry was inferred from die positions alone. The data does not span a full symmetric wafer, so the inferred diameter and centre may be wrong and dies may be mis-positioned relative to the true wafer boundary. Supply waferConfig.diameter and waferConfig.center (the prober coordinate of the wafer centre) to position partial data correctly."})),e.waferOpts?.diameter!==void 0&&v===void 0&&M>0&&f.length>=xe){const s=M/(S/2);s<At&&p.push({code:"diameter-exceeds-die-extent",message:`${Ot} ${(s*100).toFixed(0)}% of the ${S} mm wafer's radius. Either the diameter is larger than the real one, or this is a partial map covering only part of the wafer. Ring bands are equal-radius, so the outer rings are mostly or entirely empty and ring, quadrant and edge findings describe the assumed wafer rather than the probed area. Check waferConfig.diameter, or drop it and let the diameter be inferred from the die extent.`})}if(e.waferOpts?.diameter!==void 0){const s=e.dieOpts?.width!==void 0&&e.dieOpts?.height!==void 0;if(s&&M>S/2+1e-9){const x=N.filter(({x:A,y:O})=>Math.hypot(Math.abs(A)+m/2,Math.abs(O)+c/2)>S/2+1e-9).length;p.push({code:"geometry-conflict",message:`${x} of ${N.length} probed die positions ${Ct} ${S} mm wafer at the supplied die pitch of ${m} \xD7 ${c} mm. A die with test results is a real prober position and is always fully on the wafer, so one of the two supplied values must be wrong: containing these dies at this pitch would need a diameter of at least ${(M*2).toFixed(1)} mm. Check waferConfig.diameter and dieConfig.width/height against the real device.`})}}const E=Q({diameter:S,units:w,notch:e.waferOpts?.notch,orientation:e.waferOpts?.orientation??0,metadata:e.waferOpts?.metadata,reticle:e.reticleOpts});let $=h.map(s=>{const x=Math.round(s.x)-D,A=Math.round(s.y)-g,O={id:`${x}_${A}`,x,y:A,physX:x*m-F,physY:A*c-L,width:m,height:c,insideWafer:!0,partial:!1};return q(O,s)});(D!==0||g!==0)&&($=$.map(s=>({...s,x:s.x+D,y:s.y+g,id:`${s.x+D}_${s.y+g}`}))),$=se($,E),(b||k)&&($=Ce($,{flipX:b,flipY:k},E.center));const Y=[];e.waferOpts?.edgeExclusion&&e.waferOpts.edgeExclusion>0&&($=Dt($,E,e.waferOpts.edgeExclusion),e.waferOpts.edgeExclusion>E.radius&&Y.push({code:"edge-exclusion-exceeds-radius",message:`edgeExclusion (${e.waferOpts.edgeExclusion}mm) exceeds the resolved wafer radius (${E.radius}mm) \u2014 the entire wafer is excluded.`,severity:"warning"})),$=$.map(z);const j=ge(e.reticleOpts,E,$,m,c,D,g,F,L,E.orientation,b,k),P=l.map((s,x)=>z(q({id:`unpositioned_${x}`,width:m,height:c},s))),W=[...$,...P];return{wafer:E,dies:W,dataAxisFlip:{x:b,y:k},reticleConfig:e.reticleOpts,units:w,inference:r,warnings:[...e.removedFieldWarning?[e.removedFieldWarning]:[],...e.inputValueWarnings,...o?[o]:[],...we(p,r),...Y,...t,...e.ringCountWarning?[e.ringCountWarning]:[]],plotMode:be(d),metadata:E.metadata??null,isLotStack:e.lotStackOpts!==void 0,dataCoverage:computeCoverage(W),passBins:e.passBins,...i?{valueFilter:i}:{},ringCount:e.ringCount,yield:computeYield(W,e.passBins,e.edgeDieYieldMode,it(e.lotStackOpts!==void 0,e.lotStackOpts?.method)),reticles:j,hbinDefs:e.hbinDefs,sbinDefs:e.sbinDefs,testDefs:e.testDefs,metadataFields:e.metadataFields,aggrMethod:e.lotStackOpts?.method,lotSize:e.lotStackOpts?.results.length}}
@@ -21,6 +21,7 @@
21
21
  * with no further change.
22
22
  */
23
23
  import type { DieResult, TestDef, WaferWarning } from '../buildWaferMap.js';
24
+ import { type ExprNode } from './parser.js';
24
25
  import type { DieTable } from '../../core/dieTable.js';
25
26
  /**
26
27
  * A test whose values are computed from other tests on the same die, rather than
@@ -77,6 +78,15 @@ export interface ApplyResult {
77
78
  testDefs: TestDef[] | undefined;
78
79
  warnings: WaferWarning[];
79
80
  }
81
+ /**
82
+ * Unit agreement across `+` and `-`. The library knows the units, so staying
83
+ * silent about a volts-minus-amps subtraction would be exactly the kind of
84
+ * unlabelled nonsense the design principles forbid. It is a warning rather than
85
+ * a rejection: unit strings are free text and a site may legitimately use
86
+ * `"uA"` and `"µA"` for the same thing, so refusing to build would be worse than
87
+ * saying so.
88
+ */
89
+ export declare function unitMismatch(node: ExprNode, defs: Map<number, TestDef>): string[];
80
90
  /**
81
91
  * Apply `derivedTests` to a wafer's records: `records[i]` is row `i` of
82
92
  * `table` (its bins give `diePass()`). Returns a copy of the table with a
@@ -1 +1 @@
1
- import{isStdfTestNumber as D,STDF_TEST_NUM_MAX as T}from"../../core/stdf.js";import{diePassStatus as M}from"../../core/dies.js";import{getTestPassStatus as F,isParametricTest as V}from"../buildWaferMap.js";import{classifySpec as _}from"../spec.js";import{parseExpression as P}from"./parser.js";import{evaluate as A}from"./evaluate.js";import{extendTable as E,rowView as O,testValue as I,HAS_VALUES as k,HAS_VERDICTS as C,VERDICT_FAIL as L,VERDICT_NONE as S,VERDICT_PASS as R}from"../../core/dieTable.js";function l(w){return{code:"derived-test-invalid",message:w,severity:"warning"}}function j(w,p){const m=[],n=r=>{switch(r.k){case"acc":{if(r.kind!=="t")return;const o=p.get(r.test)?.unit;return o?new Set([o]):void 0}case"unary":return r.op==="-"?n(r.arg):void 0;case"binary":{const o=n(r.left),a=n(r.right);if(r.op==="+"||r.op==="-"){if(o&&a){const d=new Set([...o,...a]);return d.size>1&&m.push(`${[...d].join(" and ")} are combined by "${r.op}"`),d}return o??a}return}case"call":{if(r.name==="min"||r.name==="max"||r.name==="mean"||r.name==="sum"){const o=r.args[0];if(o?.k==="vec"&&o.kind==="t"){const a=new Set(o.tests.map(d=>p.get(d)?.unit).filter(d=>!!d));return a.size>1&&m.push(`${[...a].join(" and ")} are combined by "${r.name}"`),a}}return}default:return}};return n(w),m}function B(w,p,m){const n=[],r=new Map((p??[]).map(e=>[e.testNumber,e])),o=e=>`${JSON.stringify(e.name??"")} (test ${e.testNumber})`,a=[],d=new Set;for(const e of w){const s=o(e);if(!D(e.testNumber)){n.push(l(`Derived test ${s} was dropped: \`testNumber\` must be a whole number from 0 to ${T}, as STDF stores it.`));continue}if(m.has(e.testNumber)||r.has(e.testNumber)){n.push(l(`Derived test ${s} was dropped: test number ${e.testNumber} already exists in the data. Measured values are never replaced by a derived test \u2014 give it an unused number.`));continue}if(d.has(e.testNumber)){n.push(l(`Derived test ${s} was dropped: test number ${e.testNumber} is used by an earlier derived test.`));continue}if(typeof e.expression!="string"||e.expression.trim()===""){n.push(l(`Derived test ${s} was dropped: \`expression\` is empty.`));continue}d.add(e.testNumber),a.push(e)}const g=new Map(r);for(const e of a){const{expression:s,constants:u,...c}=e;g.set(e.testNumber,{...c,testType:e.testType??"P"})}const h=new Map,f=new Set;for(const e of a){const s=o(e),u={testDefs:g,constants:e.constants??{}},c=P(e.expression,u);if(!c.ok){n.push(l(`Derived test ${s} was dropped: ${c.message}`)),f.add(e.testNumber);continue}const t=c.type==="boolean",i=!V(e);if(t!==i){n.push(l(t?`Derived test ${s} was dropped: its expression produces a true/false verdict, so it must declare \`testType: 'F'\`.`:`Derived test ${s} was dropped: it declares \`testType: 'F'\` but its expression produces a number. Functional tests carry a verdict, not a measurement.`)),f.add(e.testNumber);continue}if(t&&(e.limitLow!==void 0||e.limitHigh!==void 0)&&n.push(l(`Derived test ${s}: test limits are ignored on a true/false derived test.`)),e.testNumber===void 0)continue;const N=e.testNumber,x=[...new Set(c.reads.map(v=>v.test))].filter(v=>v!==N&&d.has(v));if(c.reads.some(v=>v.test===N)){n.push(l(`Derived test ${s} was dropped: its expression reads itself.`)),f.add(N);continue}for(const v of j(c.ast,g))n.push(l(`Derived test ${s} combines different units \u2014 ${v}. The result is computed as written; set \`unit\` on the derived test to say what it is.`));h.set(N,{raw:e,compiled:{def:{...e,testType:t?"F":"P",derived:!0},ast:c.ast,boolean:t},deps:x})}const y=[],b=new Map,$=(e,s)=>{if(b.get(e)==="done")return!f.has(e);if(b.get(e)==="visiting"){const t=[...s.slice(s.indexOf(e)),e].join(" \u2192 ");for(const i of s.slice(s.indexOf(e)))f.has(i)||(f.add(i),n.push(l(`Derived test ${o(h.get(i).raw)} was dropped: its expression depends on itself through ${t}.`)));return!1}const u=h.get(e);if(u===void 0)return!1;b.set(e,"visiting");let c=!0;for(const t of u.deps)if(!$(t,[...s,e])){if(!f.has(e)){f.add(e);const i=h.get(t)?.raw.name??`test ${t}`;n.push(l(`Derived test ${o(u.raw)} was dropped: it reads ${JSON.stringify(i)} (test ${t}), which was itself dropped.`))}c=!1;break}return b.set(e,"done"),!c||f.has(e)?!1:(y.push(u.compiled),!0)};for(const e of a)$(e.testNumber,[]);return{compiled:y,warnings:n}}export function applyDerivedTests(w,p,m,n,r){if(n===void 0||n.length===0)return{table:p,testDefs:m,warnings:[]};const o=new Set;for(const[e,s]of p.values)s.some(u=>!Number.isNaN(u))&&o.add(e);for(const[e,s]of p.verdicts)s.some(u=>u!==S)&&o.add(e);const{compiled:a,warnings:d}=B(n,m,o);if(a.length===0)return{table:p,testDefs:m,warnings:d};const g=new Map((m??[]).map(e=>[e.testNumber,e]));for(const e of a)g.set(e.def.testNumber,e.def);const h=p.rows,f=new Map,y=new Map;for(const e of a)e.boolean?y.set(e.def.testNumber,new Int8Array(h).fill(S)):f.set(e.def.testNumber,new Float64Array(h).fill(NaN));const b=E(p,f,y),$=O(b);for(let e=0;e<h;e++){const s=$(e),u=t=>I(s,t),c={value:u,testPass:t=>F(s,t,g.get(t)),specPass:t=>{const i=_(u(t),g.get(t));return i===null?void 0:i==="pass"},diePass:()=>M(w[e],r),field:t=>{const i=w[e],N=t==="x"?i.x:t==="y"?i.y:t==="hbin"?i.hbin:t==="sbin"?i.sbin:i.siteNum;return typeof N=="number"&&Number.isFinite(N)?N:void 0}};for(const t of a){const i=A(t.ast,c);i!==void 0&&(t.boolean?(y.get(t.def.testNumber)[e]=i?R:L,b.fields[e]|=C):(f.get(t.def.testNumber)[e]=i,b.fields[e]|=k))}}return{table:b,testDefs:[...m??[],...a.map(e=>e.def)],warnings:d}}
1
+ import{isStdfTestNumber as D,STDF_TEST_NUM_MAX as T}from"../../core/stdf.js";import{diePassStatus as M}from"../../core/dies.js";import{getTestPassStatus as F,isParametricTest as V}from"../buildWaferMap.js";import{classifySpec as _}from"../spec.js";import{parseExpression as P}from"./parser.js";import{evaluate as A}from"./evaluate.js";import{extendTable as E,rowView as O,testValue as I,HAS_VALUES as k,HAS_VERDICTS as C,VERDICT_FAIL as L,VERDICT_NONE as S,VERDICT_PASS as R}from"../../core/dieTable.js";function l(w){return{code:"derived-test-invalid",message:w,severity:"warning"}}export function unitMismatch(w,p){const m=[],n=r=>{switch(r.k){case"acc":{if(r.kind!=="t")return;const o=p.get(r.test)?.unit;return o?new Set([o]):void 0}case"unary":return r.op==="-"?n(r.arg):void 0;case"binary":{const o=n(r.left),a=n(r.right);if(r.op==="+"||r.op==="-"){if(o&&a){const d=new Set([...o,...a]);return d.size>1&&m.push(`${[...d].join(" and ")} are combined by "${r.op}"`),d}return o??a}return}case"call":{if(r.name==="min"||r.name==="max"||r.name==="mean"||r.name==="sum"){const o=r.args[0];if(o?.k==="vec"&&o.kind==="t"){const a=new Set(o.tests.map(d=>p.get(d)?.unit).filter(d=>!!d));return a.size>1&&m.push(`${[...a].join(" and ")} are combined by "${r.name}"`),a}}return}default:return}};return n(w),m}function j(w,p,m){const n=[],r=new Map((p??[]).map(e=>[e.testNumber,e])),o=e=>`${JSON.stringify(e.name??"")} (test ${e.testNumber})`,a=[],d=new Set;for(const e of w){const s=o(e);if(!D(e.testNumber)){n.push(l(`Derived test ${s} was dropped: \`testNumber\` must be a whole number from 0 to ${T}, as STDF stores it.`));continue}if(m.has(e.testNumber)||r.has(e.testNumber)){n.push(l(`Derived test ${s} was dropped: test number ${e.testNumber} already exists in the data. Measured values are never replaced by a derived test \u2014 give it an unused number.`));continue}if(d.has(e.testNumber)){n.push(l(`Derived test ${s} was dropped: test number ${e.testNumber} is used by an earlier derived test.`));continue}if(typeof e.expression!="string"||e.expression.trim()===""){n.push(l(`Derived test ${s} was dropped: \`expression\` is empty.`));continue}d.add(e.testNumber),a.push(e)}const g=new Map(r);for(const e of a){const{expression:s,constants:u,...c}=e;g.set(e.testNumber,{...c,testType:e.testType??"P"})}const h=new Map,f=new Set;for(const e of a){const s=o(e),u={testDefs:g,constants:e.constants??{}},c=P(e.expression,u);if(!c.ok){n.push(l(`Derived test ${s} was dropped: ${c.message}`)),f.add(e.testNumber);continue}const t=c.type==="boolean",i=!V(e);if(t!==i){n.push(l(t?`Derived test ${s} was dropped: its expression produces a true/false verdict, so it must declare \`testType: 'F'\`.`:`Derived test ${s} was dropped: it declares \`testType: 'F'\` but its expression produces a number. Functional tests carry a verdict, not a measurement.`)),f.add(e.testNumber);continue}if(t&&(e.limitLow!==void 0||e.limitHigh!==void 0)&&n.push(l(`Derived test ${s}: test limits are ignored on a true/false derived test.`)),e.testNumber===void 0)continue;const N=e.testNumber,x=[...new Set(c.reads.map(v=>v.test))].filter(v=>v!==N&&d.has(v));if(c.reads.some(v=>v.test===N)){n.push(l(`Derived test ${s} was dropped: its expression reads itself.`)),f.add(N);continue}for(const v of unitMismatch(c.ast,g))n.push(l(`Derived test ${s} combines different units \u2014 ${v}. The result is computed as written; set \`unit\` on the derived test to say what it is.`));h.set(N,{raw:e,compiled:{def:{...e,testType:t?"F":"P",derived:!0},ast:c.ast,boolean:t},deps:x})}const y=[],b=new Map,$=(e,s)=>{if(b.get(e)==="done")return!f.has(e);if(b.get(e)==="visiting"){const t=[...s.slice(s.indexOf(e)),e].join(" \u2192 ");for(const i of s.slice(s.indexOf(e)))f.has(i)||(f.add(i),n.push(l(`Derived test ${o(h.get(i).raw)} was dropped: its expression depends on itself through ${t}.`)));return!1}const u=h.get(e);if(u===void 0)return!1;b.set(e,"visiting");let c=!0;for(const t of u.deps)if(!$(t,[...s,e])){if(!f.has(e)){f.add(e);const i=h.get(t)?.raw.name??`test ${t}`;n.push(l(`Derived test ${o(u.raw)} was dropped: it reads ${JSON.stringify(i)} (test ${t}), which was itself dropped.`))}c=!1;break}return b.set(e,"done"),!c||f.has(e)?!1:(y.push(u.compiled),!0)};for(const e of a)$(e.testNumber,[]);return{compiled:y,warnings:n}}export function applyDerivedTests(w,p,m,n,r){if(n===void 0||n.length===0)return{table:p,testDefs:m,warnings:[]};const o=new Set;for(const[e,s]of p.values)s.some(u=>!Number.isNaN(u))&&o.add(e);for(const[e,s]of p.verdicts)s.some(u=>u!==S)&&o.add(e);const{compiled:a,warnings:d}=j(n,m,o);if(a.length===0)return{table:p,testDefs:m,warnings:d};const g=new Map((m??[]).map(e=>[e.testNumber,e]));for(const e of a)g.set(e.def.testNumber,e.def);const h=p.rows,f=new Map,y=new Map;for(const e of a)e.boolean?y.set(e.def.testNumber,new Int8Array(h).fill(S)):f.set(e.def.testNumber,new Float64Array(h).fill(NaN));const b=E(p,f,y),$=O(b);for(let e=0;e<h;e++){const s=$(e),u=t=>I(s,t),c={value:u,testPass:t=>F(s,t,g.get(t)),specPass:t=>{const i=_(u(t),g.get(t));return i===null?void 0:i==="pass"},diePass:()=>M(w[e],r),field:t=>{const i=w[e],N=t==="x"?i.x:t==="y"?i.y:t==="hbin"?i.hbin:t==="sbin"?i.sbin:i.siteNum;return typeof N=="number"&&Number.isFinite(N)?N:void 0}};for(const t of a){const i=A(t.ast,c);i!==void 0&&(t.boolean?(y.get(t.def.testNumber)[e]=i?R:L,b.fields[e]|=C):(f.get(t.def.testNumber)[e]=i,b.fields[e]|=k))}}return{table:b,testDefs:[...m??[],...a.map(e=>e.def)],warnings:d}}
@@ -0,0 +1,35 @@
1
+ import type { TestDef } from '../buildWaferMap.js';
2
+ import { type AccessorKind } from './parser.js';
3
+ import { type DerivedTestDef } from './apply.js';
4
+ export interface DerivedCheckInput {
5
+ expression: string;
6
+ /** The number the derived test will have; a derived test may not read itself. */
7
+ testNumber: number;
8
+ /** The declared kind. Omitted: not checked against what the expression produces. */
9
+ testType?: 'P' | 'F';
10
+ constants?: Record<string, number>;
11
+ }
12
+ export type DerivedCheck = {
13
+ ok: true;
14
+ /** What the expression produces: a measurement, or a true/false verdict (which needs `testType: 'F'`). */
15
+ produces: 'number' | 'verdict';
16
+ /** Every test the expression reads, and how, in order of appearance. */
17
+ reads: {
18
+ kind: AccessorKind;
19
+ test: number;
20
+ }[];
21
+ /** Advice that does not stop the test being built, such as units combined by `+`. */
22
+ warnings: string[];
23
+ } | {
24
+ ok: false;
25
+ message: string;
26
+ /** 0-based character offset into `expression`, when the problem has one. */
27
+ position?: number;
28
+ };
29
+ /**
30
+ * `testDefs` are the measured tests the expression may read; `otherDerived` are the host's *other* derived
31
+ * tests, which it may read too. The identity rules are the build's: a test number is a whole number from 0 to
32
+ * the STDF maximum, and neither a measured test nor another derived test may already have it.
33
+ */
34
+ export declare function checkDerivedExpression(input: DerivedCheckInput, testDefs: readonly TestDef[], otherDerived?: readonly DerivedTestDef[]): DerivedCheck;
35
+ //# sourceMappingURL=check.d.ts.map