-
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
API proposal: Enable AsVector<T> in Vector<T> #508
Comments
@msedi, I think this is a fine proposal to take to API review. However, could you please update the original post to explicitly call out the API you would like to be exposed? Our API review process is detailed here: https://github.com/dotnet/runtime/blob/master/docs/project/api-review-process.md |
@tannergooding I have updated my proposal and hope that it fits your needs. Otherwise please just come back and hit me ;-) |
For We don't need the implementation listed as that won't be important for API review. Instead, you could probably just comment that As for |
I updated the original post to just call out the As per my last comment, the |
namespace System.Numerics
{
public partial class Vector
{
public static Vector<TTo> As<TFrom, TTo>(Vector<TFrom> vector)
where TFrom : struct
where TTo : struct;
}
} |
No concerns here |
Marking this as public partial class Vector
{
public static Vector<TTo> As<TFrom, TTo>(this Vector<TFrom> vector)
where TFrom : struct
where TTo : struct;
} |
Since we don't have partial type inference now, the extension method still needs to be used as What about an instance method that delegates to the static cast? |
The reason why most of the methods were made extensions for I'd expect the same would be true for this variant. |
public partial class Vector
{
public static Vector<TTo> As<TFrom, TTo>(this Vector<TFrom> vector)
where TFrom : struct
where TTo : struct;
} |
Vector<T>
is a helpful tool to improve performance of certain code parts without large efforts.For number crunching we are using the
Vector<T>
very often, since our data is pretty large and the application ofVector<T>
really boosts performance. Also when it comes to data conversion or data reinterpretationVector<T>
is an essential part and has some methods to perform also these tasks.Rationale and Usage
However, the
AsVector"T"
inSystem.Numerics.Vector
can only be used comfortably when explicitly using their names for the given data type. The problem is that when dealing with a "generic" environment where the datatypes are not known in advance and can change often it is currently hard to use the above method. The same holds true for the 'ConvertTo"T"' routines that could als be expressed with the API suggestion below.Following example illustrates the problem:
Proposed API
The proposed API for this specific case is only a hand-crafted if..else solution as a wrapper around the current interface, but would solve problems in methods where the input and output datatypes can be better expressed by using generics. Following method is an API proposal that solves the problem for generic environments.
Original Proposal
AsVector
ConvertTo
When writing the proposal for ´ConvertTo` I encountered a problem where ConvertTo only supports a certain range of data types. I assume that this is due the support of SSE only. The question here is if it can be extended to all datatypes or at least have some sort of fallback that can deal with other datatypes.
The text was updated successfully, but these errors were encountered: