rotta_rs 0.0.5

a Deep Learning library with rust language
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::rotta_rs_module::{ arrayy::Arrayy, BackwardLabel, NodeType, Tensor };

pub fn abs(x: &Tensor) -> Tensor {
    let tensor = Tensor::from_arrayy(x.value().abs());
    tensor.update_parent(vec![x.node.clone()]);
    tensor.update_label(Some(BackwardLabel::Abs(x.node.clone())));

    tensor
}

pub fn d_abs(x: &NodeType, grad: &Arrayy) {
    let mut x = x.lock().unwrap();

    if x.requires_grad {
        let d_x = x.value.sign() * grad;
        x.add_grad(d_x);
    }
}