@wafertools/wafermap 0.34.0 → 0.35.1
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 +7 -1
- package/CHANGELOG.md +189 -1
- package/README.md +6 -3
- package/dist/packages/canvas-adapter/charts/barPanel.d.ts +1 -1
- package/dist/packages/canvas-adapter/charts/binCluster.js +1 -1
- package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
- package/dist/packages/canvas-adapter/charts/capability.js +1 -1
- package/dist/packages/canvas-adapter/charts/chartShell.d.ts +17 -2
- package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
- package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
- package/dist/packages/canvas-adapter/charts/histogram.js +1 -1
- package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
- package/dist/packages/canvas-adapter/charts/regionYieldDiagram.d.ts +6 -1
- package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
- package/dist/packages/canvas-adapter/charts/scatter.js +1 -1
- package/dist/packages/canvas-adapter/charts/testPassRate.js +1 -1
- package/dist/packages/canvas-adapter/dataTab.d.ts +6 -0
- package/dist/packages/canvas-adapter/dataTab.js +1 -1
- package/dist/packages/canvas-adapter/dieList.js +6 -6
- package/dist/packages/canvas-adapter/drilldown.d.ts +3 -0
- package/dist/packages/canvas-adapter/drilldown.js +1 -1
- package/dist/packages/canvas-adapter/identityHeader.d.ts +4 -1
- package/dist/packages/canvas-adapter/identityHeader.js +1 -1
- package/dist/packages/canvas-adapter/insightsTab.d.ts +3 -1
- package/dist/packages/canvas-adapter/insightsTab.js +1 -1
- package/dist/packages/canvas-adapter/plotEditor.js +1 -1
- package/dist/packages/canvas-adapter/plotTab.d.ts +3 -0
- package/dist/packages/canvas-adapter/plotTab.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +8 -0
- package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferMap.d.ts +22 -1
- package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
- package/dist/packages/canvas-adapter/summaryPanel.d.ts +39 -11
- package/dist/packages/canvas-adapter/summaryPanel.js +4 -2
- package/dist/packages/canvas-adapter/summaryToggle.d.ts +11 -0
- package/dist/packages/canvas-adapter/summaryToggle.js +1 -0
- package/dist/packages/canvas-adapter/sweepEditor.js +1 -1
- package/dist/packages/canvas-adapter/toolbar.d.ts +8 -0
- 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 +57 -27
- package/dist/packages/canvas-adapter/version.d.ts +2 -2
- package/dist/packages/canvas-adapter/version.js +1 -1
- package/dist/packages/canvas-adapter/warnings.js +1 -1
- package/dist/packages/core/classify.d.ts +5 -0
- package/dist/packages/core/classify.js +1 -1
- package/dist/packages/core/dieTable.d.ts +26 -0
- package/dist/packages/core/dieTable.js +1 -1
- package/dist/packages/core/index.d.ts +1 -1
- package/dist/packages/core/index.js +1 -1
- package/dist/packages/core/passBins.d.ts +6 -0
- package/dist/packages/core/passBins.js +1 -1
- package/dist/packages/core/reticle.d.ts +20 -0
- package/dist/packages/core/reticle.js +1 -1
- package/dist/packages/core/wafer.d.ts +15 -0
- package/dist/packages/core/wafer.js +1 -1
- package/dist/packages/renderer/buildView.js +1 -1
- package/dist/packages/renderer/buildWaferMap.d.ts +32 -1
- package/dist/packages/renderer/buildWaferMap.js +1 -1
- package/dist/packages/renderer/derivedTests/apply.js +1 -1
- package/dist/packages/renderer/derivedTests/evaluate.d.ts +3 -1
- package/dist/packages/renderer/derivedTests/evaluate.js +1 -1
- package/dist/packages/renderer/derivedTests/parser.d.ts +7 -0
- package/dist/packages/renderer/derivedTests/parser.js +2 -2
- package/dist/packages/renderer/spec.d.ts +4 -0
- package/dist/packages/renderer/spec.js +1 -1
- package/dist/packages/renderer/valueFilter.d.ts +55 -0
- package/dist/packages/renderer/valueFilter.js +1 -0
- package/dist/packages/stats/analyzeWaferLot.js +1 -1
- package/dist/packages/stats/analyzeWaferMap.d.ts +44 -3
- package/dist/packages/stats/analyzeWaferMap.js +1 -1
- package/dist/packages/stats/capability.d.ts +5 -0
- package/dist/packages/stats/capability.js +1 -1
- package/dist/packages/stats/clusterDetection.js +1 -1
- package/dist/packages/stats/connectedComponents.d.ts +19 -0
- package/dist/packages/stats/connectedComponents.js +1 -1
- package/dist/packages/stats/dieRegions.d.ts +42 -0
- package/dist/packages/stats/dieRegions.js +1 -0
- package/dist/packages/stats/facets.d.ts +8 -0
- package/dist/packages/stats/facets.js +1 -1
- package/dist/packages/stats/index.d.ts +2 -1
- package/dist/packages/stats/index.js +1 -1
- package/dist/packages/stats/lotPattern.js +1 -1
- package/dist/packages/stats/math.d.ts +25 -3
- package/dist/packages/stats/math.js +1 -1
- package/dist/packages/stats/metadataColumns.js +1 -1
- package/dist/packages/stats/patternClassification.d.ts +44 -18
- package/dist/packages/stats/patternClassification.js +1 -1
- package/dist/packages/stats/plotData.d.ts +12 -1
- package/dist/packages/stats/plotData.js +1 -1
- package/dist/packages/stats/plotSpec.d.ts +1 -1
- package/dist/packages/stats/plotSpec.js +1 -1
- package/dist/packages/stats/regions.d.ts +15 -0
- package/dist/packages/stats/regions.js +1 -1
- package/dist/packages/stats/renderSummaryReport.js +33 -33
- package/dist/packages/stats/reportHtml.d.ts +7 -6
- package/dist/packages/stats/reportHtml.js +39 -37
- package/dist/packages/stats/synthesis.d.ts +44 -17
- package/dist/packages/stats/synthesis.js +1 -1
- package/dist/packages/stats/types.d.ts +12 -0
- package/llms.txt +2 -2
- package/package.json +1 -1
- package/dist/packages/canvas-adapter/summaryRail.d.ts +0 -7
- package/dist/packages/canvas-adapter/summaryRail.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{normalizeInput as Ge}from"./normalizeInput.js";import{computeCapability as Xe,computeTestFlagYield as Ze,computeRegionYield as Je}from"./summaryFigures.js";import{binPassSets as Me}from"../renderer/binColors.js";import{diePassStatus as Be,isYieldEligibleDie as de,getDieKey as Ne,isPositionedDie as Fe,positionKey as me}from"../core/dies.js";import{dieHasValues as et,testsPresent as Pe,testValue as j}from"../core/dieTable.js";import{getTestPassStatus as se,isParametricTest as W}from"../renderer/buildWaferMap.js";import{markedTestLabel as T,derivedFields as oe}from"../renderer/testLabel.js";import{buildQuadrantRegions as tt,buildReticlePositionRegions as nt,buildRingRegions as it,buildSectorRegions as st,buildTestSiteRegions as ot,sectorCompassNames as xe,areQuadrantsAdjacent as at,parseRegionKey as Y,QUADRANT_CYCLE as pe,regionAngleBins as rt}from"./regions.js";import{buildClusterFindings as ft}from"./clusterDetection.js";import{classifyPattern as lt,patternExplains as ct,patternFailVerdict as ut,PATTERN_LABELS as dt}from"./patternClassification.js";import{requirePassBins as mt}from"../core/passBins.js";import{requireRingCount as pt}from"../core/ringCount.js";import{benjaminiHochberg as ht,fiveNumberSummary as gt,normalCdf as Ce,sampleVariance as he}from"./math.js";import{mean as ae,clamp01 as Ve,maxOf as bt}from"../core/utils.js";import{classifySpec as re,isOutOfSpec as ge}from"../renderer/spec.js";const yt={significanceLevel:{min:1e-6,max:1},minimumEffectSize:{min:0,max:1},minimumRelativeEffect:{min:0,max:Number.MAX_SAFE_INTEGER}},Le=[4,8,16];export function resolveOptions(t){const i=Object.fromEntries(Object.entries(t).filter(([,f])=>f!==void 0)),s={...X,...i},n=[],e=[];for(const f of["significanceLevel","minimumEffectSize","minimumRelativeEffect"]){const{min:c,max:o}=yt[f],u=s[f];if(typeof u!="number"||!Number.isFinite(u)){e.push(`${f}=${String(u)} is not a finite number (using ${X[f]})`),s[f]=X[f];continue}const a=Math.min(o,Math.max(c,u));a!==u&&(e.push(`${f}=${u} is outside ${c}\u2013${o} (using ${a})`),s[f]=a)}if(Le.includes(s.sectorCount)||(e.push(`sectorCount=${s.sectorCount} is not one of ${Le.join(", ")} (using ${X.sectorCount})`),s.sectorCount=X.sectorCount),e.length){const f=`analyzeWaferMap: ${e.join("; ")}. The analysis ran with the corrected values.`;console.warn(`[wafermap] ${f}`),n.push({code:"analysis-option-corrected",message:f,severity:"warning"})}const l=["passBins","ringCount"].filter(f=>i[f]!==void 0);if(l.length){const f=`analyzeWaferMap: ${l.join(" and ")} ${l.length>1?"are":"is"} no longer an analysis option and was ignored. Set ${l.length>1?"them":"it"} on buildWaferMap; the analysis used the value the map was built with.`;console.warn(`[wafermap] ${f}`),n.push({code:"analysis-option-corrected",message:f,severity:"warning"})}const r=["enableYieldAnalysis","enableHardBinAnalysis","enableSoftBinAnalysis","enableReticlePositionAnalysis","enableTestSiteAnalysis","enableClusterAnalysis","enableAngularAnalysis","enablePatternClassification"].filter(f=>i[f]!==void 0);if(r.length){const f=`analyzeWaferMap: ${r.join(", ")} ${r.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] ${f}`),n.push({code:"analysis-option-corrected",message:f,severity:"warning"})}return{resolved:s,warnings:n}}const X={significanceLevel:.05,minimumEffectSize:.2,minimumRelativeEffect:1,minimumSampleSize:5,enableTestValueAnalysis:!1,computePerTestStats:!1,sectorCount:8,minimumClusterSize:5};function St(t,i){const s={...t};return s.minimumClusterSize=Math.max(5,Math.round(i*.003)),s}function wt(t){return de(t)?t.hbin!==void 0||t.sbin!==void 0||et(t):!1}function vt(t,i,s){if(!t||i)return;const n=(s??[]).filter(e=>W(e)&&(e.limitLow!==void 0||e.limitHigh!==void 0));if(n.length!==0)return e=>{for(const l of n)if(ge(re(j(e,l.testNumber),l)))return!0;return!1}}function $t(t,i,s){const n=new Set,e=new Set,l=new Set,r=new Map,f=new Map;for(const c of Pe(t))n.add(c);for(const c of t)c.hbin!==void 0&&e.add(c.hbin),c.sbin!==void 0&&l.add(c.sbin),de(c)&&(c.hbin!==void 0&&r.set(c.hbin,(r.get(c.hbin)??0)+1),c.sbin!==void 0&&f.set(c.sbin,(f.get(c.sbin)??0)+1));return{totalDies:t.length,analyzedDies:i,excludedDies:t.length-i,yieldPercent:s,testsConsidered:[...n].sort((c,o)=>c-o),hardBinsConsidered:[...e].sort((c,o)=>c-o),softBinsConsidered:[...l].sort((c,o)=>c-o),...r.size?{hardBinCounts:Object.fromEntries(r)}:{},...f.size?{softBinCounts:Object.fromEntries(f)}:{}}}function zt(t,i){if(!i?.length)return;const s=i.filter(e=>W(e)&&(e.limitLow!==void 0||e.limitHigh!==void 0));if(!s.length)return;const n=[];for(const e of s){const l=e.testNumber;let r=0,f=0,c=0,o=0;for(const u of t){if(u.partial||u.edgeExcluded)continue;const a=re(j(u,l),e);a!==null&&(o++,a==="failLow"?f++:a==="failHigh"?c++:r++)}n.push({testNumber:l,label:e.name,passDies:r,failLowDies:f,failHighDies:c,totalDies:o,yieldPercent:o>0?r/o*100:null})}return n.length?n:void 0}export function computeFunctionalYield(t,i){if(!i?.length)return;const s=i.filter(e=>!W(e));if(!s.length)return;const n=[];for(const e of s){const l=e.testNumber;let r=0,f=0;for(const o of t){if(o.partial||o.edgeExcluded)continue;const u=se(o,l,e);u!==void 0&&(u?r++:f++)}const c=r+f;n.push({testNumber:l,label:T(e,l),...oe(e),passDies:r,failDies:f,totalDies:c,passRatePercent:c>0?r/c*100:null})}return n.length?n:void 0}function kt(t,i,s,n){const e=[];for(const l of i){const r=[];for(const a of t){if(a.partial||a.edgeExcluded)continue;const h=j(a,l);h!==void 0&&Number.isFinite(h)&&r.push(h)}if(r.length<n)continue;const f=ae(r),c=Math.sqrt(he(r,f)),o=gt(Float64Array.from(r)),u=s?.find(a=>a.testNumber===l)?.name??String(l);e.push({testNumber:l,label:u,count:r.length,min:o.min,max:o.max,mean:f,stddev:c,median:o.median,q1:o.q1,q3:o.q3})}return e.length?e:void 0}export function twoProportionZ(t,i,s,n){const e=(t+s)/(i+n),l=e*(1-e)*(1/i+1/n);return!Number.isFinite(l)||l<=0?0:(t/i-s/n)/Math.sqrt(l)}export function zPValue(t){return Ve(2*(1-Ce(Math.abs(t))))}function O(t,i,s,n){const e=twoProportionZ(t,i,s,n);return e===0?1:zPValue(e)}export function adjustPValues(t){const i=new Map;for(const s of t){const n=`${s.variable.kind}:${s.comparison.family}`,e=i.get(n)??[];e.push(s),i.set(n,e)}for(const s of i.values()){const n=s.filter(l=>l.stats.pValue!==void 0),e=ht(n.map(l=>l.stats.pValue));n.forEach((l,r)=>{l.stats.adjustedPValue=e[r]})}return t}export function rateRelativeEffect(t){const i=(t.passRate?t.n-t.hits:t.hits)/t.n,s=(t.passRate?t.restN-t.restHits:t.restHits)/t.restN;return s===0?i===0?0:1/0:Math.abs(i-s)/s}export function severityForFinding(t,i,s){const n=Math.abs(i),e=s;return t<=.01&&(n>=.3||e>=2.5)?"unusual":t<=.05&&(n>=.2||e>=1.5)?"notable":"info"}export function severityForScore(t,i){return t<=.01&&Math.abs(i)>=.5?"unusual":t<=.05&&Math.abs(i)>=.15?"notable":"info"}function fe(t){return t==="reticle-position"?"other reticle positions":t==="test-site"?"other test sites":"the rest of the map"}function _(t){return t==="reticle-position"?"Other reticle positions":t==="test-site"?"Other test sites":"Rest of map"}function be(t,i,s){const n=(Math.abs(i)*100).toFixed(1);return`${t} yield is ${n} percentage points ${i>0?"higher":"lower"} than ${fe(s)}`}function ye(t,i){return i==="quadrant"&&!t.startsWith("Quadrant")?`quadrant ${t}`:t}function Ke(t){return/^(Rings|Sectors|Quadrants)\b/.test(t)?"have":"has"}function Se(t,i,s,n){const e=ye(t,n),l=(Math.abs(s)*100).toFixed(1);return`${e} ${Ke(e)} ${i} occurrence ${l} percentage points ${s>0?"higher":"lower"} than ${fe(n)}`}function we(t,i,s,n){const e=ye(t,n),l=(Math.abs(s)*100).toFixed(1);return`${e} ${Ke(e)} ${i} pass rate ${l} percentage points ${s>0?"higher":"lower"} than ${fe(n)}`}function ve(t,i,s,n,e,l){const r=ye(t,e),f=fe(e),c=s>0?"higher":"lower";if(n!==void 0&&Number.isFinite(n)){const u=(Math.abs(n)*100).toFixed(1);return`${r} mean ${i} is ${u}% ${c} than ${f}`}const o=l?` ${l}`:"";return`${r} mean ${i} is ${Math.abs(s).toPrecision(3)}${o} ${c} than ${f}`}function Ee(t,i,s){const n=i?.find(e=>e.bin===t);return n?.name?`${s} ${t} (${n.name})`:`${s} ${t}`}function Dt(t,i){const s=i?.find(n=>n.testNumber===t);return{label:T(s,t),unit:s?.unit,...oe(s)}}const Oe=new WeakMap,Te=new WeakMap,qe=new WeakMap;function Z(t,i){const s=i.highlight.dieKeys;return s&&qe.set(s,t),i}let Q=null,J;const He=new WeakMap;export function candidatesOf(t){return He.get(t)}function Ae(t,i,s,n){if(!Q)return;const e=je(t);if(!e)return;const l=t.id.slice(0,t.id.indexOf(":")),r=l==="specLimit"?"limitFail":l,{kind:f,bin:c,index:o}=t.variable;Q.push({key:[r,f,c??"",o??"",e.family,e.key].join("|"),source:r,variable:t.variable,label:t.variable.label,comparison:t.comparison,region:e,z:i,delta:t.effect.absoluteDelta??0,effectSize:t.effect.effectSize??0,relativeDelta:t.effect.relativeDelta,rate:s,mean:n})}export function describeRegional(t,i,s){const n=t.comparison.left,e=t.region.family;switch(t.source){case"yield":return be(n,i,e);case"hardBin":case"softBin":return Se(n,t.label,i,e);case"functional":return we(n,t.label.replace(/ pass rate$/,""),i,e);case"limitFail":return $e(n,t.label,i);case"test":return ve(n,t.label,i,s,e,t.variable.unit)}}function $e(t,i,s){return`${t} limit fail rate for ${i} is ${(Math.abs(s)*100).toFixed(1)} pp ${s>0?"higher":"lower"} than the rest of the wafer`}const U=new WeakMap;function le(t,i){return U.set(t,i),t}function je(t){const i=t.highlight.dieKeys;return i?qe.get(i):void 0}const Ie=new WeakMap;function I(t){let i=Ie.get(t);return i||Ie.set(t,i=t.map(me)),i}function Rt(t){let i=Oe.get(t);return i||Oe.set(t,i=t.map(Ne)),i}function ce(t,i){let s=Te.get(t);s||Te.set(t,s={members:new Set(t),byFamily:new WeakMap});const n=s.byFamily.get(i);if(n)return n;const{members:e}=s,l=new Map;for(const r of i)l.set(r.key,r.dies.filter(f=>e.has(f)));return s.byFamily.set(i,l),l}function ue(t,i){adjustPValues(t);for(const n of t){const e=U.get(n);Ae(n,twoProportionZ(e.hits,e.n,e.restHits,e.restN),e)}const s=t.filter(n=>passesRateGate(n.stats.adjustedPValue??n.stats.pValue??1,n.effect.absoluteDelta??0,rateRelativeEffect(U.get(n)),i));return s.filter(n=>!Mt(n,s,i)).map(n=>({...n,severity:severityForFinding(n.stats.adjustedPValue??n.stats.pValue??1,n.effect.absoluteDelta??0,rateRelativeEffect(U.get(n)))}))}export function passesRateGate(t,i,s,n){return t<=n.significanceLevel&&(Math.abs(i)>=n.minimumEffectSize||s>=n.minimumRelativeEffect)}export function claimForPattern(t,i,s,n,e){const l=[];for(const r of s){const f=r.comparison.family,c=f==="ring"?n(r):[];t.some(o=>ct(o,f,c,e))&&(l.push(r.id),i!=="info"&&(f==="ring"||f==="quadrant"||f==="sector")&&(r.severity="info"))}return l}function Mt(t,i,s){const n=U.get(t);if(!n)return!1;const e=t.stats.pValue??1;let{restHits:l,restN:r}=n;for(const u of We(t,i)){const a=U.get(u);a&&(l-=a.hits,r-=a.n)}if(r===n.restN)return!1;if(r<s.minimumSampleSize)return!0;const f=n.hits/n.n-l/r;if(Math.sign(f)!==Math.sign(t.effect.absoluteDelta??0))return!0;const c=e>0?(t.stats.adjustedPValue??e)/e:1,o=Math.min(1,O(n.hits,n.n,l,r)*c);return!passesRateGate(o,f,rateRelativeEffect({...n,restHits:l,restN:r}),s)}function We(t,i){const s=t.stats.pValue??1;return i.filter(n=>n!==t&&n.effect.direction!==t.effect.direction&&n.variable.kind===t.variable.kind&&n.variable.bin===t.variable.bin&&n.variable.index===t.variable.index&&n.comparison.family===t.comparison.family&&(n.stats.pValue??1)<s)}const ze=new WeakMap;export function welchOfSums(t,i,s,n){const e=(l,r,f)=>f>1?Math.max(0,l-r*r/f)/(f-1):0;return welchFromStats(t.n,t.sum/t.n,e(t.sq,t.sum,t.n),i,s/i,e(n,s,i))}function Bt(t,i,s){const n=ze.get(t);if(!n)return!1;let{restN:e,restSum:l,restSq:r}=n;for(const h of We(t,i)){const g=ze.get(h);g&&(e-=g.n,l-=g.sum,r-=g.sq)}if(e===n.restN)return!1;if(e<s.minimumSampleSize)return!0;const{pValue:f,effectSize:c,delta:o}=welchOfSums(n,e,l,r);if(Math.sign(o)!==Math.sign(t.effect.absoluteDelta??0))return!0;const u=t.stats.pValue??1,a=u>0?(t.stats.adjustedPValue??u)/u:1;return!(Math.min(1,f*a)<=s.significanceLevel&&Math.abs(c)>=s.minimumEffectSize)}function ee(t,i,s,n){const e=new Set(s),l=ce(t,i),r=new Map,f=new Map;for(const[o,u]of l){let a=0,h=0;for(const g of u)g.hbin!==void 0&&(h++,e.has(g.hbin)&&a++);r.set(o,a),f.set(o,h)}const c=[];for(const o of i){const u=f.get(o.key)??0,a=r.get(o.key)??0;let h=0,g=0;for(const[k,S]of f)k!==o.key&&(h+=S,g+=r.get(k)??0);if(u<n.minimumSampleSize||h<n.minimumSampleSize)continue;const p=a/u,d=g/h,y=p-d,w=O(a,u,g,h);c.push(le(Z(o,{id:`yield:${o.key}`,level:"wafer",severity:"info",variable:{kind:"yield",label:"Yield"},comparison:{family:o.family,left:o.label,right:_(o.family)},effect:{direction:y===0?"different":y>0?"higher":"lower",absoluteDelta:y,relativeDelta:d===0?void 0:y/d,effectSize:y},stats:{method:"two-proportion-z",pValue:w,sampleSizeLeft:u,sampleSizeRight:h},summary:be(o.label,y,o.family),highlight:{kind:"region",regionFamily:o.family,regionKeys:[o.key],dieKeys:[...o.dieKeys]}}),{hits:a,n:u,restHits:g,restN:h,passRate:!0}))}return ue(c,n)}function E(t,i,s,n,e,l){const r=p=>s==="soft"?p.sbin:p.hbin,f=[...new Set(t.map(r).filter(p=>p!==void 0))].sort((p,d)=>p-d),c=ce(t,i),o=new Map,u=new Map;for(const[p,d]of c){const y=new Map;for(const w of d){const k=r(w);k!==void 0&&y.set(k,(y.get(k)??0)+1)}o.set(p,y),u.set(p,d.length)}const a=[],h=e==="hardBin"?"HBin":"SBin",g=s==="hard"?new Set(l.passBins):l.softPassBins??Me(t,l.passBins).soft;for(const p of i){const d=u.get(p.key)??0,y=o.get(p.key);let w=0;const k=new Map;for(const[S,$]of o)if(S!==p.key){w+=u.get(S)??0;for(const[N,F]of $)k.set(N,(k.get(N)??0)+F)}if(!(d<l.minimumSampleSize||w<l.minimumSampleSize))for(const S of f){const $=y.get(S)??0,N=k.get(S)??0,F=$/d,b=N/w,v=F-b,M=O($,d,N,w),z=Ee(S,n,h);a.push(le(Z(p,{id:`${e}:${S}:${p.key}`,level:"wafer",severity:"info",variable:{kind:e,bin:S,label:z},comparison:{family:p.family,left:p.label,right:_(p.family)},effect:{direction:v===0?"different":v>0?"higher":"lower",absoluteDelta:v,relativeDelta:b===0?void 0:v/b,effectSize:v},stats:{method:"two-proportion-z",pValue:M,sampleSizeLeft:d,sampleSizeRight:w},summary:Se(p.label,z,v,p.family),highlight:{kind:"bin",bin:S,regionKeys:[p.key],dieKeys:[...p.dieKeys]}}),{hits:$,n:d,restHits:N,restN:w,passRate:g.has(S)}))}}return ue(a,l)}function te(t,i,s,n){const e=(s??[]).filter(u=>!W(u));if(!e.length)return[];const l=e.map(u=>u.testNumber),r=ce(t,i),f=new Map,c=new Map;for(const[u,a]of r){const h=new Uint32Array(e.length),g=new Uint32Array(e.length);for(const p of a)for(let d=0;d<e.length;d++){const y=se(p,l[d],e[d]);y!==void 0&&(g[d]++,y&&h[d]++)}f.set(u,h),c.set(u,g)}const o=[];for(const u of i){const a=f.get(u.key),h=c.get(u.key);for(let g=0;g<e.length;g++){let p=0,d=0;for(const[b,v]of c)b!==u.key&&(d+=v[g],p+=f.get(b)[g]);const y=h[g],w=a[g];if(y<n.minimumSampleSize||d<n.minimumSampleSize)continue;const k=w/y,S=p/d,$=k-S,N=O(w,y,p,d),F=l[g];o.push(le(Z(u,{id:`functional:${F}:${u.key}`,level:"wafer",severity:"info",variable:{kind:"functionalTest",index:F,label:`${T(e[g],F)} pass rate`,...oe(e[g])},comparison:{family:u.family,left:u.label,right:_(u.family)},effect:{direction:$===0?"different":$>0?"higher":"lower",absoluteDelta:$,relativeDelta:S===0?void 0:$/S,effectSize:$},stats:{method:"two-proportion-z",pValue:N,sampleSizeLeft:y,sampleSizeRight:d},summary:we(u.label,T(e[g],F),$,u.family),highlight:{kind:"region",regionFamily:u.family,regionKeys:[u.key],dieKeys:[...u.dieKeys]}}),{hits:w,n:y,restHits:p,restN:d,passRate:!0}))}}return ue(o,n)}export function welchFromStats(t,i,s,n,e,l){const r=Math.sqrt(s/t+l/n),f=i-e;if(!Number.isFinite(r)||r===0)return{pValue:1,effectSize:0,delta:f,z:0};const c=f/r,o=Math.sqrt(Math.max(0,(s+l)/2)),u=o===0?f:f/o;return{pValue:Ve(2*(1-Ce(Math.abs(c)))),effectSize:u,delta:f,z:c}}function Nt(t,i){const s=ae(t),n=ae(i);return welchFromStats(t.length,s,he(t,s),i.length,n,he(i,n))}const Ye=250;function _e(t,i,s){const n=r=>r.filter(f=>W(s?.find(c=>c.testNumber===f)));if(i)return{testNumbers:n(i.slice().sort((r,f)=>r-f))};const e=Pe(t,"values");if(e.length>Ye){const r=`Test-value analysis was skipped: more than ${Ye} tests were found in the die data, so no test findings were computed. Pass testNumbers: [...] to analyse specific tests.`;return console.warn(`[wafermap] analyzeWaferMap: ${r}`),{testNumbers:[],warning:{code:"test-count-capped",message:r,severity:"warning"}}}return{testNumbers:n(e)}}function ne(t,i,s,n){const e=_e(t,n.testNumbers,s);if(e.warning)return{findings:[],warning:e.warning};const l=e.testNumbers,r=new Map;for(let d=0;d<i.length;d++)for(const y of I(i[d].dies))r.set(y,d);const f=i.length,c=[],o=[];for(const d of t){const y=r.get(me(d));y!==void 0&&(c.push(d),o.push(y))}const u=[],a=new Float64Array(f),h=new Float64Array(f),g=new Float64Array(f);for(const d of l){a.fill(0),h.fill(0),g.fill(0);let y=0,w=0,k=0,S;for(let $=0;$<c.length;$++){const N=c[$],F=j(N,d);if(F===void 0)continue;S===void 0&&(S=F);const b=F-S,v=o[$];a[v]+=1,h[v]+=b,g[v]+=b*b,y+=1,w+=b,k+=b*b}if(S!==void 0)for(let $=0;$<f;$++){const N=a[$],F=y-N;if(N<n.minimumSampleSize||F<n.minimumSampleSize)continue;const b=h[$]/N,M=(w-h[$])/F,z=b+S,D=M+S,C=N>1?Math.max(0,g[$]-N*b*b)/(N-1):0,m=F>1?Math.max(0,k-g[$]-F*M*M)/(F-1):0,{pValue:R,effectSize:P,delta:B,z:x}=welchFromStats(N,z,C,F,D,m),V=i[$],{label:L,unit:q,...H}=Dt(d,s),K=D!==0?B/Math.abs(D):void 0,A=Z(V,{id:`test:${d}:${V.key}`,level:"wafer",severity:"info",variable:{kind:"test",index:d,label:L,unit:q,...H},comparison:{family:V.family,left:V.label,right:_(V.family)},effect:{direction:B===0?"different":B>0?"higher":"lower",absoluteDelta:B,relativeDelta:K,effectSize:P},stats:{method:"welch-z-approx",pValue:R,sampleSizeLeft:N,sampleSizeRight:F},summary:ve(V.label,L,B,K,V.family,q),highlight:{kind:"region",regionFamily:V.family,regionKeys:[V.key],dieKeys:[...V.dieKeys]}}),Re={n:N,sum:h[$],sq:g[$],restN:F,restSum:w-h[$],restSq:k-g[$],shift:S};ze.set(A,Re),Ae(A,x,void 0,Re),u.push(A)}}adjustPValues(u);const p=u.filter(d=>{const y=d.stats.adjustedPValue??d.stats.pValue??1,w=Math.abs(d.effect.effectSize??0);return y<=n.significanceLevel&&w>=n.minimumEffectSize});return{activeTestNumbers:l,findings:p.filter(d=>!Bt(d,p,n)).map(d=>({...d,severity:severityForScore(d.stats.adjustedPValue??d.stats.pValue??1,d.effect.effectSize??0)}))}}function Ft(t,i,s,n){if(!s?.length)return[];const e=s.filter(r=>W(r)&&(r.limitLow!==void 0||r.limitHigh!==void 0));if(!e.length)return[];const l=[];for(const r of e){const f=r.testNumber;for(const c of i){const o=ce(t,c),u=[],a=new Map;let h=0,g=0;for(const[p,d]of o){let y=0,w=0;for(const k of d){const S=j(k,f);S!==void 0&&(y++,ge(re(S,r))&&w++)}a.set(p,{valid:y,fail:w}),h+=y,g+=w}for(const p of c){const d=a.get(p.key),y=d.valid,w=h-d.valid;if(y<n.minimumSampleSize||w<n.minimumSampleSize)continue;const k=d.fail,S=g-d.fail,$=k/y,N=S/w,F=$-N,b=O(k,y,S,w);u.push(le(Z(p,{id:`specLimit:${f}:${p.key}`,level:"wafer",severity:"info",variable:{kind:"test",index:f,label:T(r,f),unit:r.unit,...oe(r)},comparison:{family:p.family,left:p.label,right:_(p.family)},effect:{direction:F===0?"different":F>0?"higher":"lower",absoluteDelta:F,relativeDelta:N===0?void 0:F/N,effectSize:F},stats:{method:"two-proportion-z",pValue:b,sampleSizeLeft:y,sampleSizeRight:w},summary:$e(p.label,T(r,f),F),highlight:{kind:"region",regionFamily:p.family,regionKeys:[p.key],dieKeys:[...p.dieKeys]}}),{hits:k,n:y,restHits:S,restN:w,passRate:!1}))}l.push(...ue(u,n))}}return l}function ke(t,i){return t==="softBin"?i.softEligibleDies:t==="test"?i.testDies:i.eligibleDies}function Pt(t){return t.id.startsWith("specLimit:")}function ie(t){return t.highlight.regionKeys??[]}function xt(t){const i=t.variable.bin??t.variable.index??"";return`${t.comparison.family}\0${Qe(t)}\0${t.variable.kind}\0${i}\0${t.effect.direction}`}function Ct(t,i){const s=Y(t);return s.family==="ring"?s.ring??0:s.family==="sector"?xe(i).indexOf(s.sector??""):0}export function inQuadrantOrder(t){const i=new Set(t),s=pe.findIndex((e,l)=>i.has(e)&&!i.has(pe[(l+3)%4])),n=s<0?0:s;return Array.from({length:4},(e,l)=>pe[(n+l)%4]).filter(e=>i.has(e))}export function findContiguousRuns(t,i,s,n){if(i==="quadrant"){const c=new Map;for(const h of t){const g=Y(n(h)).quadrant;g&&c.set(g,h)}const o=[...c.keys()],u=new Set,a=[];for(const h of o){if(u.has(h))continue;const g=[],p=[h];for(u.add(h);p.length;){const d=p.pop();g.push(d);for(const y of o)!u.has(y)&&at(d,y)&&(u.add(y),p.push(y))}a.push(inQuadrantOrder(g).map(d=>c.get(d)))}return a}const e=c=>Ct(n(c),s),l=[...t].sort((c,o)=>e(c)-e(o)),r=[];let f=[];for(const c of l){if(f.length===0){f.push(c);continue}const o=e(f[f.length-1]);e(c)-o===1?f.push(c):(r.push(f),f=[c])}if(f.length&&r.push(f),i==="sector"&&r.length>1){const o=xe(s).length,u=e(r[0][0]),a=e(r[r.length-1][r[r.length-1].length-1]);if(u===0&&a===o-1){const h=r.pop();r[0]=[...h,...r[0]]}}return r}export function mergedRegionLabel(t,i,s){if(t==="ring"){const e=i.map(c=>Y(c).ring).filter(c=>c!==void 0).sort((c,o)=>c-o),l=e[0],r=e[e.length-1];let f="";return l===r&&l===1&&s>1?f=" (core)":l===r&&l===s&&s>1&&(f=" (edge)"),l===r?`Ring ${l}${f}`:`Rings ${l}\u2013${r}`}if(t==="sector"){const e=i.map(l=>Y(l).sector??"");return e.length===1?`Sector ${e[0]}`:`Sectors ${e[0]}\u2013${e[e.length-1]}`}const n=i.map(e=>Y(e).quadrant??"");return n.length===1?n[0]:n.length===2?`Quadrants ${n[0]} & ${n[1]}`:`Quadrants ${n.slice(0,-1).join(", ")} & ${n[n.length-1]}`}function De(t){return[...new Set(t)]}export function weakestMultiplier(t){return bt(t.map(i=>{const s=i.stats.pValue??1;return s>0?(i.stats.adjustedPValue??s)/s:1}))}function G(t,i){return Math.min(1,t*i)}function Vt(t,i){const s=t[0],n=s.comparison.family,e=s.variable.kind,l=De(t.flatMap(ie));let r,f;const c=t.map(je);if(c.every(b=>b!==void 0)){const b=new Set;r=[];for(const M of c){const z=I(M.dies);for(let D=0;D<z.length;D++)b.has(z[D])||(b.add(z[D]),r.push(M.dieKeys[D]))}const v=I(ke(s.variable.kind,i));f=M=>b.has(v[M])}else{r=De(t.flatMap(M=>M.highlight.dieKeys??[]));const b=new Set(r),v=Rt(ke(s.variable.kind,i));f=M=>b.has(v[M])}const o=mergedRegionLabel(n,t.map(b=>ie(b)[0]??""),i.ringCount),u=ke(e,i),a=i.regionDies[n],h=I(u),g=[],p=[];for(let b=0;b<u.length;b++)a.has(h[b])&&(f(b)?g:p).push(u[b]);const d=weakestMultiplier(t);let y,w,k,S,$;if(Pt(s)){const b=s.variable.index,v=i.testDefs?.find(x=>x.testNumber===b),M=x=>{let V=0,L=0;for(const q of x){const H=j(q,b);H!==void 0&&(V++,v&&ge(re(H,v))&&L++)}return{valid:V,fail:L}},z=M(g),D=M(p),C=z.valid>0?z.fail/z.valid:0,m=D.valid>0?D.fail/D.valid:0,R=C-m,P=O(z.fail,z.valid,D.fail,D.valid);y={direction:R===0?"different":R>0?"higher":"lower",absoluteDelta:R,relativeDelta:m===0?void 0:R/m,effectSize:R},w={method:"two-proportion-z",pValue:P,sampleSizeLeft:z.valid,sampleSizeRight:D.valid};const B=G(P,d);k=severityForFinding(B,R,rateRelativeEffect({hits:z.fail,n:z.valid,restHits:D.fail,restN:D.valid,passRate:!1})),S=$e(o,T(v,b),R),$=`specLimit:${b}`}else if(e==="test"){const b=s.variable.index,v=x=>j(x,b),M=g.map(v).filter(x=>x!==void 0),z=p.map(v).filter(x=>x!==void 0),{pValue:D,effectSize:C,delta:m}=Nt(M,z),R=ae(z),P=R!==0?m/Math.abs(R):void 0;y={direction:m===0?"different":m>0?"higher":"lower",absoluteDelta:m,relativeDelta:P,effectSize:C},w={method:"welch-z-approx",pValue:D,sampleSizeLeft:M.length,sampleSizeRight:z.length};const B=G(D,d);k=severityForScore(B,C),S=ve(o,s.variable.label,m,P,n,s.variable.unit),$=`test:${b}`}else if(e==="yield"){const b=new Set(i.passBins),v=g.filter(L=>L.hbin!==void 0),M=p.filter(L=>L.hbin!==void 0),z=v.length,D=M.length,C=v.filter(L=>b.has(L.hbin)).length,m=M.filter(L=>b.has(L.hbin)).length,R=z>0?C/z:0,P=D>0?m/D:0,B=R-P,x=O(C,z,m,D);y={direction:B===0?"different":B>0?"higher":"lower",absoluteDelta:B,relativeDelta:P===0?void 0:B/P,effectSize:B},w={method:"two-proportion-z",pValue:x,sampleSizeLeft:z,sampleSizeRight:D};const V=G(x,d);k=severityForFinding(V,B,rateRelativeEffect({hits:C,n:z,restHits:m,restN:D,passRate:!0})),S=be(o,B,n),$="yield"}else if(e==="functionalTest"){const b=s.variable.index,v=i.testDefs?.find(V=>V.testNumber===b);let M=0,z=0,D=0,C=0;for(const V of g){const L=se(V,b,v);L!==void 0&&(z++,L&&M++)}for(const V of p){const L=se(V,b,v);L!==void 0&&(C++,L&&D++)}const m=z>0?M/z:0,R=C>0?D/C:0,P=m-R,B=O(M,z,D,C);y={direction:P===0?"different":P>0?"higher":"lower",absoluteDelta:P,relativeDelta:R===0?void 0:P/R,effectSize:P},w={method:"two-proportion-z",pValue:B,sampleSizeLeft:z,sampleSizeRight:C};const x=G(B,d);k=severityForFinding(x,P,rateRelativeEffect({hits:M,n:z,restHits:D,restN:C,passRate:!0})),S=we(o,T(v,b),P,n),$=`functional:${b}`}else{const b=s.variable.bin,v=x=>e==="softBin"?x.sbin:x.hbin,M=g.filter(x=>v(x)===b).length,z=p.filter(x=>v(x)===b).length,D=M/g.length,C=z/p.length,m=D-C,R=O(M,g.length,z,p.length);y={direction:m===0?"different":m>0?"higher":"lower",absoluteDelta:m,relativeDelta:C===0?void 0:m/C,effectSize:m},w={method:"two-proportion-z",pValue:R,sampleSizeLeft:g.length,sampleSizeRight:p.length};const P=G(R,d);k=severityForFinding(P,m,rateRelativeEffect({hits:M,n:g.length,restHits:z,restN:p.length,passRate:!1}));const B=e==="softBin"?i.sbinDefs:i.hbinDefs;S=Se(o,Ee(b,B,e==="softBin"?"SBin":"HBin"),m,n),$=`${e}:${b}`}w={...w,adjustedPValue:G(w.pValue??1,d)};const N=De(l.map(b=>b.replace(`${n}:`,""))).join("-"),F=e==="hardBin"||e==="softBin"?{kind:"bin",bin:s.variable.bin,regionKeys:l,dieKeys:r}:{kind:"region",regionFamily:n,regionKeys:l,dieKeys:r};return{...s,id:`${$}:${n}:${N}`,severity:k,comparison:{family:n,left:o,right:_(n)},effect:y,stats:w,summary:S,highlight:F,relatedIds:t.map(b=>b.id)}}function Lt(t,i){const s=new Set(["ring","quadrant","sector"]),n=[],e=new Map;for(const r of t){if(!s.has(r.comparison.family)){n.push(r);continue}const f=xt(r),c=e.get(f)??[];c.push(r),e.set(f,c)}const l=[];for(const r of e.values()){if(r.length===1){l.push(r[0]);continue}const f=r[0].comparison.family;for(const c of findContiguousRuns(r,f,i.sectorCount,o=>ie(o)[0]??""))l.push(c.length===1?c[0]:Vt(c,i))}return[...n,...l]}function Kt(t){const i=new Map,s=new Map;for(const e of t){const l=me(e);e.hbin!==void 0&&e.hbin!==null&&(i.get(e.hbin)??i.set(e.hbin,new Set).get(e.hbin)).add(l),e.sbin!==void 0&&e.sbin!==null&&(s.get(e.sbin)??s.set(e.sbin,new Set).get(e.sbin)).add(l)}const n=new Set;for(const[e,l]of i)for(const[r,f]of s){if(l.size!==f.size)continue;let c=!0;for(const o of l)if(!f.has(o)){c=!1;break}c&&n.add(`${e}:${r}`)}return n}function Et(t,i){const s=new Set(i);let n;for(const e of t){const l=Be(e,s);if(l!==void 0&&l){if(e.sbin==null||n!==void 0&&e.sbin!==n)return;n=e.sbin}}if(n!==void 0){for(const e of t)if(e.sbin===n&&Be(e,s)!==!0)return;return n}}function Ot(t){return`${t.comparison.family}\0${t.comparison.left}`}export function redundancyFacts(t,i,s){return{coincident:Kt(t),yieldSoftBin:Et(t,i),passBins:i,sectorCount:s}}const Tt=3/5;function Qe(t){return/^(?:lot-region:)?([^:|]+)/.exec(t.id)?.[1]??t.id}function qt(t){const i=ie(t);if(i.length)return i;const s=/(ring|sector|quadrant):([^:|]+)$/.exec(t.id);return s?s[2].split("-").map(n=>`${s[1]}:${n}`):[]}function Ue(t,i){const s=new Set;for(const n of qt(t)){const e=rt(n,i);if(!e)return;for(const l of e)s.add(l)}return s.size?s:void 0}export function collapseRedundantFindings(t,i){const{coincident:s,yieldSoftBin:n,passBins:e}=i,l=(o,u)=>{o.absorbedIds=[...o.absorbedIds??[],u.id]},r=new Map;for(const o of t){const u=Ot(o);(r.get(u)??r.set(u,[]).get(u)).push(o)}const f=new Set;for(const o of r.values()){for(const a of o)if(!(a.variable.kind!=="hardBin"||a.variable.bin===void 0))for(const h of o){if(h.variable.kind!=="softBin"||h.variable.bin===void 0||f.has(h.id)||!s.has(`${a.variable.bin}:${h.variable.bin}`)||h.effect.direction!==a.effect.direction)continue;l(a,h),f.add(h.id);const g=a.variable.label.replace(/^HBin\s+/,""),p=h.variable.label.replace(/^SBin\s+/,""),d=g===p?`HBin and SBin ${g} (same dies)`:`${a.variable.label} and ${h.variable.label} (same dies)`;a.summary=a.summary.replace(a.variable.label,d),a.variable.label=d;break}const u=o.find(a=>a.variable.kind==="yield");if(u){for(const a of o)if(!(a===u||f.has(a.id)||!(a.variable.kind==="hardBin"&&e.length===1&&a.variable.bin===e[0]||a.variable.kind==="softBin"&&a.variable.bin===n))){l(u,a),f.add(a.id);for(const g of a.absorbedIds??[])u.absorbedIds=[...u.absorbedIds??[],g]}}}const c=new Map;for(const o of t){if(f.has(o.id)||o.comparison.family!=="sector"&&o.comparison.family!=="quadrant")continue;const u=[Qe(o),o.variable.kind,o.variable.bin??"",o.variable.index??"",o.effect.direction].join("\0");(c.get(u)??c.set(u,[]).get(u)).push(o)}for(const o of c.values()){const u=[];for(const a of o.filter(h=>h.comparison.family==="sector")){const h=Ue(a,i.sectorCount);if(h)for(const g of o.filter(p=>p.comparison.family==="quadrant")){const p=Ue(g,i.sectorCount);if(!p)continue;let d=0;for(const w of h)p.has(w)&&d++;const y=h.size+p.size-d;d/y>=Tt-1e-9&&u.push({sector:a,quadrant:g,overlap:d/y})}}u.sort((a,h)=>h.overlap-a.overlap);for(const{sector:a,quadrant:h}of u){if(f.has(a.id)||f.has(h.id))continue;const g=(h.stats.pValue??1)<(a.stats.pValue??1),[p,d]=g?[h,a]:[a,h];l(p,d),f.add(d.id),p.absorbedIds=[...p.absorbedIds??[],...d.absorbedIds??[]]}}}export function analyzeWaferMap(t,i={}){const s=Q,n=J,e=[];Q=e,J=void 0;try{const l=Ht(t,i);return He.set(l,{candidates:e,facts:J}),l}finally{Q=s,J=n}}function Ht(t,i){const{resolved:s,warnings:n}=resolveOptions(i),e=Ge(t),l={...s,passBins:[...mt(e,"analyzeWaferMap")],ringCount:pt(e,"analyzeWaferMap")},r=e.isLotStack,f=e.aggrMethod,c=!r||f==="mode"||f==="countBin"||f==="percent",o=e.dies.filter(m=>wt(m)),u=o.filter(Fe),a=St(l,o.length);a.softPassBins=Me(o,a.passBins).soft;const h=e.dies.filter(m=>de(m)),g=h.filter(Fe),p=it(g,e.wafer,a.ringCount),d=tt(g,e.wafer,a.ringCount),y=nt(g,e.reticleConfig),w=ot(h,!1),k=st(g,e.wafer,a.sectorCount),S=[];c&&S.push(...ee(o,p,a.passBins,a),...ee(o,d,a.passBins,a),...ee(o,y,a.passBins,a),...ee(o,w,a.passBins,a),...ee(o,k,a.passBins,a)),c&&S.push(...E(o,p,"hard",e.hbinDefs,"hardBin",a),...E(o,d,"hard",e.hbinDefs,"hardBin",a),...E(o,y,"hard",e.hbinDefs,"hardBin",a),...E(o,w,"hard",e.hbinDefs,"hardBin",a),...E(o,k,"hard",e.hbinDefs,"hardBin",a));{const m=o.filter(R=>R.sbin!==void 0);S.push(...E(m,p,"soft",e.sbinDefs,"softBin",a),...E(m,d,"soft",e.sbinDefs,"softBin",a),...E(m,y,"soft",e.sbinDefs,"softBin",a),...E(m,w,"soft",e.sbinDefs,"softBin",a),...E(m,k,"soft",e.sbinDefs,"softBin",a))}const $=[...n];let N;if(a.enableTestValueAnalysis){const m=ne(o,p,e.testDefs,a),R=ne(o,d,e.testDefs,a),P=ne(o,y,e.testDefs,a),B=ne(o,w,e.testDefs,a),x=ne(o,k,e.testDefs,a);S.push(...m.findings,...R.findings,...P.findings,...B.findings,...x.findings),m.warning&&$.push(m.warning),N=m.activeTestNumbers,S.push(...Ft(o,[p,d,y,w,k],e.testDefs,a)),S.push(...te(o,p,e.testDefs,a),...te(o,d,e.testDefs,a),...te(o,y,e.testDefs,a),...te(o,w,e.testDefs,a),...te(o,k,e.testDefs,a))}{const m=vt(r,c,e.testDefs);(!r||c||m!==void 0)&&S.push(...ft(u,e.wafer,{...a,isFailingDie:m}))}const F=Lt(S,{eligibleDies:o,softEligibleDies:o.filter(m=>m.sbin!==void 0),testDies:o,passBins:a.passBins,ringCount:a.ringCount,sectorCount:a.sectorCount,regionDies:{ring:new Set(p.flatMap(m=>I(m.dies))),quadrant:new Set(d.flatMap(m=>I(m.dies))),sector:new Set(k.flatMap(m=>I(m.dies)))},hbinDefs:e.hbinDefs,sbinDefs:e.sbinDefs,testDefs:e.testDefs});S.length=0,S.push(...F);let b;if(c){const m=lt(u,e.wafer,{passBins:a.passBins,ringCount:a.ringCount});if(b=m??void 0,m!==null&&m.pattern!=="random"&&m.pattern!=="none"){const R=dt[m.pattern],P=m.confidence==="high"?"unusual":m.confidence==="medium"?"notable":"info",B=m.features,x=K=>`${(K*100).toFixed(0)}%`,V=m.pattern==="edge-ring"||m.pattern==="edge-local"?`${x(B.edgeRdd)} of edge dies failing`:m.pattern==="center"||m.pattern==="donut"?`centroid at ${x(B.centroidDistNorm)} of wafer radius from centre`:m.pattern==="scratch"?`linear score ${B.linearScore.toFixed(2)}, eccentricity ${B.eccentricity.toFixed(2)}`:`${x(B.globalRdd)} of dies failing`,L=new Set(a.passBins),q=o.filter(K=>ut(K,L)===!0),H=claimForPattern([m.pattern],P,S,K=>ie(K).map(A=>Y(A).ring).filter(A=>A!==void 0),a.ringCount);S.push({id:`spatial-pattern:${m.pattern}`,level:"wafer",severity:P,variable:{kind:"spatialPattern",label:R},comparison:{family:"spatial-pattern",left:R,right:"Wafer"},effect:{direction:"different",effectSize:B.globalRdd},stats:{method:"geometry",sampleSizeLeft:q.length,sampleSizeRight:o.length},summary:`Spatial pattern: ${R.toLowerCase()} (${m.confidence} confidence) \u2014 ${V}${m.note?` [${m.note}]`:""}`,highlight:{kind:"dies",dieKeys:q.map(K=>Ne(K))},relatedIds:H.length>0?H:void 0})}}S.sort((m,R)=>{const P=m.stats.adjustedPValue??m.stats.pValue??1,B=R.stats.adjustedPValue??R.stats.pValue??1;return P!==B?P-B:Math.abs(R.effect.absoluteDelta??0)-Math.abs(m.effect.absoluteDelta??0)});const v=$t(e.dies,o.length,e.yield.yieldPercent);r&&(v.isLotStack=!0,f&&(v.aggregationMethod=f));const M=zt(e.dies,e.testDefs);M&&(v.testSpecYield=M);const z=computeFunctionalYield(e.dies,e.testDefs);if(z&&(v.functionalYield=z),b&&(v.spatialPattern=b),N===void 0&&a.computePerTestStats){const m=_e(o,a.testNumbers,e.testDefs);m.warning&&$.push(m.warning),N=m.testNumbers}if(N?.length){const m=kt(e.dies,N,e.testDefs,a.minimumSampleSize);m&&(v.perTestStats=m);const R=Xe([{dies:e.dies}],e.testDefs,N);R&&(v.capability=R)}Object.assign(v,Ze(e.dies,e.testDefs));const D=Je([{dies:e.dies,wafer:e.wafer,passBins:a.passBins,ringCount:a.ringCount}]);D&&(v.regionYield=D),$.length>0&&(v.warnings=$);const C=redundancyFacts(o,a.passBins,a.sectorCount);return collapseRedundantFindings(S,C),Q&&(J=C),{level:"wafer",hasNotableFindings:S.some(m=>m.severity==="notable"||m.severity==="unusual"),findings:S,wafer:e.wafer.metadata??void 0,stats:v}}
|
|
1
|
+
import{normalizeInput as Ze}from"./normalizeInput.js";import{computeCapability as Je,computeTestFlagYield as et,computeRegionYield as tt}from"./summaryFigures.js";import{binPassSets as xe}from"../renderer/binColors.js";import{diePassStatus as pe,isYieldEligibleDie as ge,getDieKey as be,isPositionedDie as Pe,positionKey as ye}from"../core/dies.js";import{dieHasValues as nt,testsPresent as Ce,testValue as j}from"../core/dieTable.js";import{getTestPassStatus as re,isParametricTest as _}from"../renderer/buildWaferMap.js";import{markedTestLabel as T,derivedFields as fe}from"../renderer/testLabel.js";import{buildQuadrantRegions as it,buildReticlePositionRegions as st,buildRingRegions as ot,buildSectorRegions as at,buildTestSiteRegions as rt,sectorCompassNames as Ve,areQuadrantsAdjacent as ft,parseRegionKey as Q,QUADRANT_CYCLE as Se,regionAngleBins as lt}from"./regions.js";import{buildClusterFindings as ct}from"./clusterDetection.js";import{classifyPattern as ut,patternExplains as dt,patternFailVerdict as mt,PATTERN_LABELS as ht}from"./patternClassification.js";import{requirePassBins as pt}from"../core/passBins.js";import{requireRingCount as gt}from"../core/ringCount.js";import{benjaminiHochberg as bt,fisherExact as yt,fiveNumberSummary as St,sampleVariance as we,zPValue as Ee}from"./math.js";import{mean as le,maxOf as wt}from"../core/utils.js";import{classifySpec as ce,isOutOfSpec as ve}from"../renderer/spec.js";const vt={significanceLevel:{min:1e-6,max:1},minimumEffectSize:{min:0,max:1},minimumRelativeEffect:{min:0,max:Number.MAX_SAFE_INTEGER}},Le=[4,8,16];export function resolveOptions(t){const n=Object.fromEntries(Object.entries(t).filter(([,r])=>r!==void 0)),i={...J,...n},s=[],e=[];for(const r of["significanceLevel","minimumEffectSize","minimumRelativeEffect"]){const{min:c,max:o}=vt[r],u=i[r];if(typeof u!="number"||!Number.isFinite(u)){e.push(`${r}=${String(u)} is not a finite number (using ${J[r]})`),i[r]=J[r];continue}const f=Math.min(o,Math.max(c,u));f!==u&&(e.push(`${r}=${u} is outside ${c}\u2013${o} (using ${f})`),i[r]=f)}if(Le.includes(i.sectorCount)||(e.push(`sectorCount=${i.sectorCount} is not one of ${Le.join(", ")} (using ${J.sectorCount})`),i.sectorCount=J.sectorCount),e.length){const r=`analyzeWaferMap: ${e.join("; ")}. The analysis ran with the corrected values.`;console.warn(`[wafermap] ${r}`),s.push({code:"analysis-option-corrected",message:r,severity:"warning"})}const a=["passBins","ringCount"].filter(r=>n[r]!==void 0);if(a.length){const r=`analyzeWaferMap: ${a.join(" and ")} ${a.length>1?"are":"is"} no longer an analysis option and was ignored. Set ${a.length>1?"them":"it"} on buildWaferMap; the analysis used the value the map was built with.`;console.warn(`[wafermap] ${r}`),s.push({code:"analysis-option-corrected",message:r,severity:"warning"})}const l=["enableYieldAnalysis","enableHardBinAnalysis","enableSoftBinAnalysis","enableReticlePositionAnalysis","enableTestSiteAnalysis","enableClusterAnalysis","enableAngularAnalysis","enablePatternClassification"].filter(r=>n[r]!==void 0);if(l.length){const r=`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] ${r}`),s.push({code:"analysis-option-corrected",message:r,severity:"warning"})}return{resolved:i,warnings:s}}const J={significanceLevel:.05,minimumEffectSize:.2,minimumRelativeEffect:1,minimumSampleSize:5,enableTestValueAnalysis:!1,computePerTestStats:!1,sectorCount:8,minimumClusterSize:5};function $t(t,n){const i={...t};return i.minimumClusterSize=Math.max(5,Math.round(n*.003)),i}function kt(t){return ge(t)?t.hbin!==void 0||t.sbin!==void 0||nt(t):!1}function Rt(t,n,i){if(!t||n)return;const s=(i??[]).filter(e=>_(e)&&(e.limitLow!==void 0||e.limitHigh!==void 0));if(s.length!==0)return e=>{for(const a of s)if(ve(ce(j(e,a.testNumber),a)))return!0;return!1}}function Dt(t,n,i){const s=new Set,e=new Set,a=new Set,l=new Map,r=new Map;for(const c of Ce(t))s.add(c);for(const c of t)c.hbin!==void 0&&e.add(c.hbin),c.sbin!==void 0&&a.add(c.sbin),ge(c)&&(c.hbin!==void 0&&l.set(c.hbin,(l.get(c.hbin)??0)+1),c.sbin!==void 0&&r.set(c.sbin,(r.get(c.sbin)??0)+1));return{totalDies:t.length,analyzedDies:n,excludedDies:t.length-n,yieldPercent:i,testsConsidered:[...s].sort((c,o)=>c-o),hardBinsConsidered:[...e].sort((c,o)=>c-o),softBinsConsidered:[...a].sort((c,o)=>c-o),...l.size?{hardBinCounts:Object.fromEntries(l)}:{},...r.size?{softBinCounts:Object.fromEntries(r)}:{}}}function Mt(t,n,i){if(!n?.length)return;const s=n.filter(a=>_(a)&&(a.limitLow!==void 0||a.limitHigh!==void 0));if(!s.length)return;const e=[];for(const a of s){const l=a.testNumber;let r=0,c=0,o=0,u=0;for(const f of t){if(f.partial||f.edgeExcluded)continue;const h=ce(j(f,l),a);if(h!==null){if(u++,h==="failLow")c++;else if(h==="failHigh")o++;else{r++;continue}i?.(l,f)}}e.push({testNumber:l,label:a.name,passDies:r,failLowDies:c,failHighDies:o,totalDies:u,yieldPercent:u>0?r/u*100:null})}return e.length?e:void 0}export function computeFunctionalYield(t,n,i){if(!n?.length)return;const s=n.filter(a=>!_(a));if(!s.length)return;const e=[];for(const a of s){const l=a.testNumber;let r=0,c=0;for(const u of t){if(u.partial||u.edgeExcluded)continue;const f=re(u,l,a);if(f!==void 0){if(f){r++;continue}c++,i?.(l,u)}}const o=r+c;e.push({testNumber:l,label:T(a,l),...fe(a),passDies:r,failDies:c,totalDies:o,passRatePercent:o>0?r/o*100:null})}return e.length?e:void 0}function zt(t,n,i,s){const e=[];for(const a of n){const l=[];for(const f of t){if(f.partial||f.edgeExcluded)continue;const h=j(f,a);h!==void 0&&Number.isFinite(h)&&l.push(h)}if(l.length<s)continue;const r=le(l),c=Math.sqrt(we(l,r)),o=St(Float64Array.from(l)),u=i?.find(f=>f.testNumber===a)?.name??String(a);e.push({testNumber:a,label:u,count:l.length,min:o.min,max:o.max,mean:r,stddev:c,median:o.median,q1:o.q1,q3:o.q3})}return e.length?e:void 0}export function twoProportionZ(t,n,i,s){const e=(t+i)/(n+s),a=e*(1-e)*(1/n+1/s);return!Number.isFinite(a)||a<=0?0:(t/n-i/s)/Math.sqrt(a)}const Bt=5;function q(t,n,i,s){const e=n+s,a=t+i;if((e>0?Math.min(a,e-a)*Math.min(n,s)/e:0)<Bt)return{pValue:yt(t,n-t,i,s-i),method:"fisher-exact"};const r=twoProportionZ(t,n,i,s);return{pValue:r===0?1:Ee(r),method:"two-proportion-z"}}function Ft(t,n,i,s){return q(t,n,i,s).pValue}export function adjustPValues(t){const n=t.filter(s=>s.stats.pValue!==void 0),i=bt(n.map(s=>s.stats.pValue));return n.forEach((s,e)=>{s.stats.adjustedPValue=i[e]}),t}export function rateRelativeEffect(t){const n=(t.passRate?t.n-t.hits:t.hits)/t.n,i=(t.passRate?t.restN-t.restHits:t.restHits)/t.restN;return i===0?n===0?0:1/0:Math.abs(n-i)/i}export function severityForFinding(t,n,i){const s=Math.abs(n),e=i;return t<=.01&&(s>=.3||e>=2.5)?"unusual":t<=.05&&(s>=.2||e>=1.5)?"notable":"info"}export function severityForScore(t,n){return t<=.01&&Math.abs(n)>=.5?"unusual":t<=.05&&Math.abs(n)>=.15?"notable":"info"}function ue(t){return t==="reticle-position"?"other reticle positions":t==="test-site"?"other test sites":"the rest of the map"}function U(t){return t==="reticle-position"?"Other reticle positions":t==="test-site"?"Other test sites":"Rest of map"}function $e(t,n,i){const s=(Math.abs(n)*100).toFixed(1);return`${t} yield is ${s} percentage points ${n>0?"higher":"lower"} than ${ue(i)}`}function ke(t,n){return n==="quadrant"&&!t.startsWith("Quadrant")?`quadrant ${t}`:t}function Ke(t){return/^(Rings|Sectors|Quadrants)\b/.test(t)?"have":"has"}function Re(t,n,i,s){const e=ke(t,s),a=(Math.abs(i)*100).toFixed(1);return`${e} ${Ke(e)} ${n} occurrence ${a} percentage points ${i>0?"higher":"lower"} than ${ue(s)}`}function De(t,n,i,s){const e=ke(t,s),a=(Math.abs(i)*100).toFixed(1);return`${e} ${Ke(e)} ${n} pass rate ${a} percentage points ${i>0?"higher":"lower"} than ${ue(s)}`}function Me(t,n,i,s,e,a){const l=ke(t,e),r=ue(e),c=i>0?"higher":"lower";if(s!==void 0&&Number.isFinite(s)){const u=(Math.abs(s)*100).toFixed(1);return`${l} mean ${n} is ${u}% ${c} than ${r}`}const o=a?` ${a}`:"";return`${l} mean ${n} is ${Math.abs(i).toPrecision(3)}${o} ${c} than ${r}`}function Oe(t,n,i){const s=n?.find(e=>e.bin===t);return s?.name?`${i} ${t} (${s.name})`:`${i} ${t}`}function Nt(t,n){const i=n?.find(s=>s.testNumber===t);return{label:T(i,t),unit:i?.unit,...fe(i)}}const qe=new WeakMap,Te=new WeakMap,Ae=new WeakMap;function ee(t,n){const i=n.highlight.dieKeys;return i&&Ae.set(i,t),n}let G=null,te;const je=new WeakMap;export function candidatesOf(t){return je.get(t)}function He(t,n,i,s){if(!G)return;const e=Ie(t);if(!e)return;const a=t.id.slice(0,t.id.indexOf(":")),l=a==="specLimit"?"limitFail":a,{kind:r,bin:c,index:o}=t.variable;G.push({key:[l,r,c??"",o??"",e.family,e.key].join("|"),source:l,variable:t.variable,label:t.variable.label,comparison:t.comparison,region:e,z:n,delta:t.effect.absoluteDelta??0,effectSize:t.effect.effectSize??0,relativeDelta:t.effect.relativeDelta,rate:i,mean:s})}export function describeRegional(t,n,i){const s=t.comparison.left,e=t.region.family;switch(t.source){case"yield":return $e(s,n,e);case"hardBin":case"softBin":return Re(s,t.label,n,e);case"functional":return De(s,t.label.replace(/ pass rate$/,""),n,e);case"limitFail":return ze(s,t.label,n);case"test":return Me(s,t.label,n,i,e,t.variable.unit)}}function ze(t,n,i){return`${t} limit fail rate for ${n} is ${(Math.abs(i)*100).toFixed(1)} pp ${i>0?"higher":"lower"} than the rest of the wafer`}const H=new WeakMap;function de(t,n){return H.set(t,n),t}function Ie(t){const n=t.highlight.dieKeys;return n?Ae.get(n):void 0}const We=new WeakMap;function I(t){let n=We.get(t);return n||We.set(t,n=t.map(ye)),n}function xt(t){let n=qe.get(t);return n||qe.set(t,n=t.map(be)),n}function me(t,n){let i=Te.get(t);i||Te.set(t,i={members:new Set(t),byFamily:new WeakMap});const s=i.byFamily.get(n);if(s)return s;const{members:e}=i,a=new Map;for(const l of n)a.set(l.key,l.dies.filter(r=>e.has(r)));return i.byFamily.set(n,a),a}function Pt(t,n){adjustPValues(t);for(const e of t){const a=H.get(e);He(e,twoProportionZ(a.hits,a.n,a.restHits,a.restN),a)}const i=t.filter(e=>passesRateGate(e.stats.adjustedPValue??e.stats.pValue??1,e.effect.absoluteDelta??0,rateRelativeEffect(H.get(e)),n)),s=confirmRegionalFindings(i,Ye,(e,a)=>Ct(e,a,n),e=>isRateLoss(H.get(e)),t);return i.filter(e=>s.has(e)).map(e=>({...e,severity:severityForFinding(e.stats.adjustedPValue??e.stats.pValue??1,e.effect.absoluteDelta??0,rateRelativeEffect(H.get(e)))}))}export function passesRateGate(t,n,i,s){return t<=s.significanceLevel&&(Math.abs(n)>=s.minimumEffectSize||i>=s.minimumRelativeEffect)}export function claimForPattern(t,n,i,s,e){const a=[];for(const l of i){const r=l.comparison.family,c=r==="ring"?s(l):[];t.some(o=>dt(o,r,c,e))&&(a.push(l.id),n!=="info"&&(r==="ring"||r==="quadrant"||r==="sector")&&(l.severity="info"))}return a}export function confirmRegionalFindings(t,n,i,s,e=t){const a=new Map;for(const c of t)(a.get(n(c))??a.set(n(c),[]).get(n(c))).push(c);const l=new Map;if(s)for(const c of e)s(c)&&(l.get(n(c))??l.set(n(c),[]).get(n(c))).push(c);const r=new Set;for(const[c,o]of a){const u=l.get(c)??[],f=(d,p)=>s&&!s(d)?i(d,[...new Set([...p,...u])].filter(m=>m!==d)):i(d,p);if(o.length===1){r.add(o[0]);continue}const h=[];let b=[...o];for(;;){let d;for(const p of b){const m=f(p,h);if(m==="baseline-too-small"||!m.passes)continue;const S=s?.(p)??!1;(!d||S&&!d.loss||S===d.loss&&m.pValue<d.p)&&(d={t:p,p:m.pValue,loss:S})}if(!d)break;h.push(d.t),b=b.filter(p=>p!==d.t)}for(;;){let d;for(const p of h){const m=f(p,h.filter(S=>S!==p));m==="baseline-too-small"||m.passes||(!d||m.pValue>d.p)&&(d={t:p,p:m.pValue})}if(!d)break;h.splice(h.indexOf(d.t),1)}for(const d of h)r.add(d)}return r}function Ye(t){return[t.variable.kind,t.variable.bin??"",t.variable.index??"",t.comparison.family].join("\0")}function _e(t){const n=t.stats.pValue??1;return n>0?(t.stats.adjustedPValue??n)/n:1}export function isRateLoss(t){const n=t.hits/t.n-t.restHits/t.restN;return t.passRate?n<0:n>0}function Ct(t,n,i){const s=H.get(t);let{restHits:e,restN:a}=s;for(const o of n){const u=H.get(o);u&&(e-=u.hits,a-=u.n)}if(a<i.minimumSampleSize)return"baseline-too-small";const l=s.hits/s.n-e/a,r=Math.min(1,Ft(s.hits,s.n,e,a)*_e(t)),c=Math.sign(l)===Math.sign(t.effect.absoluteDelta??0)&&passesRateGate(r,l,rateRelativeEffect({...s,restHits:e,restN:a}),i);return{pValue:r,passes:c}}const Be=new WeakMap;export function welchOfSums(t,n,i,s){const e=(a,l,r)=>r>1?Math.max(0,a-l*l/r)/(r-1):0;return welchFromStats(t.n,t.sum/t.n,e(t.sq,t.sum,t.n),n,i/n,e(s,i,n))}function Vt(t,n,i){const s=Be.get(t);let{restN:e,restSum:a,restSq:l}=s;for(const h of n){const b=Be.get(h);b&&(e-=b.n,a-=b.sum,l-=b.sq)}if(e<i.minimumSampleSize)return"baseline-too-small";const{pValue:r,effectSize:c,delta:o}=welchOfSums(s,e,a,l),u=Math.min(1,r*_e(t)),f=Math.sign(o)===Math.sign(t.effect.absoluteDelta??0)&&u<=i.significanceLevel&&Math.abs(c)>=i.minimumEffectSize;return{pValue:u,passes:f}}function ne(t,n,i,s){const e=new Set(i),a=me(t,n),l=new Map,r=new Map;for(const[o,u]of a){let f=0,h=0;for(const b of u)b.hbin!==void 0&&(h++,e.has(b.hbin)&&f++);l.set(o,f),r.set(o,h)}const c=[];for(const o of n){const u=r.get(o.key)??0,f=l.get(o.key)??0;let h=0,b=0;for(const[w,M]of r)w!==o.key&&(h+=M,b+=l.get(w)??0);if(u<s.minimumSampleSize||h<s.minimumSampleSize)continue;const d=f/u,p=b/h,m=d-p,{pValue:S,method:D}=q(f,u,b,h);c.push(de(ee(o,{id:`yield:${o.key}`,level:"wafer",severity:"info",variable:{kind:"yield",label:"Yield"},comparison:{family:o.family,left:o.label,right:U(o.family)},effect:{direction:m===0?"different":m>0?"higher":"lower",absoluteDelta:m,relativeDelta:p===0?void 0:m/p,effectSize:m},stats:{method:D,pValue:S,sampleSizeLeft:u,sampleSizeRight:h},summary:$e(o.label,m,o.family),highlight:{kind:"region",regionFamily:o.family,regionKeys:[o.key],dieKeys:[...o.dieKeys]}}),{hits:f,n:u,restHits:b,restN:h,passRate:!0}))}return c}function O(t,n,i,s,e,a){const l=d=>i==="soft"?d.sbin:d.hbin,r=[...new Set(t.map(l).filter(d=>d!==void 0))].sort((d,p)=>d-p),c=me(t,n),o=new Map,u=new Map;for(const[d,p]of c){const m=new Map;for(const S of p){const D=l(S);D!==void 0&&m.set(D,(m.get(D)??0)+1)}o.set(d,m),u.set(d,p.length)}const f=[],h=e==="hardBin"?"HBin":"SBin",b=i==="hard"?new Set(a.passBins):a.softPassBins??xe(t,a.passBins).soft;for(const d of n){const p=u.get(d.key)??0,m=o.get(d.key);let S=0;const D=new Map;for(const[w,M]of o)if(w!==d.key){S+=u.get(w)??0;for(const[z,N]of M)D.set(z,(D.get(z)??0)+N)}if(!(p<a.minimumSampleSize||S<a.minimumSampleSize))for(const w of r){const M=m.get(w)??0,z=D.get(w)??0,N=M/p,y=z/S,$=N-y,{pValue:v,method:k}=q(M,p,z,S),R=Oe(w,s,h);f.push(de(ee(d,{id:`${e}:${w}:${d.key}`,level:"wafer",severity:"info",variable:{kind:e,bin:w,label:R},comparison:{family:d.family,left:d.label,right:U(d.family)},effect:{direction:$===0?"different":$>0?"higher":"lower",absoluteDelta:$,relativeDelta:y===0?void 0:$/y,effectSize:$},stats:{method:k,pValue:v,sampleSizeLeft:p,sampleSizeRight:S},summary:Re(d.label,R,$,d.family),highlight:{kind:"bin",bin:w,regionKeys:[d.key],dieKeys:[...d.dieKeys]}}),{hits:M,n:p,restHits:z,restN:S,passRate:b.has(w)}))}}return f}function ie(t,n,i,s){const e=(i??[]).filter(u=>!_(u));if(!e.length)return[];const a=e.map(u=>u.testNumber),l=me(t,n),r=new Map,c=new Map;for(const[u,f]of l){const h=new Uint32Array(e.length),b=new Uint32Array(e.length);for(const d of f)for(let p=0;p<e.length;p++){const m=re(d,a[p],e[p]);m!==void 0&&(b[p]++,m&&h[p]++)}r.set(u,h),c.set(u,b)}const o=[];for(const u of n){const f=r.get(u.key),h=c.get(u.key);for(let b=0;b<e.length;b++){let d=0,p=0;for(const[$,v]of c)$!==u.key&&(p+=v[b],d+=r.get($)[b]);const m=h[b],S=f[b];if(m<s.minimumSampleSize||p<s.minimumSampleSize)continue;const D=S/m,w=d/p,M=D-w,{pValue:z,method:N}=q(S,m,d,p),y=a[b];o.push(de(ee(u,{id:`functional:${y}:${u.key}`,level:"wafer",severity:"info",variable:{kind:"functionalTest",index:y,label:`${T(e[b],y)} pass rate`,...fe(e[b])},comparison:{family:u.family,left:u.label,right:U(u.family)},effect:{direction:M===0?"different":M>0?"higher":"lower",absoluteDelta:M,relativeDelta:w===0?void 0:M/w,effectSize:M},stats:{method:N,pValue:z,sampleSizeLeft:m,sampleSizeRight:p},summary:De(u.label,T(e[b],y),M,u.family),highlight:{kind:"region",regionFamily:u.family,regionKeys:[u.key],dieKeys:[...u.dieKeys]}}),{hits:S,n:m,restHits:d,restN:p,passRate:!0}))}}return o}export function welchFromStats(t,n,i,s,e,a){const l=Math.sqrt(i/t+a/s),r=n-e;if(!Number.isFinite(l)||l===0)return{pValue:1,effectSize:0,delta:r,z:0};const c=r/l,o=Math.sqrt(Math.max(0,(i+a)/2)),u=o===0?r:r/o;return{pValue:Ee(c),effectSize:u,delta:r,z:c}}function Et(t,n){const i=le(t),s=le(n);return welchFromStats(t.length,i,we(t,i),n.length,s,we(n,s))}const Qe=250;function Ue(t,n,i){const s=l=>l.filter(r=>_(i?.find(c=>c.testNumber===r)));if(n)return{testNumbers:s(n.slice().sort((l,r)=>l-r))};const e=Ce(t,"values");if(e.length>Qe){const l=`Test-value analysis was skipped: more than ${Qe} tests were found in the die data, so no test findings were computed. Pass testNumbers: [...] to analyse specific tests.`;return console.warn(`[wafermap] analyzeWaferMap: ${l}`),{testNumbers:[],warning:{code:"test-count-capped",message:l,severity:"warning"}}}return{testNumbers:s(e)}}function se(t,n,i,s){const e=Ue(t,s.testNumbers,i);if(e.warning)return{findings:[],warning:e.warning};const a=e.testNumbers,l=new Map;for(let m=0;m<n.length;m++)for(const S of I(n[m].dies))l.set(S,m);const r=n.length,c=[],o=[];for(const m of t){const S=l.get(ye(m));S!==void 0&&(c.push(m),o.push(S))}const u=[],f=new Float64Array(r),h=new Float64Array(r),b=new Float64Array(r);for(const m of a){f.fill(0),h.fill(0),b.fill(0);let S=0,D=0,w=0,M;for(let z=0;z<c.length;z++){const N=c[z],y=j(N,m);if(y===void 0)continue;M===void 0&&(M=y);const $=y-M,v=o[z];f[v]+=1,h[v]+=$,b[v]+=$*$,S+=1,D+=$,w+=$*$}if(M!==void 0)for(let z=0;z<r;z++){const N=f[z],y=S-N;if(N<s.minimumSampleSize||y<s.minimumSampleSize)continue;const $=h[z]/N,k=(D-h[z])/y,R=$+M,C=k+M,P=N>1?Math.max(0,b[z]-N*$*$)/(N-1):0,V=y>1?Math.max(0,w-b[z]-y*k*k)/(y-1):0,{pValue:E,effectSize:L,delta:g,z:B}=welchFromStats(N,R,P,y,C,V),x=n[z],{label:F,unit:K,...W}=Nt(m,i),ae=C!==0?g/Math.abs(C):void 0,Y=ee(x,{id:`test:${m}:${x.key}`,level:"wafer",severity:"info",variable:{kind:"test",index:m,label:F,unit:K,...W},comparison:{family:x.family,left:x.label,right:U(x.family)},effect:{direction:g===0?"different":g>0?"higher":"lower",absoluteDelta:g,relativeDelta:ae,effectSize:L},stats:{method:"welch-z-approx",pValue:E,sampleSizeLeft:N,sampleSizeRight:y},summary:Me(x.label,F,g,ae,x.family,K),highlight:{kind:"region",regionFamily:x.family,regionKeys:[x.key],dieKeys:[...x.dieKeys]}}),Z={n:N,sum:h[z],sq:b[z],restN:y,restSum:D-h[z],restSq:w-b[z],shift:M};Be.set(Y,Z),He(Y,B,void 0,Z),u.push(Y)}}adjustPValues(u);const d=u.filter(m=>{const S=m.stats.adjustedPValue??m.stats.pValue??1,D=Math.abs(m.effect.effectSize??0);return S<=s.significanceLevel&&D>=s.minimumEffectSize}),p=confirmRegionalFindings(d,Ye,(m,S)=>Vt(m,S,s));return{activeTestNumbers:a,findings:d.filter(m=>p.has(m)).map(m=>({...m,severity:severityForScore(m.stats.adjustedPValue??m.stats.pValue??1,m.effect.effectSize??0)}))}}function Lt(t,n,i,s){if(!i?.length)return[];const e=i.filter(l=>_(l)&&(l.limitLow!==void 0||l.limitHigh!==void 0));if(!e.length)return[];const a=[];for(const l of e){const r=l.testNumber;for(const c of n){const o=me(t,c),u=[],f=new Map;let h=0,b=0;for(const[d,p]of o){let m=0,S=0;for(const D of p){const w=j(D,r);w!==void 0&&(m++,ve(ce(w,l))&&S++)}f.set(d,{valid:m,fail:S}),h+=m,b+=S}for(const d of c){const p=f.get(d.key),m=p.valid,S=h-p.valid;if(m<s.minimumSampleSize||S<s.minimumSampleSize)continue;const D=p.fail,w=b-p.fail,M=D/m,z=w/S,N=M-z,{pValue:y,method:$}=q(D,m,w,S);u.push(de(ee(d,{id:`specLimit:${r}:${d.key}`,level:"wafer",severity:"info",variable:{kind:"test",index:r,label:T(l,r),unit:l.unit,...fe(l)},comparison:{family:d.family,left:d.label,right:U(d.family)},effect:{direction:N===0?"different":N>0?"higher":"lower",absoluteDelta:N,relativeDelta:z===0?void 0:N/z,effectSize:N},stats:{method:$,pValue:y,sampleSizeLeft:m,sampleSizeRight:S},summary:ze(d.label,T(l,r),N),highlight:{kind:"region",regionFamily:d.family,regionKeys:[d.key],dieKeys:[...d.dieKeys]}}),{hits:D,n:m,restHits:w,restN:S,passRate:!1}))}a.push(...u)}}return a}function Fe(t,n){return t==="softBin"?n.softEligibleDies:t==="test"?n.testDies:n.eligibleDies}function Kt(t){return t.id.startsWith("specLimit:")}function oe(t){return t.highlight.regionKeys??[]}function Ot(t){const n=t.variable.bin??t.variable.index??"";return`${t.comparison.family}\0${Ge(t)}\0${t.variable.kind}\0${n}\0${t.effect.direction}`}function qt(t,n){const i=Q(t);return i.family==="ring"?i.ring??0:i.family==="sector"?Ve(n).indexOf(i.sector??""):0}export function inQuadrantOrder(t){const n=new Set(t),i=Se.findIndex((e,a)=>n.has(e)&&!n.has(Se[(a+3)%4])),s=i<0?0:i;return Array.from({length:4},(e,a)=>Se[(s+a)%4]).filter(e=>n.has(e))}export function findContiguousRuns(t,n,i,s){if(n==="quadrant"){const c=new Map;for(const h of t){const b=Q(s(h)).quadrant;b&&c.set(b,h)}const o=[...c.keys()],u=new Set,f=[];for(const h of o){if(u.has(h))continue;const b=[],d=[h];for(u.add(h);d.length;){const p=d.pop();b.push(p);for(const m of o)!u.has(m)&&ft(p,m)&&(u.add(m),d.push(m))}f.push(inQuadrantOrder(b).map(p=>c.get(p)))}return f}const e=c=>qt(s(c),i),a=[...t].sort((c,o)=>e(c)-e(o)),l=[];let r=[];for(const c of a){if(r.length===0){r.push(c);continue}const o=e(r[r.length-1]);e(c)-o===1?r.push(c):(l.push(r),r=[c])}if(r.length&&l.push(r),n==="sector"&&l.length>1){const o=Ve(i).length,u=e(l[0][0]),f=e(l[l.length-1][l[l.length-1].length-1]);if(u===0&&f===o-1){const h=l.pop();l[0]=[...h,...l[0]]}}return l}export function mergedRegionLabel(t,n,i){if(t==="ring"){const e=n.map(c=>Q(c).ring).filter(c=>c!==void 0).sort((c,o)=>c-o),a=e[0],l=e[e.length-1];let r="";return a===l&&a===1&&i>1?r=" (core)":a===l&&a===i&&i>1&&(r=" (edge)"),a===l?`Ring ${a}${r}`:`Rings ${a}\u2013${l}`}if(t==="sector"){const e=n.map(a=>Q(a).sector??"");return e.length===1?`Sector ${e[0]}`:`Sectors ${e[0]}\u2013${e[e.length-1]}`}const s=n.map(e=>Q(e).quadrant??"");return s.length===1?s[0]:s.length===2?`Quadrants ${s[0]} & ${s[1]}`:`Quadrants ${s.slice(0,-1).join(", ")} & ${s[s.length-1]}`}function Ne(t){return[...new Set(t)]}export function weakestMultiplier(t){return wt(t.map(n=>{const i=n.stats.pValue??1;return i>0?(n.stats.adjustedPValue??i)/i:1}))}function X(t,n){return Math.min(1,t*n)}function Tt(t,n){const i=t[0],s=i.comparison.family,e=i.variable.kind,a=Ne(t.flatMap(oe));let l,r;const c=t.map(Ie);if(c.every(y=>y!==void 0)){const y=new Set;l=[];for(const v of c){const k=I(v.dies);for(let R=0;R<k.length;R++)y.has(k[R])||(y.add(k[R]),l.push(v.dieKeys[R]))}const $=I(Fe(i.variable.kind,n));r=v=>y.has($[v])}else{l=Ne(t.flatMap(v=>v.highlight.dieKeys??[]));const y=new Set(l),$=xt(Fe(i.variable.kind,n));r=v=>y.has($[v])}const o=mergedRegionLabel(s,t.map(y=>oe(y)[0]??""),n.ringCount),u=Fe(e,n),f=n.regionDies[s],h=I(u),b=[],d=[];for(let y=0;y<u.length;y++)f.has(h[y])&&(r(y)?b:d).push(u[y]);const p=weakestMultiplier(t);let m,S,D,w,M;if(Kt(i)){const y=i.variable.index,$=n.testDefs?.find(B=>B.testNumber===y),v=B=>{let x=0,F=0;for(const K of B){const W=j(K,y);W!==void 0&&(x++,$&&ve(ce(W,$))&&F++)}return{valid:x,fail:F}},k=v(b),R=v(d),C=k.valid>0?k.fail/k.valid:0,P=R.valid>0?R.fail/R.valid:0,V=C-P,{pValue:E,method:L}=q(k.fail,k.valid,R.fail,R.valid);m={direction:V===0?"different":V>0?"higher":"lower",absoluteDelta:V,relativeDelta:P===0?void 0:V/P,effectSize:V},S={method:L,pValue:E,sampleSizeLeft:k.valid,sampleSizeRight:R.valid};const g=X(E,p);D=severityForFinding(g,V,rateRelativeEffect({hits:k.fail,n:k.valid,restHits:R.fail,restN:R.valid,passRate:!1})),w=ze(o,T($,y),V),M=`specLimit:${y}`}else if(e==="test"){const y=i.variable.index,$=g=>j(g,y),v=b.map($).filter(g=>g!==void 0),k=d.map($).filter(g=>g!==void 0),{pValue:R,effectSize:C,delta:P}=Et(v,k),V=le(k),E=V!==0?P/Math.abs(V):void 0;m={direction:P===0?"different":P>0?"higher":"lower",absoluteDelta:P,relativeDelta:E,effectSize:C},S={method:"welch-z-approx",pValue:R,sampleSizeLeft:v.length,sampleSizeRight:k.length};const L=X(R,p);D=severityForScore(L,C),w=Me(o,i.variable.label,P,E,s,i.variable.unit),M=`test:${y}`}else if(e==="yield"){const y=new Set(n.passBins),$=b.filter(F=>F.hbin!==void 0),v=d.filter(F=>F.hbin!==void 0),k=$.length,R=v.length,C=$.filter(F=>y.has(F.hbin)).length,P=v.filter(F=>y.has(F.hbin)).length,V=k>0?C/k:0,E=R>0?P/R:0,L=V-E,{pValue:g,method:B}=q(C,k,P,R);m={direction:L===0?"different":L>0?"higher":"lower",absoluteDelta:L,relativeDelta:E===0?void 0:L/E,effectSize:L},S={method:B,pValue:g,sampleSizeLeft:k,sampleSizeRight:R};const x=X(g,p);D=severityForFinding(x,L,rateRelativeEffect({hits:C,n:k,restHits:P,restN:R,passRate:!0})),w=$e(o,L,s),M="yield"}else if(e==="functionalTest"){const y=i.variable.index,$=n.testDefs?.find(x=>x.testNumber===y);let v=0,k=0,R=0,C=0;for(const x of b){const F=re(x,y,$);F!==void 0&&(k++,F&&v++)}for(const x of d){const F=re(x,y,$);F!==void 0&&(C++,F&&R++)}const P=k>0?v/k:0,V=C>0?R/C:0,E=P-V,{pValue:L,method:g}=q(v,k,R,C);m={direction:E===0?"different":E>0?"higher":"lower",absoluteDelta:E,relativeDelta:V===0?void 0:E/V,effectSize:E},S={method:g,pValue:L,sampleSizeLeft:k,sampleSizeRight:C};const B=X(L,p);D=severityForFinding(B,E,rateRelativeEffect({hits:v,n:k,restHits:R,restN:C,passRate:!0})),w=De(o,T($,y),E,s),M=`functional:${y}`}else{const y=i.variable.bin,$=B=>e==="softBin"?B.sbin:B.hbin,v=b.filter(B=>$(B)===y).length,k=d.filter(B=>$(B)===y).length,R=v/b.length,C=k/d.length,P=R-C,{pValue:V,method:E}=q(v,b.length,k,d.length);m={direction:P===0?"different":P>0?"higher":"lower",absoluteDelta:P,relativeDelta:C===0?void 0:P/C,effectSize:P},S={method:E,pValue:V,sampleSizeLeft:b.length,sampleSizeRight:d.length};const L=X(V,p);D=severityForFinding(L,P,rateRelativeEffect({hits:v,n:b.length,restHits:k,restN:d.length,passRate:!1}));const g=e==="softBin"?n.sbinDefs:n.hbinDefs;w=Re(o,Oe(y,g,e==="softBin"?"SBin":"HBin"),P,s),M=`${e}:${y}`}S={...S,adjustedPValue:X(S.pValue??1,p)};const z=Ne(a.map(y=>y.replace(`${s}:`,""))).join("-"),N=e==="hardBin"||e==="softBin"?{kind:"bin",bin:i.variable.bin,regionKeys:a,dieKeys:l}:{kind:"region",regionFamily:s,regionKeys:a,dieKeys:l};return{...i,id:`${M}:${s}:${z}`,severity:D,comparison:{family:s,left:o,right:U(s)},effect:m,stats:S,summary:w,highlight:N,relatedIds:t.map(y=>y.id)}}function At(t,n){const i=new Set(["ring","quadrant","sector"]),s=[],e=new Map;for(const l of t){if(!i.has(l.comparison.family)){s.push(l);continue}const r=Ot(l),c=e.get(r)??[];c.push(l),e.set(r,c)}const a=[];for(const l of e.values()){if(l.length===1){a.push(l[0]);continue}const r=l[0].comparison.family;for(const c of findContiguousRuns(l,r,n.sectorCount,o=>oe(o)[0]??""))a.push(c.length===1?c[0]:Tt(c,n))}return[...s,...a]}function jt(t){const n=new Map,i=new Map;for(const e of t){const a=ye(e);e.hbin!==void 0&&e.hbin!==null&&(n.get(e.hbin)??n.set(e.hbin,new Set).get(e.hbin)).add(a),e.sbin!==void 0&&e.sbin!==null&&(i.get(e.sbin)??i.set(e.sbin,new Set).get(e.sbin)).add(a)}const s=new Set;for(const[e,a]of n)for(const[l,r]of i){if(a.size!==r.size)continue;let c=!0;for(const o of a)if(!r.has(o)){c=!1;break}c&&s.add(`${e}:${l}`)}return s}function Ht(t,n){const i=new Set(n);let s;for(const e of t){const a=pe(e,i);if(a!==void 0&&a){if(e.sbin==null||s!==void 0&&e.sbin!==s)return;s=e.sbin}}if(s!==void 0){for(const e of t)if(e.sbin===s&&pe(e,i)!==!0)return;return s}}function It(t){return`${t.comparison.family}\0${t.comparison.left}`}export function redundancyFacts(t,n,i){return{coincident:jt(t),yieldSoftBin:Ht(t,n),passBins:n,sectorCount:i}}const Wt=3/5;function Ge(t){return/^(?:lot-region:)?([^:|]+)/.exec(t.id)?.[1]??t.id}function Yt(t){const n=oe(t);if(n.length)return n;const i=/(ring|sector|quadrant):([^:|]+)$/.exec(t.id);return i?i[2].split("-").map(s=>`${i[1]}:${s}`):[]}function Xe(t,n){const i=new Set;for(const s of Yt(t)){const e=lt(s,n);if(!e)return;for(const a of e)i.add(a)}return i.size?i:void 0}export function collapseRedundantFindings(t,n){const{coincident:i,yieldSoftBin:s,passBins:e}=n,a=(o,u)=>{o.absorbedIds=[...o.absorbedIds??[],u.id]},l=new Map;for(const o of t){const u=It(o);(l.get(u)??l.set(u,[]).get(u)).push(o)}const r=new Set;for(const o of l.values()){for(const f of o)if(!(f.variable.kind!=="hardBin"||f.variable.bin===void 0))for(const h of o){if(h.variable.kind!=="softBin"||h.variable.bin===void 0||r.has(h.id)||!i.has(`${f.variable.bin}:${h.variable.bin}`)||h.effect.direction!==f.effect.direction)continue;a(f,h),r.add(h.id);const b=f.variable.label.replace(/^HBin\s+/,""),d=h.variable.label.replace(/^SBin\s+/,""),p=b===d?`HBin and SBin ${b} (same dies)`:`${f.variable.label} and ${h.variable.label} (same dies)`;f.summary=f.summary.replace(f.variable.label,p),f.variable.label=p;break}const u=o.find(f=>f.variable.kind==="yield");if(u){for(const f of o)if(!(f===u||r.has(f.id)||!(f.variable.kind==="hardBin"&&e.length===1&&f.variable.bin===e[0]||f.variable.kind==="softBin"&&f.variable.bin===s))){a(u,f),r.add(f.id);for(const b of f.absorbedIds??[])u.absorbedIds=[...u.absorbedIds??[],b]}}}const c=new Map;for(const o of t){if(r.has(o.id)||o.comparison.family!=="sector"&&o.comparison.family!=="quadrant")continue;const u=[Ge(o),o.variable.kind,o.variable.bin??"",o.variable.index??"",o.effect.direction].join("\0");(c.get(u)??c.set(u,[]).get(u)).push(o)}for(const o of c.values()){const u=[];for(const f of o.filter(h=>h.comparison.family==="sector")){const h=Xe(f,n.sectorCount);if(h)for(const b of o.filter(d=>d.comparison.family==="quadrant")){const d=Xe(b,n.sectorCount);if(!d)continue;let p=0;for(const S of h)d.has(S)&&p++;const m=h.size+d.size-p;p/m>=Wt-1e-9&&u.push({sector:f,quadrant:b,overlap:p/m})}}u.sort((f,h)=>h.overlap-f.overlap);for(const{sector:f,quadrant:h}of u){if(r.has(f.id)||r.has(h.id))continue;const b=(h.stats.pValue??1)<(f.stats.pValue??1),[d,p]=b?[h,f]:[f,h];a(d,p),r.add(p.id),d.absorbedIds=[...d.absorbedIds??[],...p.absorbedIds??[]]}}}export function analyzeWaferMap(t,n={}){const i=G,s=te,e=[];G=e,te=void 0;try{const a=_t(t,n);return je.set(a,{candidates:e,facts:te}),a}finally{G=i,te=s}}function _t(t,n){const{resolved:i,warnings:s}=resolveOptions(n),e=Ze(t),a={...i,passBins:[...pt(e,"analyzeWaferMap")],ringCount:gt(e,"analyzeWaferMap")},l=e.isLotStack,r=e.aggrMethod,c=!l||r==="mode"||r==="countBin"||r==="percent",o=e.dies.filter(g=>kt(g)),u=o.filter(Pe),f=$t(a,o.length);f.softPassBins=xe(o,f.passBins).soft;const h=e.dies.filter(g=>ge(g)),b=h.filter(Pe),d=ot(b,e.wafer,f.ringCount),p=it(b,e.wafer,f.ringCount),m=st(b,e.reticleConfig),S=rt(h,!1),D=at(b,e.wafer,f.sectorCount),w=[],M=[];c&&M.push(...ne(o,d,f.passBins,f),...ne(o,p,f.passBins,f),...ne(o,m,f.passBins,f),...ne(o,S,f.passBins,f),...ne(o,D,f.passBins,f)),c&&M.push(...O(o,d,"hard",e.hbinDefs,"hardBin",f),...O(o,p,"hard",e.hbinDefs,"hardBin",f),...O(o,m,"hard",e.hbinDefs,"hardBin",f),...O(o,S,"hard",e.hbinDefs,"hardBin",f),...O(o,D,"hard",e.hbinDefs,"hardBin",f));{const g=o.filter(B=>B.sbin!==void 0);M.push(...O(g,d,"soft",e.sbinDefs,"softBin",f),...O(g,p,"soft",e.sbinDefs,"softBin",f),...O(g,m,"soft",e.sbinDefs,"softBin",f),...O(g,S,"soft",e.sbinDefs,"softBin",f),...O(g,D,"soft",e.sbinDefs,"softBin",f))}const z=[...s];let N;if(f.enableTestValueAnalysis){const g=se(o,d,e.testDefs,f),B=se(o,p,e.testDefs,f),x=se(o,m,e.testDefs,f),F=se(o,S,e.testDefs,f),K=se(o,D,e.testDefs,f);w.push(...g.findings,...B.findings,...x.findings,...F.findings,...K.findings),g.warning&&z.push(g.warning),N=g.activeTestNumbers,M.push(...Lt(o,[d,p,m,S,D],e.testDefs,f)),M.push(...ie(o,d,e.testDefs,f),...ie(o,p,e.testDefs,f),...ie(o,m,e.testDefs,f),...ie(o,S,e.testDefs,f),...ie(o,D,e.testDefs,f))}w.push(...Pt(M,f));{const g=Rt(l,c,e.testDefs);(!l||c||g!==void 0)&&w.push(...ct(u,e.wafer,{...f,isFailingDie:g}))}const y=At(w,{eligibleDies:o,softEligibleDies:o.filter(g=>g.sbin!==void 0),testDies:o,passBins:f.passBins,ringCount:f.ringCount,sectorCount:f.sectorCount,regionDies:{ring:new Set(d.flatMap(g=>I(g.dies))),quadrant:new Set(p.flatMap(g=>I(g.dies))),sector:new Set(D.flatMap(g=>I(g.dies)))},hbinDefs:e.hbinDefs,sbinDefs:e.sbinDefs,testDefs:e.testDefs});w.length=0,w.push(...y);let $;if(c){const g=ut(u,e.wafer,{passBins:f.passBins,ringCount:f.ringCount});if($=g??void 0,g!==null&&g.pattern!=="random"&&g.pattern!=="none"){const B=ht[g.pattern],x=g.confidence==="high"?"unusual":g.confidence==="medium"?"notable":"info",F=g.features,K=A=>`${(A*100).toFixed(0)}%`,W=g.pattern==="edge-ring"||g.pattern==="edge-local"?`${K(F.edgeRdd)} of edge dies failing`:g.pattern==="center"?`centroid at ${K(F.centroidDistNorm)} of wafer radius from centre`:g.pattern==="donut"?`${K(Math.max(F.radialFailRates[1],F.radialFailRates[2]))} of dies failing at mid-radius, ${K(F.radialFailRates[0])} at the centre`:g.pattern==="scratch"?`a line ${Math.round(F.lineLength)} dies long and about ${Math.max(1,Math.round(F.lineWidth*2))} wide`:`${K(F.globalRdd)} of dies failing`,ae=new Set(f.passBins),Y=o.filter(A=>mt(A,ae)===!0),Z=claimForPattern([g.pattern],x,w,A=>oe(A).map(he=>Q(he).ring).filter(he=>he!==void 0),f.ringCount);w.push({id:`spatial-pattern:${g.pattern}`,level:"wafer",severity:x,variable:{kind:"spatialPattern",label:B},comparison:{family:"spatial-pattern",left:B,right:"Wafer"},effect:{direction:"different",effectSize:F.globalRdd},stats:{method:"geometry",sampleSizeLeft:Y.length,sampleSizeRight:o.length},summary:`Spatial pattern: ${B.toLowerCase()} (${g.confidence} confidence) \u2014 ${W}${g.note?` [${g.note}]`:""}`,highlight:{kind:"dies",dieKeys:Y.map(A=>be(A))},relatedIds:Z.length>0?Z:void 0})}}w.sort((g,B)=>{const x=g.stats.adjustedPValue??g.stats.pValue??1,F=B.stats.adjustedPValue??B.stats.pValue??1;return x!==F?x-F:Math.abs(B.effect.absoluteDelta??0)-Math.abs(g.effect.absoluteDelta??0)});const v=Dt(e.dies,o.length,e.yield.yieldPercent);l&&(v.isLotStack=!0,r&&(v.aggregationMethod=r));const k=new Set(a.passBins),R={},C=(g,B)=>{const x=R[g]??={dieKeys:[],lostDies:0};x.dieKeys.push(be(B)),pe(B,k)!==!0&&x.lostDies++},P=Mt(e.dies,e.testDefs,C);P&&(v.testSpecYield=P);const V=computeFunctionalYield(e.dies,e.testDefs,C);if(V&&(v.functionalYield=V),Object.keys(R).length&&(v.testFailures=R),$&&(v.spatialPattern=$),N===void 0&&f.computePerTestStats){const g=Ue(o,f.testNumbers,e.testDefs);g.warning&&z.push(g.warning),N=g.testNumbers}if(N?.length){const g=zt(e.dies,N,e.testDefs,f.minimumSampleSize);g&&(v.perTestStats=g);const B=Je([{dies:e.dies}],e.testDefs,N);B&&(v.capability=B)}Object.assign(v,et(e.dies,e.testDefs));const E=tt([{dies:e.dies,wafer:e.wafer,passBins:f.passBins,ringCount:f.ringCount}]);E&&(v.regionYield=E),z.length>0&&(v.warnings=z);const L=redundancyFacts(o,f.passBins,f.sectorCount);return collapseRedundantFindings(w,L),G&&(te=L),{level:"wafer",hasNotableFindings:w.some(g=>g.severity==="notable"||g.severity==="unusual"),findings:w,wafer:e.wafer.metadata??void 0,stats:v}}
|
|
@@ -29,6 +29,11 @@ export interface CapabilityDatum {
|
|
|
29
29
|
/** Pooled within-wafer sample stddev. NaN if no item contributed ≥2 values. */
|
|
30
30
|
stdWithin: number;
|
|
31
31
|
n: number;
|
|
32
|
+
/** Dies whose value for this test the value filter excluded (not in `n`), and the limit set they were outside of. */
|
|
33
|
+
excluded?: {
|
|
34
|
+
count: number;
|
|
35
|
+
limitSet: 'validity' | 'spec' | 'test';
|
|
36
|
+
};
|
|
32
37
|
/** Cp/Cpk use `stdWithin`; null when stdWithin is NaN or 0, or when `hasSpec` is false. */
|
|
33
38
|
cp: number | null;
|
|
34
39
|
cpk: number | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isYieldEligibleDie as
|
|
1
|
+
import{isYieldEligibleDie as v}from"../core/dies.js";import{excludedCounts as H,testValuesReader as E}from"../core/dieTable.js";import{drain as C}from"../core/utils.js";import{isParametricTest as O}from"../renderer/buildWaferMap.js";import{countOutOfSpec as P,hasSpecLimits as V}from"../renderer/spec.js";import{testLabel as _,derivedFields as I}from"../renderer/testLabel.js";import{describeValues as z}from"./math.js";const R=25e4;function j(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 A(n){const s=new Map,e=new Map;for(const l of n){const t=l.testNumber;if(t===void 0||!O(l))continue;e.set(t,l);const i=j(l);i&&s.set(t,i)}return{defByTestNumber:e,specByTest:s}}function*$(n,s,e){const l=[...s.keys()],t=l.length,i=new Float64Array(t),r=new Float64Array(t),o=new Float64Array(t),f=new Float64Array(t),p=new Float64Array(t),S=new Float64Array(t),y=new Float64Array(t),d=new Float64Array(t);let x=0;if(e)for(const m of n)x+=m.dies?.length??0;const g=e?Array.from({length:t},()=>new Float64Array(x)):[],u=E(l),b=new Float64Array(t),M=Math.max(500,Math.floor(R/Math.max(1,t)));let h=0;for(const m of n){S.fill(0),y.fill(0),d.fill(0);for(const c of m.dies??[])if(++h>=M&&(h=0,yield),!!v(c)){u(c,b);for(let a=0;a<t;a++){const w=b[a];Number.isFinite(w)&&(i[a]++,r[a]+=w,o[a]+=w*w,S[a]++,y[a]+=w,d[a]+=w*w,e&&(g[a][i[a]-1]=w))}}for(let c=0;c<t;c++){const a=S[c];if(a<2)continue;const w=y[c]/a,k=(d[c]-a*w*w)/(a-1);f[c]+=(a-1)*Math.max(0,k),p[c]+=a-1}}const N=new Map;for(let m=0;m<t;m++){if(i[m]===0)continue;const c=l[m];N.set(c,{n:i[m],sum:r[m],sumSq:o[m],withinNumerator:f[m],withinDenominator:p[m]}),e&&e.set(c,g[m].subarray(0,i[m]))}return N}function W(n,s,e){return C($(n,s,e))}function L(n,s,e,l){const{n:t,sum:i,sumSq:r,withinNumerator:o,withinDenominator:f}=l,p=i/t,S=t>=2?Math.max(0,(r-t*p*p)/(t-1)):0,y=Math.sqrt(S),d=f>0?Math.sqrt(o/f):NaN;let x=null,g=null,u=null,b=null;if(e){const{lsl:M,usl:h}=e,N=h-M;u=y>0?N/(6*y):null,b=y>0?Math.min((h-p)/(3*y),(p-M)/(3*y)):null,x=Number.isFinite(d)&&d>0?N/(6*d):null,g=Number.isFinite(d)&&d>0?Math.min((h-p)/(3*d),(p-M)/(3*d)):null}return{testNumber:n,label:_(s,n),unit:s.unit,...I(s),hasSpec:e!==void 0,lsl:e?.lsl,usl:e?.usl,...e?{limitBasis:e.basis}:{},mean:p,stdOverall:y,stdWithin:d,n:t,cp:x,cpk:g,pp:u,ppk:b}}function q(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:e.stdOverall-s.stdOverall)}export function buildCapabilityData(n,s){return C(buildCapabilityDataSteps(n,s))}export function*buildCapabilityDataSteps(n,s){return(yield*pooledTestStatsSteps(n,s)).capability.slice()}const F=new Map,Y=4,B=new WeakMap;let K=1;function U(n,s){const e=[];for(const t of n){const i=t.dies;if(!i){e.push(0);continue}let r=B.get(i);r===void 0&&(r=K++,B.set(i,r)),e.push(r)}const l=s.filter(t=>t.testNumber!==void 0&&O(t)).map(t=>`${t.testNumber}${t.testType??"P"}${t.limitLow??""}${t.limitHigh??""}${t.specLow??""}${t.specHigh??""}${t.name??""}${t.unit??""}`);return`${e.join(",")}${l.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=U(n,s),l=F.get(e);if(l)return F.delete(e),F.set(e,l),l;let t=T.get(e);t||(t={work:G(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*G(n,s,e){const l={stats:new Map,specTally:new Map,capability:[]},{defByTestNumber:t,specByTest:i}=A(s);if(t.size===0)return l;const r=new Map,o=yield*$(n,t,r),f=new Map,p=new Map,S=[],y=new Map;let d;for(const g of n){const u=H((g.dies??[]).filter(b=>v(b)));if(u){d??=u.by;for(const[b,M]of u.counts)y.set(b,(y.get(b)??0)+M)}}for(const g of s){yield;const u=g.testNumber;if(u===void 0)continue;const b=o.get(u);if(!b||b.n===0||!t.has(u))continue;const M=r.get(u);r.delete(u),V(g)&&p.set(u,{n:M.length,fail:P(M,g)});const h=z(M);f.set(u,h);const N=i.get(u),m=L(u,g,N,b);let c;if(N){const w=N.usl-N.lsl;c=k=>(k-N.lsl)/w}else{const w=h.min,k=h.max-w;c=k>0?D=>(D-w)/k:()=>.5}const a=y.get(u);S.push({...m,...a&&d?{excluded:{count:a,limitSet:d}}:{},min:c(h.min),q1:c(h.q1),median:c(h.median),q3:c(h.q3),max:c(h.max)})}const x={stats:f,specTally:p,capability:q(S)};return F.set(e,x),F.size>Y&&F.delete(F.keys().next().value),x}export function buildCapabilityFigures(n,s){const{defByTestNumber:e,specByTest:l}=A(s);if(e.size===0)return[];const t=W(n,e,null),i=[];for(const[r,o]of t)o.n!==0&&i.push(L(r,e.get(r),l.get(r),o));return q(i)}export function poolCapabilityFigures(n,s){const{defByTestNumber:e,specByTest:l}=A(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 p=o.stdOverall*o.stdOverall;f.n+=o.n,f.sum+=o.n*o.mean,f.sumSq+=(o.n-1)*p+o.n*o.mean*o.mean,o.n>=2&&(f.withinNumerator+=(o.n-1)*p,f.withinDenominator+=o.n-1)}const i=[];for(const[r,o]of t)i.push(L(r,e.get(r),l.get(r),o));return q(i)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{seededRandom as nt}from"./math.js";import{ringOf as it}from"../core/classify.js";import{compassBucket as st,sectorCompassNames as ot}from"./regions.js";import{getDieKey as rt,gridKey as L}from"../core/dies.js";import{findConnectedComponents as at,LargestComponentSizer as ct}from"./connectedComponents.js";function lt(t,e){return ot(16)[st(t,e,16)]}function ut(t){if(t.length<2)return 0;const e=[...t].sort((i,s)=>i-s);let n=e[0]+2*Math.PI-e[e.length-1];for(let i=1;i<e.length;i++)n=Math.max(n,e[i]-e[i-1]);return 2*Math.PI-n}function ft(t,e,n,i){const s=i!==void 0?Math.abs(i):0;return t<=.01&&(e>=.25||s>=2||n>=.1)?"unusual":t<=.05&&(e>=.15||s>=1||n>=.03)?"notable":"info"}const j=99,G=10;class ht{sizer;failCount;maxima=[];random;order;failing;constructor(e,n,i,s){this.sizer=e,this.failCount=i,this.random=nt(s),this.order=new Int32Array(n);for(let u=0;u<n;u++)this.order[u]=u;this.failing=new Uint8Array(n)}at(e){const{order:n,failing:i,failCount:s,random:u}=this,$=n.length;for(;this.maxima.length<=e;){for(let r=0;r<s;r++){const d=r+Math.floor(u()*($-r)),g=n[r];n[r]=n[d],n[d]=g,i[n[r]]=1}this.maxima.push(this.sizer.largest(i));for(let r=0;r<s;r++)i[n[r]]=0}return this.maxima[e]}pValue(e){let n=0;for(let i=0;i<j;i++)if(this.at(i)>=e&&++n===G)return G/(i+1);return(1+n)/(1+j)}}function mt(t){let e=0,n=0;for(let i=0;i<t.length;i++){let s=Math.imul(t[i].x|0,2654435761)^Math.imul(t[i].y|0,2246822507);s=Math.imul(s^s>>>16,2146121005),s=Math.imul(s^s>>>15,2221713035),e=e+(s^s>>>16)|0,n=n+Math.imul(s,668265263)+374761393|0}return`${t.length}:${e>>>0}:${n>>>0}`}function pt(t,e){return t<=20?t:Math.min(e,Math.ceil(20*1.05**Math.ceil(Math.log(t/20)/Math.log(1.05))))}const dt=new Map,gt=new Map;function _(t,e,n,i){let s=t.get(e);return s===void 0&&(s=i(),t.set(e,s),t.size>n&&t.delete(t.keys().next().value)),s}function yt(t,e,n){const i=t.length,s=mt(t),u=pt(e,i),$=_(gt,`${s}:${u}`,16,()=>{const r=_(dt,s,4,()=>new ct([...t].sort((E,v)=>E.y-v.y||E.x-v.x))),[,d,g]=s.split(":").map(Number);return new ht(r,i,u,(d^Math.imul(g,739982445)^Math.imul(u+1,2246822507))>>>0)});return n.map(r=>$.pValue(r))}export function buildClusterFindings(t,e,n){const{passBins:i,significanceLevel:s,minimumEffectSize:u,minimumRelativeEffect:$,minimumSampleSize:r,minimumClusterSize:d,ringCount:g}=n,E=new Set(i);if(t.length<r)return[];const v=o=>{const a=o.hbin??o.sbin;return a===void 0||!E.has(a)},Z=n.isFailingDie??v,P=t.filter(Z),z=P.length/t.length,D=t[0],V=D?D.width:10,A=D?D.height:10,R=Math.max(V,A)*1.5,X=new Map;for(const o of t)X.set(L(o.x,o.y),o);const K=Math.ceil(R/V),N=Math.ceil(R/A),q=at(P),O=[],C=[],Y=e.center.x,k=e.center.y,H=e.radius;for(const o of q){if(o.length<d)continue;const a=new Set(o.map(f=>L(f.x,f.y)));for(const f of o)for(let h=-N;h<=N;h++)for(let M=-K;M<=K;M++){const w=L(f.x+M,f.y+h);if(a.has(w))continue;const F=X.get(w);F&&Math.hypot(F.physX-f.physX,F.physY-f.physY)<=R&&a.add(w)}const l=[...a].map(f=>X.get(f)).filter(Boolean),m=o.length,y=l.length;if(y<r)continue;const x=m/y,b=x-z,p=z>0?b/z:void 0;(b>=u||p!==void 0&&p>=$)&&C.push({component:o,k:m,clusterRate:x,delta:b,relativeDelta:p})}if(!C.length)return[];const J=yt(t,P.length,C.map(o=>o.k));for(let o=0;o<C.length;o++){const{component:a,k:l,clusterRate:m,delta:y,relativeDelta:x}=C[o],b=J[o],p=b;if(p>s)continue;const B=a.reduce((c,S)=>c+S.physX,0)/l,f=a.reduce((c,S)=>c+S.physY,0)/l;let h=a[0],M=1/0;for(const c of a){const S=Math.hypot(c.physX-B,c.physY-f);S<M&&(M=S,h=c)}const w=ut(a.map(c=>Math.atan2(c.physY-k,c.physX-Y)))*180/Math.PI,I=a.filter(c=>it(c.physX-Y,c.physY-k,H,g)===g).length>l/2&&w<120,T=I?"edge-arc":"cluster",U=lt(B-Y,f-k),Q=I?`Edge arc ~${U}`:`Cluster at (${h.x}, ${h.y})`,W=l/t.length,tt=ft(p,y,W,x),et=a.map(c=>rt(c));O.push({id:`${T}:${h.x},${h.y}`,level:"wafer",severity:tt,variable:{kind:"yield",label:"Yield"},comparison:{family:T,left:Q,right:"Rest of wafer"},effect:{direction:"lower",absoluteDelta:-y,relativeDelta:x!==void 0?-x:void 0,effectSize:y},stats:{method:"permutation",pValue:b,adjustedPValue:p,sampleSizeLeft:l,sampleSizeRight:t.length-l},summary:I?`Edge arc near ${U}: ${l} contiguous failing dies (${(m*100).toFixed(0)}% vs ${(z*100).toFixed(0)}% background)`:`Failure cluster at (${h.x}, ${h.y}): ${l} contiguous failing dies (${(m*100).toFixed(0)}% vs ${(z*100).toFixed(0)}% background)`,highlight:{kind:"dies",dieKeys:et}})}return O.sort((o,a)=>{const l=o.stats.pValue??1,m=a.stats.pValue??1;return l!==m?l-m:Math.abs(a.effect.effectSize??0)-Math.abs(o.effect.effectSize??0)})}
|
|
@@ -11,4 +11,23 @@ import type { PositionedDie } from '../core/dies.js';
|
|
|
11
11
|
* case this is for, and it is also exactly the case that blows a call stack.
|
|
12
12
|
*/
|
|
13
13
|
export declare function findConnectedComponents(failing: readonly PositionedDie[]): PositionedDie[][];
|
|
14
|
+
/**
|
|
15
|
+
* The size of the largest 8-connected group of failing dies, for many failure sets over one die layout:
|
|
16
|
+
* a permutation null sizes the largest group on every shuffle. The neighbours of each die are found once
|
|
17
|
+
* (by the same steps as {@link findConnectedComponents}) and held as index lists, and
|
|
18
|
+
* each call is a flood fill over typed arrays, with no maps, sets or allocation.
|
|
19
|
+
*/
|
|
20
|
+
export declare class LargestComponentSizer {
|
|
21
|
+
private readonly start;
|
|
22
|
+
private readonly list;
|
|
23
|
+
private readonly seen;
|
|
24
|
+
private readonly stack;
|
|
25
|
+
private stamp;
|
|
26
|
+
constructor(dies: readonly {
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
}[]);
|
|
30
|
+
/** The largest group among the dies with `failing[i]` set (indices as given to the constructor). */
|
|
31
|
+
largest(failing: Uint8Array): number;
|
|
32
|
+
}
|
|
14
33
|
//# sourceMappingURL=connectedComponents.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{gridKey as
|
|
1
|
+
import{gridKey as p}from"../core/dies.js";const d=[-1,0,1,-1,1,-1,0,1],m=[-1,-1,-1,0,0,1,1,1];export function findConnectedComponents(l){if(l.length===0)return[];const o=new Map;for(const n of l)o.set(p(n.x,n.y),n);const e=new Set,a=[];for(const n of l){const c=p(n.x,n.y);if(e.has(c))continue;const t=[],r=[n];for(e.add(c);r.length>0;){const s=r.pop();t.push(s);for(let i=0;i<8;i++){const h=p(s.x+d[i],s.y+m[i]);if(e.has(h))continue;const f=o.get(h);f&&(e.add(h),r.push(f))}}a.push(t)}return a}export class LargestComponentSizer{start;list;seen;stack;stamp=0;constructor(o){const e=o.length,a=new Map;for(let t=0;t<e;t++)a.set(p(o[t].x,o[t].y),t);const n=new Int32Array(e+1),c=[];for(let t=0;t<e;t++){n[t]=c.length;for(let r=0;r<8;r++){const s=a.get(p(o[t].x+d[r],o[t].y+m[r]));s!==void 0&&c.push(s)}}n[e]=c.length,this.start=n,this.list=Int32Array.from(c),this.seen=new Int32Array(e),this.stack=new Int32Array(e)}largest(o){const{start:e,list:a,seen:n,stack:c}=this,t=++this.stamp;let r=0;for(let s=0;s<o.length;s++){if(!o[s]||n[s]===t)continue;n[s]=t;let i=0;c[i++]=s;let h=0;for(;i>0;){const f=c[--i];h++;for(let y=e[f];y<e[f+1];y++){const u=a[y];o[u]&&n[u]!==t&&(n[u]=t,c[i++]=u)}}h>r&&(r=h)}return r}}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Die } from '../core/dies.js';
|
|
2
|
+
import type { Wafer, WaferReticle } from '../core/wafer.js';
|
|
3
|
+
export declare const DIE_REGION_KEYS: readonly ["ring", "quadrant", "reticleCell", "reticleShot"];
|
|
4
|
+
export type DieRegionKey = (typeof DIE_REGION_KEYS)[number];
|
|
5
|
+
/** What a region needs to place a die. */
|
|
6
|
+
export interface RegionContext {
|
|
7
|
+
/** The wafer's geometry. Its `reticle`, when the host gave a stepper field, is what makes the reticle regions exist. */
|
|
8
|
+
wafer?: Wafer;
|
|
9
|
+
ringCount: number;
|
|
10
|
+
/** A stepper field to use instead of `wafer.reticle`, for a caller that was handed the config on its own. */
|
|
11
|
+
reticle?: WaferReticle;
|
|
12
|
+
}
|
|
13
|
+
/** The families findings and region yield group dies by. Reticle shot has none: no finding is made per shot. */
|
|
14
|
+
export type RegionFamily = 'ring' | 'quadrant' | 'reticle-position';
|
|
15
|
+
/** How findings and region yield group dies into this region: the key a finding carries, its words, and the order of the rows. */
|
|
16
|
+
export interface RegionGrouping {
|
|
17
|
+
family: RegionFamily;
|
|
18
|
+
place(die: Die, ctx: RegionContext): {
|
|
19
|
+
key: string;
|
|
20
|
+
label: string;
|
|
21
|
+
} | undefined;
|
|
22
|
+
/** Order of two region keys. */
|
|
23
|
+
order(a: string, b: string): number;
|
|
24
|
+
}
|
|
25
|
+
export interface DieRegionDef {
|
|
26
|
+
key: DieRegionKey;
|
|
27
|
+
/** The field's name wherever it is listed. */
|
|
28
|
+
label: string;
|
|
29
|
+
/** Whether this population can place a die in the region at all. */
|
|
30
|
+
available(ctx: RegionContext, anyPositioned: boolean): boolean;
|
|
31
|
+
/** The die's value as text on screen and in a chart (`Ring 2`, `NE`, `Reticle cell (1, 3)`), or undefined when it has none. */
|
|
32
|
+
valueOf(die: Die, ctx: RegionContext): string | undefined;
|
|
33
|
+
/** The same value as a spreadsheet wants it: a bare number or a short code. Defaults to `valueOf`. */
|
|
34
|
+
rawOf?(die: Die, ctx: RegionContext): string | undefined;
|
|
35
|
+
/** Present when findings and region yield group dies by this region. */
|
|
36
|
+
grouping?: RegionGrouping;
|
|
37
|
+
}
|
|
38
|
+
export declare const DIE_REGIONS: Record<DieRegionKey, DieRegionDef>;
|
|
39
|
+
/** The regions this population offers, in the order they are listed. */
|
|
40
|
+
export declare function availableRegions(ctx: RegionContext, anyPositioned: boolean): DieRegionDef[];
|
|
41
|
+
export declare const isDieRegionKey: (k: string) => k is DieRegionKey;
|
|
42
|
+
//# sourceMappingURL=dieRegions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{classifyDie as c}from"../core/classify.js";import{getReticleCell as f,getReticleShot as d}from"../core/reticle.js";import{requireRingCount as g}from"../core/ringCount.js";import{hasPosition as l}from"../core/dies.js";import{getRingLabel as s}from"../core/classify.js";export const DIE_REGION_KEYS=["ring","quadrant","reticleCell","reticleShot"];function p(e,r){return!!r.wafer&&l(e)&&e.physX!==void 0&&e.physY!==void 0}function i(e,r,n){if(p(e,r))return c(e,r.wafer,{ringCount:g(r,n)})}const t=new Map([["quadrant:NE",0],["quadrant:NW",1],["quadrant:SE",2],["quadrant:SW",3]]);function a(e,r){const n=r.reticle??r.wafer?.reticle;return n&&l(e)?f(e,n):void 0}export const DIE_REGIONS={ring:{key:"ring",label:"Ring",available:(e,r)=>!!e.wafer&&r,valueOf:(e,r)=>{const n=i(e,r,"a ring of a plot");return n?`Ring ${n.ring}`:void 0},rawOf:(e,r)=>{const n=i(e,r,"a ring of a plot");return n?String(n.ring):void 0},grouping:{family:"ring",place:(e,r)=>{const n=i(e,r,"a ring");return n?{key:`ring:${n.ring}`,label:s(n.ring,r.ringCount)}:void 0},order:(e,r)=>e.localeCompare(r)}},quadrant:{key:"quadrant",label:"Quadrant",available:(e,r)=>!!e.wafer&&r,valueOf:(e,r)=>i(e,r,"a quadrant of a plot")?.quadrant,grouping:{family:"quadrant",place:(e,r)=>{const n=i(e,r,"a quadrant");return n?{key:`quadrant:${n.quadrant}`,label:n.quadrant}:void 0},order:(e,r)=>(t.get(e)??4)-(t.get(r)??4)}},reticleCell:{key:"reticleCell",label:"Reticle cell",available:(e,r)=>!!(e.reticle??e.wafer?.reticle)&&r,valueOf:(e,r)=>{const n=a(e,r);return n?`Reticle cell (${n.column}, ${n.row})`:void 0},grouping:{family:"reticle-position",place:(e,r)=>{const n=a(e,r);return n?{key:`reticle-position:cell:${n.column},${n.row}`,label:`Reticle cell (${n.column}, ${n.row})`}:void 0},order:(e,r)=>e.localeCompare(r,void 0,{numeric:!0})}},reticleShot:{key:"reticleShot",label:"Reticle shot",available:(e,r)=>!!(e.reticle??e.wafer?.reticle)&&r,valueOf:(e,r)=>{const n=r.reticle??r.wafer?.reticle;if(!n||!l(e))return;const{column:o,row:u}=d(e,n);return`Reticle shot (${o}, ${u})`}}};export function availableRegions(e,r){return DIE_REGION_KEYS.map(n=>DIE_REGIONS[n]).filter(n=>n.available(e,r))}export const isDieRegionKey=e=>DIE_REGION_KEYS.includes(e);
|
|
@@ -29,6 +29,8 @@ export interface FacetField {
|
|
|
29
29
|
/** True when the field has more than one distinct value — i.e. splitting on it actually partitions the data. */
|
|
30
30
|
splittable: boolean;
|
|
31
31
|
}
|
|
32
|
+
/** What a host says about one wafer attribute (`attributes` on the render options): its label, whether it is a Group by and Compare by choice, and whether it is a date. The same shape as a curation entry. */
|
|
33
|
+
export type WaferAttributeDef = FacetCuration;
|
|
32
34
|
/** Curation for one metadata key: label + whether it's offered as a facet by default + date handling. */
|
|
33
35
|
export interface FacetCuration {
|
|
34
36
|
label: string;
|
|
@@ -41,6 +43,12 @@ export interface FacetCuration {
|
|
|
41
43
|
* (not replace) this via `buildFacetTable`'s `curation` option — their own
|
|
42
44
|
* app-specific extra keys layer on top rather than needing to redeclare these. */
|
|
43
45
|
export declare const DEFAULT_FACET_CURATION: Record<string, FacetCuration>;
|
|
46
|
+
/**
|
|
47
|
+
* A wafer attribute's name wherever it is listed or headed: the curated label when the key has one, else the key spelled out
|
|
48
|
+
* (`prettyKey`). The ONE label for an attribute, so Group by, the plot fields, the Wafers table, the header strip and the
|
|
49
|
+
* reports cannot name it differently. `curation` is the host's own on top of the defaults (`insights.attributes`).
|
|
50
|
+
*/
|
|
51
|
+
export declare function attributeLabel(key: string, curation?: Record<string, FacetCuration>): string;
|
|
44
52
|
/** The faceting value of one metadata key for one wafer's metadata — the raw
|
|
45
53
|
* value, except date-curated fields are truncated to date-only so grouping
|
|
46
54
|
* is by day, not timestamp. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{metadataDisplayValue as
|
|
1
|
+
import{metadataDisplayValue as C}from"../core/metadata.js";import{compareNatural as y,prettyKey as b}from"../core/utils.js";export const FACET_NONE_VALUE="(none)";export{prettyKey}from"../core/utils.js";export const DEFAULT_FACET_CURATION={split:{label:"Split"},lot:{label:"Lot"},product:{label:"Product"},testProgram:{label:"Test Program"},temperature:{label:"Temperature"},testDate:{label:"Test Date",date:!0},operator:{label:"Operator"},waferId:{label:"Wafer Id",facet:!1}};export function attributeLabel(t,e){return e?.[t]?.label??DEFAULT_FACET_CURATION[t]?.label??b(t)}function O(t){const e=t.indexOf("T");return e>0?t.slice(0,e):t}export function facetValueOf(t,e,o=DEFAULT_FACET_CURATION){const l=C(t?.[e]);if(l!==void 0)return o[e]?.date?O(l):l}export function commonMetadata(t){if(!t.length)return{};const e=t[0].metadata??{},o={};for(const[l,r]of Object.entries(e))r==null||r===""||t.every(d=>(d.metadata??{})[l]===r)&&(o[l]=r);return o}export function buildFacetTable(t,e={}){const o={...DEFAULT_FACET_CURATION,...e.curation},l=e.facetableOnly??!0,r=new Set;for(const n of t)for(const u of Object.keys(n.metadata??{}))r.add(u);const m=[...Object.keys(o).filter(n=>r.has(n)),...[...r].filter(n=>!(n in o))],p=[];for(const n of m){const u=o[n];if(l&&u&&u.facet===!1)continue;const c=new Map;for(const f of t){const a=facetValueOf(f.metadata,n,o)??FACET_NONE_VALUE,i=c.get(a)??{waferCount:0,dieCount:0};i.waferCount+=1,i.dieCount+=f.dieCount??0,c.set(a,i)}if(c.size===0)continue;const s=Array.from(c,([f,a])=>({value:f,waferCount:a.waferCount,dieCount:a.dieCount}));s.sort((f,a)=>(f.value===FACET_NONE_VALUE?1:0)-(a.value===FACET_NONE_VALUE?1:0)||a.waferCount-f.waferCount||y(f.value,a.value)),p.push({key:n,label:u?.label??b(n),values:s,splittable:s.length>1})}return p}
|
|
@@ -8,7 +8,8 @@ export { setReportOpener } from './renderFindingsReport.js';
|
|
|
8
8
|
export { renderWaferReportHtml, renderLotReportHtml } from './renderSummaryReport.js';
|
|
9
9
|
export type { ReportMap } from './renderSummaryReport.js';
|
|
10
10
|
export type { SummaryReportParams } from './renderSummaryReport.js';
|
|
11
|
-
export { buildFacetTable, facetValueOf, FACET_NONE_VALUE } from './facets.js';
|
|
11
|
+
export { buildFacetTable, facetValueOf, attributeLabel, FACET_NONE_VALUE } from './facets.js';
|
|
12
|
+
export type { WaferAttributeDef } from './facets.js';
|
|
12
13
|
export type { FacetField, FacetValue, FacetCuration, FacetItem, BuildFacetTableOptions } from './facets.js';
|
|
13
14
|
export type { MetadataKeySelection } from './metadataColumns.js';
|
|
14
15
|
export { mergeTestDefs } from './mergeTestDefs.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./types.js";export{analyzeWaferMap}from"./analyzeWaferMap.js";export{analyzeWaferLot}from"./analyzeWaferLot.js";export{filterFindings,visibleFindings}from"./filterFindings.js";export{setReportOpener}from"./renderFindingsReport.js";export{renderWaferReportHtml,renderLotReportHtml}from"./renderSummaryReport.js";export{buildFacetTable,facetValueOf,FACET_NONE_VALUE}from"./facets.js";export{mergeTestDefs}from"./mergeTestDefs.js";export{readPlotsFile,writePlotsFile}from"./plotSpec.js";
|
|
1
|
+
export*from"./types.js";export{analyzeWaferMap}from"./analyzeWaferMap.js";export{analyzeWaferLot}from"./analyzeWaferLot.js";export{filterFindings,visibleFindings}from"./filterFindings.js";export{setReportOpener}from"./renderFindingsReport.js";export{renderWaferReportHtml,renderLotReportHtml}from"./renderSummaryReport.js";export{buildFacetTable,facetValueOf,attributeLabel,FACET_NONE_VALUE}from"./facets.js";export{mergeTestDefs}from"./mergeTestDefs.js";export{readPlotsFile,writePlotsFile}from"./plotSpec.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{requireRingCount as P}from"../core/ringCount.js";import{getDieKey as v,isPositionedDie as L,isYieldEligibleDie as j,positionKey as h}from"../core/dies.js";import{itemPassBins as K}from"../core/passBins.js";import{classifyFailingDies as q,patternFailVerdict as C}from"./patternClassification.js";import{benjaminiHochberg as D,binomialUpperTail as F}from"./math.js";import{passesRateGate as
|
|
1
|
+
import{requireRingCount as P}from"../core/ringCount.js";import{getDieKey as v,isPositionedDie as L,isYieldEligibleDie as j,positionKey as h}from"../core/dies.js";import{itemPassBins as K}from"../core/passBins.js";import{classifyFailingDies as q,patternFailVerdict as C}from"./patternClassification.js";import{benjaminiHochberg as D,binomialUpperTail as F,zPValue as G}from"./math.js";import{passesRateGate as T,rateRelativeEffect as V,twoProportionZ as W}from"./analyzeWaferMap.js";const A=.01;export function findLotPattern(H,c){const l=[];let f,k=0,w=0;if(H.forEach((e,n)=>{if(e.isLotStack)return;const s=new Set(K(e)),t=[],i=[];for(const o of e.dies){if(!j(o)||!L(o))continue;const a=C(o,s);a!==void 0&&(t.push(o),i.push(a))}if(!t.length)return;const r=(o,a)=>Math.abs(o-a)<=A*Math.max(Math.abs(o),Math.abs(a));if(!f)f=e,k=t[0].width,w=t[0].height;else if(!r(e.wafer.radius,f.wafer.radius)||!r(t[0].width,k)||!r(t[0].height,w))return;l.push({index:n,dies:t,fails:i})}),!f||l.length<2)return null;const d=new Map;let z=0,p=0;for(const e of l)e.dies.forEach((n,s)=>{const t=h(n);let i=d.get(t);i||d.set(t,i={die:n,n:0,k:0}),i.n++,e.fails[s]&&(i.k++,p++),z++});if(p===0)return null;const E=p/z,m=[...d.values()],M=m.map(e=>{let n=0,s=0;for(let t=-1;t<=1;t++)for(let i=-1;i<=1;i++){const r=t===0&&i===0?e:d.get(h({x:e.die.x+t,y:e.die.y+i}));r&&(n+=r.n,s+=r.k)}return{n,k:s}}),N=D(M.map(e=>F(e.k,e.n,E))),x=new Set,S=[];m.forEach((e,n)=>{N[n]>c.significanceLevel||e.k/e.n<=E||(x.add(h(e.die)),S.push(e.die))});const u=q(S,m.map(e=>e.die),f.wafer,P(f,"the lot pattern"));if(!u||u.pattern==="random"||u.pattern==="none")return null;const b=l.map(e=>{let n=0,s=0,t=0,i=0;const r=[];e.dies.forEach((a,y)=>{x.has(h(a))?(s++,e.fails[y]&&(n++,r.push(v(a)))):(i++,e.fails[y]&&t++)});const o=s>=c.minimumSampleSize&&i>=c.minimumSampleSize?W(n,s,t,i):0;return{index:e.index,z:o,hits:n,n:s,restHits:t,restN:i,inside:r}}),R=D(b.map(e=>e.z>0?G(e.z):1)),g=new Map;return b.forEach((e,n)=>{if(e.z<=0)return;const s=e.hits/e.n-e.restHits/e.restN,t=V({hits:e.hits,n:e.n,restHits:e.restHits,restN:e.restN,passRate:!1});T(R[n],s,t,c)&&g.set(e.index,e.inside)}),g.size?{classification:u,carriers:g}:null}
|
|
@@ -1,16 +1,38 @@
|
|
|
1
|
+
/** The error function erf(x), from {@link complementaryErrorFunction}. */
|
|
2
|
+
export declare function errorFunction(value: number): number;
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
+
* The complementary error function erfc(x) = 1 − erf(x), accurate to about 1e-15 relative across the whole
|
|
5
|
+
* range, the far tail included: W. J. Cody's rational approximations (Math. Comp. 23, 1969; the CALERF
|
|
6
|
+
* routine). A small p-value is read from the tail, where 1 − erf(x) computed by subtraction is noise below
|
|
7
|
+
* about 1e-7 and becomes 0.
|
|
4
8
|
*/
|
|
5
|
-
export declare function
|
|
9
|
+
export declare function complementaryErrorFunction(value: number): number;
|
|
6
10
|
/** Standard normal cumulative distribution function Φ(value). */
|
|
7
11
|
export declare function normalCdf(value: number): number;
|
|
12
|
+
/** The standard normal upper tail 1 − Φ(value), accurate where it is small. */
|
|
13
|
+
export declare function normalUpperTail(value: number): number;
|
|
14
|
+
/** Two-sided p-value of a z statistic: the one rule every z-based test in the library reads its p from. */
|
|
15
|
+
export declare function zPValue(z: number): number;
|
|
8
16
|
/**
|
|
9
17
|
* Exact one-sided binomial tail P(X ≥ k) for X ~ Binomial(n, p). Exact rather
|
|
10
18
|
* than a normal approximation because it is asked about small n — how many of a
|
|
11
19
|
* lot's few wafers fail at one die position — where the approximation is poor.
|
|
12
20
|
*/
|
|
13
21
|
export declare function binomialUpperTail(k: number, n: number, p: number): number;
|
|
22
|
+
/** ln Γ(x) for x > 0, by the Lanczos approximation (g = 7, 9 terms): relative error near 1e-15. */
|
|
23
|
+
export declare function logGamma(x: number): number;
|
|
24
|
+
/**
|
|
25
|
+
* Two-sided Fisher exact p-value of the 2×2 table [[a, b], [c, d]]: the probability, with the margins fixed,
|
|
26
|
+
* of a table no more likely than the one observed. For rates whose expected counts are too small for a
|
|
27
|
+
* normal approximation, which there reports differences far more significant than they are. The table's
|
|
28
|
+
* probabilities are walked by their ratio, so the cost is the span of the first cell, not the dies.
|
|
29
|
+
*/
|
|
30
|
+
export declare function fisherExact(a: number, b: number, c: number, d: number): number;
|
|
31
|
+
/**
|
|
32
|
+
* A seeded uniform generator on [0, 1) (mulberry32). For resampling that must give the same answer on
|
|
33
|
+
* every run (a permutation test's p-value), never for anything that should look random to a user.
|
|
34
|
+
*/
|
|
35
|
+
export declare function seededRandom(seed: number): () => number;
|
|
14
36
|
/**
|
|
15
37
|
* Benjamini–Hochberg adjusted p-values, in the order given. The one
|
|
16
38
|
* false-discovery-rate rule in the library: findings (`adjustPValues`) and the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function errorFunction(t){
|
|
1
|
+
export function errorFunction(t){return t<0?-1+complementaryErrorFunction(-t):1-complementaryErrorFunction(t)}export function complementaryErrorFunction(t){const e=Math.abs(t);let n;if(e<=.46875){const o=e>111e-18?e*e:0;let r=q[4]*o,s=o;for(let u=0;u<3;u++)r=(r+q[u])*o,s=(s+b[u])*o;return 1-t*(r+q[3])/(s+b[3])}if(e<=4){let o=y[8]*e,r=e;for(let s=0;s<7;s++)o=(o+y[s])*e,r=(r+F[s])*e;n=(o+y[7])/(r+F[7])}else{if(e>=26.543)return t>0?0:2;const o=1/(e*e);let r=N[5]*o,s=o;for(let l=0;l<4;l++)r=(r+N[l])*o,s=(s+w[l])*o;n=(1/Math.sqrt(Math.PI)-o*(r+N[4])/(s+w[4]))/e}const c=Math.trunc(e*16)/16,i=(e-c)*(e+c);return n*=Math.exp(-c*c)*Math.exp(-i),t<0?2-n:n}const q=[3.1611237438705655,113.86415415105016,377.485237685302,3209.3775891384694,.18577770618460315],b=[23.601290952344122,244.02463793444417,1282.6165260773723,2844.236833439171],y=[.5641884969886701,8.883149794388377,66.11919063714163,298.6351381974001,881.952221241769,1712.0476126340707,2051.0783778260716,1230.3393547979972,21531153547440383e-24],F=[15.744926110709835,117.6939508913125,537.1811018620099,1621.3895745666903,3290.7992357334597,4362.619090143247,3439.3676741437216,1230.3393548037495],N=[.30532663496123236,.36034489994980445,.12578172611122926,.016083785148742275,.0006587491615298378,.016315387137302097],w=[2.568520192289822,1.8729528499234673,.5279051029514285,.06051834131244132,.0023352049762686918];export function normalCdf(t){return .5*complementaryErrorFunction(-t/Math.SQRT2)}export function normalUpperTail(t){return .5*complementaryErrorFunction(t/Math.SQRT2)}export function zPValue(t){return Math.min(1,2*normalUpperTail(Math.abs(t)))}export function binomialUpperTail(t,e,n){if(t<=0)return 1;if(t>e||n<=0)return 0;if(n>=1)return 1;let c=t*Math.log(n)+(e-t)*Math.log1p(-n);for(let s=0;s<t;s++)c+=Math.log(e-s)-Math.log(s+1);let i=Math.exp(c),o=0;const r=n/(1-n);for(let s=t;s<=e;s++)o+=i,i*=(e-s)/(s+1)*r;return Math.min(1,o)}export function logGamma(t){if(t<.5)return Math.log(Math.PI/Math.sin(Math.PI*t))-logGamma(1-t);const e=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,15056327351493116e-23],n=t-1;let c=e[0];for(let o=1;o<9;o++)c+=e[o]/(n+o);const i=n+7.5;return .5*Math.log(2*Math.PI)+(n+.5)*Math.log(i)-i+Math.log(c)}export function fisherExact(t,e,n,c){const i=t+e,o=n+c,r=t+n,s=i+o,l=Math.max(0,r-o),u=Math.min(i,r);if(u<=l)return 1;const m=h=>logGamma(i+1)+logGamma(o+1)+logGamma(r+1)+logGamma(s-r+1)-logGamma(s+1)-logGamma(h+1)-logGamma(i-h+1)-logGamma(r-h+1)-logGamma(o-r+h+1),p=Math.exp(m(t));let M=Math.exp(m(l)),f=0;const a=p*(1+1e-7);for(let h=l;h<=u;h++)M<=a&&(f+=M),M*=(i-h)*(r-h)/((h+1)*(o-r+h+1));return Math.min(1,f)}export function seededRandom(t){let e=t>>>0;return()=>{e=e+1831565813>>>0;let n=e;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}export function benjaminiHochberg(t){const e=t.length,n=t.map((o,r)=>r).sort((o,r)=>t[o]-t[r]),c=new Array(e);let i=1;for(let o=e-1;o>=0;o--){const r=n[o];i=Math.min(i,t[r]*e/(o+1),1),c[r]=i}return c}export function quantile(t,e){if(t.length===0)return NaN;const n=e*(t.length-1),c=Math.floor(n),i=Math.ceil(n);return t[c]+(t[i]-t[c])*(n-c)}export function robustFence(t,e=1.5,n=8){const c=Float64Array.from(Array.from(t).filter(s=>Number.isFinite(s)));if(c.length<n)return null;const{q1:i,q3:o}=fiveNumberSummary(c),r=o-i;return r===0?null:{lo:i-e*r,hi:o+e*r}}export function sampleVariance(t,e){const n=t.length;if(n<2)return 0;if(e===void 0){let i=0;for(let o=0;o<n;o++)i+=t[o];e=i/n}let c=0;for(let i=0;i<n;i++)c+=(t[i]-e)**2;return c/(n-1)}export function describeValues(t){const e=t.length;let n=0;for(let m=0;m<e;m++)n+=t[m];const c=n/e,i=Math.sqrt(sampleVariance(t,c)),{min:o,q1:r,median:s,q3:l,max:u}=fiveNumberSummary(t);return{min:o,max:u,mean:c,count:e,stddev:i,median:s,q1:r,q3:l}}export function fiveNumberSummary(t){let e=1/0,n=-1/0;for(let r=0;r<t.length;r++){const s=t[r];s<e&&(e=s),s>n&&(n=s)}t.length===0&&(e=NaN,n=NaN);const{q1:c,median:i,q3:o}=E(t);return{min:e,q1:c,median:i,q3:o,max:n}}function E(t){const e=t.length;if(e===0)return{q1:NaN,median:NaN,q3:NaN};const n=e-1,c=(p,M,f)=>{const a=p*n,h=Math.floor(a),x=R(t,h,M,f);if(a===h)return x;let g=1/0;for(let d=h+1;d<=f;d++)t[d]<g&&(g=t[d]);return x+(g-x)*(a-h)},i=Math.floor(.5*n),o=c(.5,0,n),r=Math.floor(.25*n),s=r===i?c(.25,i,n):m(.25,r,i),u=Math.floor(.75*n)===i?c(.75,i,n):c(.75,i+1,n);return{q1:s,median:o,q3:u};function m(p,M,f){const a=p*n,h=R(t,M,0,f-1);if(a===M)return h;let x=t[f];for(let g=M+1;g<f;g++)t[g]<x&&(x=t[g]);return h+(x-h)*(a-M)}}function R(t,e,n,c){for(;n<c;){const i=t[n],o=t[n+c>>>1],r=t[c],s=i<o?o<r?o:i<r?r:i:i<r?i:o<r?r:o;let l=n,u=c;for(;l<=u;){for(;t[l]<s;)l++;for(;t[u]>s;)u--;if(l<=u){const m=t[l];t[l]=t[u],t[u]=m,l++,u--}}if(e<=u)c=u;else if(e>=l)n=l;else break}return t[e]}export function mannKendall(t){const e=t.length;if(e<3)return null;let n=0;const c=[];for(let f=0;f<e-1;f++)for(let a=f+1;a<e;a++){const h=t[a]-t[f];n+=h>0?1:h<0?-1:0,c.push(h/(a-f))}const i=new Map;for(const f of t)i.set(f,(i.get(f)??0)+1);let o=e*(e-1)*(2*e+5)/18;for(const f of i.values())f>1&&(o-=f*(f-1)*(2*f+5)/18);if(o<=0)return null;const r=n===0?0:(n-Math.sign(n))/Math.sqrt(o),s=zPValue(r);c.sort((f,a)=>f-a);const l=c.length>>1,u=c.length%2?c[l]:(c[l-1]+c[l])/2,m=t.map((f,a)=>f-u*a).sort((f,a)=>f-a),p=m.length>>1,M=m.length%2?m[p]:(m[p-1]+m[p])/2;return{n:e,s:n,z:r,pValue:s,slope:u,intercept:M}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{metadataDisplayValue as
|
|
1
|
+
import{metadataDisplayValue as w}from"../core/metadata.js";import{compareNatural as K,prettyKey as A}from"../core/utils.js";import{DEFAULT_FACET_CURATION as b,attributeLabel as v}from"./facets.js";const k=64;export function discoverDieMetadataKeys(e,n,s=k){const d=new Set;for(const c of e)if(c.metadata)for(const i of Object.keys(c.metadata))d.add(i);const r=[];for(const c of n??[])d.has(c.key)&&!r.includes(c.key)&&r.push(c.key);const y=[...d].filter(c=>!r.includes(c)).sort(K),a=[...r,...y];return{keys:a.slice(0,s),truncated:a.slice(s)}}function D(e){const n=Object.keys(e).filter(r=>w(e[r])!==void 0),s=Object.keys(b).filter(r=>n.includes(r)),d=n.filter(r=>!s.includes(r)).sort(K);return[...s,...d]}const h=(e,n)=>e==="none"?[]:Array.isArray(e)?e.filter(s=>n.includes(s)):e==="identity"?n.filter(s=>s in b):n;export function resolveMetadataColumns(e){const n=e.waferMetadata??{},s=e.waferPlacement??"csv",d=discoverDieMetadataKeys(e.dies??[],e.metadataFields,e.maxDieKeys??k),r=h(e.dieKeys,d.keys),y=s==="none"?[]:h(e.waferKeys,D(n)).filter(t=>!r.includes(t)),a=new Set(e.reservedLabels??[]),c=(t,o)=>{const f=e.metadataFields?.find(u=>u.key===t)?.label??(o==="wafer"?v(t):A(t));if(!a.has(f))return a.add(f),f;const m=o==="die"?`${f} (metadata)`:`${f} (wafer metadata)`;if(!a.has(m))return a.add(m),m;const l=`${f} (${t})`;if(!a.has(l))return a.add(l),l;for(let u=2;;u++){const p=`${l} (${u})`;if(!a.has(p))return a.add(p),p}},i=[];for(const t of r)i.push({key:t,label:c(t,"die"),scope:"die",get:o=>w(o.metadata?.[t])??"",csvOnly:!1});for(const t of y){const o=w(n[t])??"";i.push({key:t,label:c(t,"wafer"),scope:"wafer",get:()=>o,constant:o,csvOnly:s==="csv"})}return{columns:i,truncatedKeys:d.truncated}}
|