Пример #1
0
        /// <summary>
        /// Smaller operator of <![CDATA[ILArray<>]]> with scalar
        /// </summary>
        /// <param name="in1">ILArray</param>
        /// <param name="in2">Scalar</param>
        /// <returns>ILLogicalArray of same size than in1, with elements having 'true' values
        /// for all corresponding elements of in1 beeing smaller in2, false if they are not.
        /// </returns>
        /// <remarks>This operator is overloaded for
        /// all numeric types of <![CDATA[ILArray<>]]> for in1. The type of in2 is always double. </remarks>
        public static ILLogicalArray operator <(ILArray <BaseT> in1, double in2)
        {
            if (false)
            {
                #region HYCALPER LOOPSTART
            }
            else if (in1 is /*!HC:inCls1*/ ILArray <double> )
            {
                return(ILMath.lt(in1 as /*!HC:inCls1*/ ILArray <double>, (/*!HC:inArr2*/ double )in2));

                #endregion HYCALPER LOOPEND
                #region HYCALPER AUTO GENERATED CODE
// DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !!
            }
            else if (in1 is  ILArray <complex> )
            {
                return(ILMath.lt(in1 as  ILArray <complex>, ( complex )in2));
            }
            else if (in1 is  ILArray <byte> )
            {
                return(ILMath.lt(in1 as  ILArray <byte>, ( byte )in2));

                #endregion HYCALPER AUTO GENERATED CODE
            }
            else
            {
                throw new ILArgumentTypeException("Operator '<' is not defined for ILArrays of type "
                                                  + in1.GetType().Name);
            }
        }
 public static void forwBackwCheck2D(ILArray <double> A, ILArray <complex> Result)
 {
     try {
         ILArray <complex> B = fft2(A);
         //double errMult = 1/(A.Dimensions.NumberOfElements * Math.Pow(10,A.Dimensions.NumberOfDimensions));
         double errMult = Math.Pow(0.1, A.Dimensions.NumberOfDimensions) / A.Dimensions.NumberOfElements;
         if (!A.IsScalar)
         {
             errMult /= (double)A.Dimensions[A.Dimensions.FirstNonSingleton()];
         }
         if (sumall(abs(subtract(Result, B))) * errMult > (double)MachineParameterDouble.eps)
         {
             throw new Exception("invalid value");
         }
         ILArray <double> ResultR = ifft2sym(B);
         if (ILMath.sumall(ILMath.abs(ResultR - A)) * errMult > (double)ILMath.MachineParameterDouble.eps)
         {
             throw new Exception("invalid value");
         }
         B = ifft2(B);
         if (ILMath.sumall(ILMath.abs(ILMath.tocomplex(A) - B)) * errMult > (double)ILMath.MachineParameterDouble.eps)
         {
             throw new Exception("invalid value");
         }
     } catch (ILNumerics.Exceptions.ILArgumentException) {
         throw new Exception("unexpected exception was thrown -> error!");
     }
 }
Пример #3
0
        //protected static bool isempty(string str)
        //{
        //    return (str == string.Empty);
        //}

        protected static double randn()
        {
            //get
            {
                return((double)(ILMath.randn()));
            }
        }
        /// <summary>
        /// For optimization, we generate a column for the data matrix only once. The rows of the columns represent the configurations of the learning set.
        /// The cells contain the value of the feature in the respective configuration. (see comment on createDataMatrix(..) function for more detail).
        /// </summary>
        /// <param name="feature">The feature for which we compute the data column.</param>
        protected void generateDM_column(Feature feature)
        {
            ILArray <double> column = ILMath.zeros(this.learningSet.Count);

            if (feature.participatingBoolOptions.Count == 1 && feature.participatingNumOptions.Count == 0 && feature.participatingBoolOptions.Contains(this.infModel.Vm.Root))
            {
                for (int r = 0; r < this.learningSet.Count; r++)
                {
                    column[r] = 1;
                }
                this.DM_columns.Add(feature, column);
                return;
            }

            int i = 0;

            foreach (Configuration config in this.learningSet)
            {
                if (feature.validConfig(config))
                {
                    column[i] = feature.eval(config);
                }
                i++;
            }
            this.DM_columns.Add(feature, column);
        }
Пример #5
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));
        }
Пример #6
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);
            }
        }
Пример #7
0
        public void Test_LDA_Performance2000_var(int rep)
        {
            int errorCode = 0;

            try {
                LDA lda                 = new LDA();
                ILArray <double> X      = ILMath.horzcat(ILMath.randn(2, 2000) * 2.0, ILMath.randn(2, 2000) * -2.0);
                ILLogicalArray   labels = ILMath.tological(ILMath.horzcat(ILMath.ones(1, 2000), ILMath.zeros(1, 2000)));
                labels = labels.Concat(ILMath.tological(ILMath.zeros(1, 2000).Concat(ILMath.ones(1, 2000), 1)), 0);
                ILPerformer    timer = new ILPerformer();
                LDA.Hyperplane C;
                int            oldRefMin = ILNumerics.Settings.ILSettings.MinimumRefDimensions;
                ILNumerics.Settings.ILSettings.MinimumRefDimensions = 2;
                timer.Tic();
                for (int i = 0; i < rep; i++)
                {
                    C = lda.TrainLDA(X, labels, 0.4);
                }
                timer.Toc();
                Info("Test_LDA_Performance: with reference - data: 2x2000 run " + rep.ToString() + " times in: " + timer.Duration + "ms");
                ILNumerics.Settings.ILSettings.MinimumRefDimensions = 3;
                timer.Tic();
                for (int i = 0; i < rep; i++)
                {
                    C = lda.TrainLDA(X, labels, 0.4);
                }
                timer.Toc();
                ILNumerics.Settings.ILSettings.MinimumRefDimensions = oldRefMin;
                Info("Test_LDA_Performance: without reference - data: 2x2000 run " + rep.ToString() + " times in: " + timer.Duration + "ms");
                Success();
            }catch (Exception e) {
                Error(errorCode, e.Message);
            }
        }
Пример #8
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));
                }
            };
        }
Пример #9
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));
         }
     };
 }
Пример #10
0
        /// <summary>
        /// Computes FFT for the given sampleset.
        /// </summary>
        /// <param name="Samples">Sampleset on which to compute a FFT</param>
        public FFT(List <double> Samples, List <BandFrequencyDefinition> CustomBands = null)
        {
            using (ILScope.Enter())
            {
                ILInArray <double>   inArr  = Samples.ToArray();
                ILRetArray <complex> output = ILMath.fft(inArr);
                rawFFTOutput = output.ToArray();
            }

            ComputeFrequencyPowerSamples();

            //FrequencyBands
            ComputeAbsoluteBandPower(BandFrequencyDefinition.Delta);
            ComputeAbsoluteBandPower(BandFrequencyDefinition.Theta);
            ComputeAbsoluteBandPower(BandFrequencyDefinition.Alpha);
            ComputeAbsoluteBandPower(BandFrequencyDefinition.Beta);
            ComputeAbsoluteBandPower(BandFrequencyDefinition.Gamma);
            if (CustomBands != null)
            {
                foreach (BandFrequencyDefinition customBand in CustomBands)
                {
                    ComputeAbsoluteBandPower(customBand);
                }
            }
        }
Пример #11
0
        public ILArray </*!HC:HCretArr*/ complex> /*!HC:funcName*/ FFTForward(ILArray </*!HC:HCinArr*/ double> A, int firstDim, int nDims)
        {
            if (A == null || nDims < 0 || firstDim < 0)
            {
                throw new ILArgumentException("invalid parameter!");
            }
            if (A.IsEmpty)
            {
                return(ILArray </*!HC:HCretArr*/ complex> .empty(A.Dimensions));
            }
            if (A.IsScalar || (A.Dimensions[firstDim] == 1 && nDims == 1))
            {
                return /*!HC:convRet*/ (ILMath.tocomplex(A));
            }
            if (nDims > A.Dimensions.NumberOfDimensions)
            {
                nDims = A.Dimensions.NumberOfDimensions;
            }
            // prepare output array
            ILArray </*!HC:HCretArr*/ complex> ret = /*!HC:convRet*/ ILMath.tocomplex(A);
            IntPtr         plan  = IntPtr.Zero;
            int            hrank = 2;
            FFTW_DIRECTION dir   = /*!HC:HCdir*/ FFTW_DIRECTION.FORWARD;

            lock (_lockobject) {
                FFTW_PLANCREATION flags = FFTW_PLANCREATION.ESTIMATE;
                if (nDims > m_n.Length)
                {
                    resizeCache(nDims);
                }
                for (int i = 0; i < nDims; i++)
                {
                    m_n[i]  = A.Dimensions[i + firstDim];
                    m_is[i] = A.Dimensions.SequentialIndexDistance(i + firstDim);
                    m_os[i] = m_is[i];
                }
                m_hn[0]  = A.Dimensions.SequentialIndexDistance(firstDim);
                m_his[0] = 1;
                m_hos[0] = 1;
                m_his[1] = A.Dimensions.SequentialIndexDistance(nDims + firstDim);
                m_hn[1]  = A.Dimensions.NumberOfElements / m_his[1];
                m_hos[1] = m_his[1];
                fixed(/*!HC:HCretArr*/ complex *retArr = ret.m_data)
                {
                    /*!HC:HCplanfun*/ dfftw_plan_guru_dft_(ref plan, ref nDims, m_n, m_is, m_os,
                                                           ref hrank, m_hn, m_his, m_hos,
                                                           retArr, retArr,
                                                           ref dir, ref flags);
                }
            }
            if (plan == IntPtr.Zero)
            {
                throw new ILInvalidOperationException("error creating plan for fftw3 (guru interface)");
            }
            dfftw_execute_(ref plan);
            dfftw_destroy_plan_(ref plan);
            /*!HC:HCbackwScale*/

            return(ret);
        }
Пример #12
0
        private void PlotSurfaceBtn_Click(object sender, RoutedEventArgs e)
        {
            var B     = ILMath.tosingle(sigma);
            var scene = new PlotCube(twoDMode: false)
            {
                // add a surface
                new Surface(B)
                {
                    // make thin transparent wireframes
                    Wireframe = { Color = Color.FromArgb(50, Color.LightGray) },
                    // choose a different colormap
                    Colormap = Colormaps.Jet,
                }
            };

            scene.Axes.XAxis.Max = (float)arguments[0].Maximum;
            scene.Axes.XAxis.Min = (float)arguments[0].Minimum;
            scene.Axes.YAxis.Max = (float)arguments[1].Maximum;
            scene.Axes.YAxis.Min = (float)arguments[1].Minimum;
            scene.First <PlotCube>().Rotation = Matrix4.Rotation(new Vector3(1f, 0.23f, 1), 0.7f);

            PlotSurface form = new PlotSurface(scene);

            form.Refresh();
            form.ShowDialog();
        }
Пример #13
0
        public ILArray <double> GetInverseMatrixOfMatrix(ILArray <double> inputMatrix, int dimension)
        {
            ILArray <double> identityMatrix   = ILMath.eye(dimension, dimension);
            ILArray <double> inverseCovMatrix = ILMath.linsolve(inputMatrix, identityMatrix);

            return(inverseCovMatrix);
        }
Пример #14
0
        public double GetSDNLL_MDF(ILArray <double> mdfVector)
        {
            double firstPart  = 0;
            double secondPart = 0;
            double thirdPart  = 0;

            if (this.items.Count < 2)
            {
                this.covarianceMatrixMDF = this.GetVarianceMatrix_MDF();
            }

            int q = this.meanMDF.Length;

            // get matrix W
            ILArray <double> W        = this.GetMatrixW_MDF();
            ILArray <double> WInverse = this.GetInverseMatrixOfMatrix(W, q);

            /*if (Double.IsNaN(WInverse.ToArray()[0]))
             * {
             *  //throw new InvalidDataException("inverse of covariance matrix MDF is NaN");
             *  WInverse = ILMath.eye(this.parent.VarianceMDF.Length, this.parent.VarianceMDF.Length);
             *  Debug.Assert(true, "Problem with covariance gaussian matrix.");
             * }*/


            ILArray <double> vector1  = mdfVector - this.meanMDF;
            ILArray <double> tmpArray = ILMath.multiply(WInverse, vector1);

            firstPart  = 0.5 * ILMath.multiply(vector1.T, tmpArray).ToArray()[0];
            secondPart = q / 2 * ILMath.log(2 * Math.PI).ToArray()[0];
            thirdPart  = 0.5 * ILMath.log(ILMath.det(W)).ToArray()[0];

            return(firstPart + secondPart + thirdPart);
        }
Пример #15
0
        private static void sortIDXTestHelper001(int dim, int[] dims, ref ILArray <double> expectInd, int[] dimsEx)
        {
            int i;

            for (i = 0; i < dimsEx.Length; i++)
            {
                if (i <= dim)
                {
                    dimsEx[i] = dims[i];
                }
                else
                {
                    dimsEx[i] = 1;
                }
            }
            expectInd = ILMath.reshape(expectInd, dimsEx);
            for (i = 0; i < dimsEx.Length; i++)
            {
                if (i <= dim)
                {
                    dimsEx[i] = 1;
                }
                else
                {
                    dimsEx[i] = dims[i];
                }
            }
        }
Пример #16
0
        public ILArray <T> Load <T>()
        {
            int    i      = 0;
            int    nrow   = 0;
            int    ncol   = 0;
            string header = "";

            GetCotentInfo(ref nrow, ref ncol, ref header);
            ILArray <T>  array = ILMath.zeros <T>(nrow, ncol);
            StreamReader sr    = new StreamReader(_Filename);

            try
            {
                header = sr.ReadLine();
                string line = "";
                for (i = 0; i < nrow; i++)
                {
                    line = sr.ReadLine();
                    var buf = TypeConverterEx.Split <T>(line);
                    for (int j = 0; j < ncol; j++)
                    {
                        array.SetValue(buf[j], i, j);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
            sr.Close();

            return(array);
        }
Пример #17
0
        private void TestQuickSortDesc()
        {
            try {
                ILArray <double> A = ILMath.counter(5, 4, 3);
                System.Diagnostics.Debug.Assert(!A.IsReference);
                ILArray <double> result = ILMath.sort(A, 1, true);
                ILArray <double> expect = A[":;3,2,1,0;:"];
                if (!result.Equals(expect))
                {
                    throw new Exception("invalid values");
                }
                // test scalar
                A      = 3.0;
                result = ILMath.sort(A, 0, true);
                if (result != 3.0)
                {
                    throw new Exception("invalid values: scalar");
                }
                // test empty
                A = ILArray <double> .empty();

                if (!ILMath.sort(A, 0, true).IsEmpty)
                {
                    throw new Exception("invalid values: empty");
                }
                Success();
            } catch (Exception e) {
                Error(0, e.Message);
            }
        }
Пример #18
0
        private void Plot2D(int selectedFuncId)
        {
            var range = 7000;

            float[][]       points = _benchmark.GeneratePoints(range);
            ILArray <float> A      = ILMath.zeros <float>(3, points.GetLength(0));

            for (int i = 0; i < points.GetLength(0); i++)
            {
                A[0, i] = points[i][0];
                A[1, i] = CallFunction(selectedFuncId, points[i]);
            }


            _scene = new ILScene();
            _scene.Add(new ILPlotCube(twoDMode: true)
            {
                new ILPoints
                {
                    Positions = ILMath.tosingle(A)
                }
            });

            ilPanel1.Scene = _scene;
            ilPanel1.Refresh();

            return;
        }
Пример #19
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);
     }
 }
Пример #20
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();
        }
Пример #21
0
        // the callback from naudio
        void waveInStream_DataAvailable(object sender, WaveInEventArgs e)
        {
            if (m_shutdown)
            {
                return;
            }
            using (ILScope.Enter()) {
                // prepare variables for requesting X values and the index of the maximum value
                ILArray <int> maxID = 1;
                // convert the recorded samples in computation module:
                ILArray <float> Y = Computation.GetMagnitudes(e.Buffer, e.BytesRecorded, m_fftlen, maxID);
                // update the line shape
                Line.Update(Y);
                // update the marker point
                ILArray <float> markerPoints = ILMath.zeros <float>(2, maxID.S[0]);
                markerPoints[0, ":"] = ILMath.tosingle(maxID);
                markerPoints[1, ":"] = Y[maxID];
                Marker.Update(markerPoints);

                // on the first only run we zoom to content
                if (m_startup)
                {
                    m_startup = false;
                    ilPanel1.Scene.First <ILPlotCube>().Reset();
                }
                // redraw the scene
                ilPanel1.Refresh();
            }
        }
Пример #22
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));
 }
Пример #23
0
 private void Test_isConj(ILArray <complex> A, ILArray <complex> conjA)
 {
     try {
         if (A.IsEmpty)
         {
             if (!conjA.IsEmpty)
             {
                 throw new Exception("conj of empty array must be empty!");
             }
             else
             {
                 Success();
                 return;
             }
         }
         if (!A.Dimensions.IsSameSize(conjA.Dimensions))
         {
             throw new Exception("dimensions must match!");
         }
         if (ILMath.sumall(ILMath.real(A) != ILMath.real(conjA)) > 0.0)
         {
             throw new Exception("real parts must match!");
         }
         if (ILMath.sumall(-ILMath.imag(A) != ILMath.imag(conjA)) > 0.0)
         {
             throw new Exception("imag parts must be the inverse of each other!");
         }
         Success();
     } catch (Exception exc) {
         Error(exc.Message);
     }
 }
Пример #24
0
        public Bars AddBars(ILArray <double> barStart, ILArray <double> barEnd, ILArray <double> barPosition, ILArray <double> barThickness, BarType barType)
        {
            int n = barStart.Dimensions[0];

            if (barThickness.IsScalar)
            {
                barThickness = ILMath.ones(n) * barThickness;
            }
            Bars bars = new Bars(this, barStart, barEnd, barPosition, barThickness, barType);

            barsList.Add(bars);
            foreach (Path rectangle in bars.Paths)
            {
                canvas.Children.Add(rectangle);
                IBoundableFromChild.Add((object)(rectangle), bars);
            }
            if (graphToCanvas.Matrix.M11 != 0)
            {
                ViewedRegion = GetCanvasChildrenBounds();
            }
            else
            {
                ViewedRegion = bars.Bounds;
            }
            return(bars);
        }
Пример #25
0
        public DataCube(int nvar, int ntime, int ncell, bool islazy = false)
        {
            _isLazy = islazy;
            _nvar   = nvar;
            _ntime  = ntime;
            _ncell  = ncell;
            _size   = new int[] { nvar, ntime, ncell };
            _arrays = new ILArray <T> [nvar];
            if (!islazy)
            {
                for (int i = 0; i < nvar; i++)
                {
                    _arrays[i] = ILMath.zeros <T>(ntime, ncell);
                }
                DataCubeType = Data.DataCubeType.General;
            }
            else
            {
                DataCubeType = Data.DataCubeType.Varient;
            }
            Name = "default";
            PopulateVariables();
            InitFlags(Size[0], Size[1]);

            AllowTableEdit = false;
            TimeBrowsable  = false;
        }
Пример #26
0
        private void TestBucketSortArrayMatrixRow()
        {
            try {
                ILArray <string> A = new ILArray <string>(3, 4);
                A[0, 0] = "abc";
                A[0, 1] = "rtu";
                A[0, 2] = "sfkw";
                A[0, 3] = "lsdkfi";
                A[1, 0] = "iowejkc";
                A[1, 1] = "cjks";
                A[1, 2] = "wokys";
                A[1, 3] = "suem,";
                A[2, 0] = "fgj";
                A[2, 1] = "JKSF";
                A[2, 2] = "SEs";
                A[2, 3] = "SEFsr";
                ILArray <double> ind;
                ILArray <string> res = ILMath.sort(A, out ind, 0, false);
                if (!res.Equals(A[ind]))
                {
                    throw new Exception("invalid indices/values detected");
                }
                ILArray <Int16> indI = ILMath.toint16(ILMath.counter(0.0, 1.0, A.Dimensions.ToIntArray()));
                res = ILMath.sort(A, ref indI, 0, true, new ILASCIIKeyMapper());
                if (!res.Equals(A[indI]))
                {
                    throw new Exception("invalid indices/values detected");
                }

                Success(" elapsed: " + m_stopwatch.ElapsedMilliseconds + " ms");
            } catch (Exception e) {
                Error(0, e.Message);
            }
        }
 public static void forwBackwCheck1DAlongD(ILArray <float> A, ILArray <fcomplex> Result, int p)
 {
     try {
         ILArray <fcomplex> B = fft(A, p);
         //double errMult = 1/(A.Dimensions.NumberOfElements * Math.Pow(10,A.Dimensions.NumberOfDimensions));
         float errMult = (float)Math.Pow(0.1f, A.Dimensions.NumberOfDimensions) / A.Dimensions.NumberOfElements;
         if (!A.IsScalar)
         {
             errMult /= (float)A.Dimensions[A.Dimensions.FirstNonSingleton()];
         }
         if (sumall(abs(subtract(Result, B))) * errMult > (double)MachineParameterFloat.eps)
         {
             throw new Exception("invalid value");
         }
         ILArray <float> ResultR = ifftsym(B, p);
         if (ILMath.sumall(ILMath.abs(ResultR - A)) * errMult > (double)ILMath.MachineParameterFloat.eps)
         {
             throw new Exception("invalid value");
         }
         B = ifft(B, p);
         if (ILMath.sumall(ILMath.abs(ILMath.tofcomplex(A) - B)) * errMult > (double)ILMath.MachineParameterFloat.eps)
         {
             throw new Exception("invalid value");
         }
     } catch (ILNumerics.Exceptions.ILArgumentException) {
         throw new Exception("unexpected exception was thrown -> error!");
     }
 }
Пример #28
0
        private void ilPanel1_Load(object sender, EventArgs e)
        {
            var inrows = 0;

            inrows = inrows + 1;

            tempX.Add(float.Parse(Gyrox, CultureInfo.InvariantCulture));
            tempY.Add(float.Parse(Gyroy, CultureInfo.InvariantCulture));
            tempZ.Add(float.Parse(Gyroz, CultureInfo.InvariantCulture));

            ILArray <float> datasamples = ILMath.zeros <float>(3, (int)inrows);

            datasamples["0;:"] = tempX.ToArray();
            datasamples["1;:"] = tempY.ToArray();
            datasamples["2;:"] = tempZ.ToArray();

            tempX.Clear();
            tempY.Clear();
            tempZ.Clear();

            var scene = new ILScene
            {
                new ILPlotCube(twoDMode: false)
                {
                    new ILPoints
                    {
                        Positions = datasamples,
                        Color     = Color.Blue,
                        Size      = 10
                    }
                }
            };

            ilPanel1.Scene = scene;
        }
Пример #29
0
        private double calcVarianceFunctionIL(double[] xi, double[] xj, ILArray <double> dispersion)
        {
            ILArray <double> xiIL = xi;
            ILArray <double> xjIL = xj;

            return((double)ILMath.multiply(ILMath.multiply(xiIL.T, dispersion), xjIL));
        }
Пример #30
0
        /// <summary>
        /// greater operator of <![CDATA[ILArray<>]]> with <![CDATA[ILArray<>]]>
        /// </summary>
        /// <param name="in1"><![CDATA[ILArray<>]]></param>
        /// <param name="in2"><![CDATA[ILArray<>]]></param>
        /// <returns>ILLogicalArray of same size than in1, with elements having 'true' values
        /// for all corresponding elements of in1 greater in2's elements, false if they are not.
        /// </returns>
        /// <remarks>Dimension of in1 and in2 must match. This operator is overloaded for
        /// all numeric types of <![CDATA[ILArray<>]]>. The type of in1 must be the same as the
        /// type of in2.</remarks>
        public static ILLogicalArray operator >(ILArray <BaseT> in1, ILArray <BaseT> in2)
        {
            if (false)
            {
                #region HYCALPER LOOPSTART GT
            }
            else if (in1 is /*!HC:inCls1*/ ILArray <double> && in2 is /*!HC:inCls2*/ ILArray <double> )
            {
                return(ILMath.gt(in1 as /*!HC:inCls1*/ ILArray <double>, in2 as /*!HC:inCls2*/ ILArray <double>));

                #endregion HYCALPER LOOPEND GT
                #region HYCALPER AUTO GENERATED CODE
// DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !!
            }
            else if (in1 is  ILArray <complex> && in2 is  ILArray <complex> )
            {
                return(ILMath.gt(in1 as  ILArray <complex>, in2 as  ILArray <complex>));
            }
            else if (in1 is  ILArray <byte> && in2 is  ILArray <byte> )
            {
                return(ILMath.gt(in1 as  ILArray <byte>, in2 as  ILArray <byte>));

                #endregion HYCALPER AUTO GENERATED CODE
            }
            else
            {
                throw new ILArgumentTypeException("Operator '>' is not defined for ILArrays of type "
                                                  + in1.GetType().Name + " and " + in2.GetType().Name);
            }
        }