Skip to content

Ensure ISimdVector default implementations throw documented exceptions #104831

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

Closed
wants to merge 3 commits into from
Closed
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 @@ -154,7 +154,14 @@ internal unsafe interface ISimdVector<TSelf, T>
/// <exception cref="ArgumentException">The length of <paramref name="destination" /> is less than <see cref="Count" />.</exception>
/// <exception cref="NotSupportedException">The type of the elements in the vector (<typeparamref name="T" />) is not supported.</exception>
/// <exception cref="NullReferenceException"><paramref name="destination" /> is <c>null</c>.</exception>
static virtual void CopyTo(TSelf vector, T[] destination) => TSelf.CopyTo(vector, destination.AsSpan());
static virtual void CopyTo(TSelf vector, T[] destination)
{
if (destination.Length < TSelf.Count)
{
ThrowHelper.ThrowArgumentException_DestinationTooShort();
}
TSelf.StoreUnsafe(vector, ref MemoryMarshal.GetArrayDataReference(destination));
}

/// <summary>Copies a vector to a given array starting at the specified index.</summary>
/// <param name="vector">The vector to be copied.</param>
Expand All @@ -164,7 +171,18 @@ internal unsafe interface ISimdVector<TSelf, T>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="startIndex" /> is negative or greater than the length of <paramref name="destination" />.</exception>
/// <exception cref="NotSupportedException">The type of the elements in the vector (<typeparamref name="T" />) is not supported.</exception>
/// <exception cref="NullReferenceException"><paramref name="destination" /> is <c>null</c>.</exception>
static virtual void CopyTo(TSelf vector, T[] destination, int startIndex) => TSelf.CopyTo(vector, destination.AsSpan(startIndex));
static virtual void CopyTo(TSelf vector, T[] destination, int startIndex)
{
if ((uint)startIndex >= (uint)destination.Length)
{
ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess();
}
if ((destination.Length - startIndex) < TSelf.Count)
{
ThrowHelper.ThrowArgumentException_DestinationTooShort();
}
TSelf.StoreUnsafe(vector, ref MemoryMarshal.GetArrayDataReference(destination), (uint)startIndex);
}

/// <summary>Copies a vector to a given span.</summary>
/// <param name="vector">The vector to be copied.</param>
Expand Down Expand Up @@ -192,7 +210,14 @@ static virtual void CopyTo(TSelf vector, Span<T> destination)
/// <exception cref="ArgumentOutOfRangeException">The length of <paramref name="values" /> is less than <see cref="Count" />.</exception>
/// <exception cref="NotSupportedException">The type of the elements in the vector (<typeparamref name="T" />) is not supported.</exception>
/// <exception cref="NullReferenceException"><paramref name="values" /> is <c>null</c>.</exception>
static virtual TSelf Create(T[] values) => TSelf.Create(values.AsSpan());
static virtual TSelf Create(T[] values)
{
if (values.Length < TSelf.Count)
{
ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException();
}
return TSelf.LoadUnsafe(ref MemoryMarshal.GetArrayDataReference(values));
}

/// <summary>Creates a new vector from a given array.</summary>
/// <param name="values">The array from which the vector is created.</param>
Expand All @@ -201,7 +226,14 @@ static virtual void CopyTo(TSelf vector, Span<T> destination)
/// <exception cref="ArgumentOutOfRangeException">The length of <paramref name="values" />, starting from <paramref name="index" />, is less than <see cref="Count" />.</exception>
/// <exception cref="NotSupportedException">The type of the elements in the vector (<typeparamref name="T" />) is not supported.</exception>
/// <exception cref="NullReferenceException"><paramref name="values" /> is <c>null</c>.</exception>
static virtual TSelf Create(T[] values, int index) => TSelf.Create(values.AsSpan(index));
static virtual TSelf Create(T[] values, int index)
{
if ((index < 0) || ((values.Length - index) < TSelf.Count))
{
ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException();
}
return TSelf.LoadUnsafe(ref MemoryMarshal.GetArrayDataReference(values), (uint)index);
}

/// <summary>Creates a new vector from a given readonly span.</summary>
/// <param name="values">The readonly span from which the vector is created.</param>
Expand Down
Loading