-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[API Proposal]: Vector.Create #94384
Comments
Tagging subscribers to this area: @dotnet/area-system-numerics Issue DetailsBackground and motivationCurrently, when we need to create a vector from a scalar or array, we do: _ = Vector64.Create(42);
_ = Vector128.Create(42);
_ = Vector256.Create(42);
_ = Vector512.Create(42);
_ = new Vector2(42);
_ = new Vector3(42);
_ = new Vector4(42);
_ = new Vector<int>(42); I propose we add API Proposalnamespace System.Numerics
{
public struct Vector
{
public static Vector<T> Create(T value);
public static Vector<T> Create(ReadOnlySpan<T> values);
}
public struct Vector2
{
public static Vector2 Create(float value);
public static Vector2 Create(float x, float y);
public static Vector2 Create(ReadOnlySpan<float> values);
}
public struct Vector3
{
public static Vector3 Create(float value);
public static Vector3 Create(float x, float y, float z);
public static Vector3 Create(ReadOnlySpan<float> values);
}
public struct Vector4
{
public static Vector4 Create(float value);
public static Vector4 Create(float x, float y, float z, float w);
public static Vector4 Create(ReadOnlySpan<float> values);
}
} Not might also add API UsageVector<int> v = Vector.Create(42); Alternative DesignsNo response RisksNo response
|
This'd probably be required for making them implement |
Probably? if we plan to implement ISimdVector in VectorT |
That's part of the long term plan, yes. However, I don't think |
Looks good as proposed namespace System.Numerics
{
public static partial class Vector
{
public static Vector<T> Create<T>(T value);
public static Vector<T> Create<T>(ReadOnlySpan<T> values);
public static Quaternion AsQuaternion(this Vector4 value);
public static Plane AsPlane(this Vector4 value);
public static Vector2 AsVector2(this Vector4 value);
public static Vector3 AsVector3(this Vector4 value);
public static Vector4 AsVector4(this Quaternion value);
public static Vector4 AsVector4(this Plane value);
public static Vector4 AsVector4(this Vector2 value);
public static Vector4 AsVector4(this Vector3 value);
public static Vector4 AsVector4Unsafe(this Vector2 value);
public static Vector4 AsVector4Unsafe(this Vector3 value);
}
public partial struct Vector2
{
public static Vector2 Create(float value);
public static Vector2 Create(float x, float y);
public static Vector2 Create(ReadOnlySpan<float> values);
}
public partial struct Vector3
{
public static Vector3 Create(float value);
public static Vector3 Create(float x, float y, float z);
public static Vector3 Create(Vector2 vector, float z);
public static Vector3 Create(ReadOnlySpan<float> values);
}
public partial struct Vector4
{
public static Vector4 Create(float value);
public static Vector4 Create(float x, float y, float z, float w);
public static Vector4 Create(Vector2 vector, float z, float w);
public static Vector4 Create(Vector3 vector, float w);
public static Vector4 Create(ReadOnlySpan<float> values);
}
}
namespace System.Runtime.Intrinsics
{
public static partial class Vector128
{
public static Vector128<float> AsVector128Unsafe(this Vector2 value);
public static Vector128<float> AsVector128Unsafe(this Vector3 value);
public static Vector128<float> AsVector128Unsafe(this Vector4 value);
}
} |
Do these |
They exist for parity with |
This was resolved in #103462 |
Background and motivation
Currently, when we need to create a vector from a scalar or array, we do:
I propose we add
Create
methods toVector2/3/4
andVector<>
too for slightly better consistency.API Proposal
We might also add
T[] values, int offset
andSpan<T>
overloads.API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: