1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
use super::*;
use crate::gradients::{NoneTape, OwnedTape};
pub fn trace<T: Tensor<Tape = OwnedTape>>(t: &T::NoTape) -> T {
traced(t.duplicate())
}
pub fn traced<T: Tensor<Tape = OwnedTape>>(t: T::NoTape) -> T {
t.put_tape(OwnedTape::default())
}
macro_rules! tensor_impl {
($typename:ident, [$($Vs:tt),*]) => {
impl<$(const $Vs: usize, )*> $typename<$($Vs, )* NoneTape> {
pub fn trace(&self) -> $typename<$($Vs, )* OwnedTape> {
trace(self)
}
pub fn traced(self) -> $typename<$($Vs, )* OwnedTape> {
traced(self)
}
}
};
}
tensor_impl!(Tensor0D, []);
tensor_impl!(Tensor1D, [M]);
tensor_impl!(Tensor2D, [M, N]);
tensor_impl!(Tensor3D, [M, N, O]);
tensor_impl!(Tensor4D, [M, N, O, P]);