Ejemplo n.º 1
0
        // Initial plot setup, modify this as needed
        private void ilPanel1_Load(object sender, EventArgs e)
        {
            // create some test data, using our private computation module as inner class
            ILArray <float> Pos = Computation.CreateData(4, 300);

            // setup the plot (modify as needed)
            ilPanel1.Scene.Add(new ILPlotCube(twoDMode: false)
            {
                new ILLinePlot(Pos, tag: "mylineplot")
                {
                    Line =
                    {
                        Width        =         2,
                        Color        = Color.Red,
                        Antialiasing = true,
                        DashStyle    = DashStyle.Dotted
                    }
                }
            });
            // register event handler for allowing updates on right mouse click:
            ilPanel1.Scene.First <ILLinePlot>().MouseClick += (_s, _a) =>
            {
                if (_a.Button == MouseButtons.Right)
                {
                    Update(ILMath.rand(3, 30));
                }
            };
        }
Ejemplo n.º 2
0
 private void TestQuickSortLoop(int len, int rep)
 {
     try {
         m_stopwatch.Stop();
         m_stopwatch.Reset();
         for (int r = 0; r < rep; r++)
         {
             double[] p = ILMath.rand(1, len).m_data;
             m_stopwatch.Start();
             ILQuickSort.QuickSortAscSolid_IT(p, 0, len - 1, 1);
             m_stopwatch.Stop();
             if (!ILMath.IsSorted(p, false))
             {
                 throw new Exception("unsorted values detected (asc). Size: " + p.Length);
             }
             // descending
             ILQuickSort.QuickSortDescSolid_IT(p, 0, len - 1, 1);
             if (!ILMath.IsSorted(p, true))
             {
                 throw new Exception("unsorted values detected (desc). Size: " + p.Length);
             }
         }
         Success(" elapsed: " + m_stopwatch.ElapsedMilliseconds + " ms");
     } catch (Exception e) {
         Error(0, e.Message);
     }
 }
Ejemplo n.º 3
0
 // Initial plot setup, modify this as needed
 private void ilPanel1_Load(object sender, EventArgs e)
 {
     // setup the plot (modify as needed)
     ilPanel1.Scene.Add(new ILPlotCube(twoDMode: false)
     {
         new ILLinePlot(Points, tag: "points")
         {
             Line =
             {
                 Width        =         2,
                 Color        = Color.Red,
                 Antialiasing = true,
                 DashStyle    = DashStyle.Dotted
             }
         },
         new ILLinePlot(PointsPerceptron, tag: "points")
         {
             Line =
             {
                 Width        =          2,
                 Color        = Color.Blue,
                 Antialiasing = true,
                 DashStyle    = DashStyle.Dotted
             }
         }
     });
     // register event handler for allowing updates on right mouse click:
     ilPanel1.Scene.First <ILLinePlot>().MouseClick += (_s, _a) =>
     {
         if (_a.Button == MouseButtons.Right)
         {
             Update(ILMath.rand(3, 30));
         }
     };
 }
Ejemplo n.º 4
0
        // Initial plot setup, modify this as needed
        private void ilPanel1_Load(object sender, EventArgs e)
        {
            // create some test data, using our private computation module as inner class
            ILArray <float> Pos = Computation.CreateData(4, 300);

            Color color1 = System.Drawing.ColorTranslator.FromHtml("#1D8C00");
            Color color2 = System.Drawing.ColorTranslator.FromHtml("#FF3100");

            // setup the plot (modify as needed)
            ilPanel1.Scene.Add(new ILPlotCube(twoDMode: false)
            {
                new ILLinePlot(desiredOutput, tag: "mylineplot")
                {
                    Line =
                    {
                        Width     =           2,
                        Color     = Color.Green,
                        DashStyle = DashStyle.Dotted
                    }/*,
                      * Marker =
                      * {
                      * Size = 4,
                      * Style = MarkerStyle.Rectangle,
                      * ColorOverride = color1
                      * }*/
                },
                new ILLinePlot(realOutput, tag: "mylineplot")
                {
                    Line =
                    {
                        Width     =      2,
                        Color     = color2,
                        DashStyle = DashStyle.Dotted
                    }/*,
                      * Marker =
                      * {
                      * Size = 4,
                      * Style = MarkerStyle.Rectangle,
                      * ColorOverride = color2
                      * }*/
                },
                new ILLegend(@"Runge Kutta",
                             @"Perceptron")
                {
                    // legends are regular scene graph objects. This gives you complete freedom for
                    // further configuration ...
                    Background = { Color = Color.FromArgb(210, Color.White) }
                }
            });
            // register event handler for allowing updates on right mouse click:
            ilPanel1.Scene.First <ILLinePlot>().MouseClick += (_s, _a) =>
            {
                if (_a.Button == MouseButtons.Right)
                {
                    Update(ILMath.rand(3, 30));
                }
            };
        }
Ejemplo n.º 5
0
        public override ILCell GenerateTestArrays()
        {
            ILCell ret   = new ILCell();
            int    count = 0;
            // empty
            ILArray <double> tmp;

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

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

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

            // scalar
            ret[count++] = (ILArray <double>) 1.0;
            ret[count++] = (ILArray <double>) double.NaN;
            ret[count++] = (ILArray <double>) double.PositiveInfinity;
            ret[count++] = (ILArray <double>) double.NegativeInfinity;
            ret[count++] = (ILArray <double>) 0.0;
            ret[count++] = (ILArray <double>)(-30.0);
            // vector
            ret[count++] = ILMath.zeros(1, 10);
            ret[count++] = ILMath.ones(1, 10);
            ret[count++] = ILMath.zeros(10, 1);
            ret[count++] = ILMath.ones(10, 1);
            ret[count++] = ILMath.vector(0.0, 10.0);
            ret[count++] = ILMath.vector(-5.0, 4.0);

            tmp          = ILMath.vector(-5.0, 4.0);
            tmp[0]       = double.NegativeInfinity;
            tmp["end"]   = double.PositiveInfinity;
            tmp[3]       = double.NaN;
            ret[count++] = tmp;
            // matrix
            ret[count++] = ILMath.zeros(3, 2);
            ret[count++] = ILMath.rand(2, 4);
            ret[count++] = ILMath.ones(2, 3) * double.NaN;
            ret[count++] = ILMath.ones(3, 2) / 0.0; // inf
            tmp          = ILMath.ones(3, 2);
            tmp[0]       = double.NaN;
            ret[count++] = tmp;
            tmp[1]       = double.PositiveInfinity;
            ret[count++] = tmp;
            tmp[3]       = double.NegativeInfinity;
            ret[count++] = tmp;
            // 3d array
            ret[count++] = ILMath.zeros(4, 3, 2);
            ret[count++] = ILMath.ones(4, 3, 2);
            ret[count++] = 0.0 / ILMath.zeros(4, 3, 2);
            ret[count++] = ILMath.ones(4, 3, 2) * double.NaN;
            ret[count++] = ILMath.ones(4, 3, 2) * double.NegativeInfinity;
            ret[count++] = ILMath.rand(4, 3, 2);
            // 4d array
            ret[count++] = ILMath.rand(30, 2, 3, 20);

            return(ret);
        }
Ejemplo n.º 6
0
        public void Test_NameRestrictions()
        {
            int errorCode = 0;

            try {
                ILMatFile        ml = new ILMatFile();
                ILArray <double> A  = ILMath.rand(3, 23, 2);
                ml["hallo"] = A;
                ILBaseArray res = ml["hallo"];
                if (!res.Equals(A))
                {
                    throw new Exception("invalid array returned for : 'hallo'");
                }
                try {
                    ml[""] = A + 1;
                    throw new Exception("empty names are not allowed!");
                } catch (ILArgumentException) {
                    Info("empty name signaled correctly");
                }
                try {
                    ml["1fsdf"] = A + 1;
                    throw new Exception("names starting with numbers are not allowed!");
                } catch (ILArgumentException) {
                    Info("names starting with numbers signaled correctly");
                }
                try {
                    ml["invaldi name"] = A + 1;
                    throw new Exception("names with blank space are not allowed!");
                } catch (ILArgumentException) {
                    Info("names with blank space signaled correctly");
                }
                try {
                    ml["a$me"] = A + 1;
                    throw new Exception("names with invalid characters are not allowed!");
                } catch (ILArgumentException e) {
                    Info("names with invalid characters signaled correctly");
                }
                try {
                    A = (ILArray <double>)ml["hallo_"];
                    throw new Exception("key not found expected");
                } catch (ILArgumentException e) {
                    Info("missing key signaled correctly");
                }
                errorCode   = 2;
                ml["hallo"] = null;
                if (ml.Arrays.Length != 0)
                {
                    throw new Exception("unable to remove array from MatFile");
                }
                Success();
            } catch (Exception e) {
                Error(errorCode, e.Message);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 8
0
        private static string Info()
        {
            StringBuilder s = new StringBuilder();

            s.Append("This is the general test routine for ILNumerics.Net" + Environment.NewLine);
            s.Append("" + Environment.OSVersion + ", ");
            s.Append("Number of proc: " + Environment.ProcessorCount + ", " + Environment.NewLine);
            s.Append("CLR: " + Environment.Version + ", ");
            s.Append("Proc.memory: " + Environment.WorkingSet + "" + Environment.NewLine);
            ILMath.rand(1);
            ILCPUID cpuid = new ILCPUID();

            s.Append(String.Format("CPUID:{0}", cpuid.ToString()));
            return(s.ToString());
        }
Ejemplo n.º 9
0
        private void Form1_Load(object sender, EventArgs e)
        {
            m_panel = ILPanel.Create();
            Controls.Add(m_panel);

            ILArray <double> data = ILMath.rand(5, 7);
            ILBarGraph3D     bars = new ILBarGraph3D(m_panel, data);

            m_panel.Graphs.AddPlot(bars);
            bars.SetLabels(m_panel, "X-Label", "Y-Label", "",
                           new string[] { "Column 1", "Column 2", "Column 3", "Column 4", "Column 5", "Column 6", "Column 7" },
                           new string[] { "Row 1", "Row 2", "Row 3", "Row 4", "Row 5" });
            m_panel.PlotBoxScreenSizeMode = PlotBoxScreenSizeMode.StrictOptimal;
            m_panel.AspectRatio           = AspectRatioMode.StretchToFill;
        }
Ejemplo n.º 10
0
        private void Test_Test()
        {
            int errorCode = 0;

            try {
                ILCell C = new ILCell(2, 3);
                // than create another cell holding an ILArray<double>,
                ILCell Ci = new ILCell(2, 4);
                Ci[0] = ILMath.rand(4, 5);
                // store this as inner cell of C
                C[0] = Ci;
                Success();
            } catch (Exception e) {
                Error(errorCode, e.Message);
            }
        }
Ejemplo n.º 11
0
        public override ILCell GenerateTestArrays()
        {
            ILCell ret   = new ILCell();
            int    count = 0;
            // empty
            ILArray <short> tmp;

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

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

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

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

            tmp          = ILMath.toint16(ILMath.vector(-5.0, 4.0));
            tmp[0]       = short.MinValue;
            tmp["end"]   = short.MaxValue;
            tmp[3]       = 0;
            ret[count++] = tmp;
            // matrix
            ret[count++] = ILMath.toint16(ILMath.zeros(3, 2));
            ret[count++] = ILMath.toint16(ILMath.rand(2, 4));
            ret[count++] = ILMath.toint16(ILMath.ones(2, 3) * double.NaN);
            ret[count++] = ILMath.toint16(ILMath.ones(3, 2) / 0.0); // inf
            // 3d array
            ret[count++] = ILMath.toint16(ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.toint16(ILMath.ones(4, 3, 2));
            ret[count++] = ILMath.toint16(0.0 / ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.toint16(ILMath.ones(4, 3, 2) * short.MinValue);
            ret[count++] = ILMath.toint16(ILMath.rand(4, 3, 2) * short.MaxValue - (short.MaxValue / 2.0));
            // 4d array
            ret[count++] = ILMath.toint16(ILMath.rand(30, 2, 3, 20) * short.MaxValue - (short.MaxValue / 2.0));
            return(ret);
        }
Ejemplo n.º 12
0
        public override ILCell GenerateTestArrays()
        {
            ILCell ret   = new ILCell();
            int    count = 0;
            // empty
            ILArray <ulong> tmp;

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

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

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

            // scalar
            ret[count++] = (ILArray <ulong>)(ulong) 1;
            ret[count++] = (ILArray <ulong>)(ulong) uint.MaxValue;
            ret[count++] = (ILArray <ulong>)(ulong) uint.MinValue;
            ret[count++] = (ILArray <ulong>)(ulong) 0;
            ret[count++] = (ILArray <ulong>)(ulong)(30);
            // vector
            ret[count++] = ILMath.touint64(ILMath.zeros(1, 10));
            ret[count++] = ILMath.touint64(ILMath.ones(1, 10));
            ret[count++] = ILMath.touint64(ILMath.zeros(10, 1));
            ret[count++] = ILMath.touint64(ILMath.ones(10, 1));
            ret[count++] = ILMath.touint64(ILMath.vector(0.0, 10.0));
            ret[count++] = ILMath.touint64(ILMath.vector(0.0, 14.0));

            tmp          = ILMath.touint64(ILMath.vector(0, 14.0));
            tmp[0]       = uint.MinValue;
            tmp["end"]   = uint.MaxValue;
            tmp[3]       = 0;
            ret[count++] = tmp;
            // matrix
            ret[count++] = ILMath.touint64(ILMath.zeros(3, 2));
            ret[count++] = ILMath.touint64(ILMath.rand(2, 4));
            ret[count++] = ILMath.touint64(ILMath.ones(2, 3) * double.NaN);
            ret[count++] = ILMath.touint64(ILMath.ones(3, 2) / 0.0); // inf
            // 3d array
            ret[count++] = ILMath.touint64(ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.touint64(ILMath.ones(4, 3, 2));
            ret[count++] = ILMath.touint64(0.0 / ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.touint64(ILMath.ones(4, 3, 2) * uint.MinValue);
            ret[count++] = ILMath.touint64(ILMath.rand(4, 3, 2) * uint.MaxValue);
            // 4d array
            ret[count++] = ILMath.touint64(ILMath.rand(30, 2, 3, 20) * uint.MaxValue);
            return(ret);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
        public void Test_Basic()
        {
            int errorCode = 0;

            try {
                ILMemoryPool.Pool.Reset(100, 200);
                ILArray <double> A    = ILMath.rand(30, 30);
                double[]         aArr = A.m_data;
                ILArray <double> B    = A.C;
                A.Dispose();
                // A's array should be in pool now - query
                double[]         retArr = ILMemoryPool.Pool.New <double>(B.Dimensions.NumberOfElements);
                ILArray <double> Res    = new ILArray <double>(retArr, B.Dimensions);
                if (!Res.Equals(B) || aArr != retArr)
                {
                    throw new Exception("the expected array was not returned from pool!");
                }
                // query again - should return new array
                aArr = ILMemoryPool.Pool.New <double>(B.Dimensions.NumberOfElements);
                if (aArr == retArr)
                {
                    throw new Exception("after reclaiming array should be removed from pool!");
                }
                // test if zero cleares everything;
                Res.Dispose();
                Res = ILMath.zeros(B.Dimensions);
                // Res should have the same array, but cleared ?
                if (Res.m_data != retArr)
                {
                    throw new Exception("unexpected array returned from pool");
                }
                B = new ILArray <double>(new double[30 * 30], 30, 30);
                if (!Res.Equals(B))
                {
                    throw new Exception("invalid values - ILMath.zeros should return zeros!");
                }
                Success();
            } catch (Exception e) {
                Error(errorCode, e.Message);
            }
        }
Ejemplo n.º 15
0
 public override void Run()
 {
     Header();
     base.Run();
     TestQuickSortAscIDX(0, 15);
     TestQuickSortAscIDX(1, 12);
     TestQuickSortAscIDX(2, 100);
     TestQuickSortAscIDX(3, 1000);
     TestQuickSortDescIDX(0, 15);
     TestQuickSortDescIDX(1, 12);
     TestQuickSortDescIDX(2, 100);
     TestQuickSortDescIDX(3, 1000);
     TestQuickSortGen(ILMath.rand(2000, 1000) * 10, 1, true);
     TestQuickSortDesc();
     TestQuickSortAsc();
     Test_SortSpeed(100000);
     TestQuickSortDescIDX();
     TestQuickSortGen(ILMath.rand(1, 1000000) * 1000000.0, 1, true);
     TestQuickSortLoop(1000, 1000);
     TestQuickSort(ILMath.rand(1, 10).m_data);
     Footer();
 }
Ejemplo n.º 16
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();
        }
Ejemplo n.º 17
0
        private void SetExampleScene(ILPanel panel)
        {
            ILScene scene = new ILScene();

            try {
                ILLabel.DefaultFont = new System.Drawing.Font("Helvetica", 8);
                //ilPanel1.Driver = RendererTypes.GDI;

                #region upper left plot
                // prepare some data
                ILArray <float> P = 1,
                                x = ILMath.linspace <float>(-2, 2, 40),
                                y = ILMath.linspace <float>(2, -2, 40);

                ILArray <float> F = ILMath.meshgrid(x, y, P);
                // a simple RBF
                ILArray <float> Z = ILMath.exp(-(1.2f * F * F + P * P));
                // surface expects a single matrix
                Z[":;:;2"] = F; Z[":;:;1"] = P;

                // add a plot cube
                var pc = scene.Add(new ILPlotCube {
                    // shrink viewport to upper left quadrant
                    ScreenRect = new RectangleF(0.05f, 0, 0.4f, 0.5f),
                    // 3D rotation
                    TwoDMode = false,
                    Children =
                    {
                        // add surface
                        new ILSurface(Z)
                        {
                            // disable mouse hover marking
                            Fill      = { Markable = false },
                            Wireframe ={ Markable                 = false },
                            // make it shiny
                            UseLighting = true,
                            Children    = { new ILColorbar() }
                        },
                        //ILLinePlot.CreateXPlots(Z["1:10;:;0"], markers: new List<MarkerStyle>() {
                        //    MarkerStyle.None,MarkerStyle.None,MarkerStyle.None,MarkerStyle.None,MarkerStyle.Circle, MarkerStyle.Cross, MarkerStyle.Plus, MarkerStyle.TriangleDown }),
                        //new ILLegend("hi","n","ku","zs","le", "blalblalblalblalb\\color{red} hier gehts rot")
                    },
                    Rotation = Matrix4.Rotation(new Vector3(1.1f, -0.4f, -0.69f), 1.3f)
                });

                #endregion

                #region top right plot
                // create a gear shape
                var gear = new ILGear(toothCount: 30, inR: 0.5f, outR: 0.9f)
                {
                    Fill = { Markable = false, Color = Color.DarkGreen }
                };
                // group with right clipping plane
                var clipgroup = new ILGroup()
                {
                    Clipping = new ILClipParams()
                    {
                        Plane0 = new Vector4(1, 0, 0, 0)
                    },
                    Children =
                    {
                        // a camera holding the (right) clipped gear
                        new ILCamera()
                        {
                            // shrink viewport to upper top quadrant
                            ScreenRect = new RectangleF(0.5f, 0, 0.5f, 0.5f),
                            // populate interactive changes back to the global scene
                            IsGlobal = true,
                            // adds the gear to the camera
                            Children ={ gear                },
                            Position = new Vector3(0, 0, -15)
                        }
                    }
                };
                // setup the scene
                var gearGroup = scene.Add(new ILGroup {
                    clipgroup, clipgroup // <- second time: group is cloned
                });

                gearGroup.First <ILCamera>().Parent.Clipping = new ILClipParams()
                {
                    Plane0 = new Vector4(-1, 0, 0, 0)
                };
                // make the left side transparent green
                gearGroup.First <ILTriangles>().Color = Color.FromArgb(100, Color.Green);

                // synchronize both cameras; source: left side
                gearGroup.First <ILCamera>().PropertyChanged += (s, arg) => {
                    gearGroup.Find <ILCamera>().ElementAt(1).CopyFrom(s as ILCamera, false);
                };
                #endregion

                #region left bottom plot
                // start value
                int nrBalls = 10; bool addBalls = true;
                var balls = new ILPoints("balls")
                {
                    Positions = ILMath.tosingle(ILMath.randn(3, nrBalls)),
                    Colors    = ILMath.tosingle(ILMath.rand(3, nrBalls)),
                    Color     = null,
                    Markable  = false
                };
                var leftBottomCam = scene.Add(new ILCamera {
                    ScreenRect = new RectangleF(0, 0.5f, 0.5f, 0.5f),
                    Projection = Projection.Perspective,
                    Children   = { balls }
                });
                // funny label
                string harmony    = @"\color{red}H\color{blue}a\color{green}r\color{yellow}m\color{magenta}o\color{cyan}n\color{black}y\reset
";
                var    ballsLabel = scene.Add(new ILLabel(tag: "harmony")
                {
                    Text     = harmony,
                    Fringe   = { Color = Color.FromArgb(240, 240, 240) },
                    Position = new Vector3(-0.75f, -0.25f, 0)
                });
                long   oldFPS          = 1;
                PointF currentMousePos = new PointF();
                // setup the swarm. Start with a few balls, increase number
                // until framerate drops below 60 fps.
                ILArray <float> velocity = ILMath.tosingle(ILMath.randn(3, nrBalls));
                EventHandler <ILRenderEventArgs> updateBallsRenderFrame = (s, arg) => {
                    // transform viewport coords into 3d scene coords
                    Vector3 mousePos = new Vector3(currentMousePos.X * 2 - 1,
                                                   currentMousePos.Y * -2 + 1, 0);
                    // framerate dropped? -> stop adding balls
                    if (panel.FPS < oldFPS && panel.FPS < 60)
                    {
                        addBalls = false;
                    }
                    oldFPS = panel.FPS;
                    Computation.UpdateBalls(mousePos, balls, velocity, addBalls);
                    // balls buffers have been changed -> must call configure() to publish
                    balls.Configure();
                    // update balls label
                    ballsLabel.Text = harmony + "(" + balls.Positions.DataCount.ToString() + " balls)";
                };

                // saving the mouse position in MouseMove is easier for
                // transforming the coordinates into the viewport
                leftBottomCam.MouseMove += (s, arg) => {
                    // save the mouse position
                    currentMousePos = arg.LocationF;
                };
                panel.BeginRenderFrame += updateBallsRenderFrame;
                m_cleanUpExample        = () => {
                    leftBottomCam.MouseMove -= (s, arg) => {
                        // save the mouse position
                        currentMousePos = arg.LocationF;
                    };
                    panel.BeginRenderFrame -= updateBallsRenderFrame;
                };
                #endregion

                panel.Scene = scene;
            } catch (Exception exc) {
                System.Diagnostics.Trace.WriteLine("ILPanel_Load Error:");
                System.Diagnostics.Trace.WriteLine("====================");
                System.Diagnostics.Trace.WriteLine(exc.ToString());
                MessageBox.Show(exc.ToString());
            }
        }
Ejemplo n.º 18
0
        public override ILCell GenerateTestArrays()
        {
            ILCell ret   = new ILCell();
            int    count = 0;

            complex[] elements = new complex[] {
                new complex(0.0, 0.0),
                new complex(1.0, 0.0),
                new complex(1.0, 1.0),
                new complex(0.0, 1.0),
                new complex(-1.0, 0.0),
                new complex(-1.0, -1.0),
                new complex(0.0, -1.0),
                new complex(double.NaN, 0.0),
                new complex(double.NaN, 1.0),
                new complex(0.0, double.NaN),
                new complex(1.0, double.NaN),
                new complex(double.NaN, double.NaN),        // 11
                new complex(double.PositiveInfinity, 0.0),
                new complex(double.PositiveInfinity, 1.0),
                new complex(0.0, double.PositiveInfinity),
                new complex(1.0, double.PositiveInfinity),
                new complex(double.PositiveInfinity, double.PositiveInfinity),
                new complex(double.NegativeInfinity, 0.0),
                new complex(double.NegativeInfinity, 1.0),
                new complex(0.0, double.NegativeInfinity),
                new complex(1.0, double.NegativeInfinity),
                new complex(double.NegativeInfinity, double.NegativeInfinity),
                // mixed
                new complex(double.NaN, double.NegativeInfinity),
                new complex(double.NaN, double.PositiveInfinity),
                new complex(double.PositiveInfinity, double.NegativeInfinity),
                new complex(double.NegativeInfinity, double.PositiveInfinity),
                new complex(double.NaN, double.PositiveInfinity),
                new complex(double.NegativeInfinity, double.NaN),
                new complex(double.PositiveInfinity, double.NaN),
                new complex(double.MaxValue, double.NaN),
                new complex(double.MinValue, double.NaN),
                new complex(double.MaxValue, double.MinValue),
                new complex(double.NaN, double.MaxValue),
                new complex(double.NaN, double.MinValue),
                new complex(double.MaxValue, double.MinValue)
            };

            // empty
            ILArray <complex> tmp;

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

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

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

            // scalar
            foreach (complex elem in elements)
            {
                ret[count++] = (ILArray <complex>)elem;
            }
            // vector
            ret[count++] = ILArray <complex> .zeros(1, 10);

            ret[count++] = ILArray <complex> .zeros(1, 10) + elements[2];

            ret[count++] = ILArray <complex> .zeros(10, 1);

            ret[count++] = ILArray <complex> .zeros(10, 1) + elements[2];

            ret[count++] = ILMath.ccomplex(ILMath.vector(0.0, 10.0), ILMath.vector(0.0, 10.0));
            ret[count++] = ILMath.ccomplex(ILMath.vector(-5.0, 4.0), -ILMath.vector(-5.0, 4.0));

            tmp          = ILMath.ccomplex(ILMath.vector(-5.0, 4.0), -ILMath.vector(-5.0, 4.0));
            tmp[0]       = elements[22];
            tmp["end"]   = elements[25];
            tmp[3]       = elements[26];
            ret[count++] = tmp;
            // matrix
            ret[count++] = ILArray <complex> .zeros(3, 2);

            ret[count++] = ILMath.ccomplex(ILMath.rand(3, 4), ILMath.rand(3, 4));
            ret[count++] = ILMath.ccomplex(ILMath.ones(2, 3) * double.NaN, ILMath.ones(2, 3) * double.NaN);
            ret[count++] = ILMath.ccomplex(ILMath.ones(3, 2) / 0.0, ILMath.ones(3, 2) / 0.0); // inf
            tmp          = ILArray <complex> .zeros(3, 2) + elements[2];

            tmp[0]       = elements[11]; // nans
            ret[count++] = tmp;
            tmp[1]       = elements[15];
            ret[count++] = tmp;
            tmp[3]       = elements[20]; // neg inf
            ret[count++] = tmp;
            // 3d array
            ret[count++] = ILMath.ccomplex(ILMath.zeros(4, 3, 2), ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.ccomplex(ILMath.ones(4, 3, 2), ILMath.ones(4, 3, 2));
            ret[count++] = ILMath.ccomplex(0.0 / ILMath.zeros(4, 3, 2), 0.0 / ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.ccomplex(ILMath.ones(4, 3, 2) * float.NaN, ILMath.ones(4, 3, 2) * float.NaN);
            ret[count++] = ILMath.ccomplex(ILMath.ones(4, 3, 2) * float.NegativeInfinity, ILMath.ones(4, 3, 2) * float.NegativeInfinity);
            ret[count++] = ILMath.ccomplex(ILMath.rand(4, 3, 2), ILMath.rand(4, 3, 2));
            // 4d array
            ret[count++] = ILMath.ccomplex(ILMath.rand(15, 12, 3, 10), ILMath.rand(15, 12, 3, 10));

            return(ret);
        }