Skip to content

Commit b84a613

Browse files
dsymemigueldeicaza
authored andcommitted
Add F# scripting sample (migueldeicaza#93)
1 parent 537e6a3 commit b84a613

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,37 @@ using (var session = new TFSession())
9191
Console.WriteLine("a*b={0}", multiplyResultValue);
9292
}
9393
```
94+
Here is an F# scripting version of the same example, you can use this in F# Interactive:
95+
```
96+
#r @"packages\TensorFlowSharp.1.2.2\lib\net461\TensorFlowSharp.dll"
97+
98+
open System
99+
open System.IO
100+
open TensorFlow
101+
102+
// set the path to find the native DLL
103+
Environment.SetEnvironmentVariable("Path",
104+
Environment.GetEnvironmentVariable("Path") + ";" + __SOURCE_DIRECTORY__ + @"/packages/TensorFlowSharp.1.2.2/native")
105+
106+
module AddTwoNumbers =
107+
let session = new TFSession()
108+
let graph = session.Graph
109+
110+
let a = graph.Const(new TFTensor(2))
111+
let b = graph.Const(new TFTensor(3))
112+
Console.WriteLine("a=2 b=3")
113+
114+
// Add two constants
115+
let addingResults = session.GetRunner().Run(graph.Add(a, b))
116+
let addingResultValue = addingResults.GetValue()
117+
Console.WriteLine("a+b={0}", addingResultValue)
118+
119+
// Multiply two constants
120+
let multiplyResults = session.GetRunner().Run(graph.Mul(a, b))
121+
let multiplyResultValue = multiplyResults.GetValue()
122+
Console.WriteLine("a*b={0}", multiplyResultValue)
123+
```
124+
94125

95126
# Working on TensorFlowSharp
96127

0 commit comments

Comments
 (0)