Skip to content

System.Numerics.Tensors Should omit .Reshape function.  #106539

@soerenwolfers

Description

@soerenwolfers

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

returns 2.

Metadata

Metadata

Assignees

Labels

area-System.Numerics.Tensorsin-prThere is an active PR which will close this issue when it is merged

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions