public void CanParseIndexExpression()
        {
            var A = Tensor.TwoD("A", (4, 3), "a", out Index a, out Index b);
            var B = Tensor.TwoD("B", (6, 7));
            var C = Tensor.TwoD("C", (8, 9));
            TensorExpression te = A[a, b];

            Assert.Single(te.TensorReferences);
            Assert.Equal(A, te.TensorReferences.First());

            TensorExpressionVisitor v = new TensorExpressionVisitor(te);

            Assert.Equal(5, v.Tree.Count);
            Assert.Equal(TensorOp.Index, v.Tree.OperatorNodeAtIndex(2).Op);
            Assert.NotNull(v.Tree.OperatorNodeAtIndex(2).Left);
            Assert.NotNull(v.Tree.OperatorNodeAtIndex(2).Right);
            Assert.IsType <Tensor>(v.Tree.ValueNodeAtIndex(3).Value);
            Assert.IsType <IndexSet>(v.Tree.ValueNodeAtIndex(4).Value);

            IndexSet s = v.Tree.ValueNodeAtIndex(4).ValueAs <IndexSet>();

            Assert.Equal(2, s.Indices.Count);
            Assert.Equal(1, s.Indices.ElementAt(1).Order);
            Assert.Equal("b", s.Indices.ElementAt(1).Name);
        }
Esempio n. 2
0
 public Kernel(Tensor output, TensorExpression expr)
 {
     output.def  = expr;
     Tree        = output.ToTree();
     InputShapes = InputTensors;
     OutputShape = output;
 }
Esempio n. 3
0
        public void CanConstructGraphDiagram()
        {
            var A = Tensor.TwoD("A", (4, 3), "a", out Index a, out Index b);
            var B = Tensor.TwoD("B", (6, 7));
            var C = Tensor.TwoD("C", (8, 9));
            TensorExpression te = A[a, b];

            GraphDiagram d = new GraphDiagram(te.ToTree());

            Assert.Equal(4, d.Graph.NodeCount);
            Assert.Equal(3, d.Graph.EdgeCount);

            te = A[a, b] * C[a, b];
            d  = new GraphDiagram(te.ToTree());
        }
Esempio n. 4
0
 public Kernel(TensorExpression expr, ICompiler compiler, DeviceType deviceType = DeviceType.CPU)
     : this(new Tensor("O", expr))
 {
     Compiler   = compiler;
     DeviceType = deviceType;
 }
Esempio n. 5
0
 public Kernel(Tensor output, TensorExpression expr, ICompiler compiler, DeviceType deviceType = DeviceType.CPU)
     : this(output, expr)
 {
     Compiler   = compiler;
     DeviceType = deviceType;
 }