-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmatrix.dart
830 lines (740 loc) · 21.6 KB
/
matrix.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
import 'dart:typed_data';
import 'package:ml_linalg/axis.dart';
import 'package:ml_linalg/decomposition.dart';
import 'package:ml_linalg/dtype.dart';
import 'package:ml_linalg/inverse.dart';
import 'package:ml_linalg/matrix_norm.dart';
import 'package:ml_linalg/sort_direction.dart';
import 'package:ml_linalg/src/common/exception/unimplemented_matrix_exception.dart';
import 'package:ml_linalg/src/matrix/eigen_method.dart';
import 'package:ml_linalg/src/matrix/float32_matrix.dart';
import 'package:ml_linalg/src/matrix/float64_matrix.g.dart';
import 'package:ml_linalg/src/matrix/serialization/from_matrix_json.dart';
import 'package:ml_linalg/vector.dart';
import 'src/matrix/eigen.dart';
/// An algebraic matrix with extended functionality, adapted for data science
/// applications
abstract class Matrix implements Iterable<Iterable<double>> {
/// Creates a matrix from a two dimensional list, every nested list is a
/// source for a matrix row.
///
/// A simple usage example:
///
/// ````dart
/// import 'package:ml_linalg/matrix.dart';
///
/// void main() {
/// final matrix = Matrix.fromList([
/// [1, 2, 3, 4, 5],
/// [6, 7, 8, 9, 0],
/// ]);
///
/// print(matrix);
/// }
/// ````
///
/// The output:
///
/// ```
/// Matrix 2 x 5:
/// (1.0, 2.0, 3.0, 4.0, 5.0)
/// (6.0, 7.0, 8.0, 9.0, 0.0)
/// ```
factory Matrix.fromList(
List<List<double>> source, {
DType dtype = DType.float32,
}) {
switch (dtype) {
case DType.float32:
return Float32Matrix.fromList(source);
case DType.float64:
return Float64Matrix.fromList(source);
default:
throw UnimplementedMatrixException(dtype);
}
}
/// Creates a matrix with predefined row vectors
///
/// A simple usage example:
///
/// ````dart
/// import 'package:ml_linalg/matrix.dart';
/// import 'package:ml_linalg/vector.dart';
///
/// void main() {
/// final matrix = Matrix.fromRows([
/// Vector.fromList([1, 2, 3, 4, 5]),
/// Vector.fromList([6, 7, 8, 9, 0]),
/// ]);
///
/// print(matrix);
/// }
/// ````
///
/// The output:
///
/// ```
/// Matrix 2 x 5:
/// (1.0, 2.0, 3.0, 4.0, 5.0)
/// (6.0, 7.0, 8.0, 9.0, 0.0)
/// ```
factory Matrix.fromRows(List<Vector> source, {DType dtype = DType.float32}) {
switch (dtype) {
case DType.float32:
return Float32Matrix.fromRows(source);
case DType.float64:
return Float64Matrix.fromRows(source);
default:
throw UnimplementedMatrixException(dtype);
}
}
/// Creates a matrix with predefined column vectors
///
/// A simple usage example:
///
/// ````dart
/// import 'package:ml_linalg/matrix.dart';
/// import 'package:ml_linalg/vector.dart';
///
/// void main() {
/// final matrix = Matrix.fromColumns([
/// Vector.fromList([1, 2, 3, 4, 5]),
/// Vector.fromList([6, 7, 8, 9, 0]),
/// ]);
///
/// print(matrix);
/// }
/// ````
///
/// The output:
///
/// ```
/// Matrix 5 x 2:
/// (1.0, 6.0)
/// (2.0, 7.0)
/// (3.0, 8.0)
/// (4.0, 9.0)
/// (5.0, 0.0)
/// ```
factory Matrix.fromColumns(
List<Vector> source, {
DType dtype = DType.float32,
}) {
switch (dtype) {
case DType.float32:
return Float32Matrix.fromColumns(source);
case DType.float64:
return Float64Matrix.fromColumns(source);
default:
throw UnimplementedMatrixException(dtype);
}
}
/// Creates a matrix of shape 0 x 0 (no rows, no columns)
///
/// A simple usage example:
///
/// ````dart
/// import 'package:ml_linalg/matrix.dart';
///
/// void main() {
/// final matrix = Matrix.empty();
///
/// print(matrix);
/// }
/// ````
///
/// The output:
///
/// ```
/// Matrix 0 x 0
/// ```
factory Matrix.empty({DType dtype = DType.float32}) {
switch (dtype) {
case DType.float32:
return Float32Matrix.fromList([]);
case DType.float64:
return Float64Matrix.fromList([]);
default:
throw UnimplementedMatrixException(dtype);
}
}
/// Creates a matrix from flattened list of length equal to
/// [rowCount] * [columnCount]
///
/// A simple usage example:
///
/// ````dart
/// import 'package:ml_linalg/matrix.dart';
///
/// void main() {
/// final source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
///
/// final matrix = Matrix.fromFlattenedList(source, 2, 5);
///
/// print(matrix);
/// }
/// ````
///
/// The output:
///
/// ```
/// Matrix 2 x 5:
/// (1.0, 2.0, 3.0, 4.0, 5.0)
/// (6.0, 7.0, 8.0, 9.0, 0.0)
/// ```
factory Matrix.fromFlattenedList(
List<double> source,
int rowCount,
int columnCount, {
DType dtype = DType.float32,
}) {
switch (dtype) {
case DType.float32:
return Float32Matrix.fromFlattenedList(source, rowCount, columnCount);
case DType.float64:
return Float64Matrix.fromFlattenedList(source, rowCount, columnCount);
default:
throw UnimplementedMatrixException(dtype);
}
}
/// Creates a matrix from byte data of [rowCount] * [columnCount] elements
///
/// A simple usage example:
///
/// ````dart
/// import 'dart:typed_data';
///
/// import 'package:ml_linalg/matrix.dart';
///
/// void main() {
/// final data = Float32List.fromList([
/// 1, 2, 3, 4, 5,
/// 6, 7, 8, 9, 0
/// ]).buffer.asByteData();
///
/// final matrix = Matrix.fromByteData(data, 2, 5);
///
/// print(matrix);
/// }
/// ````
///
/// The output:
///
/// ```
/// Matrix 2 x 5:
/// (1.0, 2.0, 3.0, 4.0, 5.0)
/// (6.0, 7.0, 8.0, 9.0, 0.0)
/// ```
factory Matrix.fromByteData(
ByteData data,
int rowCount,
int columnCount, {
DType dtype = DType.float32,
}) {
switch (dtype) {
case DType.float32:
return Float32Matrix.fromByteData(data, rowCount, columnCount);
case DType.float64:
return Float64Matrix.fromByteData(data, rowCount, columnCount);
default:
throw UnimplementedMatrixException(dtype);
}
}
/// Creates a matrix, where elements from [source] are the elements for the
/// matrix main diagonal, the rest of the elements are zero
///
/// ````dart
/// import 'package:ml_linalg/matrix.dart';
///
/// void main() {
/// final matrix = Matrix.diagonal([1, 2, 3, 4, 5]);
///
/// print(matrix);
/// }
/// ````
///
/// The output:
///
/// ```
/// Matrix 5 x 5:
/// (1.0, 0.0, 0.0, 0.0, 0.0)
/// (0.0, 2.0, 0.0, 0.0, 0.0)
/// (0.0, 0.0, 3.0, 0.0, 0.0)
/// (0.0, 0.0, 0.0, 4.0, 0.0)
/// (0.0, 0.0, 0.0, 0.0, 5.0)
/// ```
factory Matrix.diagonal(
List<double> source, {
DType dtype = DType.float32,
}) {
switch (dtype) {
case DType.float32:
return Float32Matrix.diagonal(source);
case DType.float64:
return Float64Matrix.diagonal(source);
default:
throw UnimplementedMatrixException(dtype);
}
}
/// Creates a matrix of [size] * [size] dimension, where all the main
/// diagonal elements are equal to [scalar], the rest of the elements are 0
///
/// ````dart
/// import 'package:ml_linalg/matrix.dart';
///
/// void main() {
/// final matrix = Matrix.scalar(3, 5);
///
/// print(matrix);
/// }
/// ````
///
/// The output:
///
/// ```
/// Matrix 5 x 5:
/// (3.0, 0.0, 0.0, 0.0, 0.0)
/// (0.0, 3.0, 0.0, 0.0, 0.0)
/// (0.0, 0.0, 3.0, 0.0, 0.0)
/// (0.0, 0.0, 0.0, 3.0, 0.0)
/// (0.0, 0.0, 0.0, 0.0, 3.0)
/// ```
factory Matrix.scalar(
double scalar,
int size, {
DType dtype = DType.float32,
}) {
switch (dtype) {
case DType.float32:
return Float32Matrix.scalar(scalar, size);
case DType.float64:
return Float64Matrix.scalar(scalar, size);
default:
throw UnimplementedMatrixException(dtype);
}
}
/// Creates a matrix of [size] * [size] dimension, where all the main
/// diagonal elements are equal to 1, the rest of the elements are 0
///
/// ````dart
/// import 'package:ml_linalg/matrix.dart';
///
/// void main() {
/// final matrix = Matrix.identity(5);
///
/// print(matrix);
/// }
/// ````
///
/// The output:
///
/// ```
/// Matrix 5 x 5:
/// (1.0, 0.0, 0.0, 0.0, 0.0)
/// (0.0, 1.0, 0.0, 0.0, 0.0)
/// (0.0, 0.0, 1.0, 0.0, 0.0)
/// (0.0, 0.0, 0.0, 1.0, 0.0)
/// (0.0, 0.0, 0.0, 0.0, 1.0)
/// ```
factory Matrix.identity(
int size, {
DType dtype = DType.float32,
}) {
switch (dtype) {
case DType.float32:
return Float32Matrix.scalar(1.0, size);
case DType.float64:
return Float64Matrix.scalar(1.0, size);
default:
throw UnimplementedMatrixException(dtype);
}
}
/// Creates a matrix, consisting of just one row (aka `Row matrix`)
///
/// ````dart
/// import 'package:ml_linalg/matrix.dart';
///
/// void main() {
/// final matrix = Matrix.row([1, 2, 3, 4, 5]);
///
/// print(matrix);
/// }
/// ````
///
/// The output:
///
/// ```
/// Matrix 1 x 5:
/// (1.0, 2.0, 3.0, 4.0, 5.0)
/// ```
factory Matrix.row(
List<double> source, {
DType dtype = DType.float32,
}) {
switch (dtype) {
case DType.float32:
return Float32Matrix.fromRows([Vector.fromList(source, dtype: dtype)]);
case DType.float64:
return Float64Matrix.fromRows([Vector.fromList(source, dtype: dtype)]);
default:
throw UnimplementedMatrixException(dtype);
}
}
/// Returns randomly filled matrix of [rowCount]x[columnCount] dimension
factory Matrix.random(int rowCount, int columnCount,
{DType dtype = DType.float32,
num min = -1000,
num max = 1000,
int? seed}) {
switch (dtype) {
case DType.float32:
return Float32Matrix.random(dtype, rowCount, columnCount,
min: min, max: max, seed: seed);
case DType.float64:
return Float64Matrix.random(dtype, rowCount, columnCount,
min: min, max: max, seed: seed);
default:
throw UnimplementedMatrixException(dtype);
}
}
/// Returns randomly filled symmetric and positive definite matrix of
/// [size]x[size] dimension
///
/// Keep in mind that [min] and [max] are constraints for a random
/// intermediate matrix which is used to build the result matrix
factory Matrix.randomSPD(int size,
{DType dtype = DType.float32,
num min = -1000,
num max = 1000,
int? seed}) {
final A =
Matrix.random(size, size, dtype: dtype, max: max, min: min, seed: seed);
return A * A.transpose() + Matrix.scalar(size * 1.0, size, dtype: dtype);
}
/// Returns a restored matrix from a serializable map
factory Matrix.fromJson(Map<String, dynamic> json) => fromMatrixJson(json)!;
/// Creates a matrix, consisting of just one column (aka `Column matrix`)
///
/// ````dart
/// import 'package:ml_linalg/matrix.dart';
///
/// void main() {
/// final matrix = Matrix.column([1, 2, 3, 4, 5]);
///
/// print(matrix);
/// }
/// ````
///
/// The output:
///
/// ```
/// Matrix 5 x 1:
/// (1.0)
/// (2.0)
/// (3.0)
/// (4.0)
/// (5.0)
/// ```
factory Matrix.column(List<double> source, {DType dtype = DType.float32}) {
switch (dtype) {
case DType.float32:
return Float32Matrix.fromColumns(
[Vector.fromList(source, dtype: dtype)],
);
case DType.float64:
return Float64Matrix.fromColumns(
([Vector.fromList(source, dtype: dtype)]));
default:
throw UnimplementedMatrixException(dtype);
}
}
/// A data type of [Matrix] elements
DType get dtype;
/// Returns a lazy iterable of row vectors of the matrix
Iterable<Vector> get rows;
/// Returns a lazy iterable of column vectors of the matrix
Iterable<Vector> get columns;
/// Returns a number of matrix rows
int get rowCount;
/// Returns a number of matrix columns
int get columnCount;
/// Returns a lazy iterable of row indices
Iterable<int> get rowIndices;
/// Returns a lazy iterable of column indices
Iterable<int> get columnIndices;
/// Returns a representation of the matrix as a flattened list:
///
/// ```dart
/// import 'package:ml_linalg/matrix.dart';
///
/// void main() {
/// final matrix = Matrix.fromList([
/// [1.0, 2.0, 3.0],
/// [4.0, 5.0, 6.0],
/// ]);
///
/// print(matrix.asFlattenedList); // [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
/// }
/// ```
///
/// Runtime type can be Float32List or Float64List, it depends on the [dtype]
List<double> get asFlattenedList;
/// Returns a number of matrix rows
@Deprecated('use "rowCount" instead')
int get rowsNum;
/// Returns a number of matrix columns
@Deprecated('use "columnCount" instead')
int get columnsNum;
/// Returns `true` if the [Matrix] is not empty. Use it instead of `isEmpty`
/// getter from [Iterable] interface, since the latter may return falsy true
bool get hasData;
/// Returns `true` if the [Matrix]'s [columnCount] and [rowCount] are equal
bool get isSquare;
/// Returns a matrix row on an [index] (the operator is an alias for
/// [getRow] method)
Vector operator [](int index);
/// Performs sum of the matrix and a matrix/ a vector/ a scalar/ whatever
Matrix operator +(Object value);
/// Performs subtraction of the matrix and a matrix/ a vector/ a scalar/
/// whatever
Matrix operator -(Object value);
/// Performs multiplication of the matrix and a matrix/ a vector/ a scalar/
/// whatever
Matrix operator *(Object value);
/// Performs division of the matrix by a matrix/ a vector/ a scalar
///
/// If division by a matrix is taking place, each element of this [Matrix]
/// will be divided by each element of another matrix. If the other matrix has
/// a different shape, an exception will be thrown.
///
/// If division by a vector is taking place, the direction of the division
/// will be automatically detected:
/// - if [rowCount] is equal to the vector's length, the division will be
/// applied column-wise
/// - if [columnCount] is equal to the vector's length, the division will be
/// applied row-wise
/// - if this [Matrix] is square, an exception will be thrown.
///
/// If division by a scalar is taking place, each element of this [Matrix]
/// will be divided by the scalar
Matrix operator /(Object value);
/// Performs transposition of the matrix
Matrix transpose();
/// Samples a new [Matrix] from parts of this [Matrix]
///
/// Usage examples:
///
/// - Create a new matrix from rows of the original matrix:
///
/// ```dart
/// import 'package:ml_linalg/matrix.dart';
///
/// void main() {
/// final matrix = Matrix.fromList([
/// [10, 20, 30, 40, 50],
/// [22, 33, 44, 55, 66],
/// [11, 89, 79, 69, 59],
/// ]);
/// final sampled = matrix.sample(rowIndices: [0, 2, 1, 1]);
///
/// print(sampled);
/// // [
/// // [10, 20, 30, 40, 50],
/// // [11, 89, 79, 69, 59],
/// // [22, 33, 44, 55, 66],
/// // [22, 33, 44, 55, 66],
/// // ]
/// //
/// }
/// ```
///
/// - Create a new matrix from columns of the original matrix:
///
/// ```dart
/// import 'package:ml_linalg/matrix.dart';
///
/// void main() {
/// final matrix = Matrix.fromList([
/// [10, 20, 30, 40, 50],
/// [22, 33, 44, 55, 66],
/// [11, 89, 79, 69, 59],
/// ]);
/// final sampled = matrix.sample(columnIndices: [4, 4, 2]);
///
/// print(sampled);
/// // [
/// // [50, 50, 30],
/// // [66, 66, 44],
/// // [59, 59, 79],
/// // ]
/// //
/// }
/// ```
///
/// - Create a new matrix from both rows and columns of the original matrix:
///
/// ```dart
/// import 'package:ml_linalg/matrix.dart';
///
/// void main() {
/// final matrix = Matrix.fromList([
/// [10, 20, 30, 40, 50],
/// [22, 33, 44, 55, 66],
/// [11, 89, 79, 69, 59],
/// ]);
/// final sampled = matrix.sample(
/// rowIndices: [1, 1],
/// columnIndices: [4, 4, 2],
/// );
///
/// print(sampled);
/// // [
/// // [66, 66, 44],
/// // [66, 66, 44],
/// // ]
/// //
/// }
/// ```
Matrix sample({
Iterable<int> rowIndices,
Iterable<int> columnIndices,
});
/// Returns a column of the matrix on [index]
Vector getColumn(int index);
/// Returns a row of the matrix on [index]
Vector getRow(int index);
/// Reduces all the matrix columns to only column, using [combiner] function
Vector reduceColumns(Vector Function(Vector combine, Vector vector) combiner,
{Vector? initValue});
/// Reduces all the matrix rows to only row, using [combiner] function
Vector reduceRows(Vector Function(Vector combine, Vector vector) combiner,
{Vector? initValue});
/// Performs element-wise mapping of this [Matrix] to a new one via passed
/// [mapper] function
Matrix mapElements(double Function(double element) mapper);
/// Performs column-wise mapping of this [Matrix] to a new one via passed
/// [mapper] function
Matrix mapColumns(Vector Function(Vector column) mapper);
/// Returns a new matrix consisting of filtered columns of the original matrix
Matrix filterColumns(bool Function(Vector column, int idx) predicate);
/// Performs row-wise mapping of this [Matrix] to a new one via passed
/// [mapper] function
Matrix mapRows(Vector Function(Vector row) mapper);
/// Creates a new matrix, efficiently iterating through all the matrix
/// elements (several floating point elements in a time) and applying the
/// [mapper] function
///
/// Type [E] should be either [Float32x4] or [Float64x2], depends on [dtype]
/// value
Matrix fastMap<E>(E Function(E columnElement) mapper);
/// Tries to convert the [Matrix] to a vector:
///
/// ````dart
/// import 'package:ml_linalg/matrix.dart';
///
/// void main() {
/// final matrix = Matrix.column([1, 2, 3, 4, 5]);
/// final vector = matrix.toVector();
///
/// print(vector);
/// }
/// ````
///
/// The output:
///
/// ```
/// (1.0, 2.0, 3.0, 4.0, 5.0)
/// ```
///
/// It fails, if both [columnCount] and [rowCount] are greater than `1`:
///
/// ````dart
/// import 'package:ml_linalg/matrix.dart';
///
/// void main() {
/// final matrix = Matrix.fromList([
/// [1.0, 2.0, 3.0, 4.0],
/// [5.0, 6.0, 7.0, 8.0],
/// ]);
///
/// final vector = matrix.toVector();
/// }
/// ````
///
/// The output:
///
/// ```
/// Exception: Cannot convert 2 x 4 matrix into a vector
/// ```
Vector toVector();
/// Returns a max value of the matrix
double max();
/// Return a min value of the matrix
double min();
/// Returns a norm of a matrix
double norm([MatrixNorm norm]);
/// Returns a new matrix with inserted [columns]
Matrix insertColumns(int index, List<Vector> columns);
/// Extracts non-repeated matrix rows and pack them into matrix
Matrix uniqueRows();
/// Returns mean values of matrix column/rows
Vector mean([Axis axis = Axis.columns]);
/// Returns standard deviation values of matrix column/rows
Vector deviation([Axis axis = Axis.columns]);
/// Returns variance of matrix column/rows
Vector variance([Axis axis = Axis.columns]);
/// Returns a new matrix with sorted elements from this [Matrix]
Matrix sort(double Function(Vector vector) selectSortValue,
[Axis axis = Axis.rows, SortDirection sortDir = SortDirection.asc]);
/// Raise all the elements of the matrix to the power [exponent] and returns
/// a new [Matrix] with these elements. Avoid raising a matrix to a float
/// power, since it is a slow operation
Matrix pow(num exponent);
/// Creates a new [Matrix] composed of Euler's numbers raised to powers which
/// are the elements of this [Matrix]
Matrix exp(
{@Deprecated(
'The flag is useless, it\'ll be removed in the next major update')
bool skipCaching = false});
/// Creates a new [Matrix] composed of natural logarithms of the source
/// matrix elements
Matrix log(
{@Deprecated(
'The flag is useless, it\'ll be removed in the next major update')
bool skipCaching = false});
/// Performs Hadamard product - element-wise matrices multiplication
Matrix multiply(Matrix other);
/// Returns the sum of all the matrix elements
double sum();
/// Returns the product of all the matrix elements
double prod();
/// Decomposes the original matrix into several matrices whose product results in the original matrix
/// Default value id [Decomposition.LU]
Iterable<Matrix> decompose([Decomposition decompositionType]);
/// Returns a collection of pairs of an eigenvector and its corresponding eigenvalue
///
/// Default method id [EigenMethod.powerIteration]
Iterable<Eigen> eigen(
{EigenMethod method, Vector? initial, int iterationCount, int? seed});
/// Finds the inverse of the original matrix. Product of the inverse and the original matrix results in singular matrix
/// Default value is [Inverse.LU]
Matrix inverse([Inverse inverseType]);
/// Returns a solution for [a system of linear equations](https://en.wikipedia.org/wiki/System_of_linear_equations):
///
/// ```
/// A*X = B
/// ```
///
/// where `A` is this Matrix, [B] is a column matrix of [this matrix row count]x1 dimension
///
/// To solve the system, one should do the following
///
/// ```
/// X = inverse(A)*B
/// ```
///
/// To find the inverse of this matrix, one should specify the [Inverse] type through passing the [inverse] argument, default value is [Inverse.LU]
Matrix solve(Matrix B, [Inverse inverse]);
/// Returns a serializable map
Map<String, dynamic> toJson();
}