diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index f40ac5c..0000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,3 +0,0 @@ -extends: cheminfo -parserOptions: - sourceType: module diff --git a/.github/workflows/documentationjs.yml b/.github/workflows/documentationjs.yml index 0ae90e1..4ccf44f 100644 --- a/.github/workflows/documentationjs.yml +++ b/.github/workflows/documentationjs.yml @@ -9,7 +9,7 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Build documentation uses: zakodium/documentationjs-action@v1 - name: Deploy to GitHub pages diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 0ea7496..71e0af2 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -3,7 +3,7 @@ name: Node.js CI on: push: branches: - - master + - main pull_request: jobs: @@ -11,4 +11,4 @@ jobs: # Documentation: https://github.com/zakodium/workflows#nodejs-ci uses: zakodium/workflows/.github/workflows/nodejs.yml@nodejs-v1 with: - node-version-matrix: '[12, 14, 16]' + lint-check-types: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 23bb3c4..7f5db58 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,7 @@ name: Release on: push: branches: - - master + - main jobs: release: @@ -14,4 +14,3 @@ jobs: secrets: github-token: ${{ secrets.BOT_TOKEN }} npm-token: ${{ secrets.NPM_BOT_TOKEN }} - diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..1b763b1 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +CHANGELOG.md diff --git a/.prettierrc.json b/.prettierrc.json index 89b7de8..a23e760 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,7 +1,7 @@ { - "arrowParens": "always", - "semi": true, - "singleQuote": true, - "tabWidth": 2, - "trailingComma": "all" - } \ No newline at end of file + "arrowParens": "always", + "semi": true, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "all" +} diff --git a/README.md b/README.md index f55f91d..d0b5c26 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # ml-matrix-convolution [![NPM version][npm-image]][npm-url] -[![build status][ci-image]][ci-url] -[![Test coverage][codecov-image]][codecov-url] [![npm download][download-image]][download-url] +[![test coverage][codecov-image]][codecov-url] +[![license][license-image]][license-url] Matrix convolution. @@ -45,7 +45,7 @@ console.log({ conv1, conv2 }); // both should be equal [npm-url]: https://npmjs.org/package/ml-matrix-convolution [codecov-image]: https://img.shields.io/codecov/c/github/mljs/matrix-convolution.svg [codecov-url]: https://codecov.io/gh/mljs/matrix-convolution -[ci-image]: https://github.com/mljs/matrix-convolution/workflows/Node.js%20CI/badge.svg?branch=master -[ci-url]: https://github.com/mljs/matrix-convolution/actions?query=workflow%3A%22Node.js+CI%22 [download-image]: https://img.shields.io/npm/dm/ml-matrix-convolution.svg [download-url]: https://npmjs.org/package/ml-matrix-convolution +[license-image]: https://img.shields.io/npm/l/ml-matrix-convolution.svg +[license-url]: https://github.com/image-js/ml-matrix-convolution/blob/main/LICENSE diff --git a/babel.config.js b/babel.config.js deleted file mode 100644 index 18b6e17..0000000 --- a/babel.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - plugins: ['@babel/plugin-transform-modules-commonjs'], -}; diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js index 50175bd..89c8b86 100644 --- a/benchmark/benchmark.js +++ b/benchmark/benchmark.js @@ -2,56 +2,56 @@ * Created by acastillo on 7/12/16. */ //var Benchmark = require('benchmark'); -var convolution = require("../src/index"); +var convolution = require('../src/index'); //var suite = new Benchmark.Suite; -var ns = [256,300,512,600,1024]; -var nks = [3,5,11,19,27,33,37]; +var ns = [256, 300, 512, 600, 1024]; +var nks = [3, 5, 11, 19, 27, 33, 37]; var timesNormal = new Array(ns.length); var timesFFT = new Array(ns.length); -for(var ni=0;ni=0;nki--){ - var n=ns[ni]; - var data = new Array(n*n);//Uint32Array(n*n); - for(var i=0;i= 0; nki--) { + var n = ns[ni]; + var data = new Array(n * n); //Uint32Array(n*n); + for (var i = 0; i < n; i++) { + for (var j = 0; j < n; j++) { + data[i * n + j] = i + j; + } + } - var d = new Date(); - var start = d.getTime(); - var result1 = convolution.direct(data, kernel, {rows:n,cols:n}); - var d0 = new Date(); - timesNormal[ni][nki]=(d0.getTime()-start); - var d2 = new Date(); - start = d2.getTime(); - var result2 = convolution.fft(data, kernel, {rows:n,cols:n}); - var d3 = new Date(); - timesFFT[ni][nki]=(d3.getTime()-start); + var kn = nks[nki]; + var kernel = new Array(kn); + for (var i = 0; i < kn; i++) { + kernel[i] = new Array(kn); + for (var j = 0; j < kn; j++) { + kernel[i][j] = i + j; + } } + + var d = new Date(); + var start = d.getTime(); + var result1 = convolution.direct(data, kernel, { rows: n, cols: n }); + var d0 = new Date(); + timesNormal[ni][nki] = d0.getTime() - start; + var d2 = new Date(); + start = d2.getTime(); + var result2 = convolution.fft(data, kernel, { rows: n, cols: n }); + var d3 = new Date(); + timesFFT[ni][nki] = d3.getTime() - start; + } } -console.log("Rows: Matrix size h/w "+ns.join(",")); -console.log("Columns: Filter size h/w "+nks.join(",")); -console.log("Normal"); +console.log('Rows: Matrix size h/w ' + ns.join(',')); +console.log('Columns: Filter size h/w ' + nks.join(',')); +console.log('Normal'); console.log(timesNormal); -console.log("FFT"); +console.log('FFT'); console.log(timesFFT); /* // add tests @@ -70,4 +70,4 @@ suite.add('RegExp#test', function() { }) // run async .run({ 'async': true }); -*/ \ No newline at end of file +*/ diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..9ec2bd3 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,4 @@ +import { defineConfig, globalIgnores } from 'eslint/config'; +import ts from 'eslint-config-cheminfo-typescript/base'; + +export default defineConfig(globalIgnores(['benchmark', 'lib']), ts); diff --git a/package.json b/package.json index f657dd2..f1c3849 100644 --- a/package.json +++ b/package.json @@ -2,21 +2,24 @@ "name": "ml-matrix-convolution", "version": "1.0.0", "description": "Matrix convolution: It offers the direct and the fourier transform convolution", - "main": "lib/index.js", - "module": "src/index.js", + "type": "module", + "exports": "./lib/index.js", "files": [ "lib", "src" ], "scripts": { - "compile": "npm run prepack", - "eslint": "eslint src", + "check-types": "tsc --noEmit", + "clean": "rimraf lib", + "eslint": "eslint .", "eslint-fix": "npm run eslint -- --fix", - "prepack": "rollup -c", - "prettier": "prettier --check src", - "prettier-write": "prettier --write src", - "test": "npm run test-only && npm run eslint && npm run prettier", - "test-only": "jest --coverage" + "prepack": "npm run tsc", + "prettier": "prettier --check .", + "prettier-write": "prettier --write .", + "test": "npm run test-only && npm run check-types && npm run eslint && npm run prettier", + "test-only": "vitest run --coverage", + "tsc": "npm run clean && npm run tsc-build", + "tsc-build": "tsc --project tsconfig.build.json" }, "repository": { "type": "git", @@ -36,16 +39,17 @@ }, "homepage": "https://github.com/mljs/matrix-convolution#readme", "devDependencies": { - "@babel/plugin-transform-modules-commonjs": "^7.16.8", - "@types/jest": "^27.4.1", - "eslint": "^8.10.0", - "eslint-config-cheminfo": "^7.2.2", - "jest": "^27.5.1", + "@types/node": "^22.15.21", + "@vitest/coverage-v8": "^3.1.4", + "eslint": "^9.27.0", + "eslint-config-cheminfo-typescript": "^18.0.1", "jest-matcher-deep-close-to": "^3.0.2", - "prettier": "^2.5.1", - "rollup": "^2.69.0" + "prettier": "^3.5.3", + "rimraf": "^6.0.1", + "typescript": "^5.8.3", + "vitest": "^3.1.4" }, "dependencies": { - "ml-fft": "1.3.5" + "ml-fft": "^1.3.5" } } diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index 85f3c55..0000000 --- a/rollup.config.js +++ /dev/null @@ -1,8 +0,0 @@ -export default { - input: 'src/index.js', - output: { - format: 'cjs', - file: 'lib/index.js', - }, - external: ['ml-fft'], -}; diff --git a/src/__tests__/index.test.js b/src/__tests__/index.test.js index 5ffb612..03a94c8 100644 --- a/src/__tests__/index.test.js +++ b/src/__tests__/index.test.js @@ -1,4 +1,5 @@ import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to'; +import { describe, expect, it } from 'vitest'; import * as MatrixConvolution from '..'; @@ -67,6 +68,7 @@ describe('FFT convolution', () => { describe('KernelFatory', () => { it('LoG', () => { + // eslint-disable-next-line new-cap let kernel = MatrixConvolution.kernelFactory.LoG(1.4, 9, { factor: 40 }); expect(kernel).toMatchCloseTo(smallFilter, 1e-8); }); diff --git a/src/convolutionDirect.js b/src/convolutionDirect.js index 0fdf514..77bcdf8 100644 --- a/src/convolutionDirect.js +++ b/src/convolutionDirect.js @@ -1,12 +1,15 @@ -import { matrix2Array } from './util/matrix2Array'; +import { matrix2Array } from './util/matrix2Array.js'; export function convolutionDirect(input, kernel, opt) { let tmp = matrix2Array(input); let inputData = tmp.data; - let options = Object.assign( - { normalize: false, divisor: 1, rows: tmp.rows, cols: tmp.cols }, - opt, - ); + let options = { + normalize: false, + divisor: 1, + rows: tmp.rows, + cols: tmp.cols, + ...opt, + }; let nRows, nCols; if (options.rows && options.cols) { diff --git a/src/convolutionFFT.js b/src/convolutionFFT.js index a16f101..bb46a8e 100644 --- a/src/convolutionFFT.js +++ b/src/convolutionFFT.js @@ -1,14 +1,17 @@ import { FFTUtils } from 'ml-fft'; -import { matrix2Array } from './util/matrix2Array'; +import { matrix2Array } from './util/matrix2Array.js'; export function convolutionFFT(input, kernel, opt) { let tmp = matrix2Array(input); let inputData = tmp.data; - let options = Object.assign( - { normalize: false, divisor: 1, rows: tmp.rows, cols: tmp.cols }, - opt, - ); + let options = { + normalize: false, + divisor: 1, + rows: tmp.rows, + cols: tmp.cols, + ...opt, + }; let nRows, nCols; if (options.rows && options.cols) { diff --git a/src/index.js b/src/index.js index 6fcecb0..d0116fa 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,8 @@ -import { LoG } from './util/LoG'; +import { LoG } from './util/LoG.js'; -export { convolutionFFT as fft } from './convolutionFFT'; -export { convolutionDirect as direct } from './convolutionDirect'; -export { matrix2Array } from './util/matrix2Array'; +export { convolutionFFT as fft } from './convolutionFFT.js'; +export { convolutionDirect as direct } from './convolutionDirect.js'; +export { matrix2Array } from './util/matrix2Array.js'; export const kernelFactory = { - LoG: LoG, + LoG, }; diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..5daa1ea --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["**/__tests__", "**/*.test.ts"] +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..41ea82f --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "lib": ["ES2022", "WebWorker"], + "types": [], + "target": "ES2022", + "outDir": "lib", + "module": "NodeNext", + "strict": true, + "skipLibCheck": false, + "resolveJsonModule": false, + "forceConsistentCasingInFileNames": true, + "allowJs": true, + "isolatedModules": true, + "verbatimModuleSyntax": true, + "sourceMap": true, + "declaration": true, + "declarationMap": true + }, + "include": ["src"] +}