Record Class Scalar
java.lang.Object
java.lang.Record
smile.tensor.Scalar
- All Implemented Interfaces:
Tensor
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintdim()Returns the number of dimensions of tensor.final booleanIndicates whether some other object is "equal to" this one.get(int... index) Returns a portion of tensor given the index.final inthashCode()Returns a hash code value for this object.longlength()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.Updates a sub-tensor in place.int[]shape()Returns the shape of tensor.intsize(int dim) Returns the size of given dimension.booleanReturns the boolean value of scalar.bytetoByte()Returns the byte value of scalar.doubletoDouble()Returns the double value of scalar.floattoFloat()Returns the float value of scalar.inttoInt()Returns the int value of scalar.longtoLong()Returns the long value of scalar.shorttoShort()Returns the short value of scalar.final StringtoString()Returns a string representation of this record class.value()Returns the value of thevaluerecord component.
-
Constructor Details
-
Scalar
Creates an instance of aScalarrecord class.- Parameters:
value- the value for thevaluerecord component
-
-
Method Details
-
scalarType
Description copied from interface:TensorReturns the element data type.- Specified by:
scalarTypein interfaceTensor- Returns:
- the element data type.
-
dim
-
size
-
length
public long length()Description copied from interface:TensorReturns the number of tensor elements. For tensors with packed storage (e.g., BandMatrix, SparseMatrix, SymmMatrix), it returns the number of non-zero elements. -
shape
-
reshape
Description copied from interface:TensorReturns 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. -
set
-
get
-
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
-
hashCode
-
equals
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 withObjects::equals(Object,Object). -
value
Returns the value of thevaluerecord component.- Returns:
- the value of the
valuerecord component
-