pub struct Var { /* private fields */ }
Expand description

Var can be thought as the value it holds plus a link to the computation graph. Majority of operators are methods on Var.

Implementations

Where it needs a assign operator, we should use this ref_copy. If a hard copy is necessary, then call clone().

With a &Var, use set to copy a value.

Identity matrix

Fill row by row.

Matrix/inner/dot product

use auto_diff::{Var, var_f64, AutoDiffError};
extern crate openblas_src;
fn test_matmul() -> Result<(), AutoDiffError> {

let v1 = var_f64!([[1., 2., 3.], [4., 5., 6.]]); let v2 = var_f64!([[11., 12., 13.], [14., 15., 16.], [17., 18., 19.]]); let v3 = v1.matmul(&v2)?; let em = var_f64!([[90.0, 96.0, 102.0], [216.0, 231.0, 246.0]]); assert_eq!(v3, em);

Ok(())
}
test_matmul();

Outer product

let v1 = Var::new_f64(&[1., 2., 3.], &[3]);
let v2 = Var::new_f64(&[4., 5., 6.], &[3]);
let v3 = v1.outer(&v2)?;
let em = var_f64!([[4.,   5.,  6.],
                   [8.,  10., 12.],
                   [12., 15., 18.]]);
assert_eq!(v3, em);

Concatenates the given sequence of seq tensors in the given dimension. The input tensor should all have the same size except on the given dimension. The output tensor will have all the same size as the input except the given dimension, which will be the sum of the inputs on the given dimension. Apply cat on [tensor(5, 3, 2), tensor(5, 7, 2), ] will get a tensor(5, 10, 2).

use auto_diff::{Var, var_f64, AutoDiffError};
extern crate openblas_src;
fn test_cat() -> Result<(), AutoDiffError> {

let m1 = Var::empty(&[3, 1]); let m2 = Var::empty(&[3, 1]); let m3 = Var::empty(&[3, 1]); let m4 = m1.cat(&[m2, m3], 1)?; assert_eq!(m4.size(), [3, 3]);

Ok(())
}
test_cat();

Stack tensor with the same size along a new dimension specified by dim. The difference from cat is that cat don’t create new dimension.

let m1 = var_f64!([[1., 2., ],
               [3., 4., ]]);
let m2 = var_f64!([[5., 6., ],
               [7., 8., ]]);
let m3 = m1.stack(&[m2], 1)?;

Get a portion of the tensor and return it.

let m1 = var_f64!([[1., 2., 3.],
                   [4., 5., 6.],
                   [7., 8., 9.]]);
let m2 = var_f64!([[4., 5.],
                   [7., 8.]]);
assert_eq!(m1.get_patch(&[(1, 3), (0, 2)], None)?, m2);

Set a portion of the tensor.

let m1 = var_f64!([[1., 2., 3.],
                   [4., 5., 6.],
                   [7., 8., 9.]]);
let m2 = var_f64!([[10., 11.],
                   [12., 13.]]);
let m3 = var_f64!([[1.,   2., 3.],
                   [10., 11., 6.],
                   [12., 13., 9.]]);
assert_eq!(m1.set_patch(&m2, &[(1, 3), (0, 2)], None)?, m3);

Use gradient or not, default is to use.

Reset net in the background.

The current gradient for the Var.

Apply back propagation to get numerical gradient.

Run the computation graph again.

Extract input and output from the hidden net.

Get var by string label

For debug.

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.