import numir; import mir.ndslice; import grain.testing; auto hx = uniform!float(6, 4).slice.variable(true); auto hgy = uniform!float(2, 3, 4).slice.variable; auto ugy = UntypedVariable(hgy); auto hy = hx.view([2, 3, -1]); assert(hy.sliced == numir.view(hx.sliced, [2, 3, -1])); hy.backward(&ugy); assert(hx.gradSliced == numir.view(hgy.sliced, [6, 4])); // gradCheckChain!(x => x.view([2, 3, -1]))(hx, hgy, 1e-3, 5e-2, 5e-2);
/ Topology functions reorganizing shape while it hold total elements a.k.a. reshape. At most one dimension of the new shape can be -1. In this case, the value is inferred from the size of the tensor and the remaining dimensions.