예제 #1
0
        /// <summary>
        /// Adds another matrix to this matrix.
        /// </summary>
        /// <param name="other">The matrix to add to this matrix.</param>
        /// <param name="result">The matrix to store the result of the addition.</param>
        /// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
        protected override void DoAdd(Matrix <double> other, Matrix <double> result)
        {
            // diagonal + diagonal = diagonal
            var diagOther  = other as DiagonalMatrix;
            var diagResult = result as DiagonalMatrix;

            if (diagOther != null && diagResult != null)
            {
                Control.LinearAlgebraProvider.AddArrays(_data, diagOther._data, diagResult._data);
                return;
            }

            other.CopyTo(result);
            for (int i = 0; i < _data.Length; i++)
            {
                result.At(i, i, result.At(i, i) + _data[i]);
            }
        }
예제 #2
0
        /// <summary>
        /// Adds another matrix to this matrix.
        /// </summary>
        /// <param name="other">The matrix to add to this matrix.</param>
        /// <param name="result">The matrix to store the result of the addition.</param>
        /// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
        protected override void DoAdd(Matrix <double> other, Matrix <double> result)
        {
            // diagonal + diagonal = diagonal
            var diagOther  = other as DiagonalMatrix;
            var diagResult = result as DiagonalMatrix;

            if (diagOther != null && diagResult != null)
            {
                Map2((x, y) => x + y, other, result, Zeros.AllowSkip);
                return;
            }

            other.CopyTo(result);
            for (int i = 0; i < _data.Length; i++)
            {
                result.At(i, i, result.At(i, i) + _data[i]);
            }
        }