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
3 changes: 0 additions & 3 deletions .eslintrc.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/documentationjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ name: Node.js CI
on:
push:
branches:
- master
- main
pull_request:

jobs:
nodejs:
# 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
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release
on:
push:
branches:
- master
- main

jobs:
release:
Expand All @@ -14,4 +14,3 @@ jobs:
secrets:
github-token: ${{ secrets.BOT_TOKEN }}
npm-token: ${{ secrets.NPM_BOT_TOKEN }}

1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md
12 changes: 6 additions & 6 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"arrowParens": "always",
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all"
}
"arrowParens": "always",
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all"
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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
3 changes: 0 additions & 3 deletions babel.config.js

This file was deleted.

78 changes: 39 additions & 39 deletions benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Check warning on line 5 in benchmark/benchmark.js

View check run for this annotation

Codecov / codecov/patch

benchmark/benchmark.js#L5

Added line #L5 was not covered by tests
//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];

Check warning on line 9 in benchmark/benchmark.js

View check run for this annotation

Codecov / codecov/patch

benchmark/benchmark.js#L8-L9

Added lines #L8 - L9 were not covered by tests

var timesNormal = new Array(ns.length);
var timesFFT = new Array(ns.length);

for(var ni=0;ni<ns.length;ni++){
console.log("Matrix rows "+ni);
timesNormal[ni]=new Array(nks.length);
timesFFT[ni]=new Array(nks.length);
for (var ni = 0; ni < ns.length; ni++) {
console.log('Matrix rows ' + ni);
timesNormal[ni] = new Array(nks.length);
timesFFT[ni] = new Array(nks.length);

Check warning on line 17 in benchmark/benchmark.js

View check run for this annotation

Codecov / codecov/patch

benchmark/benchmark.js#L14-L17

Added lines #L14 - L17 were not covered by tests

for(var nki=nks.length-1;nki>=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 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;
}
}
for (var nki = nks.length - 1; nki >= 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;
}
}

Check warning on line 26 in benchmark/benchmark.js

View check run for this annotation

Codecov / codecov/patch

benchmark/benchmark.js#L19-L26

Added lines #L19 - L26 were not covered by tests

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;
}

Check warning on line 34 in benchmark/benchmark.js

View check run for this annotation

Codecov / codecov/patch

benchmark/benchmark.js#L28-L34

Added lines #L28 - L34 were not covered by tests
}

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;
}

Check warning on line 47 in benchmark/benchmark.js

View check run for this annotation

Codecov / codecov/patch

benchmark/benchmark.js#L37-L47

Added lines #L37 - L47 were not covered by tests
}

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');

Check warning on line 52 in benchmark/benchmark.js

View check run for this annotation

Codecov / codecov/patch

benchmark/benchmark.js#L50-L52

Added lines #L50 - L52 were not covered by tests
console.log(timesNormal);
console.log("FFT");
console.log('FFT');

Check warning on line 54 in benchmark/benchmark.js

View check run for this annotation

Codecov / codecov/patch

benchmark/benchmark.js#L54

Added line #L54 was not covered by tests
console.log(timesFFT);
/*
// add tests
Expand All @@ -70,4 +70,4 @@
})
// run async
.run({ 'async': true });
*/
*/

Check warning on line 73 in benchmark/benchmark.js

View check run for this annotation

Codecov / codecov/patch

benchmark/benchmark.js#L73

Added line #L73 was not covered by tests
4 changes: 4 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -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);
38 changes: 21 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
8 changes: 0 additions & 8 deletions rollup.config.js

This file was deleted.

2 changes: 2 additions & 0 deletions src/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { describe, expect, it } from 'vitest';

import * as MatrixConvolution from '..';

Expand Down Expand Up @@ -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);
});
Expand Down
13 changes: 8 additions & 5 deletions src/convolutionDirect.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
13 changes: 8 additions & 5 deletions src/convolutionFFT.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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,
};
4 changes: 4 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["**/__tests__", "**/*.test.ts"]
}
20 changes: 20 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}