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

[API Proposal]: Vector.Create #94384

Open
EgorBo opened this issue Nov 5, 2023 · 5 comments
Open

[API Proposal]: Vector.Create #94384

EgorBo opened this issue Nov 5, 2023 · 5 comments
Labels
api-ready-for-review API is ready for review, it is NOT ready for implementation area-System.Numerics
Milestone

Comments

@EgorBo
Copy link
Member

EgorBo commented Nov 5, 2023

Background and motivation

Currently, 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 Create methods to Vector2/3/4 and Vector<> too for slightly better consistency.

API Proposal

namespace System.Numerics
{
    public struct Vector
    {
        public static Vector<T> Create<T>(T value);
        public static Vector<T> Create<T>(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(Vector2 vector, 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(Vector2 vector, float z, float w);
        public static Vector4 Create(Vector3 vector, float w);
        public static Vector4 Create(ReadOnlySpan<float> values);
    }
}

We might also add T[] values, int offset and Span<T> overloads.

API Usage

Vector<int> v = Vector.Create(42);

Alternative Designs

No response

Risks

No response

@EgorBo EgorBo added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Nov 5, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 5, 2023
@ghost
Copy link

ghost commented Nov 5, 2023

Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.

Issue Details

Background and motivation

Currently, 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 Create methods to Vector2/3/4 and Vector<> too for slightly better consistency.

API Proposal

namespace 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 T[] values, int offset and Span<T> overloads.

API Usage

Vector<int> v = Vector.Create(42);

Alternative Designs

No response

Risks

No response

Author: EgorBo
Assignees: -
Labels:

api-suggestion, area-System.Numerics

Milestone: -

@EgorBo
Copy link
Member Author

EgorBo commented Nov 5, 2023

cc @tannergooding

@MichalPetryka
Copy link
Contributor

This'd probably be required for making them implement ISimdVector anyway?

@EgorBo
Copy link
Member Author

EgorBo commented Nov 6, 2023

This'd probably be required for making them implement ISimdVector anyway?

Probably? if we plan to implement ISimdVector in VectorT

@tannergooding
Copy link
Member

That's part of the long term plan, yes. However, I don't think ISimdVector can be made public without a language feature or two as we won't be able to correctly version it or expose some core APIs otherwise.

@tannergooding tannergooding added api-ready-for-review API is ready for review, it is NOT ready for implementation and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation untriaged New issue has not been triaged by the area owner labels Feb 14, 2024
@tannergooding tannergooding added this to the 9.0.0 milestone May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-ready-for-review API is ready for review, it is NOT ready for implementation area-System.Numerics
Projects
None yet
Development

No branches or pull requests

3 participants