summaryrefslogtreecommitdiff
path: root/src/main/java/org/apache/commons/math3/linear/FieldMatrix.java
blob: b738dd87009b7383b0a363953b873cbed64c5719 (plain)
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
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.commons.math3.linear;

import org.apache.commons.math3.Field;
import org.apache.commons.math3.FieldElement;
import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.exception.NoDataException;
import org.apache.commons.math3.exception.NotPositiveException;
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
import org.apache.commons.math3.exception.NullArgumentException;
import org.apache.commons.math3.exception.NumberIsTooSmallException;
import org.apache.commons.math3.exception.OutOfRangeException;

/**
 * Interface defining field-valued matrix with basic algebraic operations.
 *
 * <p>Matrix element indexing is 0-based -- e.g., <code>getEntry(0, 0)</code> returns the element in
 * the first row, first column of the matrix.
 *
 * @param <T> the type of the field elements
 */
public interface FieldMatrix<T extends FieldElement<T>> extends AnyMatrix {
    /**
     * Get the type of field elements of the matrix.
     *
     * @return the type of field elements of the matrix.
     */
    Field<T> getField();

    /**
     * Create a new FieldMatrix<T> of the same type as the instance with the supplied row and column
     * dimensions.
     *
     * @param rowDimension the number of rows in the new matrix
     * @param columnDimension the number of columns in the new matrix
     * @return a new matrix of the same type as the instance
     * @throws NotStrictlyPositiveException if row or column dimension is not positive.
     * @since 2.0
     */
    FieldMatrix<T> createMatrix(final int rowDimension, final int columnDimension)
            throws NotStrictlyPositiveException;

    /**
     * Make a (deep) copy of this.
     *
     * @return a copy of this matrix.
     */
    FieldMatrix<T> copy();

    /**
     * Compute the sum of this and m.
     *
     * @param m Matrix to be added.
     * @return {@code this} + {@code m}.
     * @throws MatrixDimensionMismatchException if {@code m} is not the same size as {@code this}
     *     matrix.
     */
    FieldMatrix<T> add(FieldMatrix<T> m) throws MatrixDimensionMismatchException;

    /**
     * Subtract {@code m} from this matrix.
     *
     * @param m Matrix to be subtracted.
     * @return {@code this} - {@code m}.
     * @throws MatrixDimensionMismatchException if {@code m} is not the same size as {@code this}
     *     matrix.
     */
    FieldMatrix<T> subtract(FieldMatrix<T> m) throws MatrixDimensionMismatchException;

    /**
     * Increment each entry of this matrix.
     *
     * @param d Value to be added to each entry.
     * @return {@code d} + {@code this}.
     */
    FieldMatrix<T> scalarAdd(T d);

    /**
     * Multiply each entry by {@code d}.
     *
     * @param d Value to multiply all entries by.
     * @return {@code d} * {@code this}.
     */
    FieldMatrix<T> scalarMultiply(T d);

    /**
     * Postmultiply this matrix by {@code m}.
     *
     * @param m Matrix to postmultiply by.
     * @return {@code this} * {@code m}.
     * @throws DimensionMismatchException if the number of columns of {@code this} matrix is not
     *     equal to the number of rows of matrix {@code m}.
     */
    FieldMatrix<T> multiply(FieldMatrix<T> m) throws DimensionMismatchException;

    /**
     * Premultiply this matrix by {@code m}.
     *
     * @param m Matrix to premultiply by.
     * @return {@code m} * {@code this}.
     * @throws DimensionMismatchException if the number of columns of {@code m} differs from the
     *     number of rows of {@code this} matrix.
     */
    FieldMatrix<T> preMultiply(FieldMatrix<T> m) throws DimensionMismatchException;

    /**
     * Returns the result multiplying this with itself <code>p</code> times. Depending on the type
     * of the field elements, T, instability for high powers might occur.
     *
     * @param p raise this to power p
     * @return this^p
     * @throws NotPositiveException if {@code p < 0}
     * @throws NonSquareMatrixException if {@code this matrix} is not square
     */
    FieldMatrix<T> power(final int p) throws NonSquareMatrixException, NotPositiveException;

    /**
     * Returns matrix entries as a two-dimensional array.
     *
     * @return a 2-dimensional array of entries.
     */
    T[][] getData();

    /**
     * Get a submatrix. Rows and columns are indicated counting from 0 to n - 1.
     *
     * @param startRow Initial row index
     * @param endRow Final row index (inclusive)
     * @param startColumn Initial column index
     * @param endColumn Final column index (inclusive)
     * @return the matrix containing the data of the specified rows and columns.
     * @throws NumberIsTooSmallException is {@code endRow < startRow} of {@code endColumn <
     *     startColumn}.
     * @throws OutOfRangeException if the indices are not valid.
     */
    FieldMatrix<T> getSubMatrix(int startRow, int endRow, int startColumn, int endColumn)
            throws NumberIsTooSmallException, OutOfRangeException;

    /**
     * Get a submatrix. Rows and columns are indicated counting from 0 to n - 1.
     *
     * @param selectedRows Array of row indices.
     * @param selectedColumns Array of column indices.
     * @return the matrix containing the data in the specified rows and columns.
     * @throws NoDataException if {@code selectedRows} or {@code selectedColumns} is empty
     * @throws NullArgumentException if {@code selectedRows} or {@code selectedColumns} is {@code
     *     null}.
     * @throws OutOfRangeException if row or column selections are not valid.
     */
    FieldMatrix<T> getSubMatrix(int[] selectedRows, int[] selectedColumns)
            throws NoDataException, NullArgumentException, OutOfRangeException;

    /**
     * Copy a submatrix. Rows and columns are 0-based. The designated submatrix is copied into the
     * top left portion of the destination array.
     *
     * @param startRow Initial row index.
     * @param endRow Final row index (inclusive).
     * @param startColumn Initial column index.
     * @param endColumn Final column index (inclusive).
     * @param destination The array where the submatrix data should be copied (if larger than
     *     rows/columns counts, only the upper-left part will be modified).
     * @throws MatrixDimensionMismatchException if the dimensions of {@code destination} are not
     *     large enough to hold the submatrix.
     * @throws NumberIsTooSmallException if {@code endRow < startRow} or {@code endColumn <
     *     startColumn}.
     * @throws OutOfRangeException if the indices are not valid.
     */
    void copySubMatrix(int startRow, int endRow, int startColumn, int endColumn, T[][] destination)
            throws MatrixDimensionMismatchException, NumberIsTooSmallException, OutOfRangeException;

    /**
     * Copy a submatrix. Rows and columns are indicated counting from 0 to n - 1.
     *
     * @param selectedRows Array of row indices.
     * @param selectedColumns Array of column indices.
     * @param destination Arrays where the submatrix data should be copied (if larger than
     *     rows/columns counts, only the upper-left part will be used)
     * @throws MatrixDimensionMismatchException if the dimensions of {@code destination} do not
     *     match those of {@code this}.
     * @throws NoDataException if {@code selectedRows} or {@code selectedColumns} is empty
     * @throws NullArgumentException if {@code selectedRows} or {@code selectedColumns} is {@code
     *     null}.
     * @throws OutOfRangeException if the indices are not valid.
     */
    void copySubMatrix(int[] selectedRows, int[] selectedColumns, T[][] destination)
            throws MatrixDimensionMismatchException,
                    NoDataException,
                    NullArgumentException,
                    OutOfRangeException;

    /**
     * Replace the submatrix starting at {@code (row, column)} using data in the input {@code
     * subMatrix} array. Indexes are 0-based.
     *
     * <p>Example:<br>
     * Starting with
     *
     * <pre>
     * 1  2  3  4
     * 5  6  7  8
     * 9  0  1  2
     * </pre>
     *
     * and <code>subMatrix = {{3, 4} {5,6}}</code>, invoking <code>setSubMatrix(subMatrix,1,1))
     * </code> will result in
     *
     * <pre>
     * 1  2  3  4
     * 5  3  4  8
     * 9  5  6  2
     * </pre>
     *
     * @param subMatrix Array containing the submatrix replacement data.
     * @param row Row coordinate of the top-left element to be replaced.
     * @param column Column coordinate of the top-left element to be replaced.
     * @throws OutOfRangeException if {@code subMatrix} does not fit into this matrix from element
     *     in {@code (row, column)}.
     * @throws NoDataException if a row or column of {@code subMatrix} is empty.
     * @throws DimensionMismatchException if {@code subMatrix} is not rectangular (not all rows have
     *     the same length).
     * @throws NullArgumentException if {@code subMatrix} is {@code null}.
     * @since 2.0
     */
    void setSubMatrix(T[][] subMatrix, int row, int column)
            throws DimensionMismatchException,
                    OutOfRangeException,
                    NoDataException,
                    NullArgumentException;

    /**
     * Get the entries in row number {@code row} as a row matrix.
     *
     * @param row Row to be fetched.
     * @return a row matrix.
     * @throws OutOfRangeException if the specified row index is invalid.
     */
    FieldMatrix<T> getRowMatrix(int row) throws OutOfRangeException;

    /**
     * Set the entries in row number {@code row} as a row matrix.
     *
     * @param row Row to be set.
     * @param matrix Row matrix (must have one row and the same number of columns as the instance).
     * @throws OutOfRangeException if the specified row index is invalid.
     * @throws MatrixDimensionMismatchException if the matrix dimensions do not match one instance
     *     row.
     */
    void setRowMatrix(int row, FieldMatrix<T> matrix)
            throws MatrixDimensionMismatchException, OutOfRangeException;

    /**
     * Get the entries in column number {@code column} as a column matrix.
     *
     * @param column Column to be fetched.
     * @return a column matrix.
     * @throws OutOfRangeException if the specified column index is invalid.
     */
    FieldMatrix<T> getColumnMatrix(int column) throws OutOfRangeException;

    /**
     * Set the entries in column number {@code column} as a column matrix.
     *
     * @param column Column to be set.
     * @param matrix column matrix (must have one column and the same number of rows as the
     *     instance).
     * @throws OutOfRangeException if the specified column index is invalid.
     * @throws MatrixDimensionMismatchException if the matrix dimensions do not match one instance
     *     column.
     */
    void setColumnMatrix(int column, FieldMatrix<T> matrix)
            throws MatrixDimensionMismatchException, OutOfRangeException;

    /**
     * Get the entries in row number {@code row} as a vector.
     *
     * @param row Row to be fetched
     * @return a row vector.
     * @throws OutOfRangeException if the specified row index is invalid.
     */
    FieldVector<T> getRowVector(int row) throws OutOfRangeException;

    /**
     * Set the entries in row number {@code row} as a vector.
     *
     * @param row Row to be set.
     * @param vector row vector (must have the same number of columns as the instance).
     * @throws OutOfRangeException if the specified row index is invalid.
     * @throws MatrixDimensionMismatchException if the vector dimension does not match one instance
     *     row.
     */
    void setRowVector(int row, FieldVector<T> vector)
            throws MatrixDimensionMismatchException, OutOfRangeException;

    /**
     * Returns the entries in column number {@code column} as a vector.
     *
     * @param column Column to be fetched.
     * @return a column vector.
     * @throws OutOfRangeException if the specified column index is invalid.
     */
    FieldVector<T> getColumnVector(int column) throws OutOfRangeException;

    /**
     * Set the entries in column number {@code column} as a vector.
     *
     * @param column Column to be set.
     * @param vector Column vector (must have the same number of rows as the instance).
     * @throws OutOfRangeException if the specified column index is invalid.
     * @throws MatrixDimensionMismatchException if the vector dimension does not match one instance
     *     column.
     */
    void setColumnVector(int column, FieldVector<T> vector)
            throws MatrixDimensionMismatchException, OutOfRangeException;

    /**
     * Get the entries in row number {@code row} as an array.
     *
     * @param row Row to be fetched.
     * @return array of entries in the row.
     * @throws OutOfRangeException if the specified row index is not valid.
     */
    T[] getRow(int row) throws OutOfRangeException;

    /**
     * Set the entries in row number {@code row} as a row matrix.
     *
     * @param row Row to be set.
     * @param array Row matrix (must have the same number of columns as the instance).
     * @throws OutOfRangeException if the specified row index is invalid.
     * @throws MatrixDimensionMismatchException if the array size does not match one instance row.
     */
    void setRow(int row, T[] array) throws MatrixDimensionMismatchException, OutOfRangeException;

    /**
     * Get the entries in column number {@code col} as an array.
     *
     * @param column the column to be fetched
     * @return array of entries in the column
     * @throws OutOfRangeException if the specified column index is not valid.
     */
    T[] getColumn(int column) throws OutOfRangeException;

    /**
     * Set the entries in column number {@code column} as a column matrix.
     *
     * @param column the column to be set
     * @param array column array (must have the same number of rows as the instance)
     * @throws OutOfRangeException if the specified column index is invalid.
     * @throws MatrixDimensionMismatchException if the array size does not match one instance
     *     column.
     */
    void setColumn(int column, T[] array)
            throws MatrixDimensionMismatchException, OutOfRangeException;

    /**
     * Returns the entry in the specified row and column.
     *
     * @param row row location of entry to be fetched
     * @param column column location of entry to be fetched
     * @return matrix entry in row,column
     * @throws OutOfRangeException if the row or column index is not valid.
     */
    T getEntry(int row, int column) throws OutOfRangeException;

    /**
     * Set the entry in the specified row and column.
     *
     * @param row row location of entry to be set
     * @param column column location of entry to be set
     * @param value matrix entry to be set in row,column
     * @throws OutOfRangeException if the row or column index is not valid.
     * @since 2.0
     */
    void setEntry(int row, int column, T value) throws OutOfRangeException;

    /**
     * Change an entry in the specified row and column.
     *
     * @param row Row location of entry to be set.
     * @param column Column location of entry to be set.
     * @param increment Value to add to the current matrix entry in {@code (row, column)}.
     * @throws OutOfRangeException if the row or column index is not valid.
     * @since 2.0
     */
    void addToEntry(int row, int column, T increment) throws OutOfRangeException;

    /**
     * Change an entry in the specified row and column.
     *
     * @param row Row location of entry to be set.
     * @param column Column location of entry to be set.
     * @param factor Multiplication factor for the current matrix entry in {@code (row,column)}
     * @throws OutOfRangeException if the row or column index is not valid.
     * @since 2.0
     */
    void multiplyEntry(int row, int column, T factor) throws OutOfRangeException;

    /**
     * Returns the transpose of this matrix.
     *
     * @return transpose matrix
     */
    FieldMatrix<T> transpose();

    /**
     * Returns the <a href="http://mathworld.wolfram.com/MatrixTrace.html">trace</a> of the matrix
     * (the sum of the elements on the main diagonal).
     *
     * @return trace
     * @throws NonSquareMatrixException if the matrix is not square.
     */
    T getTrace() throws NonSquareMatrixException;

    /**
     * Returns the result of multiplying this by the vector {@code v}.
     *
     * @param v the vector to operate on
     * @return {@code this * v}
     * @throws DimensionMismatchException if the number of columns of {@code this} matrix is not
     *     equal to the size of the vector {@code v}.
     */
    T[] operate(T[] v) throws DimensionMismatchException;

    /**
     * Returns the result of multiplying this by the vector {@code v}.
     *
     * @param v the vector to operate on
     * @return {@code this * v}
     * @throws DimensionMismatchException if the number of columns of {@code this} matrix is not
     *     equal to the size of the vector {@code v}.
     */
    FieldVector<T> operate(FieldVector<T> v) throws DimensionMismatchException;

    /**
     * Returns the (row) vector result of premultiplying this by the vector {@code v}.
     *
     * @param v the row vector to premultiply by
     * @return {@code v * this}
     * @throws DimensionMismatchException if the number of rows of {@code this} matrix is not equal
     *     to the size of the vector {@code v}
     */
    T[] preMultiply(T[] v) throws DimensionMismatchException;

    /**
     * Returns the (row) vector result of premultiplying this by the vector {@code v}.
     *
     * @param v the row vector to premultiply by
     * @return {@code v * this}
     * @throws DimensionMismatchException if the number of rows of {@code this} matrix is not equal
     *     to the size of the vector {@code v}
     */
    FieldVector<T> preMultiply(FieldVector<T> v) throws DimensionMismatchException;

    /**
     * Visit (and possibly change) all matrix entries in row order.
     *
     * <p>Row order starts at upper left and iterating through all elements of a row from left to
     * right before going to the leftmost element of the next row.
     *
     * @param visitor visitor used to process all matrix entries
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
     * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @return the value returned by {@link FieldMatrixChangingVisitor#end()} at the end of the walk
     */
    T walkInRowOrder(FieldMatrixChangingVisitor<T> visitor);

    /**
     * Visit (but don't change) all matrix entries in row order.
     *
     * <p>Row order starts at upper left and iterating through all elements of a row from left to
     * right before going to the leftmost element of the next row.
     *
     * @param visitor visitor used to process all matrix entries
     * @see #walkInRowOrder(FieldMatrixChangingVisitor)
     * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @return the value returned by {@link FieldMatrixPreservingVisitor#end()} at the end of the
     *     walk
     */
    T walkInRowOrder(FieldMatrixPreservingVisitor<T> visitor);

    /**
     * Visit (and possibly change) some matrix entries in row order.
     *
     * <p>Row order starts at upper left and iterating through all elements of a row from left to
     * right before going to the leftmost element of the next row.
     *
     * @param visitor visitor used to process all matrix entries
     * @param startRow Initial row index
     * @param endRow Final row index (inclusive)
     * @param startColumn Initial column index
     * @param endColumn Final column index
     * @throws OutOfRangeException if the indices are not valid.
     * @throws NumberIsTooSmallException if {@code endRow < startRow} or {@code endColumn <
     *     startColumn}.
     * @see #walkInRowOrder(FieldMatrixChangingVisitor)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @return the value returned by {@link FieldMatrixChangingVisitor#end()} at the end of the walk
     */
    T walkInRowOrder(
            FieldMatrixChangingVisitor<T> visitor,
            int startRow,
            int endRow,
            int startColumn,
            int endColumn)
            throws OutOfRangeException, NumberIsTooSmallException;

    /**
     * Visit (but don't change) some matrix entries in row order.
     *
     * <p>Row order starts at upper left and iterating through all elements of a row from left to
     * right before going to the leftmost element of the next row.
     *
     * @param visitor visitor used to process all matrix entries
     * @param startRow Initial row index
     * @param endRow Final row index (inclusive)
     * @param startColumn Initial column index
     * @param endColumn Final column index
     * @throws OutOfRangeException if the indices are not valid.
     * @throws NumberIsTooSmallException if {@code endRow < startRow} or {@code endColumn <
     *     startColumn}.
     * @see #walkInRowOrder(FieldMatrixChangingVisitor)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
     * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @return the value returned by {@link FieldMatrixPreservingVisitor#end()} at the end of the
     *     walk
     */
    T walkInRowOrder(
            FieldMatrixPreservingVisitor<T> visitor,
            int startRow,
            int endRow,
            int startColumn,
            int endColumn)
            throws OutOfRangeException, NumberIsTooSmallException;

    /**
     * Visit (and possibly change) all matrix entries in column order.
     *
     * <p>Column order starts at upper left and iterating through all elements of a column from top
     * to bottom before going to the topmost element of the next column.
     *
     * @param visitor visitor used to process all matrix entries
     * @see #walkInRowOrder(FieldMatrixChangingVisitor)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
     * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @return the value returned by {@link FieldMatrixChangingVisitor#end()} at the end of the walk
     */
    T walkInColumnOrder(FieldMatrixChangingVisitor<T> visitor);

    /**
     * Visit (but don't change) all matrix entries in column order.
     *
     * <p>Column order starts at upper left and iterating through all elements of a column from top
     * to bottom before going to the topmost element of the next column.
     *
     * @param visitor visitor used to process all matrix entries
     * @see #walkInRowOrder(FieldMatrixChangingVisitor)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
     * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @return the value returned by {@link FieldMatrixPreservingVisitor#end()} at the end of the
     *     walk
     */
    T walkInColumnOrder(FieldMatrixPreservingVisitor<T> visitor);

    /**
     * Visit (and possibly change) some matrix entries in column order.
     *
     * <p>Column order starts at upper left and iterating through all elements of a column from top
     * to bottom before going to the topmost element of the next column.
     *
     * @param visitor visitor used to process all matrix entries
     * @param startRow Initial row index
     * @param endRow Final row index (inclusive)
     * @param startColumn Initial column index
     * @param endColumn Final column index
     * @throws NumberIsTooSmallException if {@code endRow < startRow} or {@code endColumn <
     *     startColumn}.
     * @throws OutOfRangeException if the indices are not valid.
     * @see #walkInRowOrder(FieldMatrixChangingVisitor)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
     * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @return the value returned by {@link FieldMatrixChangingVisitor#end()} at the end of the walk
     */
    T walkInColumnOrder(
            FieldMatrixChangingVisitor<T> visitor,
            int startRow,
            int endRow,
            int startColumn,
            int endColumn)
            throws NumberIsTooSmallException, OutOfRangeException;

    /**
     * Visit (but don't change) some matrix entries in column order.
     *
     * <p>Column order starts at upper left and iterating through all elements of a column from top
     * to bottom before going to the topmost element of the next column.
     *
     * @param visitor visitor used to process all matrix entries
     * @param startRow Initial row index
     * @param endRow Final row index (inclusive)
     * @param startColumn Initial column index
     * @param endColumn Final column index
     * @throws NumberIsTooSmallException if {@code endRow < startRow} or {@code endColumn <
     *     startColumn}.
     * @throws OutOfRangeException if the indices are not valid.
     * @see #walkInRowOrder(FieldMatrixChangingVisitor)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
     * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @return the value returned by {@link FieldMatrixPreservingVisitor#end()} at the end of the
     *     walk
     */
    T walkInColumnOrder(
            FieldMatrixPreservingVisitor<T> visitor,
            int startRow,
            int endRow,
            int startColumn,
            int endColumn)
            throws NumberIsTooSmallException, OutOfRangeException;

    /**
     * Visit (and possibly change) all matrix entries using the fastest possible order.
     *
     * <p>The fastest walking order depends on the exact matrix class. It may be different from
     * traditional row or column orders.
     *
     * @param visitor visitor used to process all matrix entries
     * @see #walkInRowOrder(FieldMatrixChangingVisitor)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
     * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @return the value returned by {@link FieldMatrixChangingVisitor#end()} at the end of the walk
     */
    T walkInOptimizedOrder(FieldMatrixChangingVisitor<T> visitor);

    /**
     * Visit (but don't change) all matrix entries using the fastest possible order.
     *
     * <p>The fastest walking order depends on the exact matrix class. It may be different from
     * traditional row or column orders.
     *
     * @param visitor visitor used to process all matrix entries
     * @see #walkInRowOrder(FieldMatrixChangingVisitor)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
     * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @return the value returned by {@link FieldMatrixPreservingVisitor#end()} at the end of the
     *     walk
     */
    T walkInOptimizedOrder(FieldMatrixPreservingVisitor<T> visitor);

    /**
     * Visit (and possibly change) some matrix entries using the fastest possible order.
     *
     * <p>The fastest walking order depends on the exact matrix class. It may be different from
     * traditional row or column orders.
     *
     * @param visitor visitor used to process all matrix entries
     * @param startRow Initial row index
     * @param endRow Final row index (inclusive)
     * @param startColumn Initial column index
     * @param endColumn Final column index (inclusive)
     * @throws NumberIsTooSmallException if {@code endRow < startRow} or {@code endColumn <
     *     startColumn}.
     * @throws OutOfRangeException if the indices are not valid.
     * @see #walkInRowOrder(FieldMatrixChangingVisitor)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
     * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @return the value returned by {@link FieldMatrixChangingVisitor#end()} at the end of the walk
     */
    T walkInOptimizedOrder(
            FieldMatrixChangingVisitor<T> visitor,
            int startRow,
            int endRow,
            int startColumn,
            int endColumn)
            throws NumberIsTooSmallException, OutOfRangeException;

    /**
     * Visit (but don't change) some matrix entries using the fastest possible order.
     *
     * <p>The fastest walking order depends on the exact matrix class. It may be different from
     * traditional row or column orders.
     *
     * @param visitor visitor used to process all matrix entries
     * @param startRow Initial row index
     * @param endRow Final row index (inclusive)
     * @param startColumn Initial column index
     * @param endColumn Final column index (inclusive)
     * @throws NumberIsTooSmallException if {@code endRow < startRow} or {@code endColumn <
     *     startColumn}.
     * @throws OutOfRangeException if the indices are not valid.
     * @see #walkInRowOrder(FieldMatrixChangingVisitor)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
     * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor)
     * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor)
     * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int)
     * @return the value returned by {@link FieldMatrixPreservingVisitor#end()} at the end of the
     *     walk
     */
    T walkInOptimizedOrder(
            FieldMatrixPreservingVisitor<T> visitor,
            int startRow,
            int endRow,
            int startColumn,
            int endColumn)
            throws NumberIsTooSmallException, OutOfRangeException;
}