Ejemplo n.º 1
0
        /// <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<complex> ]]> with result of operation</returns>
        /// <remarks> the values of inArray will not be altered.</remarks>
        private static ILArray <complex> ComplexOperatorComplex(ILArray <complex> inArray,
                                                                ILComplexFunctionComplex operation)
        {
            ILDimension inDim = inArray.Dimensions;

            complex [] retDblArr;
            // build ILDimension
            int newLength = inDim.NumberOfElements;

            retDblArr = new  complex [newLength];
            int leadDimLen = inDim [0];

            unsafe
            {
                fixed(complex *pOutArr = retDblArr)
                fixed(complex * pInArr = inArray.m_data)
                {
                    complex *lastElement = pOutArr + retDblArr.Length;
                    complex *tmpOut      = pOutArr;
                    complex *tmpIn       = pInArr;

                    while (tmpOut < lastElement)
                    {
                        *tmpOut++ = operation(*tmpIn++);
                    }
                }
            }

            return(new  ILArray <complex> (retDblArr, inDim.ToIntArray()));
        }
Ejemplo n.º 2
0
        /// <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<complex> ]]> with result of operation</returns>
        /// <remarks> the values of inArray will not be altered.</remarks>
        private static  ILArray<complex>  ComplexOperatorComplex ( ILArray<complex> inArray,
            ILComplexFunctionComplex operation) {
            ILDimension inDim = inArray.Dimensions;
            complex [] retDblArr;
            // build ILDimension
            int newLength = inDim.NumberOfElements;
            retDblArr = new  complex [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 ( complex * pOutArr = retDblArr)
                            fixed ( complex * pInArr = inArray.m_data) {
                                complex * tmpOut = pOutArr;
                                complex * tmpIn = pInArr;
                                complex * 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 ( complex * pOutArr = retDblArr)
                            fixed ( complex * pInArr = inArray.m_data) {
                                complex * tmpOut = pOutArr;
                                complex * tmpOutEnd = tmpOut + retDblArr.Length;
                                // init lesezeiger: add alle Dimensionen mit 0 (auer leadDim)
                                complex * 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++;
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                }
                // ==============================================================
                #endregion
            } else {
                // physical -> pointer arithmetic
                #region physical storage
                unsafe {
                    fixed ( complex * pOutArr = retDblArr)
                    fixed ( complex * pInArr = inArray.m_data) {
                        complex * lastElement = pOutArr + retDblArr.Length;
                        complex * tmpOut = pOutArr;
                        complex * tmpIn = pInArr;
                        while (tmpOut < lastElement)
                            *tmpOut++ = operation ( *tmpIn++ );
                    }
                }
                #endregion
            }
            return new  ILArray<complex> ( retDblArr, inDim.ToIntArray () );
        }
Ejemplo n.º 3
0
        /// <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<complex> ]]> with result of operation</returns>
        /// <remarks> the values of inArray will not be altered.</remarks>
        private static  ILArray<complex>  ComplexOperatorComplex ( ILArray<complex> inArray,
            ILComplexFunctionComplex operation) {
            ILDimension inDim = inArray.Dimensions;
            complex [] retDblArr;
            // build ILDimension
            int newLength = inDim.NumberOfElements;
            retDblArr = new  complex [newLength];
            int leadDimLen = inDim [0];

            unsafe
            {
                fixed ( complex * pOutArr = retDblArr)
                fixed ( complex * pInArr = inArray.m_data) {
                    complex * lastElement = pOutArr + retDblArr.Length;
                    complex * tmpOut = pOutArr;
                    complex * tmpIn = pInArr;
                    while (tmpOut < lastElement)
                        *tmpOut++ = operation ( *tmpIn++ );
                }
            }

            return new  ILArray<complex> ( retDblArr, inDim.ToIntArray () );
        }