Skip to content
Merged

slots #379

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"cheminfo-types": "^1.15.0",
"fft.js": "^4.0.4",
"is-any-array": "^3.0.0",
"ml-matrix": "^6.12.2",
"ml-matrix": "^6.13.0",
"ml-xsadd": "^3.0.1"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/fftCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class FFTCache {
#maxSize: number;
readonly #instances = new Map<number, FFT>();

constructor(maxSize = 10) {
constructor(maxSize = 1) {
this.#maxSize = maxSize;
}

Expand Down Expand Up @@ -77,7 +77,7 @@ export function clearFFTCache(): void {

/**
* Sets the maximum number of distinct transform sizes kept in the shared FFT
* cache (default 10). When the cache is full and a new size is requested, the
* cache (default 1). When the cache is full and a new size is requested, the
* whole cache is dropped and rebuilt on demand. Lowering the limit below the
* current number of cached sizes clears the cache immediately.
* @param maxSize - maximum number of cached sizes; must be a positive integer.
Expand Down
12 changes: 9 additions & 3 deletions src/xyArray/utils/getSlotsToFirst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Slot {
* Computes slots aligned to the first spectrum's x values, adding slots for any x values not covered.
* @param data - data.
* @param options - options.
* @returns the slots, sorted by x value, with non-overlapping `[from, to)` ranges.
*/
export function getSlotsToFirst(
data: DataXY[],
Expand All @@ -42,10 +43,15 @@ export function getSlotsToFirst(

const otherXs = xyArrayWeightedMerge(data.slice(1), options).x;
let currentPosition = 0;
for (const slot of slots) {
// Only the first-spectrum slots drive this pass; slots created for uncovered
// x values are appended and merged in by the sort below, so we freeze the
// count instead of iterating an array we are mutating.
const firstSlotCount = slots.length;
for (let i = 0; i < firstSlotCount; i++) {
const slot = slots[i];
while (
otherXs[currentPosition] < slot.to &&
currentPosition < otherXs.length
currentPosition < otherXs.length &&
otherXs[currentPosition] < slot.to
) {
if (otherXs[currentPosition] < slot.from) {
const currentDelta = deltaIsFunction
Expand Down
6 changes: 5 additions & 1 deletion src/xyArray/xyArrayAlignToFirst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface XYArrayAlignToFirstOptions {
* If some x values are missing in the first spectrum we will add them
* @param data - data
* @param options - options
* @returns the common `x` axis and one aligned `y` array per input spectrum.
*/
export function xyArrayAlignToFirst(
data: DataXY[],
Expand All @@ -26,7 +27,10 @@ export function xyArrayAlignToFirst(
} {
const { delta = 1 } = options;
const slots = getSlotsToFirst(data, { delta });
const x = Float64Array.from(slots.map((slot) => slot.value));
const x = new Float64Array(slots.length);
for (let i = 0; i < slots.length; i++) {
x[i] = slots[i].value;
}
const ys = Array.from(data, () => new Float64Array(x.length));

const positions = new Uint32Array(data.length);
Expand Down
Loading