Esempio n. 1
0
 public static double[] Subtract(double[] aStore, int aOffset, int aStride, double[] bStore, int bOffset, int bStride, int dimension)
 {
     double[] store = new double[dimension];
     Blas1.dCopy(aStore, aOffset, aStride, store, 0, 1, dimension);
     Blas1.dAxpy(-1.0, bStore, bOffset, bStride, store, 0, 1, dimension);
     return(store);
 }
Esempio n. 2
0
 /// <summary>
 /// Gets the U factor.
 /// </summary>
 /// <returns>The upper-right triangular factor U of the LU decomposition.</returns>
 public SquareMatrix UMatrix()
 {
     double[] uStore = new double[dimension * dimension];
     for (int c = 0; c < dimension; c++)
     {
         Blas1.dCopy(luStore, dimension * c, 1, uStore, dimension * c, 1, c + 1);
     }
     return(new SquareMatrix(uStore, dimension));
 }
Esempio n. 3
0
 /// <inheritdoc />
 public override RowVector Row(int r)
 {
     if ((r < 0) || (r >= rows))
     {
         throw new ArgumentOutOfRangeException(nameof(r));
     }
     double[] rStore = new double[cols];
     Blas1.dCopy(store, offset + rowStride * r, colStride, rStore, 0, 1, cols);
     return(new RowVector(rStore, cols));
 }
Esempio n. 4
0
 /// <inheritdoc />
 public override ColumnVector Column(int c)
 {
     if ((c < 0) || (c >= cols))
     {
         throw new ArgumentOutOfRangeException(nameof(c));
     }
     double[] cStore = new double[rows];
     Blas1.dCopy(store, offset + colStride * c, rowStride, cStore, 0, 1, rows);
     return(new ColumnVector(cStore, rows));
 }
Esempio n. 5
0
 /// <summary>
 /// Gets the L factor.
 /// </summary>
 /// <returns>The lower-left triangular factor L of the LU decomposition.</returns>
 /// <remarks>
 /// <para>The pivoted LU decomposition algorithm guarantees that the diagonal entries of this matrix are all one, and
 /// that the magnitudes of the sub-diagonal entries are all less than or equal to one.</para>
 /// </remarks>
 public SquareMatrix LMatrix()
 {
     double[] lStore = new double[dimension * dimension];
     for (int c = 0; c < dimension; c++)
     {
         int i0 = dimension * c + c;
         lStore[i0] = 1.0;
         Blas1.dCopy(luStore, i0 + 1, 1, lStore, i0 + 1, 1, dimension - c - 1);
     }
     return(new SquareMatrix(lStore, dimension));
 }
Esempio n. 6
0
        /// <summary>
        /// Sort the eigenvalues as specified.
        /// </summary>
        /// <param name="order">The desired ordering.</param>
        public void Sort(OrderBy order)
        {
            // Create an auxiluary array of indexes to sort
            int[] ranks = new int[dimension];
            for (int i = 0; i < ranks.Length; i++)
            {
                ranks[i] = i;
            }

            // Sort indexes in the requested order
            Comparison <int> comparison;

            switch (order)
            {
            case OrderBy.ValueAscending:
                comparison = (int a, int b) => eigenvalues[a].CompareTo(eigenvalues[b]);
                break;

            case OrderBy.ValueDescending:
                comparison = (int a, int b) => eigenvalues[b].CompareTo(eigenvalues[a]);
                break;

            case OrderBy.MagnitudeAscending:
                comparison = (int a, int b) => Math.Abs(eigenvalues[a]).CompareTo(Math.Abs(eigenvalues[b]));
                break;

            case OrderBy.MagnitudeDescending:
                comparison = (int a, int b) => Math.Abs(eigenvalues[b]).CompareTo(Math.Abs(eigenvalues[a]));
                break;

            default:
                throw new NotSupportedException();
            }
            Array.Sort(ranks, comparison);

            // Create new storage in the desired order and discard the old storage
            // This is faster than moving within existing storage since we can move each column just once.
            double[] newEigenvalues        = new double[dimension];
            double[] newEigenvectorStorage = new double[dimension * dimension];
            for (int i = 0; i < ranks.Length; i++)
            {
                newEigenvalues[i] = eigenvalues[ranks[i]];
                Blas1.dCopy(eigenvectorStorage, dimension * ranks[i], 1, newEigenvectorStorage, dimension * i, 1, dimension);
            }
            eigenvalues        = newEigenvalues;
            eigenvectorStorage = newEigenvectorStorage;
        }
Esempio n. 7
0
 public static double[] Copy(double[] store, int offset, int rowStride, int colStride, int nRows, int nCols)
 {
     double[] copyStore = AllocateStorage(nRows, nCols);
     if ((rowStride == 1) && (colStride == nRows))
     {
         Array.Copy(store, offset, copyStore, 0, copyStore.Length);
     }
     else
     {
         for (int c = 0; c < nCols; c++)
         {
             int sourceIndex = offset + colStride * c;
             int copyIndex   = nRows * c;
             Blas1.dCopy(store, sourceIndex, rowStride, copyStore, copyIndex, 1, nRows);
         }
     }
     return(copyStore);
 }
Esempio n. 8
0
 public static double[] Copy(double[] store, int offset, int stride, int dimension)
 {
     double[] copy = new double[dimension];
     Blas1.dCopy(store, offset, stride, copy, 0, 1, dimension);
     return(copy);
 }
Esempio n. 9
0
 void ICollection <double> .CopyTo(double[] array, int arrayIndex)
 {
     Blas1.dCopy(store, offset, stride, array, arrayIndex, 1, dimension);
 }