Skip to main content

tensor_map

Function tensor_map 

Source
pub fn tensor_map<F>(input: &Tensor<f32>, f: F) -> Result<Tensor<f32>>
where F: Fn(f32) -> f32 + Send + Sync,
Expand description

Functional map operation over tensor elements

Applies a function to each element of the tensor in parallel.

§Arguments

  • input - Input tensor
  • f - Function to apply to each element

§Performance

  • Time Complexity: O(n) where n is number of elements
  • Space Complexity: O(n) for output tensor
  • Uses scirs2-core parallel operations when beneficial

§Examples

use torsh_functional::transformations::tensor_map;

let input = Tensor::randn(&[100, 100])?;
let output = tensor_map(&input, |x| x.powi(2))?;