public final class Tensor

  1. Object
  2. 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

public static Tensor floats(String name, int[] shape, float[] data)
public static Tensor ints(String name, int[] shape, int[] data)
public static Tensor bytes(String name, TensorType type, int[] shape, byte[] data)Creates a byte-array tensor for UINT8, INT8, or BOOL data.
public String getName()
public TensorType getType()
public int[] getShape()
public Object getData()

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

name String
model tensor name, or null for positional matching
type TensorType
element type
shape int[]
tensor dimensions; an empty shape represents a scalar
data Object
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 tensor

getType

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