Expand description
Tensor Operations - Mathematical and Structural Operations
This module provides standalone tensor operations for convenient access. Operations are organized by category.
§Categories
§Comparison Operations
eq,lt,gt- Element-wise comparison returning boolean vectors
§Activation Functions
softmax,log_softmax- Probability distributionsgelu,silu,elu,leaky_relu- Advanced activations
§Clipping Operations
clamp,clamp_min,clamp_max- Value range limiting
§Conditional Operations
where_cond- Select elements based on condition
§Sorting and Top-K
topk- Returns k largest/smallest elements with indicessort- Sorts tensor along dimension with indicesargsort- Returns indices that would sort tensor
§Indexing Operations
scatter- Scatter values to specified indices (inverse of gather)nonzero- Returns indices of non-zero elementsunique- Returns unique elements with optional counts/inverse
§Shape Manipulation
flip- Reverses tensor along specified dimensionsroll- Rolls tensor elements along dimensions (circular shift)
§Example
ⓘ
use axonml_tensor::ops::{topk, sort, unique};
let t = Tensor::from_vec(vec![3.0, 1.0, 4.0, 1.0, 5.0], &[5]).unwrap();
// Get top 3 largest values
let result = topk(&t, 3, -1, true, true).unwrap();
// result.values = [5.0, 4.0, 3.0]
// result.indices = [4, 2, 0]
// Sort ascending
let sorted = sort(&t, -1, false).unwrap();
// sorted.values = [1.0, 1.0, 3.0, 4.0, 5.0]
// Get unique values
let uniq = unique(&t, true, true, true);
// uniq.values = [1.0, 3.0, 4.0, 5.0]
// uniq.counts = [2, 1, 1, 1]@version 0.2.6
@author AutomataNexus Development Team
Structs§
- Sort
Result - Result of sort operation containing sorted values and indices.
- TopK
Result - Result of topk operation containing values and indices.
- Unique
Result - Result of unique operation.
Functions§
- argsort
- Returns the indices that would sort the tensor along a dimension.
- clamp
- Clamps all elements to the range [min, max].
- clamp_
max - Clamps all elements to be at most max.
- clamp_
min - Clamps all elements to be at least min.
- elu
- Applies ELU (Exponential Linear Unit) activation.
- eq
- Element-wise equality comparison.
- flip
- Reverses the order of elements along specified dimensions.
- gelu
- Applies GELU (Gaussian Error Linear Unit) activation.
- gt
- Element-wise greater-than comparison.
- leaky_
relu - Applies Leaky
ReLUactivation. - log_
softmax - Applies log-softmax along the specified dimension.
- lt
- Element-wise less-than comparison.
- nonzero
- Returns the indices of non-zero elements.
- roll
- Rolls tensor elements along specified dimensions.
- scatter
- Writes values from src into self at locations specified by index.
- silu
- Applies
SiLU(Sigmoid Linear Unit) / Swish activation. - softmax
- Applies softmax along the specified dimension.
- sort
- Sorts the elements of the tensor along a dimension.
- topk
- Returns the k largest elements along a dimension.
- unique
- Returns the unique elements of the input tensor.
- where_
cond - Selects elements from x or y based on condition.