copy

copy tensor between devices

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