Skip to content

Commit f4b6d50

Browse files
committed
fix HelloWorld example exception.
1 parent 27fbfb0 commit f4b6d50

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

‎src/TensorFlowNET.Core/Python.cs‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using NumSharp.Core;
2+
using System;
23
using System.Collections.Generic;
34
using System.Text;
45

@@ -51,6 +52,16 @@ public static void with<T>(IPython py, Action<T> action) where T : IPython
5152
py.Dispose();
5253
}
5354
}
55+
56+
public static (T, T) zip<T>(T t1, T t2, int index = 0) where T : IList<T>
57+
{
58+
return (t1[index], t2[index]);
59+
}
60+
61+
public static (T, T) zip<T>(NDArray t1, NDArray t2, int index = 0)
62+
{
63+
return (t1.Data<T>(index), t2.Data<T>(index));
64+
}
5465
}
5566

5667
public interface IPython : IDisposable

‎test/TensorFlowNET.Examples/HelloWorld.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ of the Constant op. */
2525
{
2626
// Run the op
2727
var result = sess.run(hello);
28-
Console.WriteLine(result);
28+
Console.WriteLine(result.ToString());
2929
if(!result.ToString().Equals("Hello, TensorFlow!"))
3030
{
31-
throw new Exception("HelloWorld error");
31+
throw new ValueError("HelloWorld");
3232
}
3333
}
3434
}

‎test/TensorFlowNET.Examples/LinearRegression.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ public void Run()
5959
{
6060
// Run the initializer
6161
sess.run(init);
62+
63+
// Fit all training data
64+
for (int i = 0; i < training_epochs; i++)
65+
{
66+
for(int index = 0; index < train_X.size; index++)
67+
{
68+
(double x, double y) = Python.zip<double>(train_X, train_Y, index);
69+
var feed_dict = new Dictionary<Tensor, NDArray>();
70+
71+
// sess.run(optimizer, feed_dict);
72+
}
73+
}
6274
});
6375
}
6476
}

0 commit comments

Comments
 (0)