-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tensor validations, scope changes, and TensorPrimitives methods #103005
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -43,7 +41,7 @@ namespace System.Numerics.Tensors | |||
/// <param name="array">The target array.</param> | |||
/// <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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
scoped
as needed.Adds all but a small handful of TensorPrimitives methods for the Tensors/TensorSpans.
This PR is blocked until #102998 gets merged in.