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); }
public Kernel(Tensor output, TensorExpression expr) { output.def = expr; Tree = output.ToTree(); InputShapes = InputTensors; OutputShape = output; }
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()); }
public Kernel(TensorExpression expr, ICompiler compiler, DeviceType deviceType = DeviceType.CPU) : this(new Tensor("O", expr)) { Compiler = compiler; DeviceType = deviceType; }
public Kernel(Tensor output, TensorExpression expr, ICompiler compiler, DeviceType deviceType = DeviceType.CPU) : this(output, expr) { Compiler = compiler; DeviceType = deviceType; }