Class Tensor

java.lang.Object
com.codename1.ai.inference.Tensor

public final class Tensor extends Object
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.
  • 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 - model tensor name, or null for positional matching
      type - element type
      shape - tensor dimensions; an empty shape represents a scalar
      data - 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