internal DenseMatrix(DenseColumnMajorMatrixStorage<double> storage) : base(storage) { _rowCount = storage.RowCount; _columnCount = storage.ColumnCount; _values = storage.Data; }
/// <summary> /// Create a new dense matrix straight from an initialized matrix storage instance. /// The storage is used directly without copying. /// Intended for advanced scenarios where you're working directly with /// storage for performance or interop reasons. /// </summary> public DenseMatrix(DenseColumnMajorMatrixStorage<Complex32> storage) : base(storage) { _rowCount = storage.RowCount; _columnCount = storage.ColumnCount; _values = storage.Data; }
internal DenseMatrix(DenseColumnMajorMatrixStorage<Complex32> storage) : base(storage) { _storage = storage; _rowCount = _storage.RowCount; _columnCount = _storage.ColumnCount; _data = _storage.Data; }
/// <summary> /// Create a new dense matrix as a copy of the given enumerable of enumerable rows. /// Each enumerable in the master enumerable specifies a row. /// This new matrix will be independent from the enumerables. /// A new memory block will be allocated for storing the matrix. /// </summary> public static DenseMatrix OfRowsCovariant <TRow>(int rows, int columns, IEnumerable <TRow> data) where TRow : IEnumerable <float> { return(new DenseMatrix(DenseColumnMajorMatrixStorage <float> .OfRowEnumerables(rows, columns, data))); }
/// <summary> /// Create a new dense matrix and initialize each value using the provided init function. /// </summary> public static DenseMatrix Create(int rows, int columns, Func <int, int, float> init) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <float> .OfInit(rows, columns, init))); }
/// <summary> /// Create a new dense matrix as a copy of the given column arrays. /// This new matrix will be independent from the arrays. /// A new memory block will be allocated for storing the matrix. /// </summary> public static DenseMatrix OfColumnArrays(params float[][] columns) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <float> .OfColumnArrays(columns))); }
/// <summary> /// Create a new dense matrix as a copy of the given enumerable of enumerable columns. /// Each enumerable in the master enumerable specifies a column. /// This new matrix will be independent from the enumerables. /// A new memory block will be allocated for storing the matrix. /// </summary> public static DenseMatrix OfColumns(int rows, int columns, IEnumerable <IEnumerable <Complex> > data) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <Complex> .OfColumnEnumerables(rows, columns, data))); }
/// <summary> /// Applies the inverse Fast Fourier Transform (iFFT) to a two dimensional data in form of a matrix. /// </summary> /// <param name="spectrum">Sample matrix, where the iFFT is evaluated in place</param> /// <param name="options">Fourier Transform Convention Options.</param> public static void Inverse2D(Matrix<Complex> spectrum, FourierOptions options = FourierOptions.Default) { // since dense matrix data is column major, we switch rows and columns var denseStorage = spectrum.Storage as DenseColumnMajorMatrixStorage<Complex>; if (denseStorage == null) { var samplesColumnMajor = spectrum.ToColumnWiseArray(); InverseMultiDim(samplesColumnMajor, new[] { spectrum.ColumnCount, spectrum.RowCount }, options); denseStorage = new DenseColumnMajorMatrixStorage<Complex>(spectrum.RowCount, spectrum.ColumnCount, samplesColumnMajor); denseStorage.CopyToUnchecked(spectrum.Storage, ExistingData.Clear); return; } InverseMultiDim(denseStorage.Data, new[] { spectrum.ColumnCount, spectrum.RowCount }, options); }
public void ReturnFloatMatrixStorage(DenseColumnMajorMatrixStorage<float> storage) { lock (_lock) { if (!_floatMatrixStoragePool.Contains(storage)) _floatMatrixStoragePool.Add(storage); } }
/// <summary> /// Create a new square sparse identity matrix where each diagonal value is set to One. /// </summary> public static DenseMatrix CreateIdentity(int order) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <float> .OfDiagonalInit(order, order, i => One))); }
public DenseMatrix(float[,] array) : this(DenseColumnMajorMatrixStorage <float> .OfArray(array)) { }
/// <summary> /// Create a new dense matrix as a copy of the given row arrays. /// This new matrix will be independent from the arrays. /// A new memory block will be allocated for storing the matrix. /// </summary> public static DenseMatrix OfRowArrays(IEnumerable <float[]> rows) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <float> .OfRowArrays((rows as float[][]) ?? rows.ToArray()))); }
/// <summary> /// Create a new dense matrix as a copy of the given row vectors. /// This new matrix will be independent from the vectors. /// A new memory block will be allocated for storing the matrix. /// </summary> public static DenseMatrix OfRowVectors(IEnumerable <Vector <float> > rows) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <float> .OfRowVectors(rows.Select(r => r.Storage).ToArray()))); }
/// <summary> /// Create a new dense matrix as a copy of the given row arrays. /// This new matrix will be independent from the arrays. /// A new memory block will be allocated for storing the matrix. /// </summary> public static DenseMatrix OfRowArrays(params float[][] rows) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <float> .OfRowArrays(rows))); }
/// <summary> /// Create a new dense matrix as a copy of the given column vectors. /// This new matrix will be independent from the vectors. /// A new memory block will be allocated for storing the matrix. /// </summary> public static DenseMatrix OfColumnVectors(IEnumerable <Vector <float> > columns) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <float> .OfColumnVectors(columns.Select(c => c.Storage).ToArray()))); }
/// <summary> /// Create a new dense matrix as a copy of the given column arrays. /// This new matrix will be independent from the arrays. /// A new memory block will be allocated for storing the matrix. /// </summary> public static DenseMatrix OfColumnArrays(IEnumerable <float[]> columns) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <float> .OfColumnArrays((columns as float[][]) ?? columns.ToArray()))); }
/// <summary> /// Create a new dense matrix with values sampled from the provided random distribution. /// </summary> public static DenseMatrix CreateRandom(int rows, int columns, IContinuousDistribution distribution) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <float> .OfInit(rows, columns, (i, j) => (float)distribution.Sample()))); }
/// <summary> /// Create a new dense matrix as a copy of the given other matrix. /// This new matrix will be independent from the other matrix. /// A new memory block will be allocated for storing the matrix. /// </summary> public static DenseMatrix OfMatrix(Matrix <float> matrix) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <float> .OfMatrix(matrix.Storage))); }
public DenseMatrix(int rows, int columns, float value) : this(DenseColumnMajorMatrixStorage <float> .OfInit(rows, columns, (i, j) => value)) { }
/// <summary> /// Create a new dense matrix as a copy of the given two-dimensional array. /// This new matrix will be independent from the provided array. /// A new memory block will be allocated for storing the matrix. /// </summary> public static DenseMatrix OfArray(float[,] array) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <float> .OfArray(array))); }
public DenseMatrix(Matrix <float> matrix) : this(DenseColumnMajorMatrixStorage <float> .OfMatrix(matrix.Storage)) { }
/// <summary> /// Create a new dense matrix as a copy of the given row arrays. /// This new matrix will be independent from the arrays. /// A new memory block will be allocated for storing the matrix. /// </summary> public static DenseMatrix OfRowArrays(params Complex[][] rows) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <Complex> .OfRowArrays(rows))); }
public void ReturnComplex32MatrixStorage(DenseColumnMajorMatrixStorage<Complex32> storage) { lock (_lock) { if (!_complex32MatrixStoragePool.Contains(storage)) _complex32MatrixStoragePool.Add(storage); } }
/// <summary> /// Create a new dense matrix with values sampled from the provided random distribution. /// </summary> public static DenseMatrix CreateRandom(int rows, int columns, IContinuousDistribution distribution) { var storage = new DenseColumnMajorMatrixStorage<Complex>(rows, columns); for (var i = 0; i < storage.Data.Length; i++) { storage.Data[i] = new Complex(distribution.Sample(), distribution.Sample()); } return new DenseMatrix(storage); }
/// <summary> /// Create a new dense matrix as a copy of the given indexed enumerable. /// Keys must be provided at most once, zero is assumed if a key is omitted. /// This new matrix will be independent from the enumerable. /// A new memory block will be allocated for storing the matrix. /// </summary> public static DenseMatrix OfIndexed(int rows, int columns, IEnumerable <Tuple <int, int, float> > enumerable) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <float> .OfIndexedEnumerable(rows, columns, enumerable))); }
/// <summary> /// Create a new diagonal dense matrix and initialize each diagonal value using the provided init function. /// </summary> public static DenseMatrix CreateDiagonal(int rows, int columns, Func <int, Complex> init) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <Complex> .OfDiagonalInit(rows, columns, init))); }
/// <summary> /// Creates a matrix that contains the values from the requested sub-matrix. /// </summary> /// <param name="rowIndex">The row to start copying from.</param> /// <param name="rowCount">The number of rows to copy. Must be positive.</param> /// <param name="columnIndex">The column to start copying from.</param> /// <param name="columnCount">The number of columns to copy. Must be positive.</param> /// <returns>The requested sub-matrix.</returns> /// <exception cref="ArgumentOutOfRangeException">If: <list><item><paramref name="rowIndex"/> is /// negative, or greater than or equal to the number of rows.</item> /// <item><paramref name="columnIndex"/> is negative, or greater than or equal to the number /// of columns.</item> /// <item><c>(columnIndex + columnLength) >= Columns</c></item> /// <item><c>(rowIndex + rowLength) >= Rows</c></item></list></exception> /// <exception cref="ArgumentException">If <paramref name="rowCount"/> or <paramref name="columnCount"/> /// is not positive.</exception> public override Matrix<float> SubMatrix(int rowIndex, int rowCount, int columnIndex, int columnCount) { var storage = new DenseColumnMajorMatrixStorage<float>(rowCount, columnCount); _storage.CopySubMatrixTo(storage, rowIndex, 0, rowCount, columnIndex, 0, columnCount); return new DenseMatrix(storage.RowCount, storage.ColumnCount, storage.Data); }
/// <summary> /// Create a new dense matrix as a copy of the given enumerable. /// The enumerable is assumed to be in column-major order (column by column). /// This new matrix will be independent from the enumerable. /// A new memory block will be allocated for storing the matrix. /// </summary> public static DenseMatrix OfColumnMajor(int rows, int columns, IEnumerable <float> columnMajor) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <float> .OfColumnMajorEnumerable(rows, columns, columnMajor))); }
/// <summary> /// Create a new dense matrix as a copy of the given enumerable of enumerable rows. /// Each enumerable in the master enumerable specifies a row. /// This new matrix will be independent from the enumerables. /// A new memory block will be allocated for storing the matrix. /// </summary> public static DenseMatrix OfRows(int rows, int columns, IEnumerable <IEnumerable <float> > data) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <float> .OfRowEnumerables(rows, columns, data))); }
/// <summary> /// Create a new dense matrix as a copy of the given two-dimensional array. /// This new matrix will be independent from the provided array. /// A new memory block will be allocated for storing the matrix. /// </summary> public static DenseMatrix OfArray(Complex[,] array) { return(new DenseMatrix(DenseColumnMajorMatrixStorage <Complex> .OfArray(array))); }