From d76eebfdc713c45684204e1f5ca96f5286c4be59 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Sun, 5 Jul 2020 22:43:48 -0500 Subject: [PATCH] Clean code. --- src/TensorFlowNET.Core/APIs/c_api.cs | 2 +- src/TensorFlowNET.Core/Assembly/Properties.cs | 2 +- src/TensorFlowNET.Core/Eager/c_api.eager.cs | 49 ------------------ .../Operations/gen_array_ops.cs | 3 -- src/TensorFlowNET.Core/Util/BindingArray.cs | 50 ------------------- .../Util/BindingTensorArray.cs | 50 ------------------- src/TensorFlowNET.Core/Util/PointerInputs.cs | 30 ----------- test/TensorFlowNET.UnitTest/ImageTest.cs | 1 + 8 files changed, 3 insertions(+), 184 deletions(-) delete mode 100644 src/TensorFlowNET.Core/Util/BindingArray.cs delete mode 100644 src/TensorFlowNET.Core/Util/BindingTensorArray.cs delete mode 100644 src/TensorFlowNET.Core/Util/PointerInputs.cs diff --git a/src/TensorFlowNET.Core/APIs/c_api.cs b/src/TensorFlowNET.Core/APIs/c_api.cs index 6852e2d7..db8f1c8f 100644 --- a/src/TensorFlowNET.Core/APIs/c_api.cs +++ b/src/TensorFlowNET.Core/APIs/c_api.cs @@ -72,6 +72,6 @@ namespace Tensorflow } [DllImport(TensorFlowLibName)] - public static extern IntPtr TF_Version(); + internal static extern IntPtr TF_Version(); } } diff --git a/src/TensorFlowNET.Core/Assembly/Properties.cs b/src/TensorFlowNET.Core/Assembly/Properties.cs index 28aee65e..290a72df 100644 --- a/src/TensorFlowNET.Core/Assembly/Properties.cs +++ b/src/TensorFlowNET.Core/Assembly/Properties.cs @@ -1,4 +1,4 @@ using System.Runtime.CompilerServices; #if DEBUG -[assembly: InternalsVisibleTo("TensorFlowNET.UnitTest, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")] +[assembly: InternalsVisibleTo("Tensorflow.UnitTest, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")] #endif diff --git a/src/TensorFlowNET.Core/Eager/c_api.eager.cs b/src/TensorFlowNET.Core/Eager/c_api.eager.cs index af652824..f49b1f05 100644 --- a/src/TensorFlowNET.Core/Eager/c_api.eager.cs +++ b/src/TensorFlowNET.Core/Eager/c_api.eager.cs @@ -8,46 +8,6 @@ namespace Tensorflow { public partial class c_api { - [DllImport(TensorFlowLibName)] - public static extern void TFE_RegisterGradientFunction(gradient_function_callback gradientFunctionCallback, - delete_backward_function_callback deleteBackwardFunctionCallback); - - /// - /// - /// - /// - /// - /// - /// - /// previous node ouput - /// - /// - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - public delegate IntPtr gradient_function_callback(string op_name, - IntPtr op_inputs, - IntPtr op_outputs, - string attrs_string, - IntPtr output_grads, - IntPtr skip_input_indices); - - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - public delegate void delete_backward_function_callback(string op_name, - IntPtr op_inputs, - IntPtr op_outputs); - - [DllImport(TensorFlowLibName)] - public static extern IntPtr TFE_WrapGradientResult(IntPtr[] gradients, int num_gradients); - - [DllImport(TensorFlowLibName)] - public static extern IntPtr VSpace_Handle(VSpace_callback_Ones ones, VSpace_callback_AggregateGrads aggregate_grads); - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - public delegate IntPtr VSpace_callback_Ones(long[] shape, int dims, TF_DataType dtype); - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - public delegate IntPtr VSpace_callback_AggregateGrads(TF_BindingArray gradients); - - [DllImport(TensorFlowLibName)] - public static extern void TFE_RegisterVSpace(IntPtr vspace); - /// /// Return a new options object. /// @@ -239,15 +199,6 @@ namespace Tensorflow [DllImport(TensorFlowLibName)] public static extern IntPtr TFE_EagerTensorHandle(IntPtr t); - [DllImport(TensorFlowLibName)] - public static extern int TFE_EagerTensorId(IntPtr t); - - [DllImport(TensorFlowLibName)] - public static extern IntPtr TFE_NewEagerTensor(); - - [DllImport(TensorFlowLibName)] - public static extern void TFE_SetEagerTensorHandle(IntPtr tensor, IntPtr handle); - /// /// Sets the default execution mode (sync/async). Note that this can be /// overridden per thread using TFE_ContextSetExecutorForThread. diff --git a/src/TensorFlowNET.Core/Operations/gen_array_ops.cs b/src/TensorFlowNET.Core/Operations/gen_array_ops.cs index f95de917..c850abc2 100644 --- a/src/TensorFlowNET.Core/Operations/gen_array_ops.cs +++ b/src/TensorFlowNET.Core/Operations/gen_array_ops.cs @@ -19,9 +19,6 @@ using System.Collections.Generic; using static Tensorflow.Binding; using Tensorflow.Eager; using System.Linq; -#pragma warning disable CS0105 // Using directive appeared previously in this namespace -using static Tensorflow.Binding; -#pragma warning restore CS0105 // Using directive appeared previously in this namespace namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Util/BindingArray.cs b/src/TensorFlowNET.Core/Util/BindingArray.cs deleted file mode 100644 index 788d389d..00000000 --- a/src/TensorFlowNET.Core/Util/BindingArray.cs +++ /dev/null @@ -1,50 +0,0 @@ -/***************************************************************************** - Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -******************************************************************************/ - -using System; -using System.Runtime.InteropServices; - -namespace Tensorflow -{ - public class BindingArray : DisposableObject - { - TF_BindingArray data; - public IntPtr Address => data.array; - public int Length => data.length; - - public BindingArray(IntPtr handle) : base(handle) - { - if (_handle != IntPtr.Zero) - data = Marshal.PtrToStructure(_handle); - else - data = default; - } - - public static implicit operator BindingArray(IntPtr handle) - => new BindingArray(handle); - - public unsafe IntPtr this[int index] - => data[index]; - - public unsafe IntPtr[] Data - => data.Data; - - protected override void DisposeUnmanagedResources(IntPtr handle) - { - c_api.TF_DeleteBindingArray(_handle); - } - } -} diff --git a/src/TensorFlowNET.Core/Util/BindingTensorArray.cs b/src/TensorFlowNET.Core/Util/BindingTensorArray.cs deleted file mode 100644 index c3862d97..00000000 --- a/src/TensorFlowNET.Core/Util/BindingTensorArray.cs +++ /dev/null @@ -1,50 +0,0 @@ -/***************************************************************************** - Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -******************************************************************************/ - -using System; -using System.Runtime.InteropServices; - -namespace Tensorflow -{ - public class BindingTensorArray : DisposableObject - { - TF_BindingArray data; - public IntPtr Address => data.array; - public int Length => data.length; - - public BindingTensorArray(IntPtr handle) : base(handle) - { - if (_handle != IntPtr.Zero) - data = Marshal.PtrToStructure(_handle); - else - data = default; - } - - public static implicit operator BindingTensorArray(IntPtr handle) - => new BindingTensorArray(handle); - - public unsafe IntPtr this[int index] - => data[index]; - - public unsafe IntPtr[] Data - => data.Data; - - protected override void DisposeUnmanagedResources(IntPtr handle) - { - c_api.TFE_DeleteBindingTensorArray(_handle); - } - } -} diff --git a/src/TensorFlowNET.Core/Util/PointerInputs.cs b/src/TensorFlowNET.Core/Util/PointerInputs.cs deleted file mode 100644 index 64d638a2..00000000 --- a/src/TensorFlowNET.Core/Util/PointerInputs.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; - -namespace Tensorflow -{ - public abstract class PointerInputs - where T : IPointerInputs, new() - { - protected T[] data; - public int Length - => data.Length; - - public IntPtr[] Points - => data.Select(x => x.ToPointer()).ToArray(); - - public PointerInputs(params T[] data) - => this.data = data; - - public T this[int idx] - => data[idx]; - - public T[] Items - => data; - - public static implicit operator IntPtr[](PointerInputs inputs) - => inputs.data.Select(x => x.ToPointer()).ToArray(); - } -} diff --git a/test/TensorFlowNET.UnitTest/ImageTest.cs b/test/TensorFlowNET.UnitTest/ImageTest.cs index 02ae5e43..f9b3ec10 100644 --- a/test/TensorFlowNET.UnitTest/ImageTest.cs +++ b/test/TensorFlowNET.UnitTest/ImageTest.cs @@ -26,6 +26,7 @@ namespace TensorFlowNET.UnitTest.Basics contents = tf.io.read_file(imgPath); } + [Ignore] [TestMethod] public void decode_image() {