Struct microtensor::Tensor

source ·
pub struct Tensor<T: Inner> { /* private fields */ }
Expand description

Multidimensional array.

Tensors may contain any type that satisfies Inner, but additional methods are available for Numeric, Real and boolean inner types.

Real tensor types can be wrapped in a Variable by calling tracked or trained.

Implementations§

source§

impl<T: Inner> Tensor<T>

source

pub fn from_shape(shape: Shape, data: Vec<T>) -> Self

source

pub fn new(shape: &[usize], data: Vec<T>) -> Self

source

pub fn vec(vec: &[T]) -> Self

Examples found in repository?
examples/basic.rs (line 5)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() {
  // Define some tensors
  let x = Tensor::vec(&[1.0, 2.0]);
  let w = Tensor::randn(&[2, 8]).trained();
  let b = Tensor::zeros(&[8]).trained();

  // Do some computation
  let z = (x.tracked().mm(&w) + b - 0.5).sqr().mean(0);

  // Compute gradients
  z.backward();

  println!("Gradient of z with respect to w: {}", w.grad().unwrap());

  // Nudge w and b in order to minimize z
  for mut param in z.parameters() {
    param -= param.grad().unwrap() * 0.01
  }
}
More examples
Hide additional examples
examples/graph.rs (line 21)
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
fn build_model(filename: &str) {
  // Have some inputs
  let x1 = Tensor::vec(&[1.0, 2.0]).tracked();
  let x2 = Tensor::ones(&[16]).tracked();
  let w = Tensor::randn(&[2, 16]).trained();

  // Do some computations
  let y = x1.mm(&w);
  let z = (&y * &x2).sum(0);

  // Pack the resulting graph into a Graph structure to make its inputs
  // and outputs explicit and arrange them in an order of your liking.
  let graph = Graph::new(&[x1, x2], &[y, z]);

  // Save entire computation graph to disc
  graph.save(filename).unwrap();
}

fn load_model(filename: &str) {
  let graph = Graph::load(filename).unwrap();

  // Feed new data using #run.
  // Updating the entire graph in this way is more efficient
  // than calling #forward on each individual output.
  graph.run(&[
    &Tensor::vec(&[5.0, 6.0]).tracked(),
    &Tensor::randn(&[16]).tracked(),
  ]);

  // Get new output..
  let z = &graph.outputs[1];
  println!("z is now {}", z.item());

  // ..or train the model further
  let z = &graph.outputs[1];
  z.backward();
  for mut param in z.parameters() {
    param -= param.grad().unwrap() * 0.01
  }
}
source

pub fn from_vec(vec: Vec<T>) -> Self

source

pub fn fill(shape: &[usize], filler: T) -> Self

source

pub fn init(shape: &[usize], cb: impl FnMut(Vec<usize>) -> T) -> Self

source

pub fn raw(&self) -> RwLockReadGuard<'_, Vec<T>>

source

pub fn raw_mut(&self) -> RwLockWriteGuard<'_, Vec<T>>

source

pub fn into_raw(self) -> Vec<T>

source

pub fn size(&self) -> usize

source

pub fn rank(&self) -> usize

source

pub fn contiguous(&self) -> Self

source

pub fn detach(&self) -> Self

source

pub fn zip<O, F>(&self, rhs: &Self, cb: F) -> Tensor<O>where O: Inner, F: Fn((T, T)) -> O,

source

pub fn vectorize<O, F>(&self, cb: F) -> Tensor<O>where O: Inner, F: FnMut(T) -> O,

source

pub fn reduce<F>(&self, cb: F) -> Option<Self>where F: Fn(T, T) -> T,

source

pub fn collapse<O, F>(&self, dim: isize, cb: F) -> Tensor<O>where O: Inner, F: Fn(Self) -> O,

source

pub fn collapse_only<F>(&self, dim: isize, cb: F) -> Selfwhere F: Fn(Self) -> Self,

source

pub fn expand<O, F>(&self, cb: F) -> Tensor<O>where O: Inner, F: Fn(T) -> Vec<O>,

source

pub fn map<O, F>(&self, dim: isize, cb: F) -> Tensor<O>where O: Inner, F: Fn(Self) -> Tensor<O>,

source

pub fn iter(&self, dim: isize) -> TensorSliceIterator<'_, T>

source

pub fn param_iter(&self) -> TensorIterator<'_, T>

source

pub fn item(&self) -> T

Examples found in repository?
examples/graph.rs (line 50)
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
fn load_model(filename: &str) {
  let graph = Graph::load(filename).unwrap();

  // Feed new data using #run.
  // Updating the entire graph in this way is more efficient
  // than calling #forward on each individual output.
  graph.run(&[
    &Tensor::vec(&[5.0, 6.0]).tracked(),
    &Tensor::randn(&[16]).tracked(),
  ]);

  // Get new output..
  let z = &graph.outputs[1];
  println!("z is now {}", z.item());

  // ..or train the model further
  let z = &graph.outputs[1];
  z.backward();
  for mut param in z.parameters() {
    param -= param.grad().unwrap() * 0.01
  }
}
source

pub fn view(&self, shape: &[usize]) -> Self

source

pub fn extend_front(&self, size: usize) -> Self

source

pub fn transpose_vec(&self, extend_front: bool) -> Self

source

pub fn equal(&self, rhs: &Self) -> Tensor<bool>

source

pub fn split(&self, size: usize, dim: isize) -> Vec<Self>

source

pub fn chunks(&self, n: usize, dim: isize) -> Vec<Self>

source

pub fn to_vec(&self, dim: isize) -> Vec<Self>

source

pub fn shuffle(&self, dim: isize) -> Self

source§

impl<T: Numeric> Tensor<T>

source

pub fn ones(shape: &[usize]) -> Self

Examples found in repository?
examples/graph.rs (line 22)
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
fn build_model(filename: &str) {
  // Have some inputs
  let x1 = Tensor::vec(&[1.0, 2.0]).tracked();
  let x2 = Tensor::ones(&[16]).tracked();
  let w = Tensor::randn(&[2, 16]).trained();

  // Do some computations
  let y = x1.mm(&w);
  let z = (&y * &x2).sum(0);

  // Pack the resulting graph into a Graph structure to make its inputs
  // and outputs explicit and arrange them in an order of your liking.
  let graph = Graph::new(&[x1, x2], &[y, z]);

  // Save entire computation graph to disc
  graph.save(filename).unwrap();
}
More examples
Hide additional examples
examples/perceptron_eager.rs (line 63)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
fn main() {
  // Construct model that stores all trainable tensors explicitly
  let model = Perceptron::new(28 * 28);

  // Train with labeled samples
  let learning_rate = 0.01;
  for _ in 0..100 {
    // Insert real training data here
    let images = Tensor::ones(&[32, 28 * 28]);
    let labels = (Tensor::rand(&[32]) * 10.0).cast::<u8>().one_hot(10);

    // Run the model, creating a fresh computation graph in the process
    let output = model.run(&images.tracked());

    // Compute loss
    let loss = (&labels.tracked() - &output).sqr().mean(0);

    // Compute gradients
    loss.backward();

    // Minimize loss by updating model parameters
    for mut param in loss.parameters() {
      param -= param.grad().unwrap() * learning_rate
    }

    // Reset gradients
    loss.reset();
  }
}
examples/perceptron_graph.rs (line 42)
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() {
  // Define model by performing all computations on a placeholder once
  let image_input = Tensor::zeros(&[32, 28 * 28]).tracked();
  let output = perceptron(&image_input);

  // Define the loss to me minimized
  let label_input = Tensor::zeros(&[32, 10]).tracked();
  let loss = (&label_input - &output).sqr().mean(0);

  // Train with some labeled samples
  let learning_rate = 0.01;
  for _ in 0..100 {
    // Insert real training data here
    let images = Tensor::ones(&[32, 28 * 28]).tracked();
    let labels = (Tensor::rand(&[32]) * 10.0).cast::<u8>().one_hot(10);

    // Feed existing computation graph with new inputs
    image_input.feed(&images);
    label_input.feed(&labels);

    // Recompute output and loss
    loss.forward();

    // Compute gradients
    loss.backward();

    // Minimize loss by updating model parameters
    for mut param in loss.parameters() {
      param -= param.grad().unwrap() * learning_rate
    }

    // Reset gradients
    loss.reset();
  }
}
source

pub fn zeros(shape: &[usize]) -> Self

Examples found in repository?
examples/perceptron_eager.rs (line 27)
24
25
26
27
28
29
  pub fn new(input_size: usize, size: usize) -> Self {
    Self {
      weights: (Tensor::randn(&[input_size, size]) / size as f32).trained(),
      bias: Tensor::zeros(&[size]).trained(),
    }
  }
More examples
Hide additional examples
examples/perceptron_graph.rs (line 20)
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn dense_layer(input: &Variable<f32>, size: usize) -> Variable<f32> {
  let weights = (Tensor::randn(&[input.shape()[-1], size]) / size as f32).trained();
  let bias = Tensor::zeros(&[size]).trained();
  input.mm(&weights) + bias
}

fn perceptron(input: &Variable<f32>) -> Variable<f32> {
  let output = dense_layer(input, 16).relu();
  dense_layer(&output, 10).sigmoid()
}

fn main() {
  // Define model by performing all computations on a placeholder once
  let image_input = Tensor::zeros(&[32, 28 * 28]).tracked();
  let output = perceptron(&image_input);

  // Define the loss to me minimized
  let label_input = Tensor::zeros(&[32, 10]).tracked();
  let loss = (&label_input - &output).sqr().mean(0);

  // Train with some labeled samples
  let learning_rate = 0.01;
  for _ in 0..100 {
    // Insert real training data here
    let images = Tensor::ones(&[32, 28 * 28]).tracked();
    let labels = (Tensor::rand(&[32]) * 10.0).cast::<u8>().one_hot(10);

    // Feed existing computation graph with new inputs
    image_input.feed(&images);
    label_input.feed(&labels);

    // Recompute output and loss
    loss.forward();

    // Compute gradients
    loss.backward();

    // Minimize loss by updating model parameters
    for mut param in loss.parameters() {
      param -= param.grad().unwrap() * learning_rate
    }

    // Reset gradients
    loss.reset();
  }
}
examples/basic.rs (line 7)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() {
  // Define some tensors
  let x = Tensor::vec(&[1.0, 2.0]);
  let w = Tensor::randn(&[2, 8]).trained();
  let b = Tensor::zeros(&[8]).trained();

  // Do some computation
  let z = (x.tracked().mm(&w) + b - 0.5).sqr().mean(0);

  // Compute gradients
  z.backward();

  println!("Gradient of z with respect to w: {}", w.grad().unwrap());

  // Nudge w and b in order to minimize z
  for mut param in z.parameters() {
    param -= param.grad().unwrap() * 0.01
  }
}
source

pub fn arrange(shape: &[usize], start: T, step: T) -> Self

source

pub fn hot_encode(idx: usize, size: usize) -> Self

source

pub fn band(dims: &[usize], num_lower: isize, num_upper: isize) -> Self

source

pub fn feed(&self, other: &Self)

Examples found in repository?
examples/perceptron_graph.rs (line 46)
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() {
  // Define model by performing all computations on a placeholder once
  let image_input = Tensor::zeros(&[32, 28 * 28]).tracked();
  let output = perceptron(&image_input);

  // Define the loss to me minimized
  let label_input = Tensor::zeros(&[32, 10]).tracked();
  let loss = (&label_input - &output).sqr().mean(0);

  // Train with some labeled samples
  let learning_rate = 0.01;
  for _ in 0..100 {
    // Insert real training data here
    let images = Tensor::ones(&[32, 28 * 28]).tracked();
    let labels = (Tensor::rand(&[32]) * 10.0).cast::<u8>().one_hot(10);

    // Feed existing computation graph with new inputs
    image_input.feed(&images);
    label_input.feed(&labels);

    // Recompute output and loss
    loss.forward();

    // Compute gradients
    loss.backward();

    // Minimize loss by updating model parameters
    for mut param in loss.parameters() {
      param -= param.grad().unwrap() * learning_rate
    }

    // Reset gradients
    loss.reset();
  }
}
source

pub fn add(&self, rhs: &Self) -> Self

source

pub fn sub(&self, rhs: &Self) -> Self

source

pub fn mul(&self, rhs: &Self) -> Self

source

pub fn div(&self, rhs: &Self) -> Self

source

pub fn rem(&self, rhs: &Self) -> Self

source

pub fn sum_over(&self, dim: isize) -> Self

source

pub fn gt(&self, rhs: &Self) -> Tensor<bool>

source

pub fn lt(&self, rhs: &Self) -> Tensor<bool>

source

pub fn top_k(&self, k: usize, dim: isize) -> Self

source

pub fn argmax<O: Integer + Unsigned>(&self, dim: isize) -> Tensor<O>

Collapse dimension using index of its greatest value

source

pub fn clamp(&self, min: T, max: T) -> Self

source

pub fn cast<I: Numeric>(&self) -> Tensor<I>

Examples found in repository?
examples/perceptron_eager.rs (line 64)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
fn main() {
  // Construct model that stores all trainable tensors explicitly
  let model = Perceptron::new(28 * 28);

  // Train with labeled samples
  let learning_rate = 0.01;
  for _ in 0..100 {
    // Insert real training data here
    let images = Tensor::ones(&[32, 28 * 28]);
    let labels = (Tensor::rand(&[32]) * 10.0).cast::<u8>().one_hot(10);

    // Run the model, creating a fresh computation graph in the process
    let output = model.run(&images.tracked());

    // Compute loss
    let loss = (&labels.tracked() - &output).sqr().mean(0);

    // Compute gradients
    loss.backward();

    // Minimize loss by updating model parameters
    for mut param in loss.parameters() {
      param -= param.grad().unwrap() * learning_rate
    }

    // Reset gradients
    loss.reset();
  }
}
More examples
Hide additional examples
examples/perceptron_graph.rs (line 43)
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() {
  // Define model by performing all computations on a placeholder once
  let image_input = Tensor::zeros(&[32, 28 * 28]).tracked();
  let output = perceptron(&image_input);

  // Define the loss to me minimized
  let label_input = Tensor::zeros(&[32, 10]).tracked();
  let loss = (&label_input - &output).sqr().mean(0);

  // Train with some labeled samples
  let learning_rate = 0.01;
  for _ in 0..100 {
    // Insert real training data here
    let images = Tensor::ones(&[32, 28 * 28]).tracked();
    let labels = (Tensor::rand(&[32]) * 10.0).cast::<u8>().one_hot(10);

    // Feed existing computation graph with new inputs
    image_input.feed(&images);
    label_input.feed(&labels);

    // Recompute output and loss
    loss.forward();

    // Compute gradients
    loss.backward();

    // Minimize loss by updating model parameters
    for mut param in loss.parameters() {
      param -= param.grad().unwrap() * learning_rate
    }

    // Reset gradients
    loss.reset();
  }
}
source§

impl<T: Real> Tensor<T>

source

pub fn rand(shape: &[usize]) -> Self

Examples found in repository?
examples/perceptron_eager.rs (line 64)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
fn main() {
  // Construct model that stores all trainable tensors explicitly
  let model = Perceptron::new(28 * 28);

  // Train with labeled samples
  let learning_rate = 0.01;
  for _ in 0..100 {
    // Insert real training data here
    let images = Tensor::ones(&[32, 28 * 28]);
    let labels = (Tensor::rand(&[32]) * 10.0).cast::<u8>().one_hot(10);

    // Run the model, creating a fresh computation graph in the process
    let output = model.run(&images.tracked());

    // Compute loss
    let loss = (&labels.tracked() - &output).sqr().mean(0);

    // Compute gradients
    loss.backward();

    // Minimize loss by updating model parameters
    for mut param in loss.parameters() {
      param -= param.grad().unwrap() * learning_rate
    }

    // Reset gradients
    loss.reset();
  }
}
More examples
Hide additional examples
examples/perceptron_graph.rs (line 43)
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() {
  // Define model by performing all computations on a placeholder once
  let image_input = Tensor::zeros(&[32, 28 * 28]).tracked();
  let output = perceptron(&image_input);

  // Define the loss to me minimized
  let label_input = Tensor::zeros(&[32, 10]).tracked();
  let loss = (&label_input - &output).sqr().mean(0);

  // Train with some labeled samples
  let learning_rate = 0.01;
  for _ in 0..100 {
    // Insert real training data here
    let images = Tensor::ones(&[32, 28 * 28]).tracked();
    let labels = (Tensor::rand(&[32]) * 10.0).cast::<u8>().one_hot(10);

    // Feed existing computation graph with new inputs
    image_input.feed(&images);
    label_input.feed(&labels);

    // Recompute output and loss
    loss.forward();

    // Compute gradients
    loss.backward();

    // Minimize loss by updating model parameters
    for mut param in loss.parameters() {
      param -= param.grad().unwrap() * learning_rate
    }

    // Reset gradients
    loss.reset();
  }
}
source

pub fn randn(shape: &[usize]) -> Self

Examples found in repository?
examples/perceptron_eager.rs (line 26)
24
25
26
27
28
29
  pub fn new(input_size: usize, size: usize) -> Self {
    Self {
      weights: (Tensor::randn(&[input_size, size]) / size as f32).trained(),
      bias: Tensor::zeros(&[size]).trained(),
    }
  }
More examples
Hide additional examples
examples/perceptron_graph.rs (line 19)
18
19
20
21
22
fn dense_layer(input: &Variable<f32>, size: usize) -> Variable<f32> {
  let weights = (Tensor::randn(&[input.shape()[-1], size]) / size as f32).trained();
  let bias = Tensor::zeros(&[size]).trained();
  input.mm(&weights) + bias
}
examples/basic.rs (line 6)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() {
  // Define some tensors
  let x = Tensor::vec(&[1.0, 2.0]);
  let w = Tensor::randn(&[2, 8]).trained();
  let b = Tensor::zeros(&[8]).trained();

  // Do some computation
  let z = (x.tracked().mm(&w) + b - 0.5).sqr().mean(0);

  // Compute gradients
  z.backward();

  println!("Gradient of z with respect to w: {}", w.grad().unwrap());

  // Nudge w and b in order to minimize z
  for mut param in z.parameters() {
    param -= param.grad().unwrap() * 0.01
  }
}
examples/graph.rs (line 23)
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
fn build_model(filename: &str) {
  // Have some inputs
  let x1 = Tensor::vec(&[1.0, 2.0]).tracked();
  let x2 = Tensor::ones(&[16]).tracked();
  let w = Tensor::randn(&[2, 16]).trained();

  // Do some computations
  let y = x1.mm(&w);
  let z = (&y * &x2).sum(0);

  // Pack the resulting graph into a Graph structure to make its inputs
  // and outputs explicit and arrange them in an order of your liking.
  let graph = Graph::new(&[x1, x2], &[y, z]);

  // Save entire computation graph to disc
  graph.save(filename).unwrap();
}

fn load_model(filename: &str) {
  let graph = Graph::load(filename).unwrap();

  // Feed new data using #run.
  // Updating the entire graph in this way is more efficient
  // than calling #forward on each individual output.
  graph.run(&[
    &Tensor::vec(&[5.0, 6.0]).tracked(),
    &Tensor::randn(&[16]).tracked(),
  ]);

  // Get new output..
  let z = &graph.outputs[1];
  println!("z is now {}", z.item());

  // ..or train the model further
  let z = &graph.outputs[1];
  z.backward();
  for mut param in z.parameters() {
    param -= param.grad().unwrap() * 0.01
  }
}
source

pub fn linspace(shape: &[usize], start: T, end: T) -> Self

source

pub fn bernoulli<O: Numeric>(&self) -> Tensor<O>

source

pub fn sample(&self) -> usize

source

pub fn trained(&self) -> Variable<T>

Examples found in repository?
examples/perceptron_eager.rs (line 26)
24
25
26
27
28
29
  pub fn new(input_size: usize, size: usize) -> Self {
    Self {
      weights: (Tensor::randn(&[input_size, size]) / size as f32).trained(),
      bias: Tensor::zeros(&[size]).trained(),
    }
  }
More examples
Hide additional examples
examples/perceptron_graph.rs (line 19)
18
19
20
21
22
fn dense_layer(input: &Variable<f32>, size: usize) -> Variable<f32> {
  let weights = (Tensor::randn(&[input.shape()[-1], size]) / size as f32).trained();
  let bias = Tensor::zeros(&[size]).trained();
  input.mm(&weights) + bias
}
examples/basic.rs (line 6)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() {
  // Define some tensors
  let x = Tensor::vec(&[1.0, 2.0]);
  let w = Tensor::randn(&[2, 8]).trained();
  let b = Tensor::zeros(&[8]).trained();

  // Do some computation
  let z = (x.tracked().mm(&w) + b - 0.5).sqr().mean(0);

  // Compute gradients
  z.backward();

  println!("Gradient of z with respect to w: {}", w.grad().unwrap());

  // Nudge w and b in order to minimize z
  for mut param in z.parameters() {
    param -= param.grad().unwrap() * 0.01
  }
}
examples/graph.rs (line 23)
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
fn build_model(filename: &str) {
  // Have some inputs
  let x1 = Tensor::vec(&[1.0, 2.0]).tracked();
  let x2 = Tensor::ones(&[16]).tracked();
  let w = Tensor::randn(&[2, 16]).trained();

  // Do some computations
  let y = x1.mm(&w);
  let z = (&y * &x2).sum(0);

  // Pack the resulting graph into a Graph structure to make its inputs
  // and outputs explicit and arrange them in an order of your liking.
  let graph = Graph::new(&[x1, x2], &[y, z]);

  // Save entire computation graph to disc
  graph.save(filename).unwrap();
}
source

pub fn tracked(&self) -> Variable<T>

Examples found in repository?
examples/basic.rs (line 10)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() {
  // Define some tensors
  let x = Tensor::vec(&[1.0, 2.0]);
  let w = Tensor::randn(&[2, 8]).trained();
  let b = Tensor::zeros(&[8]).trained();

  // Do some computation
  let z = (x.tracked().mm(&w) + b - 0.5).sqr().mean(0);

  // Compute gradients
  z.backward();

  println!("Gradient of z with respect to w: {}", w.grad().unwrap());

  // Nudge w and b in order to minimize z
  for mut param in z.parameters() {
    param -= param.grad().unwrap() * 0.01
  }
}
More examples
Hide additional examples
examples/graph.rs (line 21)
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
fn build_model(filename: &str) {
  // Have some inputs
  let x1 = Tensor::vec(&[1.0, 2.0]).tracked();
  let x2 = Tensor::ones(&[16]).tracked();
  let w = Tensor::randn(&[2, 16]).trained();

  // Do some computations
  let y = x1.mm(&w);
  let z = (&y * &x2).sum(0);

  // Pack the resulting graph into a Graph structure to make its inputs
  // and outputs explicit and arrange them in an order of your liking.
  let graph = Graph::new(&[x1, x2], &[y, z]);

  // Save entire computation graph to disc
  graph.save(filename).unwrap();
}

fn load_model(filename: &str) {
  let graph = Graph::load(filename).unwrap();

  // Feed new data using #run.
  // Updating the entire graph in this way is more efficient
  // than calling #forward on each individual output.
  graph.run(&[
    &Tensor::vec(&[5.0, 6.0]).tracked(),
    &Tensor::randn(&[16]).tracked(),
  ]);

  // Get new output..
  let z = &graph.outputs[1];
  println!("z is now {}", z.item());

  // ..or train the model further
  let z = &graph.outputs[1];
  z.backward();
  for mut param in z.parameters() {
    param -= param.grad().unwrap() * 0.01
  }
}
examples/perceptron_eager.rs (line 67)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
fn main() {
  // Construct model that stores all trainable tensors explicitly
  let model = Perceptron::new(28 * 28);

  // Train with labeled samples
  let learning_rate = 0.01;
  for _ in 0..100 {
    // Insert real training data here
    let images = Tensor::ones(&[32, 28 * 28]);
    let labels = (Tensor::rand(&[32]) * 10.0).cast::<u8>().one_hot(10);

    // Run the model, creating a fresh computation graph in the process
    let output = model.run(&images.tracked());

    // Compute loss
    let loss = (&labels.tracked() - &output).sqr().mean(0);

    // Compute gradients
    loss.backward();

    // Minimize loss by updating model parameters
    for mut param in loss.parameters() {
      param -= param.grad().unwrap() * learning_rate
    }

    // Reset gradients
    loss.reset();
  }
}
examples/perceptron_graph.rs (line 31)
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() {
  // Define model by performing all computations on a placeholder once
  let image_input = Tensor::zeros(&[32, 28 * 28]).tracked();
  let output = perceptron(&image_input);

  // Define the loss to me minimized
  let label_input = Tensor::zeros(&[32, 10]).tracked();
  let loss = (&label_input - &output).sqr().mean(0);

  // Train with some labeled samples
  let learning_rate = 0.01;
  for _ in 0..100 {
    // Insert real training data here
    let images = Tensor::ones(&[32, 28 * 28]).tracked();
    let labels = (Tensor::rand(&[32]) * 10.0).cast::<u8>().one_hot(10);

    // Feed existing computation graph with new inputs
    image_input.feed(&images);
    label_input.feed(&labels);

    // Recompute output and loss
    loss.forward();

    // Compute gradients
    loss.backward();

    // Minimize loss by updating model parameters
    for mut param in loss.parameters() {
      param -= param.grad().unwrap() * learning_rate
    }

    // Reset gradients
    loss.reset();
  }
}
source§

impl<T: Integer> Tensor<T>

source

pub fn accuracy<O: Real>(&self, labels: &Self) -> O

source§

impl<T: Integer + Unsigned> Tensor<T>

source

pub fn one_hot<O: Numeric>(&self, size: usize) -> Tensor<O>

Examples found in repository?
examples/perceptron_eager.rs (line 64)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
fn main() {
  // Construct model that stores all trainable tensors explicitly
  let model = Perceptron::new(28 * 28);

  // Train with labeled samples
  let learning_rate = 0.01;
  for _ in 0..100 {
    // Insert real training data here
    let images = Tensor::ones(&[32, 28 * 28]);
    let labels = (Tensor::rand(&[32]) * 10.0).cast::<u8>().one_hot(10);

    // Run the model, creating a fresh computation graph in the process
    let output = model.run(&images.tracked());

    // Compute loss
    let loss = (&labels.tracked() - &output).sqr().mean(0);

    // Compute gradients
    loss.backward();

    // Minimize loss by updating model parameters
    for mut param in loss.parameters() {
      param -= param.grad().unwrap() * learning_rate
    }

    // Reset gradients
    loss.reset();
  }
}
More examples
Hide additional examples
examples/perceptron_graph.rs (line 43)
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() {
  // Define model by performing all computations on a placeholder once
  let image_input = Tensor::zeros(&[32, 28 * 28]).tracked();
  let output = perceptron(&image_input);

  // Define the loss to me minimized
  let label_input = Tensor::zeros(&[32, 10]).tracked();
  let loss = (&label_input - &output).sqr().mean(0);

  // Train with some labeled samples
  let learning_rate = 0.01;
  for _ in 0..100 {
    // Insert real training data here
    let images = Tensor::ones(&[32, 28 * 28]).tracked();
    let labels = (Tensor::rand(&[32]) * 10.0).cast::<u8>().one_hot(10);

    // Feed existing computation graph with new inputs
    image_input.feed(&images);
    label_input.feed(&labels);

    // Recompute output and loss
    loss.forward();

    // Compute gradients
    loss.backward();

    // Minimize loss by updating model parameters
    for mut param in loss.parameters() {
      param -= param.grad().unwrap() * learning_rate
    }

    // Reset gradients
    loss.reset();
  }
}
source

pub fn confusion(&self, labels: &Self) -> Self

source§

impl<T: Signed> Tensor<T>

source

pub fn signum(&self) -> Self

source§

impl Tensor<bool>

source

pub fn numeric<O: Numeric>(&self) -> Tensor<O>

source

pub fn and(&self, rhs: &Self) -> Self

source

pub fn or(&self, rhs: &Self) -> Self

source

pub fn all(&self) -> Option<bool>

source

pub fn any(&self) -> Option<bool>

source

pub fn when<O: Inner>(&self, either: Tensor<O>, or: Tensor<O>) -> Tensor<O>

Trait Implementations§

source§

impl<T: Numeric> Add<&Tensor<T>> for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Tensor<T>

Performs the + operation. Read more
source§

impl<T: Numeric> Add<&Tensor<T>> for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Tensor<T>) -> Tensor<T>

Performs the + operation. Read more
source§

impl Add<&Tensor<f32>> for f32

§

type Output = Tensor<f32>

The resulting type after applying the + operator.
source§

fn add(self, tensor: &Tensor<f32>) -> Tensor<f32>

Performs the + operation. Read more
source§

impl<T: Numeric> Add<T> for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: T) -> Tensor<T>

Performs the + operation. Read more
source§

impl<T: Numeric> Add<T> for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: T) -> Tensor<T>

Performs the + operation. Read more
source§

impl<T: Numeric> Add<Tensor<T>> for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Tensor<T>) -> Tensor<T>

Performs the + operation. Read more
source§

impl<T: Numeric> Add<Tensor<T>> for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Tensor<T>

Performs the + operation. Read more
source§

impl Add<Tensor<f32>> for f32

§

type Output = Tensor<f32>

The resulting type after applying the + operator.
source§

fn add(self, tensor: Tensor<f32>) -> Tensor<f32>

Performs the + operation. Read more
source§

impl<T: Numeric> AddAssign<Tensor<T>> for Tensor<T>

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl<T: Real> AddAssign<Tensor<T>> for Variable<T>

source§

fn add_assign(&mut self, rhs: Tensor<T>)

Performs the += operation. Read more
source§

impl<T: Inner> BaseHops<T> for Tensor<T>

source§

fn at(&self, indices: &[isize]) -> Self

source§

fn squeeze_only(&self, dim: isize) -> Self

source§

fn squeeze_but(&self, dim: isize) -> Self

source§

fn squeeze_first(&self, n: usize) -> Self

source§

fn squeeze_all(&self) -> Self

source§

fn unsqueeze_n(&self, n: usize, dim: isize) -> Self

source§

fn extend(&self, rank: usize) -> Self

source§

fn stack(rows: &[Self], dim: isize) -> Self

source§

fn rows(rows: &[Self]) -> Self

source§

impl<T: Inner> BaseOps<T> for Tensor<T>

source§

fn scalar(item: T) -> Self

source§

fn shape(&self) -> &Shape

source§

fn range(&self, ranges: &[Range<isize>]) -> Self

source§

fn broadcast(&self, shape: &Shape, ignore_from: Option<isize>) -> Self

source§

fn reshape(&self, shape: &[usize]) -> Self

source§

fn squeeze(&self, squeezed: &[isize]) -> Self

source§

fn unsqueeze(&self, dim: isize) -> Self

source§

fn transpose(&self, dim1: isize, dim2: isize) -> Self

source§

fn concat(&self, rhs: &Self, dim: isize) -> Self

source§

impl<T: Clone + Inner> Clone for Tensor<T>

source§

fn clone(&self) -> Tensor<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Numeric> Cops<T> for Tensor<T>

source§

default fn matmul(&self, rhs: &Self) -> Vec<T>

source§

impl Cops<f32> for Tensor<f32>

source§

fn matmul(&self, rhs: &Self) -> Vec<f32>

source§

impl Cops<f64> for Tensor<f64>

source§

fn matmul(&self, rhs: &Self) -> Vec<f64>

source§

impl<T: Debug + Inner> Debug for Tensor<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, T> Deserialize<'de> for Tensor<T>where T: Deserialize<'de> + Inner,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: Inner> Display for Tensor<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Numeric> Div<&Tensor<T>> for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: Self) -> Tensor<T>

Performs the / operation. Read more
source§

impl<T: Numeric> Div<&Tensor<T>> for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: &Tensor<T>) -> Tensor<T>

Performs the / operation. Read more
source§

impl Div<&Tensor<f32>> for f32

§

type Output = Tensor<f32>

The resulting type after applying the / operator.
source§

fn div(self, tensor: &Tensor<f32>) -> Tensor<f32>

Performs the / operation. Read more
source§

impl<T: Numeric> Div<T> for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Tensor<T>

Performs the / operation. Read more
source§

impl<T: Numeric> Div<T> for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Tensor<T>

Performs the / operation. Read more
source§

impl<T: Numeric> Div<Tensor<T>> for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: Tensor<T>) -> Tensor<T>

Performs the / operation. Read more
source§

impl<T: Numeric> Div<Tensor<T>> for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: Self) -> Tensor<T>

Performs the / operation. Read more
source§

impl Div<Tensor<f32>> for f32

§

type Output = Tensor<f32>

The resulting type after applying the / operator.
source§

fn div(self, tensor: Tensor<f32>) -> Tensor<f32>

Performs the / operation. Read more
source§

impl<T: Numeric> DivAssign<Tensor<T>> for Tensor<T>

source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
source§

impl<T: Real> DivAssign<Tensor<T>> for Variable<T>

source§

fn div_assign(&mut self, rhs: Tensor<T>)

Performs the /= operation. Read more
source§

impl<T: Numeric> Mul<&Tensor<T>> for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Tensor<T>

Performs the * operation. Read more
source§

impl<T: Numeric> Mul<&Tensor<T>> for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Tensor<T>) -> Tensor<T>

Performs the * operation. Read more
source§

impl Mul<&Tensor<f32>> for f32

§

type Output = Tensor<f32>

The resulting type after applying the * operator.
source§

fn mul(self, tensor: &Tensor<f32>) -> Tensor<f32>

Performs the * operation. Read more
source§

impl<T: Numeric> Mul<T> for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: T) -> Tensor<T>

Performs the * operation. Read more
source§

impl<T: Numeric> Mul<T> for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: T) -> Tensor<T>

Performs the * operation. Read more
source§

impl<T: Numeric> Mul<Tensor<T>> for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Tensor<T>) -> Tensor<T>

Performs the * operation. Read more
source§

impl<T: Numeric> Mul<Tensor<T>> for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Tensor<T>

Performs the * operation. Read more
source§

impl Mul<Tensor<f32>> for f32

§

type Output = Tensor<f32>

The resulting type after applying the * operator.
source§

fn mul(self, tensor: Tensor<f32>) -> Tensor<f32>

Performs the * operation. Read more
source§

impl<T: Numeric> MulAssign<Tensor<T>> for Tensor<T>

source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
source§

impl<T: Real> MulAssign<Tensor<T>> for Variable<T>

source§

fn mul_assign(&mut self, rhs: Tensor<T>)

Performs the *= operation. Read more
source§

impl<T: Signed> Neg for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl<T: Signed> Neg for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl Not for Tensor<bool>

§

type Output = Tensor<bool>

The resulting type after applying the ! operator.
source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
source§

impl<T: Numeric> NumericOps<T> for Tensor<T>

source§

fn sum(&self, dim: isize) -> Self

source§

fn mm(&self, rhs: &Self) -> Self

source§

fn min(&self, dim: isize) -> Self

source§

fn max(&self, dim: isize) -> Self

source§

fn max_over(&self, _dim: isize) -> Self

source§

impl<T: Inner> PartialEq<Tensor<T>> for Tensor<T>

source§

fn eq(&self, rhs: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Real> RealHops<T> for Tensor<T>

source§

fn powf(&self, exp: I) -> Self

source§

fn sqr(&self) -> Self

source§

fn sqrt(&self) -> Self

source§

fn exp(&self) -> Self

source§

fn norm(&self, dim: isize) -> Self

source§

fn dot(&self, rhs: &Self, dim: isize) -> Self

source§

fn mean(&self, dim: isize) -> Self

source§

fn variance(&self, dim: isize) -> Self

source§

fn softmax(&self, dim: isize) -> Self

source§

fn max_with(&self, rhs: &Self) -> Self

source§

impl<T: Real> RealOps<T> for Tensor<T>

source§

fn pow(&self, rhs: &Self) -> Self

source§

fn sin(&self) -> Self

source§

fn cos(&self) -> Self

source§

fn log(&self) -> Self

source§

fn relu(&self) -> Self

source§

fn sigmoid(&self) -> Self

source§

impl<T: Numeric> Rem<&Tensor<T>> for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the % operator.
source§

fn rem(self, rhs: Self) -> Tensor<T>

Performs the % operation. Read more
source§

impl<T: Numeric> Rem<&Tensor<T>> for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the % operator.
source§

fn rem(self, rhs: &Tensor<T>) -> Tensor<T>

Performs the % operation. Read more
source§

impl Rem<&Tensor<f32>> for f32

§

type Output = Tensor<f32>

The resulting type after applying the % operator.
source§

fn rem(self, tensor: &Tensor<f32>) -> Tensor<f32>

Performs the % operation. Read more
source§

impl<T: Numeric> Rem<T> for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the % operator.
source§

fn rem(self, rhs: T) -> Tensor<T>

Performs the % operation. Read more
source§

impl<T: Numeric> Rem<T> for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the % operator.
source§

fn rem(self, rhs: T) -> Tensor<T>

Performs the % operation. Read more
source§

impl<T: Numeric> Rem<Tensor<T>> for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the % operator.
source§

fn rem(self, rhs: Tensor<T>) -> Tensor<T>

Performs the % operation. Read more
source§

impl<T: Numeric> Rem<Tensor<T>> for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the % operator.
source§

fn rem(self, rhs: Self) -> Tensor<T>

Performs the % operation. Read more
source§

impl Rem<Tensor<f32>> for f32

§

type Output = Tensor<f32>

The resulting type after applying the % operator.
source§

fn rem(self, tensor: Tensor<f32>) -> Tensor<f32>

Performs the % operation. Read more
source§

impl<T> Serialize for Tensor<T>where T: Serialize + Inner,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: Signed> SignedOps<T> for Tensor<T>

source§

fn abs(&self) -> Self

source§

impl<T: Numeric> Sub<&Tensor<T>> for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Tensor<T>

Performs the - operation. Read more
source§

impl<T: Numeric> Sub<&Tensor<T>> for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Tensor<T>) -> Tensor<T>

Performs the - operation. Read more
source§

impl Sub<&Tensor<f32>> for f32

§

type Output = Tensor<f32>

The resulting type after applying the - operator.
source§

fn sub(self, tensor: &Tensor<f32>) -> Tensor<f32>

Performs the - operation. Read more
source§

impl<T: Numeric> Sub<T> for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: T) -> Tensor<T>

Performs the - operation. Read more
source§

impl<T: Numeric> Sub<T> for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: T) -> Tensor<T>

Performs the - operation. Read more
source§

impl<T: Numeric> Sub<Tensor<T>> for &Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Tensor<T>) -> Tensor<T>

Performs the - operation. Read more
source§

impl<T: Numeric> Sub<Tensor<T>> for Tensor<T>

§

type Output = Tensor<T>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Tensor<T>

Performs the - operation. Read more
source§

impl Sub<Tensor<f32>> for f32

§

type Output = Tensor<f32>

The resulting type after applying the - operator.
source§

fn sub(self, tensor: Tensor<f32>) -> Tensor<f32>

Performs the - operation. Read more
source§

impl<T: Numeric> SubAssign<Tensor<T>> for Tensor<T>

source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
source§

impl<T: Real> SubAssign<Tensor<T>> for Variable<T>

source§

fn sub_assign(&mut self, rhs: Tensor<T>)

Performs the -= operation. Read more
source§

impl<T: Numeric> Sum<Tensor<T>> for Tensor<T>

source§

fn sum<I>(iter: I) -> Selfwhere I: Iterator + Iterator<Item = Self>,

Method which takes an iterator and generates Self from the elements by “summing up” the items.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Tensor<T>

§

impl<T> Send for Tensor<T>

§

impl<T> Sync for Tensor<T>

§

impl<T> Unpin for Tensor<T>

§

impl<T> !UnwindSafe for Tensor<T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Any for Twhere T: Any + Serialize + Deserialize,

source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert to a &std::any::Any.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert to a &mut std::any::Any.
source§

fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>

Convert to a std::boxed::Box<dyn std::any::Any>.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> Serialize for Twhere T: Serialize + ?Sized,

source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Type for Twhere T: ?Sized,

source§

default fn meta(self: *const T) -> <T as Type>::Meta

Retrieve TraitObject, Slice or Concrete meta data respectively for a type
source§

default fn data(self: *const T) -> *const ()

Retrieve pointer to the data
source§

default fn data_mut(self: *mut T) -> *mut ()

Retrieve mut pointer to the data
source§

default fn dangling(t: <T as Type>::Meta) -> NonNull<T>

Create a dangling non-null *const Self with the provided Self::Meta.
source§

default fn fatten(thin: *mut (), t: <T as Type>::Meta) -> *mut T

Create a *mut Self with the provided Self::Meta.
source§

const METATYPE: MetaType

Enum describing whether a type is TraitObject, Slice or Concrete.
§

type Meta: 'static

Type of metadata for type.
source§

fn meta_type(self: *const Self) -> MetaType

Helper method describing whether a type is TraitObject, Slice or Concrete.
source§

impl<T> Type for T

source§

const METATYPE: MetaType = MetaType::Concrete

Enum describing whether a type is TraitObject, Slice or Concrete.
§

type Meta = Concrete

Type of metadata for type.
source§

fn meta(self: *const T) -> <T as Type>::Meta

Retrieve TraitObject, Slice or Concrete meta data respectively for a type
source§

fn data(self: *const T) -> *const ()

Retrieve pointer to the data
source§

fn data_mut(self: *mut T) -> *mut ()

Retrieve mut pointer to the data
source§

fn dangling(_t: <T as Type>::Meta) -> NonNull<T>

Create a dangling non-null *const Self with the provided Self::Meta.
source§

fn fatten(thin: *mut (), _t: <T as Type>::Meta) -> *mut T

Create a *mut Self with the provided Self::Meta.
source§

fn meta_type(self: *const Self) -> MetaType

Helper method describing whether a type is TraitObject, Slice or Concrete.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> Debug for Twhere T: Debug + Serialize + Deserialize + ?Sized,

source§

impl<T> Deserialize for Twhere T: DeserializeOwned,

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

source§

impl<T> Display for Twhere T: Display + Serialize + Deserialize + ?Sized,

source§

impl<T> Inner for Twhere T: PartialEq<T> + Clone + Send + Sync + Debug,

source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for Twhere T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,

source§

impl<T, Base> RefNum<Base> for Twhere T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>,

source§

impl<T> Serialize for Twhere T: Serialize + ?Sized,