-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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]: TensorPrimitives: convert Span<Byte> to Span<Float> and back #103756
Comments
Tagging subscribers to this area: @dotnet/area-system-numerics-tensors |
Converting between two different types is supported via the generic TensorPrimitives.ConvertTruncating, ConvertSaturating, and ConvertChecked methods. There's no built-in operation that currently combines that with the divide, but it can be done with a second call:
|
No wonder I could not find these methods.... they're in the Net9 preview packages, is that right? Anyway, given it's in preview, I would still include a byte to float conversion with divide: it's such a common operation that any future improvement would automatically be used by everybody, that is, imagine that some platform introduces a fast path for this exact operation... |
Yes |
Looking at the code, I don't see that ConvertTruncating has any kind of vectorial acceleration code to convert byte to float. Right now, is there an advantage of using ConvertTruncating, over a plain loop? |
Not in what's merged, but that's just a matter of adding an additional path for these types, e.g. |
Background and motivation
Working with images and tensors, it is fairly common to convert an array of bytes to an array of floats.
Also, in many cases the conversion requires some normalization or scaling, that is, byte values in the range of 0-255 are converted to float values in the range of 0-1
The usual operation is this:
Now, I don't know if there's faster way of doing this using SIMD, or any other exotic, platform specific mechanism, but if it doesn't exist now, it may exist in the future, so by using a system function, any current application may benefit from future improvements on the API.
Also, I don't know if this conversion already exists somewhere else in the APIs, I've looked for it without success. But certainly, I would expect such conversions to be available in TensorPrimitives.
My needs are limited to byte-float conversions, but certainly, other types may be included.
API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: