fix(web): add safeguard for split-distribution merging

This commit is contained in:
Joshua Horton 2025-10-29 13:57:55 -05:00
parent 22f534667f
commit b1ffa83c8b

View file

@ -199,23 +199,28 @@ export abstract class SearchQuotientSpur implements SearchQuotientNode {
// per-codepoint.
if(localInputId != spaceInputId || localInputId === undefined) {
return space.construct(parentMerge, space.inputs, space.inputSource);
} else {
// Get the twin halves that were split.
// Assumption: the two halves are in their original order, etc.
const localInputs = this.inputs;
const spaceInputs = space.inputs;
// Merge them!
const mergedInputs = localInputs?.map((entry, index) => {
return {
sample: buildMergedTransform(entry.sample, spaceInputs[index].sample),
p: entry.p
}
});
// Now to re-merge the two halves.
return space.construct(this.parentNode, mergedInputs, this.inputSource);
}
// Get the twin halves that were split.
// Assumption: the two halves are in their original order, etc.
const localInputs = this.inputs;
const spaceInputs = space.inputs;
// Sanity check - ensure that the input distributions have the same length;
// if not, this shouldn't represent a SearchPath split!
if(localInputs.length != spaceInputs.length) {
return space.construct(parentMerge, space.inputs, space.inputSource);
}
// Merge them!
const mergedInputs = localInputs?.map((entry, index) => {
return {
sample: buildMergedTransform(entry.sample, spaceInputs[index].sample),
p: entry.p
}
});
// Now to re-merge the two halves.
return space.construct(this.parentNode, mergedInputs, this.inputSource);
} else {
// If the parent was a cluster, the cluster itself is the merge.
return parentMerge;