public final class Tensor
- Object
- Tensor
Immutable named tensor passed to or returned from an inference session.
The primitive data array and shape are copied on construction and by their
public getters, so callers can safely reuse or mutate their source arrays.
Constructors
public Tensor(String name, TensorType type, int[] shape, Object data) | Creates a tensor and validates that its type, shape, and primitive array agree. |
Methods
Inherited methods
Constructor details
Tensor
public Tensor(String name, TensorType type, int[] shape, Object data)Creates a tensor and validates that its type, shape, and primitive array
agree. Dynamic dimensions may be negative and skip the element-count
check; fixed shapes are overflow-checked.
Parameters
nameString- model tensor name, or
nullfor positional matching typeTensorType- element type
shapeint[]- tensor dimensions; an empty shape represents a scalar
dataObject- matching primitive array
Method details
floats
public static Tensor floats(String name, int[] shape, float[] data)Returns
a FLOAT32 tensor with defensively copied data
ints
public static Tensor ints(String name, int[] shape, int[] data)Returns
an INT32 tensor with defensively copied data
bytes
public static Tensor bytes(String name, TensorType type, int[] shape, byte[] data)Creates a byte-array tensor for UINT8, INT8, or BOOL data.
Returns
a tensor with defensively copied data
getName
public String getName()Returns
the model tensor name, or
null for an unnamed tensorgetType
public TensorType getType()Returns
the element type
getShape
public int[] getShape()Returns
a defensive copy of tensor dimensions
getData
public Object getData()Returns
a defensive copy of the matching primitive data array