forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEagerTensor.cs
More file actions
85 lines (74 loc) · 2.4 KB
/
EagerTensor.cs
File metadata and controls
85 lines (74 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using Tensorflow.Util;
using static Tensorflow.Binding;
namespace Tensorflow.Eager
{
public partial class EagerTensor : Tensor
{
public override SafeTensorHandle Handle
{
get
{
Resolve();
return _handle;
}
}
public override IntPtr buffer
{
get
{
Resolve();
return base.buffer;
}
}
public override string Device => c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(_eagerTensorHandle, tf.Status));
public override TF_DataType dtype => c_api.TFE_TensorHandleDataType(_eagerTensorHandle);
public override int rank => c_api.TFE_TensorHandleNumDims(EagerTensorHandle, tf.Status);
public override ulong bytesize
{
get
{
Resolve();
return base.bytesize;
}
}
public override IntPtr TensorDataPointer
{
get
{
Resolve();
return base.TensorDataPointer;
}
}
protected override Shape GetShapeInternal()
{
var dims = new int[c_api.TFE_TensorHandleNumDims(_eagerTensorHandle, tf.Status)];
for (int i = 0; i < dims.Length; i++)
dims[i] = c_api.TFE_TensorHandleDim(_eagerTensorHandle, i, tf.Status);
return dims;
}
protected override void SetShapeInternal(Shape value)
{
if (!shape.is_compatible_with(value))
throw new ValueError($"Tensor's shape is not compatible.");
}
public static int GetRank(IntPtr handle)
{
var tfe_tensor_handle = c_api.TFE_EagerTensorHandle(handle);
return c_api.TFE_TensorHandleNumDims(tfe_tensor_handle, tf.Status);
}
public static int[] GetDims(IntPtr handle)
{
var tfe_tensor_handle = c_api.TFE_EagerTensorHandle(handle);
var dims = new int[c_api.TFE_TensorHandleNumDims(tfe_tensor_handle, tf.Status)];
for (int i = 0; i < dims.Length; i++)
dims[i] = c_api.TFE_TensorHandleDim(tfe_tensor_handle, i, tf.Status);
return dims;
}
public override T[] ToArray<T>()
{
Resolve();
return base.ToArray<T>();
}
}
}