コード例 #1
0
ファイル: ILMath_Walker.cs プロジェクト: wdxa/ILNumerics
        /*!HC:TYPELIST:
<hycalper>
    <type>
        <source	locate="after">
        inArr1
        </source>
        <destination>byte</destination>
        <destination>char</destination>
        <destination>complex</destination>
        <destination>fcomplex</destination>
        <destination>float</destination>
        <destination>Int16</destination>
        <destination>Int32</destination>
        <destination>Int64</destination>
        <destination>UInt16</destination>
        <destination>UInt32</destination>
        <destination>UInt64</destination>
        <destination>complex</destination>
        <destination>fcomplex</destination>
        <destination>double</destination>
        <destination>float</destination>
    </type>
    <type>
        <source	locate="after">
            inCls1
        </source>
        <destination><![CDATA[ILArray<byte>]]></destination>
        <destination><![CDATA[ILArray<char>]]></destination>
        <destination><![CDATA[ILArray<complex>]]></destination>
        <destination><![CDATA[ILArray<fcomplex>]]></destination>
        <destination><![CDATA[ILArray<float>]]></destination>
        <destination><![CDATA[ILArray<Int16>]]></destination>
        <destination><![CDATA[ILArray<Int32>]]></destination>
        <destination><![CDATA[ILArray<Int64>]]></destination>
        <destination><![CDATA[ILArray<UInt16>]]></destination>
        <destination><![CDATA[ILArray<UInt32>]]></destination>
        <destination><![CDATA[ILArray<UInt64>]]></destination>
        <destination><![CDATA[ILArray<complex>]]></destination>
        <destination><![CDATA[ILArray<fcomplex>]]></destination>
        <destination><![CDATA[ILArray<double>]]></destination>
        <destination><![CDATA[ILArray<float>]]></destination>
    </type>
    <type>
        <source	locate="after">
            outCls1
        </source>
        <destination><![CDATA[ILArray<byte>]]></destination>
        <destination><![CDATA[ILArray<char>]]></destination>
        <destination><![CDATA[ILArray<complex>]]></destination>
        <destination><![CDATA[ILArray<fcomplex>]]></destination>
        <destination><![CDATA[ILArray<float>]]></destination>
        <destination><![CDATA[ILArray<Int16>]]></destination>
        <destination><![CDATA[ILArray<Int32>]]></destination>
        <destination><![CDATA[ILArray<Int64>]]></destination>
        <destination><![CDATA[ILArray<UInt16>]]></destination>
        <destination><![CDATA[ILArray<UInt32>]]></destination>
        <destination><![CDATA[ILArray<UInt64>]]></destination>
        <destination><![CDATA[ILArray<double>]]></destination>
        <destination><![CDATA[ILArray<float>]]></destination>
        <destination><![CDATA[ILArray<complex>]]></destination>
        <destination><![CDATA[ILArray<fcomplex>]]></destination>
    </type>
    <type>
        <source	locate="after">
            outArr1
        </source>
        <destination>byte</destination>
        <destination>char</destination>
        <destination>complex</destination>
        <destination>fcomplex</destination>
        <destination>float</destination>
        <destination>Int16</destination>
        <destination>Int32</destination>
        <destination>Int64</destination>
        <destination>UInt16</destination>
        <destination>UInt32</destination>
        <destination>UInt64</destination>
        <destination>double</destination>
        <destination>float</destination>
        <destination>complex</destination>
        <destination>fcomplex</destination>
    </type>
    <type>
        <source	locate="after">
            delegate_unary
        </source>
        <destination>ILByteFunctionByte</destination>
        <destination>ILCharFunctionChar</destination>
        <destination>ILComplexFunctionComplex</destination>
        <destination>ILFcomplexFunctionFcomplex</destination>
        <destination>ILFloatFunctionFloat</destination>
        <destination>ILInt16FunctionInt16</destination>
        <destination>ILInt32FunctionInt32</destination>
        <destination>ILInt64FunctionInt64</destination>
        <destination>ILUInt16FunctionUInt16</destination>
        <destination>ILUInt32FunctionUInt32</destination>
        <destination>ILUInt64FunctionUInt64</destination>
        <destination>ILDoubleFunctionComplex</destination>
        <destination>ILFloatFunctionFcomplex</destination>
        <destination>ILComplexFunctionDouble</destination>
        <destination>ILFcomplexFunctionFloat</destination>
    </type>
    <type>
        <source	locate="after">
            unaryop
        </source>
        <destination>ByteOperatorByte</destination>
        <destination>CharOperatorChar</destination>
        <destination>ComplexOperatorComplex</destination>
        <destination>FcomplexOperatorFcomplex</destination>
        <destination>FloatOperatorFloat</destination>
        <destination>Int16OperatorInt16</destination>
        <destination>Int32OperatorInt32</destination>
        <destination>Int64OperatorInt64</destination>
        <destination>UInt16OperatorUInt16</destination>
        <destination>UInt32OperatorUInt32</destination>
        <destination>UInt64OperatorUInt64</destination>
        <destination>DoubleOperatorComplex</destination>
        <destination>FloatOperatorFcomplex</destination>
        <destination>ComplexOperatorDouble</destination>
        <destination>FcomplexOperatorFloat</destination>
    </type>
</hycalper>
*/
        /// <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[ /*!HC:outCls1*/ ILArray<double> ]]> with result of operation</returns>
        /// <remarks> the values of inArray will not be altered.</remarks>
        private static /*!HC:outCls1*/ ILArray<double> /*!HC:unaryop*/ DoubleOperatorDouble (/*!HC:inCls1*/ ILArray<double> inArray,
            /*!HC:delegate_unary*/ ILDoubleFunctionDouble operation) {
            ILDimension inDim = inArray.Dimensions;
            /*!HC:outArr1*/ double [] retDblArr;
            // build ILDimension
            int newLength = inDim.NumberOfElements;
            retDblArr = new /*!HC:outArr1*/ double [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 (/*!HC:outArr1*/ double * pOutArr = retDblArr)
                            fixed (/*!HC:inArr1*/ double * pInArr = inArray.m_data) {
                                /*!HC:outArr1*/ double * tmpOut = pOutArr;
                                /*!HC:inArr1*/ double * tmpIn = pInArr;
                                /*!HC:outArr1*/ 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) {
                                        *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 (/*!HC:outArr1*/ double * pOutArr = retDblArr)
                            fixed (/*!HC:inArr1*/ double * pInArr = inArray.m_data) {
                                /*!HC:outArr1*/ double * tmpOut = pOutArr;
                                /*!HC:outArr1*/ double * tmpOutEnd = tmpOut + retDblArr.Length;
                                // init lesezeiger: add alle Dimensionen mit 0 (auer leadDim)
                                /*!HC:inArr1*/ double * 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 (/*!HC:outArr1*/ double * pOutArr = retDblArr)
                    fixed (/*!HC:inArr1*/ double * pInArr = inArray.m_data) {
                        /*!HC:outArr1*/ double * lastElement = pOutArr + retDblArr.Length;
                        /*!HC:outArr1*/ double * tmpOut = pOutArr;
                        /*!HC:inArr1*/ double * tmpIn = pInArr;
                        while (tmpOut < lastElement)
                            *tmpOut++ = operation ( *tmpIn++ );
                    }
                }
                #endregion
            }
            return new /*!HC:outCls1*/ ILArray<double> ( retDblArr, inDim.ToIntArray () );
        }
コード例 #2
0
        /*!HC:TYPELIST:
         * <hycalper>
         * <type>
         * <source	locate="after">
         * inArr1
         * </source>
         * <destination>byte</destination>
         * <destination>complex</destination>
         * <destination>complex</destination>
         * <destination>double</destination>
         * </type>
         * <type>
         * <source	locate="after">
         *  inCls1
         * </source>
         * <destination><![CDATA[ILArray<byte>]]></destination>
         * <destination><![CDATA[ILArray<complex>]]></destination>
         * <destination><![CDATA[ILArray<complex>]]></destination>
         * <destination><![CDATA[ILArray<double>]]></destination>
         * </type>
         * <type>
         * <source	locate="after">
         *  outCls1
         * </source>
         * <destination><![CDATA[ILArray<byte>]]></destination>
         * <destination><![CDATA[ILArray<complex>]]></destination>
         * <destination><![CDATA[ILArray<double>]]></destination>
         * <destination><![CDATA[ILArray<complex>]]></destination>
         * </type>
         * <type>
         * <source	locate="after">
         *  outArr1
         * </source>
         * <destination>byte</destination>
         * <destination>complex</destination>
         * <destination>double</destination>
         * <destination>complex</destination>
         * </type>
         * <type>
         * <source	locate="after">
         *  delegate_unary
         * </source>
         * <destination>ILByteFunctionByte</destination>
         * <destination>ILComplexFunctionComplex</destination>
         * <destination>ILDoubleFunctionComplex</destination>
         * <destination>ILComplexFunctionDouble</destination>
         * </type>
         * <type>
         * <source	locate="after">
         *  unaryop
         * </source>
         * <destination>ByteOperatorByte</destination>
         * <destination>ComplexOperatorComplex</destination>
         * <destination>DoubleOperatorComplex</destination>
         * <destination>ComplexOperatorDouble</destination>
         * </type>
         * </hycalper>
         */
        /// <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[ /*!HC:outCls1*/ ILArray<double> ]]> with result of operation</returns>
        /// <remarks> the values of inArray will not be altered.</remarks>
        private static /*!HC:outCls1*/ ILArray <double> /*!HC:unaryop*/ DoubleOperatorDouble(/*!HC:inCls1*/ ILArray <double> inArray,
                                                                                             /*!HC:delegate_unary*/ ILDoubleFunctionDouble operation)
        {
            ILDimension inDim = inArray.Dimensions;

            /*!HC:outArr1*/ double [] retDblArr;
            // build ILDimension
            int newLength = inDim.NumberOfElements;

            retDblArr = new /*!HC:outArr1*/ double [newLength];
            int leadDimLen = inDim [0];

            unsafe
            {
                fixed(/*!HC:outArr1*/ double *pOutArr = retDblArr)
                fixed(/*!HC:inArr1*/ double *pInArr = inArray.m_data)
                {
                    /*!HC:outArr1*/ double *lastElement = pOutArr + retDblArr.Length;
                    /*!HC:outArr1*/ double *tmpOut      = pOutArr;
                    /*!HC:inArr1*/ double * tmpIn       = pInArr;

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

            return(new /*!HC:outCls1*/ ILArray <double> (retDblArr, inDim.ToIntArray()));
        }
コード例 #3
0
ファイル: ILMath_Walker.cs プロジェクト: wdxa/ILNumerics
        /*!HC:TYPELIST:
<hycalper>
    <type>
        <source	locate="after">
        inArr1
        </source>
        <destination>byte</destination>
        <destination>complex</destination>
        <destination>complex</destination>
        <destination>double</destination>
    </type>
    <type>
        <source	locate="after">
            inCls1
        </source>
        <destination><![CDATA[ILArray<byte>]]></destination>
        <destination><![CDATA[ILArray<complex>]]></destination>
        <destination><![CDATA[ILArray<complex>]]></destination>
        <destination><![CDATA[ILArray<double>]]></destination>
    </type>
    <type>
        <source	locate="after">
            outCls1
        </source>
        <destination><![CDATA[ILArray<byte>]]></destination>
        <destination><![CDATA[ILArray<complex>]]></destination>
        <destination><![CDATA[ILArray<double>]]></destination>
        <destination><![CDATA[ILArray<complex>]]></destination>
    </type>
    <type>
        <source	locate="after">
            outArr1
        </source>
        <destination>byte</destination>
        <destination>complex</destination>
        <destination>double</destination>
        <destination>complex</destination>
    </type>
    <type>
        <source	locate="after">
            delegate_unary
        </source>
        <destination>ILByteFunctionByte</destination>
        <destination>ILComplexFunctionComplex</destination>
        <destination>ILDoubleFunctionComplex</destination>
        <destination>ILComplexFunctionDouble</destination>
    </type>
    <type>
        <source	locate="after">
            unaryop
        </source>
        <destination>ByteOperatorByte</destination>
        <destination>ComplexOperatorComplex</destination>
        <destination>DoubleOperatorComplex</destination>
        <destination>ComplexOperatorDouble</destination>
    </type>
</hycalper>
*/
        /// <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[ /*!HC:outCls1*/ ILArray<double> ]]> with result of operation</returns>
        /// <remarks> the values of inArray will not be altered.</remarks>
        private static /*!HC:outCls1*/ ILArray<double> /*!HC:unaryop*/ DoubleOperatorDouble (/*!HC:inCls1*/ ILArray<double> inArray,
            /*!HC:delegate_unary*/ ILDoubleFunctionDouble operation) {
            ILDimension inDim = inArray.Dimensions;
            /*!HC:outArr1*/ double [] retDblArr;
            // build ILDimension
            int newLength = inDim.NumberOfElements;
            retDblArr = new /*!HC:outArr1*/ double [newLength];
            int leadDimLen = inDim [0];

            unsafe
            {
                fixed (/*!HC:outArr1*/ double * pOutArr = retDblArr)
                fixed (/*!HC:inArr1*/ double * pInArr = inArray.m_data) {
                    /*!HC:outArr1*/ double * lastElement = pOutArr + retDblArr.Length;
                    /*!HC:outArr1*/ double * tmpOut = pOutArr;
                    /*!HC:inArr1*/ double * tmpIn = pInArr;
                    while (tmpOut < lastElement)
                        *tmpOut++ = operation ( *tmpIn++ );
                }
            }

            return new /*!HC:outCls1*/ ILArray<double> ( retDblArr, inDim.ToIntArray () );
        }