예제 #1
0
 /// <summary>
 /// Logarithm of base 2
 /// </summary>
 /// <param name="input">input</param>
 /// <returns>logarithm of base 2.</returns>
 /// <seealso cref="ILNumerics.complex.Log(complex)"/>
 public static complex Log2(complex input) {
     return Log(input) * 1.4426950408889634;
 }
예제 #2
0
 public void zhegv (int itype, char jobz, char uplo, int n, complex [] A, int lda, complex [] B, int ldb, double [] w, ref int info) { 
     acml_zhegv (itype, jobz, uplo, n, A, lda, B, ldb, w, ref info); 
 }
예제 #3
0
파일: pow.cs 프로젝트: wdxa/ILNumerics
// DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !! 


        /// <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<complex> pow( ILArray<complex> A,  complex exponent)
        {
            opcomplex_complex helper = new  opcomplex_complex (exponent,  complex .Pow );
            return  ComplexOperatorComplex (A, helper.operate);
        }
예제 #4
0
 public void zgelsd(int m, int n, int nrhs, complex[] A, int lda, complex[] B, int ldb, double[] S, double RCond, ref int rank, ref int info) {
     zgelsd (m, n, nrhs, A, lda, B, ldb, S, RCond, ref rank, ref info); 
 }
예제 #5
0
 public void zgeevx(char balance, char jobvl, char jobvr, char sense, int n, complex[] A, int lda, complex[] w, complex[] vl, int ldvl, complex[] vr, int ldvr, ref int ilo, ref int ihi, double[] scale, ref double abnrm, double[] rconde, double[] rcondv, ref int info) {
     acml_zgeevx(balance,jobvl,jobvr,sense,n,A,lda,w,vl,ldvl,vr,ldvr,ref ilo,ref ihi,scale,ref abnrm,rconde,rcondv,ref info); 
 }
예제 #6
0
 public void zungqr(int M, int N, int K, complex[] A, int lda, complex[] tau, ref int info) {
     acml_zungqr(M,N,K,A,lda,tau,ref info); 
 }
예제 #7
0
 public void zgetrs(char trans, int N, int NRHS, complex[] A, int LDA, int[] IPIV, complex[] B, int LDB, ref int info) {
     acml_zgetrs(trans,N,NRHS,A,LDA,IPIV,B,LDB,ref info); 
 }
예제 #8
0
 /// <summary>
 /// test if any of real or imaginary parts are neg. infinite
 /// </summary>
 /// <param name="input">complex number to test</param>
 /// <returns>true if any of real or imag part is negative infinite</returns>
 public static bool IsNegativeInfinity(complex input) {  
     if (double.IsNegativeInfinity(input.real) || double.IsNegativeInfinity(input.imag)) 
         return true; 
     else 
         return false; 
 }
예제 #9
0
 /// <summary>
 /// test if any of real or imaginary parts are finite
 /// </summary>
 /// <param name="input">complex number to test</param>
 /// <returns>true if any of real and imag part is finite</returns>
 public static bool IsFinite (complex input) {
     if (ILMath.isfinite(input.real) && ILMath.isfinite(input.imag)) 
         return true; 
     else 
         return false; 
 }
예제 #10
0
 /// <summary>
 /// logarithm of base e
 /// </summary>
 /// <returns>logarithm of base e</returns>
 /// <remarks>The logarithm of a complex number A is defined as follows: <br />
 /// <list type="none"><item>real part: log(abs(A))</item>
 /// <item>imag part: Atan2(imag(A),real(A))</item></list>
 /// </remarks>
 public complex Log() {
     complex ret = new complex();
     ret.real = Math.Log(Math.Sqrt(real * real + imag * imag));
     ret.imag = Math.Atan2(imag, real);
     return ret;
 }
예제 #11
0
 /// <summary>
 /// test if any of real or imaginary parts are NAN's
 /// </summary>
 /// <param name="input">complex number to test</param>
 /// <returns>true if any of real or imag part is not a number</returns>
 public static bool IsNaN(complex input) {
     if (double.IsNaN(input.real) || double.IsNaN(input.imag)) 
         return true; 
     else 
         return false; 
 }
예제 #12
0
 /// <summary>
 /// Square root of this complex value
 /// </summary>
 /// <returns>square root of this complex value</returns>
 public complex Sqrt() {
     // Reference : numerical recipes in C: Appendix C
     complex ret = new complex();
     double x, y, w, r;
     if (real == 0.0 && imag == 0.0)
         return ret;
     else {
         x = (double)Math.Abs(real);
         y = (double)Math.Abs(imag);
         if (x >= y) {
             r = y / x;
             w = Math.Sqrt(x) * Math.Sqrt(0.5 * (1.0 + Math.Sqrt(1.0 + r * r)));
         } else {
             r = x / y;
             w = Math.Sqrt(y) * Math.Sqrt(0.5 * (r + Math.Sqrt(1.0 + r * r)));
         }
         if (real >= 0.0) {
             ret.real = w;
             ret.imag = imag / (2.0 * w);
         } else {
             ret.imag = (imag >= 0) ? w : -w;
             ret.real = imag / ( 2.0 * ret.imag );
         }
         return ret;
     }
 }
예제 #13
0
		/// <summary>
		/// complex power - complex exponent
		/// </summary>
		/// <param name="exponent">exponent</param>
		/// <returns>complex number exp(log(this) * exponent).</returns>
		/// <remarks>If this instance is a than 
		/// the result will be the complex number exp(log(a) * exponent). </remarks>
        public complex Pow(complex exponent) {
            complex ret = (Log() * exponent);
            return ret.Exp();
        }
예제 #14
0
 /// <summary>
 /// Arcus cosinus of this complex instance
 /// </summary>
 /// <returns>Arcus cosinus</returns>
 public complex Acos() {
     complex ret = new complex(0, -1);
     return complex.Log(complex.Sqrt(this * this - 1)
         + this) * ret;
 }
예제 #15
0
 public void zgetri(int N, complex[] A, int LDA, int[] IPIV, ref int info) {
     acml_zgetri(N, A, LDA, IPIV, ref info);
 }
예제 #16
0
        public override ILCell GenerateTestArrays() {
            ILCell ret = new ILCell(); 
            int count = 0;
            complex[] elements = new complex[] {
                    new complex(0.0,0.0),
                    new complex(1.0,0.0), 
                    new complex(1.0,1.0), 
                    new complex(0.0,1.0), 
                    new complex(-1.0,0.0), 
                    new complex(-1.0,-1.0), 
                    new complex(0.0,-1.0), 
                    new complex(double.NaN,0.0), 
                    new complex(double.NaN,1.0), 
                    new complex(0.0,double.NaN), 
                    new complex(1.0,double.NaN), 
                    new complex(double.NaN,double.NaN),     // 11
                    new complex(double.PositiveInfinity,0.0), 
                    new complex(double.PositiveInfinity,1.0), 
                    new complex(0.0,double.PositiveInfinity), 
                    new complex(1.0,double.PositiveInfinity), 
                    new complex(double.PositiveInfinity,double.PositiveInfinity), 
                    new complex(double.NegativeInfinity,0.0), 
                    new complex(double.NegativeInfinity,1.0), 
                    new complex(0.0,double.NegativeInfinity), 
                    new complex(1.0,double.NegativeInfinity), 
                    new complex(double.NegativeInfinity,double.NegativeInfinity), 
                    // mixed
                    new complex(double.NaN,double.NegativeInfinity), 
                    new complex(double.NaN,double.PositiveInfinity), 
                    new complex(double.PositiveInfinity,double.NegativeInfinity), 
                    new complex(double.NegativeInfinity,double.PositiveInfinity), 
                    new complex(double.NaN,double.PositiveInfinity), 
                    new complex(double.NegativeInfinity,double.NaN), 
                    new complex(double.PositiveInfinity,double.NaN), 
                    new complex(double.MaxValue,double.NaN), 
                    new complex(double.MinValue,double.NaN), 
                    new complex(double.MaxValue,double.MinValue), 
                    new complex(double.NaN,double.MaxValue), 
                    new complex(double.NaN,double.MinValue), 
                    new complex(double.MaxValue,double.MinValue)
            };

                // empty 
            ILArray<complex> tmp;
            ret[count++] = ILArray<complex>.empty(0,0);
            ret[count++] = ILArray<complex>.empty(1, 0);
            ret[count++] = ILArray<complex>.empty(0, 1, 0); 
            // scalar 
            foreach (complex elem in elements) 
                ret[count++] = (ILArray<complex>)elem; 
            // vector
            ret[count++] = ILArray<complex>.zeros(1,10); 
            ret[count++] = ILArray<complex>.zeros(1,10) + elements[2]; 
            ret[count++] = ILArray<complex>.zeros(10,1); 
            ret[count++] = ILArray<complex>.zeros(10,1) + elements[2];  
            ret[count++] = ILMath.ccomplex(ILMath.vector(0.0,10.0),ILMath.vector(0.0,10.0));
            ret[count++] = ILMath.ccomplex(ILMath.vector(-5.0,4.0),-ILMath.vector(-5.0,4.0));

            tmp = ILMath.ccomplex(ILMath.vector(-5.0,4.0),-ILMath.vector(-5.0,4.0));
            tmp[0] = elements[22]; 
            tmp["end"] = elements[25]; 
            tmp[3] = elements[26]; 
            ret[count++] = tmp; 
            // matrix
            ret[count++] = ILArray<complex>.zeros(3,2);
            ret[count++] = ILMath.ccomplex(ILMath.rand(3,4),ILMath.rand(3,4));
            ret[count++] = ILMath.ccomplex(ILMath.ones(2,3) * double.NaN,ILMath.ones(2,3) * double.NaN); 
            ret[count++] = ILMath.ccomplex(ILMath.ones(3,2) / 0.0,ILMath.ones(3,2) / 0.0); // inf 
            tmp = ILArray<complex>.zeros(3,2) + elements[2]; 
            tmp[0] = elements[11];     // nans
            ret[count++] = tmp; 
            tmp[1] = elements[15]; 
            ret[count++] = tmp; 
            tmp[3] = elements[20];    // neg inf
            ret[count++] = tmp; 
            // 3d array 
            ret[count++] = ILMath.ccomplex(ILMath.zeros(4, 3, 2),ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.ccomplex(ILMath.ones(4, 3, 2),ILMath.ones(4, 3, 2));
            ret[count++] = ILMath.ccomplex(0.0 / ILMath.zeros(4, 3, 2),0.0 / ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.ccomplex(ILMath.ones(4, 3, 2) * float.NaN,ILMath.ones(4, 3, 2) * float.NaN);
            ret[count++] = ILMath.ccomplex(ILMath.ones(4, 3, 2) * float.NegativeInfinity,ILMath.ones(4, 3, 2) * float.NegativeInfinity);
            ret[count++] = ILMath.ccomplex(ILMath.rand(4, 3, 2),ILMath.rand(4, 3, 2)); 
            // 4d array 
            ret[count++] = ILMath.ccomplex(ILMath.rand(15, 12, 3, 10),ILMath.rand(15, 12, 3, 10));

            return ret; 
        }
예제 #17
0
 public void zgeqrf(int M, int N, complex[] A, int lda, complex [] tau, ref int info) {
     acml_zgeqrf(M, N, A, lda, tau, ref info);
 }
예제 #18
0
        static void Main(string[] args)
        {
            double[] A = new double[] { 1.1, 0.2, -1.3, 4, 5 };
            A[4] = 20;
            int r = 10;
            double B = A[4];
            int[] C = new int[] { 1, 2, -1, 4, 5 };

            int[,] D = new int[,]
            {
                {1, 0, -1, 4, 5},
                {0, 1, 0, -1, 2}
            };
            //D[4, 0] = 20;

            int[,,] D3 = new int[,,]
            {
                {{1,10}, {0,4}, {-1, 2}, {4, 20}, {5, 100}},
                {{0, 2}, {1, 2}, {0, 1}, {-1, 0}, {2, 3}}
            };

            int[][] D2 = {
                new[] {11, 10, -11, 14, 15},
                new[] {20, 21, 20, -21, 22},
            };

            List<int> DList = new List<int>(){0, 1, 2, 3, 5, 6, 2, 4, 8, 10};


            // we store the data of 9 measurements:
            Measurement[] myData = new Measurement[]{
                new Measurement{X = 0, Y = 0, Z = 1.1, Data1 = 1.002, Data2 = 0.00205},
                new Measurement{X = 1, Y = 0, Z = 1.1, Data1 = 1.232, Data2 = 0.00224},
                new Measurement{X = 2, Y = 0, Z = 1.1, Data1 = 1.042, Data2 = 0.00155},
                new Measurement{X = 0, Y = 1, Z = 1.1, Data1 = 1.042, Data2 = 0.001852},
                new Measurement{X = 1, Y = 1, Z = 1.1, Data1 = 1.041, Data2 = 0.002258},
                new Measurement{X = 2, Y = 1, Z = 1.1, Data1 = 1.039, Data2 = 0.00215},
                new Measurement{X = 0, Y = 2, Z = 1.1, Data1 = 0.952, Data2 = 0.00204},
                new Measurement{X = 1, Y = 2, Z = 1.1, Data1 = 0.902, Data2 = 0.00233},
                new Measurement{X = 2, Y = 2, Z = 1.1, Data1 = 0.902, Data2 = 0.00233}
            };

            double my1stPoint = myData[4].Data1;


            complex[] complex_sysA = new complex[] {
        new complex(-0.47943,0.87758),
        new complex(-0.41831,0.90831),
        new complex(-0.35523,0.93478),
        new complex(-0.29049,0.95688),
        new complex(-0.22439,0.97450),
        new complex(-0.15724,0.98756),
        new complex(-0.08935,0.99600),
        new complex(-0.02105,0.99978),
        new complex( 0.04735,0.99888),
        new complex( 0.11553,0.99330),
        new complex( 0.18317,0.98308),
        new complex( 0.24995,0.96826),
        new complex( 0.31557,0.94890),
        new complex( 0.37970,0.92511),
        new complex( 0.44206,0.89699),
        new complex( 0.50235,0.86466),
        new complex( 0.56029,0.82830),
        new complex( 0.61561,0.78805),
        new complex( 0.66805,0.74412),
        new complex( 0.71736,0.69671)
};

            ILArraySample sample = new ILArraySample();
            sample.Test();

            ILArray<int> intA = zeros<int>(100);
            ILArray<double> doubleA = ones(5, 4);

            int N = 1024;
            double[] sinData = Enumerable.Range(0, N).Select(i => Math.Sin(i)).ToArray();
            Console.WriteLine("sin() data ({0}) generated", sinData.Length);

        }
예제 #19
0
 public void zgeqp3 ( int M,int N,complex [] A,int LDA,int [] JPVT,complex [] tau,ref int info ) {
     acml_zgeqp3(M,N,A,LDA,JPVT,tau,ref info);
 }
예제 #20
0
 private void Test_det() {
     int errorCode = 0; 
     try {
         ILArray<double> A = ILMath.counter(1.0,1.0,4,4);
         A[1] = 0.0;  // makes A nonsingular ..
         A[14] = 0.0; // - '' - 
         if (!ILMath.det(A).Equals(-360.0))
             throw new Exception("invalid result"); 
         // float 
         errorCode = 2; 
         ILArray<float> Af = ILMath.tosingle(A); 
         if (!ILMath.det(Af).Equals(-360.0f)) 
             throw new Exception("invalid result: float"); 
         // complex 
         errorCode = 3; 
         ILArray<complex> Ac = ILMath.real2complex(A,A); 
         if (!ILMath.det(Ac).Equals(new complex(1440,0.0))) 
             throw new Exception("invalid result: complex"); 
         Ac.SetValue(new complex(3,-4.0),0);
         if (ILMath.det(Ac).GetValue(0) - new complex(7.2000e+002, -1.6800e+003) >= 10e-5) {
             throw new Exception("invalid result: complex (2)"); 
         }
         // fcomplex 
         errorCode = 5; 
         ILArray<fcomplex> Afc = ILMath.real2fcomplex(A,A); 
         if (!ILMath.det(Afc).Equals(new fcomplex(1440.0f,0.0f))) 
             throw new Exception("invalid result: fcomplex"); 
         // special shapes 
         errorCode = 6; 
         A = ILArray<double>.empty(); 
         try {
             ILMath.det(A); 
         } catch (ILArgumentException) {
             Info("det: empty matrix threw exception - ok"); 
         }
         A = -4.70;
         if (!ILMath.det(A).Equals(A)) {
             throw new Exception("det: scalar double: invalid result");
         }
         Af = -4.70f;
         if (!ILMath.det(Af).Equals(Af)) {
             throw new Exception("det: scalar float: invalid result");
         }
         Ac = new complex(-4.70,45.0);
         if (!ILMath.det(Ac).Equals(Ac)) {
             throw new Exception("det: scalar complex: invalid result");
         }
         Afc = new fcomplex(-4.70f,-234.0f); 
         if (!ILMath.det(Afc).Equals(Afc)) {
             throw new Exception("det: scalar fcomplex: invalid result");
         }
         Success();
     } catch(Exception e) {
         Error(errorCode,e.Message); 
     }
 }
예제 #21
0
 public void zpotrs(char uplo, int n, int nrhs, complex[] A, int lda, complex[] B, int ldb, ref int info) {
     acml_zpotrs(uplo,n,nrhs,A,lda,B,ldb,ref info); 
 }
예제 #22
0
        private void Test_Temp() {
            int errorCode = 0; 
            try {
                ILArray<complex> A = new ILArray<complex>(3, 3);

                A[0, 0] = new complex(0.1, 0);
                A[0, 1] = new complex();
                A[0, 2] = new complex();

                A[1, 0] = new complex(0, 0);
                A[1, 1] = new complex(0.1, 0);
                A[1, 2] = new complex(-0.1, 0);

                A[2, 0] = new complex(0, 0);
                A[2, 1] = new complex(-0.1, 0);
                A[2, 2] = new complex(0.1, 0);

                Console.WriteLine("{0}", A);

                ILArray<complex> b = new complex[]{ new complex(0.1, 0), new complex(-0.1, 0), new complex(0.1, 0) };
                b[0] = new complex(0.1, 0);
                b[1] = new complex(-0.1, 0);
                b[2] = new complex(0.1, 0);

                Console.WriteLine(b);

                ILArray<complex> x;
                x = ILMath.linsolve(A, b.T);
                Console.WriteLine("LinSolve Diretto:\n",x.ToString()); //<---------- ERROR!!!

                //Can you help me?
                //Is this the best way to solve this kind of system? If I don't use Linsolve but I try:

                ILArray<complex> Q;
                ILArray<complex> R = new ILArray<complex>(3, 3);
                Q = ILMath.qr(A, ref R, true);
                x=ILMath.linsolve(R, ILMath.multiply(Q.T, b.T));

                Success();
            } catch (Exception e) {
                Error(errorCode,e.Message); 
            }
        }
예제 #23
0
 public void zgelsy(int m, int n, int nrhs, complex[] A, int lda, complex[] B, int ldb, int[] JPVT0, double RCond, ref int rank, ref int info) {
     acml_zgelsy(m,n,nrhs,A,lda,B,ldb,JPVT0,RCond,ref rank,ref info);
 }
예제 #24
0
 public void zgemm(char TransA, char TransB, int M, int N, int K, complex alpha, IntPtr A, int lda, IntPtr B, int ldb, complex beta, complex[] C, int ldc) {
     acml_zgemm(ref TransA, ref TransB, ref M, ref N, ref K, ref alpha, A, ref lda, B, ref ldb, ref beta, C, ref ldc);
 }
예제 #25
0
 public void zheevr(char jobz, char range, char uplo, int n, complex[] A, int lda, double vl, double vu, int il, int iu, double abstol, ref int m, double[] w, complex[] z, int ldz, int[] isuppz, ref int info) {
     acml_zheevr(jobz,range,uplo,n,A,lda,vl,vu,il,iu,abstol,ref m,w,z,ldz,isuppz,ref info); 
 }
예제 #26
0
 public void zgesvd(char jobz, int m, int n, complex[] a, int lda, double[] s, complex[] u, int ldu, complex[] vt, int ldvt, ref int info) {
     acml_zgesvd(jobz, jobz, m, n, a, lda, s, u, ldu, vt, ldvt, ref info);
 }
예제 #27
0
		private static extern void acml_zgemm(ref char TransA, ref char TransB, ref int M, ref int N, ref int K, ref complex alpha, IntPtr A, ref int lda, IntPtr B, ref int ldb, ref complex beta, [In, Out] complex[] C, ref int ldc);
예제 #28
0
 public void zpotri(char uplo, int n, complex[] A, int lda, ref int info) {
     acml_zpotri(uplo,n, A, lda, ref info);
 }
예제 #29
0
        /// <summary>
        /// read ONE array (arbitrary dimensions/type) from MAT file 
        /// </summary>
        /// <param name="br">binary reader initialized and pointing to the beginning of the subarray element.</param>
        /// <returns>ILBaseArray of size and type originally stored into the mat file. Null if not loading this variable.</returns>
        private ILBaseArray read_miMATRIX (BinaryReader br, string[] vars2load) {
            long entryPositionInStream = br.BaseStream.Position; 
            bool complex = false;
            bool logical = false; 
            int mxClass = 0;
            int[] dimensions = new int [0];
            MatFileType storageType = MatFileType.miUNKNOWN;
            int nrElements = 1; 
            string name; 
            ILBaseArray ret; 
            // read array flags 
            Int32 readInt = br.ReadInt32();
            if (readInt != 6) 
                throw new Exception ("found invalid datatype in array flag! currently only 'mxArray' types are supported!"); 
            readInt = br.ReadInt32();
            if (readInt != 8) 
                throw new Exception ("unexpected array flag length. expected: 8 /found: " + readInt); 
            readInt = br.ReadInt32(); 
            complex = (readInt & mtFLAG_COMPLEX) != 0; 
            logical = (readInt & mtFLAG_LOGICAL) != 0; 
            mxClass = readInt & 0x00ff;
            // unknown
            br.ReadInt32();
            // Read dimensions array 
            readInt = br.ReadInt32(); 
            if (readInt != 5) 
                throw new Exception ("found invalid datatype in dimension flag!"); 
            readInt = br.ReadInt32(); 
            if (readInt < 2) 
                throw new Exception ("Invalid number of dimensions found: " + readInt); 
            dimensions = new int[(int)readInt / 4];
            for (int i = 0; i < dimensions.Length; i++) {
                dimensions[i] = br.ReadInt32(); 
                nrElements *= dimensions[i]; 
            }
            // padding if needed
            if ((dimensions.Length % 2) != 0)
                br.ReadInt32(); 
            // read Name - check for small data element format 
            readInt = br.ReadInt32(); 
            int nrSmallBytes = (int)((readInt & 0xffff0000) >> 16); 
            if (nrSmallBytes != 0) {
                // process small element format 
                if ((readInt & 0xffff) != 1) 
                    throw new Exception ("Invalid datype for (compressed) name element found: " + (readInt & 0x00ff) ); 
                StringBuilder nameBuild = new StringBuilder(); 
                nameBuild.Append ( br.ReadChars(nrSmallBytes)); 
                // padding if needed
                while (nrSmallBytes < 4) {
                    br.ReadByte(); 
                    nrSmallBytes ++; 
                }
                name = nameBuild.ToString(); 
            } else {
                // process 'long' format 
                if (readInt != 1) 
                    throw new Exception ("Invalid datype for name element found: " + readInt); 
                readInt = br.ReadInt32(); 
                StringBuilder nameBuild = new StringBuilder(); 
                nameBuild.Append ( br.ReadChars(readInt)); 
                while (readInt % 8 != 0) {
                    readInt ++; 
                    br.ReadByte(); 
                }
                name = nameBuild.ToString(); 
            }
            if (vars2load.Length != 0) {
                int varNameIdx;
                for (varNameIdx = 0; varNameIdx < vars2load.Length; varNameIdx++)
                    if (name == vars2load[varNameIdx]) break;

                if (varNameIdx == vars2load.Length) return null;
            }
            // read data flags + check if small format
            readInt = br.ReadInt32(); 
            nrSmallBytes = (Int16)((readInt & 0xffff0000) >> 16); 
            System.Array realData = null; 
            System.Array imagData = null; 
            int len; 
            if (nrSmallBytes != 0 && nrElements <= 4) {
                // small data element format for scalars only! 
                // process small format -> real part 
                storageType = (MatFileType)(readInt & 0xffff);
                len = nrSmallBytes; 
                readElementGeneric(br, storageType, out realData, ref len,4);
                // padding
                //while (nrSmallBytes < 4 && br.BaseStream.Position < br.BaseStream.Length) {
                //    br.ReadByte(); 
                //    nrSmallBytes++; 
                //}
            } else {    
                // read regular data : real part
                storageType = (MatFileType)Enum.Parse(typeof(MatFileType), readInt.ToString()); 
                len = br.ReadInt32();
                nrSmallBytes = len; 
                readElementGeneric(br, storageType, out realData, ref len);
                // (padding is done in readElementGeneric)
            }

            // read imag part + check if small format
            if (complex) {
                readInt = br.ReadInt32(); 
                nrSmallBytes = (Int16)((readInt & 0xffff0000) >> 16); 
                if (nrSmallBytes != 0 && nrElements <= 4) {
                    // process small format -> imag part 
                    storageType = (MatFileType)(readInt & 0xffff);
                    len = nrSmallBytes; 
                    readElementGeneric(br, storageType, out imagData, ref len,4);
                    // padding
                    //while (nrSmallBytes < 4 && br.BaseStream.Position < br.BaseStream.Length) {
                    //    br.ReadByte(); 
                    //    nrSmallBytes++; 
                    //}
                } else {    
                    // read regular data : image part
                    storageType = (MatFileType)Enum.Parse(typeof(MatFileType), readInt.ToString());; 
                    len = br.ReadInt32();
                    nrSmallBytes = len; 
                    readElementGeneric(br, storageType, out imagData, ref len);
                    // (padding's done in readElementGeneric)
                }
            }
            // convert to original data type 
            if (complex) {
                complex[] retArr = new complex[nrElements];
                double[] realPart = Convert2DoubleArray(realData); 
                double[] imagPart = Convert2DoubleArray(imagData); 
                for (int i = 0; i < nrElements; i ++) {
                    retArr[i] = new complex(realPart[i] , imagPart[i]); 
                }
                ret = new ILArray<complex>(retArr, dimensions); 
            } else if (logical) {
                int numNonzero = 0; 
                byte[] retArr = Convert2Logical(realData, out numNonzero); 
                ret = new ILLogicalArray(retArr,new ILDimension(dimensions),numNonzero); 
            } else {
                if (false) { }
                #region HYCALPER LOOPSTART
/*!HC:TYPELIST:
    <hycalper>
    <type>
        <source locate="after">
            pattern1
        </source>
            <destination>mxINT8_CLASS</destination>
            <destination>mxUINT8_CLASS</destination>
    </type>
    <type>
        <source locate="after">
            pattern3
        </source>
        <destination>byte</destination>
        <destination>byte</destination>
    </type>
    <type>
        <source locate="after">
            pattern4
        </source>
        <destination>Convert2ByteArray</destination>
        <destination>Convert2ByteArray</destination>
    </type>
    <type>
        <source locate="after">
            pattern5
        </source>
        <destination><![CDATA[ILArray<byte>]]></destination>
        <destination><![CDATA[ILArray<byte>]]></destination>
    </type>
</hycalper>
*/
                else if (mxClass ==/*!HC:pattern1*/ mxDOUBLE_CLASS )
                {
                    /*!HC:pattern3*/ double [] dataArr;
                    if (realData is /*!HC:pattern3*/ double [])
                    {
                        dataArr = (/*!HC:pattern3*/ double [] ) realData;
                    }
                    else
                    {
                        dataArr = /*!HC:pattern4*/ Convert2DoubleArray (realData);
                    }
                    ret = new /*!HC:pattern5*/ ILArray<double> (dataArr, dimensions);
                }
                #endregion HYCALPER LOOPEND
#region HYCALPER AUTO GENERATED CODE
// DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !! 

                else if (mxClass == mxUINT8_CLASS )
                {
                    byte [] dataArr;
                    if (realData is  byte [])
                    {
                        dataArr = ( byte [] ) realData;
                    }
                    else
                    {
                        dataArr =  Convert2ByteArray (realData);
                    }
                    ret = new  ILArray<byte> (dataArr, dimensions);
                }

                else if (mxClass == mxINT8_CLASS )
                {
                    byte [] dataArr;
                    if (realData is  byte [])
                    {
                        dataArr = ( byte [] ) realData;
                    }
                    else
                    {
                        dataArr =  Convert2ByteArray (realData);
                    }
                    ret = new  ILArray<byte> (dataArr, dimensions);
                }

#endregion HYCALPER AUTO GENERATED CODE

                else
                    throw new Exception("Unsupported data element type found! Cancelling...");
            } 
            // set name       
            ret.Name = name; 
            return ret;
        }
예제 #30
0
 /// <summary>
 /// Logarithm of base 10
 /// </summary>
 /// <param name="input">input</param>
 /// <returns>logarithm of base 10</returns>
 /// <seealso cref="ILNumerics.complex.Log(complex)"/>
 public static complex Log10(complex input) {
     return Log(input) * 0.43429448190325176;
 }