@@ -265,9 +265,15 @@ - (NSString *)description {
265265 auto const count = _tensor->numel ();
266266 os << " \n count: " << count << " ," ;
267267 os << " \n scalars: [" ;
268+ // Create a minimal context for error handling in ET_SWITCH
269+ struct {
270+ [[noreturn]] void fail (torch::executor::Error /* error */ ) {
271+ ET_CHECK_MSG (false , " Unsupported dtype in description" );
272+ }
273+ } ctx;
268274 ET_SWITCH_REALHBBF16_TYPES (
269275 static_cast <ScalarType>(_tensor->scalar_type ()),
270- nullptr ,
276+ ctx ,
271277 " description" ,
272278 CTYPE,
273279 [&] {
@@ -488,9 +494,15 @@ - (instancetype)initWithScalars:(NSArray<NSNumber *> *)scalars
488494 " Number of scalars does not match the shape" );
489495 std::vector<uint8_t > data;
490496 data.resize (count * ExecuTorchSizeOfDataType (dataType));
497+ // Create a minimal context for error handling in ET_SWITCH
498+ struct {
499+ [[noreturn]] void fail (torch::executor::Error /* error */ ) {
500+ ET_CHECK_MSG (false , " Unsupported dtype in initWithScalars" );
501+ }
502+ } ctx;
491503 for (NSUInteger index = 0 ; index < count; ++index) {
492504 ET_SWITCH_REALHBBF16_AND_UINT_TYPES (
493- static_cast <ScalarType>(dataType), nil , " initWithScalars" , CTYPE, [&] {
505+ static_cast <ScalarType>(dataType), ctx , " initWithScalars" , CTYPE, [&] {
494506 reinterpret_cast <CTYPE *>(data.data ())[index] = utils::toType<CTYPE>(scalars[index]);
495507 }
496508 );
@@ -801,8 +813,14 @@ + (instancetype)fullTensorWithShape:(NSArray<NSNumber *> *)shape
801813 dataType : (ExecuTorchDataType)dataType
802814 shapeDynamism : (ExecuTorchShapeDynamism)shapeDynamism {
803815 Scalar fillValue;
816+ // Create a minimal context for error handling in ET_SWITCH
817+ struct {
818+ [[noreturn]] void fail (torch::executor::Error /* error */ ) {
819+ ET_CHECK_MSG (false , " Unsupported dtype in fullTensor" );
820+ }
821+ } ctx;
804822 ET_SWITCH_REALHBBF16_AND_UINT_TYPES (
805- static_cast <ScalarType>(dataType), nil , " fullTensor" , CTYPE, [&] {
823+ static_cast <ScalarType>(dataType), ctx , " fullTensor" , CTYPE, [&] {
806824 fillValue = utils::toType<CTYPE>(scalar);
807825 }
808826 );
0 commit comments