public override void layMatrixAt(Matrix<double> subMatrix, int i, int j) { checkPositive(i,j); checkBounds(i + subMatrix.RowCount, j + subMatrix.ColumnCount); for(int k=0; k<subMatrix.RowCount; k++) for(int m=0; m<subMatrix.ColumnCount; m++) this.setItemAt(i+k, j+m, subMatrix.getItemAt(k,m)); }
protected override Matrix<double> sum(Matrix<double> another) { if (this.rows != another.RowCount || this.columns != another.ColumnCount) throw new ArgumentException("Matrices must be of the same size in order to sum."); // If the matrix is SDA, we can do it quick'n'lucky. if (this.GetType().IsInstanceOfType(another)) { Matrix_SDA temp = (Matrix_SDA)another; Matrix_SDA newMatrix = new Matrix_SDA(this.rows, this.columns); for (int i = 0; i < this.ElementCount; i++) newMatrix.matrixArray[i] = this.matrixArray[i] + temp.matrixArray[i]; return newMatrix; } // Here comes the bad case else { Matrix_SDA newMatrix = new Matrix_SDA(this.rows, this.columns); for (int i = 0; i < this.ElementCount; i++) newMatrix.matrixArray[i] = this.matrixArray[i] + another.getItemAt(i / columns, i % columns); return newMatrix; } }