Exemplo n.º 1
0
        public void IllegalTensorMultiplicationTest()
        {
            // tensor a[2][1] = { [2.4], [5.1] }
            // tensor b[5][2] = { [1, 1],
            //                    [1, 1],
            //                    [1, 1],
            //                    [1, 1],
            //                    [1, 1] }
            // tensor c[2][2] = a*b;

            TensorInitNode aInit = new TensorInitNode();

            aInit.FirstRowElements = new List <ExpressionNode>()
            {
                new DoubleNode(2.4)
            };
            aInit.Elements = new List <ExpressionNode>()
            {
                new DoubleNode(5.1)
            };
            TensorDCLNode a = new TensorDCLNode("tensor", "a", 2, 1, aInit);

            TensorInitNode bInit = new TensorInitNode();

            bInit.FirstRowElements = new List <ExpressionNode>()
            {
                new DoubleNode(1), new DoubleNode(1)
            };
            bInit.Elements = new List <ExpressionNode>()
            {
                new DoubleNode(1), new DoubleNode(1),
                new DoubleNode(1), new DoubleNode(1),
                new DoubleNode(1), new DoubleNode(1),
                new DoubleNode(1), new DoubleNode(1)
            };
            TensorDCLNode b = new TensorDCLNode("tensor", "b", 5, 2, bInit);

            MultiplicationNode mulNode = new MultiplicationNode("*");

            mulNode.Left  = new IDNode("a");
            mulNode.Right = new IDNode("b");

            SymbolTable symbolTable             = new SymbolTable();
            TypeCheckSymbolTableVisitor visitor = new TypeCheckSymbolTableVisitor(symbolTable);

            visitor.Visit(a);
            visitor.Visit(b);
            Assert.ThrowsException <InvalidOperandsException>(() =>
            {
                visitor.Visit(mulNode);
            });
        }
Exemplo n.º 2
0
        public override Node VisitTensor_init(ML4DParser.Tensor_initContext context)
        {
            TensorInitNode tensorInitNode = new TensorInitNode();

            foreach (ML4DParser.ExprContext expr in context._firstRow)
            {
                tensorInitNode.FirstRowElements.Add((ExpressionNode)Visit(expr));
            }
            foreach (ML4DParser.ExprContext expr in context._elements)
            {
                tensorInitNode.Elements.Add((ExpressionNode)Visit(expr));
            }
            return(tensorInitNode);
        }
Exemplo n.º 3
0
        public override void Visit(TensorInitNode node)
        {
            base.Visit(node);

            foreach (ExpressionNode element in node.FirstRowElements)
            {
                if (element.Type is "bool" or "tensor")
                {
                    throw new TensorInitialisationException(node,
                                                            $"Incorrect element type: {element.Type}, only double and int are allowed");
                }
            }
            foreach (ExpressionNode element in node.Elements)
            {
                if (element.Type is "bool" or "tensor")
                {
                    throw new TensorInitialisationException(node,
                                                            $"Incorrect element type: {element.Type}, only double and int are allowed");
                }
            }
        }
Exemplo n.º 4
0
 public TensorInitialisationException(TensorInitNode node, string message) : base(message)
 {
     Node = node;
 }
Exemplo n.º 5
0
 public virtual void Visit(TensorInitNode node)
 {
 }