ditto
auto x = tensor!([0, 2, 2])([1, 2, 3, 4]); auto y = x.reshape!([0, 4]); assert(y.shape == [1, 4]); assert(y.value[0, 0] == 1); assert(y.value[0, 1] == 2); assert(y.value[0, 2] == 3); assert(y.value[0, 3] == 4); assert(x.grads == [[[0, 0], [0, 0]]]); y.backward(); assert(x.grads == [[[1, 1], [1, 1]]]);
ditto
auto x = tensor!([0, 4], UseGradient.no)([1, 2, 3, 4]); auto y = x.reshape!([1, 2, 2]); assert(y.shape == [1, 2, 2]); assert(y.value[0, 0, 0] == 1); assert(y.value[0, 0, 1] == 2); assert(y.value[0, 1, 0] == 3); assert(y.value[0, 1, 1] == 4); static assert(!canBackward!(typeof(y)));