// DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !!

        public static bool isequalwithequalnans(/*HC:*/ ILArray <fcomplex> A, /*HC:*/ ILArray <fcomplex> B)
        {
            if (object.Equals(A, null) || object.Equals(B, null))
            {
                return(!(object.Equals(A, null) ^ object.Equals(B, null)));
            }
            if (A.IsEmpty && B.IsEmpty)
            {
                return(true);
            }
            if (!A.Dimensions.IsSameSize(B.Dimensions))
            {
                return(false);
            }
            int pos = 0;

            foreach (fcomplex a in A.Values)
            {
                fcomplex b = B.GetValue(pos++);
                if (fcomplex.IsNaN(a) && fcomplex.IsNaN(b))
                {
                    continue;
                }
                if (fcomplex.IsInfinity(a) && fcomplex.IsInfinity(b))
                {
                    continue;
                }
                if (b != a)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #2
0
 /// <summary>
 /// sum all elements of array A
 /// </summary>
 /// <param name="A">n-dim array</param>
 /// <returns><para>scalar sum of all elements of A.</para>
 /// <para>If A is empty, an empty array will be returned.</para></returns>
 /// <exception cref="ILNumerics.Exceptions.ILArgumentException">if A was null.</exception>
 /// <seealso cref="ILNumerics.BuiltInFunctions.ILMath.sum(ILArray&lt;double&gt;)"/>
 public static  ILArray<fcomplex> sumall ( ILArray<fcomplex> A) {
     if (object.Equals(A,null))
         throw new ILArgumentException("sumall: argument must not be null!");
     if (A.IsEmpty) {
         return  ILArray<fcomplex> .empty(0,0); 
     } 
     fcomplex retArr =  new fcomplex(0.0f,0.0f) ; 
     if (A.m_indexOffset == null) {
         unsafe {
             fixed ( fcomplex * inArrStart = A.m_data) {
                 fcomplex * inArrWalk = inArrStart; 
                 fcomplex * inArrEnd = inArrStart + A.Dimensions.NumberOfElements; 
                 while (inArrWalk < inArrEnd) {
                     retArr += *inArrWalk++; 
                 }
             }
         }
     } else {
         unsafe {
             fixed ( fcomplex * inArrStart = A.m_data)  {
                 for (int i = A.Dimensions.NumberOfElements; i -->0;) {
                     retArr += *(inArrStart + A.getBaseIndex(i)); 
                 }
             }
         }
     }
     return new  ILArray<fcomplex> (new  fcomplex [1]{retArr},1,1);
 }
        /// <summary>
        /// create complex array out of real and imaginary part
        /// </summary>
        /// <param name="real">real array for real part</param>
        /// <param name="imag">real array for imaginary part</param>
        /// <returns>complex array having the real- and part imaginary parts constructed out of
        /// real and imag.</returns>
        /// <remarks>real and imag must be the same length. Eather one may be a row- or a column vector.
        /// The array returned will be the same size as real.</remarks>
        public static ILArray <fcomplex> real2fcomplex(/*!HC:inCls1*/ ILArray <double> real, /*!HC:inCls1*/ ILArray <double> imag)
        {
            int nrX = real.m_dimensions.NumberOfElements;

            fcomplex []        retArr = new fcomplex [nrX];
            ILArray <fcomplex> ret    = new ILArray <fcomplex> (retArr, real.m_dimensions);

            for (int i = 0; i < nrX; i++)
            {
                retArr[i] = new  fcomplex((float)real.GetValue(i), (float)imag.GetValue(i));
            }
            return(ret);
        }
        /// <summary>
        /// real part of complex array
        /// </summary>
        /// <param name="X">complex input array</param>
        /// <returns>real part of complex array</returns>
        public static ILArray <fcomplex> real2fcomplex(ILArray <float> X)
        {
            int nrX = X.m_dimensions.NumberOfElements;

            fcomplex []        retArr = new fcomplex [nrX];
            ILArray <fcomplex> ret    = new ILArray <fcomplex> (retArr, X.m_dimensions);

            for (int i = 0; i < nrX; i++)
            {
                retArr[i] = new  fcomplex((float)X.GetValue(i), (float)0.0);
            }
            return(ret);
        }
Exemple #5
0
        /// <summary>
        /// Decompose matrix A into uper and lower triangular part. Returns permutation matrix also.
        /// </summary>
        /// <param name="A">general input matrix. Size [m x n]</param>
        /// <param name="U">[output] reference to upper triangular matrix. Size [min(m,n) x n]. Must not be null.</param>
        /// <param name="P">[output] reference to permutation matrix. Size [min(m,n) x min(m,n)]. Must not be null.</param>
        /// <returns>lower triangular matrix L of size [m x min(m,n)]</returns>
        /// <remarks>A is decomposed into L and U, so that the equation
        /// <code>ILMath.multiply(L,U) == ILMath.multiply(P,A)</code>
        /// will hold except for round off error.
        /// <para>L and U will be true lower triangular matrices.</para>
        /// <example> <code>
        /// //Let's construct a matrix X:
        /// ILArray&lt;double&gt; X = new ILArray&lt;double&gt;(new double[]{1, 2, 3, 4, 4, 4, 5, 6, 7},3,3).T;
        /// // now X.ToString() will give something like:
        /// // {&lt;Double&gt; 63238509 [3x3] Ref(2)
        /// //(:,:)
        /// // 1,00000  2,00000  3,00000
        /// // 4,00000  4,00000  4,00000
        /// // 5,00000  6,00000  7,00000
        /// //}
        /// // construct references on U and P and call the decomposition
        /// ILArray&lt;double&gt; U = new ILArray&lt;double&gt;.empty();
        /// ILArray&lt;double&gt; P = new ILArray&lt;double&gt;.empty();
        /// ILArray&lt;double&gt; L = ILMath.lu(X, ref U, ref P);
        ///
        /// // L.ToString() is now:
        /// // {&lt;Double&gt; 19634871 [3x3] Phys.
        /// //(:,:)
        /// // 1,00000   0,00000   0,00000
        /// // 0,80000   1,00000   0,00000
        /// // 0,20000  -1,00000   1,00000
        /// //}
        /// // U is now:
        /// //{&lt;Double&gt; 22584602 [3x3] Phys.
        /// //(:,:)
        /// // 5,00000  6,00000  7,00000
        /// // 0,00000  -0,80000  -1,60000
        /// // 0,00000  0,00000  0,00000
        /// //}
        /// // and P is:
        /// //{&lt;Double&gt; 2192437 [3x3] Phys.
        /// //(:,:)
        /// // 0,00000  0,00000  1,00000
        /// // 0,00000  1,00000  0,00000
        /// // 1,00000  0,00000  0,00000
        /// //}
        /// </code>
        /// In order to reflect the pivoting done during the decomposition inside ?getrf, the matrix P may be used on A:
        /// <code>
        /// (ILMath.multiply(P,A) - ILMath.multiply(L,U)).ToString();
        /// // will give:
        /// //{&lt;Double&gt; 59192235 [3x3] Phys.
        /// //(:,:)
        /// // 0,00000  0,00000  0,00000
        /// // 0,00000  0,00000  0,00000
        /// // 0,00000  0,00000  0,00000
        /// //}
        /// </code>
        /// </example>
        /// <para>lu uses the Lapack function ?getrf.</para>
        /// <para>All of the matrices U,L,P returned will be solid ILArrays.</para>
        /// </remarks>
        /// <seealso cref="ILNumerics.BuiltInFunctions.ILMath.lu(ILArray&lt;double&gt;)"/>
        /// <seealso cref="ILNumerics.BuiltInFunctions.ILMath.lu(ILArray&lt;double&gt;, ref ILArray&lt;double&gt;)"/>
        /// <exception cref="ILNumerics.Exceptions.ILArgumentException"> if input A is not a matrix.</exception>
        public static ILArray <fcomplex> lu(ILArray <fcomplex> A, ref ILArray <fcomplex> U, ref ILArray <fcomplex> P)
        {
            if (!A.IsMatrix)
            {
                throw new ILArgumentSizeException("lu is defined for matrices only!");
            }
            int m = A.Dimensions[0], n = A.Dimensions[1], info = 0, minMN = (m < n)? m : n;
            ILArray <fcomplex> L = (ILArray <fcomplex>)A.Clone();

            int [] pivInd        = ILMemoryPool.Pool.New <int>(minMN);
            Lapack.cgetrf(m, n, L.m_data, m, pivInd, ref info);
            if (info < 0)
            {
                ILMemoryPool.Pool.RegisterObject(pivInd);
                throw new ILArgumentException("lu: illegal parameter error.");
                //} else if (info > 0) {
                //    // singular diagonal entry found
            }
            else
            {
                // completed successfuly
                if (!Object.Equals(U, null))
                {
                    if (!Object.Equals(P, null))
                    {
                        pivInd = perm2indicesForward(pivInd);
                        U      = copyUpperTriangle(L, minMN, n);
                        L      = copyLowerTriangle(L, m, minMN, new fcomplex(1.0f, 0.0f));
                        P      = ILArray <fcomplex> .zeros(minMN, minMN);

                        // construct permutation matrix P
                        for (int r = 0; r < m; r++)
                        {
                            P[r, pivInd[r]] = new fcomplex(1.0f, 0.0f);
                        }
                    }
                    else
                    {
                        pivInd = perm2indicesBackward(pivInd);
                        U      = copyUpperTriangle(L, minMN, n);
                        L      = copyLowerTrianglePerm(L, m, minMN, new fcomplex(1.0f, 0.0f), pivInd);
                    }
                }
            }
            ILMemoryPool.Pool.RegisterObject(pivInd);
            return(L);
        }
Exemple #6
0
        private void Test_AccuracyUnderflow()
        {
            float    c = 10e37f, d = 10e-37f, e = 10e29f, f = 10e-29f;
            fcomplex A = new fcomplex(c, d);
            fcomplex B = new fcomplex(e, f);
            fcomplex C = A / B;
            double   cd = 10e70, dd = 10e-70, ed = 10e56, fd = 10e-56;
            complex  Ad = new complex(cd, dd);
            complex  Bd = new complex(ed, fd);
            complex  Cd = Ad / Bd;
            // Smith(1) formula
            fcomplex t1 = f * 1 / e;
            fcomplex t2 = f * t1;
            fcomplex t3 = e + t2; // 10^56 ?
            fcomplex t4 = c * t1;
            fcomplex t5 = d - t4; // 10^-56 ?
            fcomplex b  = t5 / t3;

            Success();
        }
Exemple #7
0
        /// <summary>
        /// Determinant of square matrix
        /// </summary>
        /// <param name="A">square input matrix</param>
        /// <returns>determinant of A</returns>
        /// <remarks><para>The determinant is computed by decomposing A into upper and lower triangular part. Therefore LAPACK function ?getrf is used. <br />
        /// Due to the properties of determinants, det(a) is the same as det(L) * det(U),where det(L) can easily be extracted from the permutation indices returned from LU decomposition. det(U) - with U beeing an upper triangular matrix - equals the product of the diagonal elements.</para>
        /// <para>For scalar A, a plain copy of A is returned.</para></remarks>
        /// <example>Creating a nonsingular 4x4 (double) matrix and it's determinant
        /// <code>ILArray&lt;double&gt; A = ILMath.counter(1.0,1.0,4,4);
        ///A[1] = 0.0;  // make A nonsingular
        ///A[14] = 0.0; //(same as: A[2,3] = 0.0;)
        /// // A is now:
        /// //&lt;Double&gt; [4,4]
        /// //(:,:) 1e+001 *
        /// // 0,10000   0,50000   0,90000   1,30000
        /// // 0,00000   0,60000   1,00000   1,40000
        /// // 0,30000   0,70000   1,10000   0,00000
        /// // 0,40000   0,80000   1,20000   1,60000
        ///
        ///ILMath.det(A) gives:
        /// //&lt;Double&gt; -360
        ///</code></example>
        ///<exception cref="ILNumerics.Exceptions.ILArgumentException">if A is empty or not a square matrix</exception>
        public static ILArray <fcomplex> det(ILArray <fcomplex> A)
        {
            if (A.IsScalar)
            {
                return(A.C);
            }
            if (A.IsEmpty)
            {
                throw new ILArgumentException("det: A must be a matrix");
            }
            int m = A.Dimensions[0];

            if (m != A.Dimensions[1])
            {
                throw new ILArgumentException("det: matrix A must be square");
            }

            ILArray <fcomplex> L = A.C;

            int [] pivInd = new int[m];
            int    info   = 0;

            Lapack.cgetrf(m, m, L.m_data, m, pivInd, ref info);
            if (info < 0)
            {
                throw new ILArgumentException("det: illegal parameter error.");
            }
            // determine pivoting: number of exchanges
            fcomplex retA = new fcomplex(1.0f, 0.0f);

            for (int i = 0; i < m;)
            {
                retA *= L.m_data[i * m + i];
                if (pivInd[i] != ++i)
                {
                    retA *= -1.0f;
                }
            }
            L.Dispose();
            return(new  ILArray <fcomplex> (retA));
        }
Exemple #8
0
 /// <summary>
 /// Implement wrapper for ATLAS GeneralMatrixMultiply
 /// </summary>
 /// <param name="TransA">Transposition state for matrix A: one of the constants in enum CBlas_Transpose</param>
 /// <param name="TransB">Transposition state for matrix B: one of the constants in enum CBlas_Transpose</param>
 /// <param name="M">Number of rows in A</param>
 /// <param name="N">Number of columns in B</param>
 /// <param name="K">Number of columns in A and number of rows in B</param>
 /// <param name="alpha">multiplicationi factor for A</param>
 /// <param name="A">pointer to double array A</param>
 /// <param name="lda">distance between first elements of each column for column based orientation or 
 /// distance between first elements of each row for row based orientation for matrix B</param>
 /// <param name="B">pointer to double array B</param>
 /// <param name="ldb">distance between first elements of each column for column based orientation or 
 /// distance between first elements of each row for row based orientation for matrix A</param>
 /// <param name="beta">multiplication faktor for matrix B</param>
 /// <param name="C">pointer to predefined double array C of neccessary length</param>
 /// <param name="ldc">distance between first elements of each column for column based orientation or 
 /// distance between first elements of each row for row based orientation for matrix C</param>
 /// <remarks>All parameters except C are readonly. Only elements of matrix C will be altered. C must be a predefined 
 /// continous double array of size MxN</remarks>
 public void cgemm(char TransA, char TransB, int M, int N, int K, fcomplex alpha, IntPtr A, int lda, IntPtr B, int ldb, fcomplex beta, fcomplex[] C, int ldc) {
     mkl_cgemm(ref TransA, ref TransB, ref M, ref  N, ref  K, ref  alpha, A, ref lda, B, ref ldb, ref  beta, C, ref  ldc);
 }
Exemple #9
0
 public void cheevr(char jobz, char range, char uplo, int n, fcomplex[] A, int lda, float vl, float vu, int il, int iu, float abstol, ref int m, float[] w, fcomplex[] z, int ldz, int[] isuppz, ref int info) {
     fcomplex[] work = new fcomplex[1]; 
     float [] rwork = new float[1]; 
     int [] iwork = new int[1]; 
     int lrwork = -1, liwork = -1, lwork = -1; 
     mkl_cheevr(ref jobz,ref range,ref uplo,ref n, A,ref lda, ref vl, ref vu, ref il, ref iu, ref abstol,ref m, w,z,ref ldz,isuppz, work,ref lwork,rwork,ref lrwork, iwork,ref liwork,ref info);
     if (info != 0) {
         throw new ILArgumentException("?syevr: error returned from lapack: " + info);
     }
     lrwork = (int)rwork[0]; 
     rwork = ILMemoryPool.Pool.New<float>(lrwork);
     lwork = (int) work[0]; 
     work = ILMemoryPool.Pool.New<fcomplex>(lwork); 
     liwork = (int) iwork[0]; 
     iwork = ILMemoryPool.Pool.New<int>(liwork); 
     mkl_cheevr(ref jobz,ref range,ref uplo,ref n, A,ref lda, ref vl, ref vu, ref il, ref iu, ref abstol,ref m, w,z,ref ldz,isuppz, work,ref lwork,rwork,ref lrwork,iwork,ref liwork,ref info);
     ILMemoryPool.Pool.RegisterObject(iwork); 
     ILMemoryPool.Pool.RegisterObject(work); 
     ILMemoryPool.Pool.RegisterObject(rwork); 
 }
Exemple #10
0
 public void  cgelsy  (int m, int n, int nrhs,  fcomplex [] A, int lda,  fcomplex [] B, int ldb, int[] JPVT0,  float RCond, ref int rank, ref int info) {
     int lwork = -1;
     fcomplex [] work = new  fcomplex [1]; 
     float[] rwork = new float[1];
     mkl_cgelsy (ref m,ref n,ref nrhs,A,ref lda,B,ref ldb,JPVT0,ref RCond,ref rank,work,ref lwork, rwork, ref info);
     if (info != 0)
         throw new ILArgumentException("?gelsy: unable to determine optimal block size. cancelling...");
     lwork = (int) work[0];
     work = ILMemoryPool.Pool.New<fcomplex>(lwork);
     rwork = ILMemoryPool.Pool.New<float>(lwork);
     mkl_cgelsy (ref m,ref n,ref nrhs,A,ref lda,B,ref ldb,JPVT0,ref RCond,ref rank,work,ref lwork, rwork, ref info);
     ILMemoryPool.Pool.RegisterObject(work); 
     ILMemoryPool.Pool.RegisterObject(rwork); 
 }
Exemple #11
0
 public void cpotrs(char uplo, int n, int nrhs, fcomplex[] A, int lda, fcomplex[] B, int ldb, ref int info) {
     mkl_cpotrs(ref uplo, ref n, ref nrhs, A, ref lda, B, ref ldb, ref info); 
 }
Exemple #12
0
 public void  cgeqp3 ( int M,int N, fcomplex [] A,int LDA,int [] JPVT, fcomplex [] tau, ref int info ) {
     fcomplex [] work = new  fcomplex [1];
     int lwork = -1; 
     try {
         float[] rwork = new float[2 * N];
         mkl_cgeqp3 (ref M, ref N, A, ref LDA, JPVT, tau, work, ref lwork, rwork, ref info);
         lwork = (int)work[0]; 
         if (lwork > 0 && info == 0) {
             work = ILMemoryPool.Pool.New<  fcomplex >(lwork); 
             mkl_cgeqp3 (ref M, ref N, A, ref LDA, JPVT, tau, work, ref lwork, rwork, ref info);
             ILMemoryPool.Pool.RegisterObject(work); 
         } else {
             throw new ILException("error in mkl_?geqp3"); 
         }
     } catch (OutOfMemoryException e) {
         throw new ILException("error on ?geqp3. Not enough memory! " + (lwork * Marshal.SizeOf( work[0] )).ToString() + " bytes has been requested.",e); 
     }
 }
Exemple #13
0
        /// <summary>
        /// Create array initialized with all elements set to one.
        /// </summary>
        /// <param name="type">Numeric type specification. One value out of the types listed in the <see cred="ILNumerics.NumericType"/>
        /// enum.</param>
        /// <param name="dimensions">Dimension specification. At least one dimension must be specified.</param>
        /// <returns>ILArray&lt;BaseT&gt; of inner type corresponding to <paramref name="type"/> argument.</returns>
        /// <remarks>The array returned may be cast to the appropriate actual type afterwards.
        /// <para>
        /// <list type="number">
        /// <listheader>The following types are supported: </listheader>
        /// <item>Double</item>
        /// <item>Single</item>
        /// <item>Complex</item>
        /// <item>FComplex</item>
        /// <item>Byte</item>
        /// <item>Char</item>
        /// <item>Int16</item>
        /// <item>Int32</item>
        /// <item>Int64</item>
        /// <item>UInt16</item>
        /// <item>UInt32</item>
        /// <item>UInt64</item>
        /// </list>
        /// </para>
        /// </remarks>
        public static ILBaseArray ones(NumericType type, params int[] dimensions)
        {
            if (dimensions.Length < 1)
            {
                throw new ILArgumentException("ones: invalid dimension specified!");
            }
            switch (type)
            {
            case NumericType.Double:
                return(ones(dimensions));

            case NumericType.Single:
                ILDimension dim = new ILDimension(dimensions);
                unsafe {
                    float[] data = null;
                    data = new float[dim.NumberOfElements];
                    fixed(float *pD = data)
                    {
                        float *pStart = pD;
                        float *pEnd   = pD + data.Length;

                        while (pEnd > pStart)
                        {
                            *(--pEnd) = 1.0f;
                        }
                    }

                    return(new ILArray <float>(data, dimensions));
                }

            case NumericType.Complex:
                dim = new ILDimension(dimensions);
                unsafe {
                    complex[] data = null;
                    data = new complex[dim.NumberOfElements];
                    fixed(complex *pD = data)
                    {
                        complex *pStart = pD;
                        complex *pEnd   = pD + data.Length;

                        while (pEnd > pStart)
                        {
                            *(--pEnd) = new complex(1.0, 1.0);
                        }
                    }

                    return(new ILArray <complex>(data, dimensions));
                }

            case NumericType.FComplex:
                dim = new ILDimension(dimensions);
                unsafe {
                    fcomplex[] data = null;
                    data = new fcomplex[dim.NumberOfElements];
                    fixed(fcomplex *pD = data)
                    {
                        fcomplex *pStart = pD;
                        fcomplex *pEnd   = pD + data.Length;

                        while (pEnd > pStart)
                        {
                            *(--pEnd) = new fcomplex(1.0f, 1.0f);
                        }
                    }

                    return(new ILArray <fcomplex>(data, dimensions));
                }

            case NumericType.Byte:
                dim = new ILDimension(dimensions);
                unsafe {
                    byte[] data = null;
                    data = new byte[dim.NumberOfElements];
                    fixed(byte *pD = data)
                    {
                        byte *pStart = pD;
                        byte *pEnd   = pD + data.Length;

                        while (pEnd > pStart)
                        {
                            *(--pEnd) = 1;
                        }
                    }

                    return(new ILArray <byte>(data, dimensions));
                }

            case NumericType.Char:
                dim = new ILDimension(dimensions);
                unsafe {
                    char[] data = null;
                    data = new char[dim.NumberOfElements];
                    fixed(char *pD = data)
                    {
                        char *pStart = pD;
                        char *pEnd   = pD + data.Length;

                        while (pEnd > pStart)
                        {
                            *(--pEnd) = Char.MinValue;
                        }
                    }

                    return(new ILArray <char>(data, dimensions));
                }

            case NumericType.Int16:
                dim = new ILDimension(dimensions);
                unsafe {
                    Int16[] data = null;
                    data = new Int16[dim.NumberOfElements];
                    fixed(Int16 *pD = data)
                    {
                        Int16 *pStart = pD;
                        Int16 *pEnd   = pD + data.Length;

                        while (pEnd > pStart)
                        {
                            *(--pEnd) = 1;
                        }
                    }

                    return(new ILArray <Int16>(data, dimensions));
                }

            case NumericType.Int32:
                dim = new ILDimension(dimensions);
                unsafe {
                    Int32[] data = null;
                    data = new Int32[dim.NumberOfElements];
                    fixed(Int32 *pD = data)
                    {
                        Int32 *pStart = pD;
                        Int32 *pEnd   = pD + data.Length;

                        while (pEnd > pStart)
                        {
                            *(--pEnd) = 1;
                        }
                    }

                    return(new ILArray <Int32>(data, dimensions));
                }

            case NumericType.Int64:
                dim = new ILDimension(dimensions);
                unsafe {
                    Int64[] data = null;
                    data = new Int64[dim.NumberOfElements];
                    fixed(Int64 *pD = data)
                    {
                        Int64 *pStart = pD;
                        Int64 *pEnd   = pD + data.Length;

                        while (pEnd > pStart)
                        {
                            *(--pEnd) = 1;
                        }
                    }

                    return(new ILArray <Int64>(data, dimensions));
                }

            case NumericType.UInt16:
                dim = new ILDimension(dimensions);
                unsafe {
                    UInt16[] data = null;
                    data = new UInt16[dim.NumberOfElements];
                    fixed(UInt16 *pD = data)
                    {
                        UInt16 *pStart = pD;
                        UInt16 *pEnd   = pD + data.Length;

                        while (pEnd > pStart)
                        {
                            *(--pEnd) = 1;
                        }
                    }

                    return(new ILArray <UInt16>(data, dimensions));
                }

            case NumericType.UInt32:
                dim = new ILDimension(dimensions);
                unsafe {
                    UInt32[] data = null;
                    data = new UInt32[dim.NumberOfElements];
                    fixed(UInt32 *pD = data)
                    {
                        UInt32 *pStart = pD;
                        UInt32 *pEnd   = pD + data.Length;

                        while (pEnd > pStart)
                        {
                            *(--pEnd) = 1;
                        }
                    }

                    return(new ILArray <UInt32>(data, dimensions));
                }

            case NumericType.UInt64:
                dim = new ILDimension(dimensions);
                unsafe {
                    UInt64[] data = null;
                    data = new UInt64[dim.NumberOfElements];
                    fixed(UInt64 *pD = data)
                    {
                        UInt64 *pStart = pD;
                        UInt64 *pEnd   = pD + data.Length;

                        while (pEnd > pStart)
                        {
                            *(--pEnd) = 1;
                        }
                    }

                    return(new ILArray <UInt64>(data, dimensions));
                }
            }
            return(null);
        }
Exemple #14
0
 public void  cgetri (int N,  fcomplex [] A, int LDA, int[] IPIV, ref int info) {
     fcomplex [] work = new  fcomplex [1];  
     int lwork = -1; 
     try {
         mkl_cgetri (ref N, A, ref LDA, IPIV, work, ref lwork, ref info); 
         lwork = (int)work[0]; 
         if (lwork > 0 && info == 0) {
             work = new  fcomplex [lwork]; 
             mkl_cgetri (ref N, A, ref LDA, IPIV, work, ref lwork, ref info);
         } else {
             throw new ILException("error in mkl_dgetri"); 
         }
     } catch (OutOfMemoryException e) {
         throw new ILException("error on dgetri. Not enough memory! " + (lwork * Marshal.SizeOf( work[0] )).ToString() + " bytes has been requested.",e); 
     }
 }
Exemple #15
0
 internal  fcomplex min( fcomplex in1) {
     return  (fcomplex) ((in1 < m_parameter) ? in1 : m_parameter);
 }
Exemple #16
0
 private static extern void acml_cgemm(ref char TransA, ref char TransB, ref int M, ref int N, ref int K, ref fcomplex alpha, IntPtr A, ref int lda, IntPtr B, ref int ldb, ref fcomplex beta, [In, Out] fcomplex[] C, ref int ldc);
Exemple #17
0
 public void cgemm(char TransA, char TransB, int M, int N, int K, fcomplex alpha, IntPtr A, int lda, IntPtr B, int ldb, fcomplex beta, fcomplex [] C, int ldc)
 {
     acml_cgemm(ref TransA, ref TransB, ref M, ref N, ref K, ref alpha, A, ref lda, B, ref ldb, ref beta, C, ref ldc);
 }
        /// <summary>
        /// GEneral Matrix Multiply this array
        /// </summary>
        /// <overloads>General Matrix Multiply for double, float, complex and fcomplex arrays</overloads>
        /// <param name="A"><![CDATA[ILArray<>]]> matrix A</param>
        /// <param name="B"><![CDATA[ILArray<>]]> matrix B</param>
        /// <returns><![CDATA[ILArray<double>]]> new array - result of matrix multiplication</returns>
        /// <remarks>Both arrays must be matrices. The matrix will be multiplied only
        /// if dimensions match accordingly. Therefore B's number of rows must
        /// equal A's number of columns. An Exception will be thrown otherwise.
        /// The multiplication will carried out on BLAS libraries, if availiable and the
        /// storage memory structure meets BLAS's requirements. If not it will be done inside .NET's
        /// framework 'by hand'. This is especially true for referencing storages with
        /// irregular dimensions. However, even GEMM on those reference storages linking into
        /// a physical storage can (an will) be carried out via BLAS dll's, if the spacing
        /// into dimensions matches the requirements of BLAS. Those are:
        /// <list>
        /// <item>the elements of one dimension will be adjecently layed out, and</item>
        /// <item>the elements of the second dimension must be regular (evenly) spaced</item>
        /// </list>
        /// <para>For reference arrays where the spacing between adjecent elements do not meet the
        /// requirements above, the matrix multiplication will be made without optimization and
        /// therefore suffer from low performance in relation to solid arrays. See <a href="http://ilnumerics.net?site=5142">online documentation: referencing for ILNumerics.Net</a></para>
        /// </remarks>
        /// <exception cref="ILNumerics.Exceptions.ILArgumentSizeException">if at least one arrays is not a matrix</exception>
        /// <exception cref="ILNumerics.Exceptions.ILDimensionMismatchException">if the size of both matrices do not match</exception>
        public static ILArray <fcomplex> multiply(ILArray <fcomplex> A, ILArray <fcomplex> B)
        {
            ILArray <fcomplex> ret = null;

            if (A.Dimensions.NumberOfDimensions != 2 ||
                B.Dimensions.NumberOfDimensions != 2)
            {
                throw new ILArgumentSizeException("Matrix multiply: arguments must be 2-d.");
            }
            if (A.Dimensions[1] != B.Dimensions[0])
            {
                throw new ILDimensionMismatchException("Matrix multiply: inner matrix dimensions must match.");
            }
            // decide wich method to use
            // test auf Regelmigkeit der Dimensionen
            int  spacingA0;
            int  spacingA1;
            int  spacingB0;
            int  spacingB1;
            char transA, transB;

            fcomplex [] retArr = null;
            isSuitableForLapack(A, B, out spacingA0, out spacingA1, out spacingB0, out spacingB1, out transA, out transB);
            if (A.m_dimensions.NumberOfElements > ILAtlasMinimumElementSize ||
                B.m_dimensions.NumberOfElements > ILAtlasMinimumElementSize)
            {
                // do BLAS GEMM
                retArr = new  fcomplex [A.m_dimensions[0] * B.m_dimensions[1]];
                if (((spacingA0 == 1 && spacingA1 > int.MinValue) || (spacingA1 == 1 && spacingA0 > int.MinValue)) &&
                    ((spacingB0 == 1 && spacingB1 > int.MinValue) || (spacingB1 == 1 && spacingB0 > int.MinValue)))
                {
                    ret = new  ILArray <fcomplex> (retArr, new ILDimension(A.m_dimensions[0], B.m_dimensions[1]));
                    if (transA == 't')
                    {
                        spacingA1 = spacingA0;
                    }
                    if (transB == 't')
                    {
                        spacingB1 = spacingB0;
                    }
                    unsafe
                    {
                        fixed(fcomplex *ptrC = retArr)
                        fixed(fcomplex * pA = A.m_data)
                        fixed(fcomplex * pB = B.m_data)
                        {
                            fcomplex *ptrA = pA + A.getBaseIndex(0);
                            fcomplex *ptrB = pB + B.getBaseIndex(0);

                            if (transA == 't')
                            {
                                spacingA1 = spacingA0;
                            }
                            if (transB == 't')
                            {
                                spacingB1 = spacingB0;
                            }
                            Lapack.cgemm(transA, transB, A.m_dimensions[0], B.m_dimensions[1],
                                         A.m_dimensions[1], ( fcomplex )1.0, (IntPtr)ptrA, spacingA1,
                                         (IntPtr)ptrB, spacingB1, ( fcomplex )1.0, retArr, A.m_dimensions[0]);
                        }
                    }
                    return(ret);
                }
            }
            // do GEMM by hand
            retArr = new  fcomplex [A.m_dimensions[0] * B.m_dimensions[1]];
            ret    = new  ILArray <fcomplex> (retArr, A.m_dimensions[0], B.m_dimensions[1]);
            unsafe {
                int in2Len1 = B.m_dimensions[1];
                int in1Len0 = A.m_dimensions[0];
                int in1Len1 = A.m_dimensions[1];
                fixed(fcomplex *ptrC = retArr)
                {
                    fcomplex *pC = ptrC;

                    for (int c = 0; c < in2Len1; c++)
                    {
                        for (int r = 0; r < in1Len0; r++)
                        {
                            for (int n = 0; n < in1Len1; n++)
                            {
                                *pC += A.GetValue(r, n) * B.GetValue(n, c);
                            }
                            pC++;
                        }
                    }
                }
            }
            return(ret);
        }
Exemple #19
0
        /// <summary>
        /// singular value decomposition
        /// </summary>
        /// <param name="X">matrix X. The elements of X will not be altered.</param>
        /// <param name="U">(return value) left singular vectors of X as columns of matrix U.
        /// If this parameter is set, it must be not null. It might be an empty array. On return
        /// it will be set to a physical array accordingly.</param>
        /// <param name="V">right singular vectors of X as rows of matrix V.
        /// If this parameter is set, it must be not null. It might be an empty array. On return
        /// it will be set to a physical array accordingly.</param>
        /// <param name="small">if true: return only first min(M,N) columns of U and S will be
        /// of size [min(M,N),min(M,N)]</param>
        /// <param name="discardFiniteTest">if true: the matrix given will not be checked for infinte or NaN values. If such elements
        /// are contained nevertheless, this may result in failing convergence or error. In worst case
        /// the function may hang inside the Lapack lib. Use with care! </param>
        /// <returns>singluar values as diagonal matrix of same size as X</returns>
        /// <remarks>the right singular vectors V will be returned as reference array.</remarks>
        public static ILArray <float> svd(ILArray <fcomplex> X, ref ILArray <fcomplex> U, ref ILArray <fcomplex> V, bool small, bool discardFiniteTest)
        {
            if (!X.IsMatrix)
            {
                throw new ILArgumentSizeException("svd is defined for matrices only!");
            }
            // early exit for small matrices
            if (X.Dimensions[1] < 4 && X.Dimensions[0] == X.Dimensions[1])
            {
                switch (X.Dimensions[0])
                {
                case 1:
                    if (!Object.Equals(U, null))
                    {
                        U = ( fcomplex )1.0;
                    }
                    if (!Object.Equals(V, null))
                    {
                        V = ( fcomplex )1.0;
                    }
                    return(new  ILArray <float> (ILMath.abs(X)));
                    //case 2:
                    //    return -1;
                    //case 3:
                    //    return -1;
                }
            }
            if (!discardFiniteTest && !all(all(isfinite(X))))
            {
                throw new ILArgumentException("svd: input must have only finite elements!");
            }
            if (Lapack == null)
            {
                throw new ILMathException("No Lapack package available.");
            }
            // parameter evaluation
            int M = X.Dimensions[0]; int N = X.Dimensions[1];
            int minMN = (M < N) ? M : N;
            int LDU = M; int LDVT = N;
            int LDA = M;

            float [] dS   = new  float [minMN];
            char     jobz = (small) ? 'S' : 'A';

            fcomplex [] dU   = null;
            fcomplex [] dVT  = null;
            int         info = 0;

            if (!Object.Equals(U, null) || !Object.Equals(V, null))
            {
                // need to return U and VT
                if (small)
                {
                    dU  = new  fcomplex  [M * minMN];
                    dVT = new  fcomplex [N * minMN];
                }
                else
                {
                    dU  = new  fcomplex [M * M];
                    dVT = new  fcomplex [N * N];
                }
            }
            else
            {
                jobz = 'N';
            }

            if (X.IsReference)
            {
                X.Detach();
            }
            // must create copy of input !
            fcomplex [] dInput = new  fcomplex [X.m_data.Length];
            System.Array.Copy(X.m_data, dInput, X.m_data.Length);
            Lapack.cgesdd(jobz, M, N, dInput, LDA, dS, dU, LDU, dVT, LDVT, ref info);
            if (info < 0)
            {
                throw new ILArgumentException("ILMath.svd: the " + (-info).ToString() + "th argument was invalid.");
            }
            if (info > 0)
            {
                throw new ILArgumentException("svd was not converging!");
            }
            ILArray <float> ret = null;

            if (info == 0)
            {
                // success
                if (!Object.Equals(U, null) || !Object.Equals(V, null))
                {
                    if (small)
                    {
                        ret = ILArray <float> .zeros(minMN, minMN);
                    }
                    else
                    {
                        ret = ILArray <float> .zeros(M, N);
                    }
                    for (int i = 0; i < minMN; i++)
                    {
                        ret.SetValue(dS[i], i, i);
                    }
                    if (!Object.Equals(U, null))
                    {
                        U = new  ILArray <fcomplex> (dU, M, dU.Length / M);
                    }
                    if (!Object.Equals(V, null))
                    {
                        V = conj(new  ILArray <fcomplex> (dVT, N, dVT.Length / N).T);
                    }
                }
                else
                {
                    ret = new  ILArray <float> (dS, minMN, 1);
                }
            }
            return(ret);
        }
Exemple #20
0
// DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !! 

        public void  cgesdd (char jobz, int m, int n,  fcomplex [] a, int lda,  float [] s,  fcomplex [] u, int ldu, fcomplex [] vt, int ldvt, ref int info)
        {
            try {
                fcomplex [] work = new  fcomplex [1] { (  fcomplex )0.0 };
                float [] rwork; 
                int minMN = (m < n) ? m : n;
                if (jobz == 'N') {
                    rwork = new  float [minMN * 7];  
                } else {
                    rwork = new  float [5 * minMN * minMN + 5 * minMN];  
                }
                int lwork = -1;
                int[] iwork = new int[minMN * 8];
                mkl_cgesdd (ref jobz, ref m, ref n, a, ref lda, s, u, ref ldu, vt, ref ldvt, work, ref lwork, rwork, iwork, ref info);
                if (work[0] != 0) {
                    work = new  fcomplex [(int)work[0].real];
                    lwork = work.Length;
                    mkl_cgesdd (ref jobz, ref m, ref n, a, ref lda, s, u, ref ldu, vt, ref ldvt, work, ref lwork,rwork, iwork, ref info);
                }
            } catch (Exception e) {
                if (e is OutOfMemoryException) {
                    cgesvd (jobz, m, n, a, lda, s, u, ldu, vt, ldvt, ref info); 
                }
                throw new ILException("Unable to do " +  "zgesdd"  + ".", e); 
            }
        }
Exemple #21
0
 public void cpotri(char uplo, int n, fcomplex[] A, int lda, ref int info) {
     mkl_cpotri(ref uplo, ref n, A, ref lda, ref info);
 }
Exemple #22
0
 private static  ILArray<fcomplex> min( ILArray<fcomplex> A, fcomplex parameter) {
     opfcomplex_fcomplex helper = new  opfcomplex_fcomplex (parameter, null);
     return  FcomplexOperatorFcomplex (A, helper.min);
 }
Exemple #23
0
 private void Test_AccuracyUnderflow() {
     float c = 10e37f, d = 10e-37f, e = 10e29f, f = 10e-29f; 
     fcomplex A = new fcomplex(c,d);
     fcomplex B = new fcomplex(e,f); 
     fcomplex C = A / B; 
     double cd = 10e70, dd = 10e-70, ed = 10e56, fd = 10e-56; 
     complex Ad = new complex(cd,dd);
     complex Bd = new complex(ed,fd); 
     complex Cd = Ad / Bd; 
     // Smith(1) formula
     fcomplex t1 = f * 1/e; 
     fcomplex t2 = f * t1; 
     fcomplex t3 = e + t2; // 10^56 ?
     fcomplex t4 = c * t1; 
     fcomplex t5 = d - t4; // 10^-56 ? 
     fcomplex b = t5 / t3; 
     Success(); 
 }
Exemple #24
0
 internal  fcomplex add( fcomplex in1,  fcomplex in2) {
     // TODO: a + b = a if abs(b) < eps
     return  (fcomplex) (in1 + in2); 
 }
Exemple #25
0
 public void cpotrf(char uplo, int n, fcomplex[] A, int lda, ref int info) {
     lapack_cpotrf(ref uplo, ref n, A, ref lda, ref info);
 }
Exemple #26
0
 internal  fcomplex subtract( fcomplex in1,  fcomplex in2) {
     // TODO: a - b = a if abs(b) < eps
     return  (fcomplex) (in1 - in2); 
 }
Exemple #27
0
 public void cgetrs(char trans, int N, int NRHS, fcomplex[] A, int LDA, int[] IPIV, fcomplex[] B, int LDB, ref int info) {
     mkl_cgetrs(ref trans,ref N,ref NRHS, A, ref LDA, IPIV, B, ref LDB, ref info);     
 }
Exemple #28
0
 internal  fcomplex multiply( fcomplex in1,  fcomplex in2) {
     return  (fcomplex) (in1 * in2); 
 }
Exemple #29
0
 public void  cgelsd  (int m, int n, int nrhs,  fcomplex [] A, int lda,  fcomplex [] B, int ldb,  float [] S,  float RCond, ref int rank, ref int info) {
     fcomplex [] work = new  fcomplex [1]; 
     int [] iwork = new int[1]; 
     int lwork = -1; 
     float [] rwork = new float [1];  mkl_cgelsd (ref m, ref n, ref nrhs, A, ref lda, B, ref ldb, S,ref RCond, ref rank, work, ref lwork, rwork, iwork, ref info);
     if (info != 0) 
         throw new ILArgumentException("dgelsd: invalid parameter: #" + (-info).ToString());
     lwork = (int)work[0]; //ILAENV(9, "dgelsd", " ",0,0,0,0); 
     if (lwork <= 0)
         throw new ILArgumentException("dgelsd: unknown error determining working size lwork");
     iwork = new int[lwork * 1000];
     
     work = ILMemoryPool.Pool.New<  fcomplex >(lwork); 
     rwork = new float [(int)rwork[0]];  mkl_cgelsd (ref m, ref n, ref nrhs, A, ref lda, B, ref ldb, S,ref RCond, ref rank, work, ref lwork, rwork, iwork, ref info);
     ILMemoryPool.Pool.RegisterObject(work);
 }
Exemple #30
0
 internal  fcomplex divide( fcomplex in1,  fcomplex in2) {
     if (in2 != 0.0)
         return  (fcomplex) (in1 / in2);
     return  fcomplex.INF ; 
 }
Exemple #31
0
 public void cgeevx(char balance, char jobvl, char jobvr, char sense, int n, fcomplex[] A, int lda, fcomplex[] w, fcomplex[] vl, int ldvl, fcomplex[] vr, int ldvr, ref int ilo, ref int ihi, float[] scale, ref float abnrm, float[] rconde, float[] rcondv, ref int info) {
     fcomplex [] work = new fcomplex[1]; 
     int lwork = -1;
     float[] rwork = ILMemoryPool.Pool.New<float>(2 * n); 
     mkl_cgeevx(ref balance, ref jobvl, ref jobvr, ref sense, ref n, A, ref lda, w, vl, ref ldvl, vr, ref ldvr, ref ilo, ref ihi, scale, ref abnrm, rconde, rcondv, work, ref lwork, rwork, ref info);
     if (info != 0) 
         throw new ILArgumentException("error in lapack call: ?geevx. (" + info + ")");
     lwork = (int)work[0]; 
     work = ILMemoryPool.Pool.New<fcomplex>(lwork); 
     mkl_cgeevx(ref balance, ref jobvl, ref jobvr, ref sense, ref n, A, ref lda, w, vl, ref ldvl, vr, ref ldvr, ref ilo, ref ihi, scale, ref abnrm, rconde, rcondv, work, ref lwork, rwork, ref info);
     ILMemoryPool.Pool.RegisterObject(work);
     ILMemoryPool.Pool.RegisterObject(rwork);
 }
Exemple #32
0
 internal  fcomplex min( fcomplex in1,  fcomplex in2) {
     return  (fcomplex) ( ( in1 < in2 ) ? in1 : in2 );
 }
Exemple #33
0
 public void chegv (int itype, char jobz, char uplo, int n, fcomplex[] A, int lda, fcomplex[] B, int ldb, float  [] w, ref int info) {
     // query workspace 
     int lwork = -1; 
     fcomplex [] work = new fcomplex[1] {0.0f}; 
     float [] rwork = ILMemoryPool.Pool.New<float>(Math.Max(1,3*n-2)); 
     mkl_chegv(ref itype,ref  jobz,ref  uplo,ref  n, A,ref  lda, B,ref  ldb, w, work, ref lwork, rwork, ref info); 
     if (info != 0 || work[0] <= 0.0) return; 
     // create temporary array(s)
     lwork = (int) work[0]; 
     work = ILMemoryPool.Pool.New<fcomplex>(lwork); 
     mkl_chegv (ref itype,ref  jobz,ref  uplo,ref  n, A,ref  lda, B,ref  ldb, w, work, ref lwork, rwork, ref info); 
     ILMemoryPool.Pool.RegisterObject(rwork); 
     ILMemoryPool.Pool.RegisterObject(work); 
 }
Exemple #34
0
 internal  fcomplex max( fcomplex in1,  fcomplex in2) {
     return  (fcomplex) ( ( in1 > in2 ) ? in1 : in2 );
 }
Exemple #35
0
		private static extern void mkl_cgemm(ref char TransA, ref char TransB, ref int M,ref int N, ref int K, ref fcomplex alpha, IntPtr A, ref int lda, IntPtr B, ref int ldb, ref fcomplex beta,[In,Out] fcomplex [] C, ref int ldc);
Exemple #36
0
 public void  cungqr (int M, int N, int K,  fcomplex [] A, int lda,  fcomplex [] tau, ref int info) {
     fcomplex [] work = new  fcomplex [1];  
     int lwork = -1; 
     try {
         lapack_cungqr (ref M, ref N, ref K, A, ref lda, tau, work, ref lwork, ref info); 
         lwork = (int)work[0]; 
         if (lwork > 0 && info == 0) {
             work = new  fcomplex [lwork]; 
             lapack_cungqr (ref M, ref N, ref K, A, ref lda, tau, work, ref lwork, ref info);
         } else {
             throw new ILException("error in lapack_?[un/or]gqr"); 
         }
     } catch (OutOfMemoryException e) {
         throw new ILException("error on ?[un/or]gqr. Not enough memory! " + (lwork * Marshal.SizeOf( work[0] )).ToString() + " bytes has been requested.",e); 
     }
 }
Exemple #37
0
 /// <summary>
 /// singular value decomposition
 /// </summary>
 /// <param name="jobz"></param>
 /// <param name="m"></param>
 /// <param name="n"></param>
 /// <param name="a"></param>
 /// <param name="lda"></param>
 /// <param name="s"></param>
 /// <param name="u"></param>
 /// <param name="ldu"></param>
 /// <param name="vt"></param>
 /// <param name="ldvt"></param>
 /// <param name="info"></param>
 public void  cgesvd (char jobz, int m, int n,  fcomplex [] a, int lda,
                    float [] s,  fcomplex [] u, int ldu,  fcomplex [] vt, int ldvt, ref int info) {
     if (jobz != 'A' && jobz != 'S' && jobz != 'N')
         throw new ILArgumentException("Argument jobz must be one of 'A','S' or 'N'"); 
     try {
         fcomplex [] work = new  fcomplex [1] { ( fcomplex )0.0 };
         int lwork = -1;
         int[] iwork = new int[((m < n) ? m : n) * 8];
         mkl_cgesvd (ref jobz, ref jobz, ref m, ref n, a, ref lda, s, u, ref ldu, vt, ref ldvt, work, ref lwork, iwork, ref info);
         if (work[0] != 0) {
             work = new  fcomplex [(int)work[0]];
             lwork = work.Length; 
             mkl_cgesvd (ref jobz, ref jobz, ref m, ref n, a, ref lda, s, u, ref ldu, vt, ref ldvt, work, ref lwork, iwork, ref info);
         }
     } catch (Exception e) {
         if (e is OutOfMemoryException) {
             throw new ILMemoryException("Not enough memory for given arguments."); 
         }
         throw new ILException("Unable to do gesvd.", e);
     }
 }
        /// <summary>
        /// power function - returns same type
        /// </summary>
        /// <param name="A">input array</param>
        /// <param name="exponent">real exponent</param>
        /// <returns>array of same type as A, with corresponding elements filled with: A<sub>i,j,...</sub><sup>exponent</sup>.</returns>
        public static ILArray <fcomplex> pow(ILArray <fcomplex> A, fcomplex exponent)
        {
            opfcomplex_fcomplex helper = new  opfcomplex_fcomplex(exponent, fcomplex.Pow);

            return(FcomplexOperatorFcomplex(A, helper.operate));
        }
Exemple #39
0
 public void cgetrf(int M, int N, fcomplex[] A, int LDA, int[] IPIV, ref int info) {
     mkl_cgetrf(ref M, ref N, A, ref LDA, IPIV, ref info);
 }
Exemple #40
0
 public void cgeevx(char balance, char jobvl, char jobvr, char sense, int n, fcomplex[] A, int lda, fcomplex[] w, fcomplex[] vl, int ldvl, fcomplex[] vr, int ldvr, ref int ilo, ref int ihi, float[] scale, ref float abnrm, float[] rconde, float[] rcondv, ref int info) {
     fcomplex [] work = new fcomplex[1]; 
     int lwork = -1;
     float[] rwork = new float[2 * n]; 
     lapack_cgeevx(ref balance, ref jobvl, ref jobvr, ref sense, ref n, A, ref lda, w, vl, ref ldvl, vr, ref ldvr, ref ilo, ref ihi, scale, ref abnrm, rconde, rcondv, work, ref lwork, rwork, ref info);
     if (info != 0) 
         throw new ILArgumentException("error in lapack call: ?geevx. (" + info + ")");
     lwork = (int)work[0]; 
     work = new fcomplex[lwork]; 
     lapack_cgeevx(ref balance, ref jobvl, ref jobvr, ref sense, ref n, A, ref lda, w, vl, ref ldvl, vr, ref ldvr, ref ilo, ref ihi, scale, ref abnrm, rconde, rcondv, work, ref lwork, rwork, ref info);
 }
Exemple #41
0
 public void  cgeqrf (int M, int N,  fcomplex [] A, int lda,  fcomplex [] tau, ref int info) {
     fcomplex [] work = new  fcomplex [1];  
     int lwork = -1; 
     try {
         mkl_cgeqrf (ref M, ref N, A, ref lda, tau, work, ref lwork, ref info); 
         lwork = (int)work[0]; 
         if (lwork > 0 && info == 0) {
             work = new  fcomplex [lwork]; 
             mkl_cgeqrf (ref M, ref N, A, ref lda, tau, work, ref lwork, ref info);
         } else {
             throw new ILException("error in mkl_?geqrf"); 
         }
     } catch (OutOfMemoryException e) {
         throw new ILException("error on ?geqrf. Not enough memory! " + (lwork * Marshal.SizeOf( work[0] )).ToString() + " bytes has been requested.",e); 
     }
 }
Exemple #42
0
 public void cheevr(char jobz, char range, char uplo, int n, fcomplex[] A, int lda, float vl, float vu, int il, int iu, float abstol, ref int m, float[] w, fcomplex[] z, int ldz, int[] isuppz, ref int info) {
     fcomplex[] work = new fcomplex[1]; 
     float [] rwork = new float[1]; 
     int [] iwork = new int[1]; 
     int lrwork = -1, liwork = -1, lwork = -1; 
     lapack_cheevr(ref jobz,ref range,ref uplo,ref n, A,ref lda, ref vl, ref vu, ref il, ref iu, ref abstol,ref m, w,z,ref ldz,isuppz, work,ref lwork,rwork,ref lrwork, iwork,ref liwork,ref info);
     if (info != 0) {
         throw new ILArgumentException("?syevr: error returned from lapack: " + info);
     }
     lrwork = (int)rwork[0]; 
     rwork = new float[lrwork];
     lwork = (int) work[0]; 
     work = new fcomplex[lwork]; 
     liwork = (int) iwork[0]; 
     iwork = new int[liwork]; 
     lapack_cheevr(ref jobz,ref range,ref uplo,ref n, A,ref lda, ref vl, ref vu, ref il, ref iu, ref abstol,ref m, w,z,ref ldz,isuppz, work,ref lwork,rwork,ref lrwork,iwork,ref liwork,ref info);
 }
Exemple #43
0
 public void  cgelsy  (int m, int n, int nrhs,  fcomplex [] A, int lda,  fcomplex [] B, int ldb, int[] JPVT0,  float RCond, ref int rank, ref int info) {
     int lwork = -1;
     fcomplex [] work = new  fcomplex [1]; 
     float[] rwork = new float[1];
     lapack_cgelsy (ref m,ref n,ref nrhs,A,ref lda,B,ref ldb,JPVT0,ref RCond,ref rank,work,ref lwork, rwork, ref info);
     if (info != 0)
         throw new ILArgumentException("?gelsy: unable to determine optimal block size. cancelling...");
     lwork = (int) work[0];
     work = new  fcomplex [lwork];
     rwork = new float[lwork];
     lapack_cgelsy (ref m,ref n,ref nrhs,A,ref lda,B,ref ldb,JPVT0,ref RCond,ref rank,work,ref lwork, rwork, ref info);
 }
Exemple #44
0
        /// <summary>
        /// pseudo inverse of input matrix M
        /// </summary>
        /// <param name="M">matrix M</param>
        /// <param name="tolerance">tolerance, see remarks</param>
        /// <returns>pseudo inverse of M</returns>
        /// <remarks>The function returns the pseudo inverse (Moore-Penrose pseudoinverse)
        /// of input matrix M. The return value will be of the same size as
        /// the transposed of M. it will satisfy the following conditions:
        /// <list type="bullet">
        /// <item>M * pinv(M) * M  = M </item>
        /// <item>pinv(M) * M * pinv(M) = pinv(M)</item>
        /// <item>pinv(M) * M is hermitian</item>
        /// <item>M * pinv(M) is hermitian</item>
        /// </list>
        /// pinv uses LAPACK's function svd internally. Any singular values less than
        /// tolerance will be set to zero. If tolerance is less than zero, the following equation
        /// is used as default: \\
        /// tol = length(M) * norm(M) * Double.epsilon \\
        /// with
        /// <list type="bullet">
        /// <item>length(M) - the longest dimension of M</item>
        /// <item>norm(M) beeing the largest singular value of M, </item>
        /// <item>Double.epsilon - the smallest constructable double precision number greater than zero</item>
        /// </list>
        /// </remarks>
        public static ILArray <fcomplex> pinv(ILArray <fcomplex> M, fcomplex tolerance)
        {
            // let svd check the dimensions!
            //if (M.Dimensions.NumberOfDimensions > 2)
            //   throw new ILDimensionMismatchException("pinv: ...");

            // in order to use the cheap packed version of svd, the matrix must be m x n with m > n!
            if (M.m_dimensions[0] < M.m_dimensions[1])
            {
                ILArray <fcomplex> ret = pinv(conj(M.T), tolerance); return(conj(ret.T));
            }
            if (M.IsScalar)
            {
                return(new  ILArray <fcomplex> (1.0f / M.GetValue(0)));
            }

            ILArray <fcomplex> U = ILArray <fcomplex> .empty(0, 0);

            ILArray <fcomplex> V = ILArray <fcomplex> .empty(0, 0);

            ILArray <float> S = svd(M, ref U, ref V, true, false);

            int m = M.m_dimensions[0];
            int n = M.m_dimensions[1];

            ILArray <float> s;

            switch (m)
            {
            case 0:
                s = ILArray <float> .zeros(1, 1);

                break;

            case 1:
                s = S[0];
                break;

            default:
                s = diag(S);
                break;
            }
            if (tolerance < 0)
            {
                tolerance = ( fcomplex )(M.Dimensions.Longest * max(s).GetValue(0) * ILMath.MachineParameterFloat.eps);
            }
            // sum vector elements: ret must (and should) be dense vector returned from svd
            int count = (int)sum(s > (double)tolerance);

            ILArray <fcomplex> Ret = null;

            if (count == 0)
            {
                S = ILArray <float> .zeros(n, m);
            }
            else
            {
                ILArray <float> OneVec = ILArray <float> .zeros(count, 1);

                OneVec = set(OneVec, 1.0f);
                S      = diag(divide(OneVec, s["0:" + (count - 1)]));
                U      = conj(U[(short)1, ":;0:" + (count - 1)]);
                Ret    = multiply(multiply(V[":;0:" + (count - 1)], real2fcomplex(S)), U);
            }
            return(Ret);
        }