Ejemplo n.º 1
0
        public static void print(Stream output, ZMatrix mat, string format)
        {
            string type = "dense64";

            Console.WriteLine("Type = " + type + " complex , numRows = " + mat.getNumRows() + " , numCols = " +
                              mat.getNumCols());

            format += " ";

            Complex_F64 c = new Complex_F64();

            for (int y = 0; y < mat.getNumRows(); y++)
            {
                for (int x = 0; x < mat.getNumCols(); x++)
                {
                    mat.get(y, x, c);
                    Console.Write(format, c.real, c.imaginary);
                    if (x < mat.getNumCols() - 1)
                    {
                        Console.Write(" , ");
                    }
                }
                Console.WriteLine();
            }
        }
Ejemplo n.º 2
0
        public static void assertEquals(ZMatrix A, ZMatrix B, double tol)
        {
            assertShape(A, B);

            Complex_F64 a = new Complex_F64();
            Complex_F64 b = new Complex_F64();

            for (int i = 0; i < A.getNumRows(); i++)
            {
                for (int j = 0; j < A.getNumCols(); j++)
                {
                    A.get(i, j, a);
                    B.get(i, j, b);

                    assertTrue(!double.IsNaN(a.real) && !double.IsNaN(b.real),
                               "Real At (" + i + "," + j + ") A = " + a.real + " B = " + b.real);
                    assertTrue(!double.IsInfinity(a.real) && !double.IsInfinity(b.real),
                               "Real At (" + i + "," + j + ") A = " + a.real + " B = " + b.real);
                    assertTrue(Math.Abs(a.real - b.real) <= tol,
                               "Real At (" + i + "," + j + ") A = " + a.real + " B = " + b.real);

                    assertTrue(!double.IsNaN(a.imaginary) && !double.IsNaN(b.imaginary),
                               "Img At (" + i + "," + j + ") A = " + a.imaginary + " B = " + b.imaginary);
                    assertTrue(!double.IsInfinity(a.imaginary) && !double.IsInfinity(b.imaginary),
                               "Img At (" + i + "," + j + ") A = " + a.imaginary + " B = " + b.imaginary);
                    assertTrue(Math.Abs(a.imaginary - b.imaginary) <= tol,
                               "Img At (" + i + "," + j + ") A = " + a.imaginary + " B = " + b.imaginary);
                }
            }
        }
Ejemplo n.º 3
0
        public override void set(Matrix original)
        {
            reshape(original.getNumRows(), original.getNumCols());

            ZMatrix n = (ZMatrix)original;

            Complex_F64 c = new Complex_F64();

            for (int i = 0; i < numRows; i++)
            {
                for (int j = 0; j < numCols; j++)
                {
                    n.get(i, j, c);
                    set(i, j, c.real, c.imaginary);
                }
            }
        }
Ejemplo n.º 4
0
        public virtual void setTo(Matrix original)
        {
            reshape(original.NumRows, original.NumCols);

            ZMatrix n = (ZMatrix)original;

            Complex_F64 c = new Complex_F64();

            for (int i = 0; i < numRows; i++)
            {
                for (int j = 0; j < numCols; j++)
                {
                    n.get(i, j, c);
                    set(i, j, c.real, c.imaginary);
                }
            }
        }
    {/**
      * Generic, but slow, conversion function.
      *
      * @param input Input matrix.
      * @param output Output matrix.
      */
     /*
      * public static void convert(DMatrix input, FMatrix output)
      * {
      *  if (input.NumRows != output.NumRows)
      *      throw new ArgumentException("Number of rows do not match");
      *  if (input.NumCols != output.NumCols)
      *      throw new ArgumentException("Number of columns do not match");
      *
      *  for (int i = 0; i < input.NumRows; i++)
      *  {
      *      for (int j = 0; j < input.NumCols; j++)
      *      {
      *          output.unsafe_set(i, j, (float)input.unsafe_get(i, j));
      *      }
      *  }
      * }*/

        public static void convert(DMatrix input, ZMatrix output)
        {
            if (input.NumRows != output.NumRows)
            {
                throw new ArgumentException("Number of rows do not match");
            }
            if (input.NumCols != output.NumCols)
            {
                throw new ArgumentException("Number of columns do not match");
            }

            for (int i = 0; i < input.NumRows; i++)
            {
                for (int j = 0; j < input.NumCols; j++)
                {
                    output.set(i, j, input.unsafe_get(i, j), 0);
                }
            }
        }
        public static void printFancy(ZMatrix mat, int length)
        {
            // TODO print en consola

            /*
             * printTypeSize(out, mat);
             * DecimalFormat format = new DecimalFormat("#");
             *
             * final int cols = mat.getNumCols();
             *
             * for (int row = 0; row < mat.getNumRows(); row++)
             * {
             *  for (int col = 0; col < cols; col++)
             *  {
             *  out.print(fancyStringF(mat.get(row, col), format, length, 4));
             *      if (col != cols - 1)
             *      out.print(" ");
             *  }
             * out.println();
             * }
             */
        }
Ejemplo n.º 7
0
        /**
         * Checks to see if the provided matrix is within tolerance to an identity matrix.
         *
         * @param mat Matrix being examined.  Not modified.
         * @param tol Tolerance.
         * @return True if it is within tolerance to an identify matrix.
         */
        public static bool isIdentity(ZMatrix mat, double tol)
        {
            // see if the result is an identity matrix
            Complex_F64 c = new Complex_F64();

            for (int i = 0; i < mat.getNumRows(); i++)
            {
                for (int j = 0; j < mat.getNumCols(); j++)
                {
                    mat.get(i, j, c);
                    if (i == j)
                    {
                        if (!(Math.Abs(c.real - 1) <= tol))
                        {
                            return(false);
                        }
                        if (!(Math.Abs(c.imaginary) <= tol))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (!(Math.Abs(c.real) <= tol))
                        {
                            return(false);
                        }
                        if (!(Math.Abs(c.imaginary) <= tol))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 8
0
        public static void print(Stream output, ZMatrix mat, int numChar, int precision)
        {
            string format = "%" + numChar + "." + precision + "f + %" + numChar + "." + precision + "fi";

            print(output, mat, format);
        }
Ejemplo n.º 9
0
 public static void print(Stream output, ZMatrix mat)
 {
     print(output, mat, 6, 3);
 }