rotta_rs 0.1.0

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

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

    tensor
}

pub fn d_abs(x: &ShareTensor, grad: &Arrayy) {
    if x.requires_grad() {
        let d_x = x.value.read().unwrap().sign() * grad;
        x.add_grad(d_x);
    }
}