Memory managed, off-heap, GPU and CPU compatible N-dimensional array.
This class is a wrapper around aten.Tensor providing a more convenient API. All allocating operations require an implicit lamp.Scope.
STen instances are associated with a device which determines where the memory is allocated, and where the operations are performed. Operations on multiple tensors expect that all the arguments reside on the same device.
lamp.STen.options returns a lamp.STenOptions which describes the device, shape, data type and storage layout of a tensor. Most factory methods in the companion object in turn require a lamp.STenOptions to specify the device, data types and storage layout.
Naming convention of most operations follows libtorch. Operations return their result in a copy, i.e. not in place. These operations need a lamp.Scope. Operations whose name ends with an underscore are in place. Operations whose name contains out
will write their results into the specified output tensor, these are in the companion object. Some operations are exempt from this naming rule, e.g. +=
, -=
, *=
etc.
Semantics of operations follow those of libtorch with the same name. Many of the operations broadcasts. See https://numpy.org/doc/stable/user/basics.broadcasting.html#general-broadcasting-rules for broadcasting rules. In short:
- shapes are aligned from the right, extending with ones to the left as needed. 2. If two aligned dimensions are not matching but one of them is 1, then it is expanded to the size of the other dimension, pretending a copy of all its values. If two aligned dimension are not matching and neither of them is 1, then the operation fails. =Examples=
Scope.root { implicit scope =>
val sum = Scope { implicit scope =>
val ident = STen.eye(3, STenOptions.d)
val ones = STen.ones(List(3, 3), STenOptions.d)
ident + ones
}
assert(sum.toMat == mat.ones(3, 3) + mat.ident(3))
}
===Broadcasting examples===
// successful
3 x 4 x 6 A
4 x 6 B
3 x 4 x 6 Result // B is repeated 3 times first dimensions
// successful
3 x 4 x 6 A
3 x 1 x 6 B
3 x 4 x 6 Result // B's second dimension is repeated 4 times
// fail
3 x 4 x 6 A
3 x 2 x 6 B
3 x 4 x 6 Result // 2 != 4
The companion object contains various factories which copy data from the JVM memory to STen tensors.
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
In place multiplication.
In place multiplication.
Attributes
In place multiplication.
In place multiplication.
Attributes
Adds a scalar to all elements.
Adds a scalar to all elements.
Attributes
Adds a scalar to all elements.
Adds a scalar to all elements.
Attributes
In place add.
In place add.
Attributes
In place add.
In place add.
Attributes
Adds an other tensor multipled by a scalar (a + alpha * b)
.
Adds an other tensor multipled by a scalar (a + alpha * b)
.
Attributes
Adds a value multipled by a scalar (a + alpha * b)
.
Adds a value multipled by a scalar (a + alpha * b)
.
Attributes
Elementwise this + alpha * tensor1 * tensor2
Elementwise this + alpha * tensor1 * tensor2
Attributes
Elementwise in place this + alpha * tensor1 * tensor2
Elementwise in place this + alpha * tensor1 * tensor2
Attributes
Elementwise in place this + alpha * tensor1 * tensor2
Elementwise in place this + alpha * tensor1 * tensor2
Attributes
beta * this + alpha * (mat1 matmul mat2)
beta * this + alpha * (mat1 matmul mat2)
Attributes
Return a boolean scalar tensor indicating that all of the elements are true
Return a boolean scalar tensor indicating that all of the elements are true
Attributes
Return a boolean tensor indicating that all of the elements are true in the respective dimension
Return a boolean tensor indicating that all of the elements are true in the respective dimension
Attributes
Return a boolean scalar tensor indicating that any of the elements is true
Return a boolean scalar tensor indicating that any of the elements is true
Attributes
Return a boolean tensor indicating that any of the elements true in the respective dimension
Return a boolean tensor indicating that any of the elements true in the respective dimension
Attributes
Reduces the given dimension with the index of its maximum element.
Reduces the given dimension with the index of its maximum element.
Value parameters
- keepDim
-
if true then the reduced dimension is kept with size 1
Attributes
Reduces the given dimension with the index of its minimum element.
Reduces the given dimension with the index of its minimum element.
Value parameters
- keepDim
-
if true then the reduced dimension is kept with size 1
Attributes
Returns a long tensors with the argsort of the given dimension.
Returns a long tensors with the argsort of the given dimension.
Indexing the given dimension by the returned tensor would result in a sorted order.
Attributes
Batched add mm.
Batched add mm.
Attributes
Batched matrix multiplication. Maps to Aten.bmm.
Batched matrix multiplication. Maps to Aten.bmm.
Performs the same matrix multiplication along multiple batches. Batch dimensions do not broadcast.
Attributes
Casts to bool
Casts to bool
Attributes
Casts to byte. signed 8-bit integer (like Scala's Byte) This is called Char in libtorch
Casts to byte. signed 8-bit integer (like Scala's Byte) This is called Char in libtorch
Attributes
Casts to double
Casts to double
Attributes
Casts to float
Casts to float
Attributes
Casts to half
Casts to half
Attributes
Casts to long
Casts to long
Attributes
Casts to short
Casts to short
Attributes
Concatenates two tensors along the given dimension. Other dimensions must conform.
Concatenates two tensors along the given dimension. Other dimensions must conform.
Attributes
Returns a copy of this tensor
Returns a copy of this tensor
Attributes
Overwrites the contents of this tensor with the contents of an other. Must conform.
Overwrites the contents of this tensor with the contents of an other. Must conform.
Attributes
Overwrites the contents of this tensor with the contents of an other. Must conform. non blocking is true
Overwrites the contents of this tensor with the contents of an other. Must conform. non blocking is true
Attributes
Overwrites the contents of this tensor with the contents of an other. Must conform.
Overwrites the contents of this tensor with the contents of an other. Must conform.
Attributes
Returns a copy of this tensor adapted to the given options
Returns a copy of this tensor adapted to the given options
Attributes
Returns a copy of this tensor on the given device
Returns a copy of this tensor on the given device
Attributes
Returns the Device this tensor resides on
Returns the Device this tensor resides on
Attributes
Returns the device index. Only for Cuda tensors.
Returns the device index. Only for Cuda tensors.
Attributes
Returns a boolean tensors of the same shape, indicating equality with the other tensor.
Returns a boolean tensors of the same shape, indicating equality with the other tensor.
Attributes
Returns a boolean tensors of the same shape, indicating equality with the other value.
Returns a boolean tensors of the same shape, indicating equality with the other value.
Attributes
Returns a boolean tensors of the same shape, indicating equality with the other value.
Returns a boolean tensors of the same shape, indicating equality with the other value.
Attributes
Return a boolean tensor indicating element-wise equality. Maps to Aten.equal
Return a boolean tensor indicating element-wise equality. Maps to Aten.equal
Attributes
In place fills the tensors with the given value
In place fills the tensors with the given value
Attributes
In place fills with the given tensor.
In place fills with the given tensor.
Attributes
Flattens between the given dimensions. Inclusive.
Flattens between the given dimensions. Inclusive.
Attributes
Return a boolean tensor indicating element-wise greater-or-equal.
Return a boolean tensor indicating element-wise greater-or-equal.
Attributes
Return a boolean tensor indicating element-wise greater-or-equal.
Return a boolean tensor indicating element-wise greater-or-equal.
Attributes
Return a boolean tensor indicating element-wise greater-than.
Return a boolean tensor indicating element-wise greater-than.
Attributes
Return a boolean tensor indicating element-wise greater-than.
Return a boolean tensor indicating element-wise greater-than.
Attributes
Indexes with the given tensors along multiple dimensions.
Indexes with the given tensors along multiple dimensions.
Attributes
Selects along the given dimension with indices in the supplied long tensor.
Selects along the given dimension with indices in the supplied long tensor.
Attributes
Selects along the given dimension with indices in the supplied long tensor.
Selects along the given dimension with indices in the supplied long tensor.
Attributes
Returns indices. Only for sparse tensors
Returns indices. Only for sparse tensors
Attributes
Returns true if device is CPU
Returns true if device is CPU
Attributes
Returns true if device is Cuda
Returns true if device is Cuda
Attributes
Returns true if data type is double
Returns true if data type is double
Attributes
Returns true if data type is float
Returns true if data type is float
Attributes
Returns true if data type is int
Returns true if data type is int
Attributes
Returns true if data type is long
Returns true if data type is long
Attributes
Returns true if data type is short
Returns true if data type is short
Attributes
Returns true if this is sparse tensor
Returns true if this is sparse tensor
Attributes
Return a boolean tensor indicating element-wise is-finite.
Return a boolean tensor indicating element-wise is-finite.
Attributes
Return a boolean tensor indicating element-wise is-nan.
Return a boolean tensor indicating element-wise is-nan.
Attributes
Return a boolean tensor indicating element-wise less-or-equal.
Return a boolean tensor indicating element-wise less-or-equal.
Attributes
Return a boolean tensor indicating element-wise less-or-equal.
Return a boolean tensor indicating element-wise less-or-equal.
Attributes
Leaky rectified linear unit
Leaky rectified linear unit
Attributes
In place leaky rectified linear unit
In place leaky rectified linear unit
Attributes
Reduces the given dimension with the log-softmax of its elements.
Reduces the given dimension with the log-softmax of its elements.
Attributes
Return a boolean tensor with element-wise logical and.
Return a boolean tensor with element-wise logical and.
Attributes
Return a boolean tensor with element-wise logical not.
Return a boolean tensor with element-wise logical not.
Attributes
Return a boolean tensor with element-wise logical or.
Return a boolean tensor with element-wise logical or.
Attributes
Return a boolean tensor with element-wise logical xor.
Return a boolean tensor with element-wise logical xor.
Attributes
Return a boolean tensor indicating element-wise less-than.
Return a boolean tensor indicating element-wise less-than.
Attributes
Return a boolean tensor indicating element-wise greater-than.
Return a boolean tensor indicating element-wise greater-than.
Attributes
Fills the tensor with the given fill
value in the locations indicated by the mask
boolean mask.
Fills the tensor with the given fill
value in the locations indicated by the mask
boolean mask.
Attributes
Fills the tensor with the given fill
value in the locations indicated by the mask
boolean mask.
Fills the tensor with the given fill
value in the locations indicated by the mask
boolean mask.
Attributes
Fills with the given value according to the boolean mask.
Fills with the given value according to the boolean mask.
Attributes
Fills with the given value according to the boolean mask.
Fills with the given value according to the boolean mask.
Attributes
Selects the elements according to the boolean mask. Returns a 1D tensor.
Selects the elements according to the boolean mask. Returns a 1D tensor.
Attributes
Selects the elements according to the boolean mask. Returns a 1D tensor.
Selects the elements according to the boolean mask. Returns a 1D tensor.
Attributes
Return the elementwise max.
Return the elementwise max.
Attributes
Reduces the given dimension with its max.
Reduces the given dimension with its max.
Attributes
Reduces the given dimensions with their mean.
Reduces the given dimensions with their mean.
Attributes
Reduces the given dimension with its median.
Reduces the given dimension with its median.
Attributes
Return the elementwise minimum.
Return the elementwise minimum.
Attributes
Reduces the given dimension with its max.
Reduces the given dimension with its max.
Attributes
Matrix multiplication. Maps to Aten.mm.
Matrix multiplication. Maps to Aten.mm.
Attributes
Reduces the given dimension with its mode.
Reduces the given dimension with its mode.
Attributes
Returns a tensor with a subset of its elements.
Returns a tensor with a subset of its elements.
The returned tensor includes elements from start
to start+length
along the given dimension.
No copy is made, storage is shared.
Attributes
Return a boolean tensor indicating element-wise not-equal.
Return a boolean tensor indicating element-wise not-equal.
Attributes
Return a boolean tensor indicating element-wise less-or-equal.
Return a boolean tensor indicating element-wise less-or-equal.
Attributes
Returns the negation (not applicable for Boolean).
Returns the negation (not applicable for Boolean).
Attributes
Reduces the given dimensions with their L2 norm.
Reduces the given dimensions with their L2 norm.
Attributes
Returns the logical negation (applicable for Boolean).
Returns the logical negation (applicable for Boolean).
Attributes
Returns the number of elements in the tensor
Returns the number of elements in the tensor
Attributes
Returns the associated STenOptions
Returns the associated STenOptions
Attributes
In place rectified linear unit
In place rectified linear unit
Attributes
Returns a tensor with a new shape. May copy.
Returns a tensor with a new shape. May copy.
Attributes
Returns the byte representation of the data type
Returns the byte representation of the data type
The mapping is:
- 1 for Byte
- 2 for Short
- 3 for Int
- 4 for Long
- 5 for Half
- 6 for Float
- 7 for Double
Attributes
Selects a scalar element or a tensor in the given dimension and index.
Selects a scalar element or a tensor in the given dimension and index.
Attributes
Returns the shape of the tensor
Returns the shape of the tensor
Attributes
In place sigmoid funtion
In place sigmoid funtion
Attributes
Returns the shape of the tensor
Returns the shape of the tensor
Attributes
Returns a slice over the selected dimension
Returns a slice over the selected dimension
Attributes
Returns a slice over the selected dimension
Returns a slice over the selected dimension
Attributes
Removes dimensions of size=1 from the shape
Removes dimensions of size=1 from the shape
Attributes
Removes dimensions of size=1 from the shape
Removes dimensions of size=1 from the shape
Attributes
Reduces the given dimensions with their standard deviation.
Reduces the given dimensions with their standard deviation.
Attributes
Subtracts other after multiplying with a number.
Subtracts other after multiplying with a number.
Attributes
Subtracts other after multiplying with a number.
Subtracts other after multiplying with a number.
Attributes
Reduces the given dimensions with the sum of their elements.
Reduces the given dimensions with the sum of their elements.
Value parameters
- keepDim
-
if true then the reduced dimensions are kept with size 1
Attributes
Value parameters
- fullMatrices
-
whether to return reduced or full matrices (in case of non-square input)
Attributes
- Returns
-
(U,S,Vh) , Vh being the conjugate transpose of V ; input = U diag(S) Vh
Transposes the first two dimensions.
Transposes the first two dimensions.
Attributes
Returns a string representation of the object.
Returns a string representation of the object.
The default representation is platform dependent.
Attributes
- Returns
-
a string representation of the object.
- Definition Classes
-
Any
Selects the top k elements along the given dimension
Selects the top k elements along the given dimension
Value parameters
- dim
-
which dimension to select in
- k
-
How many elements to select
- largest
-
if true, then the highest k element is selected
- sorted
-
if true, the selected elements are further sorted
Attributes
- Returns
-
a pair of (value,index) tensors where value holds the selected elements and index holds the indices of the selected elements
Transposes the given dimensions.
Transposes the given dimensions.
Attributes
Inserts a dimension of size=1 in the given position
Inserts a dimension of size=1 in the given position
Attributes
Returns values. Only for sparse tensors
Returns values. Only for sparse tensors
Attributes
Reduces the given dimensions with their variance.
Reduces the given dimensions with their variance.
Attributes
Returns a tensor with a new shape.
Returns a tensor with a new shape.
No data is copied. The new shape must be compatible with the number of elements and the stride of the tensor.
Attributes
Returns the indices of non-zero values
Returns the indices of non-zero values
Attributes
In place fills with zeros.
In place fills with zeros.
Attributes
Inherited methods
Attributes
- Inherited from:
- Product
Attributes
- Inherited from:
- Product