Beispiel #1
0
 /// <summary>
 /// Adds two real, rectangular matrices.
 /// </summary>
 /// <param name="A">The first matrix.</param>
 /// <param name="B">The second matrix.</param>
 /// <returns>The sum matrix <paramref name="A"/> + <paramref name="B"/>.</returns>
 public static RectangularMatrix operator +(RectangularMatrix A, RectangularMatrix B)
 {
     if (A == null)
     {
         throw new ArgumentNullException(nameof(A));
     }
     if (B == null)
     {
         throw new ArgumentNullException(nameof(B));
     }
     if (A.rows != B.rows)
     {
         throw new DimensionMismatchException();
     }
     if (A.cols != B.cols)
     {
         throw new DimensionMismatchException();
     }
     double[] abStore = MatrixAlgorithms.Add(
         A.store, A.offset, A.rowStride, A.colStride,
         B.store, B.offset, B.rowStride, B.colStride,
         A.rows, A.cols
         );
     return(new RectangularMatrix(abStore, A.rows, A.cols));
 }
Beispiel #2
0
        // operators

        /// <summary>
        /// Adds two real, square matrices.
        /// </summary>
        /// <param name="A">The first matrix.</param>
        /// <param name="B">The second matrix.</param>
        /// <returns>The sum matrix <paramref name="A"/> + <paramref name="B"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="A"/> or <paramref name="B"/> is null.</exception>
        /// <exception cref="DimensionMismatchException">The dimension of <paramref name="A"/> is not the same as the dimension of <paramref name="B"/>.</exception>
        public static SquareMatrix operator +(SquareMatrix A, SquareMatrix B)
        {
            if (A == null)
            {
                throw new ArgumentNullException("A");
            }
            if (B == null)
            {
                throw new ArgumentNullException("B");
            }
            if (A.dimension != B.dimension)
            {
                throw new DimensionMismatchException();
            }
            double[] abStore = MatrixAlgorithms.Add(A.store, B.store, A.dimension, A.dimension);
            return(new SquareMatrix(abStore, A.dimension));
        }