/// <summary> /// Initializes a new instance of the <see cref="DenseMatrix"/> class from a 2D array. This constructor /// will allocate a completely new memory block for storing the dense matrix. /// </summary> /// <param name="array">The 2D array to create this matrix from.</param> public DenseMatrix(Complex32[,] array) : base(array.GetLength(0), array.GetLength(1)) { _rowCount = array.GetLength(0); _columnCount = array.GetLength(1); Data = new Complex32[_rowCount * _columnCount]; for (var i = 0; i < _rowCount; i++) { for (var j = 0; j < _columnCount; j++) { Data[(j * _rowCount) + i] = array[i, j]; } } }
/// <summary> /// Initializes a new instance of the <see cref="DiagonalMatrix"/> class from a 2D array. /// </summary> /// <param name="array">The 2D array to create this matrix from.</param> /// <exception cref="IndexOutOfRangeException">When <paramref name="array"/> contains an off-diagonal element.</exception> /// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/> /// may be thrown if one of the indices is outside the dimensions of the matrix.</exception> public DiagonalMatrix(Complex32[,] array) : this(array.GetLength(0), array.GetLength(1)) { var rows = array.GetLength(0); var columns = array.GetLength(1); for (var i = 0; i < rows; i++) { for (var j = 0; j < columns; j++) { if (i == j) { Data[i] = array[i, j]; } else if (((array[i, j].Real != 0.0) && !double.IsNaN(array[i, j].Real)) || ((array[i, j].Imaginary != 0.0) && !double.IsNaN(array[i, j].Imaginary))) { throw new IndexOutOfRangeException("Cannot set an off-diagonal element in a diagonal matrix."); } } } }
/// <summary> /// Initializes a new instance of the <see cref="SparseMatrix"/> class from a 2D array. /// </summary> /// <param name="array">The 2D array to create this matrix from.</param> public SparseMatrix(Complex32[,] array) : this(array.GetLength(0), array.GetLength(1)) { var rows = array.GetLength(0); var columns = array.GetLength(1); for (var i = 0; i < rows; i++) { for (var j = 0; j < columns; j++) { SetValueAt(i, j, array[i, j]); } } }
/// <summary> /// Initializes a new instance of the <see cref="DenseMatrix"/> class from a 2D array. This constructor /// will allocate a completely new memory block for storing the dense matrix. /// </summary> /// <param name="array">The 2D array to create this matrix from.</param> public DenseMatrix(Complex32[,] array) : this(array.GetLength(0), array.GetLength(1)) { for (var i = 0; i < _rowCount; i++) { for (var j = 0; j < _columnCount; j++) { _data[(j * _rowCount) + i] = array[i, j]; } } }
/// <summary> /// Initializes a new instance of the <see cref="SparseMatrix"/> class from a 2D array. /// </summary> /// <param name="array">The 2D array to create this matrix from.</param> public SparseMatrix(Complex32[,] array) : this(array.GetLength(0), array.GetLength(1)) { for (var i = 0; i < _storage.RowCount; i++) { for (var j = 0; j < _storage.ColumnCount; j++) { _storage.At(i, j, array[i, j]); } } }
/// <summary> /// Initializes a new instance of the <see cref="DenseMatrix"/> class from a 2D array. This constructor /// will allocate a completely new memory block for storing the dense matrix. /// </summary> /// <param name="array">The 2D array to create this matrix from.</param> public DenseMatrix(Complex32[,] array) : base(array.GetLength(0), array.GetLength(1)) { var rows = array.GetLength(0); var columns = array.GetLength(1); Data = new Complex32[rows * columns]; for (var i = 0; i < rows; i++) { for (var j = 0; j < columns; j++) { Data[(j * rows) + i] = array[i, j]; } } }