candle-ext 0.1.7

An extension library to Candle that provides PyTorch functions not currently available in Candle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use crate::{
    candle::{Result, Tensor},
    F,
};

impl F {
    /// Computes the element-wise logical NOT of the given input tensor.
    /// If not specified, the output tensor will have the bool dtype.
    /// If the input tensor is not a bool tensor, zeros are treated as False and non-zeros are treated as True.
    #[inline]
    pub fn logical_not(xs: &Tensor) -> Result<Tensor> {
        xs.where_cond(&xs.zeros_like()?, &xs.ones_like()?)
    }
}