Skip to content

Commit b6f9c35

Browse files
committed
added BasicMath sample for Visual Basic
1 parent 23056e6 commit b6f9c35

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

Gradient-Samples.sln

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LinearSVM", "LinearSVM\Line
2323
EndProject
2424
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FSharp", "FSharp", "{B18FC4F9-E13F-437F-A8DB-4783E9C0F356}"
2525
EndProject
26-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "BasicMathF", "FSharp\BasicMathF\BasicMathF.fsproj", "{CEF0739E-BD49-466E-9F8D-226C9C474DB4}"
26+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "BasicMathF", "FSharp\BasicMathF\BasicMathF.fsproj", "{CEF0739E-BD49-466E-9F8D-226C9C474DB4}"
27+
EndProject
28+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "VB", "VB", "{875975E4-796F-4181-BACE-7DC71CE35D1F}"
29+
EndProject
30+
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "BasicMathVB", "VB\BasicMathVB\BasicMathVB.vbproj", "{453E1365-83C2-46B6-B8E0-728B778CA1A7}"
2731
EndProject
2832
Global
2933
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -59,12 +63,17 @@ Global
5963
{CEF0739E-BD49-466E-9F8D-226C9C474DB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
6064
{CEF0739E-BD49-466E-9F8D-226C9C474DB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
6165
{CEF0739E-BD49-466E-9F8D-226C9C474DB4}.Release|Any CPU.Build.0 = Release|Any CPU
66+
{453E1365-83C2-46B6-B8E0-728B778CA1A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
67+
{453E1365-83C2-46B6-B8E0-728B778CA1A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
68+
{453E1365-83C2-46B6-B8E0-728B778CA1A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
69+
{453E1365-83C2-46B6-B8E0-728B778CA1A7}.Release|Any CPU.Build.0 = Release|Any CPU
6270
EndGlobalSection
6371
GlobalSection(SolutionProperties) = preSolution
6472
HideSolutionNode = FALSE
6573
EndGlobalSection
6674
GlobalSection(NestedProjects) = preSolution
6775
{CEF0739E-BD49-466E-9F8D-226C9C474DB4} = {B18FC4F9-E13F-437F-A8DB-4783E9C0F356}
76+
{453E1365-83C2-46B6-B8E0-728B778CA1A7} = {875975E4-796F-4181-BACE-7DC71CE35D1F}
6877
EndGlobalSection
6978
GlobalSection(ExtensibilityGlobals) = postSolution
7079
SolutionGuid = {052B6168-274F-43B0-B3F0-24F5C5D4BE58}

VB/BasicMathVB/BasicMath.vb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Imports Gradient
2+
Imports SharPy.Runtime
3+
Imports tensorflow
4+
Imports tensorflow.core.protobuf.config_pb2
5+
Imports tensorflow.summary
6+
7+
Module Program
8+
Sub Main(args As String())
9+
GradientSetup.OptInToUsageDataCollection()
10+
GradientSetup.UseEnvironmentFromVariable()
11+
12+
GradientLog.OutputWriter = Console.Out
13+
14+
Dim a = tf.constant(5.0, name:="a")
15+
Dim b = tf.constant(10.0, name:="b")
16+
17+
Dim sum = tf.add(a, b, name:="sum")
18+
Dim div = tf.div(a, b, name:="div")
19+
20+
' ConfigProto here must be wrapped in () to tell Visual Basic,
21+
' that .ConfigProto() is not the same as .ConfigProto.
22+
' Alternatively, one can write .ConfigProto()()
23+
Dim config = (config_pb2.ConfigProto)()
24+
config.gpu_options.allow_growth = True
25+
Session.NewDyn(config:=config).UseSelf(Sub(sess)
26+
With sess
27+
' Visual Basic does not perform implicit conversion from Graph
28+
' to ImplicitContainer(Of Graph) :(
29+
Dim writer = New FileWriter(".", New ImplicitContainer(Of Graph)(.graph))
30+
Console.WriteLine($"a = { .run(a) }")
31+
Console.WriteLine($"b = { .run(b) }")
32+
Console.WriteLine($"a + b = { .run(sum) }")
33+
Console.WriteLine($"a / b = { .run(div) }")
34+
writer.close()
35+
.close()
36+
End With
37+
End Sub)
38+
End Sub
39+
End Module

VB/BasicMathVB/BasicMathVB.vbproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<RootNamespace>BasicMathVB</RootNamespace>
6+
<TargetFramework>netcoreapp2.2</TargetFramework>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Gradient" Version="0.1.10-tech-preview5.1.1" />
11+
</ItemGroup>
12+
13+
</Project>

0 commit comments

Comments
 (0)