Skip to content
Merged
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
16 changes: 8 additions & 8 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": {
"@types/node": "^22.13.10",
"@vitest/coverage-v8": "^3.0.8",
"@types/node": "^22.14.0",
"@vitest/coverage-v8": "^3.1.1",
"cheminfo-build": "^1.2.1",
"eslint": "^9.22.0",
"eslint-config-cheminfo-typescript": "^17.0.0",
"eslint": "^9.24.0",
"eslint-config-cheminfo-typescript": "^18.0.0",
"jest-matcher-deep-close-to": "^3.0.2",
"jscpd": "^4.0.5",
"ml-spectra-fitting": "^4.2.4",
"prettier": "^3.5.3",
"rimraf": "^6.0.1",
"spectrum-generator": "^8.0.12",
"typescript": "^5.8.2",
"vitest": "^3.0.8"
"spectrum-generator": "^8.1.0",
"typescript": "^5.8.3",
"vitest": "^3.1.1"
},
"dependencies": {
"binary-search": "^1.3.6",
"cheminfo-types": "^1.8.1",
"fft.js": "^4.0.4",
"is-any-array": "^2.0.1",
"ml-matrix": "^6.12.0",
"ml-matrix": "^6.12.1",
"ml-xsadd": "^3.0.1"
}
}
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ exports[`test existence of exported functions 1`] = `
"isPowerOfTwo",
"nextPowerOfTwo",
"recursiveResolve",
"recursiveUntypeArrays",
"stringify",
"calculateAdaptiveWeights",
]
Expand Down
12 changes: 6 additions & 6 deletions src/matrix/matrixCuthillMckee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* Copyright (c) 2013 Mikola Lysenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Expand Down
34 changes: 34 additions & 0 deletions src/utils/__tests__/resursiveUntypeArrays.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { expect, test } from 'vitest';

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

test('basic cases', () => {
expect(recursiveUntypeArrays(1)).toStrictEqual(1);
expect(recursiveUntypeArrays('a')).toStrictEqual('a');
expect(recursiveUntypeArrays({})).toStrictEqual({});
expect(recursiveUntypeArrays([])).toStrictEqual([]);
expect(recursiveUntypeArrays([1, 2, 3])).toStrictEqual([1, 2, 3]);
expect(recursiveUntypeArrays(Float32Array.from([1, 2, 3]))).toStrictEqual([
1, 2, 3,
]);
});

test('simple object', async () => {
const object = {
a: {
b: {
c: Int32Array.from([1, 2, 3]),
},
},
d: [new Int32Array([1, 2, 3]), new Float32Array([3, 4, 5]), 2],
};

expect(recursiveUntypeArrays(object)).toStrictEqual({
a: {
b: {
c: [1, 2, 3],
},
},
d: [[1, 2, 3], [3, 4, 5], 2],
});
});
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export * from './getRescaler';
export * from './isPowerOfTwo';
export * from './nextPowerOfTwo';
export * from './recursiveResolve';
export * from './recursiveUntypeArrays';
export * from './stringify';
export * from './calculateAdaptiveWeights';
28 changes: 28 additions & 0 deletions src/utils/recursiveUntypeArrays.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { NumberArray } from 'cheminfo-types';

/**
* Recursively change the typed arrays to normal arrays
* The changes are done in-place !
* @param object
* @returns
*/
export function recursiveUntypeArrays(object: unknown) {
if (typeof object !== 'object') return object;
object = modifier(object);
return object;
}

function modifier(object: any) {
if (typeof object !== 'object') return object;
if (ArrayBuffer.isView(object)) {
return Array.from(object as NumberArray);
}
for (const key in object) {
if (ArrayBuffer.isView(object[key])) {
object[key] = Array.from(object[key] as NumberArray);
} else if (typeof object[key] === 'object') {
modifier(object[key]);
}
}
return object;
}
Loading