Пример #1
0
        private void TestQuickSortGen(ILArray <double> input, int dim, bool desc)
        {
            try {
                ILArray <int> A = ILMath.toint32(input);
                try {
                    ILMatFile f1 = new ILMatFile("tempADebugQuickSort.mat");
                    A = (ILArray <int>)f1["DebugQuickSort"];
                } catch (Exception) {}

                ILArray <int> result;
                System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                sw.Start();
                result = ILMath.sort(A, dim, desc);
                sw.Stop();
                if (!isSorted(ILMath.todouble(result), dim, desc))
                {
                    //ILMatFile f = new ILMatFile();
                    //A.Name = "DebugQuickSort";
                    //f.Add(A);
                    //System.IO.Stream s = new System.IO.FileStream("tempADebugQuickSort.mat",System.IO.FileMode.CreateNew);
                    //f.Write(s);
                    throw new Exception("invalid values");
                }
                Success(input.Dimensions.ToString() + "(Int32) needed: " + sw.ElapsedMilliseconds + " ms");
            } catch (Exception e) {
                Error(0, e.Message);
            }
        }
Пример #2
0
        public void MeasurePool()
        {
            Info("Measuring memory pool performance");
            Info("---------------------------------");
            ILArray <int>    Lengths = ILMath.toint32(ILMath.vector(1000000, 1000, 1000000));
            ILArray <int>    PoolSizes = ILMath.toint32(ILMath.vector(00, 10, 250));
            ILArray <double> result = ILMath.zeros(Lengths.Length, PoolSizes.Length);
            ILArray <double> dataA = ILMath.ones(1000, 1000);
            ILArray <double> dataB = ILMath.ones(1000, 1000);
            int counter = 1, countAll = Lengths.Length * PoolSizes.Length;

            for (int p = 0; p < PoolSizes.Length; p++)
            {
                for (int s = 0; s < Lengths.Length; s++)
                {
                    result[s, p] = MeasurePoolParameter((int)Lengths[s], (int)PoolSizes[p], 100, dataA, dataB);
                    Console.Out.Write(String.Format("\r... step {0} of {1} completed", counter++, countAll));
                }
            }
            result.Name = "results";
            ILMatFile mf = new ILMatFile();

            mf["results"]   = result;
            mf["lengths"]   = Lengths;
            mf["poolSizes"] = PoolSizes;
            mf.Write(new FileStream("memoryPoolTestPerf.mat", FileMode.Create));
        }
Пример #3
0
 /// <summary>
 /// create composite shape
 /// </summary>
 /// <param name="panel">scene hosting the scene</param>
 /// <param name="numVertices">number of overall vertices for the shape</param>
 /// <param name="verticesPerShape">Number of vertices per shape</param>
 public ILCompositeShape(ILPanel panel, int numVertices, int verticesPerShape)
     : base(panel, numVertices, verticesPerShape)
 {
     Opacity        = 255;
     m_shapeIndices = ILMath.toint32(
         ILMath.counter(0.0, 1.0, VerticesPerShape, numVertices / VerticesPerShape));
 }
Пример #4
0
        /// <summary>
        /// update composite shape
        /// </summary>
        /// <param name="X">x coordinates, vector of length <see cref="ILNumerics.Drawing.Shapes.ILShape.VertexCount"/></param>
        /// <param name="Y">y coordinates, vector of length <see cref="ILNumerics.Drawing.Shapes.ILShape.VertexCount"/></param>
        /// <param name="Z">z coordinates, vector of length <see cref="ILNumerics.Drawing.Shapes.ILShape.VertexCount"/></param>
        /// <param name="mapping">Mapping of shapes, composes shapes out of vertices. Matrix having
        /// <see cref="ILNumerics.Drawing.Shapes.ILShape&lt;T>.VerticesPerShape"/> rows.
        /// Every element in a column specifies the index of a vertex according to its position in X,Y,Z.
        /// The <see cref="ILNumerics.Drawing.Shapes.ILShape&lt;T>.VerticesPerShape"/> elements in a column therefore
        /// compose a single shape. Vertices may get used arbitrary times (or not at all). All elements must be
        /// positive integer values in range 0...[<see cref="ILNumerics.Drawing.Shapes.ILShape.VertexCount"/>-1].</param>
        /// <remarks>All vertices of the shape are updated with the data specified in X,Y and Z. Neither the colors or any
        /// other data of vertices are changed. The shape is invalidated for reconfiguration at next redraw. </remarks>
        public void Update(ILBaseArray X, ILBaseArray Y, ILBaseArray Z, ILBaseArray mapping)
        {
            if (!X.IsVector || !Y.IsVector || !Z.IsVector || X.Length != Y.Length || Y.Length != Z.Length)
            {
                throw new ILArgumentException("numeric vectors of same length expected for: X, Y and Z");
            }
            if (mapping == null || mapping.IsEmpty || !mapping.IsMatrix || !mapping.IsNumeric || mapping.Dimensions[0] != VerticesPerShape)
            {
                throw new ILArgumentException("mapping must be a numeric matrix, " + VerticesPerShape.ToString() + " rows, each column specifies indices for the vertices of a single shape.");
            }
            if (mapping is ILArray <int> )
            {
                m_shapeIndices = (mapping as ILArray <int>).C;
            }
            else
            {
                m_shapeIndices = ILMath.toint32(mapping);
            }
            ILArray <float> fX = ILMath.tosingle(X);
            ILArray <float> fY = ILMath.tosingle(Y);
            ILArray <float> fZ = ILMath.tosingle(Z);

            for (int i = 0; i < m_vertices.Length; i++)
            {
                m_vertices[i].XPosition = fX.GetValue(i);
                m_vertices[i].YPosition = fY.GetValue(i);
                m_vertices[i].ZPosition = fZ.GetValue(i);
            }
            Invalidate();
        }
Пример #5
0
        /// <summary>
        /// Multidimensional scaling/PCoA: transform distances to points in a coordinate system.
        /// </summary>
        /// <param name="input">A matrix of pairwise distances. Zero indicates identical objects.</param>
        /// <returns>A matrix, the columns of which are coordinates in the nth dimension.
        /// The rows are in the same order as the input.</returns>
        public static ILArray <double> Scale(ILArray <double> input)
        {
            int n = input.Length;

            ILArray <double> p = ILMath.eye <double>(n, n) - ILMath.repmat(1.0 / n, n, n);

            ILArray <double> a = -.5 * ILMath.multiplyElem(input, input);
            ILArray <double> b = ILMath.multiply(p, a, p);

            ILArray <complex> V = ILMath.empty <complex>();
            ILArray <complex> E = ILMath.eig((b + b.T) / 2, V);

            ILArray <int>    i = ILMath.empty <int>();
            ILArray <double> e = ILMath.sort(ILMath.diag(ILMath.real(E)), i);

            e = ILMath.flipud(e);
            i = ILMath.toint32(ILMath.flipud(ILMath.todouble(i)));

            ILArray <int> keep = ILMath.empty <int>();

            for (int j = 0; j < e.Length; j++)
            {
                if (e[j] > 0.000000001)
                {
                    keep.SetValue(j, keep.Length);
                }
            }

            ILArray <double> Y;

            if (ILMath.isempty(keep))
            {
                Y = ILMath.zeros(n, 1);
            }
            else
            {
                Y = ILMath.zeros <double>(V.S[0], keep.Length);
                for (int j = 0; j < keep.Length; j++)
                {
                    Y[ILMath.full, j] = ILMath.todouble(-V[ILMath.full, i[keep[j]]]);
                }
                Y = ILMath.multiply(Y, ILMath.diag(ILMath.sqrt(e[keep])));
            }

            ILArray <int> maxind = ILMath.empty <int>();

            ILMath.max(ILMath.abs(Y), maxind, 0);
            int              d       = Y.S[1];
            ILArray <int>    indices = maxind + ILMath.toint32(ILMath.array <int>(SteppedRange(0, n, (d - 1) * n)));
            ILArray <double> colsign = ILMath.sign(Y[indices]);

            for (int j = 0; j < Y.S[1]; j++)
            {
                Y[ILMath.full, j] = Y[ILMath.full, j] * colsign[j];
            }

            return(Y);
        }
Пример #6
0
 /// <summary>
 /// create composite shape
 /// </summary>
 /// <param name="panel">hosting panel</param>
 /// <param name="verticesPerShape">number of vertices per shape</param>
 /// <param name="X">x coordinates vector </param>
 /// <param name="Y">y coordinates vector </param>
 /// <param name="Z">z coordinates vector </param>
 /// <remarks>The constructor creates a new composite shape out of all vertices specified in X,Y and Z.
 /// Every vertex is only used once. Every shape uses
 /// <see cref="ILNumerics.Drawing.Shapes.ILShape&lt;T>.VerticesPerShape"/> vertices one after another.</remarks>
 public ILCompositeShape(ILPanel panel, int verticesPerShape, ILBaseArray X, ILBaseArray Y, ILBaseArray Z)
     : base(panel, X.Length, verticesPerShape)
 {
     Update(X, Y, Z);
     m_shapeIndices = ILMath.toint32(
         ILMath.counter(0.0, 1.0, VerticesPerShape, m_vertCount / VerticesPerShape));
     Opacity   = 255;
     m_shading = ShadingStyles.Flat;
 }
Пример #7
0
        private string[] generateStringsRandom(int count, int maxLen)
        {
            string []     ret  = new string[count];
            ILArray <int> r    = ILMath.toint32(ILMath.rand(maxLen, count) * 26) + (int)'a';
            ILArray <int> lens = ILMath.toint32(ILMath.rand(1, count) * (maxLen - 1));

            for (int i = 0; i < count; i++)
            {
                ILArray <double> rang  = ILMath.vector(0, lens.GetValue(i));
                ILArray <char>   chars = ILMath.tochar(r[rang, i]);
                ret[i] = new String(chars.Detach().m_data);
            }
            return(ret);
        }
Пример #8
0
        public override ILCell GenerateTestArrays()
        {
            ILCell ret   = new ILCell();
            int    count = 0;
            // empty
            ILArray <long> tmp;

            ret[count++] = ILArray <long> .empty(0, 0);

            ret[count++] = ILArray <long> .empty(1, 0);

            ret[count++] = ILArray <long> .empty(0, 1, 0);

            // scalar
            ret[count++] = (ILArray <long>)(long) 1;
            ret[count++] = (ILArray <long>)(long) int.MaxValue;
            ret[count++] = (ILArray <long>)(long) int.MinValue;
            ret[count++] = (ILArray <long>)(long) 0;
            ret[count++] = (ILArray <long>)(long)(-30);
            // vector
            ret[count++] = ILMath.toint64(ILMath.zeros(1, 10));
            ret[count++] = ILMath.toint64(ILMath.ones(1, 10));
            ret[count++] = ILMath.toint64(ILMath.zeros(10, 1));
            ret[count++] = ILMath.toint64(ILMath.ones(10, 1));
            ret[count++] = ILMath.toint64(ILMath.vector(0.0, 10.0));
            ret[count++] = ILMath.toint64(ILMath.vector(-5.0, 4.0));

            tmp          = ILMath.toint64(ILMath.vector(-5.0, 4.0));
            tmp[0]       = int.MinValue;
            tmp["end"]   = int.MaxValue;
            tmp[3]       = 0;
            ret[count++] = tmp;
            // matrix
            ret[count++] = ILMath.toint64(ILMath.zeros(3, 2));
            ret[count++] = ILMath.toint64(ILMath.rand(2, 4));
            ret[count++] = ILMath.toint64(ILMath.ones(2, 3));
            ret[count++] = ILMath.toint64(ILMath.ones(3, 2));
            // 3d array
            ret[count++] = ILMath.toint64(ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.toint64(ILMath.ones(4, 3, 2));
            ret[count++] = ILMath.toint64(ILMath.toint32(0.0 / (ILMath.randn(4, 3, 2))));
            ret[count++] = ILMath.toint64(ILMath.ones(4, 3, 2) * int.MinValue);
            ret[count++] = ILMath.toint64(ILMath.rand(4, 3, 2) * int.MaxValue);
            // 4d array
            ret[count++] = ILMath.toint64(ILMath.rand(30, 2, 3, 20) * int.MaxValue);
            return(ret);
        }
Пример #9
0
 protected static ILArray <int> _int(ILArray <double> ilArray)
 {
     return(ILMath.toint32(ilArray));
 }
Пример #10
0
        /// <summary>
        /// update composite shape
        /// </summary>
        /// <param name="X">x coordinates, vector of length <see cref="ILNumerics.Drawing.Shapes.ILShape.VertexCount"/></param>
        /// <param name="Y">y coordinates, vector of length <see cref="ILNumerics.Drawing.Shapes.ILShape.VertexCount"/></param>
        /// <param name="Z">z coordinates, vector of length <see cref="ILNumerics.Drawing.Shapes.ILShape.VertexCount"/></param>
        /// <param name="mapping">Mapping of shapes, composes shapes out of vertices. Matrix having
        /// <see cref="ILNumerics.Drawing.Shapes.ILShape&lt;T>.VerticesPerShape"/> rows.
        /// Every element in a column specifies the index of a vertex according to its position in X,Y,Z.
        /// The <see cref="ILNumerics.Drawing.Shapes.ILShape&lt;T>.VerticesPerShape"/> elements in a column therefore
        /// compose a single shape. Vertices may get used arbitrary times (or not at all). All elements must be
        /// positive integer values in range 0...[<see cref="ILNumerics.Drawing.Shapes.ILShape.VertexCount"/>-1].</param>
        /// <param name="colors">The colors.</param>
        /// <remarks>All vertices of the shape are updated with the data specified in X,Y and Z. Neither the colors or any
        /// other data of vertices are changed. The shape is invalidated for reconfiguration at next redraw. </remarks>
        public void Update(ILBaseArray X, ILBaseArray Y, ILBaseArray Z, ILBaseArray mapping, ILBaseArray colors)
        {
            if (!VertexDefinition.StoresColor)
            {
                throw new NotSupportedException("The underlying vertex type cannot store individual color values! Use another shape or flat shading!");
            }
            if (!X.IsVector || !Y.IsVector || !Z.IsVector || X.Length != Y.Length || Y.Length != Z.Length)
            {
                throw new ILArgumentException("numeric vectors of same length expected for: X, Y and Z");
            }
            if ((colors.Dimensions[1] != 3 && colors.Dimensions[1] != 4) || colors.Length != X.Length)
            {
                throw new ILArgumentException("invalid size of colors data! Colors must have 3 or 4 columns with color components (RGB) or alpha value + color components (ARGB) respectively. Number of rows must match number of vertices.");
            }
            if (mapping == null || mapping.IsEmpty || !mapping.IsMatrix || !mapping.IsNumeric || mapping.Dimensions[0] != VerticesPerShape)
            {
                throw new ILArgumentException("mapping must be a numeric matrix, " + VerticesPerShape.ToString() + " rows, each column specifies indices for the vertices of a single shape.");
            }
            if (mapping is ILArray <int> )
            {
                m_shapeIndices = (mapping as ILArray <int>).C;
            }
            else
            {
                m_shapeIndices = ILMath.toint32(mapping);
            }
            if (m_shapeIndices.MinValue < 0 || m_shapeIndices.MaxValue >= X.Dimensions[1])
            {
                throw new ILArgumentException("invalid mapping: indices must point to existing vertex indices");
            }
            ILArray <float> fX   = ILMath.tosingle(X);
            ILArray <float> fY   = ILMath.tosingle(Y);
            ILArray <float> fZ   = ILMath.tosingle(Z);
            ILArray <byte>  fcol = ILMath.tobyte(colors);

            if (fcol.Dimensions[1] == 3)
            {
                for (int i = 0; i < m_vertices.Length; i++)
                {
                    m_vertices[i].XPosition = fX.GetValue(i);
                    m_vertices[i].YPosition = fY.GetValue(i);
                    m_vertices[i].ZPosition = fZ.GetValue(i);
                    m_vertices[i].Color     = Color.FromArgb(
                        fcol.GetValue(i, 0),
                        fcol.GetValue(i, 1),
                        fcol.GetValue(i, 2));
                }
            }
            else if (fcol.Dimensions[1] == 4)
            {
                for (int i = 0; i < m_vertices.Length; i++)
                {
                    m_vertices[i].XPosition = fX.GetValue(i);
                    m_vertices[i].YPosition = fY.GetValue(i);
                    m_vertices[i].ZPosition = fZ.GetValue(i);
                    m_vertices[i].Color     = Color.FromArgb(
                        fcol.GetValue(i, 1),
                        fcol.GetValue(i, 2),
                        fcol.GetValue(i, 3));
                    m_vertices[i].Alpha = fcol.GetValue(i);
                }
            }
            Invalidate();
        }
Пример #11
0
        /// <summary>
        /// run all tests for ILMatFile
        /// </summary>
        public override void Run()
        {
            // tests: creation
            // =================
            Header();
            Test_TestMatlab();
            Test_StreamMatlab("testarray1.mat", ILMath.empty());
            Test_StreamMatlab("testarray1.mat", ILMath.ones(1, 1));
            Test_StreamMatlab("testarray1.mat", ILMath.rand(10, 1));
            Test_StreamMatlab("testarray1.mat", ILMath.rand(1, 10));
            Test_StreamMatlab("testarray1.mat", ILMath.rand(0, 1));
            Test_StreamMatlab("testarray1.mat", ILMath.rand(10, 100, 4));

            Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.ones(1, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.empty()));
            Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.rand(10, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.rand(1, 10)));
            Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.rand(0, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.rand(10, 100, 4)));

            Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.ones(1, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.empty()));
            Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.rand(10, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.rand(1, 10)));
            Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.rand(0, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.rand(10, 100, 4)));

            Test_StreamMatlab("testarray1.mat", new ILArray <complex>(new complex[] { new complex(1.0, 2.0) }));
            Test_StreamMatlab("testarray1.mat", ILMath.tocomplex(ILMath.empty()));
            Test_StreamMatlab("testarray1.mat", ILMath.tocomplex(ILMath.rand(10, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tocomplex(ILMath.rand(1, 10)));
            Test_StreamMatlab("testarray1.mat", ILMath.tocomplex(ILMath.rand(0, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tocomplex(ILMath.rand(10, 100, 4)));

            Test_StreamMatlab("testarray1.mat", new ILArray <fcomplex>(new fcomplex[] { new fcomplex(1.0f, 2.0f) }));
            Test_StreamMatlab("testarray1.mat", ILMath.tofcomplex(ILMath.empty()));
            Test_StreamMatlab("testarray1.mat", ILMath.tofcomplex(ILMath.rand(10, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tofcomplex(ILMath.rand(1, 10)));
            Test_StreamMatlab("testarray1.mat", ILMath.tofcomplex(ILMath.rand(0, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tofcomplex(ILMath.rand(10, 100, 4)));

            Test_StreamMatlab("testarray1.mat", new ILArray <char>(new char[] { 'A', 'B', 'F' }));
            Test_StreamMatlab("testarray1.mat", new ILArray <char>(new char[] { 'A', 'B', 'F' }).T);
            Test_StreamMatlab("testarray1.mat", ILMath.tochar(ILMath.empty()));
            Test_StreamMatlab("testarray1.mat", ILMath.tochar(ILMath.rand(10, 1) * 250));
            Test_StreamMatlab("testarray1.mat", ILMath.tochar(ILMath.rand(1, 10) * 250));
            Test_StreamMatlab("testarray1.mat", ILMath.tochar(ILMath.rand(0, 1) * 250));
            Test_StreamMatlab("testarray1.mat", ILMath.tochar(ILMath.rand(10, 100, 4) * 250));

            Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.ones(1, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.empty()));
            Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.rand(10, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.rand(1, 10) * 255));
            Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.rand(0, 1) * 255));
            Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.rand(10, 100, 4) * 255));

            Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.ones(1, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.empty()) * 16000);
            Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.rand(10, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.rand(1, 10) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.rand(0, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.rand(10, 100, 4) * 16000));

            Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.ones(1, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.empty() * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.rand(10, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.rand(1, 10) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.rand(0, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.rand(10, 100, 4) * 16000));

            Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.ones(1, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.empty() * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.rand(10, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.rand(1, 10) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.rand(0, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.rand(10, 100, 4) * 16000));

            Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.ones(1, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.empty()));
            Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.rand(10, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.rand(1, 10)));
            Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.rand(0, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.rand(10, 100, 4)));
            Test_ImportMatlab2();
            Test_ImportMatlab();
            Test_NameRestrictions();
            // summary
            Footer();
        }