Repository navigation
Expand file tree
/
Copy pathEagerTensor.cs
More file actions
76 lines (68 loc) · 2.39 KB
/
Copy pathEagerTensor.cs
File metadata and controls
76 lines (68 loc) · 2.39 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
using NumSharp;
using System;
using System.Collections.Generic;
using System.Text;
namespace Tensorflow.Eager
{
public partial class EagerTensor : Tensor
{
Status status = new Status();
TFE_TensorHandle tfe_tensor_handle;
public EagerTensor(IntPtr handle) : base(handle)
{
tfe_tensor_handle = handle;
_handle = c_api.TFE_TensorHandleResolve(handle, status);
_id = ops.uid();
}
public EagerTensor(string value, string device_name) : base(value)
{
tfe_tensor_handle = c_api.TFE_NewTensorHandle(_handle, status);
_id = ops.uid();
}
public EagerTensor(int value, string device_name) : base(value)
{
tfe_tensor_handle = c_api.TFE_NewTensorHandle(_handle, status);
_id = ops.uid();
}
public EagerTensor(float[] value, string device_name) : base(value)
{
tfe_tensor_handle = c_api.TFE_NewTensorHandle(_handle, status);
_id = ops.uid();
}
public EagerTensor(double[] value, string device_name) : base(value)
{
tfe_tensor_handle = c_api.TFE_NewTensorHandle(_handle, status);
_id = ops.uid();
}
public EagerTensor(NDArray value, string device_name) : base(value)
{
tfe_tensor_handle = c_api.TFE_NewTensorHandle(_handle, status);
_id = ops.uid();
}
public override string ToString()
{
switch (rank)
{
case -1:
return $"tf.Tensor: shape=<unknown>, dtype={dtype.as_numpy_name()}, numpy={GetFormattedString()}";
case 0:
return $"tf.Tensor: shape=(), dtype={dtype.as_numpy_name()}, numpy={GetFormattedString()}";
default:
return $"tf.Tensor: shape=({string.Join(",", shape)}), dtype={dtype.as_numpy_name()}, numpy={GetFormattedString()}";
}
}
private string GetFormattedString()
{
var nd = numpy();
switch (dtype)
{
case TF_DataType.TF_STRING:
return $"b'{(string)nd}'";
case TF_DataType.TF_BOOL:
return (nd.GetByte(0) > 0).ToString();
default:
return nd.ToString();
}
}
}
}