示例#1
0
 /// <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;
 }
示例#2
0
 internal DenseMatrix(DenseColumnMajorMatrixStorage<double> 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;
 }
示例#4
0
 /// <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);
 }
示例#5
0
 /// <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) &gt;= Columns</c></item>
 /// <item><c>(rowIndex + rowLength) &gt;= 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);
 }
示例#6
0
        public void ReturnFloatMatrixStorage(DenseColumnMajorMatrixStorage<float> storage)
        {
            lock (_lock)
            {
                if (!_floatMatrixStoragePool.Contains(storage))
                    _floatMatrixStoragePool.Add(storage);

            }
        }
示例#7
0
        public void ReturnComplex32MatrixStorage(DenseColumnMajorMatrixStorage<Complex32> storage)
        {
            lock (_lock)
            {
                if (!_complex32MatrixStoragePool.Contains(storage))
                    _complex32MatrixStoragePool.Add(storage);

            }
        }
示例#8
0
        /// <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);
        }