| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 67a58b3 commit 226720d
89 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ limitations under the License. | |||
| 16 | 16 | ||
| 17 | 17 | using Tensorflow.Operations; | |
| 18 | 18 | using Tensorflow.Operations.Activation; | |
| 19 | - using static Tensorflow.Python; | ||
| 19 | + using static Tensorflow.Binding; | ||
| 20 | 20 | ||
| 21 | 21 | namespace Tensorflow | |
| 22 | 22 | { | |
@@ -141,7 +141,7 @@ public Tensor[] top_k(Tensor input, int k = 1, bool sorted = true, string name = | |||
| 141 | 141 | ||
| 142 | 142 | public Tensor bias_add(Tensor value, RefVariable bias, string data_format = null, string name = null) | |
| 143 | 143 | { | |
| 144 | - return Python.tf_with(ops.name_scope(name, "BiasAdd", new { value, bias }), scope => | ||
| 144 | + return tf_with(ops.name_scope(name, "BiasAdd", new { value, bias }), scope => | ||
| 145 | 145 | { | |
| 146 | 146 | name = scope; | |
| 147 | 147 | return gen_nn_ops.bias_add(value, bias, data_format: data_format, name: name); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,6 @@ limitations under the License. | |||
| 15 | 15 | ******************************************************************************/ | |
| 16 | 16 | ||
| 17 | 17 | using NumSharp; | |
| 18 | - using NumSharp.Backends; | ||
| 19 | 18 | using System; | |
| 20 | 19 | using System.Collections; | |
| 21 | 20 | using System.Collections.Generic; | |
@@ -26,18 +25,15 @@ limitations under the License. | |||
| 26 | 25 | namespace Tensorflow | |
| 27 | 26 | { | |
| 28 | 27 | /// <summary> | |
| 29 | - /// Mapping C# functions to Python | ||
| 28 | + /// Binding utilities to mimic python functions. | ||
| 30 | 29 | /// </summary> | |
| 31 | - public static class Python | ||
| 30 | + public static partial class Binding | ||
| 32 | 31 | { | |
| 33 | 32 | public static void print(object obj) | |
| 34 | 33 | { | |
| 35 | 34 | Console.WriteLine(obj.ToString()); | |
| 36 | 35 | } | |
| 37 | 36 | ||
| 38 | - //protected int len<T>(IEnumerable<T> a) | ||
| 39 | - // => a.Count(); | ||
| 40 | - | ||
| 41 | 37 | public static int len(object a) | |
| 42 | 38 | { | |
| 43 | 39 | switch (a) | |
@@ -66,15 +62,15 @@ public static IEnumerable<int> range(int start, int end) | |||
| 66 | 62 | return Enumerable.Range(start, end - start); | |
| 67 | 63 | } | |
| 68 | 64 | ||
| 69 | - public static T New<T>() where T : IPyClass, new() | ||
| 65 | + public static T New<T>() where T : IObjectLife, new() | ||
| 70 | 66 | { | |
| 71 | 67 | var instance = new T(); | |
| 72 | - instance.__init__(instance); | ||
| 68 | + instance.__init__(); | ||
| 73 | 69 | return instance; | |
| 74 | 70 | } | |
| 75 | 71 | ||
| 76 | 72 | [DebuggerNonUserCode()] // with "Just My Code" enabled this lets the debugger break at the origin of the exception | |
| 77 | - public static void tf_with(IPython py, Action<IPython> action) | ||
| 73 | + public static void tf_with(IObjectLife py, Action<IObjectLife> action) | ||
| 78 | 74 | { | |
| 79 | 75 | try | |
| 80 | 76 | { | |
@@ -94,7 +90,7 @@ public static void tf_with(IPython py, Action<IPython> action) | |||
| 94 | 90 | } | |
| 95 | 91 | ||
| 96 | 92 | [DebuggerNonUserCode()] // with "Just My Code" enabled this lets the debugger break at the origin of the exception | |
| 97 | - public static void tf_with<T>(T py, Action<T> action) where T : IPython | ||
| 93 | + public static void tf_with<T>(T py, Action<T> action) where T : IObjectLife | ||
| 98 | 94 | { | |
| 99 | 95 | try | |
| 100 | 96 | { | |
@@ -114,7 +110,7 @@ public static void tf_with<T>(T py, Action<T> action) where T : IPython | |||
| 114 | 110 | } | |
| 115 | 111 | ||
| 116 | 112 | [DebuggerNonUserCode()] // with "Just My Code" enabled this lets the debugger break at the origin of the exception | |
| 117 | - public static TOut tf_with<TIn, TOut>(TIn py, Func<TIn, TOut> action) where TIn : IPython | ||
| 113 | + public static TOut tf_with<TIn, TOut>(TIn py, Func<TIn, TOut> action) where TIn : IObjectLife | ||
| 118 | 114 | { | |
| 119 | 115 | try | |
| 120 | 116 | { | |
@@ -124,7 +120,6 @@ public static TOut tf_with<TIn, TOut>(TIn py, Func<TIn, TOut> action) where TIn | |||
| 124 | 120 | catch (Exception ex) | |
| 125 | 121 | { | |
| 126 | 122 | Console.WriteLine(ex.ToString()); | |
| 127 | - throw; | ||
| 128 | 123 | return default(TOut); | |
| 129 | 124 | } | |
| 130 | 125 | finally | |
@@ -276,7 +271,9 @@ public static bool hasattr(object obj, string key) | |||
| 276 | 271 | var __memberobject__ = __type__.GetMember(key); | |
| 277 | 272 | return (__memberobject__.Length > 0) ? true : false; | |
| 278 | 273 | } | |
| 274 | + | ||
| 279 | 275 | public delegate object __object__(params object[] args); | |
| 276 | + | ||
| 280 | 277 | public static __object__ getattr(object obj, string key, params Type[] ___parameter_type__) | |
| 281 | 278 | { | |
| 282 | 279 | var __dyn_obj__ = obj.GetType().GetMember(key); | |
@@ -288,7 +285,7 @@ public static __object__ getattr(object obj, string key, params Type[] ___parame | |||
| 288 | 285 | try | |
| 289 | 286 | { | |
| 290 | 287 | var __method__ = (___parameter_type__.Length > 0) ? obj.GetType().GetMethod(key, ___parameter_type__) : obj.GetType().GetMethod(key); | |
| 291 | - return (__object__)((object[] args) => __method__.Invoke(obj, args)); | ||
| 288 | + return (object[] args) => __method__.Invoke(obj, args); | ||
| 292 | 289 | } | |
| 293 | 290 | catch (System.Reflection.AmbiguousMatchException ex) | |
| 294 | 291 | { | |
@@ -297,16 +294,17 @@ public static __object__ getattr(object obj, string key, params Type[] ___parame | |||
| 297 | 294 | } | |
| 298 | 295 | else if (__type__.MemberType == System.Reflection.MemberTypes.Field) | |
| 299 | 296 | { | |
| 300 | - var __field__ = (object)obj.GetType().GetField(key).GetValue(obj); | ||
| 301 | - return (__object__)((object[] args) => { return __field__; }); | ||
| 297 | + var __field__ = obj.GetType().GetField(key).GetValue(obj); | ||
| 298 | + return (object[] args) => { return __field__; }; | ||
| 302 | 299 | } | |
| 303 | 300 | else if (__type__.MemberType == System.Reflection.MemberTypes.Property) | |
| 304 | 301 | { | |
| 305 | - var __property__ = (object)obj.GetType().GetProperty(key).GetValue(obj); | ||
| 306 | - return (__object__)((object[] args) => { return __property__; }); | ||
| 302 | + var __property__ = obj.GetType().GetProperty(key).GetValue(obj); | ||
| 303 | + return (object[] args) => { return __property__; }; | ||
| 307 | 304 | } | |
| 308 | - return (__object__)((object[] args) => { return "NaN"; }); | ||
| 305 | + return (object[] args) => { return "NaN"; }; | ||
| 309 | 306 | } | |
| 307 | + | ||
| 310 | 308 | public static IEnumerable TupleToEnumerable(object tuple) | |
| 311 | 309 | { | |
| 312 | 310 | Type t = tuple.GetType(); | |
@@ -315,18 +313,20 @@ public static IEnumerable TupleToEnumerable(object tuple) | |||
| 315 | 313 | var flds = t.GetFields(); | |
| 316 | 314 | for(int i = 0; i < flds.Length;i++) | |
| 317 | 315 | { | |
| 318 | - yield return ((object)flds[i].GetValue(tuple)); | ||
| 316 | + yield return flds[i].GetValue(tuple); | ||
| 319 | 317 | } | |
| 320 | 318 | } | |
| 321 | 319 | else | |
| 322 | 320 | { | |
| 323 | 321 | throw new System.Exception("Expected Tuple."); | |
| 324 | 322 | } | |
| 325 | 323 | } | |
| 324 | + | ||
| 326 | 325 | public static bool isinstance(object Item1, Type Item2) | |
| 327 | 326 | { | |
| 328 | - return (Item1.GetType() == Item2); | ||
| 327 | + return Item1.GetType() == Item2; | ||
| 329 | 328 | } | |
| 329 | + | ||
| 330 | 330 | public static bool isinstance(object Item1, object tuple) | |
| 331 | 331 | { | |
| 332 | 332 | var tup = TupleToEnumerable(tuple); | |
@@ -338,11 +338,4 @@ public static bool isinstance(object Item1, object tuple) | |||
| 338 | 338 | return false; | |
| 339 | 339 | } | |
| 340 | 340 | } | |
| 341 | - | ||
| 342 | - public interface IPython : IDisposable | ||
| 343 | - { | ||
| 344 | - void __enter__(); | ||
| 345 | - | ||
| 346 | - void __exit__(); | ||
| 347 | - } | ||
| 348 | 341 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,8 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | 5 | namespace Tensorflow | |
| 6 | 6 | { | |
| 7 | - public static class Binding | ||
| 7 | + public static partial class Binding | ||
| 8 | 8 | { | |
| 9 | - public static tensorflow tf { get; } = Python.New<tensorflow>(); | ||
| 9 | + public static tensorflow tf { get; } = New<tensorflow>(); | ||
| 10 | 10 | } | |
| 11 | 11 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,7 @@ limitations under the License. | |||
| 15 | 15 | ******************************************************************************/ | |
| 16 | 16 | ||
| 17 | 17 | using System.Linq; | |
| 18 | - using static Tensorflow.Python; | ||
| 18 | + using static Tensorflow.Binding; | ||
| 19 | 19 | ||
| 20 | 20 | namespace Tensorflow.Clustering | |
| 21 | 21 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,7 @@ limitations under the License. | |||
| 18 | 18 | using System; | |
| 19 | 19 | using System.Collections.Generic; | |
| 20 | 20 | using System.Linq; | |
| 21 | - using static Tensorflow.Python; | ||
| 21 | + using static Tensorflow.Binding; | ||
| 22 | 22 | ||
| 23 | 23 | namespace Tensorflow | |
| 24 | 24 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,7 @@ limitations under the License. | |||
| 19 | 19 | using System.Collections.Generic; | |
| 20 | 20 | using System.Linq; | |
| 21 | 21 | using static Tensorflow.OpDef.Types; | |
| 22 | - using static Tensorflow.Python; | ||
| 22 | + using static Tensorflow.Binding; | ||
| 23 | 23 | ||
| 24 | 24 | namespace Tensorflow | |
| 25 | 25 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,6 @@ limitations under the License. | |||
| 17 | 17 | using System.Collections.Generic; | |
| 18 | 18 | using System.Linq; | |
| 19 | 19 | using Tensorflow.Framework; | |
| 20 | - using static Tensorflow.Python; | ||
| 21 | 20 | using static Tensorflow.Binding; | |
| 22 | 21 | ||
| 23 | 22 | namespace Tensorflow.Gradients | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ limitations under the License. | |||
| 17 | 17 | using System; | |
| 18 | 18 | using System.Collections.Generic; | |
| 19 | 19 | using System.Linq; | |
| 20 | - using static Tensorflow.Python; | ||
| 20 | + using static Tensorflow.Binding; | ||
| 21 | 21 | ||
| 22 | 22 | namespace Tensorflow | |
| 23 | 23 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,6 @@ limitations under the License. | |||
| 17 | 17 | using System; | |
| 18 | 18 | using System.Linq; | |
| 19 | 19 | using Tensorflow.Operations; | |
| 20 | - using static Tensorflow.Python; | ||
| 21 | 20 | using static Tensorflow.Binding; | |
| 22 | 21 | ||
| 23 | 22 | namespace Tensorflow.Gradients | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,7 @@ limitations under the License. | |||
| 19 | 19 | using System.Collections.Generic; | |
| 20 | 20 | using System.Linq; | |
| 21 | 21 | using System.Runtime.InteropServices; | |
| 22 | + using static Tensorflow.Binding; | ||
| 22 | 23 | ||
| 23 | 24 | namespace Tensorflow | |
| 24 | 25 | { | |
@@ -247,7 +248,7 @@ public unsafe Operation create_op(string op_type, Tensor[] inputs, TF_DataType[] | |||
| 247 | 248 | if (inputs == null) | |
| 248 | 249 | inputs = new Tensor[0]; | |
| 249 | 250 | ||
| 250 | - foreach ((int idx, Tensor a) in Python.enumerate(inputs)) | ||
| 251 | + foreach ((int idx, Tensor a) in enumerate(inputs)) | ||
| 251 | 252 | { | |
| 252 | 253 | ||
| 253 | 254 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments