data-structure-typed 2.6.1 → 2.6.2
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/CHANGELOG.md +9 -1
- package/dist/cjs/binary-tree.cjs +2927 -23688
- package/dist/cjs/graph.cjs +845 -2634
- package/dist/cjs/hash.cjs +185 -616
- package/dist/cjs/heap.cjs +266 -818
- package/dist/cjs/index.cjs +5116 -31358
- package/dist/cjs/linked-list.cjs +644 -2615
- package/dist/cjs/matrix.cjs +220 -535
- package/dist/cjs/priority-queue.cjs +266 -818
- package/dist/cjs/queue.cjs +637 -2343
- package/dist/cjs/stack.cjs +124 -530
- package/dist/cjs/trie.cjs +145 -592
- package/dist/cjs-legacy/binary-tree.cjs +4352 -25113
- package/dist/cjs-legacy/graph.cjs +847 -2636
- package/dist/cjs-legacy/hash.cjs +181 -612
- package/dist/cjs-legacy/heap.cjs +266 -818
- package/dist/cjs-legacy/index.cjs +6657 -32899
- package/dist/cjs-legacy/linked-list.cjs +640 -2611
- package/dist/cjs-legacy/matrix.cjs +220 -535
- package/dist/cjs-legacy/priority-queue.cjs +266 -818
- package/dist/cjs-legacy/queue.cjs +634 -2340
- package/dist/cjs-legacy/stack.cjs +124 -530
- package/dist/cjs-legacy/trie.cjs +145 -592
- package/dist/esm/binary-tree.mjs +2927 -23688
- package/dist/esm/graph.mjs +845 -2634
- package/dist/esm/hash.mjs +185 -616
- package/dist/esm/heap.mjs +266 -818
- package/dist/esm/index.mjs +5116 -31358
- package/dist/esm/linked-list.mjs +644 -2615
- package/dist/esm/matrix.mjs +220 -535
- package/dist/esm/priority-queue.mjs +266 -818
- package/dist/esm/queue.mjs +637 -2343
- package/dist/esm/stack.mjs +124 -530
- package/dist/esm/trie.mjs +145 -592
- package/dist/esm-legacy/binary-tree.mjs +4352 -25113
- package/dist/esm-legacy/graph.mjs +847 -2636
- package/dist/esm-legacy/hash.mjs +181 -612
- package/dist/esm-legacy/heap.mjs +266 -818
- package/dist/esm-legacy/index.mjs +6657 -32899
- package/dist/esm-legacy/linked-list.mjs +640 -2611
- package/dist/esm-legacy/matrix.mjs +220 -535
- package/dist/esm-legacy/priority-queue.mjs +266 -818
- package/dist/esm-legacy/queue.mjs +634 -2340
- package/dist/esm-legacy/stack.mjs +124 -530
- package/dist/esm-legacy/trie.mjs +145 -592
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +29 -500
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +38 -563
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +230 -1212
- package/dist/types/data-structures/binary-tree/bst.d.ts +124 -1063
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +99 -854
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +62 -314
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +366 -5057
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +277 -4885
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +253 -3929
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +261 -4782
- package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -44
- package/dist/types/data-structures/graph/directed-graph.d.ts +130 -527
- package/dist/types/data-structures/graph/undirected-graph.d.ts +125 -482
- package/dist/types/data-structures/hash/hash-map.d.ts +132 -562
- package/dist/types/data-structures/heap/heap.d.ts +194 -746
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +120 -809
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -733
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +193 -863
- package/dist/types/data-structures/matrix/matrix.d.ts +159 -474
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -6
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +6 -11
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/data-structures/queue/deque.d.ts +196 -804
- package/dist/types/data-structures/queue/queue.d.ts +99 -585
- package/dist/types/data-structures/stack/stack.d.ts +75 -481
- package/dist/types/data-structures/trie/trie.d.ts +98 -584
- package/dist/umd/data-structure-typed.js +6580 -32822
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +162 -215
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +47 -47
- package/docs-site-docusaurus/docs/api/classes/BST.md +155 -208
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +7 -7
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -29
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +104 -158
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +72 -104
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +67 -101
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +52 -48
- package/docs-site-docusaurus/docs/api/classes/Heap.md +40 -68
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +17 -17
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +38 -38
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +45 -45
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +68 -96
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +57 -52
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +38 -66
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +41 -74
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +38 -66
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +46 -79
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +40 -68
- package/docs-site-docusaurus/docs/api/classes/Queue.md +54 -78
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +171 -225
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -22
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +68 -98
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +4 -4
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +98 -75
- package/docs-site-docusaurus/docs/api/classes/Stack.md +33 -53
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +104 -129
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +57 -124
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +45 -116
- package/docs-site-docusaurus/docs/api/classes/Trie.md +37 -61
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +59 -77
- package/package.json +1 -1
- package/src/data-structures/binary-tree/tree-multi-set.ts +15 -11
|
@@ -141,7 +141,7 @@ properties:
|
|
|
141
141
|
get addFn(): (a, b) => number | undefined;
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
144
|
+
Defined in: [data-structures/matrix/matrix.ts:163](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L163)
|
|
145
145
|
|
|
146
146
|
The above function returns the value of the _addFn property.
|
|
147
147
|
|
|
@@ -161,7 +161,7 @@ The value of the property `_addFn` is being returned.
|
|
|
161
161
|
get cols(): number;
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
164
|
+
Defined in: [data-structures/matrix/matrix.ts:145](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L145)
|
|
165
165
|
|
|
166
166
|
The function returns the value of the protected variable _cols.
|
|
167
167
|
|
|
@@ -181,7 +181,7 @@ The number of columns.
|
|
|
181
181
|
get data(): number[][];
|
|
182
182
|
```
|
|
183
183
|
|
|
184
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
184
|
+
Defined in: [data-structures/matrix/matrix.ts:155](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L155)
|
|
185
185
|
|
|
186
186
|
The function returns a two-dimensional array of numbers.
|
|
187
187
|
|
|
@@ -201,7 +201,7 @@ The data property, which is a two-dimensional array of numbers.
|
|
|
201
201
|
get multiplyFn(): (a, b) => number;
|
|
202
202
|
```
|
|
203
203
|
|
|
204
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
204
|
+
Defined in: [data-structures/matrix/matrix.ts:179](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L179)
|
|
205
205
|
|
|
206
206
|
The function returns the value of the _multiplyFn property.
|
|
207
207
|
|
|
@@ -221,7 +221,7 @@ The `_multiplyFn` property is being returned.
|
|
|
221
221
|
get rows(): number;
|
|
222
222
|
```
|
|
223
223
|
|
|
224
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
224
|
+
Defined in: [data-structures/matrix/matrix.ts:135](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L135)
|
|
225
225
|
|
|
226
226
|
The function returns the number of rows.
|
|
227
227
|
|
|
@@ -241,7 +241,7 @@ The number of rows.
|
|
|
241
241
|
get size(): [number, number];
|
|
242
242
|
```
|
|
243
243
|
|
|
244
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
244
|
+
Defined in: [data-structures/matrix/matrix.ts:186](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L186)
|
|
245
245
|
|
|
246
246
|
Returns [rows, cols] dimensions tuple.
|
|
247
247
|
|
|
@@ -259,7 +259,7 @@ Returns [rows, cols] dimensions tuple.
|
|
|
259
259
|
get subtractFn(): (a, b) => number;
|
|
260
260
|
```
|
|
261
261
|
|
|
262
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
262
|
+
Defined in: [data-structures/matrix/matrix.ts:171](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L171)
|
|
263
263
|
|
|
264
264
|
The function returns the value of the _subtractFn property.
|
|
265
265
|
|
|
@@ -277,7 +277,7 @@ The `_subtractFn` property is being returned.
|
|
|
277
277
|
iterator: IterableIterator<number[]>;
|
|
278
278
|
```
|
|
279
279
|
|
|
280
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
280
|
+
Defined in: [data-structures/matrix/matrix.ts:688](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L688)
|
|
281
281
|
|
|
282
282
|
Iterates over rows.
|
|
283
283
|
|
|
@@ -293,7 +293,7 @@ Iterates over rows.
|
|
|
293
293
|
add(matrix): Matrix | undefined;
|
|
294
294
|
```
|
|
295
295
|
|
|
296
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
296
|
+
Defined in: [data-structures/matrix/matrix.ts:324](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L324)
|
|
297
297
|
|
|
298
298
|
The `add` function adds two matrices together, returning a new matrix with the result.
|
|
299
299
|
|
|
@@ -312,8 +312,6 @@ The `matrix` parameter is an instance of the `Matrix` class.
|
|
|
312
312
|
The `add` method returns a new `Matrix` object that represents the result of adding the
|
|
313
313
|
current matrix with the provided `matrix` parameter.
|
|
314
314
|
|
|
315
|
-
*
|
|
316
|
-
|
|
317
315
|
#### Example
|
|
318
316
|
|
|
319
317
|
```ts
|
|
@@ -348,7 +346,7 @@ current matrix with the provided `matrix` parameter.
|
|
|
348
346
|
clone(): Matrix;
|
|
349
347
|
```
|
|
350
348
|
|
|
351
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
349
|
+
Defined in: [data-structures/matrix/matrix.ts:650](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L650)
|
|
352
350
|
|
|
353
351
|
The `clone` function returns a new instance of the Matrix class with the same data and properties
|
|
354
352
|
as the original instance.
|
|
@@ -368,7 +366,7 @@ and properties as the current instance.
|
|
|
368
366
|
dot(matrix): Matrix | undefined;
|
|
369
367
|
```
|
|
370
368
|
|
|
371
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
369
|
+
Defined in: [data-structures/matrix/matrix.ts:601](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L601)
|
|
372
370
|
|
|
373
371
|
The dot function calculates the dot product of two matrices and returns a new matrix.
|
|
374
372
|
|
|
@@ -386,16 +384,23 @@ The `matrix` parameter is an instance of the `Matrix` class.
|
|
|
386
384
|
|
|
387
385
|
a new Matrix object.
|
|
388
386
|
|
|
389
|
-
*
|
|
390
|
-
|
|
391
387
|
#### Example
|
|
392
388
|
|
|
393
389
|
```ts
|
|
394
390
|
// Dot product of two matrices
|
|
395
|
-
const a = Matrix.from([
|
|
396
|
-
|
|
391
|
+
const a = Matrix.from([
|
|
392
|
+
[1, 2],
|
|
393
|
+
[3, 4]
|
|
394
|
+
]);
|
|
395
|
+
const b = Matrix.from([
|
|
396
|
+
[5, 6],
|
|
397
|
+
[7, 8]
|
|
398
|
+
]);
|
|
397
399
|
const result = a.dot(b);
|
|
398
|
-
console.log(result?.toArray()); // [
|
|
400
|
+
console.log(result?.toArray()); // [
|
|
401
|
+
// [19, 22],
|
|
402
|
+
// [43, 50]
|
|
403
|
+
// ];
|
|
399
404
|
```
|
|
400
405
|
|
|
401
406
|
***
|
|
@@ -406,7 +411,7 @@ a new Matrix object.
|
|
|
406
411
|
flatten(): number[];
|
|
407
412
|
```
|
|
408
413
|
|
|
409
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
414
|
+
Defined in: [data-structures/matrix/matrix.ts:677](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L677)
|
|
410
415
|
|
|
411
416
|
Returns a flat row-major array.
|
|
412
417
|
|
|
@@ -422,7 +427,7 @@ Returns a flat row-major array.
|
|
|
422
427
|
forEach(callback): void;
|
|
423
428
|
```
|
|
424
429
|
|
|
425
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
430
|
+
Defined in: [data-structures/matrix/matrix.ts:709](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L709)
|
|
426
431
|
|
|
427
432
|
Visits each element with its row and column index.
|
|
428
433
|
|
|
@@ -444,7 +449,7 @@ Visits each element with its row and column index.
|
|
|
444
449
|
get(row, col): number | undefined;
|
|
445
450
|
```
|
|
446
451
|
|
|
447
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
452
|
+
Defined in: [data-structures/matrix/matrix.ts:253](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L253)
|
|
448
453
|
|
|
449
454
|
The `get` function returns the value at the specified row and column index if it is a valid index.
|
|
450
455
|
|
|
@@ -471,8 +476,6 @@ retrieve from the data array.
|
|
|
471
476
|
The `get` function returns a number if the provided row and column indices are valid.
|
|
472
477
|
Otherwise, it returns `undefined`.
|
|
473
478
|
|
|
474
|
-
*
|
|
475
|
-
|
|
476
479
|
#### Example
|
|
477
480
|
|
|
478
481
|
```ts
|
|
@@ -501,7 +504,7 @@ Otherwise, it returns `undefined`.
|
|
|
501
504
|
inverse(): Matrix | undefined;
|
|
502
505
|
```
|
|
503
506
|
|
|
504
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
507
|
+
Defined in: [data-structures/matrix/matrix.ts:518](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L518)
|
|
505
508
|
|
|
506
509
|
The `inverse` function calculates the inverse of a square matrix using Gaussian elimination.
|
|
507
510
|
|
|
@@ -511,13 +514,14 @@ The `inverse` function calculates the inverse of a square matrix using Gaussian
|
|
|
511
514
|
|
|
512
515
|
a Matrix object, which represents the inverse of the original matrix.
|
|
513
516
|
|
|
514
|
-
*
|
|
515
|
-
|
|
516
517
|
#### Example
|
|
517
518
|
|
|
518
519
|
```ts
|
|
519
520
|
// Compute the inverse of a 2x2 matrix
|
|
520
|
-
const m = Matrix.from([
|
|
521
|
+
const m = Matrix.from([
|
|
522
|
+
[4, 7],
|
|
523
|
+
[2, 6]
|
|
524
|
+
]);
|
|
521
525
|
const inv = m.inverse();
|
|
522
526
|
console.log(inv); // defined;
|
|
523
527
|
// A * A^-1 should ≈ Identity
|
|
@@ -536,7 +540,7 @@ a Matrix object, which represents the inverse of the original matrix.
|
|
|
536
540
|
isMatchForCalculate(matrix): boolean;
|
|
537
541
|
```
|
|
538
542
|
|
|
539
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
543
|
+
Defined in: [data-structures/matrix/matrix.ts:292](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L292)
|
|
540
544
|
|
|
541
545
|
The function checks if the dimensions of the given matrix match the dimensions of the current
|
|
542
546
|
matrix.
|
|
@@ -563,7 +567,7 @@ a boolean value.
|
|
|
563
567
|
isValidIndex(row, col): boolean;
|
|
564
568
|
```
|
|
565
569
|
|
|
566
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
570
|
+
Defined in: [data-structures/matrix/matrix.ts:640](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L640)
|
|
567
571
|
|
|
568
572
|
The function checks if a given row and column index is valid within a specified range.
|
|
569
573
|
|
|
@@ -597,7 +601,7 @@ A boolean value is being returned.
|
|
|
597
601
|
map(callback): Matrix;
|
|
598
602
|
```
|
|
599
603
|
|
|
600
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
604
|
+
Defined in: [data-structures/matrix/matrix.ts:720](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L720)
|
|
601
605
|
|
|
602
606
|
Maps each element (number → number) and returns a new Matrix.
|
|
603
607
|
|
|
@@ -619,7 +623,7 @@ Maps each element (number → number) and returns a new Matrix.
|
|
|
619
623
|
multiply(matrix): Matrix | undefined;
|
|
620
624
|
```
|
|
621
625
|
|
|
622
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
626
|
+
Defined in: [data-structures/matrix/matrix.ts:422](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L422)
|
|
623
627
|
|
|
624
628
|
The `multiply` function performs matrix multiplication between two matrices and returns the result
|
|
625
629
|
as a new matrix.
|
|
@@ -638,8 +642,6 @@ The `matrix` parameter is an instance of the `Matrix` class.
|
|
|
638
642
|
|
|
639
643
|
a new Matrix object.
|
|
640
644
|
|
|
641
|
-
*
|
|
642
|
-
|
|
643
645
|
#### Example
|
|
644
646
|
|
|
645
647
|
```ts
|
|
@@ -677,7 +679,7 @@ set(
|
|
|
677
679
|
value): boolean;
|
|
678
680
|
```
|
|
679
681
|
|
|
680
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
682
|
+
Defined in: [data-structures/matrix/matrix.ts:278](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L278)
|
|
681
683
|
|
|
682
684
|
The set function updates the value at a specified row and column in a two-dimensional array.
|
|
683
685
|
|
|
@@ -712,8 +714,6 @@ a boolean value. It returns true if the index (row, col) is valid and the value
|
|
|
712
714
|
successfully set in the data array. It returns false if the index is invalid and the value is not
|
|
713
715
|
set.
|
|
714
716
|
|
|
715
|
-
*
|
|
716
|
-
|
|
717
717
|
#### Example
|
|
718
718
|
|
|
719
719
|
```ts
|
|
@@ -733,7 +733,7 @@ set.
|
|
|
733
733
|
subtract(matrix): Matrix | undefined;
|
|
734
734
|
```
|
|
735
735
|
|
|
736
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
736
|
+
Defined in: [data-structures/matrix/matrix.ts:370](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L370)
|
|
737
737
|
|
|
738
738
|
The `subtract` function performs element-wise subtraction between two matrices and returns a new
|
|
739
739
|
matrix with the result.
|
|
@@ -753,16 +753,23 @@ represents the matrix that you want to subtract from the current matrix.
|
|
|
753
753
|
|
|
754
754
|
a new Matrix object with the result of the subtraction operation.
|
|
755
755
|
|
|
756
|
-
*
|
|
757
|
-
|
|
758
756
|
#### Example
|
|
759
757
|
|
|
760
758
|
```ts
|
|
761
759
|
// Element-wise subtraction
|
|
762
|
-
const a = Matrix.from([
|
|
763
|
-
|
|
760
|
+
const a = Matrix.from([
|
|
761
|
+
[5, 6],
|
|
762
|
+
[7, 8]
|
|
763
|
+
]);
|
|
764
|
+
const b = Matrix.from([
|
|
765
|
+
[1, 2],
|
|
766
|
+
[3, 4]
|
|
767
|
+
]);
|
|
764
768
|
const result = a.subtract(b);
|
|
765
|
-
console.log(result?.toArray()); // [
|
|
769
|
+
console.log(result?.toArray()); // [
|
|
770
|
+
// [4, 4],
|
|
771
|
+
// [4, 4]
|
|
772
|
+
// ];
|
|
766
773
|
```
|
|
767
774
|
|
|
768
775
|
***
|
|
@@ -773,7 +780,7 @@ a new Matrix object with the result of the subtraction operation.
|
|
|
773
780
|
toArray(): number[][];
|
|
774
781
|
```
|
|
775
782
|
|
|
776
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
783
|
+
Defined in: [data-structures/matrix/matrix.ts:670](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L670)
|
|
777
784
|
|
|
778
785
|
Returns a deep copy of the data as a plain 2D array.
|
|
779
786
|
|
|
@@ -789,7 +796,7 @@ Returns a deep copy of the data as a plain 2D array.
|
|
|
789
796
|
transpose(): Matrix;
|
|
790
797
|
```
|
|
791
798
|
|
|
792
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
799
|
+
Defined in: [data-structures/matrix/matrix.ts:477](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L477)
|
|
793
800
|
|
|
794
801
|
The transpose function takes a matrix and returns a new matrix that is the transpose of the
|
|
795
802
|
original matrix.
|
|
@@ -800,8 +807,6 @@ original matrix.
|
|
|
800
807
|
|
|
801
808
|
The transpose() function returns a new Matrix object with the transposed data.
|
|
802
809
|
|
|
803
|
-
*
|
|
804
|
-
|
|
805
810
|
#### Example
|
|
806
811
|
|
|
807
812
|
```ts
|
|
@@ -833,7 +838,7 @@ The transpose() function returns a new Matrix object with the transposed data.
|
|
|
833
838
|
static from(data): Matrix;
|
|
834
839
|
```
|
|
835
840
|
|
|
836
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
841
|
+
Defined in: [data-structures/matrix/matrix.ts:224](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L224)
|
|
837
842
|
|
|
838
843
|
Creates a Matrix from a plain 2D array (deep copy).
|
|
839
844
|
|
|
@@ -862,7 +867,7 @@ m.get(0, 1); // 2
|
|
|
862
867
|
static identity(n): Matrix;
|
|
863
868
|
```
|
|
864
869
|
|
|
865
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
870
|
+
Defined in: [data-structures/matrix/matrix.ts:209](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L209)
|
|
866
871
|
|
|
867
872
|
Creates an n×n identity matrix.
|
|
868
873
|
|
|
@@ -890,7 +895,7 @@ const I = Matrix.identity(3); // [[1,0,0],[0,1,0],[0,0,1]]
|
|
|
890
895
|
static zeros(rows, cols): Matrix;
|
|
891
896
|
```
|
|
892
897
|
|
|
893
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
898
|
+
Defined in: [data-structures/matrix/matrix.ts:197](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L197)
|
|
894
899
|
|
|
895
900
|
Creates a rows×cols zero matrix.
|
|
896
901
|
|
|
@@ -928,7 +933,7 @@ protected _addScaledRow(
|
|
|
928
933
|
scalar): void;
|
|
929
934
|
```
|
|
930
935
|
|
|
931
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
936
|
+
Defined in: [data-structures/matrix/matrix.ts:793](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L793)
|
|
932
937
|
|
|
933
938
|
The function `_addScaledRow` multiplies a row in a matrix by a scalar value and adds it to another
|
|
934
939
|
row.
|
|
@@ -968,7 +973,7 @@ source row before adding them to the target row.
|
|
|
968
973
|
protected _scaleRow(row, scalar): void;
|
|
969
974
|
```
|
|
970
975
|
|
|
971
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
976
|
+
Defined in: [data-structures/matrix/matrix.ts:775](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L775)
|
|
972
977
|
|
|
973
978
|
The function scales a specific row in a matrix by a given scalar value.
|
|
974
979
|
|
|
@@ -1000,7 +1005,7 @@ a specific row of a matrix.
|
|
|
1000
1005
|
protected _swapRows(row1, row2): void;
|
|
1001
1006
|
```
|
|
1002
1007
|
|
|
1003
|
-
Defined in: [data-structures/matrix/matrix.ts:
|
|
1008
|
+
Defined in: [data-structures/matrix/matrix.ts:762](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/matrix/matrix.ts#L762)
|
|
1004
1009
|
|
|
1005
1010
|
The function `_swapRows` swaps the positions of two rows in an array.
|
|
1006
1011
|
|