|
1 |
| -# AutoGraphSharp |
| 1 | +# AutoGraphSharp |
| 2 | + |
| 3 | +## This is the AutoGraph implementation for C# code. |
| 4 | + |
| 5 | +To test this code, clone the repo and open the example project. AutoGraphSharp generates the Tensorflow Graph creation code at compile time. |
| 6 | + |
| 7 | +In a future release, a development NuGet package will be publihed. |
| 8 | + |
| 9 | +### Example |
| 10 | + |
| 11 | +This function: |
| 12 | + |
| 13 | + [AutoGraph] |
| 14 | + public static int Function(int a, int b) |
| 15 | + { |
| 16 | + var c = (a + b *3 )/a; |
| 17 | + |
| 18 | + if (a > b) |
| 19 | + c = 1; |
| 20 | + else |
| 21 | + c = 2; |
| 22 | + |
| 23 | + return c; |
| 24 | + } |
| 25 | + |
| 26 | +will be automatically translated to this function: |
| 27 | + |
| 28 | + [AutoGraph] |
| 29 | + public static int Function(int a, int b, TensorFlow.TFSession session) |
| 30 | + { |
| 31 | + var runner = session.GetRunner(); |
| 32 | + var _a = new AutoTFOutput(session.Graph.Placeholder(TFTensor.TensorTypeFromType(a.GetType())), session); |
| 33 | + runner.AddInput(_a, new TFTensor(a)); |
| 34 | + var _b = new AutoTFOutput(session.Graph.Placeholder(TFTensor.TensorTypeFromType(b.GetType())), session); |
| 35 | + runner.AddInput(_b, new TFTensor(b)); |
| 36 | + return (int)runner.Run(_Function(_a, _b, session)).GetValue(); |
| 37 | + } |
| 38 | + |
| 39 | + [AutoGraph] |
| 40 | + public static AutoTFOutput _Function(AutoTFOutput a, AutoTFOutput b, TensorFlow.TFSession session) |
| 41 | + { |
| 42 | + var c = (a + b * 3) / a; |
| 43 | + var predicate1 = a > b; |
| 44 | + Func<Tuple<AutoTFOutput>> ifTrue1 = () => |
| 45 | + { |
| 46 | + var _c = c; |
| 47 | + _c = new AutoTFOutput(session.Graph.Const(1), session); |
| 48 | + return Tuple.Create(_c); |
| 49 | + }; |
| 50 | + Func<Tuple<AutoTFOutput>> ifFalse1 = () => |
| 51 | + { |
| 52 | + var _c = c; |
| 53 | + _c = new AutoTFOutput(session.Graph.Const(2), session); |
| 54 | + return Tuple.Create(_c); |
| 55 | + }; |
| 56 | + var res = new AutoCond<Tuple<AutoTFOutput>>(predicate1, ifTrue1, ifFalse1, session); |
| 57 | + res.Deconstruct(out c); |
| 58 | + return c; |
| 59 | + } |
| 60 | + |
| 61 | +>Note: This is an incomplete work in progress. The first goal if to implement a generic **if statement** Graph translation that will work for any C# **if** permutation. Once there, the rest of the C# language features will follow (while loops, switch cases etc). |
0 commit comments