|
|
@@ -7,50 +7,60 @@ namespace Tensorflow |
|
|
|
{ |
|
|
|
public class Tensor |
|
|
|
{ |
|
|
|
private readonly Operation _op; |
|
|
|
public Operation op => _op; |
|
|
|
private readonly int _value_index; |
|
|
|
public int value_index => _value_index; |
|
|
|
private TF_DataType _dtype; |
|
|
|
public TF_DataType dtype => _dtype; |
|
|
|
public Operation op { get; } |
|
|
|
public int value_index { get; } |
|
|
|
public TF_DataType dtype { get; } |
|
|
|
|
|
|
|
public Graph graph => _op.graph; |
|
|
|
public Graph graph => op.graph; |
|
|
|
|
|
|
|
public string name; |
|
|
|
|
|
|
|
private readonly IntPtr _handle; |
|
|
|
public IntPtr handle => _handle; |
|
|
|
|
|
|
|
private readonly int _ndim; |
|
|
|
public int ndim => _ndim; |
|
|
|
public IntPtr handle { get; } |
|
|
|
public int ndim { get; } |
|
|
|
public ulong bytesize { get; } |
|
|
|
public ulong dataTypeSize { get;} |
|
|
|
public ulong size => bytesize / dataTypeSize; |
|
|
|
public IntPtr buffer { get; } |
|
|
|
|
|
|
|
public Tensor(IntPtr handle) |
|
|
|
{ |
|
|
|
_handle = handle; |
|
|
|
_dtype = c_api.TF_TensorType(_handle); |
|
|
|
_ndim = c_api.TF_NumDims(_handle); |
|
|
|
this.handle = handle; |
|
|
|
dtype = c_api.TF_TensorType(handle); |
|
|
|
ndim = c_api.TF_NumDims(handle); |
|
|
|
bytesize = c_api.TF_TensorByteSize(handle); |
|
|
|
buffer = c_api.TF_TensorData(handle); |
|
|
|
dataTypeSize = c_api.TF_DataTypeSize(dtype); |
|
|
|
} |
|
|
|
|
|
|
|
public Tensor(Operation op, int value_index, TF_DataType dtype) |
|
|
|
{ |
|
|
|
_op = op; |
|
|
|
_value_index = value_index; |
|
|
|
_dtype = dtype; |
|
|
|
this.op = op; |
|
|
|
this.value_index = value_index; |
|
|
|
this.dtype = dtype; |
|
|
|
} |
|
|
|
|
|
|
|
public TF_Output _as_tf_output() |
|
|
|
{ |
|
|
|
return c_api_util.tf_output(_op._c_op, _value_index); |
|
|
|
return c_api_util.tf_output(op._c_op, value_index); |
|
|
|
} |
|
|
|
|
|
|
|
public T[] Data<T>() |
|
|
|
{ |
|
|
|
var data = new T[size]; |
|
|
|
|
|
|
|
for (ulong i = 0; i < size; i++) |
|
|
|
{ |
|
|
|
data[i] = Marshal.PtrToStructure<T>(buffer + (int)(i * dataTypeSize)); |
|
|
|
} |
|
|
|
|
|
|
|
return data; |
|
|
|
} |
|
|
|
|
|
|
|
public T Data<T>() |
|
|
|
public byte[] Data() |
|
|
|
{ |
|
|
|
/*var buffer = new byte[6 * sizeof(float)]; |
|
|
|
var h1 = c_api.TF_TensorData(handle); |
|
|
|
var bytes = Marshal.PtrToStructure<float>(h1); |
|
|
|
Marshal.Copy(h1, buffer, 0, 24);*/ |
|
|
|
var data = new byte[bytesize]; |
|
|
|
Marshal.Copy(buffer, data, 0, (int)bytesize); |
|
|
|
|
|
|
|
return default(T); |
|
|
|
return data; |
|
|
|
} |
|
|
|
} |
|
|
|
} |