Skip to content
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

Consolidate a few exception throws in TensorPrimitives #93168

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,6 @@ public static float Distance(ReadOnlySpan<float> x, ReadOnlySpan<float> y)
ThrowHelper.ThrowArgument_SpansMustBeNonEmpty();
}

if (x.Length != y.Length)
{
ThrowHelper.ThrowArgument_SpansMustHaveSameLength();
}

return MathF.Sqrt(Aggregate<SubtractSquaredOperator, AddOperator>(x, y));
}

Expand Down Expand Up @@ -282,15 +277,8 @@ public static void Divide(ReadOnlySpan<float> x, float y, Span<float> destinatio
/// operating systems or architectures.
/// </para>
/// </remarks>
public static float Dot(ReadOnlySpan<float> x, ReadOnlySpan<float> y)
{
if (x.Length != y.Length)
{
ThrowHelper.ThrowArgument_SpansMustHaveSameLength();
}

return Aggregate<MultiplyOperator, AddOperator>(x, y);
}
public static float Dot(ReadOnlySpan<float> x, ReadOnlySpan<float> y) =>
Aggregate<MultiplyOperator, AddOperator>(x, y);

/// <summary>Computes the element-wise result of raising <c>e</c> to the single-precision floating-point number powers in the specified tensor.</summary>
/// <param name="x">The tensor, represented as a span.</param>
Expand Down Expand Up @@ -910,11 +898,6 @@ public static float ProductOfDifferences(ReadOnlySpan<float> x, ReadOnlySpan<flo
ThrowHelper.ThrowArgument_SpansMustBeNonEmpty();
}

if (x.Length != y.Length)
{
ThrowHelper.ThrowArgument_SpansMustHaveSameLength();
}

return Aggregate<SubtractOperator, MultiplyOperator>(x, y);
}

Expand Down Expand Up @@ -946,11 +929,6 @@ public static float ProductOfSums(ReadOnlySpan<float> x, ReadOnlySpan<float> y)
ThrowHelper.ThrowArgument_SpansMustBeNonEmpty();
}

if (x.Length != y.Length)
{
ThrowHelper.ThrowArgument_SpansMustHaveSameLength();
}

return Aggregate<AddOperator, MultiplyOperator>(x, y);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,10 @@ private static float Aggregate<TBinaryOperator, TAggregationOperator>(
where TBinaryOperator : struct, IBinaryOperator
where TAggregationOperator : struct, IAggregationOperator
{
Debug.Assert(x.Length == y.Length);
if (x.Length != y.Length)
{
ThrowHelper.ThrowArgument_SpansMustHaveSameLength();
}

if (x.IsEmpty)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ private static float Aggregate<TBinaryOperator, TAggregationOperator>(
where TBinaryOperator : struct, IBinaryOperator
where TAggregationOperator : struct, IAggregationOperator
{
Debug.Assert(x.Length == y.Length);
if (x.Length != y.Length)
{
ThrowHelper.ThrowArgument_SpansMustHaveSameLength();
}

if (x.Length == 0)
{
Expand Down