Tensor validations, scope changes, and TensorPrimitives methods#103005
Tensor validations, scope changes, and TensorPrimitives methods#103005michaelgsharp merged 5 commits intodotnet:mainfrom
Conversation
|
Note regarding the |
|
Tagging subscribers to this area: @dotnet/area-system-numerics-tensors |
src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs
Show resolved
Hide resolved
| public static System.Numerics.Tensors.TensorSpan<T> AsTensorSpan<T>(this T[]? array, scoped System.ReadOnlySpan<nint> shape) { throw null; } | ||
| public static bool SequenceEqual<T>(this System.Numerics.Tensors.TensorSpan<T> span, System.Numerics.Tensors.TensorSpan<T> other) where T : System.IEquatable<T>? { throw null; } | ||
| public static System.Numerics.Tensors.TensorSpan<T> AbsInPlace<T>(System.Numerics.Tensors.TensorSpan<T> input) where T : System.IEquatable<T>, System.Numerics.IEqualityOperators<T, T, bool>, System.Numerics.INumberBase<T> { throw null; } | ||
| public static System.Numerics.Tensors.TensorSpan<T> Abs<T>(System.Numerics.Tensors.TensorSpan<T> input) where T : System.IEquatable<T>, System.Numerics.IEqualityOperators<T, T, bool>, System.Numerics.INumberBase<T> { throw null; } |
There was a problem hiding this comment.
A lot of these inputs should be ReadOnlyTensorSpan to indicate they can't be mutated. They should also be scoped to indicate the return buffer won't be capturing the underlying byref.
There was a problem hiding this comment.
I'm not going to block the PR on this happening, so we can get the improvements in.
But we do need to fix it in a follow up.
src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs
Outdated
Show resolved
Hide resolved
| /// <remarks>Returns default when <paramref name="array"/> is null.</remarks> | ||
| /// <exception cref="ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception> | ||
| public ReadOnlyTensorSpan(T[]? array) : this(array, 0, [], []) | ||
| public ReadOnlyTensorSpan(T[]? array) : this(array, 0, [array?.Length ?? 0], []) |
There was a problem hiding this comment.
nit: This is one of the cases where for perf reasons we should have a simpler implementation in the constructor body rather than deferring down to the other overload
tannergooding
left a comment
There was a problem hiding this comment.
Still more work to do, but this is an incremental improvement in the right direction
55a77fd to
fe754db
Compare
|
wasm failures are known issues. |
This PR adds in a bunch of additional validations for Tensors, TensorSpans, and ReadOnlyTensorSpans to make sure they are constructed correctly and that the associated lengths/strides are correct/safe/sensible.
Adds in the changes made by the scope analysis to add in or remove
scopedas needed.Adds all but a small handful of TensorPrimitives methods for the Tensors/TensorSpans.
This PR is blocked until #102998 gets merged in.