ml-sparse-matrix
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -0,1 +1,8 @@ | ||
## [2.1.0](https://github.com/mljs/sparse-matrix/compare/v2.0.0...v2.1.0) (2021-03-03) | ||
### Features | ||
* add isEmpty function ([e0f8327](https://github.com/mljs/sparse-matrix/commit/e0f8327d58c1a3d508fc120fd5d9b9140156d069)) | ||
# [2.0.0](https://github.com/mljs/sparse-matrix/compare/v1.0.0...v2.0.0) (2019-06-29) | ||
@@ -2,0 +9,0 @@ |
@@ -5,6 +5,10 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var HashTable = require('ml-hash-table'); | ||
var HashTable = _interopDefault(require('ml-hash-table')); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var HashTable__default = /*#__PURE__*/_interopDefaultLegacy(HashTable); | ||
/* eslint-disable no-eval */ | ||
class SparseMatrix { | ||
@@ -19,3 +23,3 @@ constructor(rows, columns, options = {}) { | ||
other.elements.clone(), | ||
other.threshold | ||
other.threshold, | ||
); | ||
@@ -30,6 +34,6 @@ return; | ||
columns = matrix[0].length; | ||
this._init(rows, columns, new HashTable(options), options.threshold); | ||
for (var i = 0; i < rows; i++) { | ||
for (var j = 0; j < columns; j++) { | ||
var value = matrix[i][j]; | ||
this._init(rows, columns, new HashTable__default['default'](options), options.threshold); | ||
for (let i = 0; i < rows; i++) { | ||
for (let j = 0; j < columns; j++) { | ||
let value = matrix[i][j]; | ||
if (this.threshold && Math.abs(value) < this.threshold) value = 0; | ||
@@ -42,3 +46,3 @@ if (value !== 0) { | ||
} else { | ||
this._init(rows, columns, new HashTable(options), options.threshold); | ||
this._init(rows, columns, new HashTable__default['default'](options), options.threshold); | ||
} | ||
@@ -57,3 +61,3 @@ } | ||
const matrix = new SparseMatrix(rows, columns, { initialCapacity: min }); | ||
for (var i = 0; i < min; i++) { | ||
for (let i = 0; i < min; i++) { | ||
matrix.set(i, i, 1); | ||
@@ -70,5 +74,5 @@ } | ||
const copy = new Array(this.rows); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
copy[i] = new Array(this.columns); | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
copy[i][j] = this.get(i, j); | ||
@@ -87,3 +91,3 @@ } | ||
var symmetric = true; | ||
let symmetric = true; | ||
this.forEachNonZero((i, j, v) => { | ||
@@ -151,3 +155,3 @@ if (this.get(j, i) !== v) { | ||
console.warn( | ||
'Number of columns of left matrix are not equal to number of rows of right matrix.' | ||
'Number of columns of left matrix are not equal to number of rows of right matrix.', | ||
); | ||
@@ -179,3 +183,3 @@ } | ||
const result = new SparseMatrix(m * p, n * q, { | ||
initialCapacity: this.cardinality * other.cardinality | ||
initialCapacity: this.cardinality * other.cardinality, | ||
}); | ||
@@ -217,3 +221,3 @@ this.forEachNonZero((i, j, v1) => { | ||
const values = new Array(cardinality); | ||
var idx = 0; | ||
let idx = 0; | ||
this.forEachNonZero((i, j, value) => { | ||
@@ -242,3 +246,3 @@ rows[idx] = i; | ||
let trans = new SparseMatrix(this.columns, this.rows, { | ||
initialCapacity: this.cardinality | ||
initialCapacity: this.cardinality, | ||
}); | ||
@@ -251,2 +255,6 @@ this.forEachNonZero((i, j, value) => { | ||
} | ||
isEmpty() { | ||
return this.rows === 0 || this.columns === 0; | ||
} | ||
} | ||
@@ -263,3 +271,3 @@ | ||
var inplaceOperator = ` | ||
let inplaceOperator = ` | ||
(function %name%(value) { | ||
@@ -271,3 +279,3 @@ if (typeof value === 'number') return this.%name%S(value); | ||
var inplaceOperatorScalar = ` | ||
let inplaceOperatorScalar = ` | ||
(function %name%S(value) { | ||
@@ -279,3 +287,3 @@ this.forEachNonZero((i, j, v) => v %op% value); | ||
var inplaceOperatorMatrix = ` | ||
let inplaceOperatorMatrix = ` | ||
(function %name%M(matrix) { | ||
@@ -290,3 +298,3 @@ matrix.forEachNonZero((i, j, v) => { | ||
var staticOperator = ` | ||
let staticOperator = ` | ||
(function %name%(matrix, value) { | ||
@@ -298,3 +306,3 @@ var newMatrix = new SparseMatrix(matrix); | ||
var inplaceMethod = ` | ||
let inplaceMethod = ` | ||
(function %name%() { | ||
@@ -306,3 +314,3 @@ this.forEachNonZero((i, j, v) => %method%(v)); | ||
var staticMethod = ` | ||
let staticMethod = ` | ||
(function %name%(matrix) { | ||
@@ -327,3 +335,3 @@ var newMatrix = new SparseMatrix(matrix); | ||
['>>', 'signPropagatingRightShift'], | ||
['>>>', 'rightShift', 'zeroFillRightShift'] | ||
['>>>', 'rightShift', 'zeroFillRightShift'], | ||
]; | ||
@@ -336,4 +344,4 @@ | ||
name: operator[i], | ||
op: operator[0] | ||
}) | ||
op: operator[0], | ||
}), | ||
); | ||
@@ -343,4 +351,4 @@ SparseMatrix.prototype[`${operator[i]}S`] = eval( | ||
name: `${operator[i]}S`, | ||
op: operator[0] | ||
}) | ||
op: operator[0], | ||
}), | ||
); | ||
@@ -350,8 +358,8 @@ SparseMatrix.prototype[`${operator[i]}M`] = eval( | ||
name: `${operator[i]}M`, | ||
op: operator[0] | ||
}) | ||
op: operator[0], | ||
}), | ||
); | ||
SparseMatrix[operator[i]] = eval( | ||
fillTemplateFunction(staticOperator, { name: operator[i] }) | ||
fillTemplateFunction(staticOperator, { name: operator[i] }), | ||
); | ||
@@ -361,3 +369,3 @@ } | ||
var methods = [['~', 'not']]; | ||
let methods = [['~', 'not']]; | ||
@@ -392,3 +400,3 @@ [ | ||
'tanh', | ||
'trunc' | ||
'trunc', | ||
].forEach(function (mathMethod) { | ||
@@ -403,7 +411,7 @@ methods.push([`Math.${mathMethod}`, mathMethod]); | ||
name: method[i], | ||
method: method[0] | ||
}) | ||
method: method[0], | ||
}), | ||
); | ||
SparseMatrix[method[i]] = eval( | ||
fillTemplateFunction(staticMethod, { name: method[i] }) | ||
fillTemplateFunction(staticMethod, { name: method[i] }), | ||
); | ||
@@ -410,0 +418,0 @@ } |
{ | ||
"name": "ml-sparse-matrix", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Sparse matrix library", | ||
@@ -38,10 +38,11 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@babel/plugin-transform-modules-commonjs": "^7.4.4", | ||
"eslint": "^6.0.1", | ||
"eslint-config-cheminfo": "^1.20.1", | ||
"eslint-plugin-import": "^2.18.0", | ||
"eslint-plugin-jest": "^22.7.1", | ||
"jest": "^24.8.0", | ||
"rollup": "^1.16.3" | ||
"@babel/plugin-transform-modules-commonjs": "^7.13.8", | ||
"eslint": "^7.21.0", | ||
"eslint-config-cheminfo": "^5.2.3", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-jest": "^24.1.5", | ||
"jest": "^26.6.3", | ||
"prettier": "^2.2.1", | ||
"rollup": "^2.40.0" | ||
} | ||
} |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable no-eval */ | ||
import HashTable from 'ml-hash-table'; | ||
@@ -12,3 +13,3 @@ | ||
other.elements.clone(), | ||
other.threshold | ||
other.threshold, | ||
); | ||
@@ -24,5 +25,5 @@ return; | ||
this._init(rows, columns, new HashTable(options), options.threshold); | ||
for (var i = 0; i < rows; i++) { | ||
for (var j = 0; j < columns; j++) { | ||
var value = matrix[i][j]; | ||
for (let i = 0; i < rows; i++) { | ||
for (let j = 0; j < columns; j++) { | ||
let value = matrix[i][j]; | ||
if (this.threshold && Math.abs(value) < this.threshold) value = 0; | ||
@@ -49,3 +50,3 @@ if (value !== 0) { | ||
const matrix = new SparseMatrix(rows, columns, { initialCapacity: min }); | ||
for (var i = 0; i < min; i++) { | ||
for (let i = 0; i < min; i++) { | ||
matrix.set(i, i, 1); | ||
@@ -62,5 +63,5 @@ } | ||
const copy = new Array(this.rows); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
copy[i] = new Array(this.columns); | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
copy[i][j] = this.get(i, j); | ||
@@ -79,3 +80,3 @@ } | ||
var symmetric = true; | ||
let symmetric = true; | ||
this.forEachNonZero((i, j, v) => { | ||
@@ -143,3 +144,3 @@ if (this.get(j, i) !== v) { | ||
console.warn( | ||
'Number of columns of left matrix are not equal to number of rows of right matrix.' | ||
'Number of columns of left matrix are not equal to number of rows of right matrix.', | ||
); | ||
@@ -171,3 +172,3 @@ } | ||
const result = new SparseMatrix(m * p, n * q, { | ||
initialCapacity: this.cardinality * other.cardinality | ||
initialCapacity: this.cardinality * other.cardinality, | ||
}); | ||
@@ -209,3 +210,3 @@ this.forEachNonZero((i, j, v1) => { | ||
const values = new Array(cardinality); | ||
var idx = 0; | ||
let idx = 0; | ||
this.forEachNonZero((i, j, value) => { | ||
@@ -234,3 +235,3 @@ rows[idx] = i; | ||
let trans = new SparseMatrix(this.columns, this.rows, { | ||
initialCapacity: this.cardinality | ||
initialCapacity: this.cardinality, | ||
}); | ||
@@ -243,2 +244,6 @@ this.forEachNonZero((i, j, value) => { | ||
} | ||
isEmpty() { | ||
return this.rows === 0 || this.columns === 0; | ||
} | ||
} | ||
@@ -255,3 +260,3 @@ | ||
var inplaceOperator = ` | ||
let inplaceOperator = ` | ||
(function %name%(value) { | ||
@@ -263,3 +268,3 @@ if (typeof value === 'number') return this.%name%S(value); | ||
var inplaceOperatorScalar = ` | ||
let inplaceOperatorScalar = ` | ||
(function %name%S(value) { | ||
@@ -271,3 +276,3 @@ this.forEachNonZero((i, j, v) => v %op% value); | ||
var inplaceOperatorMatrix = ` | ||
let inplaceOperatorMatrix = ` | ||
(function %name%M(matrix) { | ||
@@ -282,3 +287,3 @@ matrix.forEachNonZero((i, j, v) => { | ||
var staticOperator = ` | ||
let staticOperator = ` | ||
(function %name%(matrix, value) { | ||
@@ -290,3 +295,3 @@ var newMatrix = new SparseMatrix(matrix); | ||
var inplaceMethod = ` | ||
let inplaceMethod = ` | ||
(function %name%() { | ||
@@ -298,3 +303,3 @@ this.forEachNonZero((i, j, v) => %method%(v)); | ||
var staticMethod = ` | ||
let staticMethod = ` | ||
(function %name%(matrix) { | ||
@@ -319,3 +324,3 @@ var newMatrix = new SparseMatrix(matrix); | ||
['>>', 'signPropagatingRightShift'], | ||
['>>>', 'rightShift', 'zeroFillRightShift'] | ||
['>>>', 'rightShift', 'zeroFillRightShift'], | ||
]; | ||
@@ -328,4 +333,4 @@ | ||
name: operator[i], | ||
op: operator[0] | ||
}) | ||
op: operator[0], | ||
}), | ||
); | ||
@@ -335,4 +340,4 @@ SparseMatrix.prototype[`${operator[i]}S`] = eval( | ||
name: `${operator[i]}S`, | ||
op: operator[0] | ||
}) | ||
op: operator[0], | ||
}), | ||
); | ||
@@ -342,8 +347,8 @@ SparseMatrix.prototype[`${operator[i]}M`] = eval( | ||
name: `${operator[i]}M`, | ||
op: operator[0] | ||
}) | ||
op: operator[0], | ||
}), | ||
); | ||
SparseMatrix[operator[i]] = eval( | ||
fillTemplateFunction(staticOperator, { name: operator[i] }) | ||
fillTemplateFunction(staticOperator, { name: operator[i] }), | ||
); | ||
@@ -353,3 +358,3 @@ } | ||
var methods = [['~', 'not']]; | ||
let methods = [['~', 'not']]; | ||
@@ -384,3 +389,3 @@ [ | ||
'tanh', | ||
'trunc' | ||
'trunc', | ||
].forEach(function (mathMethod) { | ||
@@ -395,7 +400,7 @@ methods.push([`Math.${mathMethod}`, mathMethod]); | ||
name: method[i], | ||
method: method[0] | ||
}) | ||
method: method[0], | ||
}), | ||
); | ||
SparseMatrix[method[i]] = eval( | ||
fillTemplateFunction(staticMethod, { name: method[i] }) | ||
fillTemplateFunction(staticMethod, { name: method[i] }), | ||
); | ||
@@ -402,0 +407,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22638
707
8
13