示例#1
0
 /// <inheritdoc/>
 public new void multiplyEntry(int row, int column, double factor)
 {
     // we don't care about non-diagonal elements for multiplication
     if (row == column)
     {
         MatrixUtils.checkRowIndex(this, row);
         data[row] *= factor;
     }
 }
示例#2
0
 /// <inheritdoc/>
 /// <exception cref="NumberIsTooLargeException"> if <c>row != column</c> and increment is
 /// non-zero.</exception>
 public new void addToEntry(int row, int column, double increment)
 {
     if (row == column)
     {
         MatrixUtils.checkRowIndex(this, row);
         data[row] += increment;
     }
     else
     {
         ensureZero(increment);
     }
 }
示例#3
0
 /// <inheritdoc/>
 /// <exception cref="NumberIsTooLargeException"> if <c>row != column</c> and value is
 /// non-zero.</exception>
 public override void setEntry(int row, int column, double value)
 {
     if (row == column)
     {
         MatrixUtils.checkRowIndex(this, row);
         data[row] = value;
     }
     else
     {
         ensureZero(value);
     }
 }
 /// <inheritdoc/>
 public override void setEntry(int row, int column, double value)
 {
     MatrixUtils.checkRowIndex(this, row);
     MatrixUtils.checkColumnIndex(this, column);
     if (value == 0.0)
     {
         entries.remove(computeKey(row, column));
     }
     else
     {
         entries.put(computeKey(row, column), value);
     }
 }
        /// <inheritdoc/>
        public double[] getRow(int row)
        {
            MatrixUtils.checkRowIndex(this, row);
            int nCols = getColumnDimension();

            double[] outp = new double[nCols];
            for (int i = 0; i < nCols; ++i)
            {
                outp[i] = getEntry(row, i);
            }

            return(outp);
        }
        /// <inheritdoc/>
        public RealMatrix getRowMatrix(int row)
        {
            MatrixUtils.checkRowIndex(this, row);
            int        nCols = getColumnDimension();
            RealMatrix outp  = createMatrix(1, nCols);

            for (int i = 0; i < nCols; ++i)
            {
                outp.setEntry(0, i, getEntry(row, i));
            }

            return(outp);
        }
        /// <inheritdoc/>
        public void setRow(int row, double[] array)
        {
            MatrixUtils.checkRowIndex(this, row);
            int nCols = getColumnDimension();

            if (array.Length != nCols)
            {
                throw new MatrixDimensionMismatchException(1, array.Length, 1, nCols);
            }
            for (int i = 0; i < nCols; ++i)
            {
                setEntry(row, i, array[i]);
            }
        }
        /// <inheritdoc/>
        public void setRowVector(int row, RealVector vector)
        {
            MatrixUtils.checkRowIndex(this, row);
            int nCols = getColumnDimension();

            if (vector.getDimension() != nCols)
            {
                throw new MatrixDimensionMismatchException(1, vector.getDimension(),
                                                           1, nCols);
            }
            for (int i = 0; i < nCols; ++i)
            {
                setEntry(row, i, vector.getEntry(i));
            }
        }
        /// <inheritdoc/>
        public new void multiplyEntry(int row, int column, double factor)
        {
            MatrixUtils.checkRowIndex(this, row);
            MatrixUtils.checkColumnIndex(this, column);
            int    key   = computeKey(row, column);
            double value = entries.get(key) * factor;

            if (value == 0.0)
            {
                entries.remove(key);
            }
            else
            {
                entries.put(key, value);
            }
        }
        /// <inheritdoc/>
        public new void addToEntry(int row, int column, double increment)
        {
            MatrixUtils.checkRowIndex(this, row);
            MatrixUtils.checkColumnIndex(this, column);
            int    key   = computeKey(row, column);
            double value = entries.get(key) + increment;

            if (value == 0.0)
            {
                entries.remove(key);
            }
            else
            {
                entries.put(key, value);
            }
        }
        /// <inheritdoc/>
        public void setRowMatrix(int row, RealMatrix matrix)
        {
            MatrixUtils.checkRowIndex(this, row);
            int nCols = getColumnDimension();

            if ((matrix.getRowDimension() != 1) ||
                (matrix.getColumnDimension() != nCols))
            {
                throw new MatrixDimensionMismatchException(matrix.getRowDimension(),
                                                           matrix.getColumnDimension(),
                                                           1, nCols);
            }
            for (int i = 0; i < nCols; ++i)
            {
                setEntry(row, i, matrix.getEntry(0, i));
            }
        }
        /// <inheritdoc/>
        public void setSubMatrix(double[][] subMatrix, int row, int column)
        {
            MathUtils.checkNotNull(subMatrix);
            int nRows = subMatrix.Length;

            if (nRows == 0)
            {
                throw new NoDataException(new LocalizedFormats("AT_LEAST_ONE_ROW"));
            }

            int nCols = subMatrix[0].Length;

            if (nCols == 0)
            {
                throw new NoDataException(new LocalizedFormats("AT_LEAST_ONE_COLUMN"));
            }

            for (int r = 1; r < nRows; ++r)
            {
                if (subMatrix[r].Length != nCols)
                {
                    throw new DimensionMismatchException(nCols, subMatrix[r].Length);
                }
            }

            MatrixUtils.checkRowIndex(this, row);
            MatrixUtils.checkColumnIndex(this, column);
            MatrixUtils.checkRowIndex(this, nRows + row - 1);
            MatrixUtils.checkColumnIndex(this, nCols + column - 1);

            for (int i = 0; i < nRows; ++i)
            {
                for (int j = 0; j < nCols; ++j)
                {
                    setEntry(row + i, column + j, subMatrix[i][j]);
                }
            }
        }
 /// <inheritdoc/>
 public override double getEntry(int row, int column)
 {
     MatrixUtils.checkRowIndex(this, row);
     MatrixUtils.checkColumnIndex(this, column);
     return(entries.get(computeKey(row, column)));
 }