Beispiel #1
0
        /// <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;
        }
Beispiel #2
0
        /// <summary>
        /// invert elements of A, return result as out argument
        /// </summary>
        /// <param name="A"></param>
        /// <param name="outArray"></param>
        public static void /*!HC:HCFuncName*/ invert(/*!HC:inCls1*/ ILArray <double> A, /*!HC:inCls2*/ ILArray <double> 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(/*!HC:inArr1*/ double *inA1 = A.m_data)
                fixed(/*!HC:inArr2*/ double *inA2 = outArray.m_data)
                {
                    /*!HC:inArr1*/ double *pInA1 = inA1;
                    /*!HC:inArr2*/ double *pInA2 = inA2;
                    int c = 0;
                    /*!HC:inArr2*/ double *outEnd = inA2 + outArray.m_data.Length;

                    if (A.IsReference)
                    {
                        while (pInA2 < outEnd)    //HC07
                        /*!HC:HCCompute07*/
                        {
                            *pInA2++ = /*!HC:outCast*/ /**/ (*(pInA1 + A.getBaseIndex(c++)) /*!HC:HCoperation*/ * -1.0);
                        }
                    }
                    else
                    {
                        while (pInA2 < outEnd)    //HC11
                        /*!HC:HCCompute11*/
                        {
                            *pInA2++ = /*!HC:outCast*/ /**/ (*pInA1++ /*HC:HCoperation*/ *(-1.0));
                        }
                    }
                }
                #endregion array + array
            }
            return;
        }
Beispiel #3
0
// DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !!
        /// <summary>
        /// invert elements of A, return result as out argument
        /// </summary>
        /// <param name="A"></param>
        /// <param name="outArray"></param>
        public static void  invert(ILArray <byte> A, ILArray <byte> 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(byte *inA1 = A.m_data)
                fixed(byte *inA2 = outArray.m_data)
                {
                    byte *pInA1  = inA1;
                    byte *pInA2  = inA2;
                    byte *outEnd = inA2 + outArray.m_data.Length;

                    while (pInA2 < outEnd)    //HC11

                    {
                        *pInA2++ = (byte)(*pInA1++ /*HC:*/ *(-1));
                    }
                }
                #endregion array + array
            }
            return;
        }
        /// <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<byte> ]]> 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 <byte> ByteOperatorByteByte(ILArray <byte> inArray1, ILArray <byte> inArray2,
                                                           ILByteFunctionByteByte operation)
        {
            ILDimension inDim = inArray1.Dimensions;

            if (!inDim.IsSameSize(inArray2.Dimensions))
            {
                throw new ILDimensionMismatchException();
            }
            byte [] retSystemArr;
            // build ILDimension
            int newLength = inDim.NumberOfElements;

            retSystemArr = new  byte [newLength];
            int leadDimLen = inDim [0];

            // physical -> pointer arithmetic
            unsafe
            {
                fixed(byte *pInArr1 = inArray1.m_data)
                fixed(byte *pInArr2 = inArray2.m_data)
                fixed(byte *pOutArr = retSystemArr)
                {
                    byte *poutarr = pOutArr;
                    byte *poutend = poutarr + newLength;
                    byte *pIn1    = pInArr1;
                    byte *pIn2    = pInArr2;

                    while (poutarr < poutend)
                    {
                        *poutarr++ = operation(*pIn1++, *pIn2++);
                    }
                }
            }

            return(new  ILArray <byte> (retSystemArr, inDim.ToIntArray()));
        }
// DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !!

        /// <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<complex> ]]> 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 <complex> ComplexOperatorComplexComplex(ILArray <complex> inArray1, ILArray <complex> inArray2,
                                                                       ILComplexFunctionComplexComplex operation)
        {
            ILDimension inDim = inArray1.Dimensions;

            if (!inDim.IsSameSize(inArray2.Dimensions))
            {
                throw new ILDimensionMismatchException();
            }
            complex [] retSystemArr;
            // build ILDimension
            int newLength = inDim.NumberOfElements;

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

            // physical -> pointer arithmetic
            unsafe
            {
                fixed(complex *pInArr1 = inArray1.m_data)
                fixed(complex * pInArr2 = inArray2.m_data)
                fixed(complex * pOutArr = retSystemArr)
                {
                    complex *poutarr = pOutArr;
                    complex *poutend = poutarr + newLength;
                    complex *pIn1    = pInArr1;
                    complex *pIn2    = pInArr2;

                    while (poutarr < poutend)
                    {
                        *poutarr++ = operation(*pIn1++, *pIn2++);
                    }
                }
            }

            return(new  ILArray <complex> (retSystemArr, inDim.ToIntArray()));
        }
        /*!HC:TYPELIST:
         * <hycalper>
         * <type>
         * <source	locate="after">
         * inArr1
         * </source>
         * <destination>byte</destination>
         * <destination>complex</destination>
         * </type>
         * <type>
         * <source	locate="after">
         *  inArr2
         * </source>
         * <destination>byte</destination>
         * <destination>complex</destination>
         * </type>
         * <type>
         * <source	locate="after">
         *  inCls1
         * </source>
         * <destination><![CDATA[ILArray<byte>]]></destination>
         * <destination><![CDATA[ILArray<complex>]]></destination>
         * </type>
         * <type>
         * <source	locate="after">
         *  inCls2
         * </source>
         * <destination><![CDATA[ILArray<byte>]]></destination>
         * <destination><![CDATA[ILArray<complex>]]></destination>
         * </type>
         * <type>
         * <source	locate="after">
         *  outCls1
         * </source>
         * <destination><![CDATA[ILArray<byte>]]></destination>
         * <destination><![CDATA[ILArray<complex>]]></destination>
         * </type>
         * <type>
         * <source	locate="after">
         *  outArr1
         * </source>
         * <destination>byte</destination>
         * <destination>complex</destination>
         * </type>
         * <type>
         * <source	locate="after">
         *  delegate_binary
         * </source>
         * <destination>ILByteFunctionByteByte</destination>
         * <destination>ILComplexFunctionComplexComplex</destination>
         * </type>
         * <type>
         * <source	locate="after">
         *  hcfunctionName
         * </source>
         * <destination>ByteOperatorByteByte</destination>
         * <destination>ComplexOperatorComplexComplex</destination>
         * </type>
         * </hycalper>
         */
        /// <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[ /*!HC:outCls1*/ ILArray<double> ]]> 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 /*!HC:outCls1*/ ILArray <double> /*!HC:hcfunctionName*/ DoubleOperatorDoubleDouble(/*!HC:inCls1*/ ILArray <double> inArray1, /*!HC:inCls2*/ ILArray <double> inArray2,
                                                                                                          /*!HC:delegate_binary*/ ILDoubleFunctionDoubleDouble operation)
        {
            ILDimension inDim = inArray1.Dimensions;

            if (!inDim.IsSameSize(inArray2.Dimensions))
            {
                throw new ILDimensionMismatchException();
            }
            /*!HC:outArr1*/ double [] retSystemArr;
            // build ILDimension
            int newLength = inDim.NumberOfElements;

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

            // physical -> pointer arithmetic
            unsafe
            {
                fixed(/*!HC:inArr1*/ double *pInArr1 = inArray1.m_data)
                fixed(/*!HC:inArr2*/ double *pInArr2  = inArray2.m_data)
                fixed(/*!HC:outArr1*/ double *pOutArr = retSystemArr)
                {
                    /*!HC:outArr1*/ double *poutarr = pOutArr;
                    /*!HC:outArr1*/ double *poutend = poutarr + newLength;
                    /*!HC:inArr1*/ double * pIn1    = pInArr1;
                    /*!HC:inArr2*/ double * pIn2    = pInArr2;

                    while (poutarr < poutend)
                    {
                        *poutarr++ = operation(*pIn1++, *pIn2++);
                    }
                }
            }

            return(new /*!HC:outCls1*/ ILArray <double> (retSystemArr, inDim.ToIntArray()));
        }
Beispiel #7
0
        /// <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 <double> subtract(ILArray <double> A, ILArray <double> B)
        {
            if (A.IsEmpty)
            {
                return(ILArray <double> .empty(A.Dimensions));
            }
            if (B.IsEmpty)
            {
                return(ILArray <double> .empty(B.Dimensions));
            }
            if (A.IsScalar)
            {
                if (B.IsScalar)
                {
                    return(new  ILArray <double> (new  double [1] {
                        (A.m_data[0] - B.m_data[0])
                    }));
                }
                else
                {
                    #region scalar + array
                    ILDimension inDim = B.Dimensions;

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

                    double scalarValue = A.m_data[0];

                    unsafe
                    {
                        fixed(double *pOutArr = retArr)
                        fixed(double *pInArr = B.m_data)
                        {
                            double *lastElement = pOutArr + retArr.Length;
                            double *tmpOut      = pOutArr;
                            double *tmpIn       = pInArr;

                            while (tmpOut < lastElement) //HC03

                            {
                                *tmpOut++ = (scalarValue - (*tmpIn++));
                            }
                        }
                    }

                    return(new  ILArray <double> (retArr, inDim));

                    #endregion scalar + array
                }
            }
            else
            {
                if (B.IsScalar)
                {
                    #region array + scalar
                    ILDimension inDim = A.Dimensions;

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

                    double scalarValue = B.m_data[0];

                    unsafe
                    {
                        fixed(double *pOutArr = retArr)
                        fixed(double *pInArr = A.m_data)
                        {
                            double *lastElement = pOutArr + retArr.Length;
                            double *tmpOut      = pOutArr;
                            double *tmpIn       = pInArr;

                            while (tmpOut < lastElement)   //HC06

                            {
                                *tmpOut++ = (*tmpIn++ - scalarValue);
                            }
                        }
                    }

                    return(new  ILArray <double> (retArr, inDim));

                    #endregion array + scalar
                }
                else
                {
                    #region array + array
                    ILDimension inDim = A.Dimensions;
                    if (!inDim.IsSameSize(B.Dimensions))
                    {
                        throw new ILDimensionMismatchException();
                    }

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

                    unsafe
                    {
                        fixed(double *pOutArr = retSystemArr)
                        fixed(double *inA1 = A.m_data)
                        fixed(double *inA2 = B.m_data)
                        {
                            double *pInA1   = inA1;
                            double *pInA2   = inA2;
                            double *poutarr = pOutArr;
                            double *outEnd  = poutarr + retSystemArr.Length;

                            while (poutarr < outEnd)    //HC11

                            {
                                *poutarr++ = (*pInA1++ - (*pInA2++));
                            }
                        }
                    }

                    return(new  ILArray <double> (retSystemArr, inDim));

                    #endregion array + array
                }
            }
        }
Beispiel #8
0
        /// <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>new ILLogicalArray with result of operation for corresponding
        /// elements of both arrays.</returns>
        /// <remarks>The values of inArray2 nor inArray2 will not be altered.The dimensions
        /// of both arrays must match.</remarks>
        private static ILArray <double> DoubleBinaryDoubleOperator(ILArray <double> inArray1, ILArray <double> inArray2,
                                                                   ILApplyDouble_DoubleDouble operation)
        {
            ILDimension inDim = inArray1.Dimensions;

            if (!inDim.IsSameSize(inArray2.Dimensions))
            {
                throw new Exception("Array dimensions must match.");
            }
            double[] retBoolArr;
            // build ILDimension
            int newLength = inDim.NumberOfElements;

            retBoolArr = new double[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;
                    }
                }
                ILIterator <double> it1 = inArray1.CreateIterator(ILIteratorPositions.ILEnd, leadDim);
                ILIterator <double> it2 = inArray2.CreateIterator(ILIteratorPositions.ILEnd, leadDim);
                unsafe
                {
                    fixed(double *pOutArr = retBoolArr)
                    {
                        double *poutarr = pOutArr;
                        double *outEnd  = poutarr + newLength;

                        while (poutarr < outEnd)
                        {
                            *poutarr++ = operation(it1.Increment(), it2.Increment());
                        }
                    }
                }
                // ==============================================================
                #endregion
            }
            else
            {
                // physical -> pointer arithmetic
                #region physical storage
                unsafe
                {
                    fixed(double *pInArr1 = inArray1.m_data,
                          pInArr2         = inArray2.m_data)
                    {
                        fixed(double *pOutArr = retBoolArr)
                        {
                            double *poutarr = pOutArr;
                            double *poutend = poutarr + newLength;
                            double *pIn1    = pInArr1;
                            double *pIn2    = pInArr2;

                            while (poutarr < poutend)
                            {
                                *poutarr++ = operation(*pIn1++, *pIn2++);
                            }
                        }
                    }
                }
                #endregion
            }
            return(new ILArray <double>(retBoolArr, inDim.ToIntArray()));
        }
Beispiel #9
0
// DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !!
        /// <summary>Multiply elements</summary>
        /// <param name="A">input 1</param>
        /// <param name="B">input 2</param>
        /// <returns>Array with elementwise multiplication 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 <complex> multiplyElem(ILArray <complex> A, ILArray <complex> B)
        {
            if (A.IsEmpty)
            {
                return(ILArray <complex> .empty(A.Dimensions));
            }
            if (B.IsEmpty)
            {
                return(ILArray <complex> .empty(B.Dimensions));
            }
            if (A.IsScalar)
            {
                if (B.IsScalar)
                {
                    return(new  ILArray <complex> (new  complex [1] {
                        (A.m_data[0] * B.m_data[0])
                    }));
                }
                else
                {
                    #region scalar + array
                    ILDimension inDim = B.Dimensions;

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

                    complex scalarValue = A.m_data[0];

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

                            while (tmpOut < lastElement) //HC03

                            {
                                *tmpOut++ = (scalarValue * (*tmpIn++));
                            }
                        }
                    }

                    return(new  ILArray <complex> (retArr, inDim));

                    #endregion scalar + array
                }
            }
            else
            {
                if (B.IsScalar)
                {
                    #region array + scalar
                    ILDimension inDim = A.Dimensions;

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

                    complex scalarValue = B.m_data[0];

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

                            while (tmpOut < lastElement)   //HC06

                            {
                                *tmpOut++ = (*tmpIn++  *scalarValue);
                            }
                        }
                    }

                    return(new  ILArray <complex> (retArr, inDim));

                    #endregion array + scalar
                }
                else
                {
                    #region array + array
                    ILDimension inDim = A.Dimensions;
                    if (!inDim.IsSameSize(B.Dimensions))
                    {
                        throw new ILDimensionMismatchException();
                    }

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

                    unsafe
                    {
                        fixed(complex *pOutArr = retSystemArr)
                        fixed(complex * inA1 = A.m_data)
                        fixed(complex * inA2 = B.m_data)
                        {
                            complex *pInA1   = inA1;
                            complex *pInA2   = inA2;
                            complex *poutarr = pOutArr;
                            complex *outEnd  = poutarr + retSystemArr.Length;

                            while (poutarr < outEnd)    //HC11

                            {
                                *poutarr++ = (*pInA1++  *(*pInA2++));
                            }
                        }
                    }

                    return(new  ILArray <complex> (retSystemArr, inDim));

                    #endregion array + array
                }
            }
        }