copy

copy tensor between devices

  1. auto copy(Tensor!(N, T, Src) x, Opt opt)
    @nogc nothrow
    copy
    (
    Dst
    size_t N
    T
    Src
    )
    (
    Tensor!(N, T, Src) x
    ,
    Opt opt
    )
  2. auto copy(Tensor!(N, T, Src) x)
  3. auto copy(Tensor!(N, T, Src) x)
  4. import grain.storage : DefaultCPUStorage;

Examples

1 import grain.ops.transposed : transposed;
2 import mir.ndslice.topology : iota, as;
3 import grain.tensor;
4 import std.meta : AliasSeq;
5 import std.typecons : tuple;
6 
7 static foreach (dtype; AliasSeq!(float, double, int, long))
8 {
9     {
10         auto x = Tensor!(2, dtype)(2, 3);
11         x.asSlice[] = iota(x.shape).as!dtype;
12         auto y = x.copy;
13         assert(y.asSlice == x.asSlice);
14         x.asSlice[0, 0] = 1;
15         assert(y.asSlice != x.asSlice);
16     }
17 }

Meta