Skip to content

Commit 16d48a1

Browse files
committed
Remove AllocationType.
1 parent 01e6a38 commit 16d48a1

3 files changed

Lines changed: 3 additions & 73 deletions

File tree

‎src/TensorFlowNET.Core/Tensors/AllocationType.cs‎

Lines changed: 0 additions & 27 deletions
This file was deleted.

‎src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ limitations under the License.
1919
using System.Diagnostics.CodeAnalysis;
2020
using System.Linq;
2121
using System.Numerics;
22-
using System.Runtime.CompilerServices;
23-
using System.Runtime.InteropServices;
2422
using System.Text;
2523
using static Tensorflow.c_api;
2624

@@ -29,21 +27,6 @@ namespace Tensorflow
2927
[SuppressMessage("ReSharper", "InvokeAsExtensionMethod")]
3028
public partial class Tensor
3129
{
32-
/// <summary>
33-
/// The handle that was used to allocate this tensor, dependent on <see cref="AllocationType"/>.
34-
/// </summary>
35-
protected object AllocationHandle;
36-
37-
/// <summary>
38-
/// True if this Tensor holds data allocated by C#.
39-
/// </summary>
40-
public bool IsMemoryOwner => AllocationType >= AllocationType.Marshal;
41-
42-
/// <summary>
43-
/// The allocation method used to create this Tensor.
44-
/// </summary>
45-
public AllocationType AllocationType { get; protected set; }
46-
4730
public IntPtr TensorDataPointer => _handle == IntPtr.Zero ? IntPtr.Zero : TF_TensorData(_handle);
4831

4932
public Tensor()
@@ -125,11 +108,7 @@ unsafe void InitTensor(Array array, Shape? shape = null)
125108
/// <param name="num_bytes">Size of the tensor in memory</param>
126109
public Tensor(IntPtr data_ptr, long[] shape, TF_DataType dType, int num_bytes)
127110
{
128-
unsafe
129-
{
130-
_handle = TF_NewTensor(dType, dims: shape, num_dims: shape.Length, data: data_ptr, len: (ulong)num_bytes);
131-
AllocationType = TF_TensorData(_handle) == data_ptr ? AllocationType.FromPointer : AllocationType.Tensorflow;
132-
}
111+
_handle = TF_NewTensor(dType, dims: shape, num_dims: shape.Length, data: data_ptr, len: (ulong)num_bytes);
133112
}
134113

135114
public unsafe Tensor(NDArray nd)

‎src/TensorFlowNET.Core/Tensors/Tensor.cs‎

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public partial class Tensor : DisposableObject,
9393
/// TFE_TensorHandle
9494
/// </summary>
9595
public SafeTensorHandleHandle EagerTensorHandle { get; set; }
96-
96+
protected bool _createdInGraphMode;
97+
public bool CreatedInGraphMode => _createdInGraphMode;
9798
public bool IsEagerTensor => this is EagerTensor;
9899
public bool IsSparseTensor => this is SparseTensor;
99100

@@ -262,29 +263,6 @@ protected override void DisposeUnmanagedResources(IntPtr handle)
262263
#if TRACK_TENSOR_LIFE
263264
print($"Delete Tensor 0x{handle.ToString("x16")} {AllocationType} Data: 0x{TensorDataPointer.ToString("x16")}");
264265
#endif
265-
if (AllocationHandle != null)
266-
{
267-
if (AllocationType == AllocationType.GCHandle)
268-
{
269-
((GCHandle)AllocationHandle).Free();
270-
AllocationHandle = null;
271-
AllocationType = AllocationType.None;
272-
}
273-
else if (AllocationType == AllocationType.Marshal)
274-
{
275-
Marshal.FreeHGlobal((IntPtr)AllocationHandle);
276-
AllocationHandle = null;
277-
AllocationType = AllocationType.None;
278-
}
279-
else if (AllocationType == AllocationType.FromPointer)
280-
{
281-
AllocationHandle = null;
282-
AllocationType = AllocationType.None;
283-
}
284-
else
285-
throw new InvalidOperationException($"Tensor.AllocationHandle is not null ({AllocationHandle}) but AllocationType is not matched to a C# allocation type ({AllocationType}).");
286-
}
287-
288266
if (dtype == TF_DataType.TF_STRING)
289267
{
290268
long size = 1;

0 commit comments

Comments
 (0)