pub struct Tensor {
pub value: Array1<f64>,
pub grad: Option<Array1<f64>>,
}Expand description
Represents a basic implementation of a tensor.
Fields§
§value: Array1<f64>§grad: Option<Array1<f64>>Implementations§
Trait Implementations§
Source§impl TensorTrait for Tensor
impl TensorTrait for Tensor
Source§fn forward(&self, _ctx: &mut Context, _inputs: Vec<ArrayView1<'_, f64>>) -> f64
fn forward(&self, _ctx: &mut Context, _inputs: Vec<ArrayView1<'_, f64>>) -> f64
Implements the forward pass for the Tensor.
§Arguments
_ctx- A mutable reference to the computation context (not used in this example)._inputs- A vector of ArrayView1representing the input values (not used in this example).
§Returns
(f64): The result of the forward pass (not implemented in this example, returns 0.0).
Source§fn backward(&self, _ctx: &mut Context, _grad_output: ArrayView1<'_, f64>)
fn backward(&self, _ctx: &mut Context, _grad_output: ArrayView1<'_, f64>)
Implements the backward pass for the Tensor.
§Arguments
_ctx- A mutable reference to the computation context (not used in this example)._grad_output- An ArrayView1representing the gradient of the output.
§Examples
use ndarray::{array, Array1};
use tinygrad::{Tensor, Context, TensorTrait};
let mut ctx = Context::new();
let tensor = Tensor::new(array![1.0, 2.0, 3.0]);
tensor.backward(&mut ctx, array![1.0, 1.0, 1.0].view());Source§fn get_value(&self) -> ArrayView1<'_, f64>
fn get_value(&self) -> ArrayView1<'_, f64>
Auto Trait Implementations§
impl Freeze for Tensor
impl RefUnwindSafe for Tensor
impl Send for Tensor
impl Sync for Tensor
impl Unpin for Tensor
impl UnwindSafe for Tensor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more