use crate::{ rotta_rs_module::{ arrayy::Arrayy, BackwardLabel, Tensor }, ShareTensor };
pub fn powf(x: &Tensor, n: f32) -> Tensor {
let arrayy = x.value.read().unwrap().powf(n);
let mut tensor = Tensor::from_arrayy(arrayy);
tensor.update_parent(vec![x.shared_tensor()]);
tensor.update_label(Some(BackwardLabel::Powf(x.shared_tensor(), n)));
tensor
}
pub fn d_powf(x: &ShareTensor, powf: f32, grad: &Arrayy) {
if x.requires_grad() {
let dx =
powf *
&x.value
.read()
.unwrap()
.powf(powf - 1.0) *
grad;
x.add_grad(dx);
}
}