@smockle/matrix 3.0.5 → 4.0.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.
Files changed (39) hide show
  1. package/.github/CODEOWNERS +1 -0
  2. package/.github/workflows/publish.yml +33 -0
  3. package/.github/workflows/test.yml +30 -0
  4. package/LICENSE +21 -13
  5. package/README.md +97 -82
  6. package/package.json +28 -39
  7. package/src/__tests__/index.test.ts +540 -0
  8. package/src/index.ts +290 -0
  9. package/tsconfig.json +17 -0
  10. package/.editorconfig +0 -7
  11. package/.eslintignore +0 -1
  12. package/.eslintrc.json +0 -6
  13. package/.flowconfig +0 -27
  14. package/.prettierignore +0 -1
  15. package/.travis.yml +0 -19
  16. package/appveyor.yml +0 -21
  17. package/flow-typed/npm/@std/esm_vx.x.x.js +0 -33
  18. package/flow-typed/npm/codecov_vx.x.x.js +0 -276
  19. package/flow-typed/npm/colortape_vx.x.x.js +0 -80
  20. package/flow-typed/npm/eslint-config-standard_vx.x.x.js +0 -45
  21. package/flow-typed/npm/eslint-plugin-import_vx.x.x.js +0 -333
  22. package/flow-typed/npm/eslint-plugin-node_vx.x.x.js +0 -249
  23. package/flow-typed/npm/eslint-plugin-promise_vx.x.x.js +0 -150
  24. package/flow-typed/npm/eslint-plugin-standard_vx.x.x.js +0 -87
  25. package/flow-typed/npm/eslint_vx.x.x.js +0 -2363
  26. package/flow-typed/npm/flow-bin_v0.x.x.js +0 -6
  27. package/flow-typed/npm/flow-typed_vx.x.x.js +0 -193
  28. package/flow-typed/npm/husky_vx.x.x.js +0 -88
  29. package/flow-typed/npm/jsdoc-to-markdown_vx.x.x.js +0 -95
  30. package/flow-typed/npm/lint-staged_vx.x.x.js +0 -143
  31. package/flow-typed/npm/lodash_v4.x.x.js +0 -530
  32. package/flow-typed/npm/mathjs_vx.x.x.js +0 -5561
  33. package/flow-typed/npm/nyc_vx.x.x.js +0 -108
  34. package/flow-typed/npm/prettier-eslint-cli_vx.x.x.js +0 -74
  35. package/jsdoc.json +0 -6
  36. package/jsdoc2md/README.hbs +0 -41
  37. package/lib/matrix.js +0 -4
  38. package/lib/matrix.mjs +0 -312
  39. package/test/matrix.mjs +0 -243
package/test/matrix.mjs DELETED
@@ -1,243 +0,0 @@
1
- // @flow
2
-
3
- import Matrix from '../lib/matrix'
4
- import test from 'tape'
5
- import util from 'util'
6
- const { inspect } = util
7
-
8
- test('Matrix', function (t) {
9
- t.plan(60)
10
-
11
- // Matrix
12
- const error = new TypeError('Matrix must be a number or array of numbers')
13
- t.ok(Matrix([]) instanceof Matrix, 'instanceof Matrix')
14
- t.throws(Matrix.bind(Matrix, 'string'), error, 'throws string')
15
- t.throws(Matrix.bind(Matrix, ['string']), error, 'throws string array')
16
- t.throws(Matrix.bind(Matrix, [['string']]), error, 'throws 2D string array')
17
- t.throws(Matrix.bind(Matrix, [[1, 2]]), error, 'throws unnecessary nesting')
18
- t.throws(
19
- Matrix.bind(Matrix, [[1, 2], [3, 'string']]),
20
- error,
21
- 'throws mixed type arrays'
22
- )
23
- t.throws(
24
- Matrix.bind(Matrix, [[1, 2], [3], [4, 5]]),
25
- error,
26
- 'throws uneven rows'
27
- )
28
- t.doesNotThrow(Matrix.bind(Matrix, 1), 'does not throw number')
29
- t.doesNotThrow(Matrix.bind(Matrix, [1]), 'does not throw number array')
30
- t.doesNotThrow(
31
- Matrix.bind(Matrix, [[1], [2]]),
32
- 'does not throw 2D number array'
33
- )
34
-
35
- // Matrix.addable
36
- t.notOk(Matrix.addable('string', Matrix([3])), 'addable string and matrix')
37
- t.notOk(Matrix.addable(Matrix([3]), 'string'), 'addable matrix and string')
38
- t.notOk(
39
- Matrix.addable(Matrix([[1, 2], [3, 4]]), Matrix([[1, 2, 3], [4, 5, 6]])),
40
- 'addable mismatched columns'
41
- )
42
- t.notOk(
43
- Matrix.addable(Matrix([[1, 2], [3, 4]]), Matrix([[1, 2], [4, 5], [7, 8]])),
44
- 'addable mismatched rows'
45
- )
46
- t.ok(
47
- Matrix.addable(Matrix([[1, 2], [3, 4]]), Matrix([[5, 6], [7, 8]])),
48
- 'addable'
49
- )
50
-
51
- // Matrix#addable
52
- t.notOk(Matrix([3]).addable('string'), 'addable matrix and string')
53
- t.notOk(
54
- Matrix([[1, 2], [3, 4]]).addable(Matrix([[1, 2, 3], [4, 5, 6]])),
55
- 'addable mismatched columns'
56
- )
57
- t.notOk(
58
- Matrix([[1, 2], [3, 4]]).addable(Matrix([[1, 2], [4, 5], [7, 8]])),
59
- 'addable mismatched rows'
60
- )
61
- t.ok(Matrix([[1, 2], [3, 4]]).addable(Matrix([[5, 6], [7, 8]])), 'addable')
62
-
63
- // Matrix.add
64
- t.throws(
65
- Matrix.add.bind(
66
- Matrix,
67
- Matrix([[1, 2], [3, 4]]),
68
- Matrix([[1, 2, 3], [4, 5, 6]])
69
- ),
70
- new TypeError('Matrices are not addable'),
71
- 'add throws typerror'
72
- )
73
- t.deepEqual(
74
- Matrix.add(Matrix([[1, 2], [3, 4]]), Matrix([[5, 6], [7, 8]])),
75
- Matrix([[6, 8], [10, 12]]),
76
- 'add'
77
- )
78
-
79
- // Matrix#add
80
- const addmatrix = Matrix([[1, 2], [3, 4]])
81
- t.throws(
82
- addmatrix.add.bind(addmatrix, Matrix([[1, 2, 3], [4, 5, 6]])),
83
- new TypeError('Matrices are not addable'),
84
- 'add throws typerror'
85
- )
86
- t.deepEqual(
87
- Matrix([[1, 2], [3, 4]]).add(Matrix([[5, 6], [7, 8]])),
88
- Matrix([[6, 8], [10, 12]]),
89
- 'add'
90
- )
91
-
92
- // Matrix.multipliable
93
- t.notOk(
94
- Matrix.multipliable('string', Matrix([3])),
95
- 'multipliable string and matrix'
96
- )
97
- t.notOk(
98
- Matrix.multipliable(Matrix([3]), 'string'),
99
- 'multipliable matrix and string'
100
- )
101
- t.notOk(
102
- Matrix.multipliable(
103
- Matrix([[1, 2, 3], [4, 5, 6]]),
104
- Matrix([[1, 2], [4, 5]])
105
- ),
106
- 'multipliable mismatched columns and rows'
107
- )
108
- t.ok(
109
- Matrix.multipliable(Matrix([[1, 2], [3, 4]]), Matrix([[5, 6], [7, 8]])),
110
- 'multipliable'
111
- )
112
-
113
- // Matrix#multipliable
114
- t.notOk(Matrix([3]).multipliable('string'), 'multipliable matrix and string')
115
- t.notOk(
116
- Matrix([[1, 2, 3], [4, 5, 6]]).multipliable(Matrix([[1, 2], [4, 5]])),
117
- 'multipliable mismatched columns and rows'
118
- )
119
- t.ok(
120
- Matrix([[1, 2], [3, 4]]).multipliable(Matrix([[5, 6], [7, 8]])),
121
- 'multipliable'
122
- )
123
-
124
- // Matrix.multiply
125
- const multiplymatrix = Matrix([1, 2, 3])
126
- t.throws(
127
- multiplymatrix.multiply.bind(multiplymatrix, Matrix([1, 2], [3, 4])),
128
- new TypeError('Matrices are not multipliable'),
129
- 'multiply throws typerror'
130
- )
131
- t.deepEqual(Matrix(3).multiply(Matrix(6)), Matrix(18), 'multiply number')
132
- t.deepEqual(
133
- Matrix([1, 2]).multiply(Matrix([[3], [4]])),
134
- Matrix([11]),
135
- 'multiply A (1x2) and B (2x1)'
136
- )
137
- t.deepEqual(
138
- Matrix([[1, 2], [3, 4]]).multiply(Matrix([[5, 6], [7, 8]])),
139
- Matrix([[19, 22], [43, 50]]),
140
- 'multiply A (2x2) and B (2x2)'
141
- )
142
- t.deepEqual(
143
- Matrix([[1, 9, 7], [8, 1, 2]]).multiply(
144
- Matrix([[3, 2, 1, 5], [5, 4, 7, 3], [6, 9, 6, 8]])
145
- ),
146
- Matrix([[90, 101, 106, 88], [41, 38, 27, 59]]),
147
- 'multiply A (2x3) and B (3x4)'
148
- )
149
-
150
- // Matrix#multiply
151
- t.throws(
152
- Matrix.multiply.bind(Matrix, Matrix([1, 2, 3]), Matrix([1, 2], [3, 4])),
153
- new TypeError('Matrices are not multipliable'),
154
- 'multiply throws typerror'
155
- )
156
- t.deepEqual(
157
- Matrix.multiply(Matrix(3), Matrix(6)),
158
- Matrix(18),
159
- 'multiply number'
160
- )
161
- t.deepEqual(
162
- Matrix.multiply(Matrix([1, 2]), Matrix([[3], [4]])),
163
- Matrix([11]),
164
- 'multiply A (1x2) and B (2x1)'
165
- )
166
- t.deepEqual(
167
- Matrix.multiply(Matrix([[1, 2], [3, 4]]), Matrix([[5, 6], [7, 8]])),
168
- Matrix([[19, 22], [43, 50]]),
169
- 'multiply A (2x2) and B (2x2)'
170
- )
171
- t.deepEqual(
172
- Matrix.multiply(
173
- Matrix([[1, 9, 7], [8, 1, 2]]),
174
- Matrix([[3, 2, 1, 5], [5, 4, 7, 3], [6, 9, 6, 8]])
175
- ),
176
- Matrix([[90, 101, 106, 88], [41, 38, 27, 59]]),
177
- 'multiply A (2x3) and B (3x4)'
178
- )
179
-
180
- // Matrix#valueOf
181
- const array = [3]
182
- t.equal(Matrix(array).valueOf(), array, 'valueOf Matrix')
183
-
184
- // Matrix#countRows
185
- t.equal(Matrix(1).countRows(), 0, 'countRows number')
186
- t.equal(Matrix([1]).countRows(), 1, 'countRows number array')
187
- t.equal(
188
- Matrix([[1, 2], [3, 4], [5, 6]]).countRows(),
189
- 3,
190
- 'countRows 2D number array'
191
- )
192
-
193
- // Matrix#countColumns
194
- t.equal(Matrix(1).countColumns(), 0, 'countColumns number')
195
- t.equal(Matrix([1]).countColumns(), 1, 'countColumns number array')
196
- t.equal(Matrix([[1], [2]]).countColumns(), 1, 'countColumns 2D number array')
197
- t.equal(
198
- Matrix([[1, 2], [3, 4], [5, 6]]).countColumns(),
199
- 2,
200
- 'countColumns many 2D number array'
201
- )
202
-
203
- // Matrix#transpose
204
- t.deepEqual(Matrix(1).transpose(), Matrix(1), 'transpose number')
205
- t.deepEqual(
206
- Matrix([1, 2]).transpose(),
207
- Matrix([[1], [2]]),
208
- 'transpose number array'
209
- )
210
- t.deepEqual(
211
- Matrix([[1, 2, 3], [4, 5, 6]]).transpose(),
212
- Matrix([[1, 4], [2, 5], [3, 6]]),
213
- 'transpose 2D number array'
214
- )
215
-
216
- // Matrix#invert
217
- t.deepEqual(
218
- Matrix([[1, 2], [3, 4]]).invert(),
219
- Matrix([[-2, 1], [1.5, -0.5]]),
220
- 'invert 2D number array'
221
- )
222
-
223
- // Matrix#map
224
- const matrix = Matrix([1, 2, 3])
225
- t.ok(matrix.map(x => x + 1) instanceof Matrix, 'map returns a matrix')
226
- t.deepEqual(matrix.map(x => x), matrix, 'map identity')
227
- t.deepEqual(matrix.map(x => x + 1), Matrix([2, 3, 4]), 'map increment')
228
- t.deepEqual(matrix, Matrix([1, 2, 3]), 'map non-mutable')
229
-
230
- // Matrix#inspect
231
- t.equal(inspect(Matrix(3)), '3', 'inspect number')
232
- t.equal(inspect(Matrix([1, 2, 3])), '[ 1 2 3 ]', 'inspect number array')
233
- t.equal(
234
- inspect(Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])),
235
- '[ 1 2 3 ]\n[ 4 5 6 ]\n[ 7 8 9 ]',
236
- 'inspect 2D number array'
237
- )
238
- t.equal(
239
- inspect(Matrix([[1, 2, 3], [-10, 11, -12], [100, 0, 0]])),
240
- '[ 1 2 3 ]\n[ -10 11 -12 ]\n[ 100 0 0 ]',
241
- 'inspect padded 2D number array'
242
- )
243
- })