Class Shape

java.lang.Object
ai.beestream.jitnn.Shape

public final class Shape extends Object
An immutable, row-major tensor shape. A rank-0 shape is a scalar with one element.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    axis(int axis)
    Normalises a possibly negative axis to [0, rank).
    static Shape
    NumPy broadcasting of two shapes.
    int[]
    Strides for reading a tensor of this shape as if it had shape target: broadcast dimensions get stride 0.
    int
    dim(int axis)
    Dimension axis; negative values count from the end.
    int[]
    A copy of the sizes.
    boolean
     
    int
     
    int
    The number of elements: the product of the sizes (1 for a scalar).
    static Shape
    of(int... dims)
    The shape with the given sizes (the array is copied).
    int
    The number of axes.
    reduce(int axis, boolean keepDim)
    The shape with axis removed (keepDim=false) or set to 1 (keepDim=true).
    static Shape
    The rank-0 shape: a scalar with one element.
    int[]
    Contiguous row-major strides, in elements.
     

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • of

      public static Shape of(int... dims)
      The shape with the given sizes (the array is copied).
    • scalar

      public static Shape scalar()
      The rank-0 shape: a scalar with one element.
    • rank

      public int rank()
      The number of axes.
    • dim

      public int dim(int axis)
      Dimension axis; negative values count from the end.
    • dims

      public int[] dims()
      A copy of the sizes.
    • numel

      public int numel()
      The number of elements: the product of the sizes (1 for a scalar).
    • axis

      public int axis(int axis)
      Normalises a possibly negative axis to [0, rank).
    • strides

      public int[] strides()
      Contiguous row-major strides, in elements.
    • reduce

      public Shape reduce(int axis, boolean keepDim)
      The shape with axis removed (keepDim=false) or set to 1 (keepDim=true).
    • broadcast

      public static Shape broadcast(Shape a, Shape b)
      NumPy broadcasting of two shapes.
    • broadcastStrides

      public int[] broadcastStrides(Shape target)
      Strides for reading a tensor of this shape as if it had shape target: broadcast dimensions get stride 0. Returned with rank target.rank().
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object