Exemplo n.º 1
0
        public static NRealMatrix operator *(NRealMatrix a, NRealMatrix b)
        {
            var c = new MCJRMatrix();

            NLapackSingleton.Instance.multiply(a.ManagedMatrix, b.ManagedMatrix, c);
            return(new NRealMatrix(c));
        }
Exemplo n.º 2
0
        public double SleTestBig(int size)
        {
            var mat1 = new MCJRMatrix(size, size);
            var mat2 = new MCJRMatrix(size, size);

            var random = new Random();

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    mat1.setAt(i, j, random.NextDouble());
                    mat2.setAt(i, j, random.NextDouble());
                }
            }

            var time = DateTime.Now;
            var lib  = new MLapackLib();

            var result = new MCJRMatrix(size, size);

            Console.WriteLine("multiplication started...");


            lib.solveSLE(mat1, mat2, result);


            Console.WriteLine("multiplication completed.");

            double ms = (DateTime.Now - time).TotalMilliseconds;

            Console.WriteLine("time = " + ms);
            return(ms);
        }
Exemplo n.º 3
0
        public double SvdzTestBig(int size)
        {
            var mat1 = new MCJCMatrix(size, size);

            var random = new Random();

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    mat1.setAt(i, j, random.NextDouble(), 0);
                }
            }

            var lib = new MLapackLib();

            Console.WriteLine("multiplication started...");

            var s  = new MCJRMatrix();
            var u  = new MCJCMatrix();
            var vt = new MCJCMatrix();

            var time = DateTime.Now;

            lib.SVDDecomposition(mat1, s, u, vt);

            double ms = (DateTime.Now - time).TotalMilliseconds;

            Console.WriteLine("time = " + ms);
            return(ms);
        }
Exemplo n.º 4
0
        public void TestMult()
        {
            var lib = new MLapackLib();

            var mat1 = new MCJRMatrix(2, 3);

            mat1.setAt(0, 0, 1);
            mat1.setAt(0, 1, 2);
            mat1.setAt(0, 2, 3);

            mat1.setAt(1, 0, 4);
            mat1.setAt(1, 1, 5);
            mat1.setAt(1, 2, 6);

            var mat2 = new MCJRMatrix(3, 2);

            mat2.setAt(0, 0, 1);
            mat2.setAt(0, 1, 2);

            mat2.setAt(1, 0, 3);
            mat2.setAt(1, 1, 4);

            mat2.setAt(2, 0, 5);
            mat2.setAt(2, 1, 6);

            var mat3 = new MCJRMatrix();

            lib.multiply(mat1, mat2, mat3);
            PrintMatrix(mat3);
        }
Exemplo n.º 5
0
        private static void CalcNorm(MCJRMatrix matrix, MatrixNormType normType)
        {
            var    lib  = new MLapackLib();
            double norm = lib.norm(Convert.ToSByte(normType), matrix);

            Console.WriteLine("norm = " + norm);
        }
Exemplo n.º 6
0
        public static NRealMatrix operator !(NRealMatrix a)
        {
            var c = new MCJRMatrix();

            NLapackSingleton.Instance.inv(a.ManagedMatrix, c);
            return(new NRealMatrix(c));
        }
Exemplo n.º 7
0
        public void PrintMatrix(MCJRMatrix matrix)
        {
            int rows = matrix.rows();
            int cols = matrix.cols();

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    Console.Write(matrix.getAt(i, j) + " ");
                }
                Console.WriteLine("");
            }
        }
Exemplo n.º 8
0
        public void TestNorm()
        {
            var mat1 = new MCJRMatrix(3, 2);

            mat1.setAt(0, 0, 8);
            mat1.setAt(0, 1, 8);

            mat1.setAt(1, 0, 3);
            mat1.setAt(1, 1, -2);

            mat1.setAt(2, 0, 8);
            mat1.setAt(2, 1, -8);

            CalcNorm(mat1, MatrixNormType.Frobenius);
        }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        public void TestMultBig()
        {
            for (int size = 100; size <= 4500; size += 100)
            {
                try
                {
                    Console.WriteLine(size);
                    var mat1 = new MCJRMatrix(size, size);

                    var random = new Random();

                    for (int i = 0; i < size; i++)
                    {
                        for (int j = 0; j < size; j++)
                        {
                            mat1.setAt(i, j, random.NextDouble());
                        }
                    }


                    var mat2 = new MCJRMatrix(size, size);

                    for (int i = 0; i < size; i++)
                    {
                        for (int j = 0; j < size; j++)
                        {
                            mat2.setAt(i, j, random.NextDouble());
                        }
                    }

                    var mat3 = new MCJRMatrix();

                    var time = DateTime.Now;
                    var lib  = new MLapackLib();

                    Console.WriteLine("multiplication started...");
                    lib.multiply(mat1, mat2, mat3);

                    Console.WriteLine("multiplication completed.");

                    Console.WriteLine("size = " + size + "time = " + (DateTime.Now - time).TotalMilliseconds);
                }
                catch (Exception)
                {
                    Console.WriteLine("exception");
                }
            }
        }
Exemplo n.º 10
0
        public void TestInv()
        {
            var mat1 = new MCJRMatrix(2, 2);

            mat1.setAt(0, 0, 1);
            mat1.setAt(0, 1, 2);

            mat1.setAt(1, 0, 3);
            mat1.setAt(1, 1, 4);

            var lib = new MLapackLib();

            var result = new MCJRMatrix();

            lib.inv(mat1, result);

            PrintMatrix(result);
        }
Exemplo n.º 11
0
        public double TestMultdBig(int size)
        {
            var mat1 = new MCJRMatrix(size, size);

            var random = new Random();

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    mat1.setAt(i, j, random.NextDouble());
                }
            }


            var mat2 = new MCJRMatrix(size, size);

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    mat2.setAt(i, j, random.NextDouble());
                }
            }

            var mat3 = new MCJRMatrix();

            var time = DateTime.Now;

            Console.WriteLine("multiplication started...");

            var lib = new MLapackLib();

            lib.multiply(mat1, mat2, mat3);

            double elapsedTime = (DateTime.Now - time).TotalMilliseconds;

            Console.WriteLine("multiplication completed.");

            Console.WriteLine("size = " + size + "time = " + (DateTime.Now - time).TotalMilliseconds);

            return(elapsedTime);
        }
Exemplo n.º 12
0
        public void GetAtSetAtTest()
        {
            var mat = new MCJRMatrix();

            const int size = 5000;

            mat.allocate(size, size);

            var random = new Random();


            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    double value = random.NextDouble();
                    mat.setAt(i, j, value);
                }
            }
        }
Exemplo n.º 13
0
        public void PrintMatrix(MCJRMatrix matrix)
        {
            int rows = matrix.rows();
            int cols = matrix.cols();

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    Console.Write(matrix.getAt(i, j) + " ");
                }
                Console.WriteLine("");
            }
        }
Exemplo n.º 14
0
 public NRealMatrix()
 {
     _mat = new MCJRMatrix();
 }
Exemplo n.º 15
0
        public void TestNorm()
        {
            var mat1 = new MCJRMatrix(3, 2);

            mat1.setAt(0, 0, 8);
            mat1.setAt(0, 1, 8);

            mat1.setAt(1, 0, 3);
            mat1.setAt(1, 1, -2);

            mat1.setAt(2, 0, 8);
            mat1.setAt(2, 1, -8);

            CalcNorm(mat1, MatrixNormType.Frobenius);
        }
Exemplo n.º 16
0
        private static void CalcNorm(MCJRMatrix matrix, MatrixNormType normType)
        {
            var lib = new MLapackLib();
            double norm = lib.norm(Convert.ToSByte(normType), matrix);

            Console.WriteLine("norm = " + norm);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 
        /// </summary>
        public void TestMultBig()
        {
            for (int size = 100; size <= 4500; size += 100)
            {
                try
                {
                    Console.WriteLine(size);
                    var mat1 = new MCJRMatrix(size, size);

                    var random = new Random();

                    for (int i = 0; i < size; i++)
                    {
                        for (int j = 0; j < size; j++)
                        {
                            mat1.setAt(i, j, random.NextDouble());
                        }
                    }

                    var mat2 = new MCJRMatrix(size, size);

                    for (int i = 0; i < size; i++)
                    {
                        for (int j = 0; j < size; j++)
                        {
                            mat2.setAt(i, j, random.NextDouble());
                        }
                    }

                    var mat3 = new MCJRMatrix();

                    var time = DateTime.Now;
                    var lib = new MLapackLib();

                    Console.WriteLine("multiplication started...");
                    lib.multiply(mat1, mat2, mat3);

                    Console.WriteLine("multiplication completed.");

                    Console.WriteLine("size = " + size + "time = " + (DateTime.Now - time).TotalMilliseconds);

                }
                catch (Exception)
                {

                    Console.WriteLine("exception");
                }
            }
        }
Exemplo n.º 18
0
        public double TestMultdBig(int size)
        {
            var mat1 = new MCJRMatrix(size, size);

            var random = new Random();

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    mat1.setAt(i, j, random.NextDouble());
                }
            }

            var mat2 = new MCJRMatrix(size, size);

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    mat2.setAt(i, j, random.NextDouble());
                }
            }

            var mat3 = new MCJRMatrix();

            var time = DateTime.Now;
            Console.WriteLine("multiplication started...");

            var lib = new MLapackLib();

            lib.multiply(mat1, mat2, mat3);

            double elapsedTime = (DateTime.Now - time).TotalMilliseconds;

            Console.WriteLine("multiplication completed.");

            Console.WriteLine("size = " + size + "time = " + (DateTime.Now - time).TotalMilliseconds);

            return elapsedTime;
        }
Exemplo n.º 19
0
        public void TestMult()
        {
            var lib = new MLapackLib();

            var mat1 = new MCJRMatrix(2, 3);
            mat1.setAt(0, 0, 1);
            mat1.setAt(0, 1, 2);
            mat1.setAt(0, 2, 3);

            mat1.setAt(1, 0, 4);
            mat1.setAt(1, 1, 5);
            mat1.setAt(1, 2, 6);

            var mat2 = new MCJRMatrix(3, 2);

            mat2.setAt(0, 0, 1);
            mat2.setAt(0, 1, 2);

            mat2.setAt(1, 0, 3);
            mat2.setAt(1, 1, 4);

            mat2.setAt(2, 0, 5);
            mat2.setAt(2, 1, 6);

            var mat3 = new MCJRMatrix();
            lib.multiply(mat1, mat2, mat3);
            PrintMatrix(mat3);
        }
Exemplo n.º 20
0
        public void TestInv()
        {
            var mat1 = new MCJRMatrix(2, 2);
            mat1.setAt(0, 0, 1);
            mat1.setAt(0, 1, 2);

            mat1.setAt(1, 0, 3);
            mat1.setAt(1, 1, 4);

            var lib = new MLapackLib();

            var result = new MCJRMatrix();
            lib.inv(mat1, result);

            PrintMatrix(result);
        }
Exemplo n.º 21
0
        public double SvdzTestBig(int size)
        {
            var mat1 = new MCJCMatrix(size, size);

            var random = new Random();

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    mat1.setAt(i, j, random.NextDouble(), 0);
                }
            }

            var lib = new MLapackLib();

            Console.WriteLine("multiplication started...");

            var s = new MCJRMatrix();
            var u = new MCJCMatrix();
            var vt = new MCJCMatrix();

            var time = DateTime.Now;
            lib.SVDDecomposition(mat1, s, u, vt);

            double ms = (DateTime.Now - time).TotalMilliseconds;
            Console.WriteLine("time = " + ms);
            return ms;
        }
Exemplo n.º 22
0
        public void GetAtSetAtTest()
        {
            var mat = new MCJRMatrix();

            const int size = 5000;

            mat.allocate(size, size);

            var random = new Random();

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    double value = random.NextDouble();
                    mat.setAt(i, j, value);
                }
            }
        }
Exemplo n.º 23
0
 public NRealMatrix(int rows, int cols)
 {
     _mat = new MCJRMatrix(rows, cols);
 }
Exemplo n.º 24
0
 public NRealMatrix(MCJRMatrix matrix)
 {
     _mat = matrix;
 }
Exemplo n.º 25
0
        public double SleTestBig(int size)
        {
            var mat1 = new MCJRMatrix(size, size);
            var mat2 = new MCJRMatrix(size, size);

            var random = new Random();

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    mat1.setAt(i, j, random.NextDouble());
                    mat2.setAt(i, j, random.NextDouble());
                }
            }

            var time = DateTime.Now;
            var lib = new MLapackLib();

            var result = new MCJRMatrix(size, size);

            Console.WriteLine("multiplication started...");

            lib.solveSLE(mat1, mat2, result);

            Console.WriteLine("multiplication completed.");

            double ms = (DateTime.Now - time).TotalMilliseconds;
            Console.WriteLine("time = " + ms);
            return ms;
        }