Record Class Scalar

java.lang.Object
java.lang.Record
smile.tensor.Scalar
All Implemented Interfaces:
Tensor

public record Scalar(Number value) extends Record implements Tensor
A scalar is a single number.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Scalar(Number value)
    Creates an instance of a Scalar record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    dim()
    Returns the number of dimensions of tensor.
    final boolean
    Indicates whether some other object is "equal to" this one.
    get(int... index)
    Returns a portion of tensor given the index.
    final int
    Returns a hash code value for this object.
    long
    Returns the number of tensor elements.
    reshape(int... shape)
    Returns a tensor with the same data and number of elements but with the specified shape.
    Returns the element data type.
    set(Tensor value, int... index)
    Updates a sub-tensor in place.
    int[]
    Returns the shape of tensor.
    int
    size(int dim)
    Returns the size of given dimension.
    boolean
    Returns the boolean value of scalar.
    byte
    Returns the byte value of scalar.
    double
    Returns the double value of scalar.
    float
    Returns the float value of scalar.
    int
    Returns the int value of scalar.
    long
    Returns the long value of scalar.
    short
    Returns the short value of scalar.
    final String
    Returns a string representation of this record class.
    Returns the value of the value record component.

    Methods inherited from class Object

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

    • Scalar

      public Scalar(Number value)
      Creates an instance of a Scalar record class.
      Parameters:
      value - the value for the value record component
  • Method Details

    • scalarType

      public ScalarType scalarType()
      Description copied from interface: Tensor
      Returns the element data type.
      Specified by:
      scalarType in interface Tensor
      Returns:
      the element data type.
    • dim

      public int dim()
      Description copied from interface: Tensor
      Returns the number of dimensions of tensor.
      Specified by:
      dim in interface Tensor
      Returns:
      the number of dimensions of tensor
    • size

      public int size(int dim)
      Description copied from interface: Tensor
      Returns the size of given dimension.
      Specified by:
      size in interface Tensor
      Parameters:
      dim - dimension index.
      Returns:
      the size of given dimension.
    • length

      public long length()
      Description copied from interface: Tensor
      Returns the number of tensor elements. For tensors with packed storage (e.g., BandMatrix, SparseMatrix, SymmMatrix), it returns the number of non-zero elements.
      Specified by:
      length in interface Tensor
      Returns:
      the number of tensor elements.
    • shape

      public int[] shape()
      Description copied from interface: Tensor
      Returns the shape of tensor. That is a list of the extent of each dimension.
      Specified by:
      shape in interface Tensor
      Returns:
      the shape of tensor.
    • reshape

      public Tensor reshape(int... shape)
      Description copied from interface: Tensor
      Returns a tensor with the same data and number of elements but with the specified shape. This method returns a view if shape is compatible with the current shape.
      Specified by:
      reshape in interface Tensor
      Parameters:
      shape - the new shape of tensor.
      Returns:
      the tensor with the specified shape.
    • set

      public Tensor set(Tensor value, int... index)
      Description copied from interface: Tensor
      Updates a sub-tensor in place.
      Specified by:
      set in interface Tensor
      Parameters:
      value - the sub-tensor.
      index - the index.
      Returns:
      this tensor.
    • get

      public Tensor get(int... index)
      Description copied from interface: Tensor
      Returns a portion of tensor given the index.
      Specified by:
      get in interface Tensor
      Parameters:
      index - the index along the dimensions.
      Returns:
      the sub-tensor.
    • toBoolean

      public boolean toBoolean()
      Returns the boolean value of scalar.
      Returns:
      the boolean value.
    • toByte

      public byte toByte()
      Returns the byte value of scalar.
      Returns:
      the scalar value.
    • toShort

      public short toShort()
      Returns the short value of scalar.
      Returns:
      the scalar value.
    • toInt

      public int toInt()
      Returns the int value of scalar.
      Returns:
      the scalar value.
    • toLong

      public long toLong()
      Returns the long value of scalar.
      Returns:
      the scalar value.
    • toFloat

      public float toFloat()
      Returns the float value of scalar.
      Returns:
      the scalar value.
    • toDouble

      public double toDouble()
      Returns the double value of scalar.
      Returns:
      the scalar value.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • value

      public Number value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component