Array2DRowFieldMatrix.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.apache.commons.math4.legacy.linear;

  18. import java.io.Serializable;

  19. import org.apache.commons.math4.legacy.core.Field;
  20. import org.apache.commons.math4.legacy.core.FieldElement;
  21. import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
  22. import org.apache.commons.math4.legacy.exception.MathIllegalStateException;
  23. import org.apache.commons.math4.legacy.exception.NoDataException;
  24. import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
  25. import org.apache.commons.math4.legacy.exception.NullArgumentException;
  26. import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
  27. import org.apache.commons.math4.legacy.exception.OutOfRangeException;
  28. import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
  29. import org.apache.commons.math4.legacy.core.MathArrays;

  30. /**
  31.  * Implementation of {@code FieldMatrix<T>} using a {@link FieldElement}[][] array to store entries.
  32.  * <p>
  33.  * As specified in the {@link FieldMatrix} interface, matrix element indexing
  34.  * is 0-based -- e.g., <code>getEntry(0, 0)</code>
  35.  * returns the element in the first row, first column of the matrix.
  36.  * </p>
  37.  *
  38.  * @param <T> the type of the field elements
  39.  */
  40. public class Array2DRowFieldMatrix<T extends FieldElement<T>>
  41.     extends AbstractFieldMatrix<T>
  42.     implements Serializable {
  43.     /** Serializable version identifier. */
  44.     private static final long serialVersionUID = 7260756672015356458L;
  45.     /** Entries of the matrix. */
  46.     private T[][] data;

  47.     /**
  48.      * Creates a matrix with no data.
  49.      * @param field field to which the elements belong
  50.      */
  51.     public Array2DRowFieldMatrix(final Field<T> field) {
  52.         super(field);
  53.     }

  54.     /**
  55.      * Create a new {@code FieldMatrix<T>} with the supplied row and column dimensions.
  56.      *
  57.      * @param field Field to which the elements belong.
  58.      * @param rowDimension Number of rows in the new matrix.
  59.      * @param columnDimension Number of columns in the new matrix.
  60.      * @throws NotStrictlyPositiveException if row or column dimension is not positive.
  61.      */
  62.     public Array2DRowFieldMatrix(final Field<T> field, final int rowDimension,
  63.                                  final int columnDimension)
  64.         throws NotStrictlyPositiveException {
  65.         super(field, rowDimension, columnDimension);
  66.         data = MathArrays.buildArray(field, rowDimension, columnDimension);
  67.     }

  68.     /**
  69.      * Create a new {@code FieldMatrix<T>} using the input array as the underlying
  70.      * data array.
  71.      * <p>The input array is copied, not referenced. This constructor has
  72.      * the same effect as calling {@link #Array2DRowFieldMatrix(FieldElement[][], boolean)}
  73.      * with the second argument set to {@code true}.</p>
  74.      *
  75.      * @param d Data for the new matrix.
  76.      * @throws DimensionMismatchException if {@code d} is not rectangular.
  77.      * @throws NullArgumentException if {@code d} is {@code null}.
  78.      * @throws NoDataException if there are not at least one row and one column.
  79.      * @see #Array2DRowFieldMatrix(FieldElement[][], boolean)
  80.      */
  81.     public Array2DRowFieldMatrix(final T[][] d)
  82.         throws DimensionMismatchException, NullArgumentException,
  83.         NoDataException {
  84.         this(extractField(d), d);
  85.     }

  86.     /**
  87.      * Create a new {@code FieldMatrix<T>} using the input array as the underlying
  88.      * data array.
  89.      * <p>The input array is copied, not referenced. This constructor has
  90.      * the same effect as calling {@link #Array2DRowFieldMatrix(FieldElement[][], boolean)}
  91.      * with the second argument set to {@code true}.</p>
  92.      *
  93.      * @param field Field to which the elements belong.
  94.      * @param d Data for the new matrix.
  95.      * @throws DimensionMismatchException if {@code d} is not rectangular.
  96.      * @throws NullArgumentException if {@code d} is {@code null}.
  97.      * @throws NoDataException if there are not at least one row and one column.
  98.      * @see #Array2DRowFieldMatrix(FieldElement[][], boolean)
  99.      */
  100.     public Array2DRowFieldMatrix(final Field<T> field, final T[][] d)
  101.         throws DimensionMismatchException, NullArgumentException,
  102.         NoDataException {
  103.         super(field);
  104.         copyIn(d);
  105.     }

  106.     /**
  107.      * Create a new {@code FieldMatrix<T>} using the input array as the underlying
  108.      * data array.
  109.      * <p>If an array is built specially in order to be embedded in a
  110.      * {@code FieldMatrix<T>} and not used directly, the {@code copyArray} may be
  111.      * set to {@code false}. This will prevent the copying and improve
  112.      * performance as no new array will be built and no data will be copied.</p>
  113.      *
  114.      * @param d Data for the new matrix.
  115.      * @param copyArray Whether to copy or reference the input array.
  116.      * @throws DimensionMismatchException if {@code d} is not rectangular.
  117.      * @throws NoDataException if there are not at least one row and one column.
  118.      * @throws NullArgumentException if {@code d} is {@code null}.
  119.      * @see #Array2DRowFieldMatrix(FieldElement[][])
  120.      */
  121.     public Array2DRowFieldMatrix(final T[][] d, final boolean copyArray)
  122.         throws DimensionMismatchException, NoDataException,
  123.         NullArgumentException {
  124.         this(extractField(d), d, copyArray);
  125.     }

  126.     /**
  127.      * Create a new {@code FieldMatrix<T>} using the input array as the underlying
  128.      * data array.
  129.      * <p>If an array is built specially in order to be embedded in a
  130.      * {@code FieldMatrix<T>} and not used directly, the {@code copyArray} may be
  131.      * set to {@code false}. This will prevent the copying and improve
  132.      * performance as no new array will be built and no data will be copied.</p>
  133.      *
  134.      * @param field Field to which the elements belong.
  135.      * @param d Data for the new matrix.
  136.      * @param copyArray Whether to copy or reference the input array.
  137.      * @throws DimensionMismatchException if {@code d} is not rectangular.
  138.      * @throws NoDataException if there are not at least one row and one column.
  139.      * @throws NullArgumentException if {@code d} is {@code null}.
  140.      * @see #Array2DRowFieldMatrix(FieldElement[][])
  141.      */
  142.     public Array2DRowFieldMatrix(final Field<T> field, final T[][] d, final boolean copyArray)
  143.         throws DimensionMismatchException, NoDataException, NullArgumentException {
  144.         super(field);
  145.         if (copyArray) {
  146.             copyIn(d);
  147.         } else {
  148.             NullArgumentException.check(d);
  149.             final int nRows = d.length;
  150.             if (nRows == 0) {
  151.                 throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
  152.             }
  153.             final int nCols = d[0].length;
  154.             if (nCols == 0) {
  155.                 throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
  156.             }
  157.             for (int r = 1; r < nRows; r++) {
  158.                 if (d[r].length != nCols) {
  159.                     throw new DimensionMismatchException(nCols, d[r].length);
  160.                 }
  161.             }
  162.             data = d;
  163.         }
  164.     }

  165.     /**
  166.      * Create a new (column) {@code FieldMatrix<T>} using {@code v} as the
  167.      * data for the unique column of the created matrix.
  168.      * The input array is copied.
  169.      *
  170.      * @param v Column vector holding data for new matrix.
  171.      * @throws NoDataException if v is empty
  172.      */
  173.     public Array2DRowFieldMatrix(final T[] v) throws NoDataException {
  174.         this(extractField(v), v);
  175.     }

  176.     /**
  177.      * Create a new (column) {@code FieldMatrix<T>} using {@code v} as the
  178.      * data for the unique column of the created matrix.
  179.      * The input array is copied.
  180.      *
  181.      * @param field Field to which the elements belong.
  182.      * @param v Column vector holding data for new matrix.
  183.      */
  184.     public Array2DRowFieldMatrix(final Field<T> field, final T[] v) {
  185.         super(field);
  186.         final int nRows = v.length;
  187.         data = MathArrays.buildArray(getField(), nRows, 1);
  188.         for (int row = 0; row < nRows; row++) {
  189.             data[row][0] = v[row];
  190.         }
  191.     }

  192.     /** {@inheritDoc} */
  193.     @Override
  194.     public FieldMatrix<T> createMatrix(final int rowDimension,
  195.                                        final int columnDimension)
  196.         throws NotStrictlyPositiveException {
  197.         return new Array2DRowFieldMatrix<>(getField(), rowDimension, columnDimension);
  198.     }

  199.     /** {@inheritDoc} */
  200.     @Override
  201.     public FieldMatrix<T> copy() {
  202.         return new Array2DRowFieldMatrix<>(getField(), copyOut(), false);
  203.     }

  204.     /**
  205.      * Add {@code m} to this matrix.
  206.      *
  207.      * @param m Matrix to be added.
  208.      * @return {@code this} + m.
  209.      * @throws MatrixDimensionMismatchException if {@code m} is not the same
  210.      * size as this matrix.
  211.      */
  212.     public Array2DRowFieldMatrix<T> add(final Array2DRowFieldMatrix<T> m)
  213.         throws MatrixDimensionMismatchException {
  214.         // safety check
  215.         checkAdd(m);

  216.         final int rowCount    = getRowDimension();
  217.         final int columnCount = getColumnDimension();
  218.         final T[][] outData = MathArrays.buildArray(getField(), rowCount, columnCount);
  219.         for (int row = 0; row < rowCount; row++) {
  220.             final T[] dataRow    = data[row];
  221.             final T[] mRow       = m.data[row];
  222.             final T[] outDataRow = outData[row];
  223.             for (int col = 0; col < columnCount; col++) {
  224.                 outDataRow[col] = dataRow[col].add(mRow[col]);
  225.             }
  226.         }

  227.         return new Array2DRowFieldMatrix<>(getField(), outData, false);
  228.     }

  229.     /**
  230.      * Subtract {@code m} from this matrix.
  231.      *
  232.      * @param m Matrix to be subtracted.
  233.      * @return {@code this} + m.
  234.      * @throws MatrixDimensionMismatchException if {@code m} is not the same
  235.      * size as this matrix.
  236.      */
  237.     public Array2DRowFieldMatrix<T> subtract(final Array2DRowFieldMatrix<T> m)
  238.         throws MatrixDimensionMismatchException {
  239.         // safety check
  240.         checkAdd(m);

  241.         final int rowCount    = getRowDimension();
  242.         final int columnCount = getColumnDimension();
  243.         final T[][] outData = MathArrays.buildArray(getField(), rowCount, columnCount);
  244.         for (int row = 0; row < rowCount; row++) {
  245.             final T[] dataRow    = data[row];
  246.             final T[] mRow       = m.data[row];
  247.             final T[] outDataRow = outData[row];
  248.             for (int col = 0; col < columnCount; col++) {
  249.                 outDataRow[col] = dataRow[col].subtract(mRow[col]);
  250.             }
  251.         }

  252.         return new Array2DRowFieldMatrix<>(getField(), outData, false);
  253.     }

  254.     /**
  255.      * Postmultiplying this matrix by {@code m}.
  256.      *
  257.      * @param m Matrix to postmultiply by.
  258.      * @return {@code this} * m.
  259.      * @throws DimensionMismatchException if the number of columns of this
  260.      * matrix is not equal to the number of rows of {@code m}.
  261.      */
  262.     public Array2DRowFieldMatrix<T> multiply(final Array2DRowFieldMatrix<T> m)
  263.         throws DimensionMismatchException {
  264.         // safety check
  265.         checkMultiply(m);

  266.         final int nRows = this.getRowDimension();
  267.         final int nCols = m.getColumnDimension();
  268.         final int nSum = this.getColumnDimension();
  269.         final T[][] outData = MathArrays.buildArray(getField(), nRows, nCols);
  270.         for (int row = 0; row < nRows; row++) {
  271.             final T[] dataRow    = data[row];
  272.             final T[] outDataRow = outData[row];
  273.             for (int col = 0; col < nCols; col++) {
  274.                 T sum = getField().getZero();
  275.                 for (int i = 0; i < nSum; i++) {
  276.                     sum = sum.add(dataRow[i].multiply(m.data[i][col]));
  277.                 }
  278.                 outDataRow[col] = sum;
  279.             }
  280.         }

  281.         return new Array2DRowFieldMatrix<>(getField(), outData, false);
  282.     }

  283.     /** {@inheritDoc} */
  284.     @Override
  285.     public T[][] getData() {
  286.         return copyOut();
  287.     }

  288.     /**
  289.      * Get a reference to the underlying data array.
  290.      * This methods returns internal data, <strong>not</strong> fresh copy of it.
  291.      *
  292.      * @return the 2-dimensional array of entries.
  293.      */
  294.     public T[][] getDataRef() {
  295.         return data;
  296.     }

  297.     /** {@inheritDoc} */
  298.     @Override
  299.     public void setSubMatrix(final T[][] subMatrix, final int row,
  300.                              final int column)
  301.         throws OutOfRangeException, NullArgumentException, NoDataException,
  302.         DimensionMismatchException {
  303.         if (data == null) {
  304.             if (row > 0) {
  305.                 throw new MathIllegalStateException(LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row);
  306.             }
  307.             if (column > 0) {
  308.                 throw new MathIllegalStateException(LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column);
  309.             }
  310.             final int nRows = subMatrix.length;
  311.             if (nRows == 0) {
  312.                 throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
  313.             }

  314.             final int nCols = subMatrix[0].length;
  315.             if (nCols == 0) {
  316.                 throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
  317.             }
  318.             data = MathArrays.buildArray(getField(), subMatrix.length, nCols);
  319.             for (int i = 0; i < data.length; ++i) {
  320.                 if (subMatrix[i].length != nCols) {
  321.                     throw new DimensionMismatchException(nCols, subMatrix[i].length);
  322.                 }
  323.                 System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols);
  324.             }
  325.         } else {
  326.             super.setSubMatrix(subMatrix, row, column);
  327.         }
  328.     }

  329.     /** {@inheritDoc} */
  330.     @Override
  331.     public T getEntry(final int row, final int column)
  332.         throws OutOfRangeException {
  333.         checkRowIndex(row);
  334.         checkColumnIndex(column);

  335.         return data[row][column];
  336.     }

  337.     /** {@inheritDoc} */
  338.     @Override
  339.     public void setEntry(final int row, final int column, final T value)
  340.         throws OutOfRangeException {
  341.         checkRowIndex(row);
  342.         checkColumnIndex(column);

  343.         data[row][column] = value;
  344.     }

  345.     /** {@inheritDoc} */
  346.     @Override
  347.     public void addToEntry(final int row, final int column, final T increment)
  348.         throws OutOfRangeException {
  349.         checkRowIndex(row);
  350.         checkColumnIndex(column);

  351.         data[row][column] = data[row][column].add(increment);
  352.     }

  353.     /** {@inheritDoc} */
  354.     @Override
  355.     public void multiplyEntry(final int row, final int column, final T factor)
  356.         throws OutOfRangeException {
  357.         checkRowIndex(row);
  358.         checkColumnIndex(column);

  359.         data[row][column] = data[row][column].multiply(factor);
  360.     }

  361.     /** {@inheritDoc} */
  362.     @Override
  363.     public int getRowDimension() {
  364.         return (data == null) ? 0 : data.length;
  365.     }

  366.     /** {@inheritDoc} */
  367.     @Override
  368.     public int getColumnDimension() {
  369.         return (data == null || data[0] == null) ? 0 : data[0].length;
  370.     }

  371.     /** {@inheritDoc} */
  372.     @Override
  373.     public T[] operate(final T[] v) throws DimensionMismatchException {
  374.         final int nRows = this.getRowDimension();
  375.         final int nCols = this.getColumnDimension();
  376.         if (v.length != nCols) {
  377.             throw new DimensionMismatchException(v.length, nCols);
  378.         }
  379.         final T[] out = MathArrays.buildArray(getField(), nRows);
  380.         for (int row = 0; row < nRows; row++) {
  381.             final T[] dataRow = data[row];
  382.             T sum = getField().getZero();
  383.             for (int i = 0; i < nCols; i++) {
  384.                 sum = sum.add(dataRow[i].multiply(v[i]));
  385.             }
  386.             out[row] = sum;
  387.         }
  388.         return out;
  389.     }

  390.     /** {@inheritDoc} */
  391.     @Override
  392.     public T[] preMultiply(final T[] v) throws DimensionMismatchException {
  393.         final int nRows = getRowDimension();
  394.         final int nCols = getColumnDimension();
  395.         if (v.length != nRows) {
  396.             throw new DimensionMismatchException(v.length, nRows);
  397.         }

  398.         final T[] out = MathArrays.buildArray(getField(), nCols);
  399.         for (int col = 0; col < nCols; ++col) {
  400.             T sum = getField().getZero();
  401.             for (int i = 0; i < nRows; ++i) {
  402.                 sum = sum.add(data[i][col].multiply(v[i]));
  403.             }
  404.             out[col] = sum;
  405.         }

  406.         return out;
  407.     }

  408.     /** {@inheritDoc} */
  409.     @Override
  410.     public T walkInRowOrder(final FieldMatrixChangingVisitor<T> visitor) {
  411.         final int rows    = getRowDimension();
  412.         final int columns = getColumnDimension();
  413.         visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
  414.         for (int i = 0; i < rows; ++i) {
  415.             final T[] rowI = data[i];
  416.             for (int j = 0; j < columns; ++j) {
  417.                 rowI[j] = visitor.visit(i, j, rowI[j]);
  418.             }
  419.         }
  420.         return visitor.end();
  421.     }

  422.     /** {@inheritDoc} */
  423.     @Override
  424.     public T walkInRowOrder(final FieldMatrixPreservingVisitor<T> visitor) {
  425.         final int rows    = getRowDimension();
  426.         final int columns = getColumnDimension();
  427.         visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
  428.         for (int i = 0; i < rows; ++i) {
  429.             final T[] rowI = data[i];
  430.             for (int j = 0; j < columns; ++j) {
  431.                 visitor.visit(i, j, rowI[j]);
  432.             }
  433.         }
  434.         return visitor.end();
  435.     }

  436.     /** {@inheritDoc} */
  437.     @Override
  438.     public T walkInRowOrder(final FieldMatrixChangingVisitor<T> visitor,
  439.                             final int startRow, final int endRow,
  440.                             final int startColumn, final int endColumn)
  441.         throws OutOfRangeException, NumberIsTooSmallException {
  442.         checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
  443.         visitor.start(getRowDimension(), getColumnDimension(),
  444.                       startRow, endRow, startColumn, endColumn);
  445.         for (int i = startRow; i <= endRow; ++i) {
  446.             final T[] rowI = data[i];
  447.             for (int j = startColumn; j <= endColumn; ++j) {
  448.                 rowI[j] = visitor.visit(i, j, rowI[j]);
  449.             }
  450.         }
  451.         return visitor.end();
  452.     }

  453.     /** {@inheritDoc} */
  454.     @Override
  455.     public T walkInRowOrder(final FieldMatrixPreservingVisitor<T> visitor,
  456.                             final int startRow, final int endRow,
  457.                             final int startColumn, final int endColumn)
  458.         throws OutOfRangeException, NumberIsTooSmallException {
  459.         checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
  460.         visitor.start(getRowDimension(), getColumnDimension(),
  461.                       startRow, endRow, startColumn, endColumn);
  462.         for (int i = startRow; i <= endRow; ++i) {
  463.             final T[] rowI = data[i];
  464.             for (int j = startColumn; j <= endColumn; ++j) {
  465.                 visitor.visit(i, j, rowI[j]);
  466.             }
  467.         }
  468.         return visitor.end();
  469.     }

  470.     /** {@inheritDoc} */
  471.     @Override
  472.     public T walkInColumnOrder(final FieldMatrixChangingVisitor<T> visitor) {
  473.         final int rows    = getRowDimension();
  474.         final int columns = getColumnDimension();
  475.         visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
  476.         for (int j = 0; j < columns; ++j) {
  477.             for (int i = 0; i < rows; ++i) {
  478.                 final T[] rowI = data[i];
  479.                 rowI[j] = visitor.visit(i, j, rowI[j]);
  480.             }
  481.         }
  482.         return visitor.end();
  483.     }

  484.     /** {@inheritDoc} */
  485.     @Override
  486.     public T walkInColumnOrder(final FieldMatrixPreservingVisitor<T> visitor) {
  487.         final int rows    = getRowDimension();
  488.         final int columns = getColumnDimension();
  489.         visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
  490.         for (int j = 0; j < columns; ++j) {
  491.             for (int i = 0; i < rows; ++i) {
  492.                 visitor.visit(i, j, data[i][j]);
  493.             }
  494.         }
  495.         return visitor.end();
  496.     }

  497.     /** {@inheritDoc} */
  498.     @Override
  499.     public T walkInColumnOrder(final FieldMatrixChangingVisitor<T> visitor,
  500.                                final int startRow, final int endRow,
  501.                                final int startColumn, final int endColumn)
  502.         throws OutOfRangeException, NumberIsTooSmallException {
  503.     checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
  504.         visitor.start(getRowDimension(), getColumnDimension(),
  505.                       startRow, endRow, startColumn, endColumn);
  506.         for (int j = startColumn; j <= endColumn; ++j) {
  507.             for (int i = startRow; i <= endRow; ++i) {
  508.                 final T[] rowI = data[i];
  509.                 rowI[j] = visitor.visit(i, j, rowI[j]);
  510.             }
  511.         }
  512.         return visitor.end();
  513.     }

  514.     /** {@inheritDoc} */
  515.     @Override
  516.     public T walkInColumnOrder(final FieldMatrixPreservingVisitor<T> visitor,
  517.                                final int startRow, final int endRow,
  518.                                final int startColumn, final int endColumn)
  519.         throws OutOfRangeException, NumberIsTooSmallException {
  520.         checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
  521.         visitor.start(getRowDimension(), getColumnDimension(),
  522.                       startRow, endRow, startColumn, endColumn);
  523.         for (int j = startColumn; j <= endColumn; ++j) {
  524.             for (int i = startRow; i <= endRow; ++i) {
  525.                 visitor.visit(i, j, data[i][j]);
  526.             }
  527.         }
  528.         return visitor.end();
  529.     }

  530.     /**
  531.      * Get a fresh copy of the underlying data array.
  532.      *
  533.      * @return a copy of the underlying data array.
  534.      */
  535.     private T[][] copyOut() {
  536.         final int nRows = this.getRowDimension();
  537.         final T[][] out = MathArrays.buildArray(getField(), nRows, getColumnDimension());
  538.         // can't copy 2-d array in one shot, otherwise get row references
  539.         for (int i = 0; i < nRows; i++) {
  540.             System.arraycopy(data[i], 0, out[i], 0, data[i].length);
  541.         }
  542.         return out;
  543.     }

  544.     /**
  545.      * Replace data with a fresh copy of the input array.
  546.      *
  547.      * @param in Data to copy.
  548.      * @throws NoDataException if the input array is empty.
  549.      * @throws DimensionMismatchException if the input array is not rectangular.
  550.      * @throws NullArgumentException if the input array is {@code null}.
  551.      */
  552.     private void copyIn(final T[][] in)
  553.         throws NullArgumentException, NoDataException,
  554.         DimensionMismatchException {
  555.         setSubMatrix(in, 0, 0);
  556.     }
  557. }