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


C# ILArray.getBaseIndex方法代码示例

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


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

示例1: sqrt

        /// <summary>
        /// Sinus of array elements 
        /// </summary>
        /// <param name="A">input array</param>
        /// <returns>Sinus of elements from input array</returns>
        /// <remarks><para>If the input array is empty, an empty array will be returned.</para>
        /// <para>The array returned will be a dense array.</para></remarks>
        public static  ILArray<double>  sqrt ( ILArray<double> A) {
            if (A.IsEmpty)
                return  ILArray<double> .empty(A.Dimensions); 
            ILDimension inDim = A.Dimensions;
            double [] retDblArr;
            // build ILDimension    
            int newLength = inDim.NumberOfElements;
            //retDblArr = new  double [newLength];
            retDblArr = ILMemoryPool.Pool.New< double > (newLength); 
            int leadDim = 0;
            int leadDimLen = inDim [0];
            if (A.IsReference) {
                #region Reference storage
                // walk along the longest dimension (for performance reasons)
                for (int i = 1; i < inDim.NumberOfDimensions; i++) {
                    if (leadDimLen < inDim [i]) {
                        leadDimLen = inDim [i];
                        leadDim = i;
                    }
                }
                ILIndexOffset idxOffset = A.m_indexOffset;
                int incOut = inDim.SequentialIndexDistance ( leadDim );
                System.Diagnostics.Debug.Assert(!A.IsVector,"Reference arrays of vector size should not exist!"); 
                if (A.IsMatrix) {
                    #region Matrix
                    ////////////////////////////   MATRIX   ////////////////////
                    int secDim = ( leadDim + 1 ) % 2;
                    unsafe {
                        fixed (int* leadDimStart = idxOffset [leadDim],
                                secDimStart = idxOffset [secDim]) {
                            fixed ( double * pOutArr = retDblArr)
                            fixed ( double * pInArr = A.m_data) {
                                double * tmpOut = pOutArr;
                                double * tmpIn = pInArr;
                                double * 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) {   // HC00
                                       
                                        *tmpOut =  Math.Sqrt ( *( tmpIn + *leadDimIdx++ ) )  ;
                                        tmpOut += incOut;
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                } else {
                    #region arbitrary size
                    unsafe {
                        int [] curPosition = new int [A.Dimensions.NumberOfDimensions];
                        fixed (int* leadDimStart = idxOffset [leadDim]) {
                            fixed ( double * pOutArr = retDblArr)
                            fixed ( double * pInArr = A.m_data) {
                                double * tmpOut = pOutArr;
                                double * tmpOutEnd = tmpOut + retDblArr.Length - 1;
                                double * tmpIn = pInArr + A.getBaseIndex ( 0, 0 );
                                tmpIn -= idxOffset [leadDim, 0];     // if the first index of leaddim is not 0, it will be added later anyway. so we subtract it here
                                int* leadDimIdx = leadDimStart;
                                int* leadDimEnd = leadDimStart + leadDimLen;
                                int dimLen = curPosition.Length;
                                int d, curD, count = retDblArr.Length / leadDimLen;
                                // start at first element
                                while (count --> 0) {
                                    leadDimIdx = leadDimStart;
                                    while (leadDimIdx < leadDimEnd) {  //HC01
                                       
                                        *tmpOut =  Math.Sqrt ( *( tmpIn + *leadDimIdx++ ) )  ;
                                        tmpOut += incOut;
                                    }
                                    if (tmpOut > tmpOutEnd)
                                        tmpOut -= retDblArr.Length - 1;

                                    // increment higher dimensions 
                                    d = 1;
                                    while (d < dimLen) {
                                        curD = ( d + leadDim ) % dimLen;
                                        tmpIn -= idxOffset [curD, curPosition [curD]];
                                        curPosition [curD]++;
                                        if (curPosition [curD] < idxOffset [curD].Length) {
                                            tmpIn += idxOffset [curD, curPosition [curD]];
                                            break;
                                        }
                                        curPosition [curD] = 0;
                                        tmpIn += idxOffset [curD, 0];
                                        d++;
//.........这里部分代码省略.........
开发者ID:wdxa,项目名称:ILNumerics,代码行数:101,代码来源:sqrt.cs

示例2: minall

 /// <summary>
 /// minimum of all elements of array A
 /// </summary>
 /// <param name="A">n-dim array</param>
 /// <returns><para>scalar minimum 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.min(ILArray&lt;double&gt;)"/>
 public static  ILArray<float> minall ( ILArray<float> A) {
     if (object.Equals(A,null))
         throw new ILArgumentException("minall: argument must not be null!");
     if (A.IsEmpty) {
         return  ILArray<float> .empty(A.Dimensions); 
     } 
     float retArr =  float .MaxValue;  
     if (A.m_indexOffset == null) {
         unsafe {
             fixed ( float * inArrStart = A.m_data) {
                 float * inArrWalk = inArrStart; 
                 float * inArrEnd = inArrStart + A.Dimensions.NumberOfElements; 
                 while (inArrWalk < inArrEnd) {
                     if (retArr > *inArrWalk)
                         retArr = *inArrWalk;
                     inArrWalk++;
                 }
             }
         }
     } else {
         float tmp; 
         unsafe {
             fixed ( float * inArrStart = A.m_data)  {
                 for (int i = A.Dimensions.NumberOfElements; i -->0;) {
                     tmp = *(inArrStart + A.getBaseIndex(i));
                     if (retArr > tmp)
                         retArr = tmp; 
                 }
             }
         }
     }
     return new  ILArray<float> (new  float [1]{retArr},1,1);
 }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:41,代码来源:minall.cs

示例3: 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

示例4: sub2ind

 /// <summary>
 /// convert subscript indices to sequential index
 /// </summary>
 /// <param name="A">input array</param>
 /// <param name="subscripts"></param>
 /// <returns>sequential index for subscript indices</returns>
 /// <remarks>the function returns the sequential index i into A referencing the same element as would be referenced by the subscript indices. <br />This is an alias for A.getBaseIndex(in[])</remarks>
 public static int sub2ind(ILArray<byte>     A,int [] subscripts) {              
     if (object.Equals(A,null) || A.IsEmpty || subscripts == null || subscripts.Length == 0) 
         throw new ILArgumentException("sub2ind: both A and subscripts must be non-empty!");
     return A.getBaseIndex(subscripts);  
 }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:12,代码来源:sub2ind.cs

示例5: maxall

 /// <summary>
 /// maximum for all elements of A
 /// </summary>
 /// <param name="A">n-dim array</param>
 /// <returns><para>scalar maximum of all elements for 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.max(ILArray&lt;double&gt;)"/>
 public static  ILArray<byte> maxall ( ILArray<byte> A) {
     if (object.Equals(A,null))
         throw new ILArgumentException("maxall: argument must not be null!");
     if (A.IsEmpty) {
         return  ILArray<byte> .empty(0,0); 
     } 
     byte retArr =  byte .MinValue;  
     if (A.m_indexOffset == null) {
         unsafe {
             fixed ( byte * inArrStart = A.m_data) {
                 byte * inArrWalk = inArrStart; 
                 byte * inArrEnd = inArrStart + A.Dimensions.NumberOfElements; 
                 while (inArrWalk < inArrEnd) {
                     if (retArr < *inArrWalk)
                         retArr = *inArrWalk;
                     inArrWalk++;
                 }
             }
         }
     } else {
         byte tmp; 
         unsafe {
             fixed ( byte * inArrStart = A.m_data)  {
                 for (int i = A.Dimensions.NumberOfElements; i -->0;) {
                     tmp = *(inArrStart + A.getBaseIndex(i));
                     if (retArr < tmp)
                         retArr = tmp; 
                 }
             }
         }
     }
     return new  ILArray<byte> (new  byte [1]{retArr},1,1);
 }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:41,代码来源:maxall.cs

示例6: LogicalUnaryByteOperator

        /// <summary>
        /// Applys the function (delegate) given to all elements of the storage
        /// </summary>
        /// <param name="inArray">storage array to be apply the function to</param>
        /// <param name="operation">operation to apply to the elements of inArray. This
        /// acts like a function pointer.</param>
        /// <returns>new <![CDATA[ILArray<>]]> with result</returns>
        /// <remarks> the values of inArray will not be altered.</remarks>
        private static ILLogicalArray  LogicalUnaryByteOperator (ILArray< byte > inArray,
            ILLogicalFunctionByte operation) {
            ILDimension inDim = inArray.Dimensions;
            byte [] retByteArr;
            // build ILDimension
            int newLength = inDim.NumberOfElements;
            retByteArr = new byte [newLength];
            int leadDim = 0;
            int leadDimLen = inDim [0];
            if (inArray.IsReference) {
                #region Reference storage
                // walk along the longest dimension (for performance reasons)
                for (int i = 1; i < inDim.NumberOfDimensions; i++) {
                    if (leadDimLen < inDim [i]) {
                        leadDimLen = inDim [i];
                        leadDim = i;
                    }
                }
                ILIndexOffset idxOffset = inArray.m_indexOffset;
                int incOut = inDim.SequentialIndexDistance ( leadDim );
                // ========================  REFERENCE double Storage ===========
                if (inArray.IsMatrix) {
                    #region Matrix
                    ////////////////////////////   MATRIX   ////////////////////
                    int secDim = ( leadDim + 1 ) % 2;
                    unsafe {
                        fixed (int* leadDimStart = idxOffset [leadDim],
                                secDimStart = idxOffset [secDim]) {
                            fixed (byte* pOutArr = retByteArr) {
                                fixed ( byte * pInArr = inArray.m_data) {
                                    byte* tmpOut = pOutArr;
                                    byte * tmpIn = pInArr;
                                    byte* tmpOutEnd = pOutArr + inDim.NumberOfElements - 1;
                                    int* secDimEnd = secDimStart + idxOffset [secDim].Length;
                                    int* secDimIdx = secDimStart;
                                    int* leadDimIdx = leadDimStart;
                                    int* leadDimEnd = leadDimStart + idxOffset [secDim].Length; ;
                                    while (secDimIdx < secDimEnd) {
                                        tmpIn = pInArr + *secDimIdx++;
                                        leadDimIdx = leadDimStart;
                                        while (leadDimIdx < leadDimEnd) {
                                            *tmpOut = operation ( *( tmpIn + *leadDimIdx++ ) );
                                            tmpOut += incOut;
                                        }
                                        if (tmpOut > tmpOutEnd)
                                            tmpOut = pOutArr + ( tmpOutEnd - tmpOut );
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                } else if (inArray.IsVector) {
                    #region Vector
                    ////////////////////////////   VECTOR   ///////////////////////
                    unsafe {
                        fixed (int* leadDimStart = idxOffset [leadDim]) {
                            fixed (byte* pOutArr = retByteArr) {
                                fixed ( byte * pInArr = inArray.m_data) {
                                    byte* tmpOut = pOutArr;
                                    byte * tmpIn = pInArr + idxOffset [( ( leadDim + 1 ) % 2 ), 0];
                                    int* leadDimIdx = leadDimStart;
                                    int* leadDimEnd = leadDimStart + leadDimLen;
                                    // start at first element
                                    while (leadDimIdx < leadDimEnd)
                                        *tmpOut++ = operation ( *( tmpIn + *leadDimIdx++ ) );
                                }
                            }
                        }
                    }
                    #endregion
                } else {
                    /////////////////////////////   ARBITRARY DIMENSIONS //////////
                    #region arbitrary size
                    unsafe {
                        int [] curPosition = new int [inArray.Dimensions.NumberOfDimensions];
                        fixed (int* leadDimStart = idxOffset [leadDim]) {
                            fixed (byte* pOutArr = retByteArr) {
                                fixed ( byte * pInArr = inArray.m_data) {
                                    byte* tmpOut = pOutArr;
                                    byte* tmpOutEnd = tmpOut + retByteArr.Length;
                                    // init lesezeiger: add alle Dimensionen mit 0 (auer leadDim)
                                    byte * tmpIn = pInArr + inArray.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) {
//.........这里部分代码省略.........
开发者ID:wdxa,项目名称:ILNumerics,代码行数:101,代码来源:ILMath_Logical.cs

示例7: invert

 /// <summary>
 /// invert elements of A, return result as out argument
 /// </summary>
 /// <param name="A"></param>
 /// <param name="outArray"></param>
 public static void  invert ( ILArray<complex> A,  ILArray<complex> outArray) {
     #region array + array
     ILDimension inDim = A.Dimensions;
     if (!inDim.IsSameSize ( outArray.Dimensions ))
         throw new ILDimensionMismatchException ();
     int leadDim = 0, leadDimLen = inDim [0];
     // walk along the longest dimension (for performance reasons)
     for (int i = 1; i < inDim.NumberOfDimensions; i++) {
         if (leadDimLen < inDim [i]) {
             leadDimLen = inDim [i];
             leadDim = i;
         }
     }
     unsafe {
         fixed ( complex * inA1 = A.m_data) 
         fixed ( complex * inA2 = outArray.m_data) {
             complex * pInA1 = inA1; 
             complex * pInA2 = inA2;
             int c = 0; 
             complex * outEnd = inA2 + outArray.m_data.Length;
             if (A.IsReference) { 
                 while (pInA2 < outEnd) {  //HC07
                     
                     *pInA2++ =   ( *(pInA1 + A.getBaseIndex(c++))  *(-1.0) );
                 }
             } else {
                 while (pInA2 < outEnd) {  //HC11
                      
                     *pInA2++ =   ( *pInA1++ /*HC:*/ *(-1.0) );
                 }
             }
         }
         #endregion array + array
     }
     return;
 }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:41,代码来源:Invert.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: Test_tmpPerfCount

        public void Test_tmpPerfCount() {
            double [] data = new double[1000*1000*10];
            ILArray<double> A = new ILArray<double>(data, 1000, 1000, 10);
            ILPerformer p = new ILPerformer(); 
                        
            p.Tic();
            for (int i = 0; i < 10000000; i++) {
                A.getBaseIndex(i); 
            }
            p.Toc();
            Info("1000x1000x10: dense GetBaseIndex needed: " + p.Duration + " ms");

            ILIterator<double> it = A.CreateIterator();
            p.Tic();
            do {
                it.Increment(); 
            } while(!it.IsAtStart());
            p.Toc();
            Info("1000x1000x10: dense Iterator needed: " + p.Duration + " ms");
            
            A = (ILArray<double>)A[1,""];
            p.Tic();
            for (int i = 0; i < 10000000; i++) {
                A.getBaseIndex(i);
            }
            p.Toc();
            Info("1000x1000x10: ref. GetBaseIndex needed: " + p.Duration + " ms");

            it = A.CreateIterator();
            p.Tic();
            do {
                it.Increment();
            } while (!it.IsAtStart());
            p.Toc();
            Info("1000x1000x10: ref Iterator needed: " + p.Duration + " ms");
            p.Tic(); 
        }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:37,代码来源:TESTILStorage.cs

示例10: FcomplexOperatorFcomplexFcomplex

        /// <summary>
        /// operate on elements of both storages by the given function -> relational operations 
        /// </summary>
        /// <param name="inArray1">First storage array</param>
        /// <param name="inArray2">Second storage array</param>
        /// <param name="operation">operation to apply to the elements of inArray. This
        /// acts like a function pointer.</param>
        /// <returns><![CDATA[  ILArray<fcomplex> ]]> with result of operation for corresponding 
        /// elements of both arrays.</returns>
        /// <remarks>The values of inArray1 nor inArray2 will not be altered.The dimensions 
        /// of both arrays must match.</remarks>
        private static  ILArray<fcomplex>  FcomplexOperatorFcomplexFcomplex ( ILArray<fcomplex> inArray1, ILArray<fcomplex> inArray2,
            ILFcomplexFunctionFcomplexFcomplex operation) {
            ILDimension inDim = inArray1.Dimensions;
            if (!inDim.IsSameSize ( inArray2.Dimensions ))
                throw new ILDimensionMismatchException ();
            fcomplex [] retSystemArr;
            // build ILDimension
            int newLength = inDim.NumberOfElements;
            retSystemArr = new  fcomplex [newLength];
            int leadDim = 0;
            int leadDimLen = inDim [0];
            if (inArray1.IsReference || inArray2.IsReference) {
                // this will most probably be not very fast, but .... :|
                #region Reference storage
                // walk along the longest dimension (for performance reasons)
                for (int i = 1; i < inDim.NumberOfDimensions; i++) {
                    if (leadDimLen < inDim [i]) {
                        leadDimLen = inDim [i];
                        leadDim = i;
                    }
                }
                unsafe {
                    fixed ( fcomplex * pOutArr = retSystemArr)
                    fixed ( fcomplex * inA1 = inArray1.m_data) 
                    fixed ( fcomplex * inA2 = inArray2.m_data) {
                        fcomplex * pInA1 = inA1; 
                        fcomplex * pInA2 = inA2;
                        int c = 0; 
                        fcomplex * poutarr = pOutArr;
                        fcomplex * outEnd = poutarr + newLength;
                        if (inArray1.IsReference && !inArray2.IsReference)
                            while (poutarr < outEnd) {
                                *poutarr++ = operation ( *(pInA1 + inArray1.getBaseIndex(c++)), *pInA2++);
                            }
                        else if (!inArray1.IsReference && inArray2.IsReference)
                            while (poutarr < outEnd) {
                                *poutarr++ = operation ( *pInA1++, *(pInA2 + inArray2.getBaseIndex(c++)));
                            }
                        else if (!inArray1.IsReference && !inArray2.IsReference)
                            while (poutarr < outEnd) {
                                *poutarr++ = operation ( *pInA1++, *pInA2++);
                            }
                        else if (inArray1.IsReference && inArray2.IsReference)
                            if (inArray1.Dimensions.NumberOfDimensions < 3 && inArray2.Dimensions.NumberOfDimensions < 3) {
                                fixed (int * pA1idx0 = inArray1.m_indexOffset[0])
                                fixed (int * pA1idx1 = inArray1.m_indexOffset[1])
                                fixed (int * pA2idx0 = inArray2.m_indexOffset[0])
                                fixed (int * pA2idx1 = inArray2.m_indexOffset[1]) {
                                    int r = 0, rLen = inArray1.m_dimensions[0];
                                    int        cLen = inArray1.m_dimensions[1]; 
                                    while (poutarr < outEnd) {
                                        *poutarr++ = operation ( *(pInA1 + *(pA1idx0 + r) + *(pA1idx1 + c)), *(pInA2+ *(pA2idx0 + r) + *(pA2idx1 + c)));
                                        if (++r == rLen) {
                                            r = 0; 
                                            c++; 
                                        }
                                    }
                                }
                            } else {
                                 while (poutarr < outEnd) {
                                    *poutarr++ = operation ( *(pInA1 + inArray1.getBaseIndex(c)), *(pInA2+inArray2.getBaseIndex(c++)));
                                }
                           }
                    }
                }
                // ==============================================================
                #endregion
            } else {
                // physical -> pointer arithmetic
                #region physical storage
                unsafe {
                    fixed ( fcomplex * pInArr1 = inArray1.m_data)
                    fixed ( fcomplex * pInArr2 = inArray2.m_data)
                    fixed ( fcomplex * pOutArr = retSystemArr) {
                        fcomplex * poutarr = pOutArr;
                        fcomplex * poutend = poutarr + newLength;
                        fcomplex * pIn1 = pInArr1;
                        fcomplex * pIn2 = pInArr2;
                        while (poutarr < poutend)
                            *poutarr++ = operation ( *pIn1++, *pIn2++ );

                    }
                }
                #endregion
            }
            return new  ILArray<fcomplex> ( retSystemArr, inDim.ToIntArray () );
        }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:98,代码来源:ILMath_Walker.cs

示例11: FloatOperatorFcomplex

        /// <summary>
        /// Applys the function (delegate) given to all elements of the storage
        /// </summary>
        /// <param name="inArray">storage array to apply the function to</param>
        /// <param name="operation">operation to apply to the elements of inArray. This
        /// acts like a function pointer.</param>
        /// <returns>new <![CDATA[  ILArray<float> ]]> with result of operation</returns>
        /// <remarks> the values of inArray will not be altered.</remarks>
        private static  ILArray<float>  FloatOperatorFcomplex ( ILArray<fcomplex> inArray,
            ILFloatFunctionFcomplex operation) {
            ILDimension inDim = inArray.Dimensions;
            float [] retDblArr;
            // build ILDimension
            int newLength = inDim.NumberOfElements;
            retDblArr = new  float [newLength];
            int leadDim = 0;
            int leadDimLen = inDim [0];
            if (inArray.IsReference) {
                #region Reference storage
                // walk along the longest dimension (for performance reasons)
                for (int i = 1; i < inDim.NumberOfDimensions; i++) {
                    if (leadDimLen < inDim [i]) {
                        leadDimLen = inDim [i];
                        leadDim = i;
                    }
                }
                ILIndexOffset idxOffset = inArray.m_indexOffset;
                int incOut = inDim.SequentialIndexDistance ( leadDim );
                // ========================  REFERENCE double Storage ===========
                System.Diagnostics.Debug.Assert(!inArray.IsVector,"Reference arrays of vector size should not exist!"); 
                if (inArray.IsMatrix) {
                    #region Matrix
                    ////////////////////////////   MATRIX   ////////////////////
                    int secDim = ( leadDim + 1 ) % 2;
                    unsafe {
                        fixed (int* leadDimStart = idxOffset [leadDim],
                                secDimStart = idxOffset [secDim]) {
                            fixed ( float * pOutArr = retDblArr)
                            fixed ( fcomplex * pInArr = inArray.m_data) {
                                float * tmpOut = pOutArr;
                                fcomplex * tmpIn = pInArr;
                                float * 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 = operation ( *( tmpIn + *leadDimIdx++ ) );
                                        tmpOut += incOut;
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                } else {
                    /////////////////////////////   ARBITRARY DIMENSIONS //////////
                    #region arbitrary size
                    unsafe {
                        int [] curPosition = new int [inArray.Dimensions.NumberOfDimensions];
                        fixed (int* leadDimStart = idxOffset [leadDim]) {
                            fixed ( float * pOutArr = retDblArr)
                            fixed ( fcomplex * pInArr = inArray.m_data) {
                                float * tmpOut = pOutArr;
                                float * tmpOutEnd = tmpOut + retDblArr.Length;
                                // init lesezeiger: add alle Dimensionen mit 0 (auer leadDim)
                                fcomplex * tmpIn = pInArr + inArray.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 = operation ( *( tmpIn + *leadDimIdx++ ) );
                                        tmpOut += incOut;
                                    }
                                    if (tmpOut > tmpOutEnd)
                                        tmpOut = pOutArr + ( tmpOutEnd - tmpOut );

                                    // increment higher dimensions 
                                    d = 1;
                                    while (d < dimLen) {
                                        curD = ( d + leadDim ) % dimLen;
                                        tmpIn -= idxOffset [curD, curPosition [curD]];
                                        curPosition [curD]++;
                                        if (curPosition [curD] < idxOffset [curD].Length) {
                                            tmpIn += idxOffset [curD, curPosition [curD]];
                                            break;
                                        }
                                        curPosition [curD] = 0;
                                        tmpIn += idxOffset [curD, 0];
                                        d++;
//.........这里部分代码省略.........
开发者ID:wdxa,项目名称:ILNumerics,代码行数:101,代码来源:ILMath_Walker.cs

示例12: solveLowerTriangularSystem

 /// <summary>
 /// Solve system of linear equations A*x = b, with A beeing a lower triangular matrix
 /// </summary>
 /// <param name="A">input matrix of Size [n x n], must be lower triangular. No check is made for that!</param>
 /// <param name="B">solution vector. Size [n x 1]</param>
 /// <param name="singularityDetect">output: this value gives the row of A, where a singularity has been detected (if any). If A is not singular, this will be a negative value.</param>
 /// <returns>Solution x solving A * x = b.</returns>
 /// <remarks><para>The solution will be determined via forward substitution</para>
 /// <para>Make sure, A and b are of correct size, since no checks are made for that!</para>
 /// <para>This function is used by ILMath.linsolve. There should be rare need for you to call this function directly.</para>
 /// <para>Elements of A above the main diagonal will not be accessed.</para>
 /// <para>If A has been found to be singular, the array returned will contain NaN values for corresponding elements!</para></remarks>
 internal static  ILArray<fcomplex> solveLowerTriangularSystem ( ILArray<fcomplex> A,  ILArray<fcomplex> B, ref int singularityDetect) {
     System.Diagnostics.Debug.Assert(B.Dimensions[1] >= 0); 
     System.Diagnostics.Debug.Assert(B.Dimensions[0] == A.Dimensions[1]); 
     System.Diagnostics.Debug.Assert(A.Dimensions[0] == A.Dimensions[1]); 
     singularityDetect = -1; 
     int n = A.Dimensions[0]; 
     int m = B.Dimensions[1]; 
     int spacingA0, spacingA1, info = 0; 
     char transA; 
     ILArray<fcomplex> ret = ( ILArray<fcomplex> )B.Clone(); 
     fcomplex [] retArr = ret.m_data;  
     if (isSuitableForLapack(A,out spacingA0,out spacingA1,out transA)) {
         // solve using Lapack
         unsafe {
             fixed ( fcomplex * ptrA = A.m_data) 
             fixed ( fcomplex * ptrB = ret.m_data) {
                 fcomplex * pA = ptrA + A.getBaseIndex(0); 
                 Lapack.ctrtrs ((transA == 'T')? 'U':'L',transA,'N',A.Dimensions[0],ret.Dimensions[1],(IntPtr)pA,spacingA1,(IntPtr)ptrB,n,ref info);
                 if (info < 0) 
                     throw new ILArgumentException ("linsolve: error inside Lapack function ?trtrs for argument: " + (-info));
                 if (info > 0) {
                     singularityDetect = info-1;
                     retArr = ret.m_data; 
                     for (spacingA0 = 0; spacingA0 < ret.Dimensions[1]; spacingA0++) {
                         info = spacingA0 * n + singularityDetect; 
                         for (spacingA1 = singularityDetect; spacingA1 < n; spacingA1++) {
                             retArr[info++] =  new fcomplex(float.NaN,float.NaN) ;     
                         }
                     }
                 } else {
                     singularityDetect = -1; 
                 }
             }
         }
         return ret; 
     }
     // must do it manually.... 
     System.Diagnostics.Debug.Assert(A.IsReference); 
     int[] Adim0 = A.m_indexOffset[0]; 
     int[] Adim1 = A.m_indexOffset[1];    
     fcomplex diagVal =  new fcomplex(0.0f,0.0f) ;
     fcomplex tmpVal;
     for (int b = 0; b < m; b++) {
         for (int r = 0; r < n; r++) {
             tmpVal =  new fcomplex(0.0f,0.0f) ; 
             diagVal = A.GetValue(r,r); 
             if (diagVal ==  new fcomplex(0.0f,0.0f) ) {
                 singularityDetect = r; 
                 for (; r < n; r++)
                     retArr[r + b * n] =  new fcomplex(float.PositiveInfinity,float.PositiveInfinity) ; 
             } else {
                 for (int c = 0; c < r; c++) {
                     tmpVal +=  A.m_data[Adim0[r] + Adim1[c]] * retArr[c + b * n]; 
                 }
                 retArr[r + b * n] = (retArr[r + b * n] - tmpVal) / diagVal; 
             }
         }
     }
     ret = new  ILArray<fcomplex> (retArr,n,m); 
     return ret; 
 }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:73,代码来源:slash.cs


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