public override void KroneckerProduct(Matrix<Complex> other, Matrix<Complex> result) { if (other == null) { throw new ArgumentNullException("other"); } if (result == null) { throw new ArgumentNullException("result"); } if (result.RowCount != (RowCount*other.RowCount) || result.ColumnCount != (ColumnCount*other.ColumnCount)) { throw DimensionsDontMatch<ArgumentOutOfRangeException>(this, other, result); } var rowPointers = _storage.RowPointers; var columnIndices = _storage.ColumnIndices; var values = _storage.Values; var valueCount = _storage.ValueCount; for (var i = 0; i < RowCount; i++) { // Get the begin / end index for the current row var startIndex = rowPointers[i]; var endIndex = i < rowPointers.Length - 1 ? rowPointers[i + 1] : valueCount; for (var j = startIndex; j < endIndex; j++) { if (!values[j].IsZero()) { result.SetSubMatrix(i*other.RowCount, other.RowCount, columnIndices[j]*other.ColumnCount, other.ColumnCount, values[j]*other); } } } }
public override void KroneckerProduct(Matrix<float> other, Matrix<float> result) { if (other == null) { throw new ArgumentNullException("other"); } if (result == null) { throw new ArgumentNullException("result"); } if (result.RowCount != (RowCount*other.RowCount) || result.ColumnCount != (ColumnCount*other.ColumnCount)) { throw DimensionsDontMatch<ArgumentOutOfRangeException>(this, other, result); } var rowPointers = _storage.RowPointers; var columnIndices = _storage.ColumnIndices; var values = _storage.Values; for (var i = 0; i < RowCount; i++) { var endIndex = rowPointers[i + 1]; for (var j = rowPointers[i]; j < endIndex; j++) { if (values[j] != 0f) { result.SetSubMatrix(i*other.RowCount, other.RowCount, columnIndices[j]*other.ColumnCount, other.ColumnCount, values[j]*other); } } } }
/// <summary> /// Diagonally stacks his matrix on top of the given matrix and places the combined matrix into the result matrix. /// </summary> /// <param name="lower">The lower, right matrix.</param> /// <param name="result">The combined matrix</param> /// <exception cref="ArgumentNullException">If lower is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException">If the result matrix is <see langword="null" />.</exception> /// <exception cref="ArgumentException">If the result matrix's dimensions are not (this.Rows + lower.rows) x (this.Columns + lower.Columns).</exception> public override void DiagonalStack(Matrix<float> lower, Matrix<float> result) { if (lower == null) { throw new ArgumentNullException("lower"); } if (result == null) { throw new ArgumentNullException("result"); } if (result.RowCount != RowCount + lower.RowCount || result.ColumnCount != ColumnCount + lower.ColumnCount) { throw DimensionsDontMatch<ArgumentException>(this, lower, result); } // Clear the result matrix result.Clear(); // Copy the diagonal part into the result matrix. for (var i = 0; i < _data.Length; i++) { result[i, i] = _data[i]; } // Copy the lower matrix into the result matrix. result.SetSubMatrix(RowCount, lower.RowCount, ColumnCount, lower.ColumnCount, lower); }