Skip to content

Commit

Permalink
fix: xyGrowingX bug (#268)
Browse files Browse the repository at this point in the history
* test: add xyGrowingX failing test

* fix: xyGrowingX bug

* chore: update dependencis

* chore: fix test cases ?
  • Loading branch information
lpatiny authored Nov 12, 2024
1 parent 4702fe6 commit bb00293
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 44 deletions.
32 changes: 13 additions & 19 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import cheminfo from 'eslint-config-cheminfo-typescript';
import globals from 'globals';

export default [
...cheminfo,
{
languageOptions: {
globals: {
...globals.node,
},
},
languageOptions: {},
rules: {
"jsdoc/lines-before-block": "off",
"no-loss-of-precision": "off",
'jsdoc/lines-before-block': 'off',
'no-loss-of-precision': 'off',
'@typescript-eslint/prefer-for-of': 'off',
"unicorn/import-style": [
"error",
'unicorn/import-style': [
'error',
{
"styles": {
"node:path": false
}
}
]
}
}
]

styles: {
'node:path': false,
},
},
],
},
},
];
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,26 @@
},
"homepage": "https://github.com/mljs/spectra-processing#readme",
"devDependencies": {
"@vitest/coverage-v8": "^2.1.1",
"@vitest/coverage-v8": "^2.1.4",
"cheminfo-build": "^1.2.0",
"eslint": "^8.57.0",
"eslint-config-cheminfo-typescript": "^15.0.1",
"eslint": "^9.14.0",
"eslint-config-cheminfo-typescript": "^16.0.0",
"jest-matcher-deep-close-to": "^3.0.2",
"jscpd": "^4.0.5",
"ml-spectra-fitting": "^4.2.3",
"ml-spectra-fitting": "^4.2.4",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"spectrum-generator": "^8.0.11",
"typescript": "^5.6.2",
"vitest": "^2.1.1"
"typescript": "^5.6.3",
"vitest": "^2.1.4"
},
"dependencies": {
"binary-search": "^1.3.6",
"cheminfo-types": "^1.8.0",
"cheminfo-types": "^1.8.1",
"fft.js": "^4.0.4",
"is-any-array": "^2.0.1",
"ml-matrix": "^6.11.1",
"ml-xsadd": "^2.0.0",
"ml-matrix": "^6.12.0",
"ml-xsadd": "^3.0.1",
"spline-interpolator": "^1.0.0"
}
}
4 changes: 2 additions & 2 deletions src/reim/__tests__/reimPhaseCorrection.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import XSAdd from 'ml-xsadd';
import { XSadd } from 'ml-xsadd';
import { expect, test } from 'vitest';

import { reimPhaseCorrection } from '../reimPhaseCorrection';
Expand Down Expand Up @@ -117,7 +117,7 @@ test('test reimPhaseCorrection even', () => {
});

test('180 zero order phasing', () => {
const generator = new XSAdd(0);
const generator = new XSadd(0);
const phased = reimPhaseCorrection(data, Math.PI, 0);
const diff = data.re.map((e, i) => e + phased.re[i]);
const index = Math.floor(generator.random() * data.x.length);
Expand Down
8 changes: 4 additions & 4 deletions src/utils/createRandomArray.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import XSAdd from 'ml-xsadd';
import { XSadd } from 'ml-xsadd';

export interface CreateRandomArrayOptions {
/**
Expand Down Expand Up @@ -56,7 +56,7 @@ export function createRandomArray(
distribution = 'normal',
} = options;

const generator = new XSAdd(seed);
const generator = new XSadd(seed);
const returnArray = new Float64Array(length);

switch (distribution) {
Expand Down Expand Up @@ -91,9 +91,9 @@ class GaussianGenerator {

#mean: number;
#standardDeviation: number;
#generator: XSAdd;
#generator: XSadd;

constructor(mean: number, standardDeviation: number, generator: XSAdd) {
constructor(mean: number, standardDeviation: number, generator: XSadd) {
this.#mean = mean;
this.#standardDeviation = standardDeviation;
this.#generator = generator;
Expand Down
10 changes: 5 additions & 5 deletions src/x/__tests__/xHistogram.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import XSAdd from 'ml-xsadd';
import { XSadd } from 'ml-xsadd';
import { expect, test } from 'vitest';

import { createFromToArray } from '../../utils';
Expand Down Expand Up @@ -88,7 +88,7 @@ test('simple y log case', () => {
});

test('256 slots', () => {
const generator = new XSAdd(0);
const generator = new XSadd(0);
const array = new Float64Array(10000).map(() => generator.random());
const histogram = xHistogram(array);
expect(histogram.y).toHaveLength(256);
Expand All @@ -98,7 +98,7 @@ test('256 slots', () => {
});

test('10 slots', () => {
const generator = new XSAdd(0);
const generator = new XSadd(0);
const array = new Float64Array(100000).map(() => generator.random() * 900);
const histogram = xHistogram(array, { nbSlots: 10, centerX: false });
expect(histogram.x).toMatchCloseTo(
Expand All @@ -114,7 +114,7 @@ test('10 slots', () => {
});

test('11 slots center X', () => {
const generator = new XSAdd(0);
const generator = new XSadd(0);
const array = new Float64Array(110000).map(
() => generator.random() * 1100 - 50,
);
Expand All @@ -131,7 +131,7 @@ test('11 slots center X', () => {
});

test('min -10, max 10', () => {
const generator = new XSAdd(0);
const generator = new XSadd(0);
const array = new Float64Array(10000).map(() => generator.random());
const histogram = xHistogram(array, { nbSlots: 20, min: -10, max: 10 });
expect(histogram.y).toStrictEqual(
Expand Down
4 changes: 2 additions & 2 deletions src/x/__tests__/xMedian.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import XSAdd from 'ml-xsadd';
import { XSadd } from 'ml-xsadd';
import { expect, test } from 'vitest';

import { xMedian } from '../xMedian';

const generator = new XSAdd(0);
const generator = new XSadd(0);
const data: number[] = [];
for (let i = 0; i < 1000; i++) {
data.push(generator.random());
Expand Down
11 changes: 11 additions & 0 deletions src/xy/__tests__/xyGrowingX.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ test('test xyGrowingX do nothing', () => {
});
});

test('test xyGrowingX do nothing', () => {
const x = [1, 2, 3];
const y = [1, 2, 3];
const result = xyGrowingX({ x, y });

expect(result).toStrictEqual({
x: [1, 2, 3],
y: [1, 2, 3],
});
});

test('test xyGrowingX reverse', () => {
const x = [3, 2, 1, 0];
const y = [0, 1, 2, 3];
Expand Down
2 changes: 1 addition & 1 deletion src/xy/xyGrowingX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function xyGrowingX(data: DataXY): DataXY {
throw new TypeError('length of x and y must be identical');
}

if (x.length < 2 || x[0] < x[x.at(-1) as number]) return data;
if (x.length < 2 || x[0] < (x.at(-1) as number)) return data;

return {
x: x.slice(0).reverse(),
Expand Down
4 changes: 2 additions & 2 deletions src/xyArray/__tests__/xyArrayWeightedMerge.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataXY } from 'cheminfo-types';
import XSAdd from 'ml-xsadd';
import { XSadd } from 'ml-xsadd';
import { expect, test } from 'vitest';

import { xyArrayWeightedMerge } from '../xyArrayWeightedMerge';
Expand Down Expand Up @@ -82,7 +82,7 @@ test('empty data', () => {
test('large Data Set', () => {
const data = [];
const arraySize = 1e5;
const generator = new XSAdd(0);
const generator = new XSadd(0);
for (let dataset = 0; dataset < 20; dataset++) {
const datum = {
x: new Float64Array(arraySize),
Expand Down

0 comments on commit bb00293

Please sign in to comment.