@wafertools/wafermap 0.40.1 → 0.41.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.
- package/AGENTS.md +20 -21
- package/CHANGELOG.md +140 -0
- package/README.md +6 -6
- package/dist/packages/canvas-adapter/canvasTheme.d.ts +12 -0
- package/dist/packages/canvas-adapter/canvasTheme.js +1 -1
- package/dist/packages/canvas-adapter/cellShade.d.ts +2 -2
- package/dist/packages/canvas-adapter/cellShade.js +1 -1
- package/dist/packages/canvas-adapter/chartPopulation.d.ts +3 -0
- package/dist/packages/canvas-adapter/chartPopulation.js +1 -1
- package/dist/packages/canvas-adapter/charts/capability.d.ts +3 -0
- package/dist/packages/canvas-adapter/charts/capability.js +1 -1
- package/dist/packages/canvas-adapter/charts/cardAbout.d.ts +2 -1
- package/dist/packages/canvas-adapter/charts/cardAbout.js +1 -1
- package/dist/packages/canvas-adapter/charts/chartShell.d.ts +47 -27
- package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
- package/dist/packages/canvas-adapter/charts/commonality.js +4 -4
- package/dist/packages/canvas-adapter/charts/correlation.d.ts +6 -12
- package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
- package/dist/packages/canvas-adapter/charts/divergingScale.d.ts +45 -15
- package/dist/packages/canvas-adapter/charts/divergingScale.js +1 -1
- package/dist/packages/canvas-adapter/charts/groupComparison.js +1 -1
- package/dist/packages/canvas-adapter/charts/palette.d.ts +16 -30
- package/dist/packages/canvas-adapter/charts/palette.js +1 -1
- package/dist/packages/canvas-adapter/charts/patCard.js +1 -1
- package/dist/packages/canvas-adapter/charts/plotChart.d.ts +24 -1
- package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
- package/dist/packages/canvas-adapter/charts/regionYieldDiagram.d.ts +3 -0
- package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
- package/dist/packages/canvas-adapter/charts/sweep.d.ts +3 -0
- package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
- package/dist/packages/canvas-adapter/chromeRow.d.ts +68 -0
- package/dist/packages/canvas-adapter/chromeRow.js +1 -0
- package/dist/packages/canvas-adapter/chunked.d.ts +6 -0
- package/dist/packages/canvas-adapter/chunked.js +1 -1
- package/dist/packages/canvas-adapter/columnFilterPopup.d.ts +25 -0
- package/dist/packages/canvas-adapter/columnFilterPopup.js +1 -0
- package/dist/packages/canvas-adapter/composePng.d.ts +37 -0
- package/dist/packages/canvas-adapter/composePng.js +1 -0
- package/dist/packages/canvas-adapter/dataTab.d.ts +27 -0
- package/dist/packages/canvas-adapter/dataTab.js +1 -1
- package/dist/packages/canvas-adapter/dieList.js +1 -1
- package/dist/packages/canvas-adapter/differenceMapPanel.d.ts +3 -1
- package/dist/packages/canvas-adapter/differenceMapPanel.js +1 -1
- package/dist/packages/canvas-adapter/drilldown.d.ts +19 -0
- package/dist/packages/canvas-adapter/drilldown.js +1 -1
- package/dist/packages/canvas-adapter/filterEditor.d.ts +5 -0
- package/dist/packages/canvas-adapter/filterEditor.js +1 -1
- package/dist/packages/canvas-adapter/guideWindow.js +1 -1
- package/dist/packages/canvas-adapter/icons.js +1 -1
- package/dist/packages/canvas-adapter/identityHeader.d.ts +5 -0
- package/dist/packages/canvas-adapter/identityHeader.js +1 -1
- package/dist/packages/canvas-adapter/index.d.ts +7 -0
- package/dist/packages/canvas-adapter/index.js +1 -1
- package/dist/packages/canvas-adapter/insightsTab.d.ts +23 -5
- package/dist/packages/canvas-adapter/insightsTab.js +1 -1
- package/dist/packages/canvas-adapter/maplessSummary.d.ts +4 -2
- package/dist/packages/canvas-adapter/maplessSummary.js +1 -1
- package/dist/packages/canvas-adapter/openWaferMode.js +1 -1
- package/dist/packages/canvas-adapter/panelChart.d.ts +7 -0
- package/dist/packages/canvas-adapter/panelChart.js +1 -0
- package/dist/packages/canvas-adapter/panelTable.d.ts +50 -0
- package/dist/packages/canvas-adapter/panelTable.js +1 -0
- package/dist/packages/canvas-adapter/plotCard.js +1 -1
- package/dist/packages/canvas-adapter/plotEditor.d.ts +12 -0
- package/dist/packages/canvas-adapter/plotEditor.js +10 -10
- package/dist/packages/canvas-adapter/plotItems.d.ts +9 -4
- package/dist/packages/canvas-adapter/plotItems.js +1 -1
- package/dist/packages/canvas-adapter/plotJsonComplete.js +1 -1
- package/dist/packages/canvas-adapter/plotModal.d.ts +7 -0
- package/dist/packages/canvas-adapter/plotModal.js +1 -1
- package/dist/packages/canvas-adapter/plotStore.js +1 -1
- package/dist/packages/canvas-adapter/plotTab.d.ts +59 -1
- package/dist/packages/canvas-adapter/plotTab.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +7 -0
- package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferMap.d.ts +41 -9
- package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
- package/dist/packages/canvas-adapter/reportCharts.d.ts +41 -0
- package/dist/packages/canvas-adapter/reportCharts.js +1 -0
- package/dist/packages/canvas-adapter/reportExport.d.ts +91 -0
- package/dist/packages/canvas-adapter/reportExport.js +1 -0
- package/dist/packages/canvas-adapter/reportFigures.d.ts +29 -0
- package/dist/packages/canvas-adapter/reportFigures.js +1 -0
- package/dist/packages/canvas-adapter/reportRun.d.ts +9 -0
- package/dist/packages/canvas-adapter/reportRun.js +1 -0
- package/dist/packages/canvas-adapter/selectionOverlay.d.ts +12 -0
- package/dist/packages/canvas-adapter/selectionOverlay.js +1 -0
- package/dist/packages/canvas-adapter/summaryPanel.d.ts +150 -109
- package/dist/packages/canvas-adapter/summaryPanel.js +7 -4
- package/dist/packages/canvas-adapter/summaryToggle.js +1 -1
- package/dist/packages/canvas-adapter/tableDrilldown.d.ts +48 -0
- package/dist/packages/canvas-adapter/tableDrilldown.js +1 -0
- package/dist/packages/canvas-adapter/tableFilter.d.ts +42 -0
- package/dist/packages/canvas-adapter/tableFilter.js +1 -0
- package/dist/packages/canvas-adapter/tablePlots.d.ts +85 -0
- package/dist/packages/canvas-adapter/tablePlots.js +1 -0
- package/dist/packages/canvas-adapter/themeWatch.d.ts +7 -0
- package/dist/packages/canvas-adapter/themeWatch.js +1 -0
- package/dist/packages/canvas-adapter/toCanvas.d.ts +3 -0
- package/dist/packages/canvas-adapter/toCanvas.js +1 -1
- package/dist/packages/canvas-adapter/toolbar.d.ts +125 -36
- package/dist/packages/canvas-adapter/toolbar.js +2 -2
- package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
- package/dist/packages/canvas-adapter/userGuideHtml.js +521 -412
- package/dist/packages/canvas-adapter/version.d.ts +2 -2
- package/dist/packages/canvas-adapter/version.js +1 -1
- package/dist/packages/canvas-adapter/viewSwitch.js +1 -1
- package/dist/packages/canvas-adapter/virtualTable.d.ts +35 -6
- package/dist/packages/canvas-adapter/virtualTable.js +1 -1
- package/dist/packages/core/aggregates.d.ts +14 -0
- package/dist/packages/core/aggregates.js +1 -1
- package/dist/packages/core/dies.d.ts +7 -0
- package/dist/packages/core/dies.js +1 -1
- package/dist/packages/core/utils.d.ts +2 -0
- package/dist/packages/core/utils.js +1 -1
- package/dist/packages/experimental/charts.d.ts +4 -0
- package/dist/packages/experimental/charts.js +1 -0
- package/dist/packages/renderer/binColors.d.ts +6 -2
- package/dist/packages/renderer/binColors.js +1 -1
- package/dist/packages/renderer/buildView.d.ts +36 -14
- package/dist/packages/renderer/buildView.js +1 -1
- package/dist/packages/renderer/buildWaferMap.d.ts +8 -0
- package/dist/packages/renderer/buildWaferMap.js +1 -1
- package/dist/packages/renderer/categoryColors.d.ts +3 -0
- package/dist/packages/renderer/categoryColors.js +1 -0
- package/dist/packages/renderer/colorMap.d.ts +15 -16
- package/dist/packages/renderer/colorMap.js +1 -1
- package/dist/packages/renderer/colorSchemes.d.ts +34 -30
- package/dist/packages/renderer/colorSchemes.js +1 -1
- package/dist/packages/renderer/dataColors.d.ts +126 -0
- package/dist/packages/renderer/dataColors.js +1 -0
- package/dist/packages/renderer/deprecate.js +1 -1
- package/dist/packages/renderer/fmt.d.ts +14 -0
- package/dist/packages/renderer/fmt.js +1 -1
- package/dist/packages/renderer/index.d.ts +2 -0
- package/dist/packages/renderer/index.js +1 -1
- package/dist/packages/renderer/spec.d.ts +5 -0
- package/dist/packages/renderer/spec.js +1 -1
- package/dist/packages/renderer/stacks.d.ts +21 -0
- package/dist/packages/renderer/stacks.js +1 -0
- package/dist/packages/renderer/timeAxis.d.ts +19 -0
- package/dist/packages/renderer/timeAxis.js +1 -0
- package/dist/packages/stats/analyzeWaferLot.js +1 -1
- package/dist/packages/stats/analyzeWaferMap.d.ts +2 -4
- package/dist/packages/stats/analyzeWaferMap.js +1 -1
- package/dist/packages/stats/binRows.js +1 -1
- package/dist/packages/stats/binShifts.d.ts +59 -0
- package/dist/packages/stats/binShifts.js +1 -0
- package/dist/packages/stats/capability.d.ts +6 -1
- package/dist/packages/stats/capability.js +1 -1
- package/dist/packages/stats/chartCatalogue.d.ts +3 -0
- package/dist/packages/stats/chartCatalogue.js +1 -1
- package/dist/packages/stats/clusterDetection.js +1 -1
- package/dist/packages/stats/columnPlot.d.ts +38 -0
- package/dist/packages/stats/columnPlot.js +1 -0
- package/dist/packages/stats/commonality.d.ts +7 -0
- package/dist/packages/stats/commonality.js +1 -1
- package/dist/packages/stats/correlation.d.ts +7 -2
- package/dist/packages/stats/correlation.js +1 -1
- package/dist/packages/stats/dataTable.d.ts +44 -0
- package/dist/packages/stats/dataTable.js +1 -0
- package/dist/packages/stats/dieRegions.js +1 -1
- package/dist/packages/stats/facets.d.ts +11 -0
- package/dist/packages/stats/facets.js +1 -1
- package/dist/packages/stats/filterFindings.d.ts +21 -0
- package/dist/packages/stats/filterFindings.js +1 -1
- package/dist/packages/stats/math.d.ts +2 -0
- package/dist/packages/stats/math.js +1 -1
- package/dist/packages/stats/overview.d.ts +114 -0
- package/dist/packages/stats/overview.js +1 -0
- package/dist/packages/stats/pat.d.ts +0 -2
- package/dist/packages/stats/pat.js +1 -1
- package/dist/packages/stats/patternClassification.d.ts +20 -3
- package/dist/packages/stats/patternClassification.js +1 -1
- package/dist/packages/stats/permutationNull.d.ts +16 -0
- package/dist/packages/stats/permutationNull.js +1 -0
- package/dist/packages/stats/plotData.d.ts +131 -10
- package/dist/packages/stats/plotData.js +1 -1
- package/dist/packages/stats/plotSpec.d.ts +10 -1
- package/dist/packages/stats/plotSpec.js +3 -3
- package/dist/packages/stats/plotTable.js +1 -1
- package/dist/packages/stats/plotWords.d.ts +52 -0
- package/dist/packages/stats/plotWords.js +1 -0
- package/dist/packages/stats/presentation.d.ts +63 -14
- package/dist/packages/stats/presentation.js +1 -1
- package/dist/packages/stats/presentationPresets.d.ts +35 -0
- package/dist/packages/stats/presentationPresets.js +1 -0
- package/dist/packages/stats/presentationSections.d.ts +83 -0
- package/dist/packages/stats/presentationSections.js +1 -0
- package/dist/packages/stats/renderSummaryReport.d.ts +80 -2
- package/dist/packages/stats/renderSummaryReport.js +1 -67
- package/dist/packages/stats/reportBlocks.d.ts +249 -0
- package/dist/packages/stats/reportBlocks.js +1 -0
- package/dist/packages/stats/reportContents.d.ts +22 -0
- package/dist/packages/stats/reportContents.js +1 -0
- package/dist/packages/stats/reportDeck.d.ts +245 -0
- package/dist/packages/stats/reportDeck.js +212 -0
- package/dist/packages/stats/reportHtml.d.ts +44 -43
- package/dist/packages/stats/reportHtml.js +82 -46
- package/dist/packages/stats/reportMaps.d.ts +67 -0
- package/dist/packages/stats/reportMaps.js +1 -0
- package/dist/packages/stats/reportSections.d.ts +55 -0
- package/dist/packages/stats/reportSections.js +1 -0
- package/dist/packages/stats/sweep.d.ts +14 -6
- package/dist/packages/stats/sweep.js +1 -1
- package/dist/packages/stats/synthesis.d.ts +79 -9
- package/dist/packages/stats/synthesis.js +1 -1
- package/dist/packages/stats/types.d.ts +22 -0
- package/dist/packages/stats/worthItems.d.ts +15 -0
- package/dist/packages/stats/worthItems.js +1 -0
- package/dist/packages/stats/yield.d.ts +13 -0
- package/dist/packages/stats/yield.js +1 -1
- package/llms.txt +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type AggregationMethod } from '../core/aggregates.js';
|
|
2
|
+
import type { Die } from '../core/dies.js';
|
|
3
|
+
import type { TestDef } from './buildWaferMap.js';
|
|
4
|
+
/**
|
|
5
|
+
* One test stacked over the wafers by `method`, at each die position: the dies, with the stacked value at test 0, and the
|
|
6
|
+
* definition a stacked map shows (the test's name, unit and derived marker; its limits are left off, as a stack is not a
|
|
7
|
+
* measurement of one die).
|
|
8
|
+
*/
|
|
9
|
+
export declare function stackTestValues(diesByWafer: readonly (readonly Die[])[], method: AggregationMethod, def: TestDef): {
|
|
10
|
+
dies: Die[];
|
|
11
|
+
testDef: TestDef;
|
|
12
|
+
};
|
|
13
|
+
/** The wafers failing at each die position (`aggregateFailCounts`), and the definition its map shows. */
|
|
14
|
+
export declare function stackFails(wafers: ReadonlyArray<{
|
|
15
|
+
dies: readonly Die[];
|
|
16
|
+
passBins: readonly number[];
|
|
17
|
+
}>): {
|
|
18
|
+
dies: Die[];
|
|
19
|
+
testDef: TestDef;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=stacks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{aggregateFailCounts as s,aggregateValues as a}from"../core/aggregates.js";import{derivedFields as i}from"./testLabel.js";export function stackTestValues(e,r,t){return{dies:a(e,r,t.testNumber),testDef:{testNumber:0,name:t.name,unit:t.unit,...i(t)}}}export function stackFails(e){return{dies:s(e),testDef:{testNumber:0,name:`Wafers failing (of ${e.length})`}}}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A date or date-time as days since 1970-01-01 UTC (fractional for the time of day), or `undefined` when the text is not
|
|
3
|
+
* an ISO date: a month beyond 12, a 31st of February, or any other text.
|
|
4
|
+
*/
|
|
5
|
+
export declare function parseDay(text: string): number | undefined;
|
|
6
|
+
/** A day number as `YYYY-MM-DD`, with `HH:MM` when it has a time of day: the form a table or a tooltip states it in. */
|
|
7
|
+
export declare function formatDay(days: number): string;
|
|
8
|
+
export interface TimeTicks {
|
|
9
|
+
ticks: number[];
|
|
10
|
+
/** The tick's label, in the coarsest form that tells the ticks apart (a year, a month, a day, a time). */
|
|
11
|
+
label: (v: number) => string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Ticks for a date axis from `lo` to `hi` (days). The finest round step that leaves each label `minSpacingPx` of room
|
|
15
|
+
* across `lengthPx`: hours, days, weeks, months or years. Never more ticks than fit, and always at least the range's
|
|
16
|
+
* ends when nothing round fits.
|
|
17
|
+
*/
|
|
18
|
+
export declare function timeTicks(lo: number, hi: number, lengthPx: number, minSpacingPx: number): TimeTicks;
|
|
19
|
+
//# sourceMappingURL=timeAxis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const N=864e5,h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],l=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?\s*(Z|[+-]\d{2}:?\d{2})?)?$/;export function parseDay(t){const e=l.exec(t.trim());if(!e)return;const[a,u,r]=[Number(e[1]),Number(e[2]),Number(e[3])],s=e[4]===void 0?0:Number(e[4]),i=e[5]===void 0?0:Number(e[5]),c=(e[6]===void 0?0:Number(e[6]))+(e[7]===void 0?0:Number(e[7]));if(u<1||u>12||r<1||s>23||i>59||c>=61)return;const o=Date.UTC(a,u-1,r,s,i,0,0)+c*1e3;if(new Date(Date.UTC(a,u-1,r)).getUTCDate()!==r)return;let g=0;const p=e[8];if(p&&p!=="Z"){const y=p[0]==="-"?-1:1,d=p.slice(1).replace(":","");g=y*(Number(d.slice(0,2))*60+Number(d.slice(2,4)))*6e4}return(o-g)/864e5}const f=t=>{const e=new Date(Math.round(t*1440)*6e4);return{y:e.getUTCFullYear(),mo:e.getUTCMonth(),d:e.getUTCDate(),hh:e.getUTCHours(),mi:e.getUTCMinutes()}},m=t=>String(t).padStart(2,"0");export function formatDay(t){if(!Number.isFinite(t))return"";const e=f(t),a=`${e.y}-${m(e.mo+1)}-${m(e.d)}`;return Number.isInteger(t)?a:`${a} ${m(e.hh)}:${m(e.mi)}`}const b=[{grain:"hour",step:1},{grain:"hour",step:3},{grain:"hour",step:6},{grain:"hour",step:12},{grain:"day",step:1},{grain:"day",step:2},{grain:"day",step:7},{grain:"day",step:14},{grain:"month",step:1},{grain:"month",step:2},{grain:"month",step:3},{grain:"month",step:6},{grain:"year",step:1},{grain:"year",step:2},{grain:"year",step:5},{grain:"year",step:10},{grain:"year",step:20},{grain:"year",step:50},{grain:"year",step:100}];function $(t,e,a){const u=[];if(t.grain==="hour"){const r=t.step/24;for(let s=Math.ceil(e/r)*r;s<=a+1e-9;s+=r)u.push(s)}else if(t.grain==="day"){const r=t.step,s=t.step===7||t.step===14?4:0;for(let i=Math.ceil((e-s)/r)*r+s;i<=a+1e-9;i+=r)u.push(i)}else{const r=f(e),s=(o,g)=>o*12+g,i=t.grain==="year"?t.step*12:t.step;let c=Math.ceil(s(r.y,r.mo)/i)*i;for(;;c+=i){const o=Date.UTC(Math.floor(c/12),c%12,1)/864e5;if(o>a+1e-9)break;o>=e-1e-9&&u.push(o)}}return u}export function timeTicks(t,e,a,u){const r=e-t;if(!(r>0)||!(a>0)||!Number.isFinite(r))return{ticks:Number.isFinite(t)?[t]:[],label:formatDay};let s;for(const d of b){const n=$(d,t,e);if(n.length!==0){if(n.length>1&&a/(n.length-1)*((n[n.length-1]-n[0])/r)>=u){s={c:d,ticks:n};break}n.length<=1&&!s&&(s={c:d,ticks:n})}}if(!s)return{ticks:[t,e],label:formatDay};const{c:i,ticks:c}=s,o=f(c[0]),g=f(c[c.length-1]),p=o.y!==g.y;return{ticks:c,label:d=>{const n=f(d);return i.grain==="year"?String(n.y):i.grain==="month"?`${h[n.mo]} ${n.y}`:i.grain==="day"?`${n.d} ${h[n.mo]}${p?` ${n.y}`:""}`:o.y===g.y&&o.mo===g.mo&&o.d===g.d?`${m(n.hh)}:${m(n.mi)}`:`${n.d} ${h[n.mo]} ${m(n.hh)}:${m(n.mi)}`}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{waferDisplayLabel as le}from"../core/waferLabel.js";import{requireRingCount as fe}from"../core/ringCount.js";import{isPositionedDie as de}from"../core/dies.js";import{analyzeWaferMapDecided as N,candidatesOf as Q,describeRegional as X,resolveOptions as ue,adjustPValues as me,testValueSize as pe,recordedOptions as ge,twoProportionZ as Z,welchOfSums as J,rateRelativeEffect as he,passesRateGate as ye,severityForFinding as ee,severityForScore as te,collapseRedundantFindings as we,findContiguousRuns as be,mergedRegionLabel as Se}from"./analyzeWaferMap.js";import{normalizeInput as ne}from"./normalizeInput.js";import{autoDecision as ve,lotTestValueStatus as ze}from"./testValueBudget.js";import{poolCapability as Ie,poolRegionYield as ke,poolPassRates as xe}from"./summaryFigures.js";import{mergeTestDefs as Pe}from"./mergeTestDefs.js";import{findingPatternKey as Re}from"./filterFindings.js";import{median as ie}from"../core/utils.js";import{robustFence as se,zPValue as q}from"./math.js";import{findLotPattern as Me}from"./lotPattern.js";import{buildDriftFindings as $e}from"./lotDrift.js";import{claimForPattern as De,confirmRegionalFindings as Be,weakestMultiplier as We}from"./analyzeWaferMap.js";import{PATTERN_LABELS as Le}from"./patternClassification.js";import{describeWaferPopulation as Ke,populationStat as Ee}from"./population.js";const O=8,Te={3:[.97,.994],4:[.829,.926],5:[.71,.821],6:[.625,.74],7:[.568,.68]},qe=3;export function outlierWafers(e){const s=e.length;if(s<3)return null;const i=ie([...e]),r=o=>Math.abs(o-i)>=qe;if(s>=O){const o=se(e,1.5,O),f=se(e,3,O);if(!o||!f)return null;const u=(o.hi-o.lo)/4,y=[];return e.forEach((w,v)=>{if(w>=o.lo&&w<=o.hi||!r(w))return;const n=w<f.lo||w>f.hi?"unusual":"notable";y.push({index:v,severity:n,statistic:(w-i)/u})}),{method:"tukey-fence",outliers:y}}const t=e.map((o,f)=>f).sort((o,f)=>e[o]-e[f]),d=e[t[s-1]]-e[t[0]];if(d===0)return null;const[l,c]=Te[s],m=[],h=(o,f)=>{const u=Math.abs(e[o]-e[f])/d;u>l&&r(e[o])&&m.push({index:o,severity:u>c?"unusual":"notable",statistic:u})};return h(t[0],t[1]),h(t[s-1],t[s-2]),{method:"dixon-q",outliers:m}}const A=2;function j(e,s){const i={info:0,notable:1,unusual:2};return i[e]>=i[s]?e:s}const Ae=new Set(["ring","quadrant","sector"]),Fe=new Set(["ring","quadrant","sector","reticle-position","test-site"]),Ne=new Set(["yield","hardBin","softBin","functionalTest","test"]);function Oe(e){return Fe.has(e.comparison.family)&&Ne.has(e.variable.kind)}function je(e,s){const i=e.map(l=>l.facts);if(!i.length||i.some(l=>!l))return{coincident:new Set,yieldSoftBin:void 0,passBins:[],sectorCount:s};const[r,...t]=i,d=t.every(l=>l.passBins.length===r.passBins.length&&l.passBins.every(c=>r.passBins.includes(c)));return{coincident:new Set([...r.coincident].filter(l=>t.every(c=>c.coincident.has(l)))),yieldSoftBin:t.every(l=>l.yieldSoftBin===r.yieldSoftBin)?r.yieldSoftBin:void 0,passBins:d?r.passBins:[],sectorCount:s}}function V(e,s){let i=0,r=0,t=0,d=0,l=0,c=0,m=0,h=0,o=0,f=!0,u=0;for(const{waferIndex:v,c:n}of e){const g=s(v,n),a=n.rate??n.mean,p=Math.sqrt(a.n+g.n);if(n.rate)i+=p*Z(n.rate.hits,n.rate.n,g.hits,g.n),t+=n.rate.hits,d+=n.rate.n,l+=g.hits,c+=g.n;else{const b=J(n.mean,g.n,g.sum,g.sq);i+=p*b.z,m+=n.mean.n*b.effectSize,h+=n.mean.n*b.delta,u+=n.mean.n,n.relativeDelta===void 0?f=!1:o+=n.mean.n*n.relativeDelta}r+=p*p}const y=r>0?i/Math.sqrt(r):0,w=e[0].c;if(w.rate){const v=l/c,n=t/d-v;return{z:y,delta:n,relativeDelta:v===0?void 0:n/v,size:he({hits:t,n:d,restHits:l,restN:c,passRate:w.rate.passRate})}}return{z:y,delta:h/u,relativeDelta:f?o/u:void 0,size:m/u}}function _(e,s,i,r){return e.rate?ye(s,i.delta,i.size,r):s<=r.significanceLevel&&Math.abs(i.size)>=r.minimumEffectSize}function Y(e,s){return s<e?` with positions, ${e-s} without`:""}function Ve(e,s,i,r,t){const d=new Map;for(const{waferIndex:n,byKey:g}of e)for(const a of g.values())(d.get(a.key)??d.set(a.key,[]).get(a.key)).push({waferIndex:n,c:a});const l=new Map(e.map(n=>[n.waferIndex,n.byKey])),c=(n,g)=>g.rate?{hits:g.rate.restHits,n:g.rate.restN,sum:0,sq:0}:{hits:0,n:g.mean.restN,sum:g.mean.restSum,sq:g.mean.restSq},m=[];for(const[n,g]of d){if(g.length<A)continue;const a=V(g,c);if(a.z===0)continue;const p=g[0].c;m.push({key:n,entries:g,combined:a,finding:{id:`lot-region:${n}`,level:"lot",severity:"info",variable:{...p.variable,label:p.label},comparison:{...p.comparison},effect:{direction:a.z>0?"higher":"lower",absoluteDelta:a.delta,relativeDelta:a.relativeDelta,effectSize:p.rate?a.delta:a.size},stats:{method:"stouffer-z",pValue:q(a.z),sampleSizeLeft:0,sampleSizeRight:0},summary:"",highlight:{kind:"wafer",waferIndices:[]}}})}me(m.map(n=>n.finding));const h=m.filter(n=>_(n.entries[0].c,n.finding.stats.adjustedPValue??1,n.combined,s)),u=Be(h,n=>{const g=n.entries[0].c;return[g.source,g.variable.kind,g.variable.bin??"",g.variable.index??"",g.region.family].join("\0")},(n,g)=>{const a=(M,B)=>{const k=c(M,B);for(const z of g){const R=l.get(M)?.get(z.key);R&&(R.rate?(k.hits-=R.rate.hits,k.n-=R.rate.n):(k.n-=R.mean.n,k.sum-=R.mean.sum,k.sq-=R.mean.sq))}return k},p=n.entries.filter(M=>a(M.waferIndex,M.c).n>=s.minimumSampleSize);if(!p.length)return"baseline-too-small";const b=V(p,a),x=n.finding.stats.pValue??1,P=x>0?(n.finding.stats.adjustedPValue??x)/x:1,S=Math.min(1,q(b.z)*P);return{pValue:S,passes:Math.sign(b.z)===Math.sign(n.combined.z)&&_(n.entries[0].c,S,b,s)}},n=>{const g=n.entries[0].c.rate;return g!==void 0&&(g.passRate?n.combined.z<0:n.combined.z>0)},m),y=[],w=new Map;for(const n of h){if(!u.has(n))continue;const g=n.finding.stats.pValue??1,a=Math.sign(n.combined.z),p=n.entries.filter(z=>Math.sign(z.c.delta)===a),b=t,x=n.entries[0].c,P=n.finding.stats.adjustedPValue??g,S=x.rate?ee(P,n.combined.delta,n.combined.size):te(P,n.combined.size),M=j(S,p.length/b>=.6?"unusual":"info"),B={};for(const z of p)B[z.waferIndex]=[...z.c.region.dieKeys];const k={...n.finding,severity:M,stats:{...n.finding.stats,sampleSizeLeft:p.length,sampleSizeRight:b-p.length},summary:`${X(x,n.combined.delta,n.combined.relativeDelta)} \u2014 ${n.finding.effect.direction} on ${p.length}/${b} wafers${Y(e.length,b)}, all wafers' data combined`,highlight:{kind:"wafer",waferIndices:p.map(z=>z.waferIndex),dieKeysByWafer:B}};y.push(k),w.set(k,n)}const v=_e(w,l,t,e.length,s,r,c);return y.splice(0,y.length,...y.filter(n=>!v.replaced.has(n)),...v.findings),we(y,i),y}function _e(e,s,i,r,t,d,l){const c=new Map;for(const[o,f]of e){const u=f.entries[0].c;if(!Ae.has(u.region.family))continue;const y=[u.source,u.variable.kind,u.variable.bin??"",u.variable.index??"",u.region.family,o.effect.direction].join("|");(c.get(y)??c.set(y,[]).get(y)).push({finding:o,c:u,key:f.key})}const m=[],h=new Set;for(const o of c.values()){if(o.length<2)continue;const f=o[0].c.region.family;for(const u of be(o,f,t.sectorCount,y=>y.c.region.key)){if(u.length<2)continue;const y=Ye(u,s,i,r,t,d,l);if(y){m.push(y);for(const w of u)h.add(w.finding)}}}return{findings:m,replaced:h}}function Ye(e,s,i,r,t,d,l){const c=e[0].c,m=e[0].finding.effect.direction==="higher"?1:-1,h=Se(c.region.family,e.map(S=>S.c.region.key),d),o=[];for(const[S,M]of s){const B=e.map(I=>M.get(I.key));if(B.some(I=>!I))continue;const k=B,z=k[0];let R,F;if(z.rate){const I=k.reduce((D,W)=>D+W.rate.hits,0),$=k.reduce((D,W)=>D+W.rate.n,0),K=z.rate.hits+z.rate.restHits-I,L=z.rate.n+z.rate.restN-$;if($<t.minimumSampleSize||L<t.minimumSampleSize)continue;R={...z,rate:{hits:I,n:$,restHits:K,restN:L,passRate:z.rate.passRate}},F=Z(I,$,K,L)}else{const I=z.mean,$=k.reduce((E,T)=>E+T.mean.n,0),K=k.reduce((E,T)=>E+T.mean.sum,0),L=k.reduce((E,T)=>E+T.mean.sq,0),D=I.n+I.restN-$,W=I.sum+I.restSum-K,C=I.sq+I.restSq-L;if($<t.minimumSampleSize||D<t.minimumSampleSize)continue;const G={n:$,sum:K,sq:L,restN:D,restSum:W,restSq:C,shift:I.shift},H=J(G,D,W,C),U=W/D+I.shift;R={...z,mean:G,relativeDelta:U!==0?H.delta/Math.abs(U):void 0},F=H.z}const ce=[...new Set(k.flatMap(I=>[...I.region.dieKeys]))];o.push({waferIndex:S,c:R,z:F,dieKeys:ce})}if(o.length<A)return;const f=V(o,l);if(f.z===0||Math.sign(f.z)!==m)return;const u=q(f.z),y=We(e.map(S=>S.finding)),w=Math.min(1,u*y);if(!_(c,w,f,t))return;const v=o.filter(S=>Math.sign(S.z)===m&&q(S.z)<=t.significanceLevel);if(!v.length)return;const n=c.rate?ee(w,f.delta,f.size):te(w,f.size),g=j(n,v.length/i>=.6?"unusual":"info"),a={};for(const S of v)a[S.waferIndex]=S.dieKeys;const p=e.map(S=>S.c.region.key.slice(S.c.region.key.indexOf(":")+1)).join("-"),b={...c,comparison:{...c.comparison,left:h}},x=e[0].finding,P=x.effect.direction;return{...x,id:`lot-region:${e[0].key.split("|").slice(0,-1).join("|")}|${c.region.family}:${p}`,severity:g,comparison:{...x.comparison,left:h},effect:{direction:P,absoluteDelta:f.delta,relativeDelta:f.relativeDelta,effectSize:c.rate?f.delta:f.size},stats:{method:"stouffer-z",pValue:u,adjustedPValue:w,sampleSizeLeft:v.length,sampleSizeRight:i-v.length},summary:`${X(b,f.delta,f.relativeDelta)} \u2014 ${P} on ${v.length}/${i} wafers${Y(r,i)}, all wafers' data combined`,highlight:{kind:"wafer",waferIndices:v.map(S=>S.waferIndex),dieKeysByWafer:a},relatedIds:e.map(S=>S.finding.id)}}const ae={"Edge-ring":"edge","Edge-local":"edge","Center cluster":"centre or donut",Donut:"centre or donut"};function Ce(e,s){const i=new Map,r=l=>{const c=l.variable.kind==="spatialPattern"?ae[l.comparison.left]:void 0;return c?`spatialPattern|${c}`:Re(l)};for(const l of e){const c=new Set,m=new Map;for(const o of l.summary.findings)if(o.variable.kind==="spatialPattern")for(const f of o.relatedIds??[])m.set(f,r(o));const h=new Set(l.summary.findings.flatMap(o=>o.absorbedIds??[]));for(const o of l.summary.findings){if(h.has(o.id)||Oe(o)||o.variable.kind==="spatialPattern"&&s?.carriers.has(l.waferIndex))continue;const f=r(o);if(c.has(f))continue;c.add(f);const u=i.get(f)??{finding:o,waferIndices:[],severity:o.severity,labels:new Map,dieKeysByWafer:{},explainedBy:new Map};u.waferIndices.push(l.waferIndex);const y=m.get(o.id);if(y&&u.explainedBy.set(y,(u.explainedBy.get(y)??0)+1),o.variable.kind==="spatialPattern"){u.labels.set(o.comparison.left,(u.labels.get(o.comparison.left)??0)+1);const w=o.highlight.dieKeys;w&&(u.dieKeysByWafer[l.waferIndex]=w)}u.severity=j(u.severity,o.severity),i.set(f,u)}}const t=[];for(const[l,c]of i){if(c.waferIndices.length<A)continue;const m=c.waferIndices.length/Math.max(1,e.length),h=m>=.6||c.severity==="unusual"?"unusual":"notable",o=c.finding;t.push({id:`lot-repeat:${l}`,level:"lot",severity:h,variable:{...o.variable},comparison:{...o.comparison},effect:{direction:o.effect.direction,absoluteDelta:o.effect.absoluteDelta,relativeDelta:o.effect.relativeDelta,effectSize:o.effect.effectSize},stats:{method:"wafer-finding-frequency",sampleSizeLeft:c.waferIndices.length,sampleSizeRight:e.length-c.waferIndices.length},summary:`${Ue(o,c.labels)} \u2014 seen on ${c.waferIndices.length}/${e.length} wafers (${Math.round(m*100)}%)`,highlight:{kind:"wafer",waferIndices:c.waferIndices,...c.labels.size?{dieKeysByWafer:c.dieKeysByWafer}:{}}})}const d=new Map(t.map(l=>[l.id,l]));for(const[l,c]of i){const m=d.get(`lot-repeat:${l}`);if(m)for(const[h,o]of c.explainedBy){const f=d.get(`lot-repeat:${h}`);!f||o!==c.waferIndices.length||(f.relatedIds??=[]).push(m.id)}}return t}function Ge(e,s,i){const{classification:r,carriers:t}=e,d=Le[r.pattern],l=t.size/Math.max(1,s),c={};for(const[m,h]of t)c[m]=h;return{id:"lot-repeat:spatialPattern|lot",level:"lot",severity:l>=.6||r.confidence==="high"?"unusual":"notable",variable:{kind:"spatialPattern",label:d},comparison:{family:"spatial-pattern",left:d,right:"Wafer"},effect:{direction:"different",effectSize:r.features.globalRdd},stats:{method:"wafer-finding-frequency",sampleSizeLeft:t.size,sampleSizeRight:s-t.size},summary:`Spatial pattern: ${d.toLowerCase()} \u2014 seen on ${t.size}/${s} wafers${Y(i,s)} (${Math.round(l*100)}%)`,highlight:{kind:"wafer",waferIndices:[...t.keys()].sort((m,h)=>m-h),dieKeysByWafer:c}}}function He(e){const s=/^Rings? (\d+)(?:\s*[–-]\s*(\d+))?/.exec(e.comparison.left);if(!s)return[];const i=+s[1],r=s[2]?+s[2]:i;return Array.from({length:Math.max(0,r-i+1)},(t,d)=>i+d)}function Ue(e,s){if(!s.size)return e.summary;const i=d=>d.toLowerCase();if(s.size===1)return`Spatial pattern: ${i([...s.keys()][0])}`;const r=ae[e.comparison.left],t=[...s].sort((d,l)=>l[1]-d[1]).map(([d,l])=>`${i(d)} on ${l}`);return`Spatial pattern: ${r} (${t.join(", ")})`}function Qe(e,s){const i=Ee(s,"median"),r=e.map(m=>({waferIndex:m.waferIndex,yieldPercent:m.summary.stats.yieldPercent})).filter(m=>m.yieldPercent!==null),t=r.map(m=>m.yieldPercent),d=outlierWafers(t);if(!d)return[];const l=ie(t),c=[];for(const{index:m,severity:h,statistic:o}of d.outliers){const f=r[m],u=f.yieldPercent-l,y=le({wafer:{metadata:e.find(w=>w.waferIndex===f.waferIndex)?.summary.wafer}},f.waferIndex);c.push({id:`inter-wafer:yield:${f.waferIndex}`,level:"inter-wafer",severity:h,variable:{kind:"yield",label:"Yield"},comparison:{family:"wafer",left:y,right:i.charAt(0).toUpperCase()+i.slice(1)},effect:{direction:u>0?"higher":"lower",absoluteDelta:u/100,relativeDelta:l===0?void 0:u/l,effectSize:o},stats:{method:d.method,sampleSizeLeft:1,sampleSizeRight:r.length-1},summary:`${y} yield is ${Math.abs(u).toFixed(1)} percentage points ${u>0?"higher":"lower"} than the ${i}`,highlight:{kind:"wafer",waferIndices:[f.waferIndex]}})}return c}function re(e,s){if((s.enableTestValueAnalysis??"auto")!=="auto")return;let i=0;for(const r of e){const{tests:t,dies:d}=pe(r,s);i+=t*d}return ve(i)}export function analyzeWaferLot(e,s={}){const i=e.map(ne),r=re(i,s),t=i.map((a,p)=>({waferIndex:p,summary:s.perWaferSummaries?.[p]??N(a,s,r)})),d=t.map(({waferIndex:a,summary:p})=>Q(p)??Q(N(i[a],s,r))),l=d.map((a,p)=>({waferIndex:p,byKey:new Map(a.candidates.map(b=>[b.key,b]))})),c=ue(s).resolved,m=i.filter(a=>a.dies.some(de)).length,h=i.length>0?fe(i[0],"analyzeWaferLot"):void 0,o=Me(i,c),f=o&&o.carriers.size>=A?o:null,u=[...h===void 0?[]:Ve(l,c,je(d,c.sectorCount),h,m),...Ce(t,f),...Qe(t,Ke(t.map(a=>a.summary.wafer))),...$e(t,c.significanceLevel)];if(f&&h!==void 0){const a=Ge(f,m,t.length);a.relatedIds=De([f.classification.pattern],a.severity,u,He,h),a.relatedIds.length||delete a.relatedIds,u.push(a)}u.sort((a,p)=>{const b=a.severity==="unusual"?2:a.severity==="notable"?1:0,x=p.severity==="unusual"?2:p.severity==="notable"?1:0;return b!==x?x-b:a.summary.localeCompare(p.summary,"en")});const y=t.map(a=>a.summary.wafer).filter(a=>!!a),w={},v=[];if(y.length>0){const a=new Set;for(const p of y)for(const b of Object.keys(p))a.add(b);a.delete("wafer"),a.delete("waferId");for(const p of a){const b=y.filter(P=>p in P).map(P=>P[p]);b.every(P=>P===b[0])?w[p]=b[0]:v.push(p)}}const n=t.map(({waferIndex:a,summary:p})=>({waferIndex:a,yieldPercent:p.stats.yieldPercent})),g=t.map(({waferIndex:a,summary:p})=>p.stats.perTestStats?.length?{waferIndex:a,tests:p.stats.perTestStats}:null).filter(a=>a!==null);return{level:"lot",hasNotableFindings:u.some(a=>a.severity!=="info")||t.some(a=>a.summary.hasNotableFindings),findings:u,lot:Object.keys(w).length>0?w:void 0,...v.length>0?{mixedIdentityFields:v}:{},analysisOptions:ge(s),stats:{waferCount:e.length,...Xe(i,t.map(a=>a.summary)),...Ze(ze(t.map(a=>a.summary)))},lotYieldSeries:n,perWafer:t,...g.length>0?{perWaferTestStats:g}:{}}}function Xe(e,s){const i={...xe(s)},r=Ie(s,Pe(e).defs);r&&(i.capability=r);const t=ke(s,e.map(d=>d.ringCount));return t&&(i.regionYield=t),i}const Ze=e=>e?{testValueAnalysis:e}:{},oe=()=>new Promise(e=>setTimeout(e,0));export async function analyzeWaferLotAsync(e,s={}){const{onProgress:i,signal:r,...t}=s,d=e.map(ne),l=re(d,t),c=[];let m=Date.now();for(let h=0;h<d.length;h++)r?.throwIfAborted(),c.push(t.perWaferSummaries?.[h]??N(d[h],t,l)),i?.(h+1,d.length),Date.now()-m>100&&(await oe(),m=Date.now());return await oe(),r?.throwIfAborted(),analyzeWaferLot(d,{...t,perWaferSummaries:c})}export function remapLotWaferIndices(e,s){const i=r=>s[r]??r;return{...e,perWafer:e.perWafer.map(r=>({...r,waferIndex:i(r.waferIndex)})),lotYieldSeries:e.lotYieldSeries.map(r=>({...r,waferIndex:i(r.waferIndex)})),...e.perWaferTestStats?{perWaferTestStats:e.perWaferTestStats.map(r=>({...r,waferIndex:i(r.waferIndex)}))}:{},findings:e.findings.map(r=>{const t=r.highlight;if(!t||t.kind!=="wafer")return r;const d=t.dieKeysByWafer?Object.fromEntries(Object.entries(t.dieKeysByWafer).map(([l,c])=>[i(Number(l)),c])):void 0;return{...r,highlight:{...t,waferIndices:t.waferIndices.map(i),...d?{dieKeysByWafer:d}:{}}}})}}
|
|
1
|
+
import{waferDisplayLabel as fe}from"../core/waferLabel.js";import{requireRingCount as de}from"../core/ringCount.js";import{isPositionedDie as ue}from"../core/dies.js";import{analyzeWaferMapDecided as q,candidatesOf as Q,describeRegional as X,resolveOptions as me,adjustPValues as pe,testValueSize as ge,recordedOptions as he,twoProportionZ as Z,welchOfSums as J,rateRelativeEffect as ye,passesRateGate as we,severityForFinding as ee,severityForScore as te,collapseRedundantFindings as be,findContiguousRuns as Se,mergedRegionLabel as ve}from"./analyzeWaferMap.js";import{normalizeInput as ne}from"./normalizeInput.js";import{autoDecision as ze,lotTestValueStatus as Ie}from"./testValueBudget.js";import{poolCapability as ke,poolRegionYield as Me,poolPassRates as Re}from"./summaryFigures.js";import{mergeTestDefs as xe}from"./mergeTestDefs.js";import{findingPatternKey as Pe}from"./filterFindings.js";import{median as ie}from"../core/utils.js";import{robustFence as se,zPValue as A}from"./math.js";import{findLotPattern as De}from"./lotPattern.js";import{buildDriftFindings as Ee}from"./lotDrift.js";import{claimForPattern as $e,confirmRegionalFindings as Be,weakestMultiplier as We}from"./analyzeWaferMap.js";import{PATTERN_LABELS as Le}from"./patternClassification.js";import{describeWaferPopulation as Te,populationStat as Ke}from"./population.js";import{lotYieldFromSummaries as Ae}from"./yield.js";const O=8,Ne={3:[.97,.994],4:[.829,.926],5:[.71,.821],6:[.625,.74],7:[.568,.68]},Fe=3;export function outlierWafers(e){const a=e.length;if(a<3)return null;const n=ie([...e]),i=r=>Math.abs(r-n)>=Fe;if(a>=O){const r=se(e,1.5,O),d=se(e,3,O);if(!r||!d)return null;const u=(r.hi-r.lo)/4,y=[];return e.forEach((w,v)=>{if(w>=r.lo&&w<=r.hi||!i(w))return;const s=w<d.lo||w>d.hi?"unusual":"notable";y.push({index:v,severity:s,statistic:(w-n)/u})}),{method:"tukey-fence",outliers:y}}const t=e.map((r,d)=>d).sort((r,d)=>e[r]-e[d]),f=e[t[a-1]]-e[t[0]];if(f===0)return null;const[l,c]=Ne[a],p=[],h=(r,d)=>{const u=Math.abs(e[r]-e[d])/f;u>l&&i(e[r])&&p.push({index:r,severity:u>c?"unusual":"notable",statistic:u})};return h(t[0],t[1]),h(t[a-1],t[a-2]),{method:"dixon-q",outliers:p}}const N=2;function _(e,a){const n={info:0,notable:1,unusual:2};return n[e]>=n[a]?e:a}const qe=new Set(["ring","quadrant","sector"]),Oe=new Set(["ring","quadrant","sector","reticle-position","test-site"]),_e=new Set(["yield","hardBin","softBin","functionalTest","test"]);function je(e){return Oe.has(e.comparison.family)&&_e.has(e.variable.kind)}function Ve(e,a){const n=e.map(l=>l.facts);if(!n.length||n.some(l=>!l))return{coincident:new Set,yieldSoftBin:void 0,passBins:[],sectorCount:a};const[i,...t]=n,f=t.every(l=>l.passBins.length===i.passBins.length&&l.passBins.every(c=>i.passBins.includes(c)));return{coincident:new Set([...i.coincident].filter(l=>t.every(c=>c.coincident.has(l)))),yieldSoftBin:t.every(l=>l.yieldSoftBin===i.yieldSoftBin)?i.yieldSoftBin:void 0,passBins:f?i.passBins:[],sectorCount:a}}function j(e,a){let n=0,i=0,t=0,f=0,l=0,c=0,p=0,h=0,r=0,d=!0,u=0;for(const{waferIndex:v,c:s}of e){const g=a(v,s),o=s.rate??s.mean,m=Math.sqrt(o.n+g.n);if(s.rate)n+=m*Z(s.rate.hits,s.rate.n,g.hits,g.n),t+=s.rate.hits,f+=s.rate.n,l+=g.hits,c+=g.n;else{const b=J(s.mean,g.n,g.sum,g.sq);n+=m*b.z,p+=s.mean.n*b.effectSize,h+=s.mean.n*b.delta,u+=s.mean.n,s.relativeDelta===void 0?d=!1:r+=s.mean.n*s.relativeDelta}i+=m*m}const y=i>0?n/Math.sqrt(i):0,w=e[0].c;if(w.rate){const v=l/c,s=t/f-v;return{z:y,delta:s,relativeDelta:v===0?void 0:s/v,size:ye({hits:t,n:f,restHits:l,restN:c,passRate:w.rate.passRate})}}return{z:y,delta:h/u,relativeDelta:d?r/u:void 0,size:p/u}}const Ye=.05,Ce=.6;function V(e,a,n,i,t){if(e.rate&&Math.abs(n.delta)<i.minimumEffectSize&&n.size<i.minimumRelativeEffect){const f=Math.sign(n.delta);if((t?t.filter(c=>Math.sign(c.c.delta)===f).length/t.length:0)<Ce)return!1}return e.rate?we(a,n.delta,n.size,{...i,minimumEffectSize:Math.min(i.minimumEffectSize,Ye)}):a<=i.significanceLevel&&Math.abs(n.size)>=i.minimumEffectSize}function ae(e,a,n,i,t){return`${e}, all wafers' data combined; ${a} on ${n}/${i} wafers${t}`}function Y(e,a){return a<e?` with positions, ${e-a} without`:""}function He(e,a,n,i,t){const f=new Map;for(const{waferIndex:s,byKey:g}of e)for(const o of g.values())(f.get(o.key)??f.set(o.key,[]).get(o.key)).push({waferIndex:s,c:o});const l=new Map(e.map(s=>[s.waferIndex,s.byKey])),c=(s,g)=>g.rate?{hits:g.rate.restHits,n:g.rate.restN,sum:0,sq:0}:{hits:0,n:g.mean.restN,sum:g.mean.restSum,sq:g.mean.restSq},p=[];for(const[s,g]of f){if(g.length<N)continue;const o=j(g,c);if(o.z===0)continue;const m=g[0].c;p.push({key:s,entries:g,combined:o,finding:{id:`lot-region:${s}`,level:"lot",severity:"info",variable:{...m.variable,label:m.label},comparison:{...m.comparison},effect:{direction:o.z>0?"higher":"lower",absoluteDelta:o.delta,relativeDelta:o.relativeDelta,effectSize:m.rate?o.delta:o.size},stats:{method:"stouffer-z",pValue:A(o.z),sampleSizeLeft:0,sampleSizeRight:0},summary:"",highlight:{kind:"wafer",waferIndices:[]}}})}pe(p.map(s=>s.finding));const h=p.filter(s=>V(s.entries[0].c,s.finding.stats.adjustedPValue??1,s.combined,a,s.entries)),u=Be(h,s=>{const g=s.entries[0].c;return[g.source,g.variable.kind,g.variable.bin??"",g.variable.index??"",g.region.family].join("\0")},(s,g)=>{const o=(P,$)=>{const k=c(P,$);for(const z of g){const x=l.get(P)?.get(z.key);x&&(x.rate?(k.hits-=x.rate.hits,k.n-=x.rate.n):(k.n-=x.mean.n,k.sum-=x.mean.sum,k.sq-=x.mean.sq))}return k},m=s.entries.filter(P=>o(P.waferIndex,P.c).n>=a.minimumSampleSize);if(!m.length)return"baseline-too-small";const b=j(m,o),M=s.finding.stats.pValue??1,R=M>0?(s.finding.stats.adjustedPValue??M)/M:1,S=Math.min(1,A(b.z)*R);return{pValue:S,passes:Math.sign(b.z)===Math.sign(s.combined.z)&&V(s.entries[0].c,S,b,a,m)}},s=>{const g=s.entries[0].c.rate;return g!==void 0&&(g.passRate?s.combined.z<0:s.combined.z>0)},p),y=[],w=new Map;for(const s of h){if(!u.has(s))continue;const g=s.finding.stats.pValue??1,o=Math.sign(s.combined.z),m=s.entries.filter(z=>Math.sign(z.c.delta)===o),b=t,M=s.entries[0].c,R=s.finding.stats.adjustedPValue??g,S=M.rate?ee(R,s.combined.delta,s.combined.size):te(R,s.combined.size),P=_(S,m.length/b>=.6?"unusual":"info"),$={};for(const z of m)$[z.waferIndex]=[...z.c.region.dieKeys];const k={...s.finding,severity:P,stats:{...s.finding.stats,sampleSizeLeft:m.length,sampleSizeRight:b-m.length},summary:ae(X(M,s.combined.delta,s.combined.relativeDelta),s.finding.effect.direction,m.length,b,Y(e.length,b)),highlight:{kind:"wafer",waferIndices:m.map(z=>z.waferIndex),dieKeysByWafer:$}};y.push(k),w.set(k,s)}const v=Ge(w,l,t,e.length,a,i,c);return y.splice(0,y.length,...y.filter(s=>!v.replaced.has(s)),...v.findings),be(y,n),y}function Ge(e,a,n,i,t,f,l){const c=new Map;for(const[r,d]of e){const u=d.entries[0].c;if(!qe.has(u.region.family))continue;const y=[u.source,u.variable.kind,u.variable.bin??"",u.variable.index??"",u.region.family,r.effect.direction].join("|");(c.get(y)??c.set(y,[]).get(y)).push({finding:r,c:u,key:d.key})}const p=[],h=new Set;for(const r of c.values()){if(r.length<2)continue;const d=r[0].c.region.family;for(const u of Se(r,d,t.sectorCount,y=>y.c.region.key)){if(u.length<2)continue;const y=Ue(u,a,n,i,t,f,l);if(y){p.push(y);for(const w of u)h.add(w.finding)}}}return{findings:p,replaced:h}}function Ue(e,a,n,i,t,f,l){const c=e[0].c,p=e[0].finding.effect.direction==="higher"?1:-1,h=ve(c.region.family,e.map(S=>S.c.region.key),f),r=[];for(const[S,P]of a){const $=e.map(I=>P.get(I.key));if($.some(I=>!I))continue;const k=$,z=k[0];let x,F;if(z.rate){const I=k.reduce((E,B)=>E+B.rate.hits,0),D=k.reduce((E,B)=>E+B.rate.n,0),L=z.rate.hits+z.rate.restHits-I,W=z.rate.n+z.rate.restN-D;if(D<t.minimumSampleSize||W<t.minimumSampleSize)continue;x={...z,rate:{hits:I,n:D,restHits:L,restN:W,passRate:z.rate.passRate}},F=Z(I,D,L,W)}else{const I=z.mean,D=k.reduce((T,K)=>T+K.mean.n,0),L=k.reduce((T,K)=>T+K.mean.sum,0),W=k.reduce((T,K)=>T+K.mean.sq,0),E=I.n+I.restN-D,B=I.sum+I.restSum-L,C=I.sq+I.restSq-W;if(D<t.minimumSampleSize||E<t.minimumSampleSize)continue;const H={n:D,sum:L,sq:W,restN:E,restSum:B,restSq:C,shift:I.shift},G=J(H,E,B,C),U=B/E+I.shift;x={...z,mean:H,relativeDelta:U!==0?G.delta/Math.abs(U):void 0},F=G.z}const le=[...new Set(k.flatMap(I=>[...I.region.dieKeys]))];r.push({waferIndex:S,c:x,z:F,dieKeys:le})}if(r.length<N)return;const d=j(r,l);if(d.z===0||Math.sign(d.z)!==p)return;const u=A(d.z),y=We(e.map(S=>S.finding)),w=Math.min(1,u*y);if(!V(c,w,d,t,r.map(S=>({c:{...S.c,delta:S.z}}))))return;const v=r.filter(S=>Math.sign(S.z)===p&&A(S.z)<=t.significanceLevel);if(!v.length)return;const s=c.rate?ee(w,d.delta,d.size):te(w,d.size),g=_(s,v.length/n>=.6?"unusual":"info"),o={};for(const S of v)o[S.waferIndex]=S.dieKeys;const m=e.map(S=>S.c.region.key.slice(S.c.region.key.indexOf(":")+1)).join("-"),b={...c,comparison:{...c.comparison,left:h}},M=e[0].finding,R=M.effect.direction;return{...M,id:`lot-region:${e[0].key.split("|").slice(0,-1).join("|")}|${c.region.family}:${m}`,severity:g,comparison:{...M.comparison,left:h},effect:{direction:R,absoluteDelta:d.delta,relativeDelta:d.relativeDelta,effectSize:c.rate?d.delta:d.size},stats:{method:"stouffer-z",pValue:u,adjustedPValue:w,sampleSizeLeft:v.length,sampleSizeRight:n-v.length},summary:ae(X(b,d.delta,d.relativeDelta),R,v.length,n,Y(i,n)),highlight:{kind:"wafer",waferIndices:v.map(S=>S.waferIndex),dieKeysByWafer:o},relatedIds:e.map(S=>S.finding.id)}}const re={"Edge-ring":"edge","Edge-local":"edge","Center cluster":"centre or donut",Donut:"centre or donut"};function Qe(e,a){const n=new Map,i=l=>{const c=l.variable.kind==="spatialPattern"?re[l.comparison.left]:void 0;return c?`spatialPattern|${c}`:Pe(l)};for(const l of e){const c=new Set,p=new Map;for(const r of l.summary.findings)if(r.variable.kind==="spatialPattern")for(const d of r.relatedIds??[])p.set(d,i(r));const h=new Set(l.summary.findings.flatMap(r=>r.absorbedIds??[]));for(const r of l.summary.findings){if(h.has(r.id)||je(r)||r.variable.kind==="spatialPattern"&&a?.carriers.has(l.waferIndex))continue;const d=i(r);if(c.has(d))continue;c.add(d);const u=n.get(d)??{finding:r,waferIndices:[],severity:r.severity,labels:new Map,dieKeysByWafer:{},explainedBy:new Map};u.waferIndices.push(l.waferIndex);const y=p.get(r.id);y&&u.explainedBy.set(y,(u.explainedBy.get(y)??0)+1),r.variable.kind==="spatialPattern"&&u.labels.set(r.comparison.left,(u.labels.get(r.comparison.left)??0)+1);const w=r.highlight.dieKeys;w&&w.length&&(u.dieKeysByWafer[l.waferIndex]=w),u.severity=_(u.severity,r.severity),n.set(d,u)}}const t=[];for(const[l,c]of n){if(c.waferIndices.length<N)continue;const p=c.waferIndices.length/Math.max(1,e.length),h=p>=.6||c.severity==="unusual"?"unusual":"notable",r=c.finding;t.push({id:`lot-repeat:${l}`,level:"lot",severity:h,variable:{...r.variable},comparison:{...r.comparison},effect:{direction:r.effect.direction,absoluteDelta:r.effect.absoluteDelta,relativeDelta:r.effect.relativeDelta,effectSize:r.effect.effectSize},stats:{method:"wafer-finding-frequency",sampleSizeLeft:c.waferIndices.length,sampleSizeRight:e.length-c.waferIndices.length},summary:`${Je(r,c.labels)}, seen on ${c.waferIndices.length}/${e.length} wafers (${Math.round(p*100)}%)`,highlight:{kind:"wafer",waferIndices:c.waferIndices,...Object.keys(c.dieKeysByWafer).length?{dieKeysByWafer:c.dieKeysByWafer}:{}}})}const f=new Map(t.map(l=>[l.id,l]));for(const[l,c]of n){const p=f.get(`lot-repeat:${l}`);if(p)for(const[h,r]of c.explainedBy){const d=f.get(`lot-repeat:${h}`);!d||r!==c.waferIndices.length||(d.relatedIds??=[]).push(p.id)}}return t}function Xe(e,a,n){const{classification:i,carriers:t}=e,f=Le[i.pattern],l=t.size/Math.max(1,a),c={};for(const[p,h]of t)c[p]=h;return{id:"lot-repeat:spatialPattern|lot",level:"lot",severity:l>=.6||i.confidence==="high"?"unusual":"notable",variable:{kind:"spatialPattern",label:f},comparison:{family:"spatial-pattern",left:f,right:"Wafer"},effect:{direction:"different",effectSize:i.features.globalRdd},stats:{method:"wafer-finding-frequency",sampleSizeLeft:t.size,sampleSizeRight:a-t.size},summary:`Spatial pattern: ${f.toLowerCase()}, seen on ${t.size}/${a} wafers${Y(n,a)} (${Math.round(l*100)}%)`,highlight:{kind:"wafer",waferIndices:[...t.keys()].sort((p,h)=>p-h),dieKeysByWafer:c}}}function Ze(e){const a=/^Rings? (\d+)(?:\s*[–-]\s*(\d+))?/.exec(e.comparison.left);if(!a)return[];const n=+a[1],i=a[2]?+a[2]:n;return Array.from({length:Math.max(0,i-n+1)},(t,f)=>n+f)}function Je(e,a){if(!a.size)return e.summary;const n=f=>f.toLowerCase();if(a.size===1)return`Spatial pattern: ${n([...a.keys()][0])}`;const i=re[e.comparison.left],t=[...a].sort((f,l)=>l[1]-f[1]).map(([f,l])=>`${n(f)} on ${l}`);return`Spatial pattern: ${i} (${t.join(", ")})`}function et(e,a){const n=Ke(a,"median"),i=e.map(p=>({waferIndex:p.waferIndex,yieldPercent:p.summary.stats.yieldPercent})).filter(p=>p.yieldPercent!==null),t=i.map(p=>p.yieldPercent),f=outlierWafers(t);if(!f)return[];const l=ie(t),c=[];for(const{index:p,severity:h,statistic:r}of f.outliers){const d=i[p],u=d.yieldPercent-l,y=fe({wafer:{metadata:e.find(w=>w.waferIndex===d.waferIndex)?.summary.wafer}},d.waferIndex);c.push({id:`inter-wafer:yield:${d.waferIndex}`,level:"inter-wafer",severity:h,variable:{kind:"yield",label:"Yield"},comparison:{family:"wafer",left:y,right:n.charAt(0).toUpperCase()+n.slice(1)},effect:{direction:u>0?"higher":"lower",absoluteDelta:u/100,relativeDelta:l===0?void 0:u/l,effectSize:r},stats:{method:f.method,sampleSizeLeft:1,sampleSizeRight:i.length-1},summary:`${y} yield is ${Math.abs(u).toFixed(1)} percentage points ${u>0?"higher":"lower"} than the ${n}`,highlight:{kind:"wafer",waferIndices:[d.waferIndex]}})}return c}function oe(e,a){if((a.enableTestValueAnalysis??"auto")!=="auto")return;let n=0;for(const i of e){const{tests:t,dies:f}=ge(i,a);n+=t*f}return ze(n)}export function analyzeWaferLot(e,a={}){const n=e.map(ne),i=oe(n,a),t=n.map((o,m)=>({waferIndex:m,summary:a.perWaferSummaries?.[m]??q(o,a,i)})),f=t.map(({waferIndex:o,summary:m})=>Q(m)??Q(q(n[o],a,i))),l=f.map((o,m)=>({waferIndex:m,byKey:new Map(o.candidates.map(b=>[b.key,b]))})),c=me(a).resolved,p=n.filter(o=>o.dies.some(ue)).length,h=n.length>0?de(n[0],"analyzeWaferLot"):void 0,r=De(n,c),d=r&&r.carriers.size>=N?r:null,u=[...h===void 0?[]:He(l,c,Ve(f,c.sectorCount),h,p),...Qe(t,d),...et(t,Te(t.map(o=>o.summary.wafer))),...Ee(t,c.significanceLevel)];if(d&&h!==void 0){const o=Xe(d,p,t.length);o.relatedIds=$e([d.classification.pattern],o.severity,u,Ze,h),o.relatedIds.length||delete o.relatedIds,u.push(o)}u.sort((o,m)=>{const b=o.severity==="unusual"?2:o.severity==="notable"?1:0,M=m.severity==="unusual"?2:m.severity==="notable"?1:0;return b!==M?M-b:o.summary.localeCompare(m.summary,"en")});const y=t.map(o=>o.summary.wafer).filter(o=>!!o),w={},v=[];if(y.length>0){const o=new Set;for(const m of y)for(const b of Object.keys(m))o.add(b);o.delete("wafer"),o.delete("waferId");for(const m of o){const b=y.filter(R=>m in R).map(R=>R[m]);b.every(R=>R===b[0])?w[m]=b[0]:v.push(m)}}const s=t.map(({waferIndex:o,summary:m})=>({waferIndex:o,yieldPercent:m.stats.yieldPercent})),g=t.map(({waferIndex:o,summary:m})=>m.stats.perTestStats?.length?{waferIndex:o,tests:m.stats.perTestStats}:null).filter(o=>o!==null);return{level:"lot",hasNotableFindings:u.some(o=>o.severity!=="info")||t.some(o=>o.summary.hasNotableFindings),findings:u,lot:Object.keys(w).length>0?w:void 0,...v.length>0?{mixedIdentityFields:v}:{},analysisOptions:he(a),stats:{waferCount:e.length,...tt(n,t.map(o=>o.summary)),...nt(Ie(t.map(o=>o.summary)))},lotYieldSeries:s,perWafer:t,...g.length>0?{perWaferTestStats:g}:{}}}function tt(e,a){const n={...Re(a)},i=Ae(a);i&&(n.yield=i);const t=ke(a,xe(e).defs);t&&(n.capability=t);const f=Me(a,e.map(l=>l.ringCount));return f&&(n.regionYield=f),n}const nt=e=>e?{testValueAnalysis:e}:{},ce=()=>new Promise(e=>setTimeout(e,0));export async function analyzeWaferLotAsync(e,a={}){const{onProgress:n,signal:i,...t}=a,f=e.map(ne),l=oe(f,t),c=[];let p=Date.now();for(let h=0;h<f.length;h++)i?.throwIfAborted(),c.push(t.perWaferSummaries?.[h]??q(f[h],t,l)),n?.(h+1,f.length),Date.now()-p>100&&(await ce(),p=Date.now());return await ce(),i?.throwIfAborted(),analyzeWaferLot(f,{...t,perWaferSummaries:c})}export function remapLotWaferIndices(e,a){const n=i=>a[i]??i;return{...e,perWafer:e.perWafer.map(i=>({...i,waferIndex:n(i.waferIndex)})),lotYieldSeries:e.lotYieldSeries.map(i=>({...i,waferIndex:n(i.waferIndex)})),...e.perWaferTestStats?{perWaferTestStats:e.perWaferTestStats.map(i=>({...i,waferIndex:n(i.waferIndex)}))}:{},findings:e.findings.map(i=>{const t=i.highlight;if(!t||t.kind!=="wafer")return i;const f=t.dieKeysByWafer?Object.fromEntries(Object.entries(t.dieKeysByWafer).map(([l,c])=>[n(Number(l)),c])):void 0;return{...i,highlight:{...t,waferIndices:t.waferIndices.map(n),...f?{dieKeysByWafer:f}:{}}}})}}
|
|
@@ -131,10 +131,8 @@ export declare function passesRateGate(adjustedP: number, delta: number, relEffe
|
|
|
131
131
|
* over the lot's. `patterns` holds more than one label for a lot row that
|
|
132
132
|
* counts a family together (edge-ring and edge-local wafers).
|
|
133
133
|
*
|
|
134
|
-
* A
|
|
135
|
-
*
|
|
136
|
-
* edge-arc rows keep their own severity — they carry their own evidence (a
|
|
137
|
-
* p-value, an exact die count) and are supporting detail, not a restatement.
|
|
134
|
+
* A row the pattern claims keeps its own severity: it is shown under the pattern's item with its own strength, and is
|
|
135
|
+
* counted once, through `relatedIds` (`findingsTally`).
|
|
138
136
|
*/
|
|
139
137
|
export declare function claimForPattern<F extends StatsFinding>(patterns: PatternLabel[], severity: StatsSeverity, candidates: readonly F[], ringsOf: (f: F) => number[], ringCount: number): string[];
|
|
140
138
|
/** A re-test of a regional finding against a reduced rest: its p-value (BH multiplier applied) and whether it still passes. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{normalizeInput as pt}from"./normalizeInput.js";import{autoDecision as gt,testValueStatus as bt}from"./testValueBudget.js";import{computeCapability as yt,computeTestFlagYield as St,computeRegionYield as vt}from"./summaryFigures.js";import{binPassSets as Te}from"../renderer/binColors.js";import{diePassStatus as ae,isYieldEligibleDie as Z,getDieKey as re,isPositionedDie as qe,positionKey as Re}from"../core/dies.js";import{dieHasValues as wt,testsPresent as Ie,testValue as Y}from"../core/dieTable.js";import{stackBinsAreData as $t}from"../core/aggregates.js";import{getTestPassStatus as pe,isParametricTest as J}from"../renderer/buildWaferMap.js";import{markedTestLabel as j,derivedFields as ge}from"../renderer/testLabel.js";import{buildQuadrantRegions as Rt,buildReticlePositionRegions as kt,buildRingRegions as Mt,buildSectorRegions as Dt,buildTestSiteRegions as zt,sectorCompassNames as je,areQuadrantsAdjacent as Bt,parseRegionKey as ee,QUADRANT_CYCLE as ke,regionAngleBins as Ft}from"./regions.js";import{buildClusterFindings as He}from"./clusterDetection.js";import{classifyPattern as Ct,classifyFailingDies as Nt,patternExplains as xt,patternFailVerdict as _e,PATTERN_LABELS as Pt}from"./patternClassification.js";import{requirePassBins as Vt}from"../core/passBins.js";import{requireRingCount as Et}from"../core/ringCount.js";import{benjaminiHochberg as Lt,fisherExact as Kt,fiveNumberSummary as Ot,sampleVariance as Me,zPValue as We}from"./math.js";import{mean as be,maxOf as At}from"../core/utils.js";import{classifySpec as ye,isOutOfSpec as De}from"../renderer/spec.js";import{ringOf as Tt}from"../core/classify.js";import{SEVERITY_ORDER as Ye,isOneBinCluster as Ue}from"./filterFindings.js";const qt={significanceLevel:{min:1e-6,max:1},minimumEffectSize:{min:0,max:1},minimumRelativeEffect:{min:0,max:Number.MAX_SAFE_INTEGER}},Qe=[4,8,16];export function resolveOptions(e){const t=Object.fromEntries(Object.entries(e).filter(([,a])=>a!==void 0)),s={...fe,...t},o=[],i=[];for(const a of["significanceLevel","minimumEffectSize","minimumRelativeEffect"]){const{min:d,max:r}=qt[a],l=s[a];if(typeof l!="number"||!Number.isFinite(l)){i.push(`${a}=${String(l)} is not a finite number (using ${fe[a]})`),s[a]=fe[a];continue}const u=Math.min(r,Math.max(d,l));u!==l&&(i.push(`${a}=${l} is outside ${d}\u2013${r} (using ${u})`),s[a]=u)}if(Qe.includes(s.sectorCount)||(i.push(`sectorCount=${s.sectorCount} is not one of ${Qe.join(", ")} (using ${fe.sectorCount})`),s.sectorCount=fe.sectorCount),i.length){const a=`analyzeWaferMap: ${i.join("; ")}. The analysis ran with the corrected values.`;console.warn(`[wafermap] ${a}`),o.push({code:"analysis-option-corrected",message:a,severity:"warning"})}const n=["passBins","ringCount"].filter(a=>t[a]!==void 0);if(n.length){const a=`analyzeWaferMap: ${n.join(" and ")} ${n.length>1?"are":"is"} no longer an analysis option and was ignored. Set ${n.length>1?"them":"it"} on buildWaferMap; the analysis used the value the map was built with.`;console.warn(`[wafermap] ${a}`),o.push({code:"analysis-option-corrected",message:a,severity:"warning"})}const f=["enableYieldAnalysis","enableHardBinAnalysis","enableSoftBinAnalysis","enableReticlePositionAnalysis","enableTestSiteAnalysis","enableClusterAnalysis","enableAngularAnalysis","enablePatternClassification"].filter(a=>t[a]!==void 0);if(f.length){const a=`analyzeWaferMap: ${f.join(", ")} ${f.length>1?"are":"is"} no longer an option and was ignored: every analysis now runs. Filter the findings (filterFindings) to show fewer.`;console.warn(`[wafermap] ${a}`),o.push({code:"analysis-option-corrected",message:a,severity:"warning"})}return{resolved:s,warnings:o}}const fe={significanceLevel:.05,minimumEffectSize:.2,minimumRelativeEffect:1,minimumSampleSize:5,enableTestValueAnalysis:"auto",computePerTestStats:!1,sectorCount:8,minimumClusterSize:5};function It(e,t){const s={...e};return s.minimumClusterSize=Math.max(5,Math.round(t*.003)),s}function Ge(e){return Z(e)?e.hbin!==void 0||e.sbin!==void 0||wt(e):!1}function jt(e,t,s){if(!e||t)return;const o=(s??[]).filter(i=>J(i)&&(i.limitLow!==void 0||i.limitHigh!==void 0));if(o.length!==0)return i=>{for(const n of o)if(De(ye(Y(i,n.testNumber),n)))return!0;return!1}}const Ht=8,_t=.8,Wt=.8,Yt=.5;function Ut(e,t,s,o,i){const n=new Set(o.passBins),f=e.filter(m=>ae(m,n)!==void 0),a=new Map;let d=0;for(const m of f)ae(m,n)||(d++,m.hbin!==void 0&&a.set(m.hbin,(a.get(m.hbin)??0)+1));const r=[...a].filter(([,m])=>m>=o.minimumClusterSize&&m<=_t*d).sort((m,c)=>c[1]-m[1]||m[0]-c[0]).slice(0,Ht).map(([m])=>m);if(!r.length)return[];const l=i.filter(m=>m.comparison.family==="cluster").map(Se),u=[];for(const m of r){const c=He(f,t,{...o,significanceLevel:o.significanceLevel/r.length,isFailingDie:h=>h.hbin===m,bin:{bin:m,label:xe(m,s,"HBin")}});u.push(...c.filter(h=>!l.some(p=>Gt(Se(h),p))))}return u}const Qt=.5;export function claimForBinClusters(e){const t=e.filter(s=>(s.comparison.family==="ring"||s.comparison.family==="quadrant"||s.comparison.family==="sector")&&s.variable.kind==="hardBin"&&s.effect.direction==="higher");for(const s of e){if(!Ue(s))continue;const o=Se(s),i=t.filter(n=>{if(n.variable.bin!==s.variable.bin||Ye[n.severity]<Ye[s.severity])return!1;const f=(n.effect.absoluteDelta??0)*n.stats.sampleSizeLeft;let a=0;for(const d of Se(n))o.has(d)&&a++;return f>0&&a>=Qt*f});if(s.severity!=="info")for(const n of i)n.severity="info";i.length&&(s.relatedIds=i.map(n=>n.id))}}function Se(e){return new Set("dieKeys"in e.highlight?e.highlight.dieKeys??[]:[])}function Gt(e,t){let s=0;for(const o of e)t.has(o)&&s++;return s>=Wt*e.size&&e.size>=Yt*t.size}function Xt(e,t,s,o){const i=new Set,n=new Set,f=new Set,a=new Map,d=new Map;for(const r of Ie(e))i.add(r);for(const r of o?e:[])r.hbin!==void 0&&n.add(r.hbin),r.sbin!==void 0&&f.add(r.sbin),Z(r)&&(r.hbin!==void 0&&a.set(r.hbin,(a.get(r.hbin)??0)+1),r.sbin!==void 0&&d.set(r.sbin,(d.get(r.sbin)??0)+1));return{totalDies:e.length,analyzedDies:t,excludedDies:e.length-t,yieldPercent:s,testsConsidered:[...i].sort((r,l)=>r-l),hardBinsConsidered:[...n].sort((r,l)=>r-l),softBinsConsidered:[...f].sort((r,l)=>r-l),...a.size?{hardBinCounts:Object.fromEntries(a)}:{},...d.size?{softBinCounts:Object.fromEntries(d)}:{}}}function Zt(e,t,s){if(!t?.length)return;const o=t.filter(n=>J(n)&&(n.limitLow!==void 0||n.limitHigh!==void 0));if(!o.length)return;const i=[];for(const n of o){const f=n.testNumber;let a=0,d=0,r=0,l=0;for(const u of e){if(!Z(u))continue;const m=ye(Y(u,f),n);if(m!==null){if(l++,m==="failLow")d++;else if(m==="failHigh")r++;else{a++;continue}s?.(f,u)}}i.push({testNumber:f,label:j(n,f),passDies:a,failLowDies:d,failHighDies:r,totalDies:l,yieldPercent:l>0?a/l*100:null})}return i.length?i:void 0}export function computeFunctionalYield(e,t,s){if(!t?.length)return;const o=t.filter(n=>!J(n));if(!o.length)return;const i=[];for(const n of o){const f=n.testNumber;let a=0,d=0;for(const l of e){if(!Z(l))continue;const u=pe(l,f,n);if(u!==void 0){if(u){a++;continue}d++,s?.(f,l)}}const r=a+d;i.push({testNumber:f,label:j(n,f),...ge(n),passDies:a,failDies:d,totalDies:r,passRatePercent:r>0?a/r*100:null})}return i.length?i:void 0}function Jt(e,t,s,o){const i=[];for(const n of t){const f=[];for(const u of e){if(!Z(u))continue;const m=Y(u,n);m!==void 0&&Number.isFinite(m)&&f.push(m)}if(f.length<o)continue;const a=be(f),d=Math.sqrt(Me(f,a)),r=Ot(Float64Array.from(f)),l=s?.find(u=>u.testNumber===n)?.name??String(n);i.push({testNumber:n,label:l,count:f.length,min:r.min,max:r.max,mean:a,stddev:d,median:r.median,q1:r.q1,q3:r.q3})}return i.length?i:void 0}export function twoProportionZ(e,t,s,o){const i=(e+s)/(t+o),n=i*(1-i)*(1/t+1/o);return!Number.isFinite(n)||n<=0?0:(e/t-s/o)/Math.sqrt(n)}const en=5;function H(e,t,s,o){const i=t+o,n=e+s;if((i>0?Math.min(n,i-n)*Math.min(t,o)/i:0)<en)return{pValue:Kt(e,t-e,s,o-s),method:"fisher-exact"};const a=twoProportionZ(e,t,s,o);return{pValue:a===0?1:We(a),method:"two-proportion-z"}}function tn(e,t,s,o){return H(e,t,s,o).pValue}export function adjustPValues(e){const t=e.filter(o=>o.stats.pValue!==void 0),s=Lt(t.map(o=>o.stats.pValue));return t.forEach((o,i)=>{o.stats.adjustedPValue=s[i]}),e}export function rateRelativeEffect(e){const t=(e.passRate?e.n-e.hits:e.hits)/e.n,s=(e.passRate?e.restN-e.restHits:e.restHits)/e.restN;return s===0?t===0?0:1/0:Math.abs(t-s)/s}export function severityForFinding(e,t,s){const o=Math.abs(t),i=s;return e<=.01&&(o>=.3||i>=2.5)?"unusual":e<=.05&&(o>=.2||i>=1.5)?"notable":"info"}export function severityForScore(e,t){return e<=.01&&Math.abs(t)>=.5?"unusual":e<=.05&&Math.abs(t)>=.15?"notable":"info"}function ve(e){return e==="reticle-position"?"other reticle positions":e==="test-site"?"other test sites":"the rest of the map"}function te(e){return e==="reticle-position"?"Other reticle positions":e==="test-site"?"Other test sites":"Rest of map"}function ze(e,t,s){const o=(Math.abs(t)*100).toFixed(1);return`${e} yield is ${o} percentage points ${t>0?"higher":"lower"} than ${ve(s)}`}function Be(e,t){return t==="quadrant"&&!e.startsWith("Quadrant")?`quadrant ${e}`:e}function Xe(e){return/^(Rings|Sectors|Quadrants)\b/.test(e)?"have":"has"}function Fe(e,t,s,o){const i=Be(e,o),n=(Math.abs(s)*100).toFixed(1);return`${i} ${Xe(i)} ${t} occurrence ${n} percentage points ${s>0?"higher":"lower"} than ${ve(o)}`}function Ce(e,t,s,o){const i=Be(e,o),n=(Math.abs(s)*100).toFixed(1);return`${i} ${Xe(i)} ${t} pass rate ${n} percentage points ${s>0?"higher":"lower"} than ${ve(o)}`}function Ne(e,t,s,o,i,n){const f=Be(e,i),a=ve(i),d=s>0?"higher":"lower";if(o!==void 0&&Number.isFinite(o)){const l=(Math.abs(o)*100).toFixed(1);return`${f} mean ${t} is ${l}% ${d} than ${a}`}const r=n?` ${n}`:"";return`${f} mean ${t} is ${Math.abs(s).toPrecision(3)}${r} ${d} than ${a}`}function xe(e,t,s){const o=t?.find(i=>i.bin===e);return o?.name?`${s} ${e} (${o.name})`:`${s} ${e}`}function nn(e,t){const s=t?.find(o=>o.testNumber===e);return{label:j(s,e),unit:s?.unit,...ge(s)}}const Ze=new WeakMap,Je=new WeakMap,et=new WeakMap;function le(e,t){const s=t.highlight.dieKeys;return s&&et.set(s,e),t}let ne=null,ce;const tt=new WeakMap;export function candidatesOf(e){return tt.get(e)}function nt(e,t,s,o){if(!ne)return;const i=it(e);if(!i)return;const n=e.id.slice(0,e.id.indexOf(":")),f=n==="specLimit"?"limitFail":n,{kind:a,bin:d,index:r}=e.variable;ne.push({key:[f,a,d??"",r??"",i.family,i.key].join("|"),source:f,variable:e.variable,label:e.variable.label,comparison:e.comparison,region:i,z:t,delta:e.effect.absoluteDelta??0,effectSize:e.effect.effectSize??0,relativeDelta:e.effect.relativeDelta,rate:s,mean:o})}export function describeRegional(e,t,s){const o=e.comparison.left,i=e.region.family;switch(e.source){case"yield":return ze(o,t,i);case"hardBin":case"softBin":return Fe(o,e.label,t,i);case"functional":return Ce(o,e.label.replace(/ pass rate$/,""),t,i);case"limitFail":return Pe(o,e.label,t);case"test":return Ne(o,e.label,t,s,i,e.variable.unit)}}function Pe(e,t,s){return`${e} limit fail rate for ${t} is ${(Math.abs(s)*100).toFixed(1)} pp ${s>0?"higher":"lower"} than the rest of the wafer`}const U=new WeakMap;function we(e,t){return U.set(e,t),e}function it(e){const t=e.highlight.dieKeys;return t?et.get(t):void 0}const st=new WeakMap;function Q(e){let t=st.get(e);return t||st.set(e,t=e.map(Re)),t}function sn(e){let t=Ze.get(e);return t||Ze.set(e,t=e.map(re)),t}function $e(e,t){let s=Je.get(e);s||Je.set(e,s={members:new Set(e),byFamily:new WeakMap});const o=s.byFamily.get(t);if(o)return o;const{members:i}=s,n=new Map;for(const f of t)n.set(f.key,f.dies.filter(a=>i.has(a)));return s.byFamily.set(t,n),n}function on(e,t){adjustPValues(e);for(const i of e){const n=U.get(i);nt(i,twoProportionZ(n.hits,n.n,n.restHits,n.restN),n)}const s=e.filter(i=>passesRateGate(i.stats.adjustedPValue??i.stats.pValue??1,i.effect.absoluteDelta??0,rateRelativeEffect(U.get(i)),t)),o=confirmRegionalFindings(s,ot,(i,n)=>an(i,n,t),i=>isRateLoss(U.get(i)),e);return s.filter(i=>o.has(i)).map(i=>({...i,severity:severityForFinding(i.stats.adjustedPValue??i.stats.pValue??1,i.effect.absoluteDelta??0,rateRelativeEffect(U.get(i)))}))}export function passesRateGate(e,t,s,o){return e<=o.significanceLevel&&(Math.abs(t)>=o.minimumEffectSize||s>=o.minimumRelativeEffect)}export function claimForPattern(e,t,s,o,i){const n=[];for(const f of s){const a=f.comparison.family,d=a==="ring"||a==="cluster"?o(f):[];e.some(r=>xt(r,a,d,i))&&(n.push(f.id),t!=="info"&&(a==="ring"||a==="quadrant"||a==="sector")&&(f.severity="info"))}return n}export function confirmRegionalFindings(e,t,s,o,i=e){const n=new Map;for(const d of e)(n.get(t(d))??n.set(t(d),[]).get(t(d))).push(d);const f=new Map;if(o)for(const d of i)o(d)&&(f.get(t(d))??f.set(t(d),[]).get(t(d))).push(d);const a=new Set;for(const[d,r]of n){const l=f.get(d)??[],u=(h,p)=>o&&!o(h)?s(h,[...new Set([...p,...l])].filter(g=>g!==h)):s(h,p);if(r.length===1&&(!o||o(r[0])||l.length===0)){a.add(r[0]);continue}const m=[];let c=[...r];for(;;){let h;for(const p of c){const g=u(p,m);if(g==="baseline-too-small"||!g.passes)continue;const S=o?.(p)??!1;(!h||S&&!h.loss||S===h.loss&&g.pValue<h.p)&&(h={t:p,p:g.pValue,loss:S})}if(!h)break;m.push(h.t),c=c.filter(p=>p!==h.t)}for(;;){let h;for(const p of m){const g=u(p,m.filter(S=>S!==p));g==="baseline-too-small"||g.passes||(!h||g.pValue>h.p)&&(h={t:p,p:g.pValue})}if(!h)break;m.splice(m.indexOf(h.t),1)}for(const h of m)a.add(h)}return a}function ot(e){return[e.variable.kind,e.variable.bin??"",e.variable.index??"",e.comparison.family].join("\0")}function at(e){const t=e.stats.pValue??1;return t>0?(e.stats.adjustedPValue??t)/t:1}export function isRateLoss(e){const t=e.hits/e.n-e.restHits/e.restN;return e.passRate?t<0:t>0}function an(e,t,s){const o=U.get(e);let{restHits:i,restN:n}=o;for(const r of t){const l=U.get(r);l&&(i-=l.hits,n-=l.n)}if(n<s.minimumSampleSize)return"baseline-too-small";const f=o.hits/o.n-i/n,a=Math.min(1,tn(o.hits,o.n,i,n)*at(e)),d=Math.sign(f)===Math.sign(e.effect.absoluteDelta??0)&&passesRateGate(a,f,rateRelativeEffect({...o,restHits:i,restN:n}),s);return{pValue:a,passes:d}}const Ve=new WeakMap;export function welchOfSums(e,t,s,o){const i=(n,f,a)=>a>1?Math.max(0,n-f*f/a)/(a-1):0;return welchFromStats(e.n,e.sum/e.n,i(e.sq,e.sum,e.n),t,s/t,i(o,s,t))}function rn(e,t,s){const o=Ve.get(e);let{restN:i,restSum:n,restSq:f}=o;for(const m of t){const c=Ve.get(m);c&&(i-=c.n,n-=c.sum,f-=c.sq)}if(i<s.minimumSampleSize)return"baseline-too-small";const{pValue:a,effectSize:d,delta:r}=welchOfSums(o,i,n,f),l=Math.min(1,a*at(e)),u=Math.sign(r)===Math.sign(e.effect.absoluteDelta??0)&&l<=s.significanceLevel&&Math.abs(d)>=s.minimumEffectSize;return{pValue:l,passes:u}}function ue(e,t,s,o){const i=new Set(s),n=$e(e,t),f=new Map,a=new Map;for(const[r,l]of n){let u=0,m=0;for(const c of l)c.hbin!==void 0&&(m++,i.has(c.hbin)&&u++);f.set(r,u),a.set(r,m)}const d=[];for(const r of t){const l=a.get(r.key)??0,u=f.get(r.key)??0;let m=0,c=0;for(const[k,v]of a)k!==r.key&&(m+=v,c+=f.get(k)??0);if(l<o.minimumSampleSize||m<o.minimumSampleSize)continue;const h=u/l,p=c/m,g=h-p,{pValue:S,method:F}=H(u,l,c,m);d.push(we(le(r,{id:`yield:${r.key}`,level:"wafer",severity:"info",variable:{kind:"yield",label:"Yield"},comparison:{family:r.family,left:r.label,right:te(r.family)},effect:{direction:g===0?"different":g>0?"higher":"lower",absoluteDelta:g,relativeDelta:p===0?void 0:g/p,effectSize:g},stats:{method:F,pValue:S,sampleSizeLeft:l,sampleSizeRight:m},summary:ze(r.label,g,r.family),highlight:{kind:"region",regionFamily:r.family,regionKeys:[r.key],dieKeys:[...r.dieKeys]}}),{hits:u,n:l,restHits:c,restN:m,passRate:!0}))}return d}function q(e,t,s,o,i,n){const f=h=>s==="soft"?h.sbin:h.hbin,a=[...new Set(e.map(f).filter(h=>h!==void 0))].sort((h,p)=>h-p),d=$e(e,t),r=new Map,l=new Map;for(const[h,p]of d){const g=new Map;for(const S of p){const F=f(S);F!==void 0&&g.set(F,(g.get(F)??0)+1)}r.set(h,g),l.set(h,p.length)}const u=[],m=i==="hardBin"?"HBin":"SBin",c=s==="hard"?new Set(n.passBins):n.softPassBins??Te(e,n.passBins).soft;for(const h of t){const p=l.get(h.key)??0,g=r.get(h.key);let S=0;const F=new Map;for(const[k,v]of r)if(k!==h.key){S+=l.get(k)??0;for(const[B,z]of v)F.set(B,(F.get(B)??0)+z)}if(!(p<n.minimumSampleSize||S<n.minimumSampleSize))for(const k of a){const v=g.get(k)??0,B=F.get(k)??0,z=v/p,b=B/S,w=z-b,{pValue:M,method:y}=H(v,p,B,S),$=xe(k,o,m);u.push(we(le(h,{id:`${i}:${k}:${h.key}`,level:"wafer",severity:"info",variable:{kind:i,bin:k,label:$},comparison:{family:h.family,left:h.label,right:te(h.family)},effect:{direction:w===0?"different":w>0?"higher":"lower",absoluteDelta:w,relativeDelta:b===0?void 0:w/b,effectSize:w},stats:{method:y,pValue:M,sampleSizeLeft:p,sampleSizeRight:S},summary:Fe(h.label,$,w,h.family),highlight:{kind:"bin",bin:k,regionKeys:[h.key],dieKeys:[...h.dieKeys]}}),{hits:v,n:p,restHits:B,restN:S,passRate:c.has(k)}))}}return u}function de(e,t,s,o){const i=(s??[]).filter(l=>!J(l));if(!i.length)return[];const n=i.map(l=>l.testNumber),f=$e(e,t),a=new Map,d=new Map;for(const[l,u]of f){const m=new Uint32Array(i.length),c=new Uint32Array(i.length);for(const h of u)for(let p=0;p<i.length;p++){const g=pe(h,n[p],i[p]);g!==void 0&&(c[p]++,g&&m[p]++)}a.set(l,m),d.set(l,c)}const r=[];for(const l of t){const u=a.get(l.key),m=d.get(l.key);for(let c=0;c<i.length;c++){let h=0,p=0;for(const[w,M]of d)w!==l.key&&(p+=M[c],h+=a.get(w)[c]);const g=m[c],S=u[c];if(g<o.minimumSampleSize||p<o.minimumSampleSize)continue;const F=S/g,k=h/p,v=F-k,{pValue:B,method:z}=H(S,g,h,p),b=n[c];r.push(we(le(l,{id:`functional:${b}:${l.key}`,level:"wafer",severity:"info",variable:{kind:"functionalTest",index:b,label:`${j(i[c],b)} pass rate`,...ge(i[c])},comparison:{family:l.family,left:l.label,right:te(l.family)},effect:{direction:v===0?"different":v>0?"higher":"lower",absoluteDelta:v,relativeDelta:k===0?void 0:v/k,effectSize:v},stats:{method:z,pValue:B,sampleSizeLeft:g,sampleSizeRight:p},summary:Ce(l.label,j(i[c],b),v,l.family),highlight:{kind:"region",regionFamily:l.family,regionKeys:[l.key],dieKeys:[...l.dieKeys]}}),{hits:S,n:g,restHits:h,restN:p,passRate:!0}))}}return r}export function welchFromStats(e,t,s,o,i,n){const f=Math.sqrt(s/e+n/o),a=t-i;if(!Number.isFinite(f)||f===0)return{pValue:1,effectSize:0,delta:a,z:0};const d=a/f,r=Math.sqrt(Math.max(0,(s+n)/2)),l=r===0?a:a/r;return{pValue:We(d),effectSize:l,delta:a,z:d}}function fn(e,t){const s=be(e),o=be(t);return welchFromStats(e.length,s,Me(e,s),t.length,o,Me(t,o))}function rt(e,t,s){const o=new Map;for(const n of s??[])o.has(n.testNumber)||o.set(n.testNumber,n);const i=n=>n.filter(f=>J(o.get(f)));return i(t?t.slice().sort((n,f)=>n-f):Ie(e,"values"))}export function testValueSize(e,t){const s=e.dies.filter(Ge);return{tests:rt(s,t.testNumbers,e.testDefs).length,dies:s.length}}export function recordedOptions(e){const t={};return e.enableTestValueAnalysis!==void 0&&(t.enableTestValueAnalysis=e.enableTestValueAnalysis),e.computePerTestStats!==void 0&&(t.computePerTestStats=e.computePerTestStats),e.sectorCount!==void 0&&(t.sectorCount=e.sectorCount),e.testNumbers!==void 0&&(t.testNumbers=[...e.testNumbers]),t}function ln(e,t,s,o,i){const n=new Map;for(let p=0;p<t.length;p++)for(const g of Q(t[p].dies))n.set(g,p);const f=t.length,a=[],d=[];for(const p of e){const g=n.get(Re(p));g!==void 0&&(a.push(p),d.push(g))}const r=[],l=new Float64Array(f),u=new Float64Array(f),m=new Float64Array(f);for(const p of s){l.fill(0),u.fill(0),m.fill(0);let g=0,S=0,F=0,k;for(let v=0;v<a.length;v++){const B=a[v],z=Y(B,p);if(z===void 0)continue;k===void 0&&(k=z);const b=z-k,w=d[v];l[w]+=1,u[w]+=b,m[w]+=b*b,g+=1,S+=b,F+=b*b}if(k!==void 0)for(let v=0;v<f;v++){const B=l[v],z=g-B;if(B<i.minimumSampleSize||z<i.minimumSampleSize)continue;const b=u[v]/B,M=(S-u[v])/z,y=b+k,$=M+k,P=B>1?Math.max(0,m[v]-B*b*b)/(B-1):0,C=z>1?Math.max(0,F-m[v]-z*M*M)/(z-1):0,{pValue:V,effectSize:x,delta:D,z:O}=welchFromStats(B,y,P,z,$,C),N=t[v],{label:A,unit:L,...G}=nn(p,o),_=$!==0?D/Math.abs($):void 0,X=le(N,{id:`test:${p}:${N.key}`,level:"wafer",severity:"info",variable:{kind:"test",measure:"mean",index:p,label:A,unit:L,...G},comparison:{family:N.family,left:N.label,right:te(N.family)},effect:{direction:D===0?"different":D>0?"higher":"lower",absoluteDelta:D,relativeDelta:_,effectSize:x},stats:{method:"welch-z-approx",pValue:V,sampleSizeLeft:B,sampleSizeRight:z},summary:Ne(N.label,A,D,_,N.family,L),highlight:{kind:"region",regionFamily:N.family,regionKeys:[N.key],dieKeys:[...N.dieKeys]}}),R={n:B,sum:u[v],sq:m[v],restN:z,restSum:S-u[v],restSq:F-m[v],shift:k};Ve.set(X,R),nt(X,O,void 0,R),r.push(X)}}adjustPValues(r);const c=r.filter(p=>{const g=p.stats.adjustedPValue??p.stats.pValue??1,S=Math.abs(p.effect.effectSize??0);return g<=i.significanceLevel&&S>=i.minimumEffectSize}),h=confirmRegionalFindings(c,ot,(p,g)=>rn(p,g,i));return c.filter(p=>h.has(p)).map(p=>({...p,severity:severityForScore(p.stats.adjustedPValue??p.stats.pValue??1,p.effect.effectSize??0)}))}function cn(e,t,s,o){if(!s?.length)return[];const i=s.filter(f=>J(f)&&(f.limitLow!==void 0||f.limitHigh!==void 0));if(!i.length)return[];const n=[];for(const f of i){const a=f.testNumber;for(const d of t){const r=$e(e,d),l=[],u=new Map;let m=0,c=0;for(const[h,p]of r){let g=0,S=0;for(const F of p){const k=Y(F,a);k!==void 0&&(g++,De(ye(k,f))&&S++)}u.set(h,{valid:g,fail:S}),m+=g,c+=S}for(const h of d){const p=u.get(h.key),g=p.valid,S=m-p.valid;if(g<o.minimumSampleSize||S<o.minimumSampleSize)continue;const F=p.fail,k=c-p.fail,v=F/g,B=k/S,z=v-B,{pValue:b,method:w}=H(F,g,k,S);l.push(we(le(h,{id:`specLimit:${a}:${h.key}`,level:"wafer",severity:"info",variable:{kind:"test",measure:"limitFailRate",index:a,label:j(f,a),...ge(f)},comparison:{family:h.family,left:h.label,right:te(h.family)},effect:{direction:z===0?"different":z>0?"higher":"lower",absoluteDelta:z,relativeDelta:B===0?void 0:z/B,effectSize:z},stats:{method:w,pValue:b,sampleSizeLeft:g,sampleSizeRight:S},summary:Pe(h.label,j(f,a),z),highlight:{kind:"region",regionFamily:h.family,regionKeys:[h.key],dieKeys:[...h.dieKeys]}}),{hits:F,n:g,restHits:k,restN:S,passRate:!1}))}n.push(...l)}}return n}function Ee(e,t){return e==="softBin"?t.softEligibleDies:t.eligibleDies}function un(e){return e.variable.measure==="limitFailRate"}function dn(e,t,s,o,i,n){if(e.pattern!=="scratch")return;const f=t.filter(l=>l.comparison.family==="reticle-position"&&l.severity!=="info"&&l.highlight.kind==="region");if(!f.length)return;const a=new Set(f.flatMap(l=>l.highlight.kind==="region"?l.highlight.dieKeys??[]:[])),d=Nt(s().filter(l=>!a.has(re(l))),o,i,n);if(!d||d.pattern==="scratch")return;const r=f[0].comparison.left;return{...d,note:`${r.charAt(0).toLowerCase()}${r.slice(1)}'s failures set aside`}}function me(e){return e.highlight.regionKeys??[]}function mn(e){const t=e.variable.bin??e.variable.index??"";return`${e.comparison.family}\0${ft(e)}\0${e.variable.kind}\0${t}\0${e.effect.direction}`}function hn(e,t){const s=ee(e);return s.family==="ring"?s.ring??0:s.family==="sector"?je(t).indexOf(s.sector??""):0}export function inQuadrantOrder(e){const t=new Set(e),s=ke.findIndex((i,n)=>t.has(i)&&!t.has(ke[(n+3)%4])),o=s<0?0:s;return Array.from({length:4},(i,n)=>ke[(o+n)%4]).filter(i=>t.has(i))}export function findContiguousRuns(e,t,s,o){if(t==="quadrant"){const d=new Map;for(const m of e){const c=ee(o(m)).quadrant;c&&d.set(c,m)}const r=[...d.keys()],l=new Set,u=[];for(const m of r){if(l.has(m))continue;const c=[],h=[m];for(l.add(m);h.length;){const p=h.pop();c.push(p);for(const g of r)!l.has(g)&&Bt(p,g)&&(l.add(g),h.push(g))}u.push(inQuadrantOrder(c).map(p=>d.get(p)))}return u}const i=d=>hn(o(d),s),n=[...e].sort((d,r)=>i(d)-i(r)),f=[];let a=[];for(const d of n){if(a.length===0){a.push(d);continue}const r=i(a[a.length-1]);i(d)-r===1?a.push(d):(f.push(a),a=[d])}if(a.length&&f.push(a),t==="sector"&&f.length>1){const r=je(s).length,l=i(f[0][0]),u=i(f[f.length-1][f[f.length-1].length-1]);if(l===0&&u===r-1){const m=f.pop();f[0]=[...m,...f[0]]}}return f}export function mergedRegionLabel(e,t,s){if(e==="ring"){const i=t.map(d=>ee(d).ring).filter(d=>d!==void 0).sort((d,r)=>d-r),n=i[0],f=i[i.length-1];let a="";return n===f&&n===1&&s>1?a=" (core)":n===f&&n===s&&s>1&&(a=" (edge)"),n===f?`Ring ${n}${a}`:`Rings ${n}\u2013${f}`}if(e==="sector"){const i=t.map(n=>ee(n).sector??"");return i.length===1?`Sector ${i[0]}`:`Sectors ${i[0]}\u2013${i[i.length-1]}`}const o=t.map(i=>ee(i).quadrant??"");return o.length===1?o[0]:o.length===2?`Quadrants ${o[0]} & ${o[1]}`:`Quadrants ${o.slice(0,-1).join(", ")} & ${o[o.length-1]}`}function Le(e){return[...new Set(e)]}export function weakestMultiplier(e){return At(e.map(t=>{const s=t.stats.pValue??1;return s>0?(t.stats.adjustedPValue??s)/s:1}))}function ie(e,t){return Math.min(1,e*t)}function pn(e,t){const s=e[0],o=s.comparison.family,i=s.variable.kind,n=Le(e.flatMap(me));let f,a;const d=e.map(it);if(d.every(b=>b!==void 0)){const b=new Set;f=[];for(const M of d){const y=Q(M.dies);for(let $=0;$<y.length;$++)b.has(y[$])||(b.add(y[$]),f.push(M.dieKeys[$]))}const w=Q(Ee(s.variable.kind,t));a=M=>b.has(w[M])}else{f=Le(e.flatMap(M=>M.highlight.dieKeys??[]));const b=new Set(f),w=sn(Ee(s.variable.kind,t));a=M=>b.has(w[M])}const r=mergedRegionLabel(o,e.map(b=>me(b)[0]??""),t.ringCount),l=Ee(i,t),u=t.regionDies[o],m=Q(l),c=[],h=[];for(let b=0;b<l.length;b++)u.has(m[b])&&(a(b)?c:h).push(l[b]);const p=weakestMultiplier(e);let g,S,F,k,v;if(un(s)){const b=s.variable.index,w=t.testDefs?.find(N=>N.testNumber===b),M=N=>{let A=0,L=0;for(const G of N){const _=Y(G,b);_!==void 0&&(A++,w&&De(ye(_,w))&&L++)}return{valid:A,fail:L}},y=M(c),$=M(h),P=y.valid>0?y.fail/y.valid:0,C=$.valid>0?$.fail/$.valid:0,V=P-C,{pValue:x,method:D}=H(y.fail,y.valid,$.fail,$.valid);g={direction:V===0?"different":V>0?"higher":"lower",absoluteDelta:V,relativeDelta:C===0?void 0:V/C,effectSize:V},S={method:D,pValue:x,sampleSizeLeft:y.valid,sampleSizeRight:$.valid};const O=ie(x,p);F=severityForFinding(O,V,rateRelativeEffect({hits:y.fail,n:y.valid,restHits:$.fail,restN:$.valid,passRate:!1})),k=Pe(r,j(w,b),V),v=`specLimit:${b}`}else if(i==="test"){const b=s.variable.index,w=O=>Y(O,b),M=c.map(w).filter(O=>O!==void 0),y=h.map(w).filter(O=>O!==void 0),{pValue:$,effectSize:P,delta:C}=fn(M,y),V=be(y),x=V!==0?C/Math.abs(V):void 0;g={direction:C===0?"different":C>0?"higher":"lower",absoluteDelta:C,relativeDelta:x,effectSize:P},S={method:"welch-z-approx",pValue:$,sampleSizeLeft:M.length,sampleSizeRight:y.length};const D=ie($,p);F=severityForScore(D,P),k=Ne(r,s.variable.label,C,x,o,s.variable.unit),v=`test:${b}`}else if(i==="yield"){const b=new Set(t.passBins),w=c.filter(L=>L.hbin!==void 0),M=h.filter(L=>L.hbin!==void 0),y=w.length,$=M.length,P=w.filter(L=>b.has(L.hbin)).length,C=M.filter(L=>b.has(L.hbin)).length,V=y>0?P/y:0,x=$>0?C/$:0,D=V-x,{pValue:O,method:N}=H(P,y,C,$);g={direction:D===0?"different":D>0?"higher":"lower",absoluteDelta:D,relativeDelta:x===0?void 0:D/x,effectSize:D},S={method:N,pValue:O,sampleSizeLeft:y,sampleSizeRight:$};const A=ie(O,p);F=severityForFinding(A,D,rateRelativeEffect({hits:P,n:y,restHits:C,restN:$,passRate:!0})),k=ze(r,D,o),v="yield"}else if(i==="functionalTest"){const b=s.variable.index,w=t.testDefs?.find(A=>A.testNumber===b);let M=0,y=0,$=0,P=0;for(const A of c){const L=pe(A,b,w);L!==void 0&&(y++,L&&M++)}for(const A of h){const L=pe(A,b,w);L!==void 0&&(P++,L&&$++)}const C=y>0?M/y:0,V=P>0?$/P:0,x=C-V,{pValue:D,method:O}=H(M,y,$,P);g={direction:x===0?"different":x>0?"higher":"lower",absoluteDelta:x,relativeDelta:V===0?void 0:x/V,effectSize:x},S={method:O,pValue:D,sampleSizeLeft:y,sampleSizeRight:P};const N=ie(D,p);F=severityForFinding(N,x,rateRelativeEffect({hits:M,n:y,restHits:$,restN:P,passRate:!0})),k=Ce(r,j(w,b),x,o),v=`functional:${b}`}else{const b=s.variable.bin,w=N=>i==="softBin"?N.sbin:N.hbin,M=c.filter(N=>w(N)===b).length,y=h.filter(N=>w(N)===b).length,$=M/c.length,P=y/h.length,C=$-P,{pValue:V,method:x}=H(M,c.length,y,h.length);g={direction:C===0?"different":C>0?"higher":"lower",absoluteDelta:C,relativeDelta:P===0?void 0:C/P,effectSize:C},S={method:x,pValue:V,sampleSizeLeft:c.length,sampleSizeRight:h.length};const D=ie(V,p);F=severityForFinding(D,C,rateRelativeEffect({hits:M,n:c.length,restHits:y,restN:h.length,passRate:!1}));const O=i==="softBin"?t.sbinDefs:t.hbinDefs;k=Fe(r,xe(b,O,i==="softBin"?"SBin":"HBin"),C,o),v=`${i}:${b}`}S={...S,adjustedPValue:ie(S.pValue??1,p)};const B=Le(n.map(b=>b.replace(`${o}:`,""))).join("-"),z=i==="hardBin"||i==="softBin"?{kind:"bin",bin:s.variable.bin,regionKeys:n,dieKeys:f}:{kind:"region",regionFamily:o,regionKeys:n,dieKeys:f};return{...s,id:`${v}:${o}:${B}`,severity:F,comparison:{family:o,left:r,right:te(o)},effect:g,stats:S,summary:k,highlight:z,relatedIds:e.map(b=>b.id)}}function gn(e,t){const s=new Set(["ring","quadrant","sector"]),o=[],i=new Map;for(const f of e){if(!s.has(f.comparison.family)){o.push(f);continue}const a=mn(f),d=i.get(a)??[];d.push(f),i.set(a,d)}const n=[];for(const f of i.values()){if(f.length===1){n.push(f[0]);continue}const a=f[0].comparison.family;for(const d of findContiguousRuns(f,a,t.sectorCount,r=>me(r)[0]??""))n.push(d.length===1?d[0]:pn(d,t))}return[...o,...n]}function bn(e){const t=new Map,s=new Map;for(const i of e){const n=Re(i);i.hbin!==void 0&&i.hbin!==null&&(t.get(i.hbin)??t.set(i.hbin,new Set).get(i.hbin)).add(n),i.sbin!==void 0&&i.sbin!==null&&(s.get(i.sbin)??s.set(i.sbin,new Set).get(i.sbin)).add(n)}const o=new Set;for(const[i,n]of t)for(const[f,a]of s){if(n.size!==a.size)continue;let d=!0;for(const r of n)if(!a.has(r)){d=!1;break}d&&o.add(`${i}:${f}`)}return o}function yn(e,t){const s=new Set(t);let o;for(const i of e){const n=ae(i,s);if(n!==void 0&&n){if(i.sbin==null||o!==void 0&&i.sbin!==o)return;o=i.sbin}}if(o!==void 0){for(const i of e)if(i.sbin===o&&ae(i,s)!==!0)return;return o}}function Sn(e){return`${e.comparison.family}\0${e.comparison.left}`}export function redundancyFacts(e,t,s){return{coincident:bn(e),yieldSoftBin:yn(e,t),passBins:t,sectorCount:s}}const vn=3/5;function ft(e){return/^(?:lot-region:)?([^:|]+)/.exec(e.id)?.[1]??e.id}function wn(e){const t=me(e);if(t.length)return t;const s=/(ring|sector|quadrant):([^:|]+)$/.exec(e.id);return s?s[2].split("-").map(o=>`${s[1]}:${o}`):[]}function lt(e,t){const s=new Set;for(const o of wn(e)){const i=Ft(o,t);if(!i)return;for(const n of i)s.add(n)}return s.size?s:void 0}export function collapseRedundantFindings(e,t){const{coincident:s,yieldSoftBin:o,passBins:i}=t,n=(r,l)=>{r.absorbedIds=[...r.absorbedIds??[],l.id]},f=new Map;for(const r of e){const l=Sn(r);(f.get(l)??f.set(l,[]).get(l)).push(r)}const a=new Set;for(const r of f.values()){for(const u of r)if(!(u.variable.kind!=="hardBin"||u.variable.bin===void 0))for(const m of r){if(m.variable.kind!=="softBin"||m.variable.bin===void 0||a.has(m.id)||!s.has(`${u.variable.bin}:${m.variable.bin}`)||m.effect.direction!==u.effect.direction)continue;n(u,m),a.add(m.id);const c=u.variable.label.replace(/^HBin\s+/,""),h=m.variable.label.replace(/^SBin\s+/,""),p=c===h?`HBin and SBin ${c} (same dies)`:`${u.variable.label} and ${m.variable.label} (same dies)`;u.summary=u.summary.replace(u.variable.label,p),u.variable.label=p;break}const l=r.find(u=>u.variable.kind==="yield");if(l){for(const u of r)if(!(u===l||a.has(u.id)||!(u.variable.kind==="hardBin"&&i.length===1&&u.variable.bin===i[0]||u.variable.kind==="softBin"&&u.variable.bin===o))){n(l,u),a.add(u.id);for(const c of u.absorbedIds??[])l.absorbedIds=[...l.absorbedIds??[],c]}}}const d=new Map;for(const r of e){if(a.has(r.id)||r.comparison.family!=="sector"&&r.comparison.family!=="quadrant")continue;const l=[ft(r),r.variable.kind,r.variable.bin??"",r.variable.index??"",r.effect.direction].join("\0");(d.get(l)??d.set(l,[]).get(l)).push(r)}for(const r of d.values()){const l=[];for(const u of r.filter(m=>m.comparison.family==="sector")){const m=lt(u,t.sectorCount);if(m)for(const c of r.filter(h=>h.comparison.family==="quadrant")){const h=lt(c,t.sectorCount);if(!h)continue;let p=0;for(const S of m)h.has(S)&&p++;const g=m.size+h.size-p;p/g>=vn-1e-9&&l.push({sector:u,quadrant:c,overlap:p/g})}}l.sort((u,m)=>m.overlap-u.overlap);for(const{sector:u,quadrant:m}of l){if(a.has(u.id)||a.has(m.id))continue;const c=(m.stats.pValue??1)<(u.stats.pValue??1),[h,p]=c?[m,u]:[u,m];n(h,p),a.add(p.id),h.absorbedIds=[...h.absorbedIds??[],...p.absorbedIds??[]]}}}export function analyzeWaferMap(e,t={}){return analyzeWaferMapDecided(e,t)}export function analyzeWaferMapDecided(e,t={},s){const o=ne,i=ce,n=[];ne=n,ce=void 0;try{const f=$n(e,t,s);return tt.set(f,{candidates:n,facts:ce}),f}finally{ne=o,ce=i}}function $n(e,t,s){const{resolved:o,warnings:i}=resolveOptions(t),n=pt(e),f={...o,passBins:[...Vt(n,"analyzeWaferMap")],ringCount:Et(n,"analyzeWaferMap")},a=n.isLotStack,d=n.aggrMethod,r=$t(a,d),l=r,u=n.dies.filter(R=>Ge(R)),m=u.filter(qe),c=It(f,u.length);c.softPassBins=Te(u,c.passBins).soft;const h=rt(u,c.testNumbers,n.testDefs),p=c.enableTestValueAnalysis,g=p===!1?"off":p===!0?"done":s??gt(h.length*u.length),S=n.dies.filter(R=>Z(R)),F=S.filter(qe),k=r?u.filter(R=>R.sbin!==void 0):[],v=l&&u.some(R=>R.hbin!==void 0)||k.length>0||p!==!1,B=v?Mt(F,n.wafer,c.ringCount):[],z=v?Rt(F,n.wafer,c.ringCount):[],b=v?kt(F,n.reticleConfig):[],w=v?zt(S,!1):[],M=v?Dt(F,n.wafer,c.sectorCount):[],y=[],$=[];l&&$.push(...ue(u,B,c.passBins,c),...ue(u,z,c.passBins,c),...ue(u,b,c.passBins,c),...ue(u,w,c.passBins,c),...ue(u,M,c.passBins,c)),l&&$.push(...q(u,B,"hard",n.hbinDefs,"hardBin",c),...q(u,z,"hard",n.hbinDefs,"hardBin",c),...q(u,b,"hard",n.hbinDefs,"hardBin",c),...q(u,w,"hard",n.hbinDefs,"hardBin",c),...q(u,M,"hard",n.hbinDefs,"hardBin",c));{const R=k;$.push(...q(R,B,"soft",n.sbinDefs,"softBin",c),...q(R,z,"soft",n.sbinDefs,"softBin",c),...q(R,b,"soft",n.sbinDefs,"softBin",c),...q(R,w,"soft",n.sbinDefs,"softBin",c),...q(R,M,"soft",n.sbinDefs,"softBin",c))}const P=[...i];let C;if(p!==!1){if(g==="done"){for(const R of[B,z,b,w,M])y.push(...ln(u,R,h,n.testDefs,c));C=h}$.push(...cn(u,[B,z,b,w,M],n.testDefs,c)),$.push(...de(u,B,n.testDefs,c),...de(u,z,n.testDefs,c),...de(u,b,n.testDefs,c),...de(u,w,n.testDefs,c),...de(u,M,n.testDefs,c))}y.push(...on($,c));{const R=jt(a,l,n.testDefs);if(!a||l||R!==void 0){const T=He(m,n.wafer,{...c,isFailingDie:R});y.push(...T),l&&y.push(...Ut(m,n.wafer,n.hbinDefs,c,T))}}const V=gn(y,{eligibleDies:u,softEligibleDies:k,passBins:c.passBins,ringCount:c.ringCount,sectorCount:c.sectorCount,regionDies:{ring:new Set(B.flatMap(R=>Q(R.dies))),quadrant:new Set(z.flatMap(R=>Q(R.dies))),sector:new Set(M.flatMap(R=>Q(R.dies)))},hbinDefs:n.hbinDefs,sbinDefs:n.sbinDefs,testDefs:n.testDefs});y.length=0,y.push(...V),claimForBinClusters(y);let x;if(l){const R=Ct(m,n.wafer,{passBins:c.passBins,ringCount:c.ringCount});x=R??void 0;const T=R?dn(R,y,()=>{const W=new Set(c.passBins);return m.filter(he=>_e(he,W)===!0)},m,n.wafer,c.ringCount):void 0,E=T??R;if(T&&(x=T),E!=null&&E.pattern!=="random"&&E.pattern!=="none"){const W=Pt[E.pattern],he=E.confidence==="high"?"unusual":E.confidence==="medium"?"notable":"info",I=E.features,se=K=>`${(K*100).toFixed(0)}%`,ct=E.pattern==="edge-ring"||E.pattern==="edge-local"?`${se(I.edgeRdd)} of edge dies failing`:E.pattern==="center"?`centroid at ${se(I.centroidDistNorm)} of wafer radius from centre`:E.pattern==="donut"?`${se(Math.max(I.radialFailRates[1],I.radialFailRates[2]))} of dies failing at mid-radius, ${se(I.radialFailRates[0])} at the centre`:E.pattern==="scratch"?`a line ${Math.round(I.lineLength)} dies long and about ${Math.max(1,Math.round(I.lineWidth*2))} wide`:`${se(I.globalRdd)} of dies failing`,ut=new Set(c.passBins),Ke=u.filter(K=>_e(K,ut)===!0),{center:Oe,radius:dt}=n.wafer,mt=new Map(m.map(K=>[re(K),Tt(K.physX-Oe.x,K.physY-Oe.y,dt,c.ringCount)])),ht=new Set(y.flatMap(K=>Ue(K)?K.relatedIds??[]:[])),Ae=claimForPattern([E.pattern],he,y.filter(K=>!ht.has(K.id)),K=>K.comparison.family==="cluster"?[...new Set(K.highlight.kind==="dies"?K.highlight.dieKeys.map(oe=>mt.get(oe)??0):[])]:me(K).map(oe=>ee(oe).ring).filter(oe=>oe!==void 0),c.ringCount);y.push({id:`spatial-pattern:${E.pattern}`,level:"wafer",severity:he,variable:{kind:"spatialPattern",label:W},comparison:{family:"spatial-pattern",left:W,right:"Wafer"},effect:{direction:"different",effectSize:I.globalRdd},stats:{method:"geometry",sampleSizeLeft:Ke.length,sampleSizeRight:u.length},summary:`Spatial pattern: ${W.toLowerCase()} (${E.confidence} confidence) \u2014 ${ct}${E.note?` [${E.note}]`:""}`,highlight:{kind:"dies",dieKeys:Ke.map(K=>re(K))},relatedIds:Ae.length>0?Ae:void 0})}}y.sort((R,T)=>{const E=R.stats.adjustedPValue??R.stats.pValue??1,W=T.stats.adjustedPValue??T.stats.pValue??1;return E!==W?E-W:Math.abs(T.effect.absoluteDelta??0)-Math.abs(R.effect.absoluteDelta??0)});const D=Xt(n.dies,u.length,n.yield.yieldPercent,r);a&&(D.isLotStack=!0,d&&(D.aggregationMethod=d));const O=new Set(f.passBins),N={},A=(R,T)=>{const E=N[R]??={dieKeys:[],lostDies:0};E.dieKeys.push(re(T)),(!r||ae(T,O)!==!0)&&E.lostDies++},L=Zt(n.dies,n.testDefs,A);L&&(D.testSpecYield=L);const G=computeFunctionalYield(n.dies,n.testDefs,A);if(G&&(D.functionalYield=G),Object.keys(N).length&&(D.testFailures=N),x&&(D.spatialPattern=x),C===void 0&&c.computePerTestStats&&(C=h),h.length&&(D.testValueAnalysis=bt(g,h.length,u.length)),C?.length){const R=Jt(n.dies,C,n.testDefs,c.minimumSampleSize);R&&(D.perTestStats=R);const T=yt([{dies:n.dies}],n.testDefs,C);T&&(D.capability=T)}Object.assign(D,St(n.dies,n.testDefs));const _=vt([{dies:n.dies,wafer:n.wafer,passBins:c.passBins,ringCount:c.ringCount}]);_&&(D.regionYield=_),P.length>0&&(D.warnings=P);const X=redundancyFacts(u,c.passBins,c.sectorCount);return collapseRedundantFindings(y,X),ne&&(ce=X),{level:"wafer",hasNotableFindings:y.some(R=>R.severity==="notable"||R.severity==="unusual"),findings:y,wafer:n.wafer.metadata??void 0,analysisOptions:recordedOptions(t),stats:D}}
|
|
1
|
+
import{normalizeInput as pt}from"./normalizeInput.js";import{autoDecision as gt,testValueStatus as bt}from"./testValueBudget.js";import{computeCapability as yt,computeTestFlagYield as St,computeRegionYield as vt}from"./summaryFigures.js";import{binPassSets as qe}from"../renderer/binColors.js";import{diePassStatus as ae,isYieldEligibleDie as Z,getDieKey as re,isPositionedDie as Ie,positionKey as Re}from"../core/dies.js";import{dieHasValues as wt,testsPresent as je,testValue as Y}from"../core/dieTable.js";import{stackBinsAreData as $t}from"../core/aggregates.js";import{getTestPassStatus as pe,isParametricTest as J}from"../renderer/buildWaferMap.js";import{markedTestLabel as j,derivedFields as ge}from"../renderer/testLabel.js";import{buildQuadrantRegions as Rt,buildReticlePositionRegions as Dt,buildRingRegions as kt,buildSectorRegions as Mt,buildTestSiteRegions as zt,sectorCompassNames as He,areQuadrantsAdjacent as Bt,parseRegionKey as ee,QUADRANT_CYCLE as De,regionAngleBins as Ft}from"./regions.js";import{buildClusterFindings as _e}from"./clusterDetection.js";import{classifyPattern as Ct,classifyFailingDies as Nt,patternExplains as xt,patternFailVerdict as We,PATTERN_LABELS as Pt}from"./patternClassification.js";import{requirePassBins as Vt}from"../core/passBins.js";import{requireRingCount as Et}from"../core/ringCount.js";import{benjaminiHochberg as Lt,fisherExact as Kt,fiveNumberSummary as Ot,sampleVariance as ke,zPValue as Ye}from"./math.js";import{mean as be,maxOf as At}from"../core/utils.js";import{classifySpec as ye,isOutOfSpec as Me}from"../renderer/spec.js";import{ringOf as Tt}from"../core/classify.js";import{SEVERITY_ORDER as Ue,isOneBinCluster as Qe}from"./filterFindings.js";const qt={significanceLevel:{min:1e-6,max:1},minimumEffectSize:{min:0,max:1},minimumRelativeEffect:{min:0,max:Number.MAX_SAFE_INTEGER}},Ge=[4,8,16];export function resolveOptions(e){const t=Object.fromEntries(Object.entries(e).filter(([,a])=>a!==void 0)),s={...le,...t},o=[],i=[];for(const a of["significanceLevel","minimumEffectSize","minimumRelativeEffect"]){const{min:h,max:r}=qt[a],u=s[a];if(typeof u!="number"||!Number.isFinite(u)){i.push(`${a}=${String(u)} is not a finite number (using ${le[a]})`),s[a]=le[a];continue}const f=Math.min(r,Math.max(h,u));f!==u&&(i.push(`${a}=${u} is outside ${h}\u2013${r} (using ${f})`),s[a]=f)}if(Ge.includes(s.sectorCount)||(i.push(`sectorCount=${s.sectorCount} is not one of ${Ge.join(", ")} (using ${le.sectorCount})`),s.sectorCount=le.sectorCount),i.length){const a=`analyzeWaferMap: ${i.join("; ")}. The analysis ran with the corrected values.`;console.warn(`[wafermap] ${a}`),o.push({code:"analysis-option-corrected",message:a,severity:"warning"})}const n=["passBins","ringCount"].filter(a=>t[a]!==void 0);if(n.length){const a=`analyzeWaferMap: ${n.join(" and ")} ${n.length>1?"are":"is"} no longer an analysis option and was ignored. Set ${n.length>1?"them":"it"} on buildWaferMap; the analysis used the value the map was built with.`;console.warn(`[wafermap] ${a}`),o.push({code:"analysis-option-corrected",message:a,severity:"warning"})}const l=["enableYieldAnalysis","enableHardBinAnalysis","enableSoftBinAnalysis","enableReticlePositionAnalysis","enableTestSiteAnalysis","enableClusterAnalysis","enableAngularAnalysis","enablePatternClassification"].filter(a=>t[a]!==void 0);if(l.length){const a=`analyzeWaferMap: ${l.join(", ")} ${l.length>1?"are":"is"} no longer an option and was ignored: every analysis now runs. Filter the findings (filterFindings) to show fewer.`;console.warn(`[wafermap] ${a}`),o.push({code:"analysis-option-corrected",message:a,severity:"warning"})}return{resolved:s,warnings:o}}const le={significanceLevel:.05,minimumEffectSize:.2,minimumRelativeEffect:1,minimumSampleSize:5,enableTestValueAnalysis:"auto",computePerTestStats:!1,sectorCount:8,minimumClusterSize:5};function It(e,t){const s={...e};return s.minimumClusterSize=Math.max(5,Math.round(t*.003)),s}function Xe(e){return Z(e)?e.hbin!==void 0||e.sbin!==void 0||wt(e):!1}function jt(e,t,s){if(!e||t)return;const o=(s??[]).filter(i=>J(i)&&(i.limitLow!==void 0||i.limitHigh!==void 0));if(o.length!==0)return i=>{for(const n of o)if(Me(ye(Y(i,n.testNumber),n)))return!0;return!1}}const Ht=8,_t=.8,Wt=.8,Yt=.5;function Ut(e,t,s,o,i){const n=new Set(o.passBins),l=e.filter(d=>ae(d,n)!==void 0),a=new Map;let h=0;for(const d of l)ae(d,n)||(h++,d.hbin!==void 0&&a.set(d.hbin,(a.get(d.hbin)??0)+1));const r=[...a].filter(([,d])=>d>=o.minimumClusterSize&&d<=_t*h).sort((d,c)=>c[1]-d[1]||d[0]-c[0]).slice(0,Ht).map(([d])=>d);if(!r.length)return[];const u=i.filter(d=>d.comparison.family==="cluster").map(Se),f=[];for(const d of r){const c=_e(l,t,{...o,significanceLevel:o.significanceLevel/r.length,isFailingDie:m=>m.hbin===d,bin:{bin:d,label:xe(d,s,"HBin")}});f.push(...c.filter(m=>!u.some(p=>Gt(Se(m),p))))}return f}const Qt=.5;export function claimForBinClusters(e){const t=e.filter(s=>(s.comparison.family==="ring"||s.comparison.family==="quadrant"||s.comparison.family==="sector")&&s.variable.kind==="hardBin"&&s.effect.direction==="higher");for(const s of e){if(!Qe(s))continue;const o=Se(s),i=t.filter(n=>{if(n.variable.bin!==s.variable.bin||Ue[n.severity]<Ue[s.severity])return!1;const l=(n.effect.absoluteDelta??0)*n.stats.sampleSizeLeft;let a=0;for(const h of Se(n))o.has(h)&&a++;return l>0&&a>=Qt*l});i.length&&(s.relatedIds=i.map(n=>n.id))}}function Se(e){return new Set("dieKeys"in e.highlight?e.highlight.dieKeys??[]:[])}function Gt(e,t){let s=0;for(const o of e)t.has(o)&&s++;return s>=Wt*e.size&&e.size>=Yt*t.size}function Xt(e,t,s,o){const i=new Set,n=new Set,l=new Set,a=new Map,h=new Map;for(const r of je(e))i.add(r);for(const r of o?e:[])r.hbin!==void 0&&n.add(r.hbin),r.sbin!==void 0&&l.add(r.sbin),Z(r)&&(r.hbin!==void 0&&a.set(r.hbin,(a.get(r.hbin)??0)+1),r.sbin!==void 0&&h.set(r.sbin,(h.get(r.sbin)??0)+1));return{totalDies:e.length,analyzedDies:t,excludedDies:e.length-t,yieldPercent:s.yieldPercent,yieldPassDies:s.passDies,yieldTestedDies:s.totalDies,testsConsidered:[...i].sort((r,u)=>r-u),hardBinsConsidered:[...n].sort((r,u)=>r-u),softBinsConsidered:[...l].sort((r,u)=>r-u),...a.size?{hardBinCounts:Object.fromEntries(a)}:{},...h.size?{softBinCounts:Object.fromEntries(h)}:{}}}function Zt(e,t,s){if(!t?.length)return;const o=t.filter(n=>J(n)&&(n.limitLow!==void 0||n.limitHigh!==void 0));if(!o.length)return;const i=[];for(const n of o){const l=n.testNumber;let a=0,h=0,r=0,u=0;for(const f of e){if(!Z(f))continue;const d=ye(Y(f,l),n);if(d!==null){if(u++,d==="failLow")h++;else if(d==="failHigh")r++;else{a++;continue}s?.(l,f)}}i.push({testNumber:l,label:j(n,l),passDies:a,failLowDies:h,failHighDies:r,totalDies:u,yieldPercent:u>0?a/u*100:null})}return i.length?i:void 0}export function computeFunctionalYield(e,t,s){if(!t?.length)return;const o=t.filter(n=>!J(n));if(!o.length)return;const i=[];for(const n of o){const l=n.testNumber;let a=0,h=0;for(const u of e){if(!Z(u))continue;const f=pe(u,l,n);if(f!==void 0){if(f){a++;continue}h++,s?.(l,u)}}const r=a+h;i.push({testNumber:l,label:j(n,l),...ge(n),passDies:a,failDies:h,totalDies:r,passRatePercent:r>0?a/r*100:null})}return i.length?i:void 0}function Jt(e,t,s,o){const i=[];for(const n of t){const l=[];for(const f of e){if(!Z(f))continue;const d=Y(f,n);d!==void 0&&Number.isFinite(d)&&l.push(d)}if(l.length<o)continue;const a=be(l),h=Math.sqrt(ke(l,a)),r=Ot(Float64Array.from(l)),u=s?.find(f=>f.testNumber===n)?.name??String(n);i.push({testNumber:n,label:u,count:l.length,min:r.min,max:r.max,mean:a,stddev:h,median:r.median,q1:r.q1,q3:r.q3})}return i.length?i:void 0}export function twoProportionZ(e,t,s,o){const i=(e+s)/(t+o),n=i*(1-i)*(1/t+1/o);return!Number.isFinite(n)||n<=0?0:(e/t-s/o)/Math.sqrt(n)}const en=5;function H(e,t,s,o){const i=t+o,n=e+s;if((i>0?Math.min(n,i-n)*Math.min(t,o)/i:0)<en)return{pValue:Kt(e,t-e,s,o-s),method:"fisher-exact"};const a=twoProportionZ(e,t,s,o);return{pValue:a===0?1:Ye(a),method:"two-proportion-z"}}function tn(e,t,s,o){return H(e,t,s,o).pValue}export function adjustPValues(e){const t=e.filter(o=>o.stats.pValue!==void 0),s=Lt(t.map(o=>o.stats.pValue));return t.forEach((o,i)=>{o.stats.adjustedPValue=s[i]}),e}export function rateRelativeEffect(e){const t=(e.passRate?e.n-e.hits:e.hits)/e.n,s=(e.passRate?e.restN-e.restHits:e.restHits)/e.restN;return s===0?t===0?0:1/0:Math.abs(t-s)/s}export function severityForFinding(e,t,s){const o=Math.abs(t),i=s;return e<=.01&&(o>=.3||i>=2.5)?"unusual":e<=.05&&(o>=.2||i>=1.5)?"notable":"info"}export function severityForScore(e,t){return e<=.01&&Math.abs(t)>=.5?"unusual":e<=.05&&Math.abs(t)>=.15?"notable":"info"}function ve(e){return e==="reticle-position"?"other reticle positions":e==="test-site"?"other test sites":"the rest of the map"}function te(e){return e==="reticle-position"?"Other reticle positions":e==="test-site"?"Other test sites":"Rest of map"}function ze(e,t,s){const o=(Math.abs(t)*100).toFixed(1);return`${e} yield is ${o} percentage points ${t>0?"higher":"lower"} than ${ve(s)}`}function Be(e,t){return t==="quadrant"&&!e.startsWith("Quadrant")?`quadrant ${e}`:e}function Ze(e){return/^(Rings|Sectors|Quadrants)\b/.test(e)?"have":"has"}function Fe(e,t,s,o){const i=Be(e,o),n=(Math.abs(s)*100).toFixed(1);return`${i} ${Ze(i)} ${t} occurrence ${n} percentage points ${s>0?"higher":"lower"} than ${ve(o)}`}function Ce(e,t,s,o){const i=Be(e,o),n=(Math.abs(s)*100).toFixed(1);return`${i} ${Ze(i)} ${t} pass rate ${n} percentage points ${s>0?"higher":"lower"} than ${ve(o)}`}function Ne(e,t,s,o,i,n){const l=Be(e,i),a=ve(i),h=s>0?"higher":"lower";if(o!==void 0&&Number.isFinite(o)){const u=(Math.abs(o)*100).toFixed(1);return`${l} mean ${t} is ${u}% ${h} than ${a}`}const r=n?` ${n}`:"";return`${l} mean ${t} is ${Math.abs(s).toPrecision(3)}${r} ${h} than ${a}`}function xe(e,t,s){const o=t?.find(i=>i.bin===e);return o?.name?`${s} ${e} (${o.name})`:`${s} ${e}`}function nn(e,t){const s=t?.find(o=>o.testNumber===e);return{label:j(s,e),unit:s?.unit,...ge(s)}}const Je=new WeakMap,et=new WeakMap,tt=new WeakMap;function fe(e,t){const s=t.highlight.dieKeys;return s&&tt.set(s,e),t}let ne=null,ce;const nt=new WeakMap;export function candidatesOf(e){return nt.get(e)}function it(e,t,s,o){if(!ne)return;const i=st(e);if(!i)return;const n=e.id.slice(0,e.id.indexOf(":")),l=n==="specLimit"?"limitFail":n,{kind:a,bin:h,index:r}=e.variable;ne.push({key:[l,a,h??"",r??"",i.family,i.key].join("|"),source:l,variable:e.variable,label:e.variable.label,comparison:e.comparison,region:i,z:t,delta:e.effect.absoluteDelta??0,effectSize:e.effect.effectSize??0,relativeDelta:e.effect.relativeDelta,rate:s,mean:o})}export function describeRegional(e,t,s){const o=e.comparison.left,i=e.region.family;switch(e.source){case"yield":return ze(o,t,i);case"hardBin":case"softBin":return Fe(o,e.label,t,i);case"functional":return Ce(o,e.label.replace(/ pass rate$/,""),t,i);case"limitFail":return Pe(o,e.label,t);case"test":return Ne(o,e.label,t,s,i,e.variable.unit)}}function Pe(e,t,s){return`${e} limit fail rate for ${t} is ${(Math.abs(s)*100).toFixed(1)} percentage points ${s>0?"higher":"lower"} than the rest of the wafer`}const U=new WeakMap;function we(e,t){return U.set(e,t),e}function st(e){const t=e.highlight.dieKeys;return t?tt.get(t):void 0}const ot=new WeakMap;function Q(e){let t=ot.get(e);return t||ot.set(e,t=e.map(Re)),t}function sn(e){let t=Je.get(e);return t||Je.set(e,t=e.map(re)),t}function $e(e,t){let s=et.get(e);s||et.set(e,s={members:new Set(e),byFamily:new WeakMap});const o=s.byFamily.get(t);if(o)return o;const{members:i}=s,n=new Map;for(const l of t)n.set(l.key,l.dies.filter(a=>i.has(a)));return s.byFamily.set(t,n),n}function on(e,t){adjustPValues(e);for(const i of e){const n=U.get(i);it(i,twoProportionZ(n.hits,n.n,n.restHits,n.restN),n)}const s=e.filter(i=>passesRateGate(i.stats.adjustedPValue??i.stats.pValue??1,i.effect.absoluteDelta??0,rateRelativeEffect(U.get(i)),t)),o=confirmRegionalFindings(s,at,(i,n)=>an(i,n,t),i=>isRateLoss(U.get(i)),e);return s.filter(i=>o.has(i)).map(i=>({...i,severity:severityForFinding(i.stats.adjustedPValue??i.stats.pValue??1,i.effect.absoluteDelta??0,rateRelativeEffect(U.get(i)))}))}export function passesRateGate(e,t,s,o){return e<=o.significanceLevel&&(Math.abs(t)>=o.minimumEffectSize||s>=o.minimumRelativeEffect)}export function claimForPattern(e,t,s,o,i){const n=[];for(const l of s){const a=l.comparison.family,h=a==="ring"||a==="cluster"?o(l):[];e.some(r=>xt(r,a,h,i))&&n.push(l.id)}return n}export function confirmRegionalFindings(e,t,s,o,i=e){const n=new Map;for(const h of e)(n.get(t(h))??n.set(t(h),[]).get(t(h))).push(h);const l=new Map;if(o)for(const h of i)o(h)&&(l.get(t(h))??l.set(t(h),[]).get(t(h))).push(h);const a=new Set;for(const[h,r]of n){const u=l.get(h)??[],f=(m,p)=>o&&!o(m)?s(m,[...new Set([...p,...u])].filter(g=>g!==m)):s(m,p);if(r.length===1&&(!o||o(r[0])||u.length===0)){a.add(r[0]);continue}const d=[];let c=[...r];for(;;){let m;for(const p of c){const g=f(p,d);if(g==="baseline-too-small"||!g.passes)continue;const S=o?.(p)??!1;(!m||S&&!m.loss||S===m.loss&&g.pValue<m.p)&&(m={t:p,p:g.pValue,loss:S})}if(!m)break;d.push(m.t),c=c.filter(p=>p!==m.t)}for(;;){let m;for(const p of d){const g=f(p,d.filter(S=>S!==p));g==="baseline-too-small"||g.passes||(!m||g.pValue>m.p)&&(m={t:p,p:g.pValue})}if(!m)break;d.splice(d.indexOf(m.t),1)}for(const m of d)a.add(m)}return a}function at(e){return[e.variable.kind,e.variable.bin??"",e.variable.index??"",e.comparison.family].join("\0")}function rt(e){const t=e.stats.pValue??1;return t>0?(e.stats.adjustedPValue??t)/t:1}export function isRateLoss(e){const t=e.hits/e.n-e.restHits/e.restN;return e.passRate?t<0:t>0}function an(e,t,s){const o=U.get(e);let{restHits:i,restN:n}=o;for(const r of t){const u=U.get(r);u&&(i-=u.hits,n-=u.n)}if(n<s.minimumSampleSize)return"baseline-too-small";const l=o.hits/o.n-i/n,a=Math.min(1,tn(o.hits,o.n,i,n)*rt(e)),h=Math.sign(l)===Math.sign(e.effect.absoluteDelta??0)&&passesRateGate(a,l,rateRelativeEffect({...o,restHits:i,restN:n}),s);return{pValue:a,passes:h}}const Ve=new WeakMap;export function welchOfSums(e,t,s,o){const i=(n,l,a)=>a>1?Math.max(0,n-l*l/a)/(a-1):0;return welchFromStats(e.n,e.sum/e.n,i(e.sq,e.sum,e.n),t,s/t,i(o,s,t))}function rn(e,t,s){const o=Ve.get(e);let{restN:i,restSum:n,restSq:l}=o;for(const d of t){const c=Ve.get(d);c&&(i-=c.n,n-=c.sum,l-=c.sq)}if(i<s.minimumSampleSize)return"baseline-too-small";const{pValue:a,effectSize:h,delta:r}=welchOfSums(o,i,n,l),u=Math.min(1,a*rt(e)),f=Math.sign(r)===Math.sign(e.effect.absoluteDelta??0)&&u<=s.significanceLevel&&Math.abs(h)>=s.minimumEffectSize;return{pValue:u,passes:f}}function ue(e,t,s,o){const i=new Set(s),n=$e(e,t),l=new Map,a=new Map;for(const[r,u]of n){let f=0,d=0;for(const c of u)c.hbin!==void 0&&(d++,i.has(c.hbin)&&f++);l.set(r,f),a.set(r,d)}const h=[];for(const r of t){const u=a.get(r.key)??0,f=l.get(r.key)??0;let d=0,c=0;for(const[D,v]of a)D!==r.key&&(d+=v,c+=l.get(D)??0);if(u<o.minimumSampleSize||d<o.minimumSampleSize)continue;const m=f/u,p=c/d,g=m-p,{pValue:S,method:F}=H(f,u,c,d);h.push(we(fe(r,{id:`yield:${r.key}`,level:"wafer",severity:"info",variable:{kind:"yield",label:"Yield"},comparison:{family:r.family,left:r.label,right:te(r.family)},effect:{direction:g===0?"different":g>0?"higher":"lower",absoluteDelta:g,relativeDelta:p===0?void 0:g/p,effectSize:g},stats:{method:F,pValue:S,sampleSizeLeft:u,sampleSizeRight:d},summary:ze(r.label,g,r.family),highlight:{kind:"region",regionFamily:r.family,regionKeys:[r.key],dieKeys:[...r.dieKeys]}}),{hits:f,n:u,restHits:c,restN:d,passRate:!0}))}return h}function q(e,t,s,o,i,n){const l=m=>s==="soft"?m.sbin:m.hbin,a=[...new Set(e.map(l).filter(m=>m!==void 0))].sort((m,p)=>m-p),h=$e(e,t),r=new Map,u=new Map;for(const[m,p]of h){const g=new Map;for(const S of p){const F=l(S);F!==void 0&&g.set(F,(g.get(F)??0)+1)}r.set(m,g),u.set(m,p.length)}const f=[],d=i==="hardBin"?"HBin":"SBin",c=s==="hard"?new Set(n.passBins):n.softPassBins??qe(e,n.passBins).soft;for(const m of t){const p=u.get(m.key)??0,g=r.get(m.key);let S=0;const F=new Map;for(const[D,v]of r)if(D!==m.key){S+=u.get(D)??0;for(const[B,z]of v)F.set(B,(F.get(B)??0)+z)}if(!(p<n.minimumSampleSize||S<n.minimumSampleSize))for(const D of a){const v=g.get(D)??0,B=F.get(D)??0,z=v/p,b=B/S,w=z-b,{pValue:k,method:y}=H(v,p,B,S),$=xe(D,o,d);f.push(we(fe(m,{id:`${i}:${D}:${m.key}`,level:"wafer",severity:"info",variable:{kind:i,bin:D,label:$},comparison:{family:m.family,left:m.label,right:te(m.family)},effect:{direction:w===0?"different":w>0?"higher":"lower",absoluteDelta:w,relativeDelta:b===0?void 0:w/b,effectSize:w},stats:{method:y,pValue:k,sampleSizeLeft:p,sampleSizeRight:S},summary:Fe(m.label,$,w,m.family),highlight:{kind:"bin",bin:D,regionKeys:[m.key],dieKeys:[...m.dieKeys]}}),{hits:v,n:p,restHits:B,restN:S,passRate:c.has(D)}))}}return f}function de(e,t,s,o){const i=(s??[]).filter(u=>!J(u));if(!i.length)return[];const n=i.map(u=>u.testNumber),l=$e(e,t),a=new Map,h=new Map;for(const[u,f]of l){const d=new Uint32Array(i.length),c=new Uint32Array(i.length);for(const m of f)for(let p=0;p<i.length;p++){const g=pe(m,n[p],i[p]);g!==void 0&&(c[p]++,g&&d[p]++)}a.set(u,d),h.set(u,c)}const r=[];for(const u of t){const f=a.get(u.key),d=h.get(u.key);for(let c=0;c<i.length;c++){let m=0,p=0;for(const[w,k]of h)w!==u.key&&(p+=k[c],m+=a.get(w)[c]);const g=d[c],S=f[c];if(g<o.minimumSampleSize||p<o.minimumSampleSize)continue;const F=S/g,D=m/p,v=F-D,{pValue:B,method:z}=H(S,g,m,p),b=n[c];r.push(we(fe(u,{id:`functional:${b}:${u.key}`,level:"wafer",severity:"info",variable:{kind:"functionalTest",index:b,label:`${j(i[c],b)} pass rate`,...ge(i[c])},comparison:{family:u.family,left:u.label,right:te(u.family)},effect:{direction:v===0?"different":v>0?"higher":"lower",absoluteDelta:v,relativeDelta:D===0?void 0:v/D,effectSize:v},stats:{method:z,pValue:B,sampleSizeLeft:g,sampleSizeRight:p},summary:Ce(u.label,j(i[c],b),v,u.family),highlight:{kind:"region",regionFamily:u.family,regionKeys:[u.key],dieKeys:[...u.dieKeys]}}),{hits:S,n:g,restHits:m,restN:p,passRate:!0}))}}return r}export function welchFromStats(e,t,s,o,i,n){const l=Math.sqrt(s/e+n/o),a=t-i;if(!Number.isFinite(l)||l===0)return{pValue:1,effectSize:0,delta:a,z:0};const h=a/l,r=Math.sqrt(Math.max(0,(s+n)/2)),u=r===0?a:a/r;return{pValue:Ye(h),effectSize:u,delta:a,z:h}}function ln(e,t){const s=be(e),o=be(t);return welchFromStats(e.length,s,ke(e,s),t.length,o,ke(t,o))}function lt(e,t,s){const o=new Map;for(const n of s??[])o.has(n.testNumber)||o.set(n.testNumber,n);const i=n=>n.filter(l=>J(o.get(l)));return i(t?t.slice().sort((n,l)=>n-l):je(e,"values"))}export function testValueSize(e,t){const s=e.dies.filter(Xe);return{tests:lt(s,t.testNumbers,e.testDefs).length,dies:s.length}}export function recordedOptions(e){const t={};return e.enableTestValueAnalysis!==void 0&&(t.enableTestValueAnalysis=e.enableTestValueAnalysis),e.computePerTestStats!==void 0&&(t.computePerTestStats=e.computePerTestStats),e.sectorCount!==void 0&&(t.sectorCount=e.sectorCount),e.testNumbers!==void 0&&(t.testNumbers=[...e.testNumbers]),t}function fn(e,t,s,o,i){const n=new Map;for(let p=0;p<t.length;p++)for(const g of Q(t[p].dies))n.set(g,p);const l=t.length,a=[],h=[];for(const p of e){const g=n.get(Re(p));g!==void 0&&(a.push(p),h.push(g))}const r=[],u=new Float64Array(l),f=new Float64Array(l),d=new Float64Array(l);for(const p of s){u.fill(0),f.fill(0),d.fill(0);let g=0,S=0,F=0,D;for(let v=0;v<a.length;v++){const B=a[v],z=Y(B,p);if(z===void 0)continue;D===void 0&&(D=z);const b=z-D,w=h[v];u[w]+=1,f[w]+=b,d[w]+=b*b,g+=1,S+=b,F+=b*b}if(D!==void 0)for(let v=0;v<l;v++){const B=u[v],z=g-B;if(B<i.minimumSampleSize||z<i.minimumSampleSize)continue;const b=f[v]/B,k=(S-f[v])/z,y=b+D,$=k+D,V=B>1?Math.max(0,d[v]-B*b*b)/(B-1):0,C=z>1?Math.max(0,F-d[v]-z*k*k)/(z-1):0,{pValue:E,effectSize:x,delta:M,z:O}=welchFromStats(B,y,V,z,$,C),N=t[v],{label:A,unit:L,...G}=nn(p,o),_=$!==0?M/Math.abs($):void 0,X=fe(N,{id:`test:${p}:${N.key}`,level:"wafer",severity:"info",variable:{kind:"test",measure:"mean",index:p,label:A,unit:L,...G},comparison:{family:N.family,left:N.label,right:te(N.family)},effect:{direction:M===0?"different":M>0?"higher":"lower",absoluteDelta:M,relativeDelta:_,effectSize:x},stats:{method:"welch-z-approx",pValue:E,sampleSizeLeft:B,sampleSizeRight:z},summary:Ne(N.label,A,M,_,N.family,L),highlight:{kind:"region",regionFamily:N.family,regionKeys:[N.key],dieKeys:[...N.dieKeys]}}),R={n:B,sum:f[v],sq:d[v],restN:z,restSum:S-f[v],restSq:F-d[v],shift:D};Ve.set(X,R),it(X,O,void 0,R),r.push(X)}}adjustPValues(r);const c=r.filter(p=>{const g=p.stats.adjustedPValue??p.stats.pValue??1,S=Math.abs(p.effect.effectSize??0);return g<=i.significanceLevel&&S>=i.minimumEffectSize}),m=confirmRegionalFindings(c,at,(p,g)=>rn(p,g,i));return c.filter(p=>m.has(p)).map(p=>({...p,severity:severityForScore(p.stats.adjustedPValue??p.stats.pValue??1,p.effect.effectSize??0)}))}function cn(e,t,s,o){if(!s?.length)return[];const i=s.filter(l=>J(l)&&(l.limitLow!==void 0||l.limitHigh!==void 0));if(!i.length)return[];const n=[];for(const l of i){const a=l.testNumber;for(const h of t){const r=$e(e,h),u=[],f=new Map;let d=0,c=0;for(const[m,p]of r){let g=0,S=0;for(const F of p){const D=Y(F,a);D!==void 0&&(g++,Me(ye(D,l))&&S++)}f.set(m,{valid:g,fail:S}),d+=g,c+=S}for(const m of h){const p=f.get(m.key),g=p.valid,S=d-p.valid;if(g<o.minimumSampleSize||S<o.minimumSampleSize)continue;const F=p.fail,D=c-p.fail,v=F/g,B=D/S,z=v-B,{pValue:b,method:w}=H(F,g,D,S);u.push(we(fe(m,{id:`specLimit:${a}:${m.key}`,level:"wafer",severity:"info",variable:{kind:"test",measure:"limitFailRate",index:a,label:j(l,a),...ge(l)},comparison:{family:m.family,left:m.label,right:te(m.family)},effect:{direction:z===0?"different":z>0?"higher":"lower",absoluteDelta:z,relativeDelta:B===0?void 0:z/B,effectSize:z},stats:{method:w,pValue:b,sampleSizeLeft:g,sampleSizeRight:S},summary:Pe(m.label,j(l,a),z),highlight:{kind:"region",regionFamily:m.family,regionKeys:[m.key],dieKeys:[...m.dieKeys]}}),{hits:F,n:g,restHits:D,restN:S,passRate:!1}))}n.push(...u)}}return n}function Ee(e,t){return e==="softBin"?t.softEligibleDies:t.eligibleDies}function un(e){return e.variable.measure==="limitFailRate"}function dn(e,t,s,o,i,n,l){if(e.pattern!=="scratch"&&e.resembles!=="scratch")return;const a=t.filter(f=>f.comparison.family==="reticle-position"&&f.severity!=="info"&&f.highlight.kind==="region");if(!a.length)return;const h=new Set(a.flatMap(f=>f.highlight.kind==="region"?f.highlight.dieKeys??[]:[])),r=Nt(s().filter(f=>!h.has(re(f))),o,i,n,l);if(!r||r.pattern==="scratch")return;const u=a[0].comparison.left;return{...r,note:`${u.charAt(0).toLowerCase()}${u.slice(1)}'s failures set aside`}}function he(e){return e.highlight.regionKeys??[]}function hn(e){const t=e.variable.bin??e.variable.index??"";return`${e.comparison.family}\0${ft(e)}\0${e.variable.kind}\0${t}\0${e.effect.direction}`}function mn(e,t){const s=ee(e);return s.family==="ring"?s.ring??0:s.family==="sector"?He(t).indexOf(s.sector??""):0}export function inQuadrantOrder(e){const t=new Set(e),s=De.findIndex((i,n)=>t.has(i)&&!t.has(De[(n+3)%4])),o=s<0?0:s;return Array.from({length:4},(i,n)=>De[(o+n)%4]).filter(i=>t.has(i))}export function findContiguousRuns(e,t,s,o){if(t==="quadrant"){const h=new Map;for(const d of e){const c=ee(o(d)).quadrant;c&&h.set(c,d)}const r=[...h.keys()],u=new Set,f=[];for(const d of r){if(u.has(d))continue;const c=[],m=[d];for(u.add(d);m.length;){const p=m.pop();c.push(p);for(const g of r)!u.has(g)&&Bt(p,g)&&(u.add(g),m.push(g))}f.push(inQuadrantOrder(c).map(p=>h.get(p)))}return f}const i=h=>mn(o(h),s),n=[...e].sort((h,r)=>i(h)-i(r)),l=[];let a=[];for(const h of n){if(a.length===0){a.push(h);continue}const r=i(a[a.length-1]);i(h)-r===1?a.push(h):(l.push(a),a=[h])}if(a.length&&l.push(a),t==="sector"&&l.length>1){const r=He(s).length,u=i(l[0][0]),f=i(l[l.length-1][l[l.length-1].length-1]);if(u===0&&f===r-1){const d=l.pop();l[0]=[...d,...l[0]]}}return l}export function mergedRegionLabel(e,t,s){if(e==="ring"){const i=t.map(h=>ee(h).ring).filter(h=>h!==void 0).sort((h,r)=>h-r),n=i[0],l=i[i.length-1];let a="";return n===l&&n===1&&s>1?a=" (core)":n===l&&n===s&&s>1&&(a=" (edge)"),n===l?`Ring ${n}${a}`:`Rings ${n}\u2013${l}`}if(e==="sector"){const i=t.map(n=>ee(n).sector??"");return i.length===1?`Sector ${i[0]}`:`Sectors ${i[0]}\u2013${i[i.length-1]}`}const o=t.map(i=>ee(i).quadrant??"");return o.length===1?o[0]:o.length===2?`Quadrants ${o[0]} & ${o[1]}`:`Quadrants ${o.slice(0,-1).join(", ")} & ${o[o.length-1]}`}function Le(e){return[...new Set(e)]}export function weakestMultiplier(e){return At(e.map(t=>{const s=t.stats.pValue??1;return s>0?(t.stats.adjustedPValue??s)/s:1}))}function ie(e,t){return Math.min(1,e*t)}function pn(e,t){const s=e[0],o=s.comparison.family,i=s.variable.kind,n=Le(e.flatMap(he));let l,a;const h=e.map(st);if(h.every(b=>b!==void 0)){const b=new Set;l=[];for(const k of h){const y=Q(k.dies);for(let $=0;$<y.length;$++)b.has(y[$])||(b.add(y[$]),l.push(k.dieKeys[$]))}const w=Q(Ee(s.variable.kind,t));a=k=>b.has(w[k])}else{l=Le(e.flatMap(k=>k.highlight.dieKeys??[]));const b=new Set(l),w=sn(Ee(s.variable.kind,t));a=k=>b.has(w[k])}const r=mergedRegionLabel(o,e.map(b=>he(b)[0]??""),t.ringCount),u=Ee(i,t),f=t.regionDies[o],d=Q(u),c=[],m=[];for(let b=0;b<u.length;b++)f.has(d[b])&&(a(b)?c:m).push(u[b]);const p=weakestMultiplier(e);let g,S,F,D,v;if(un(s)){const b=s.variable.index,w=t.testDefs?.find(N=>N.testNumber===b),k=N=>{let A=0,L=0;for(const G of N){const _=Y(G,b);_!==void 0&&(A++,w&&Me(ye(_,w))&&L++)}return{valid:A,fail:L}},y=k(c),$=k(m),V=y.valid>0?y.fail/y.valid:0,C=$.valid>0?$.fail/$.valid:0,E=V-C,{pValue:x,method:M}=H(y.fail,y.valid,$.fail,$.valid);g={direction:E===0?"different":E>0?"higher":"lower",absoluteDelta:E,relativeDelta:C===0?void 0:E/C,effectSize:E},S={method:M,pValue:x,sampleSizeLeft:y.valid,sampleSizeRight:$.valid};const O=ie(x,p);F=severityForFinding(O,E,rateRelativeEffect({hits:y.fail,n:y.valid,restHits:$.fail,restN:$.valid,passRate:!1})),D=Pe(r,j(w,b),E),v=`specLimit:${b}`}else if(i==="test"){const b=s.variable.index,w=O=>Y(O,b),k=c.map(w).filter(O=>O!==void 0),y=m.map(w).filter(O=>O!==void 0),{pValue:$,effectSize:V,delta:C}=ln(k,y),E=be(y),x=E!==0?C/Math.abs(E):void 0;g={direction:C===0?"different":C>0?"higher":"lower",absoluteDelta:C,relativeDelta:x,effectSize:V},S={method:"welch-z-approx",pValue:$,sampleSizeLeft:k.length,sampleSizeRight:y.length};const M=ie($,p);F=severityForScore(M,V),D=Ne(r,s.variable.label,C,x,o,s.variable.unit),v=`test:${b}`}else if(i==="yield"){const b=new Set(t.passBins),w=c.filter(L=>L.hbin!==void 0),k=m.filter(L=>L.hbin!==void 0),y=w.length,$=k.length,V=w.filter(L=>b.has(L.hbin)).length,C=k.filter(L=>b.has(L.hbin)).length,E=y>0?V/y:0,x=$>0?C/$:0,M=E-x,{pValue:O,method:N}=H(V,y,C,$);g={direction:M===0?"different":M>0?"higher":"lower",absoluteDelta:M,relativeDelta:x===0?void 0:M/x,effectSize:M},S={method:N,pValue:O,sampleSizeLeft:y,sampleSizeRight:$};const A=ie(O,p);F=severityForFinding(A,M,rateRelativeEffect({hits:V,n:y,restHits:C,restN:$,passRate:!0})),D=ze(r,M,o),v="yield"}else if(i==="functionalTest"){const b=s.variable.index,w=t.testDefs?.find(A=>A.testNumber===b);let k=0,y=0,$=0,V=0;for(const A of c){const L=pe(A,b,w);L!==void 0&&(y++,L&&k++)}for(const A of m){const L=pe(A,b,w);L!==void 0&&(V++,L&&$++)}const C=y>0?k/y:0,E=V>0?$/V:0,x=C-E,{pValue:M,method:O}=H(k,y,$,V);g={direction:x===0?"different":x>0?"higher":"lower",absoluteDelta:x,relativeDelta:E===0?void 0:x/E,effectSize:x},S={method:O,pValue:M,sampleSizeLeft:y,sampleSizeRight:V};const N=ie(M,p);F=severityForFinding(N,x,rateRelativeEffect({hits:k,n:y,restHits:$,restN:V,passRate:!0})),D=Ce(r,j(w,b),x,o),v=`functional:${b}`}else{const b=s.variable.bin,w=N=>i==="softBin"?N.sbin:N.hbin,k=c.filter(N=>w(N)===b).length,y=m.filter(N=>w(N)===b).length,$=k/c.length,V=y/m.length,C=$-V,{pValue:E,method:x}=H(k,c.length,y,m.length);g={direction:C===0?"different":C>0?"higher":"lower",absoluteDelta:C,relativeDelta:V===0?void 0:C/V,effectSize:C},S={method:x,pValue:E,sampleSizeLeft:c.length,sampleSizeRight:m.length};const M=ie(E,p);F=severityForFinding(M,C,rateRelativeEffect({hits:k,n:c.length,restHits:y,restN:m.length,passRate:!1}));const O=i==="softBin"?t.sbinDefs:t.hbinDefs;D=Fe(r,xe(b,O,i==="softBin"?"SBin":"HBin"),C,o),v=`${i}:${b}`}S={...S,adjustedPValue:ie(S.pValue??1,p)};const B=Le(n.map(b=>b.replace(`${o}:`,""))).join("-"),z=i==="hardBin"||i==="softBin"?{kind:"bin",bin:s.variable.bin,regionKeys:n,dieKeys:l}:{kind:"region",regionFamily:o,regionKeys:n,dieKeys:l};return{...s,id:`${v}:${o}:${B}`,severity:F,comparison:{family:o,left:r,right:te(o)},effect:g,stats:S,summary:D,highlight:z,relatedIds:e.map(b=>b.id)}}function gn(e,t){const s=new Set(["ring","quadrant","sector"]),o=[],i=new Map;for(const l of e){if(!s.has(l.comparison.family)){o.push(l);continue}const a=hn(l),h=i.get(a)??[];h.push(l),i.set(a,h)}const n=[];for(const l of i.values()){if(l.length===1){n.push(l[0]);continue}const a=l[0].comparison.family;for(const h of findContiguousRuns(l,a,t.sectorCount,r=>he(r)[0]??""))n.push(h.length===1?h[0]:pn(h,t))}return[...o,...n]}function bn(e){const t=new Map,s=new Map;for(const i of e){const n=Re(i);i.hbin!==void 0&&i.hbin!==null&&(t.get(i.hbin)??t.set(i.hbin,new Set).get(i.hbin)).add(n),i.sbin!==void 0&&i.sbin!==null&&(s.get(i.sbin)??s.set(i.sbin,new Set).get(i.sbin)).add(n)}const o=new Set;for(const[i,n]of t)for(const[l,a]of s){if(n.size!==a.size)continue;let h=!0;for(const r of n)if(!a.has(r)){h=!1;break}h&&o.add(`${i}:${l}`)}return o}function yn(e,t){const s=new Set(t);let o;for(const i of e){const n=ae(i,s);if(n!==void 0&&n){if(i.sbin==null||o!==void 0&&i.sbin!==o)return;o=i.sbin}}if(o!==void 0){for(const i of e)if(i.sbin===o&&ae(i,s)!==!0)return;return o}}function Sn(e){return`${e.comparison.family}\0${e.comparison.left}`}export function redundancyFacts(e,t,s){return{coincident:bn(e),yieldSoftBin:yn(e,t),passBins:t,sectorCount:s}}const vn=3/5;function ft(e){return/^(?:lot-region:)?([^:|]+)/.exec(e.id)?.[1]??e.id}function wn(e){const t=he(e);if(t.length)return t;const s=/(ring|sector|quadrant):([^:|]+)$/.exec(e.id);return s?s[2].split("-").map(o=>`${s[1]}:${o}`):[]}function ct(e,t){const s=new Set;for(const o of wn(e)){const i=Ft(o,t);if(!i)return;for(const n of i)s.add(n)}return s.size?s:void 0}export function collapseRedundantFindings(e,t){const{coincident:s,yieldSoftBin:o,passBins:i}=t,n=(r,u)=>{r.absorbedIds=[...r.absorbedIds??[],u.id]},l=new Map;for(const r of e){const u=Sn(r);(l.get(u)??l.set(u,[]).get(u)).push(r)}const a=new Set;for(const r of l.values()){for(const f of r)if(!(f.variable.kind!=="hardBin"||f.variable.bin===void 0))for(const d of r){if(d.variable.kind!=="softBin"||d.variable.bin===void 0||a.has(d.id)||!s.has(`${f.variable.bin}:${d.variable.bin}`)||d.effect.direction!==f.effect.direction)continue;n(f,d),a.add(d.id);const c=f.variable.label.replace(/^HBin\s+/,""),m=d.variable.label.replace(/^SBin\s+/,""),p=c===m?`HBin and SBin ${c} (same dies)`:`${f.variable.label} and ${d.variable.label} (same dies)`;f.summary=f.summary.replace(f.variable.label,p),f.variable.label=p;break}const u=r.find(f=>f.variable.kind==="yield");if(u){for(const f of r)if(!(f===u||a.has(f.id)||!(f.variable.kind==="hardBin"&&i.length===1&&f.variable.bin===i[0]||f.variable.kind==="softBin"&&f.variable.bin===o))){n(u,f),a.add(f.id);for(const c of f.absorbedIds??[])u.absorbedIds=[...u.absorbedIds??[],c]}}}const h=new Map;for(const r of e){if(a.has(r.id)||r.comparison.family!=="sector"&&r.comparison.family!=="quadrant")continue;const u=[ft(r),r.variable.kind,r.variable.bin??"",r.variable.index??"",r.effect.direction].join("\0");(h.get(u)??h.set(u,[]).get(u)).push(r)}for(const r of h.values()){const u=[];for(const f of r.filter(d=>d.comparison.family==="sector")){const d=ct(f,t.sectorCount);if(d)for(const c of r.filter(m=>m.comparison.family==="quadrant")){const m=ct(c,t.sectorCount);if(!m)continue;let p=0;for(const S of d)m.has(S)&&p++;const g=d.size+m.size-p;p/g>=vn-1e-9&&u.push({sector:f,quadrant:c,overlap:p/g})}}u.sort((f,d)=>d.overlap-f.overlap);for(const{sector:f,quadrant:d}of u){if(a.has(f.id)||a.has(d.id))continue;const c=(d.stats.pValue??1)<(f.stats.pValue??1),[m,p]=c?[d,f]:[f,d];n(m,p),a.add(p.id),m.absorbedIds=[...m.absorbedIds??[],...p.absorbedIds??[]]}}}export function analyzeWaferMap(e,t={}){return analyzeWaferMapDecided(e,t)}export function analyzeWaferMapDecided(e,t={},s){const o=ne,i=ce,n=[];ne=n,ce=void 0;try{const l=$n(e,t,s);return nt.set(l,{candidates:n,facts:ce}),l}finally{ne=o,ce=i}}function $n(e,t,s){const{resolved:o,warnings:i}=resolveOptions(t),n=pt(e),l={...o,passBins:[...Vt(n,"analyzeWaferMap")],ringCount:Et(n,"analyzeWaferMap")},a=n.isLotStack,h=n.aggrMethod,r=$t(a,h),u=r,f=n.dies.filter(R=>Xe(R)),d=f.filter(Ie),c=It(l,f.length);c.softPassBins=qe(f,c.passBins).soft;const m=lt(f,c.testNumbers,n.testDefs),p=c.enableTestValueAnalysis,g=p===!1?"off":p===!0?"done":s??gt(m.length*f.length),S=n.dies.filter(R=>Z(R)),F=S.filter(Ie),D=r?f.filter(R=>R.sbin!==void 0):[],v=u&&f.some(R=>R.hbin!==void 0)||D.length>0||p!==!1,B=v?kt(F,n.wafer,c.ringCount):[],z=v?Rt(F,n.wafer,c.ringCount):[],b=v?Dt(F,n.reticleConfig):[],w=v?zt(S,!1):[],k=v?Mt(F,n.wafer,c.sectorCount):[],y=[],$=[];u&&$.push(...ue(f,B,c.passBins,c),...ue(f,z,c.passBins,c),...ue(f,b,c.passBins,c),...ue(f,w,c.passBins,c),...ue(f,k,c.passBins,c)),u&&$.push(...q(f,B,"hard",n.hbinDefs,"hardBin",c),...q(f,z,"hard",n.hbinDefs,"hardBin",c),...q(f,b,"hard",n.hbinDefs,"hardBin",c),...q(f,w,"hard",n.hbinDefs,"hardBin",c),...q(f,k,"hard",n.hbinDefs,"hardBin",c));{const R=D;$.push(...q(R,B,"soft",n.sbinDefs,"softBin",c),...q(R,z,"soft",n.sbinDefs,"softBin",c),...q(R,b,"soft",n.sbinDefs,"softBin",c),...q(R,w,"soft",n.sbinDefs,"softBin",c),...q(R,k,"soft",n.sbinDefs,"softBin",c))}const V=[...i];let C;if(p!==!1){if(g==="done"){for(const R of[B,z,b,w,k])y.push(...fn(f,R,m,n.testDefs,c));C=m}$.push(...cn(f,[B,z,b,w,k],n.testDefs,c)),$.push(...de(f,B,n.testDefs,c),...de(f,z,n.testDefs,c),...de(f,b,n.testDefs,c),...de(f,w,n.testDefs,c),...de(f,k,n.testDefs,c))}y.push(...on($,c));{const R=jt(a,u,n.testDefs);if(!a||u||R!==void 0){const T=_e(d,n.wafer,{...c,isFailingDie:R});y.push(...T),u&&y.push(...Ut(d,n.wafer,n.hbinDefs,c,T))}}const E=gn(y,{eligibleDies:f,softEligibleDies:D,passBins:c.passBins,ringCount:c.ringCount,sectorCount:c.sectorCount,regionDies:{ring:new Set(B.flatMap(R=>Q(R.dies))),quadrant:new Set(z.flatMap(R=>Q(R.dies))),sector:new Set(k.flatMap(R=>Q(R.dies)))},hbinDefs:n.hbinDefs,sbinDefs:n.sbinDefs,testDefs:n.testDefs});y.length=0,y.push(...E),claimForBinClusters(y);let x;if(u){const R=Ct(d,n.wafer,{passBins:c.passBins,ringCount:c.ringCount,significanceLevel:c.significanceLevel});x=R??void 0;const T=R?dn(R,y,()=>{const W=new Set(c.passBins);return d.filter(me=>We(me,W)===!0)},d,n.wafer,c.ringCount,c.significanceLevel):void 0,P=T??R;if(T&&(x=T),P!=null&&P.pattern!=="random"&&P.pattern!=="none"){const W=Pt[P.pattern],me=P.confidence==="high"?"unusual":P.confidence==="medium"?"notable":"info",I=P.features,se=K=>`${(K*100).toFixed(0)}%`,Ke=P.pattern==="edge-ring"||P.pattern==="edge-local"?`${se(I.edgeRdd)} of edge dies failing`:P.pattern==="center"?`centroid at ${se(I.centroidDistNorm)} of wafer radius from centre`:P.pattern==="donut"?`${se(Math.max(I.radialFailRates[1],I.radialFailRates[2]))} of dies failing at mid-radius, ${se(I.radialFailRates[0])} at the centre`:P.pattern==="scratch"?`a line ${Math.round(I.lineLength)} dies long and about ${Math.max(1,Math.round(I.lineWidth*2))} wide`:`${se(I.globalRdd)} of dies failing`,ut=new Set(c.passBins),Oe=f.filter(K=>We(K,ut)===!0),{center:Ae,radius:dt}=n.wafer,ht=new Map(d.map(K=>[re(K),Tt(K.physX-Ae.x,K.physY-Ae.y,dt,c.ringCount)])),mt=new Set(y.flatMap(K=>Qe(K)?K.relatedIds??[]:[])),Te=claimForPattern([P.pattern],me,y.filter(K=>!mt.has(K.id)),K=>K.comparison.family==="cluster"?[...new Set(K.highlight.kind==="dies"?K.highlight.dieKeys.map(oe=>ht.get(oe)??0):[])]:he(K).map(oe=>ee(oe).ring).filter(oe=>oe!==void 0),c.ringCount);y.push({id:`spatial-pattern:${P.pattern}`,level:"wafer",severity:me,variable:{kind:"spatialPattern",label:W},comparison:{family:"spatial-pattern",left:W,right:"Wafer"},effect:{direction:"different",effectSize:I.globalRdd},stats:{method:P.pValue!==void 0?"permutation":"geometry",...P.pValue!==void 0?{pValue:P.pValue}:{},sampleSizeLeft:Oe.length,sampleSizeRight:f.length},summary:`Spatial pattern: ${W.toLowerCase()} (${P.confidence} confidence), ${Ke}${P.note?` [${P.note}]`:""}`,detail:Ke,highlight:{kind:"dies",dieKeys:Oe.map(K=>re(K))},relatedIds:Te.length>0?Te:void 0})}}y.sort((R,T)=>{const P=R.stats.adjustedPValue??R.stats.pValue??1,W=T.stats.adjustedPValue??T.stats.pValue??1;return P!==W?P-W:Math.abs(T.effect.absoluteDelta??0)-Math.abs(R.effect.absoluteDelta??0)});const M=Xt(n.dies,f.length,n.yield,r);a&&(M.isLotStack=!0,h&&(M.aggregationMethod=h));const O=new Set(l.passBins),N={},A=(R,T)=>{const P=N[R]??={dieKeys:[],lostDies:0};P.dieKeys.push(re(T)),(!r||ae(T,O)!==!0)&&P.lostDies++},L=Zt(n.dies,n.testDefs,A);L&&(M.testSpecYield=L);const G=computeFunctionalYield(n.dies,n.testDefs,A);if(G&&(M.functionalYield=G),Object.keys(N).length&&(M.testFailures=N),x&&(M.spatialPattern=x),C===void 0&&c.computePerTestStats&&(C=m),m.length&&(M.testValueAnalysis=bt(g,m.length,f.length)),C?.length){const R=Jt(n.dies,C,n.testDefs,c.minimumSampleSize);R&&(M.perTestStats=R);const T=yt([{dies:n.dies}],n.testDefs,C);T&&(M.capability=T)}Object.assign(M,St(n.dies,n.testDefs));const _=vt([{dies:n.dies,wafer:n.wafer,passBins:c.passBins,ringCount:c.ringCount}]);_&&(M.regionYield=_),V.length>0&&(M.warnings=V);const X=redundancyFacts(f,c.passBins,c.sectorCount);return collapseRedundantFindings(y,X),ne&&(ce=X),{level:"wafer",hasNotableFindings:y.some(R=>R.severity==="notable"||R.severity==="unusual"),findings:y,wafer:n.wafer.metadata??void 0,analysisOptions:recordedOptions(t),stats:M}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isYieldEligibleDie as f}from"../core/dies.js";import{sortBinsForDisplay as u}from"./binPareto.js";export function binCountsFrom(e,r,s){const o=new Map;if(s){for(const[n,i]of Object.entries(s))o.set(Number(n),i);return o}for(const n of e){if(!f(n))continue;const i=r==="hard"?n.hbin:n.sbin;i!=null&&o.set(i,(o.get(i)??0)+1)}return o}export function pooledBinCounts(e,r,s){const o=s==="hard"?"hardBinCounts":"softBinCounts";if(e?.length&&e.every(n=>n.stats[o]!==void 0)){const n=new Map;for(const i of e)for(const[t,a]of Object.entries(i.stats[o]))n.set(Number(t),(n.get(Number(t))??0)+a);return n}return binCountsFrom(r,s)}export function binBreakdownRows(e,r,s){const o=new Set(s),n=[...e.values()].reduce((t,a)=>t+a,0),i=r?new Map(r.map(t=>[t.bin,t.name])):void 0;return u(e.entries(),o).map(([t,a])=>{const c=i?.get(t);return{bin:t,...c?{name:c}:{},label:c?`Bin ${t} \xB7 ${c}`:`Bin ${t}`,count:a,percent:n?a/n*100:0,passing:o.has(t)}})}export const binBreakdownTitle=(e,r)=>`${e==="hard"?"Hard":"Soft"}
|
|
1
|
+
import{isYieldEligibleDie as f}from"../core/dies.js";import{sortBinsForDisplay as u}from"./binPareto.js";export function binCountsFrom(e,r,s){const o=new Map;if(s){for(const[n,i]of Object.entries(s))o.set(Number(n),i);return o}for(const n of e){if(!f(n))continue;const i=r==="hard"?n.hbin:n.sbin;i!=null&&o.set(i,(o.get(i)??0)+1)}return o}export function pooledBinCounts(e,r,s){const o=s==="hard"?"hardBinCounts":"softBinCounts";if(e?.length&&e.every(n=>n.stats[o]!==void 0)){const n=new Map;for(const i of e)for(const[t,a]of Object.entries(i.stats[o]))n.set(Number(t),(n.get(Number(t))??0)+a);return n}return binCountsFrom(r,s)}export function binBreakdownRows(e,r,s){const o=new Set(s),n=[...e.values()].reduce((t,a)=>t+a,0),i=r?new Map(r.map(t=>[t.bin,t.name])):void 0;return u(e.entries(),o).map(([t,a])=>{const c=i?.get(t);return{bin:t,...c?{name:c}:{},label:c?`Bin ${t} \xB7 ${c}`:`Bin ${t}`,count:a,percent:n?a/n*100:0,passing:o.has(t)}})}export const binBreakdownTitle=(e,r)=>`${e==="hard"?"Hard":"Soft"} bin breakdown \u2014 share of ${r.toLocaleString("en-GB")} dies`,totalOf=e=>[...e.values()].reduce((r,s)=>r+s,0);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type Chunked } from '../core/utils.js';
|
|
2
|
+
import { type TestDef } from '../renderer/buildWaferMap.js';
|
|
3
|
+
import { type TableDieRule, type WaferDies } from './overview.js';
|
|
4
|
+
/** Fail dies with a value that a cell needs before it is shown. */
|
|
5
|
+
export declare const SHIFT_MIN_DIES = 10;
|
|
6
|
+
/** Passing dies with a value that a wafer needs before its fail dies are compared with them. */
|
|
7
|
+
export declare const SHIFT_MIN_PASSING = 10;
|
|
8
|
+
/** A clear shift is at least this many standard deviations: smaller ones follow from where on the wafer a bin falls. */
|
|
9
|
+
export declare const SHIFT_MIN_SIGMA = 1;
|
|
10
|
+
/** And its sign test, multiplied by the number of cells compared, is under this. */
|
|
11
|
+
export declare const SHIFT_ALPHA = 0.05;
|
|
12
|
+
export interface BinShiftCell {
|
|
13
|
+
/** The bin's dies with a value for the test, on wafers with enough passing dies. */
|
|
14
|
+
n: number;
|
|
15
|
+
/** Median deviation from the passing dies' median, in their standard deviations: positive reads higher. */
|
|
16
|
+
shift: number;
|
|
17
|
+
/** Large enough, and on enough dies, to be more than chance. */
|
|
18
|
+
clear: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface TestShiftsByBin {
|
|
21
|
+
/** The bins compared: hard, or soft when the dies carry no hard bin. */
|
|
22
|
+
field: 'hbin' | 'sbin';
|
|
23
|
+
/** The largest fail bins with enough dies to compare, largest first, and each one's dies. */
|
|
24
|
+
bins: Array<{
|
|
25
|
+
bin: number;
|
|
26
|
+
dies: number;
|
|
27
|
+
}>;
|
|
28
|
+
/** The tests that differ most, those with a clear shift first: a cell per bin, `null` where too few dies have a value. */
|
|
29
|
+
rows: Array<{
|
|
30
|
+
def: TestDef;
|
|
31
|
+
cells: Array<BinShiftCell | null>;
|
|
32
|
+
}>;
|
|
33
|
+
/** Further tests compared, not listed. */
|
|
34
|
+
more: number;
|
|
35
|
+
/** The largest clear shift, when there is one. */
|
|
36
|
+
lead?: {
|
|
37
|
+
def: TestDef;
|
|
38
|
+
bin: number;
|
|
39
|
+
cell: BinShiftCell;
|
|
40
|
+
};
|
|
41
|
+
/** Some wafer's fail dies are left out of a test: it has too few passing dies with a value. */
|
|
42
|
+
leftOut: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The shifts of every parametric test in the largest fail bins, a step to set up and one a test. `null` when no fail bin has enough
|
|
46
|
+
* dies, or no test has enough values to compare.
|
|
47
|
+
*/
|
|
48
|
+
export declare function testShiftsByBinSteps(wafers: readonly WaferDies[], defs: readonly TestDef[], limits?: {
|
|
49
|
+
bins: number;
|
|
50
|
+
tests: number;
|
|
51
|
+
}): Chunked<TestShiftsByBin | null>;
|
|
52
|
+
/** {@link testShiftsByBinSteps} run to the end. */
|
|
53
|
+
export declare function testShiftsByBin(wafers: readonly WaferDies[], defs: readonly TestDef[], limits?: {
|
|
54
|
+
bins: number;
|
|
55
|
+
tests: number;
|
|
56
|
+
}): TestShiftsByBin | null;
|
|
57
|
+
/** The dies one cell counts: the bin's dies with a value for the test, on the wafers whose passing dies it was compared with. */
|
|
58
|
+
export declare function binShiftRule(wafers: readonly WaferDies[], field: 'hbin' | 'sbin', testNumber: number, bin: number): TableDieRule;
|
|
59
|
+
//# sourceMappingURL=binShifts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{diePassStatus as D,isYieldEligibleDie as O}from"../core/dies.js";import{testValue as _}from"../core/dieTable.js";import{drain as R}from"../core/utils.js";import{binFieldOf as L,isParametricTest as Q}from"../renderer/buildWaferMap.js";import{binomialUpperTail as U,fiveNumberSummary as A,IQR_SIGMA as W,sampleVariance as Y}from"./math.js";import{inFailBin as H}from"./overview.js";export const SHIFT_MIN_DIES=10,SHIFT_MIN_PASSING=10,SHIFT_MIN_SIGMA=1,SHIFT_ALPHA=.05;function P(f,r,a){const c=new Map(a.map((t,n)=>[t,n]));return f.map(t=>{const n=new Set(t.passBins),i={passing:[],failing:a.map(()=>[])};for(const o of t.dies)if(H(o,n,r)){const h=c.get(o[r]);h!==void 0&&i.failing[h].push(o)}else O(o)&&D(o,n)===!0&&i.passing.push(o);return i})}function q(f,r,a,c){let t=0;for(const n of f){const i=_(n,r);i!==void 0&&Number.isFinite(i)&&(a[c+t++]=i)}return t}function j(f,r,a){const c=new Map;for(const t of f){const n=new Set(t.passBins);for(const i of t.dies)H(i,n,r)&&c.set(i[r],(c.get(i[r])??0)+1)}return[...c].filter(([,t])=>t>=SHIFT_MIN_DIES).sort((t,n)=>n[1]-t[1]||t[0]-n[0]).slice(0,a).map(([t,n])=>({bin:t,dies:n}))}export function*testShiftsByBinSteps(f,r,a={bins:6,tests:10}){const c=L(f.map(e=>e.dies)),t=j(f,c,a.bins);if(!t.length)return null;yield;const n=P(f,c,t.map(e=>e.bin)),i=n.reduce((e,s)=>e+s.passing.length,0),o=new Float64Array(i),h=t.map((e,s)=>new Float64Array(n.reduce((p,l)=>p+l.failing[s].length,0))),I=[];let T=!1;for(const e of r){if(!Q(e))continue;yield;let s=0;const p=t.map(()=>0);for(const d of n){const N=q(d.passing,e.testNumber,o,s);if(N<SHIFT_MIN_PASSING){T||=d.failing.some(u=>u.some(m=>_(m,e.testNumber)!==void 0));continue}const b=o.subarray(s,s+N),{median:g}=A(b);for(let u=0;u<b.length;u++)b[u]-=g;s+=N,d.failing.forEach((u,m)=>{const y=q(u,e.testNumber,h[m],p[m]);for(let B=p[m];B<p[m]+y;B++)h[m][B]-=g;p[m]+=y})}if(p.every(d=>d<SHIFT_MIN_DIES))continue;const l=o.subarray(0,s),x=Math.sqrt(Y(l)),{q1:M,q3:G}=A(l),v=(G-M)/W||x;if(!(v>0))continue;const V=p.map((d,N)=>{if(d<SHIFT_MIN_DIES)return null;const b=h[N].subarray(0,d);let g=0,u=0;for(const y of b)y>0?g++:y<0&&u++;const m=g+u?Math.min(1,2*U(Math.max(g,u),g+u,.5)):1;return{n:d,shift:A(b).median/v,clear:!1,p:m}});I.push({def:e,cells:V})}if(!I.length)return null;const E=I.reduce((e,s)=>e+s.cells.filter(Boolean).length,0),F=I.map(e=>{const s=e.cells.map(l=>l&&{n:l.n,shift:l.shift,clear:Math.abs(l.shift)>=SHIFT_MIN_SIGMA&&l.p*E<SHIFT_ALPHA}),p=l=>s.reduce((x,M)=>M&&l(M)?Math.max(x,Math.abs(M.shift)):x,-1);return{def:e.def,cells:s,clearest:p(l=>l.clear),largest:p(()=>!0)}}).sort((e,s)=>s.clearest-e.clearest||s.largest-e.largest||e.def.testNumber-s.def.testNumber);let w;const S=F[0];if(S.clearest>=0){const e=S.cells.findIndex(s=>s?.clear&&Math.abs(s.shift)===S.clearest);w={def:S.def,bin:t[e].bin,cell:S.cells[e]}}return{field:c,bins:t,leftOut:T,...w?{lead:w}:{},rows:F.slice(0,a.tests).map(({def:e,cells:s})=>({def:e,cells:s})),more:Math.max(0,F.length-a.tests)}}export function testShiftsByBin(f,r,a){return R(testShiftsByBinSteps(f,r,a))}export function binShiftRule(f,r,a,c){const t=new Set;for(const n of P(f,r,[c])){const i=o=>Number.isFinite(_(o,a));if(!(n.passing.filter(i).length<SHIFT_MIN_PASSING))for(const o of n.failing[0])i(o)&&t.add(o)}return n=>t.has(n)}
|
|
@@ -50,6 +50,9 @@ export interface CapabilityDatum {
|
|
|
50
50
|
median: number;
|
|
51
51
|
q3: number;
|
|
52
52
|
max: number;
|
|
53
|
+
/** With limits: the dies below `lsl` and above `usl`, the limits the box is placed between. */
|
|
54
|
+
below?: number;
|
|
55
|
+
above?: number;
|
|
53
56
|
}
|
|
54
57
|
export interface CapabilityItem {
|
|
55
58
|
/** One item's dies — typically one wafer, the natural short-term subgroup for Cp/Cpk. */
|
|
@@ -72,7 +75,7 @@ export declare function capabilityLimits(def: TestDef): CapabilityLimits | undef
|
|
|
72
75
|
* (`hasSpec: false`), normalized onto their own observed range instead, so a
|
|
73
76
|
* lot where most tests lack full limits doesn't render as an empty chart.
|
|
74
77
|
* Sorted spec'd-first (worst-Ppk-first within that tier), then unspec'd
|
|
75
|
-
* (
|
|
78
|
+
* (in test number order).
|
|
76
79
|
*/
|
|
77
80
|
export declare function buildCapabilityData(items: CapabilityItem[], testDefs: TestDef[]): CapabilityDatum[];
|
|
78
81
|
/**
|
|
@@ -107,6 +110,8 @@ export interface PooledTestStats {
|
|
|
107
110
|
specTally: Map<number, {
|
|
108
111
|
n: number;
|
|
109
112
|
fail: number;
|
|
113
|
+
low: number;
|
|
114
|
+
high: number;
|
|
110
115
|
}>;
|
|
111
116
|
/** Capability indices plus the chart's normalised five-number summary,
|
|
112
117
|
* worst-Ppk first. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isYieldEligibleDie as
|
|
1
|
+
import{isYieldEligibleDie as H}from"../core/dies.js";import{excludedCounts as V,testValuesReader as _}from"../core/dieTable.js";import{drain as $}from"../core/utils.js";import{isParametricTest as B}from"../renderer/buildWaferMap.js";import{countOutOfSpecSides as D,hasSpecLimits as I}from"../renderer/spec.js";import{testLabel as z,derivedFields as R}from"../renderer/testLabel.js";import{describeValues as j}from"./math.js";const W=25e4;export function capabilityLimits(n){if(n.specLow!==void 0&&n.specHigh!==void 0&&n.specHigh>n.specLow)return{lsl:n.specLow,usl:n.specHigh,basis:"spec"};if(n.limitLow!==void 0&&n.limitHigh!==void 0&&n.limitHigh>n.limitLow)return{lsl:n.limitLow,usl:n.limitHigh,basis:"test"}}function q(n){const s=new Map,e=new Map;for(const a of n){const t=a.testNumber;if(t===void 0||!B(a))continue;e.set(t,a);const i=capabilityLimits(a);i&&s.set(t,i)}return{defByTestNumber:e,specByTest:s}}function*E(n,s,e){const a=[...s.keys()],t=a.length,i=new Float64Array(t),r=new Float64Array(t),o=new Float64Array(t),f=new Float64Array(t),m=new Float64Array(t),S=new Float64Array(t),h=new Float64Array(t),p=new Float64Array(t);let x=0;if(e)for(const c of n)x+=c.dies?.length??0;const N=e?Array.from({length:t},()=>new Float64Array(x)):[],u=_(a),w=new Float64Array(t),M=Math.max(500,Math.floor(W/Math.max(1,t)));let y=0;for(const c of n){S.fill(0),h.fill(0),p.fill(0);for(const d of c.dies??[])if(++y>=M&&(y=0,yield),!!H(d)){u(d,w);for(let l=0;l<t;l++){const g=w[l];Number.isFinite(g)&&(i[l]++,r[l]+=g,o[l]+=g*g,S[l]++,h[l]+=g,p[l]+=g*g,e&&(N[l][i[l]-1]=g))}}for(let d=0;d<t;d++){const l=S[d];if(l<2)continue;const g=h[d]/l,k=(p[d]-l*g*g)/(l-1);f[d]+=(l-1)*Math.max(0,k),m[d]+=l-1}}const b=new Map;for(let c=0;c<t;c++){if(i[c]===0)continue;const d=a[c];b.set(d,{n:i[c],sum:r[c],sumSq:o[c],withinNumerator:f[c],withinDenominator:m[c]}),e&&e.set(d,N[c].subarray(0,i[c]))}return b}function Y(n,s,e){return $(E(n,s,e))}function C(n,s,e,a){const{n:t,sum:i,sumSq:r,withinNumerator:o,withinDenominator:f}=a,m=i/t,S=t>=2?Math.max(0,(r-t*m*m)/(t-1)):0,h=Math.sqrt(S),p=f>0?Math.sqrt(o/f):NaN;let x=null,N=null,u=null,w=null;if(e){const{lsl:M,usl:y}=e,b=y-M;u=h>0?b/(6*h):null,w=h>0?Math.min((y-m)/(3*h),(m-M)/(3*h)):null,x=Number.isFinite(p)&&p>0?b/(6*p):null,N=Number.isFinite(p)&&p>0?Math.min((y-m)/(3*p),(m-M)/(3*p)):null}return{testNumber:n,label:z(s,n),unit:s.unit,...R(s),hasSpec:e!==void 0,lsl:e?.lsl,usl:e?.usl,...e?{limitBasis:e.basis}:{},mean:m,stdOverall:h,stdWithin:p,n:t,cp:x,cpk:N,pp:u,ppk:w}}function v(n){return n.sort((s,e)=>s.hasSpec!==e.hasSpec?s.hasSpec?-1:1:s.hasSpec?s.ppk===null&&e.ppk===null?0:s.ppk===null?1:e.ppk===null?-1:s.ppk-e.ppk:s.testNumber-e.testNumber)}export function buildCapabilityData(n,s){return $(buildCapabilityDataSteps(n,s))}export function*buildCapabilityDataSteps(n,s){return(yield*pooledTestStatsSteps(n,s)).capability.slice()}const F=new Map,K=4,O=new WeakMap;let U=1;function G(n,s){const e=[];for(const t of n){const i=t.dies;if(!i){e.push(0);continue}let r=O.get(i);r===void 0&&(r=U++,O.set(i,r)),e.push(r)}const a=s.filter(t=>t.testNumber!==void 0&&B(t)).map(t=>`${t.testNumber}${t.testType??"P"}${t.limitLow??""}${t.limitHigh??""}${t.specLow??""}${t.specHigh??""}${t.name??""}${t.unit??""}`);return`${e.join(",")}${a.join("")}`}export function clearPooledTestStatsCache(){F.clear();for(const n of T.values())n.work.return(void 0);T.clear()}export function*pooledTestStatsSteps(n,s){const e=G(n,s),a=F.get(e);if(a)return F.delete(e),F.set(e,a),a;let t=T.get(e);t||(t={work:J(n,s,e),callers:0},T.set(e,t));const i=t;i.callers++;try{for(;;){if(i.result)return i.result;const r=i.work.next();if(r.done)return i.result=r.value,T.delete(e),r.value;yield}}finally{i.callers--,!i.result&&i.callers===0&&(i.work.return(void 0),T.get(e)===i&&T.delete(e))}}const T=new Map;function*J(n,s,e){const a={stats:new Map,specTally:new Map,capability:[]},{defByTestNumber:t,specByTest:i}=q(s);if(t.size===0)return a;const r=new Map,o=yield*E(n,t,r),f=new Map,m=new Map,S=[],h=new Map;let p;for(const N of n){const u=V((N.dies??[]).filter(w=>H(w)));if(u){p??=u.by;for(const[w,M]of u.counts)h.set(w,(h.get(w)??0)+M)}}for(const N of s){yield;const u=N.testNumber;if(u===void 0)continue;const w=o.get(u);if(!w||w.n===0||!t.has(u))continue;const M=r.get(u);r.delete(u);const y=I(N)?D(M,N):void 0;y&&m.set(u,{n:M.length,fail:y.low+y.high,low:y.low,high:y.high});const b=j(M);f.set(u,b);const c=i.get(u),d=C(u,N,c,w);let l;if(c){const A=c.usl-c.lsl;l=L=>(L-c.lsl)/A}else{const A=b.min,L=b.max-A;l=L>0?P=>(P-A)/L:()=>.5}const g=h.get(u),k=c?c.basis==="test"&&y?y:D(M,{limitLow:c.lsl,limitHigh:c.usl}):void 0;S.push({...d,...k?{below:k.low,above:k.high}:{},...g&&p?{excluded:{count:g,limitSet:p}}:{},min:l(b.min),q1:l(b.q1),median:l(b.median),q3:l(b.q3),max:l(b.max)})}const x={stats:f,specTally:m,capability:v(S)};return F.set(e,x),F.size>K&&F.delete(F.keys().next().value),x}export function buildCapabilityFigures(n,s){const{defByTestNumber:e,specByTest:a}=q(s);if(e.size===0)return[];const t=Y(n,e,null),i=[];for(const[r,o]of t)o.n!==0&&i.push(C(r,e.get(r),a.get(r),o));return v(i)}export function poolCapabilityFigures(n,s){const{defByTestNumber:e,specByTest:a}=q(s),t=new Map;for(const r of n)for(const o of r){if(!e.has(o.testNumber)||o.n===0)continue;let f=t.get(o.testNumber);f||(f={n:0,sum:0,sumSq:0,withinNumerator:0,withinDenominator:0},t.set(o.testNumber,f));const m=o.stdOverall*o.stdOverall;f.n+=o.n,f.sum+=o.n*o.mean,f.sumSq+=(o.n-1)*m+o.n*o.mean*o.mean,o.n>=2&&(f.withinNumerator+=(o.n-1)*m,f.withinDenominator+=o.n-1)}const i=[];for(const[r,o]of t)i.push(C(r,e.get(r),a.get(r),o));return v(i)}
|
|
@@ -2,6 +2,9 @@ import type { PlotChart } from './plotSpec.js';
|
|
|
2
2
|
import { type GuideSection } from './guideSections.js';
|
|
3
3
|
/** The built-in cards that are not plots. */
|
|
4
4
|
export type CardKind = 'capability' | 'correlation' | 'ring-yield' | 'quadrant-yield' | 'reticle-yield' | 'comparison' | 'commonality' | 'pat' | 'difference-map';
|
|
5
|
+
/** The stable id of a built-in card that is not a plot (a plot card's id is its plot's). Never renamed once released. */
|
|
6
|
+
export declare const cardKindId: (kind: CardKind) => string;
|
|
7
|
+
export { catalogueCardId } from './reportSections.js';
|
|
5
8
|
/** Where a chart or table is found in Insights; `drilldown` is the menu opened on picked dies. */
|
|
6
9
|
export type CatalogueTab = 'overview' | 'distributions' | 'correlation' | 'data' | 'plots' | 'drilldown';
|
|
7
10
|
/** What an entry is: a way of colouring the map, a chart, a built-in card (a chart or a table), or a table of the Data tab. */
|