Add support for the default float, int and bool types for executorch::runtime::etensor::Scalar to` method #10040
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
float
,::executorch::runtime::etensor::Half
, and::executorch::runtime::etensor::BFloat16
forto
method of ExecuTorch's Scalarto
methods withto##name()
macros (same as PyTorch c10::Scalar).float
type.uint16/32/64_t
types (since 'uint64_t' can overflow' int64_t', separate logic is required) and does not includeexecutorch::runtime::etensor::complex
.c10::overflows.h
from torch. (I will add an overflow check after I figure out what is the right way to do this :))I need a bit further guidance related to adding support for more complex types and handling overflows:
TypeCast.h
for typecasting (similar to PyTorch c10). Would this be better than having the casting code in theScalar
class?c10::overflows.h
from pytorch c10 to handle overflows?Fixes #9500
P.S. If you have any concerns about this PR, please let me know, I will fix :)
Test plan
I added tests in' runtime/core/portable_type/test/scalar_test.cpp' for additional types types.