Skip to content

Commit

Permalink
feat(tensor): create method abs
Browse files Browse the repository at this point in the history
  • Loading branch information
drewxs committed Sep 8, 2023
1 parent 9958fbc commit fbf378d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/linalg/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,20 @@ impl Tensor {
Tensor1D::from(flat_data)
}

/// Returns a tensor with the absolute value of each element in the tensor.
///
/// # Examples
///
/// ```
/// # use engram::*;
/// let a = tensor![[-1.0, 2.0], [-3.0, 4.0]];
/// let b = a.abs();
/// assert_eq!(b.data, vec![vec![1.0, 2.0], vec![3.0, 4.0]]);
/// ```
pub fn abs(&self) -> Tensor {
self.mapv(&|x| x.abs())
}

/// Returns the transpose of the tensor.
///
/// # Examples
Expand Down

0 comments on commit fbf378d

Please sign in to comment.