The output of this.Reshape currently can expose entries of the backing memory that aren't available on this, which to me seems a fatal flaw.
It feels like .Reshape was added to match numpy functionality (correct me if that's wrong), but it's behaving subtly differently and I don't think there is value in having it over requiring users to create explicit new tensors.
For example,
var a = new TensorSpan<double>(array: [0d, 1, 2, 3]); // [0, 1, 2, 3]
var b = a.Reshape(lengths: new IntPtr[] { 2, 2 }); // [[0, 1], [2, 3]]
var c = b.Slice(ranges: new NRange[] { ..2, ..1}); // [[0], [2]]
var d = c.Reshape(lengths: new IntPtr[] {2, 1}); // [[0], [1]]!!!
Console.WriteLine(d[new IntPtr[] { 1, 0 }]); // 1
returns 1 whereas
import numpy as np
a = np.array([0, 1, 2, 3]) # [0, 1, 2, 3]
b = a.reshape([2, 2]) # [[0, 1], [2, 3]]
c = b[:2, :1] # [[0], [2]]
d = c.reshape([2, 1]) # [[0], [2]]
d[1, 0] # 2
The output of
this.Reshape
currently can expose entries of the backing memory that aren't available onthis
, which to me seems a fatal flaw.It feels like
.Reshape
was added to matchnumpy
functionality (correct me if that's wrong), but it's behaving subtly differently and I don't think there is value in having it over requiring users to create explicit new tensors.For example,
returns
1
whereasreturns
2
.