当前位置: 首页>>代码示例>>C#>>正文


C# ILArray.GetValue方法代码示例

本文整理汇总了C#中ILArray.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# ILArray.GetValue方法的具体用法?C# ILArray.GetValue怎么用?C# ILArray.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILArray的用法示例。


在下文中一共展示了ILArray.GetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: imag

 /// <summary>
 /// imaginary part of complex array elements
 /// </summary>
 /// <param name="X">complex input array</param>
 /// <returns>imaginary part of complex array</returns>
 public static /*!HC:outCls1*/ ILArray<double> imag (/*!HC:inCls1*/ ILArray<complex> X) {
     int nrX = X.m_dimensions.NumberOfElements; 
     /*!HC:outArr1*/ double [] retArr = new /*!HC:outArr1*/ double [nrX]; 
     /*!HC:outCls1*/ ILArray<double> ret = new /*!HC:outCls1*/ ILArray<double> (retArr,X.m_dimensions); 
     for (int i= 0; i < nrX; i++) {
         retArr[i] = X.GetValue(i).imag; 
     }
     return ret; 
 }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:14,代码来源:imag.cs

示例2: DistributePower

        //P_ref is a vector of power refenreces for tehe wind turbine with dimension 1xN
        //v_nac is a vector of wind speed at each wind turbine with dimension 1xN
        //P_demand is a scale of the wind farm power demand.
        //parm is a struct of wind turbine parameters e.g. NREL5MW
        public static void DistributePower(ILArray<double> v_nac, double P_demand, ILArray<double> Power, WindTurbineParameters parm, out ILArray<double> P_ref, out ILArray<double> P_a)
        {
            double rho;
            ILArray<double> R;
            ILArray<double> rated;
            int N;
            ILArray<double> Cp;
            double P_avail;

            rho = parm.rho;                 //air density for each wind turbine(probably the same for all)
            R = parm.radius.C;              //rotor radius for each wind turbine(NREL.r=63m)
            rated = parm.rated.C;           //Rated power for each wind turbine(NREL.Prated=5MW)
            N = parm.N;                     //Number of turbines in windfarm
            Cp = parm.Cp.C;                 // Max cp of the turbines for each wind turbine(NREL.Cp.max=0.45)

            P_a = ILMath.zeros(N, 1);
            P_ref = ILMath.zeros(N, 1);

            // Compute available power at each turbine
            for (var i = 0; i <= N - 1; i++)
            {
                //P_a=A*pi*r*r*Cp*v*v*v
                P_a[i] = Math.Min(rated.GetValue(i), (ILMath.pi / 2) * rho * Math.Pow(R.GetValue(i), 2) * Math.Pow(v_nac.GetValue(i), 3) * Cp.GetValue(i));
            }

            //Compute total available power
            P_avail = (double)ILMath.sum(P_a);

            //Distribute power according to availibility
            for (var i = 0; i <= N - 1; i++)
            {
                if (P_demand < P_avail)
                {
                    P_ref[i] = Math.Max(0, Math.Min(rated.GetValue(i), P_demand * P_a.GetValue(i) / P_avail));
                }
                else
                {
                    P_ref[i] = P_a.GetValue(i);
                }
            }
        }
开发者ID:mohsenboojari,项目名称:offwind,代码行数:45,代码来源:PowerDistributionControl.cs

示例3: isequalwithequalnans

/*!HC:TYPELIST:
<hycalper>
<type>
    <source>
        inCls1
    </source>
    <destination><![CDATA[ILArray<complex>]]></destination>
    <destination><![CDATA[ILArray<float>]]></destination>
    <destination><![CDATA[ILArray<fcomplex>]]></destination>
</type>
<type>
    <source>
        inCls2
    </source>
    <destination><![CDATA[ILArray<complex>]]></destination>
    <destination><![CDATA[ILArray<float>]]></destination>
    <destination><![CDATA[ILArray<fcomplex>]]></destination>
</type>
<type>
    <source>
        inArr1
    </source>
    <destination>complex</destination>
    <destination>float</destination>
    <destination>fcomplex</destination>
</type>
</hycalper>
*/
        public static bool isequalwithequalnans(/*HC:inCls1*/ ILArray<double> A,/*HC:inCls2*/ ILArray<double> 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 (/*!HC:inArr1*/ double a in A.Values) {
                /*!HC:inArr1*/ double b = B.GetValue(pos++); 
                if (/*!HC:inArr1*/ double .IsNaN(a) && /*!HC:inArr1*/ double .IsNaN(b)) continue; 
                if (/*!HC:inArr1*/ double .IsInfinity(a) && /*!HC:inArr1*/ double .IsInfinity(b)) continue; 
                if (b != a) return false; 
            }
            return true;
        }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:43,代码来源:isequalwithequalnans.cs

示例4: Model

        public void Model(ILArray<double> x, ILArray<double> u, ILMatFile wt, ILMatFile env, double DT, out double Omega, out double Ct, out double Cp)
        {
            // Parameters

            var R = (double)wt.GetArray<double>("wt_rotor_radius");
            var I = (double)wt.GetArray<double>("wt_rotor_inertia");
            var Rho = (double)env.GetArray<double>("env_rho");

            // Definitons etc.

            Omega = x.GetValue(0);
            var Ve = x.GetValue(1);
            var Beta = u.GetValue(0);
            var Tg = u.GetValue(1);

            // Algorithm

            var Lambda = Omega * R / Ve;
            _eInterpolCp.Interpolate(Beta, Lambda, wt.GetArray<double>("wt_cp_table"), wt.GetArray<double>("wt_cp_beta"), wt.GetArray<double>("wt_cp_tsr"), out Cp);
            _eInterpolCt.Interpolate(Beta, Lambda, wt.GetArray<double>("wt_ct_table"), wt.GetArray<double>("wt_ct_beta"), wt.GetArray<double>("wt_ct_tsr"), out Ct);

            var Tr = 0.5 * Rho * ILMath.pi * Math.Pow(R, 2) * Math.Pow(Ve, 3) * Cp / Omega;
            Omega = Omega + DT * (Tr - Tg) / I; //Integration method: Forward Euler
        }
开发者ID:mohsenboojari,项目名称:offwind,代码行数:24,代码来源:TurbineDrivetrainModel.cs

示例5: polyfit

 /// <summary>
 /// Polynomial curve fitting of degree n
 /// </summary>
 /// <param name="x">Vector of X values</param>
 /// <param name="y">Vector of Y values</param>
 /// <param name="n">Degress of polynomial to fit</param>
 /// <returns>Vector of polynomial coefficients [p1, p2, .., pn+1], fit is p(x) = p1*x^n + p2*x^(n-1) + ...</returns>
 public static ILArray<double> polyfit(ILArray<double> x, ILArray<double> y, int n)
 {
     // Create Vandermonde matrix [[x0^n, x0^(n-1), ..., 1], [x1^n, x1^(n-1), ..., 1], ...]
     if (!x.IsVector || !y.IsVector)
         throw new ILArgumentException("x and y must be vectors");
     if (x.Length != y.Length)
         throw new ILArgumentException("x and y must have the same length");
     int m = x.Length;
     ILArray<double> V = new ILArray<double>(m, n + 1);
     for (int i = 0; i < m; ++i)
     {
         double vElement = 1;
         double currentX = x.GetValue(i);
         for (int j = n; j >= 0; --j)
         {
             V[i, j] = vElement;
             vElement *= currentX;
         }
     }
     ILArray<double> coefficients = ILMath.linsolve(V, y);
     return coefficients;
 }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:29,代码来源:polyfit.cs

示例6: single

 /// <summary>
 /// convert numerical ILArray to single precision floating point precision
 /// </summary>
 /// <param name="X">numeric input array</param>
 /// <returns><![CDATA[ILArray<float>]]> of same size as X having all elements converted to 
 /// single precision floating point format.</returns>
 /// <remarks>All overloads of this function will return a solid physical copy 
 /// of the input array X.</remarks>
 public static ILArray<float> single (/*!HC:inCls1*/ ILArray<double> X) {
     int nrX = X.m_dimensions.NumberOfElements; 
     float [] retArr = new float [nrX]; 
     ILArray<float> ret = new ILArray<float> (retArr,X.m_dimensions); 
     if (X.IsReference) {
         for (int i= 0; i < nrX; i++) {
             retArr[i] = (float) X.GetValue(i); 
         }
     } else {
         unsafe {
             fixed (float * outArr = ret.m_data)
             fixed (/*!HC:inArr1*/ double * inArr = X.m_data) {
                 float* lastElementAfter = outArr + nrX;
                 float* outArrP = outArr; 
                 /*!HC:inArr1*/ double * inArrP = inArr; 
                 while (outArrP < lastElementAfter){
                     *outArrP++ = (float)*inArrP++; 
                 }
             }
         }
     }
     return ret; 
 }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:31,代码来源:single.cs

示例7: max

        /// <summary> sum two arrays elementwise</summary>
        /// <param name="A">input 1</param>
        /// <param name="B">input 2</param>
        /// <returns> Array with elementwise sum of A and B </returns>
        /// <remarks><para>On empty input - empty array will be returned.</para>
        /// <para>A and / or B may be scalar. The scalar value will operate on all elements of the other arrays in this case.</para>
        /// <para>If neither of A or B is scalar or empty, the dimensions of both arrays must match.</para></remarks>
        public static  ILArray<byte>  max ( ILArray<byte> A,  ILArray<byte> B) {
            if (A.IsEmpty) {
                return  ILArray<byte> .empty(A.Dimensions); 
            }
            if (B.IsEmpty) {
                return  ILArray<byte> .empty(B.Dimensions);
            }
            if (A.IsScalar) {
                if (B.IsScalar) {
                    return new ILArray<byte> (new byte[1]{(A.GetValue(0) > B.GetValue(0))?A.GetValue(0):B.GetValue(0)});
                } else {
                    #region scalar + array  
                    ILDimension inDim = B.Dimensions;

                    byte [] retArr =
                        ILMemoryPool.Pool.New< byte > (inDim.NumberOfElements);

                    byte scalarValue = A.m_data[0]; 
                    
                    unsafe {
                        fixed ( byte * pOutArr = retArr)
                        fixed ( byte * pInArr = B.m_data) {
                            byte * lastElement = pOutArr + retArr.Length;
                            byte * tmpOut = pOutArr;
                            byte * tmpIn = pInArr;
                            while (tmpOut < lastElement) //HC03
                                { *tmpOut++ = (scalarValue > *tmpIn)? scalarValue: *tmpIn; tmpIn++; }
                        }       
                    }

                    return new  ILArray<byte> ( retArr, inDim );
                    #endregion scalar + array
                }
            } else {
                if (B.IsScalar) {
                    #region array + scalar
                    ILDimension inDim = A.Dimensions;

                    byte [] retArr = 
                        ILMemoryPool.Pool.New< byte > (A.m_data.Length);

                    byte scalarValue = B.m_data[0]; 

                    unsafe {
                        fixed ( byte * pOutArr = retArr)
                        fixed ( byte * pInArr = A.m_data) {
                            byte * lastElement = pOutArr + retArr.Length;
                            byte * tmpOut = pOutArr;
                            byte * tmpIn = pInArr;
                            while (tmpOut < lastElement) { //HC06
                                { *tmpOut++ = (scalarValue > *tmpIn)? scalarValue: *tmpIn; tmpIn++; }
                            }
                        }
                    }

                    return new  ILArray<byte> ( retArr, inDim );
                    #endregion array + scalar
                } else {
                    #region array + array
                    ILDimension inDim = A.Dimensions;
                    if (!inDim.IsSameSize ( B.Dimensions ))
                        throw new ILDimensionMismatchException ();

                    byte [] retSystemArr =
                        ILMemoryPool.Pool.New< byte > (inDim.NumberOfElements);

                    unsafe {
                        fixed ( byte * pOutArr = retSystemArr)
                        fixed ( byte * inA1 = A.m_data) 
                        fixed ( byte * inA2 = B.m_data) {
                            byte * pInA1 = inA1; 
                            byte * pInA2 = inA2;
                            byte * poutarr = pOutArr;
                            byte * outEnd = poutarr + retSystemArr.Length;
                            while (poutarr < outEnd) {  //HC11
                                if (*pInA1> *pInA2) { *poutarr++ = *pInA1++; pInA2++;} else {*poutarr++ = *pInA2++; pInA1++;}
                            }
                        }
                    }

                    return new  ILArray<byte> ( retSystemArr, inDim );
                    #endregion array + array
                }
            }
        }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:92,代码来源:Max.cs

示例8: ccomplex

 /// <summary>
 /// Create complex array from real and imaginary parts. 
 /// </summary>
 /// <param name="real">Array with real part elements.</param>
 /// <param name="imag">Array with imaginary part elements.</param>
 /// <returns>Complex array constructed out of real and imaginary parts supplied.</returns>
 /// <exception cref="ILNumerics.Exceptions.ILArgumentException">If the size of both arguments is not the same.</exception>
 public static ILArray<fcomplex> ccomplex(ILArray<float> real, ILArray<float> imag) {
     if (!real.Dimensions.IsSameSize(imag.Dimensions)) 
         throw new ILArgumentException("fcomplex: input arrays must have the same size!");
     ILArray<fcomplex> ret = ILMath.tofcomplex(real);
     int nelem = real.Dimensions.NumberOfElements; 
     int baseIdxRet; 
     for (int i = 0; i < nelem; i++) {
         baseIdxRet = real.getBaseIndex(i); 
         ret.m_data[baseIdxRet].imag = imag.GetValue(i); 
     }
     return ret; 
 }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:19,代码来源:ILMathCreation.cs

示例9: sum

        /// <summary>
		/// Sum elements of A along dimension specified.
		/// </summary>
		/// <param name="A">N-dimensional array</param>
		/// <param name="leadDim">index of dimension to operate along</param>
		/// <returns>array, same size as A, but having the 'leadDim's dimension 
		/// reduced to the length 1 with the sum of all
		/// elements along that dimension.</returns>
        public static  ILArray<UInt16>  sum ( ILArray<UInt16> A, int leadDim) {
            if (leadDim >= A.Dimensions.NumberOfDimensions)
                throw new ILArgumentException("dimension parameter out of range!");
            if (A.IsEmpty)       
                return  ILArray<UInt16> .empty(A.Dimensions); 
            if (A.IsScalar) {
               
                return new  ILArray<UInt16> (new  UInt16 []{A.GetValue(0)},1,1);
            }
            ILDimension inDim = A.Dimensions; 
			int[] newDims = inDim.ToIntArray();
           
            if (inDim[leadDim] == 1) return ( ILArray<UInt16> )A.Clone();
			int newLength;
			 UInt16 [] retDblArr;
			// build ILDimension
			newLength = inDim.NumberOfElements / newDims[leadDim];
			newDims[leadDim] = 1;
			retDblArr = ILMemoryPool.Pool.New< UInt16 >(newLength);
            ILDimension newDimension = new ILDimension(newDims); 
            int incOut = newDimension.SequentialIndexDistance(leadDim); 
            int leadDimLen = inDim[leadDim];
            int posCounter; 
			int nrHigherDims = inDim.NumberOfElements / leadDimLen;
            if (A.IsReference) {
#region Reference storage
				// ========================  REFERENCE double Storage ===========
				if (A.IsMatrix) {
#region Matrix
					////////////////////////////   MATRIX   ///////////////////////
					unsafe {
						ILIndexOffset idxOffset = A.m_indexOffset;
						int secDim = (leadDim + 1) % 2;
						fixed (int* leadDimStart = idxOffset[leadDim],
								secDimStart = idxOffset[secDim]) {
							fixed ( UInt16 * pOutArr = retDblArr)
						    fixed ( UInt16 * pInArr = A.m_data) {
								 UInt16 * tmpOut = pOutArr;
								 UInt16 * lastElementOut = tmpOut + retDblArr.Length;
								 UInt16 * tmpIn = pInArr;
								int* secDimEnd = secDimStart + idxOffset[secDim].Length - 1;
								int* secDimIdx = secDimStart; 
								int* leadDimIdx = leadDimStart;
								int* leadDimEnd = leadDimStart + leadDimLen - 1;
								// start at first element
								while (secDimIdx <= secDimEnd) {
									tmpIn = pInArr + *secDimIdx++; 
									leadDimIdx = leadDimStart;
                                    *tmpOut = 0;
									while (leadDimIdx <= leadDimEnd) {
                                        UInt16 inVal = *(tmpIn + *leadDimIdx++); 
                                        /**/
										 *tmpOut +=  (UInt16) (inVal)  ;
									}
                                    
                                    /**/
                                    tmpOut++;
								}
							}
						}
					} 
#endregion
				} else {
					/////////////////////////////   ARBITRARY DIMENSIONS //////////
#region arbitrary size
					unsafe {
						ILIndexOffset idxOffset = A.m_indexOffset;
						int[] curPosition = new int[A.Dimensions.NumberOfDimensions];
						fixed (int* leadDimStart = idxOffset[leadDim]) {
							fixed ( UInt16 * pOutArr = retDblArr)
							fixed ( UInt16 * pInArr = A.m_data) {
								 UInt16 * tmpOut = pOutArr;
								 UInt16 * lastElementOut = tmpOut + retDblArr.Length - 1;
								 UInt16 * tmpIn = pInArr + A.m_indexOffset.Map(0);
								int* leadDimIdx = leadDimStart;
								int* leadDimEnd = leadDimStart + leadDimLen;
								int dimLen = curPosition.Length;
								int d, curD;
								// start at first element
                                posCounter = retDblArr.Length; 
								while (posCounter-->0) {
									leadDimIdx = leadDimStart;
                                    *tmpOut = 0;
									while (leadDimIdx < leadDimEnd){
                                        UInt16 inVal = *(tmpIn + *leadDimIdx++); 
                                        /**/
										 *tmpOut +=  (UInt16) (inVal)  ;
									 
                                    /**/
                                    }
                                    tmpOut += incOut;
                                    if (tmpOut > lastElementOut)
//.........这里部分代码省略.........
开发者ID:wdxa,项目名称:ILNumerics,代码行数:101,代码来源:Sum.cs

示例10: convert

// DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !! 
        /// <summary>
        /// convert arbitrary numeric array to arbitrary numeric type
        /// </summary>
        /// <param name="X">input array</param>
        /// <param name="outputType">type description for return type</param>
        /// <returns>converted array</returns>
        /// <remarks> The newly created array will be converted to the type requested. 
        /// <para>Important note: if X matches the type requested, NO COPY will be made for it and the SAME array will be returned!</para></remarks>
        public static ILBaseArray convert(NumericType outputType,  ILArray< UInt64 > X) {
            if (outputType  ==  NumericType.UInt64 )
                return X; 
            ILBaseArray ret = null; 
            switch (outputType) {
                case NumericType.Double:
                    unsafe {
                        double [] retA = ILMemoryPool.Pool.New<double>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            fixed (double * pretA = retA) {
                                int c = 0; 
                                double * pStart = pretA; 
                                double * pEnd = pretA + retA.Length; 
                                while (pStart < pEnd) {
                                    *(pStart++) = (double) X.GetValue(c++);
                                }
                            }
                        } else {
                            fixed (double * pretA = retA)
                            fixed ( UInt64 * pX = X.m_data) {
                                double * pStartR = pretA; 
                                double * pEndR = pretA + X.m_data.Length;
                                UInt64 * pWalkX = pX; 
                                while (pStartR < pEndR) {
                                    *(pStartR++) = (double) *(pWalkX++); 
                                }
                            }
                        }
                        ret = new ILArray<double> (retA,X.Dimensions); 
                    }
                    return ret; 
                case NumericType.Single:
                    unsafe {
                        float [] retA = ILMemoryPool.Pool.New<float>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            int c = 0; 
                            fixed (float * pretA = retA) {
                                float * pStart = pretA; 
                                float * pEnd = pretA + retA.Length; 
                                while (pStart < pEnd) {
                                    *(pStart++) = (float) X.GetValue(c++);
                                }
                            }
                        } else {
                            fixed (float * pretA = retA)
                            fixed ( UInt64 * pX = X.m_data) {
                                float * pStartR = pretA; 
                                float * pEndR = pretA + X.m_data.Length;
                                UInt64 * pWalkX = pX; 
                                while (pStartR < pEndR) {
                                    *(pStartR++) = (float) *(pWalkX++); 
                                }
                            }
                        }
                        ret = new ILArray<float> (retA,X.Dimensions); 
                    }
                    return ret; 
                case NumericType.Complex:
                    unsafe {
                        complex [] retA = ILMemoryPool.Pool.New<complex>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            int c = 0; 
                            fixed (complex * pretA = retA) {
                                complex * pStart = pretA; 
                                complex * pEnd = pretA + retA.Length; 
                                while (pStart < pEnd) {
                                    *(pStart++) = X.GetValue(c++);
                                }
                            }
                        } else {
                            fixed (complex * pretA = retA)
                            fixed ( UInt64 * pX = X.m_data) {
                                complex * pStartR = pretA; 
                                complex * pEndR = pretA + X.m_data.Length;
                                UInt64 * pWalkX = pX; 
                                while (pStartR < pEndR) {
                                    *(pStartR++) = (complex) (*(pWalkX++)); 
                                }
                            }
                        }
                        ret = new ILArray<complex> (retA,X.Dimensions); 
                    }
                    return ret; 
                case NumericType.FComplex:
                    unsafe {
                        fcomplex [] retA = ILMemoryPool.Pool.New<fcomplex>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            int c = 0; 
                            fixed (fcomplex * pretA = retA) {
                                fcomplex * pStart = pretA; 
                                fcomplex * pEnd = pretA + retA.Length; 
//.........这里部分代码省略.........
开发者ID:wdxa,项目名称:ILNumerics,代码行数:101,代码来源:convert.cs

示例11: qr

 /// <summary>
 /// QR decomposition, returning Q and R, optionally economical sized
 /// </summary>
 /// <param name="A">general input matrix A of size [m x n]</param>
 /// <param name="R">output parameter. Upper triangular matrix R as 
 /// result of decomposition. Size [m x n] or [min(m,n) x n] (see remarks). </param>
 /// <param name="economySize">if true, the size of Q and R will 
 /// be [m x m] and [m x n] respectively. However, if m &lt; n, 
 /// the economySize parameter has no effect. </param>
 /// <returns>Orthonormal real / unitary complex matrix Q as result 
 /// of decomposition. Size [m x m] or [m x min(m,n)], depending 
 /// on <paramref name="economySize"/> (see remarks below)</returns>
 /// <remarks>The function returns Q and R such that the equation 
 /// <para>A = Q * R</para> holds with roundoff errors. ('*' 
 /// denotes matrix multiplication.) 
 /// <para>Q and R will be solid ILArray's.</para></remarks>
 public static  ILArray<complex> qr(
                         ILArray<complex> A, 
                         ref  ILArray<complex> R, bool economySize) {
     if (Object.Equals(R,null)) {
         return qr(A); 
     }
     int m = A.Dimensions[0]; 
     int n = A.Dimensions[1]; 
     if (m < n && economySize) return qr(A,ref R, false); 
     ILArray<complex> ret;
     if (m == 0 || n == 0) { 
         R = new  ILArray<complex> (new  complex [0],m,n); 
         return  ILArray<complex> .empty(A.Dimensions);  
     }
     int minMN = (m<n)?m:n;
     int info = 0; 
     complex [] tau = new  complex [minMN];  
     complex [] QArr;
     if (m >= n) {
         ret = new  ILArray<complex> (
                             new  complex [(economySize)? minMN * m : m * m],
                             m,(economySize)? minMN: m); 
     } else {
         // economySize is always false ... !
         // a temporary array is needed for extraction of the compact lapack Q (?geqrf)
         ret = new  ILArray<complex> (
                             new  complex [m * n],m,n); 
     }
     QArr = ret.m_data;
     for (int i = m*n; i-->0;) {
         QArr[i] = A.GetValue(i); 
     }
     Lapack.zgeqrf (m,n,QArr,m,tau,ref info);
     if (info != 0) {
         throw new ILArgumentException("qr: error inside lapack library (?geqrf). info=" + info.ToString());
     }
     // extract R, Q
     if (economySize) {
         R = copyUpperTriangle(QArr,m,n,minMN); 
         Lapack.zungqr (m,minMN,tau.Length,QArr,m,tau,ref info); 
     } else {
         R = copyUpperTriangle(QArr,m,n,m); 
         Lapack.zungqr (m,m,tau.Length,QArr,m,tau,ref info); 
         if (m < n) 
             ret = ret[":;0:" + (m-1)]; 
     }
     if (info != 0) 
         throw new ILArgumentException("qr: error in lapack library (???gqr). info=" + info.ToString());
     return ret; 
 }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:66,代码来源:qr.cs

示例12: istriup

        /// <summary>
        /// Determine if matrix A is upper triangular matrix
        /// </summary>
        /// <param name="A">Matrix or scalar A of numeric inner type</param>
        /// <returns>true if A is a upper triangular matrix, false otherwise</returns>
        /// <exception cref="ILNumerics.Exceptions.ILArgumentException">if A was not a matrix or if A was null</exception>
        public static bool istriup( ILArray<byte> A) {
            if (object.Equals(A,null))
                throw new ILArgumentException ("istriup: A must not be null!"); 
            if (A.IsScalar) {   return true;    }
            if (A.IsEmpty)  {   return false;   }
            if (!A.IsMatrix)
                throw new ILArgumentException ("istriup: A must be matrix or scalar!"); 
            int m = A.Dimensions[0]; 
            int n = A.Dimensions[1]; 
            for (int c = 0; c < n; c++) {
                for (int r = c+1; r < m; r++){
                    if (A.GetValue(r,c) !=  0.0 ) return false; 
			    }       
			}
            return true; 
        }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:22,代码来源:matrixTest.cs

示例13: ishermitian

        /// <summary>
        /// Determine if matrix A is Hermitian matrix 
        /// </summary>
        /// <param name="A">Matrix or scalar A of numeric inner type</param>
        /// <returns>true if A is a Hermitian matrix, false otherwise</returns>
        /// <exception cref="ILNumerics.Exceptions.ILArgumentException">if A was null</exception>
        public static bool ishermitian( ILArray<byte> A) {
            if (object.Equals(A,null))
                throw new ILArgumentException ("ishessup: A must not be null!"); 
            if (A.IsScalar) {   return true;    }
            if (A.IsEmpty)  {   return false;   }
            if (!A.IsMatrix)    return false; 
            int n = A.Dimensions[1]; 
            if (n != A.Dimensions[0]) return false; 
            for (int c = 0; c < n; c++) {
                 
                for (int r = c+1; r < n; r++){
                    if (A.GetValue(r,c) != A.GetValue(c,r)) return false; 
			    }       
			}
            return true; 
        }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:22,代码来源:matrixTest.cs

示例14: subtract

        /// <summary> sum two arrays elementwise</summary>
        /// <param name="A">input 1</param>
        /// <param name="B">input 2</param>
        /// <returns> Array with elementwise sum of A and B </returns>
        /// <remarks><para>On empty input - empty array will be returned.</para>
        /// <para>A and / or B may be scalar. The scalar value will operate on all elements of the 
        /// other array in this case.</para>
        /// <para>If neither of A or B is scalar or empty, the dimensions of both arrays must match.
        /// </para></remarks>
        public static  ILArray<UInt16>  subtract ( ILArray<UInt16> A,  ILArray<UInt16> B) {
            if (A.IsEmpty && B.IsEmpty ) {
                if (!A.Dimensions.IsSameShape(B.Dimensions))
                    throw new ILDimensionMismatchException(); 
                return  ILArray<UInt16> .empty(A.Dimensions); 
            }
            if (A.IsScalar) {
                if (B.IsScalar) {
                   
                    return new  ILArray<UInt16> (new  UInt16 [1]{ saturateUInt16 (A.GetValue(0)  - (double) B.GetValue(0))}, A.Dimensions);
                } else {
                    if (B.IsEmpty) {
                        return  ILArray<UInt16> .empty(B.Dimensions); 
                    }
                    #region scalar + array  
                    ILDimension inDim = B.Dimensions;
                    //  UInt16 [] retArr = new  UInt16 [inDim.NumberOfElements];
                    UInt16 [] retArr = ILMemoryPool.Pool.New< UInt16 > (inDim.NumberOfElements);
                    double scalarValue = A.GetValue(0); 
                    UInt16 tmpValue2; 
                    int leadDim = 0,leadDimLen = inDim [0];
                    if (B.IsReference) {
                        #region Reference storage
                        // walk along the longest dimension (for performance reasons)
                        ILIndexOffset idxOffset = B.m_indexOffset;
                        int incOut = inDim.SequentialIndexDistance ( leadDim );
                        System.Diagnostics.Debug.Assert(!B.IsVector,"Reference arrays of vector size should not exist!"); 
                        for (int i = 1; i < inDim.NumberOfDimensions; i++) {
                            if (leadDimLen < inDim [i]) {
                                leadDimLen = inDim [i];
                                leadDim = i;
                                incOut = inDim.SequentialIndexDistance ( leadDim );
                            }
                        }
                        if (B.IsMatrix) {
                            #region Matrix
                            ////////////////////////////   MATRIX   ////////////////////
                            int secDim = ( leadDim + 1 ) % 2;
                            unsafe {
                                fixed (int* leadDimStart = idxOffset [leadDim],secDimStart = idxOffset [secDim])
                                fixed ( UInt16 * pOutArr = retArr)
                                fixed ( UInt16 * pInArr = B.m_data) {
                                        UInt16 * tmpOut = pOutArr;
                                        UInt16 * tmpIn = pInArr;
                                        UInt16 * tmpOutEnd = pOutArr + inDim.NumberOfElements - 1;
                                        int* secDimEnd = secDimStart + idxOffset [secDim].Length;
                                        int* secDimIdx = secDimStart;
                                        int* leadDimIdx = leadDimStart;
                                        int* leadDimEnd = leadDimStart + leadDimLen;
                                        while (secDimIdx < secDimEnd) {
                                            if (tmpOut > tmpOutEnd)
                                                tmpOut = pOutArr + ( tmpOut - tmpOutEnd);
                                            tmpIn = pInArr + *secDimIdx++;
                                            leadDimIdx = leadDimStart;
                                            while (leadDimIdx < leadDimEnd) {
                                               
                                                *tmpOut =  saturateUInt16 (scalarValue  - (double) (*( tmpIn + *leadDimIdx++ )));
                                                tmpOut += incOut;
                                            }
                                        }
                                }
                            }
                            #endregion
                        } else {
                            #region arbitrary size
                            unsafe {
                                int [] curPosition = new int [B.Dimensions.NumberOfDimensions];
                                fixed (int* leadDimStart = idxOffset [leadDim]) {
                                    fixed ( UInt16 * pOutArr = retArr)
                                    fixed ( UInt16 * pInArr = B.m_data) {
                                        UInt16 * tmpOut = pOutArr;
                                        UInt16 * tmpOutEnd = tmpOut + retArr.Length;
                                        // init lesezeiger: add alle Dimensionen mit 0 (auer leadDim)
                                        UInt16 * tmpIn = pInArr + B.getBaseIndex (0,0);
                                        tmpIn -= idxOffset [leadDim, 0];
                                        int* leadDimIdx = leadDimStart;
                                        int* leadDimEnd = leadDimStart + leadDimLen;
                                        int dimLen = curPosition.Length;
                                        int d, curD;
                                        // start at first element
                                        while (tmpOut < tmpOutEnd) {
                                            leadDimIdx = leadDimStart;
                                            while (leadDimIdx < leadDimEnd) {
                                               
                                                *tmpOut =  saturateUInt16 (scalarValue  - (double) (*(tmpIn + *leadDimIdx++)));
                                                tmpOut += incOut;
                                            }
                                            if (tmpOut > tmpOutEnd)
                                                tmpOut = pOutArr + ( tmpOutEnd - tmpOut );

                                            // increment higher dimensions 
//.........这里部分代码省略.........
开发者ID:wdxa,项目名称:ILNumerics,代码行数:101,代码来源:Subtract.cs

示例15: neq

 /// <summary>
 /// Elementwise logical 'not equal' operator
 /// </summary>
 /// <param name="A">input array 1</param>
 /// <param name="B">input array 2</param>
 /// <returns>Logical array having '1' for elements in A not equal elements in B, '0' else</returns>
 /// <remarks><para>On empty input - empty array will be returned.</para>
 /// <para>A and / or B may be scalar. The scalar value will operate on all elements of the other arrays in this case.</para>
 /// <para>If neither of A or B is scalar or empty, the dimensions of both arrays must match.</para></remarks>
 /// <exception cref="ILNumerics.Exceptions.ILDimensionMismatchException">if neither of A or B is scalar and the size of both arrays does not match</exception>
 public static ILLogicalArray neq (ILArray<String> A, ILArray<String> B) {
     if (object.Equals(A,null)) 
         throw new ILArgumentException("neq: input argurment A must not be null!");
     if (object.Equals(B,null)) 
         throw new ILArgumentException("neq: input argurment B must not be null!");
     if (!A.Dimensions.IsSameShape(B.Dimensions)) 
         throw new ILArgumentException("input arrays must have the same size"); 
     if (A.IsEmpty || B.IsEmpty)
         return ILLogicalArray.empty(A.Dimensions); 
     ILLogicalArray ret = null; 
     string scalarValue; 
     ILDimension retDim = null; 
     byte[] retArr = null; 
     if (A.IsScalar) {
         if (B.IsScalar) {
             retDim = new ILDimension(1,1); 
             ret = new ILLogicalArray(new byte[1]{(A.GetValue(0) != B.GetValue(0))?(byte)1:(byte)0},1,1); 
         } else {
             retDim = B.Dimensions; 
             int len = B.Dimensions.NumberOfElements; 
             retArr = new byte[len]; 
             scalarValue = A.GetValue(0); 
             for (int i = 0; i < len; i++) {
                 if (scalarValue != B.GetValue(i)) {
                     retArr[i] = 1; 
                 }
             }
         }
     } else {
         retDim = A.Dimensions; 
         if (B.IsScalar) {
             int len = A.Dimensions.NumberOfElements; 
             retArr = new byte[len]; 
             scalarValue = B.GetValue(0); 
             for (int i = 0; i < len; i++) {
                 if (scalarValue != A.GetValue(i))
                     retArr[i] = 1; 
             }
         } else {
             if (!A.Dimensions.IsSameSize(B.Dimensions))
                 throw new ILDimensionMismatchException("neq: size of arrays must match!");
             int len = A.Dimensions.NumberOfElements; 
             retArr = new byte[len]; 
             for (int i = 0; i < len; i++) {
                 if (A.GetValue(i) != B.GetValue(i))
                     retArr[i] = 1; 
             }
         }
     }
     return new ILLogicalArray(retArr,retDim); 
 }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:61,代码来源:ILMath_Logical.cs


注:本文中的ILArray.GetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。