| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8546b8d commit 6c8c2e5
34 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,6 +59,6 @@ public struct DeallocatorArgs | |||
| 59 | 59 | } | |
| 60 | 60 | ||
| 61 | 61 | [DllImport(TensorFlowLibName)] | |
| 62 | - public static unsafe extern IntPtr TF_Version(); | ||
| 62 | + public static extern IntPtr TF_Version(); | ||
| 63 | 63 | } | |
| 64 | 64 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -308,15 +308,14 @@ public static __object__ getattr(object obj, string key, params Type[] ___parame | |||
| 308 | 308 | public static IEnumerable TupleToEnumerable(object tuple) | |
| 309 | 309 | { | |
| 310 | 310 | Type t = tuple.GetType(); | |
| 311 | - if(t.IsGenericType && (t.FullName.StartsWith("System.Tuple") || t.FullName.StartsWith("System.ValueTuple"))) | ||
| 311 | + if (t.IsGenericType && (t.FullName.StartsWith("System.Tuple") || t.FullName.StartsWith("System.ValueTuple"))) | ||
| 312 | 312 | { | |
| 313 | 313 | var flds = t.GetFields(); | |
| 314 | - for(int i = 0; i < flds.Length;i++) | ||
| 314 | + for (int i = 0; i < flds.Length; i++) | ||
| 315 | 315 | { | |
| 316 | 316 | yield return flds[i].GetValue(tuple); | |
| 317 | 317 | } | |
| 318 | - } | ||
| 319 | - else | ||
| 318 | + } else | ||
| 320 | 319 | { | |
| 321 | 320 | throw new System.Exception("Expected Tuple."); | |
| 322 | 321 | } | |
@@ -329,12 +328,9 @@ public static bool isinstance(object Item1, Type Item2) | |||
| 329 | 328 | ||
| 330 | 329 | public static bool isinstance(object Item1, object tuple) | |
| 331 | 330 | { | |
| 332 | - var tup = TupleToEnumerable(tuple); | ||
| 333 | - foreach(var t in tup) | ||
| 334 | - { | ||
| 335 | - if(isinstance(Item1, (Type)t)) | ||
| 331 | + foreach (var t in TupleToEnumerable(tuple)) | ||
| 332 | + if (isinstance(Item1, (Type) t)) | ||
| 336 | 333 | return true; | |
| 337 | - } | ||
| 338 | 334 | return false; | |
| 339 | 335 | } | |
| 340 | 336 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,7 +66,7 @@ public static implicit operator byte[](Buffer buffer) | |||
| 66 | 66 | return buffer.Data; | |
| 67 | 67 | } | |
| 68 | 68 | ||
| 69 | - protected override void DisposeUnManagedState(IntPtr handle) | ||
| 69 | + protected override void DisposeUnmanagedResources(IntPtr handle) | ||
| 70 | 70 | => c_api.TF_DeleteBuffer(handle); | |
| 71 | 71 | } | |
| 72 | 72 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,49 +29,54 @@ public abstract class DisposableObject : IDisposable | |||
| 29 | 29 | ||
| 30 | 30 | protected DisposableObject() { } | |
| 31 | 31 | ||
| 32 | - public DisposableObject(IntPtr handle) | ||
| 33 | - { | ||
| 34 | - _handle = handle; | ||
| 35 | - } | ||
| 36 | - | ||
| 37 | - protected virtual void DisposeManagedState() | ||
| 38 | - { | ||
| 39 | - } | ||
| 32 | + protected DisposableObject(IntPtr handle) | ||
| 33 | + => _handle = handle; | ||
| 40 | 34 | ||
| 41 | - protected abstract void DisposeUnManagedState(IntPtr handle); | ||
| 42 | - | ||
| 43 | - protected virtual void Dispose(bool disposing) | ||
| 35 | + private void internal_dispose(bool disposing) | ||
| 44 | 36 | { | |
| 45 | 37 | if (disposing) | |
| 46 | 38 | { | |
| 47 | 39 | // free unmanaged resources (unmanaged objects) and override a finalizer below. | |
| 48 | 40 | if (_handle != IntPtr.Zero) | |
| 49 | 41 | { | |
| 50 | 42 | // dispose managed state (managed objects). | |
| 51 | - DisposeManagedState(); | ||
| 43 | + DisposeManagedResources(); | ||
| 52 | 44 | ||
| 53 | 45 | // set large fields to null. | |
| 54 | - DisposeUnManagedState(_handle); | ||
| 46 | + DisposeUnmanagedResources(_handle); | ||
| 55 | 47 | ||
| 56 | 48 | _handle = IntPtr.Zero; | |
| 57 | 49 | } | |
| 58 | 50 | } | |
| 59 | 51 | } | |
| 60 | 52 | ||
| 53 | + /// <summary> | ||
| 54 | + /// Dispose any managed resources. | ||
| 55 | + /// </summary> | ||
| 56 | + /// <remarks>Equivalent to what you would perform inside <see cref="Dispose()"/></remarks> | ||
| 57 | + protected virtual void DisposeManagedResources() | ||
| 58 | + { | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + /// <summary> | ||
| 62 | + /// Dispose any unmanaged resources related to given <paramref name="handle"/>. | ||
| 63 | + /// </summary> | ||
| 64 | + protected abstract void DisposeUnmanagedResources(IntPtr handle); | ||
| 65 | + | ||
| 61 | 66 | // override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. | |
| 62 | 67 | ~DisposableObject() | |
| 63 | 68 | { | |
| 64 | 69 | // Do not change this code. Put cleanup code in Dispose(bool disposing) above. | |
| 65 | - Dispose(false); | ||
| 70 | + internal_dispose(false); | ||
| 66 | 71 | } | |
| 67 | 72 | ||
| 68 | 73 | // This code added to correctly implement the disposable pattern. | |
| 69 | 74 | public void Dispose() | |
| 70 | 75 | { | |
| 71 | 76 | // Do not change this code. Put cleanup code in Dispose(bool disposing) above. | |
| 72 | - Dispose(true); | ||
| 77 | + internal_dispose(true); | ||
| 73 | 78 | // uncomment the following line if the finalizer is overridden above. | |
| 74 | 79 | GC.SuppressFinalize(this); | |
| 75 | 80 | } | |
| 76 | 81 | } | |
| 77 | - } | ||
| 82 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,9 @@ | |||
| 1 | 1 | using System; | |
| 2 | + using System.IO; | ||
| 2 | 3 | ||
| 3 | 4 | namespace Tensorflow.Eager | |
| 4 | 5 | { | |
| 5 | - public class ContextOptions : IDisposable | ||
| 6 | + public class ContextOptions : IDisposable //TODO! Eli: Shouldn't this inherieting DisposableObject? | ||
| 6 | 7 | { | |
| 7 | 8 | private IntPtr _handle; | |
| 8 | 9 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,57 +23,58 @@ limitations under the License. | |||
| 23 | 23 | ||
| 24 | 24 | namespace Tensorflow | |
| 25 | 25 | { | |
| 26 | + /* | ||
| 27 | + A TensorFlow computation, represented as a dataflow graph. | ||
| 28 | + | ||
| 29 | + A `Graph` contains a set of | ||
| 30 | + `tf.Operation` objects, | ||
| 31 | + which represent units of computation; and | ||
| 32 | + `tf.Tensor` objects, which represent | ||
| 33 | + the units of data that flow between operations. | ||
| 34 | + | ||
| 35 | + A default `Graph` is always registered, and accessible by calling | ||
| 36 | + `tf.get_default_graph`. | ||
| 37 | + To add an operation to the default graph, simply call one of the functions | ||
| 38 | + that defines a new `Operation`: | ||
| 39 | + | ||
| 40 | + ```python | ||
| 41 | + c = tf.constant(4.0) | ||
| 42 | + assert c.graph is tf.get_default_graph() | ||
| 43 | + ``` | ||
| 44 | + | ||
| 45 | + Another typical usage involves the | ||
| 46 | + `tf.Graph.as_default` | ||
| 47 | + context manager, which overrides the current default graph for the | ||
| 48 | + lifetime of the context: | ||
| 49 | + | ||
| 50 | + ```python | ||
| 51 | + g = tf.Graph() | ||
| 52 | + with g.as_default(): | ||
| 53 | + # Define operations and tensors in `g`. | ||
| 54 | + c = tf.constant(30.0) | ||
| 55 | + assert c.graph is g | ||
| 56 | + ``` | ||
| 57 | + | ||
| 58 | + Important note: This class *is not* thread-safe for graph construction. All | ||
| 59 | + operations should be created from a single thread, or external | ||
| 60 | + synchronization must be provided. Unless otherwise specified, all methods | ||
| 61 | + are not thread-safe. | ||
| 62 | + | ||
| 63 | + A `Graph` instance supports an arbitrary number of "collections" | ||
| 64 | + that are identified by name. For convenience when building a large | ||
| 65 | + graph, collections can store groups of related objects: for | ||
| 66 | + example, the `tf.Variable` uses a collection (named | ||
| 67 | + `tf.GraphKeys.GLOBAL_VARIABLES`) for | ||
| 68 | + all variables that are created during the construction of a graph. The caller | ||
| 69 | + may define additional collections by specifying a new name. | ||
| 70 | + */ | ||
| 71 | + | ||
| 26 | 72 | /// <summary> | |
| 27 | - /// TensorFlow uses a dataflow graph to represent your computation in terms of the dependencies between individual operations. | ||
| 28 | - /// This leads to a low-level programming model in which you first define the dataflow graph, | ||
| 29 | - /// then create a TensorFlow session to run parts of the graph across a set of local and remote devices. | ||
| 30 | - /// https://www.tensorflow.org/guide/graphs | ||
| 73 | + /// TensorFlow uses a dataflow graph to represent your computation in terms of the dependencies between individual operations. | ||
| 74 | + /// This leads to a low-level programming model in which you first define the dataflow graph, | ||
| 75 | + /// then create a TensorFlow session to run parts of the graph across a set of local and remote devices. | ||
| 31 | 76 | /// </summary> | |
| 32 | - /* | ||
| 33 | - A TensorFlow computation, represented as a dataflow graph. | ||
| 34 | - | ||
| 35 | - A `Graph` contains a set of | ||
| 36 | - `tf.Operation` objects, | ||
| 37 | - which represent units of computation; and | ||
| 38 | - `tf.Tensor` objects, which represent | ||
| 39 | - the units of data that flow between operations. | ||
| 40 | - | ||
| 41 | - A default `Graph` is always registered, and accessible by calling | ||
| 42 | - `tf.get_default_graph`. | ||
| 43 | - To add an operation to the default graph, simply call one of the functions | ||
| 44 | - that defines a new `Operation`: | ||
| 45 | - | ||
| 46 | - ```python | ||
| 47 | - c = tf.constant(4.0) | ||
| 48 | - assert c.graph is tf.get_default_graph() | ||
| 49 | - ``` | ||
| 50 | - | ||
| 51 | - Another typical usage involves the | ||
| 52 | - `tf.Graph.as_default` | ||
| 53 | - context manager, which overrides the current default graph for the | ||
| 54 | - lifetime of the context: | ||
| 55 | - | ||
| 56 | - ```python | ||
| 57 | - g = tf.Graph() | ||
| 58 | - with g.as_default(): | ||
| 59 | - # Define operations and tensors in `g`. | ||
| 60 | - c = tf.constant(30.0) | ||
| 61 | - assert c.graph is g | ||
| 62 | - ``` | ||
| 63 | - | ||
| 64 | - Important note: This class *is not* thread-safe for graph construction. All | ||
| 65 | - operations should be created from a single thread, or external | ||
| 66 | - synchronization must be provided. Unless otherwise specified, all methods | ||
| 67 | - are not thread-safe. | ||
| 68 | - | ||
| 69 | - A `Graph` instance supports an arbitrary number of "collections" | ||
| 70 | - that are identified by name. For convenience when building a large | ||
| 71 | - graph, collections can store groups of related objects: for | ||
| 72 | - example, the `tf.Variable` uses a collection (named | ||
| 73 | - `tf.GraphKeys.GLOBAL_VARIABLES`) for | ||
| 74 | - all variables that are created during the construction of a graph. The caller | ||
| 75 | - may define additional collections by specifying a new name. | ||
| 76 | - */ | ||
| 77 | + /// <remarks>https://www.tensorflow.org/guide/graphs <br></br>https://www.tensorflow.org/api_docs/python/tf/Graph</remarks> | ||
| 77 | 78 | public partial class Graph : DisposableObject, IEnumerable<Operation> | |
| 78 | 79 | { | |
| 79 | 80 | private Dictionary<int, ITensorOrOperation> _nodes_by_id; | |
@@ -439,12 +440,12 @@ public void prevent_fetching(Operation op) | |||
| 439 | 440 | _unfetchable_ops.Add(op); | |
| 440 | 441 | } | |
| 441 | 442 | ||
| 442 | - protected override void DisposeManagedState() | ||
| 443 | + protected override void DisposeManagedResources() | ||
| 443 | 444 | { | |
| 444 | 445 | ops.default_graph_stack.remove(this); | |
| 445 | 446 | } | |
| 446 | 447 | ||
| 447 | - protected override void DisposeUnManagedState(IntPtr handle) | ||
| 448 | + protected override void DisposeUnmanagedResources(IntPtr handle) | ||
| 448 | 449 | { | |
| 449 | 450 | c_api.TF_DeleteGraph(handle); | |
| 450 | 451 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,7 +37,7 @@ public void AddReturnOutput(string name, int index) | |||
| 37 | 37 | c_api.TF_ImportGraphDefOptionsAddReturnOutput(_handle, name, index); | |
| 38 | 38 | } | |
| 39 | 39 | ||
| 40 | - protected override void DisposeUnManagedState(IntPtr handle) | ||
| 40 | + protected override void DisposeUnmanagedResources(IntPtr handle) | ||
| 41 | 41 | => c_api.TF_DeleteImportGraphDefOptions(handle); | |
| 42 | 42 | ||
| 43 | 43 | public static implicit operator IntPtr(ImportGraphDefOptions opts) => opts._handle; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,7 @@ limitations under the License. | |||
| 16 | 16 | ||
| 17 | 17 | using System.Collections.Generic; | |
| 18 | 18 | using System.IO; | |
| 19 | + using System.Linq; | ||
| 19 | 20 | ||
| 20 | 21 | namespace Tensorflow.IO | |
| 21 | 22 | { | |
@@ -28,6 +29,9 @@ public class GFile | |||
| 28 | 29 | /// <param name="in_order">Traverse in order if True, post order if False.</param> | |
| 29 | 30 | public IEnumerable<(string, string[], string[])> Walk(string top, bool in_order = true) | |
| 30 | 31 | { | |
| 32 | + if (!Directory.Exists(top)) | ||
| 33 | + return Enumerable.Empty<(string, string[], string[])>(); | ||
| 34 | + | ||
| 31 | 35 | return walk_v2(top, in_order); | |
| 32 | 36 | } | |
| 33 | 37 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -141,7 +141,7 @@ protected virtual Tensor _Enter(Tensor data, string frame_name, | |||
| 141 | 141 | data, frame_name, is_constant, parallel_iterations, name: name); | |
| 142 | 142 | ||
| 143 | 143 | if (use_input_shape) | |
| 144 | - result.SetShape(data.TensorShape); | ||
| 144 | + result.set_shape(data.TensorShape); | ||
| 145 | 145 | ||
| 146 | 146 | return result; | |
| 147 | 147 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -233,7 +233,7 @@ public static Tensor _transpose_batch_time(Tensor x) | |||
| 233 | 233 | dims.AddRange(x_static_shape.dims.Skip(2)); | |
| 234 | 234 | var shape = new TensorShape(dims.ToArray()); | |
| 235 | 235 | ||
| 236 | - x_t.SetShape(shape); | ||
| 236 | + x_t.set_shape(shape); | ||
| 237 | 237 | ||
| 238 | 238 | return x_t; | |
| 239 | 239 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments