/// <summary> /// Adds two matrices. This operation can only be performed if the matrices are of the same type and dimensions. </summary> /// <param name="m1"> The first matrix, not null </param> /// <param name="m2"> The second matrix, not null </param> /// <returns> The sum of the two matrices </returns> /// <exception cref="IllegalArgumentException"> If the matrices are not of the same type, if the matrices are not the same shape. </exception> public virtual Matrix add(Matrix m1, Matrix m2) { ArgChecker.notNull(m1, "m1"); ArgChecker.notNull(m2, "m2"); if (m1 is DoubleArray) { if (m2 is DoubleArray) { DoubleArray array1 = (DoubleArray)m1; DoubleArray array2 = (DoubleArray)m2; return(array1.plus(array2)); } throw new System.ArgumentException("Tried to add a " + m1.GetType() + " and " + m2.GetType()); } else if (m1 is DoubleMatrix) { if (m2 is DoubleMatrix) { DoubleMatrix matrix1 = (DoubleMatrix)m1; DoubleMatrix matrix2 = (DoubleMatrix)m2; return(matrix1.plus(matrix2)); } throw new System.ArgumentException("Tried to add a " + m1.GetType() + " and " + m2.GetType()); } throw new System.NotSupportedException(); }