Skip to main content

Module ops

Module ops 

Source
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 distributions
  • gelu, 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 indices
  • sort - Sorts tensor along dimension with indices
  • argsort - Returns indices that would sort tensor

§Indexing Operations

  • scatter - Scatter values to specified indices (inverse of gather)
  • nonzero - Returns indices of non-zero elements
  • unique - Returns unique elements with optional counts/inverse

§Shape Manipulation

  • flip - Reverses tensor along specified dimensions
  • roll - 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§

SortResult
Result of sort operation containing sorted values and indices.
TopKResult
Result of topk operation containing values and indices.
UniqueResult
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 ReLU activation.
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.