Ejemplo n.º 1
0
        private void Test_conj()
        {
            // test for common matrix 4x3
            ILArray <complex> A = new complex[, ] {
                { new complex(1, 2), new complex(3, 4), new complex(5, 6) },
                { new complex(7, 8), new complex(9, 10), new complex(11, 12) },
                { new complex(13, 14), new complex(15, 16), new complex(17, 18) },
                { new complex(19, 20), new complex(21, 22), new complex(23, 24) }
            };
            ILArray <fcomplex> Af = ILMath.tofcomplex(A);

            Test_isConj(A, ILMath.conj(A));
            Test_isfConj(Af, ILMath.conj(Af));
            // test on reference matrix
            Test_isConj(A, ILMath.conj(A.R));
            Test_isfConj(Af, ILMath.conj(Af.R));
            // test on 2x2x3 matrix (reference)
            A = A.Reshape(new ILDimension(2, 2, 3)).R;
            if (!A.IsReference)
            {
                throw new Exception("Unable to test conj() for reference 2x2x3!");
            }
            Af = Af.Reshape(new ILDimension(2, 2, 3)).R;
            if (!Af.IsReference)
            {
                throw new Exception("Unable to test conj() for reference 2x2x3!");
            }
            Test_isConj(A, ILMath.conj(A));
            Test_isfConj(Af, ILMath.conj(Af));
            // test those on dense array
            Test_isConj(A, ILMath.conj(A.C));
            Test_isfConj(Af, ILMath.conj(Af.C));
            // test for empty
            A = ILArray <complex> .empty();

            Af = ILArray <fcomplex> .empty();

            Test_isConj(A, ILMath.conj(A));
            Test_isfConj(Af, ILMath.conj(Af));
            // test on vector
            A  = new complex[] { new complex(1, 2), new complex(3, 4), new complex(5, 6) };
            Af = ILMath.tofcomplex(A);
            Test_isConj(A, ILMath.conj(A));
            Test_isfConj(Af, ILMath.conj(Af));
            // transpose
            Test_isConj(A.T, ILMath.conj(A.T));
            Test_isfConj(Af.T, ILMath.conj(Af.T));
            // test on scalar
            A = A[2]; Af = Af[2];
            Test_isConj(A, ILMath.conj(A));
            Test_isfConj(Af, ILMath.conj(Af));
        }
Ejemplo n.º 2
0
            internal static ILArray <double> CreateVertices(ILBaseArray dataInput
                                                            , out ILArray <double> indices
                                                            , double beta, double scaling
                                                            , ILColormap colormap)
            {
                // each arrow needs 4 vertices (indexed rendering)
                ILArray <double> data = todouble(dataInput);
                int numRows           = data.Dimensions[0];
                int numCols           = data.Dimensions[1];
                ILArray <double> ret  = new ILArray <double>(4, numCols * numRows, 2);

                // prepare indices
                indices = repmat(new ILArray <double>(new double[] { 0, 2, 1, 2, 3, 2 }, 6, 1), 1, numCols * numRows);
                indices = indices + repmat(counter(0.0, 4.0, 1, numCols * numRows), 6, 1);
                indices = indices.Reshape(2, numRows * numCols * 3);
                // normalize incoming data to length 1.0
                ILArray <double> l    = sqrt(sum(data * data, 2));
                double           maxL = (double)max(maxall(l), MachineParameterDouble.eps);

                l = (l / maxL)[":"].T * scaling;
                ILArray <double> alpha = atan2(data[":;:;1"], data[":;:;0"]);

                alpha = alpha[":"].T;
                ILArray <double> x  = data[":;:;0"][":"].T * scaling;
                ILArray <double> y  = data[":;:;1"][":"].T * scaling;
                ILArray <double> xO = repmat(linspace(1, numCols, numCols), numRows, 1)[":"].T;
                ILArray <double> yO = repmat(linspace(numRows, 1, numRows).T, 1, numCols)[":"].T;

                ret["0;:;0"] = xO - x;
                ret["1;:;0"] = xO + x - l / 2 * cos(alpha + beta);
                ret["2;:;0"] = xO + x;
                ret["3;:;0"] = xO + x - l / 2 * cos(alpha - beta);

                ret["0;:;1"] = yO - y;
                ret["1;:;1"] = yO + y - l / 2 * sin(alpha + beta);
                ret["2;:;1"] = yO + y;
                ret["3;:;1"] = yO + y - l / 2 * sin(alpha - beta);

                ret["0;0;2"] = 0.0;
                // prepare colors
                ret[":;:;3:5"] = todouble(
                    repmat(colormap.Map
                               (tosingle(l) * colormap.Length).Reshape(1, l.Length, 3) * 255, 4, 1, 1));
                return(ret.Reshape(4 * numRows * numCols, 6).T);
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Create three 3D arrays for the valuation and visualization of functions of three variables
        /// </summary>
        /// <param name="x">Vector of x values</param>
        /// <param name="y">Vector of y values</param>
        /// <param name="z">Vector of z values</param>
        /// <returns>A List of three arrays, the rows of the first comprising the x vector values and the columns of the second comprising the y vector values</returns>
        /// <remarks></remarks>
        public static List <ILArray <double> > meshgrid(ILArray <double> x, ILArray <double> y, ILArray <double> z)
        {
            if (!x.IsVector || !y.IsVector || !z.IsVector)
            {
                throw new ILArgumentException("meshgrid: inputs must be vectors");
            }
            int xLength = x.Length;
            int yLength = y.Length;
            int zLength = z.Length;
            //ILDimension dimRet = new ILDimension(xLength, yLength, zLength);
            //double[] retArrX = ILMemoryPool.Pool.New<double>(dimRet.NumberOfElements);
            //double[] retArrY = ILMemoryPool.Pool.New<double>(dimRet.NumberOfElements);
            //double[] retArrZ = ILMemoryPool.Pool.New<double>(dimRet.NumberOfElements);
            //unsafe
            //{
            //    fixed (double* pRetArrX = retArrX)
            //    fixed (double* pRetArrY = retArrY)
            //    fixed (double* pRetArrZ = retArrZ)
            //    fixed (double* pX = x.m_data)
            //    fixed (double* pY = y.m_data)
            //    fixed (double* pZ = z.m_data)
            //    {
            //        double* pRetArrayX = pRetArrX;
            //        double* pRetArrayY = pRetArrY;
            //        double* pRetArrayZ = pRetArrZ;
            //        double* pArrayX;
            //        double* pArrayY;
            //        double* pArrayZ = pZ;
            //        double* pXEnd = pX + xLength;
            //        double* pYEnd = pY + yLength;
            //        double* pZEnd = pZ + zLength;
            //        while (pArrayZ < pZEnd)
            //        {
            //            pArrayY = pY;
            //            while (pArrayY < pYEnd)
            //            {
            //                pArrayX = pX;
            //                while (pArrayX < pXEnd)
            //                {
            //                    *pRetArrayX = *pArrayX;
            //                    *pRetArrayY = *pArrayY;
            //                    *pRetArrayZ = *pArrayZ;
            //                    pArrayX++;
            //                    pRetArrayX++;
            //                    pRetArrayY++;
            //                    pRetArrayZ++;
            //                }
            //                pArrayY++;
            //            }
            //            pArrayZ++;
            //        }

            //    }
            //}

            List <ILArray <double> > retList = new List <ILArray <double> >();

            if (!x.IsRowVector)
            {
                x.Reshape(1, x.Length);
            }
            if (!y.IsColumnVector)
            {
                y.Reshape(y.Length, 1);
            }
            z = z[":"].Reshape(1, 1, z.Dimensions.NumberOfElements);

            retList.Add(repmat(x, yLength, 1, zLength));
            retList.Add(repmat(y, 1, xLength, zLength));
            retList.Add(repmat(z, yLength, xLength, 1));
            return(retList);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create three 3D arrays for the valuation and visualization of functions of three variables 
        /// </summary>
        /// <param name="x">Vector of x values</param>
        /// <param name="y">Vector of y values</param>
        /// <param name="z">Vector of z values</param>
        /// <returns>A List of three arrays, the rows of the first comprising the x vector values and the columns of the second comprising the y vector values</returns>
        /// <remarks></remarks>
        public static List<ILArray<double>> meshgrid(ILArray<double> x, ILArray<double> y, ILArray<double> z)
        {
            if (!x.IsVector || !y.IsVector || !z.IsVector)
            {
                throw new ILArgumentException("meshgrid: inputs must be vectors");
            }
            int xLength = x.Length;
            int yLength = y.Length;
            int zLength = z.Length;
            //ILDimension dimRet = new ILDimension(xLength, yLength, zLength);
            //double[] retArrX = ILMemoryPool.Pool.New<double>(dimRet.NumberOfElements);
            //double[] retArrY = ILMemoryPool.Pool.New<double>(dimRet.NumberOfElements);
            //double[] retArrZ = ILMemoryPool.Pool.New<double>(dimRet.NumberOfElements);
            //unsafe
            //{
            //    fixed (double* pRetArrX = retArrX)
            //    fixed (double* pRetArrY = retArrY)
            //    fixed (double* pRetArrZ = retArrZ)
            //    fixed (double* pX = x.m_data)
            //    fixed (double* pY = y.m_data)
            //    fixed (double* pZ = z.m_data)
            //    {
            //        double* pRetArrayX = pRetArrX;
            //        double* pRetArrayY = pRetArrY;
            //        double* pRetArrayZ = pRetArrZ;
            //        double* pArrayX;
            //        double* pArrayY;
            //        double* pArrayZ = pZ;
            //        double* pXEnd = pX + xLength;
            //        double* pYEnd = pY + yLength;
            //        double* pZEnd = pZ + zLength;
            //        while (pArrayZ < pZEnd)
            //        {
            //            pArrayY = pY;
            //            while (pArrayY < pYEnd)
            //            {
            //                pArrayX = pX;
            //                while (pArrayX < pXEnd)
            //                {
            //                    *pRetArrayX = *pArrayX;
            //                    *pRetArrayY = *pArrayY;
            //                    *pRetArrayZ = *pArrayZ;
            //                    pArrayX++;
            //                    pRetArrayX++;
            //                    pRetArrayY++;
            //                    pRetArrayZ++;
            //                }
            //                pArrayY++;
            //            }
            //            pArrayZ++;
            //        }

            //    }
            //}

            List<ILArray<double>> retList = new List<ILArray<double>>();
            if (!x.IsRowVector) x.Reshape(1,x.Length); 
            if (!y.IsColumnVector) y.Reshape(y.Length,1);  
            z = z[":"].Reshape(1,1,z.Dimensions.NumberOfElements); 

            retList.Add(repmat(x,yLength,1,zLength));
            retList.Add(repmat(y,1,xLength,zLength));
            retList.Add(repmat(z,yLength,xLength,1));
            return retList;
        }
Ejemplo n.º 5
0
            internal static ILArray<double> CreateVertices(ILBaseArray dataInput 
                                            ,out ILArray<double> indices
                                            ,double beta, double scaling
                                            , ILColormap colormap) {
                // each arrow needs 4 vertices (indexed rendering)
                ILArray<double> data = todouble(dataInput);
                int numRows = data.Dimensions[0];
                int numCols = data.Dimensions[1];
                ILArray<double> ret = new ILArray<double>(4, numCols * numRows, 2);
                // prepare indices
                indices = repmat(new ILArray<double>(new double[] { 0, 2, 1, 2, 3, 2 }, 6, 1), 1, numCols * numRows);
                indices = indices + repmat(counter(0.0, 4.0, 1, numCols * numRows), 6, 1);
                indices = indices.Reshape(2, numRows * numCols * 3);
                // normalize incoming data to length 1.0 
                ILArray<double> l = sqrt(sum(data * data, 2));
                double maxL = (double)max(maxall(l),MachineParameterDouble.eps);
                l = (l / maxL)[":"].T * scaling;
                ILArray<double> alpha = atan2(data[":;:;1"], data[":;:;0"]);
                alpha = alpha[":"].T;
                ILArray<double> x = data[":;:;0"][":"].T * scaling;
                ILArray<double> y = data[":;:;1"][":"].T * scaling;
                ILArray<double> xO = repmat(linspace(1, numCols, numCols), numRows, 1)[":"].T;
                ILArray<double> yO = repmat(linspace(numRows, 1, numRows).T, 1, numCols)[":"].T;
                ret["0;:;0"] = xO - x;
                ret["1;:;0"] = xO + x - l / 2 * cos(alpha + beta);
                ret["2;:;0"] = xO + x;
                ret["3;:;0"] = xO + x - l / 2 * cos(alpha - beta);

                ret["0;:;1"] = yO - y;
                ret["1;:;1"] = yO + y - l / 2 * sin(alpha + beta);
                ret["2;:;1"] = yO + y;
                ret["3;:;1"] = yO + y - l / 2 * sin(alpha - beta);

                ret["0;0;2"] = 0.0;
                // prepare colors 
                ret[":;:;3:5"] = todouble(
                    repmat(colormap.Map
                            (tosingle(l) * colormap.Length).Reshape(1, l.Length, 3) * 255, 4, 1, 1));
                return ret.Reshape(4 * numRows * numCols, 6).T;
            }