TF_Tensor
tensorflow: TF_Tensor
A TensorFlow Tensor holding a copy of an Octave array.
A TF_Tensor owns the Tensor it wraps and releases it when the object
is destroyed, so it does not have to be freed by hand. Being a handle
class, assigning it to another variable refers to the same Tensor rather
than copying it, and the Tensor is released once no variable refers to it
any more.
The elements are repositioned on the way in and on the way out, since Octave stores arrays column major and TensorFlow stores them row major, so the shape and the element positions are those of the Octave array in both directions.
Source Code: TF_Tensor
The TF_Tensor class contains the following properties:
The TF_Tensor class offers the following public methods:
TF_Tensor: obj = TF_Tensor (data)
data must be a non-empty numeric, logical, or character array of a data type supported by TensorFlow. The values are copied, so data may be modified or cleared afterwards without affecting the Tensor.
Called without arguments it returns an object referring to no Tensor, which every method rejects.
A TF_Tensor holds a copy of an Octave array in the form TensorFlow works with. The values are copied, so the array it was built from may be changed or cleared afterwards.
t = TF_Tensor (single ([1, 2, 3; 4, 5, 6])); t.shape ()
ans = 2 3
t.dataType ()
ans = TF_FLOAT
t.value ()
ans = 1 2 3 4 5 6
Octave stores arrays column major and TensorFlow stores them row major, so the elements are repositioned in both directions. The shape and the values that come back are those that went in, whatever the rank.
x = reshape (1:24, 2, 3, 4); t = TF_Tensor (x); t.shape ()
ans = 2 3 4
isequal (t.value (), x)
ans = 1
The Octave class decides the TensorFlow data type.
TF_Tensor (1.5).dataType ()
ans = TF_DOUBLE
TF_Tensor (single (1.5)).dataType ()
ans = TF_FLOAT
TF_Tensor (int32 (1)).dataType ()
ans = TF_INT32
TF_Tensor (true).dataType ()
ans = TF_BOOL
TF_Tensor: data = value (obj)
value returns the contents of the tensor as an ordinary Octave array, of the class matching its TensorFlow data type.
t = TF_Tensor (int32 (magic (3))); v = t.value ()
v = 8 1 6 3 5 7 4 9 2
class (v)
ans = int32
The tensor is released once no variable refers to it, so it does not have to be freed by hand. Releasing it explicitly is allowed, after which it no longer holds anything to return.
t = TF_Tensor (42); t.value ()
ans = 42
t.delete (); try t.value () catch err disp (err.message) end
TF_Tensor.value: the Tensor has already been released.
TF_Tensor: sz = shape (obj)
A Tensor of no dimensions, which holds a single value, reports a size of
[1, 1], and a Tensor of one dimension reports [1, N], so
that the reported size is always that of the corresponding Octave array.
TF_Tensor: n = numElements (obj)
It is deliberately not named numel, which Octave uses when
resolving an indexing expression on an object.
TF_Tensor: name = dataType (obj)
TF_Tensor: delete (obj)
This is called automatically when no variable refers to the object any more, and calling it a second time does nothing.