From 82724eb50110b58cd495022e1197fb18c0f4757e Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Sat, 5 Oct 2019 23:16:06 -0500 Subject: [PATCH] Slice.NewAxis --- src/TensorFlowNET.Core/APIs/tf.array.cs | 3 ++- .../Exceptions/StopIteration.cs | 17 +++++++++++++++++ .../TensorFlowNET.Core.csproj | 8 ++++---- src/TensorFlowNET.Core/Tensors/Tensor.Index.cs | 11 +++++++---- 4 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 src/TensorFlowNET.Core/Exceptions/StopIteration.cs diff --git a/src/TensorFlowNET.Core/APIs/tf.array.cs b/src/TensorFlowNET.Core/APIs/tf.array.cs index bd6f6101..3a674e83 100644 --- a/src/TensorFlowNET.Core/APIs/tf.array.cs +++ b/src/TensorFlowNET.Core/APIs/tf.array.cs @@ -14,6 +14,7 @@ limitations under the License. ******************************************************************************/ +using NumSharp; using System; using System.Collections.Generic; using System.Linq; @@ -25,7 +26,7 @@ namespace Tensorflow /// /// A convenient alias for None, useful for indexing arrays. /// - public string newaxis = ""; + public Slice newaxis = Slice.NewAxis; /// /// BatchToSpace for N-D tensors of type T. diff --git a/src/TensorFlowNET.Core/Exceptions/StopIteration.cs b/src/TensorFlowNET.Core/Exceptions/StopIteration.cs new file mode 100644 index 00000000..d91408a2 --- /dev/null +++ b/src/TensorFlowNET.Core/Exceptions/StopIteration.cs @@ -0,0 +1,17 @@ +using System; + +namespace Tensorflow +{ + public class StopIteration : TensorflowException + { + public StopIteration() : base() + { + + } + + public StopIteration(string message) : base(message) + { + + } + } +} diff --git a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj index 13f56a60..12a4c5f3 100644 --- a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj +++ b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj @@ -5,7 +5,7 @@ TensorFlow.NET Tensorflow 1.14.0 - 0.11.4 + 0.11.5 Haiping Chen, Meinrad Recheis, Eli Belash SciSharp STACK true @@ -17,7 +17,7 @@ TensorFlow, NumSharp, SciSharp, MachineLearning, TensorFlow.NET, C# Google's TensorFlow full binding in .NET Standard. Docs: https://tensorflownet.readthedocs.io - 0.11.4.0 + 0.11.5.0 Changes since v0.10.0: 1. Upgrade NumSharp to v0.20.3. 2. Add DisposableObject class to manage object lifetime. @@ -31,7 +31,7 @@ Docs: https://tensorflownet.readthedocs.io 10. Support n-dim indexing for tensor. 11. Add RegisterNoGradient 7.3 - 0.11.4.0 + 0.11.5.0 LICENSE true true @@ -63,7 +63,7 @@ Docs: https://tensorflownet.readthedocs.io - + diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.Index.cs b/src/TensorFlowNET.Core/Tensors/Tensor.Index.cs index 552bddfd..d916f624 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.Index.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.Index.cs @@ -27,11 +27,10 @@ namespace Tensorflow { public Tensor this[int idx] => slice(idx); - public Tensor this[params string[] slices] + public Tensor this[params Slice[] slices] { get { - var slice_spec = slices.Select(x => new Slice(x)).ToArray(); var begin = new List(); var end = new List(); var strides = new List(); @@ -41,9 +40,9 @@ namespace Tensorflow var (begin_mask, end_mask) = (0, 0); var ellipsis_mask = 0; - foreach (var s in slice_spec) + foreach (var s in slices) { - if(s.IsNewAxis) + if (s.IsNewAxis) { begin.Add(0); end.Add(0); @@ -113,6 +112,10 @@ namespace Tensorflow } } + public Tensor this[params string[] slices] + => this[slices.Select(x => new Slice(x)).ToArray()]; + + public Tensor slice(Slice slice) { var slice_spec = new int[] { slice.Start.Value };