ml-matrix 6.8.1 → 6.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -20
- package/matrix.d.ts +56 -37
- package/matrix.js +110 -67
- package/matrix.umd.js +1 -1
- package/package.json +13 -15
- package/src/correlation.js +3 -1
- package/src/covariance.js +3 -1
- package/src/dc/nipals.js +3 -1
- package/src/matrix.js +88 -27
- package/src/util.js +14 -30
- package/src/views/columnSelection.js +1 -1
- package/src/views/rowSelection.js +1 -1
- package/src/views/selection.js +6 -5
- package/src/wrap/wrap.js +4 -2
package/src/util.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isAnyArray } from 'is-any-array';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @private
|
|
3
5
|
* Check that a row index is not out of bounds
|
|
@@ -64,46 +66,28 @@ export function checkColumnVector(matrix, vector) {
|
|
|
64
66
|
return vector;
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
export function checkIndices(matrix, rowIndices, columnIndices) {
|
|
68
|
-
return {
|
|
69
|
-
row: checkRowIndices(matrix, rowIndices),
|
|
70
|
-
column: checkColumnIndices(matrix, columnIndices),
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
69
|
export function checkRowIndices(matrix, rowIndices) {
|
|
75
|
-
if (
|
|
76
|
-
throw new TypeError('
|
|
70
|
+
if (!isAnyArray(rowIndices)) {
|
|
71
|
+
throw new TypeError('row indices must be an array');
|
|
77
72
|
}
|
|
78
73
|
|
|
79
|
-
let
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (rowOut) {
|
|
84
|
-
throw new RangeError('row indices are out of range');
|
|
74
|
+
for (let i = 0; i < rowIndices.length; i++) {
|
|
75
|
+
if (rowIndices[i] < 0 || rowIndices[i] >= matrix.rows) {
|
|
76
|
+
throw new RangeError('row indices are out of range');
|
|
77
|
+
}
|
|
85
78
|
}
|
|
86
|
-
|
|
87
|
-
if (!Array.isArray(rowIndices)) rowIndices = Array.from(rowIndices);
|
|
88
|
-
|
|
89
|
-
return rowIndices;
|
|
90
79
|
}
|
|
91
80
|
|
|
92
81
|
export function checkColumnIndices(matrix, columnIndices) {
|
|
93
|
-
if (
|
|
94
|
-
throw new TypeError('
|
|
82
|
+
if (!isAnyArray(columnIndices)) {
|
|
83
|
+
throw new TypeError('column indices must be an array');
|
|
95
84
|
}
|
|
96
85
|
|
|
97
|
-
let
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (columnOut) {
|
|
102
|
-
throw new RangeError('column indices are out of range');
|
|
86
|
+
for (let i = 0; i < columnIndices.length; i++) {
|
|
87
|
+
if (columnIndices[i] < 0 || columnIndices[i] >= matrix.columns) {
|
|
88
|
+
throw new RangeError('column indices are out of range');
|
|
89
|
+
}
|
|
103
90
|
}
|
|
104
|
-
if (!Array.isArray(columnIndices)) columnIndices = Array.from(columnIndices);
|
|
105
|
-
|
|
106
|
-
return columnIndices;
|
|
107
91
|
}
|
|
108
92
|
|
|
109
93
|
export function checkRange(matrix, startRow, endRow, startColumn, endColumn) {
|
|
@@ -4,7 +4,7 @@ import BaseView from './base';
|
|
|
4
4
|
|
|
5
5
|
export default class MatrixColumnSelectionView extends BaseView {
|
|
6
6
|
constructor(matrix, columnIndices) {
|
|
7
|
-
|
|
7
|
+
checkColumnIndices(matrix, columnIndices);
|
|
8
8
|
super(matrix, matrix.rows, columnIndices.length);
|
|
9
9
|
this.columnIndices = columnIndices;
|
|
10
10
|
}
|
|
@@ -4,7 +4,7 @@ import BaseView from './base';
|
|
|
4
4
|
|
|
5
5
|
export default class MatrixRowSelectionView extends BaseView {
|
|
6
6
|
constructor(matrix, rowIndices) {
|
|
7
|
-
|
|
7
|
+
checkRowIndices(matrix, rowIndices);
|
|
8
8
|
super(matrix, rowIndices.length, matrix.columns);
|
|
9
9
|
this.rowIndices = rowIndices;
|
|
10
10
|
}
|
package/src/views/selection.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { checkRowIndices, checkColumnIndices } from '../util';
|
|
2
2
|
|
|
3
3
|
import BaseView from './base';
|
|
4
4
|
|
|
5
5
|
export default class MatrixSelectionView extends BaseView {
|
|
6
6
|
constructor(matrix, rowIndices, columnIndices) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
this.
|
|
7
|
+
checkRowIndices(matrix, rowIndices);
|
|
8
|
+
checkColumnIndices(matrix, columnIndices);
|
|
9
|
+
super(matrix, rowIndices.length, columnIndices.length);
|
|
10
|
+
this.rowIndices = rowIndices;
|
|
11
|
+
this.columnIndices = columnIndices;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
set(rowIndex, columnIndex, value) {
|
package/src/wrap/wrap.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { isAnyArray } from 'is-any-array';
|
|
2
|
+
|
|
1
3
|
import WrapperMatrix1D from './WrapperMatrix1D';
|
|
2
4
|
import WrapperMatrix2D from './WrapperMatrix2D';
|
|
3
5
|
|
|
4
6
|
export function wrap(array, options) {
|
|
5
|
-
if (
|
|
6
|
-
if (array[0] &&
|
|
7
|
+
if (isAnyArray(array)) {
|
|
8
|
+
if (array[0] && isAnyArray(array[0])) {
|
|
7
9
|
return new WrapperMatrix2D(array);
|
|
8
10
|
} else {
|
|
9
11
|
return new WrapperMatrix1D(array, options);
|