From aacabff3e0b6303d0c800a073a7cf79c82c4dbe4 Mon Sep 17 00:00:00 2001 From: Luc Patiny Date: Wed, 16 Oct 2024 16:58:59 +0200 Subject: [PATCH 1/5] feat: update dependencies --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index a48b1c0..6fd148f 100644 --- a/package.json +++ b/package.json @@ -71,14 +71,14 @@ "ml-distance-matrix": "^2.0.1", "ml-fcnnls": "^3.0.0", "ml-fnn": "^5.0.0", - "ml-gsd": "^12.1.3", + "ml-gsd": "^12.1.8", "ml-hash-table": "^1.0.0", "ml-hclust": "^3.1.0", "ml-kernel": "^3.0.0", "ml-kmeans": "^6.0.0", "ml-knn": "^3.0.0", "ml-levenberg-marquardt": "^4.1.3", - "ml-matrix": "^6.11.0", + "ml-matrix": "^6.12.0", "ml-naivebayes": "^4.0.0", "ml-ngmca": "^1.0.0", "ml-pad-array": "^2.0.0", @@ -87,7 +87,7 @@ "ml-pls": "^4.3.2", "ml-random": "^1.0.1", "ml-random-forest": "^2.1.0", - "ml-regression": "^5.0.0", + "ml-regression": "^6.1.0", "ml-savitzky-golay": "^5.0.0", "ml-som": "^0.0.6", "ml-sparse-matrix": "^2.1.0", @@ -95,14 +95,14 @@ "num-sort": "^3.0.0" }, "devDependencies": { - "@babel/plugin-transform-modules-commonjs": "^7.23.3", - "@types/jest": "^29.5.12", + "@babel/plugin-transform-modules-commonjs": "^7.25.7", + "@types/jest": "^29.5.13", "cheminfo-build": "^1.2.0", "eslint": "^8.56.0", "eslint-config-cheminfo": "^9.1.1", "esm": "^3.2.25", "jest": "^29.7.0", - "prettier": "^3.2.4", - "rollup": "^4.9.6" + "prettier": "^3.3.3", + "rollup": "^4.24.0" } } From 5aa5a83180eef420bcf36dbd94c6e4c3e727c974 Mon Sep 17 00:00:00 2001 From: Luc Patiny Date: Thu, 17 Oct 2024 15:29:45 +0200 Subject: [PATCH 2/5] fix: migrate to vitest and update ml-regression --- .eslintrc.yml | 5 ---- eslint.config.mjs | 16 +++++++++++ package.json | 14 +++++----- src/__tests__/index.test.js | 3 ++- src/index.js | 53 ++++++++++++++++++++----------------- 5 files changed, 54 insertions(+), 37 deletions(-) delete mode 100644 .eslintrc.yml create mode 100644 eslint.config.mjs diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index f4ab74d..0000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,5 +0,0 @@ -extends: cheminfo -parserOptions: - sourceType: module -env: - jest: true diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..210a66d --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,16 @@ +import cheminfo from 'eslint-config-cheminfo'; +import globals from 'globals'; + +export default [ + ...cheminfo, + { + languageOptions: { + globals: { + ...globals.node, + }, + }, + rules: { + // "camelcase": "off", + } + } +] \ No newline at end of file diff --git a/package.json b/package.json index 6fd148f..1d1787d 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "prettier": "prettier --check src", "prettier-write": "prettier --write src", "test": "npm run test-only && npm run eslint && npm run prettier", - "test-only": "jest --coverage" + "test-only": "vitest run --coverage" }, "files": [ "src", @@ -87,7 +87,7 @@ "ml-pls": "^4.3.2", "ml-random": "^1.0.1", "ml-random-forest": "^2.1.0", - "ml-regression": "^6.1.0", + "ml-regression": "^6.2.0", "ml-savitzky-golay": "^5.0.0", "ml-som": "^0.0.6", "ml-sparse-matrix": "^2.1.0", @@ -96,13 +96,13 @@ }, "devDependencies": { "@babel/plugin-transform-modules-commonjs": "^7.25.7", - "@types/jest": "^29.5.13", + "@vitest/coverage-v8": "^2.1.3", "cheminfo-build": "^1.2.0", - "eslint": "^8.56.0", - "eslint-config-cheminfo": "^9.1.1", + "eslint": "^9.12.0", + "eslint-config-cheminfo": "^12.0.1", "esm": "^3.2.25", - "jest": "^29.7.0", "prettier": "^3.3.3", - "rollup": "^4.24.0" + "rollup": "^4.24.0", + "vitest": "^2.1.3" } } diff --git a/src/__tests__/index.test.js b/src/__tests__/index.test.js index ae29b38..61c1f93 100644 --- a/src/__tests__/index.test.js +++ b/src/__tests__/index.test.js @@ -1,4 +1,5 @@ -/* eslint-disable import/namespace */ +import { it, describe, expect } from 'vitest'; + import * as ML from '..'; describe('Check all properties are defined', () => { diff --git a/src/index.js b/src/index.js index c49e505..b0af69f 100644 --- a/src/index.js +++ b/src/index.js @@ -2,31 +2,28 @@ /* eslint-disable import/order */ /* eslint-disable import/first */ -import { DecisionTreeClassifier, DecisionTreeRegression } from 'ml-cart'; -import { - RandomForestClassifier, - RandomForestRegression, -} from 'ml-random-forest'; + + // Try to keep this list in the same structure as the README. // Unsupervised learning export { PCA } from 'ml-pca'; -import * as HClust from 'ml-hclust'; -export { HClust }; -import * as KMeans from 'ml-kmeans'; -export { KMeans }; + + + + // Supervised learning -import * as NaiveBayes from 'ml-naivebayes'; -export { NaiveBayes }; + + export { default as KNN } from 'ml-knn'; export { PLS, KOPLS, OPLS, oplsNipals } from 'ml-pls'; -import * as CrossValidation from 'ml-cross-validation'; -export { CrossValidation }; + + export { ConfusionMatrix } from 'ml-confusion-matrix'; -export { DecisionTreeClassifier }; -export { RandomForestClassifier }; + + // Artificial neural networks export { default as FNN } from 'ml-fnn'; @@ -42,13 +39,13 @@ export { TheilSenRegression, RobustPolynomialRegression, } from 'ml-regression'; -export { DecisionTreeRegression }; -export { RandomForestRegression }; + + // Optimization export { levenbergMarquardt } from 'ml-levenberg-marquardt'; -import * as FCNNLS from 'ml-fcnnls'; -export { FCNNLS }; + + // Math import * as MatrixLib from 'ml-matrix'; @@ -61,7 +58,7 @@ const { QrDecomposition, } = MatrixLib; export { - MatrixLib, + Matrix, SVD, EVD, @@ -72,8 +69,7 @@ export { export { SparseMatrix } from 'ml-sparse-matrix'; export { default as Kernel } from 'ml-kernel'; -import { distance, similarity } from 'ml-distance'; -export { distance as Distance, similarity as Similarity }; +export { distance as Distance, similarity as Similarity } from 'ml-distance'; export { default as distanceMatrix } from 'ml-distance-matrix'; export { default as XSadd } from 'ml-xsadd'; export { nGMCA } from 'ml-ngmca'; @@ -90,8 +86,8 @@ export { default as HashTable } from 'ml-hash-table'; export { default as padArray } from 'ml-pad-array'; export { default as binarySearch } from 'binary-search'; export { default as Random } from 'ml-random'; -import * as GSD from 'ml-gsd'; -export { GSD }; + + import min from 'ml-array-min'; import max from 'ml-array-max'; @@ -140,3 +136,12 @@ export const ArrayXY = { equallySpaced, filterX, }; +export { DecisionTreeClassifier, DecisionTreeRegression } from 'ml-cart'; +export { RandomForestClassifier, RandomForestRegression } from 'ml-random-forest'; +export * as HClust from 'ml-hclust'; +export * as KMeans from 'ml-kmeans'; +export * as NaiveBayes from 'ml-naivebayes'; +export * as CrossValidation from 'ml-cross-validation'; +export * as FCNNLS from 'ml-fcnnls'; +export * as MatrixLib from 'ml-matrix'; +export * as GSD from 'ml-gsd'; From c1da1b7b74b8878a78231562274c4e1143c46d97 Mon Sep 17 00:00:00 2001 From: Luc Patiny Date: Thu, 17 Oct 2024 15:30:57 +0200 Subject: [PATCH 3/5] chore: fix prettier --- src/index.js | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/index.js b/src/index.js index b0af69f..d3a3dcd 100644 --- a/src/index.js +++ b/src/index.js @@ -2,29 +2,18 @@ /* eslint-disable import/order */ /* eslint-disable import/first */ - - - // Try to keep this list in the same structure as the README. // Unsupervised learning export { PCA } from 'ml-pca'; - - - - // Supervised learning - export { default as KNN } from 'ml-knn'; export { PLS, KOPLS, OPLS, oplsNipals } from 'ml-pls'; - export { ConfusionMatrix } from 'ml-confusion-matrix'; - - // Artificial neural networks export { default as FNN } from 'ml-fnn'; export { default as SOM } from 'ml-som'; @@ -40,13 +29,9 @@ export { RobustPolynomialRegression, } from 'ml-regression'; - - // Optimization export { levenbergMarquardt } from 'ml-levenberg-marquardt'; - - // Math import * as MatrixLib from 'ml-matrix'; const { @@ -58,7 +43,6 @@ const { QrDecomposition, } = MatrixLib; export { - Matrix, SVD, EVD, @@ -87,8 +71,6 @@ export { default as padArray } from 'ml-pad-array'; export { default as binarySearch } from 'binary-search'; export { default as Random } from 'ml-random'; - - import min from 'ml-array-min'; import max from 'ml-array-max'; import median from 'ml-array-median'; @@ -137,7 +119,10 @@ export const ArrayXY = { filterX, }; export { DecisionTreeClassifier, DecisionTreeRegression } from 'ml-cart'; -export { RandomForestClassifier, RandomForestRegression } from 'ml-random-forest'; +export { + RandomForestClassifier, + RandomForestRegression, +} from 'ml-random-forest'; export * as HClust from 'ml-hclust'; export * as KMeans from 'ml-kmeans'; export * as NaiveBayes from 'ml-naivebayes'; From 681ce9f10265fd371685a7d540234170fd893332 Mon Sep 17 00:00:00 2001 From: Luc Patiny Date: Thu, 17 Oct 2024 17:01:18 +0200 Subject: [PATCH 4/5] chore: add `npm run dupe` to find duplicate dependencies --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 1d1787d..ddefe44 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,9 @@ "description": "Machine learning tools", "main": "src/index.js", "scripts": { - "compile": "rollup -c", "build": "cheminfo-build --root ML", + "compile": "rollup -c", + "dupe": "find-duplicate-dependencies", "eslint": "eslint src --cache", "eslint-fix": "npm run eslint -- --fix", "prepack": "npm run compile", @@ -101,6 +102,7 @@ "eslint": "^9.12.0", "eslint-config-cheminfo": "^12.0.1", "esm": "^3.2.25", + "find-duplicate-dependencies": "^3.0.0", "prettier": "^3.3.3", "rollup": "^4.24.0", "vitest": "^2.1.3" From 53024d94d16eaea68eeb008e4f2e49804773e39b Mon Sep 17 00:00:00 2001 From: Luc Patiny Date: Mon, 21 Oct 2024 08:50:19 +0200 Subject: [PATCH 5/5] test: try to add test to check if we didn't messup with default export --- package.json | 6 ++---- src/__tests__/index.test.js | 30 ++++++++++++++++++++++++++++++ src/index.js | 4 ++-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index ddefe44..c88b149 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,6 @@ "scripts": { "build": "cheminfo-build --root ML", "compile": "rollup -c", - "dupe": "find-duplicate-dependencies", "eslint": "eslint src --cache", "eslint-fix": "npm run eslint -- --fix", "prepack": "npm run compile", @@ -86,13 +85,13 @@ "ml-pca": "^4.1.1", "ml-performance": "^0.2.0", "ml-pls": "^4.3.2", - "ml-random": "^1.0.1", + "ml-random": "^2.0.0", "ml-random-forest": "^2.1.0", "ml-regression": "^6.2.0", "ml-savitzky-golay": "^5.0.0", "ml-som": "^0.0.6", "ml-sparse-matrix": "^2.1.0", - "ml-xsadd": "^2.0.0", + "ml-xsadd": "^3.0.1", "num-sort": "^3.0.0" }, "devDependencies": { @@ -102,7 +101,6 @@ "eslint": "^9.12.0", "eslint-config-cheminfo": "^12.0.1", "esm": "^3.2.25", - "find-duplicate-dependencies": "^3.0.0", "prettier": "^3.3.3", "rollup": "^4.24.0", "vitest": "^2.1.3" diff --git a/src/__tests__/index.test.js b/src/__tests__/index.test.js index 61c1f93..0e65101 100644 --- a/src/__tests__/index.test.js +++ b/src/__tests__/index.test.js @@ -3,7 +3,37 @@ import { it, describe, expect } from 'vitest'; import * as ML from '..'; describe('Check all properties are defined', () => { + const objectsAndNbKeys = { + Distance: 42, + Similarity: 11, + Array: 11, + ArrayXY: 10, + BitArray: 12, + KMeans: 2, + HClust: 2, + NaiveBayes: 2, + CrossValidation: 6, + FCNNLS: 2, + MatrixLib: 36, + GSD: 7, + }; + it.each(Object.keys(ML))('Check %s', (key) => { + // if a function it should key should start with lowercase + // if a class it should key should start with uppercase expect(ML[key]).toBeDefined(); + + if (objectsAndNbKeys[key]) { + expect(typeof ML[key]).toBe('object'); + expect(Object.keys(ML[key]).length).toBe(objectsAndNbKeys[key]); + } else if (key[0] === key[0].toUpperCase()) { + // should be a class + expect(typeof ML[key]).toBe('function'); + expect(typeof ML[key].prototype).toBe('object'); + expect(ML[key].prototype?.constructor).toBe(ML[key]); + } else { + // should be function + expect(typeof ML[key]).toBe('function'); + } }); }); diff --git a/src/index.js b/src/index.js index d3a3dcd..67c7d94 100644 --- a/src/index.js +++ b/src/index.js @@ -55,7 +55,7 @@ export { SparseMatrix } from 'ml-sparse-matrix'; export { default as Kernel } from 'ml-kernel'; export { distance as Distance, similarity as Similarity } from 'ml-distance'; export { default as distanceMatrix } from 'ml-distance-matrix'; -export { default as XSadd } from 'ml-xsadd'; +export { XSadd } from 'ml-xsadd'; export { nGMCA } from 'ml-ngmca'; // Statistics @@ -69,7 +69,7 @@ export { default as BitArray } from 'ml-bit-array'; export { default as HashTable } from 'ml-hash-table'; export { default as padArray } from 'ml-pad-array'; export { default as binarySearch } from 'binary-search'; -export { default as Random } from 'ml-random'; +export { Random } from 'ml-random'; import min from 'ml-array-min'; import max from 'ml-array-max';