Ejemplo n.º 1
0
        public void TestAdd2()
        {
            int[][] matrix = new int[][]
            {
                new [] { 1, 0, 0 },
                new [] { 0, 1, 0 },
                new [] { 0, 0, 1 }
            };

            var matrix1 = new SymmetricalMatrix <int>(matrix);

            int[][] matrixx = new int[][]
            {
                new [] { 1, 0, 0 },
                new [] { 0, 1, 0 },
                new [] { 0, 0, 1 }
            };

            var matrix2 = new DiagonalMatrix <int>(matrixx);

            int[][] expected = new int[][]
            {
                new [] { 2, 0, 0 },
                new [] { 0, 2, 0 },
                new [] { 0, 0, 2 }
            };


            var actual = new MatrixVisitor <int>().Add(matrix1, matrix2);

            CollectionAssert.AreEqual(expected, actual.ToArray());
        }
Ejemplo n.º 2
0
        public void TestAdd()
        {
            int[][] matrix = new int[][]
            {
                new[] { 1, 2, 3, 5 },
                new[] { 11, 2, -3, 5 },
                new[] { 0, 122, -1, 11 },
                new[] { 0, 0, 0, 0 }
            };

            var matrix1 = new DiagonalMatrix <int>(matrix);

            int[][] matrixx = new int[][]
            {
                new[] { 1, 2, 3, 5 },
                new[] { 11, 2, -3, 5 },
                new[] { 0, 122, -1, 11 },
                new[] { 0, 0, 0, 0 }
            };

            var matrix2 = new SquareMatrix <int>(matrixx);

            int[][] expected = new int[][]
            {
                new[] { 2, 2, 3, 5 },
                new[] { 11, 4, -3, 5 },
                new[] { 0, 122, -2, 11 },
                new[] { 0, 0, 0, 0 }
            };


            var actual = new MatrixVisitor <int>().Add(matrix1, matrix2);

            CollectionAssert.AreEqual(expected, actual.ToArray());
        }
Ejemplo n.º 3
0
 public static void Visit <T>(this T[,] matrix, MatrixVisitor <T> visitor)
 {
     for (var x = 0; x < matrix.GetLength(0); x++)
     {
         for (var y = 0; y < matrix.GetLength(1); y++)
         {
             visitor(matrix[x, y], x, y);
         }
     }
 }
Ejemplo n.º 4
0
        public static void VisitRect <T>(this T[,] matrix, int x, int y, int r, MatrixVisitor <T> visitor)
        {
            var x0 = Math.Max(0, x - r);
            var y0 = Math.Max(0, y - r);
            var x1 = Math.Min(matrix.GetLength(0), x + r);
            var y1 = Math.Min(matrix.GetLength(1), y + r);

            for (var xi = x0; xi <= x1; xi++)
            {
                for (var yi = y0; yi <= y1; yi++)
                {
                    visitor(matrix[xi, yi], xi, yi);
                }
            }
        }
Ejemplo n.º 5
0
        // Parameters //
        public static HParameterSet GetHParameter(Workspace Home, HScriptParser.Hparameter_setContext context)
        {

            // Create a set //
            HParameterSet parmset = new HParameterSet();

            // Step one: cycle through all parameters and look for any tables //
            DataSet first_data = null;
            List<HScriptParser.HparameterContext> param_context = new List<HScriptParser.HparameterContext>();
            foreach (HScriptParser.HparameterContext ctx in context.hparameter())
            {

                if (ctx.full_table_name() != null)
                {
                    DataSet d = VisitorHelper.GetData(Home, ctx.full_table_name());
                    if (first_data == null)
                        first_data = d;
                    parmset.Add(ctx.SCALAR().GetText(), d);
                }
                else
                    param_context.Add(ctx);

            }

            ExpressionVisitor exp_vis =
                first_data != null
                ? new ExpressionVisitor(null, Home, first_data.Name, first_data.Columns, new StaticRegister(null)) 
                : new ExpressionVisitor(null, Home);

            MatrixVisitor mat_vis = new MatrixVisitor(Home, null, exp_vis);

            foreach (HScriptParser.HparameterContext ctx in param_context)
            {

                string name = ctx.SCALAR().GetText();
                if (ctx.expression() != null)
                    parmset.Add(name, exp_vis.ToNode(ctx.expression()));
                else if (ctx.expression_alias_list() != null)
                    parmset.Add(name, exp_vis.ToNodes(ctx.expression_alias_list()));
                else if (ctx.lambda_unit() != null)
                    parmset.Add(name, VisitorHelper.RenderLambda(Home, ctx.lambda_unit()));
                else if (ctx.matrix_expression() != null)
                    parmset.Add(name, mat_vis.ToMatrix(ctx.matrix_expression()));
                else if (ctx.K_OUT() != null)
                    parmset.Add(name, Home.GlobalHeap.Scalars, ctx.IDENTIFIER().GetText());

            }

            return parmset;

        }
Ejemplo n.º 6
0
        public static void AllocateMemory(Workspace Home, MemoryStruct Heap, ExpressionVisitor Evaluator, HScriptParser.DeclareMatrixLiteralContext context)
        {

            string name = context.IDENTIFIER().GetText();
            CellAffinity type = GetAffinity(context.type());
            MatrixVisitor vis = new MatrixVisitor(Home, Heap, Evaluator);
            CellMatrix mat = vis.ToMatrix(context.matrix_expression()).Evaluate();
            Heap.Arrays.Reallocate(name, mat);

        }
Ejemplo n.º 7
0
        internal static DeclareMatrixNode RenderDeclareNode(Workspace Home, ExpressionVisitor Evaluator, HScriptParser.DeclareMatrixLiteralContext context)
        {

            string name = context.IDENTIFIER().GetText();
            MatrixVisitor MEvaluator = new MatrixVisitor(Home, Home.GlobalHeap, Evaluator);
            MNode node = MEvaluator.ToMatrix(context.matrix_expression());
            return new DeclareMatrixNode(Home.GlobalHeap, name, node);

        }