@@ -38,7 +38,7 @@ static inline EValue toEValue(ExecuTorchValue *value) {
3838 return EValue ();
3939}
4040
41- static inline ExecuTorchValue *toExecuTorchValue (EValue value) {
41+ static inline ExecuTorchValue *toExecuTorchValue (EValue value) NS_RETURNS_RETAINED {
4242 if (value.isTensor ()) {
4343 auto nativeInstance = make_tensor_ptr (value.toTensor ());
4444 return [ExecuTorchValue valueWithTensor: [[ExecuTorchTensor alloc ] initWithNativeInstance: &nativeInstance]];
@@ -118,20 +118,20 @@ - (nullable instancetype)initWithMethodMetadata:(const MethodMeta &)methodMeta
118118 error : (NSError **)error {
119119 self = [super init ];
120120 if (self) {
121- _name = @( methodMeta.name ()) ;
121+ _name = [[ NSString alloc ] initWithUTF8String: methodMeta.name ()] ;
122122 const NSInteger inputCount = methodMeta.num_inputs ();
123123 const NSInteger outputCount = methodMeta.num_outputs ();
124124 const NSInteger attributeCount = methodMeta.num_attributes ();
125125 const NSInteger memoryPlannedBufferCount = methodMeta.num_memory_planned_buffers ();
126126 const NSInteger backendCount = methodMeta.num_backends ();
127127 _instructionCount = methodMeta.num_instructions ();
128- _inputValueTags = [NSMutableArray arrayWithCapacity : inputCount];
129- _outputValueTags = [NSMutableArray arrayWithCapacity : outputCount];
130- _inputTensorMetadatas = [NSMutableDictionary dictionary ];
131- _outputTensorMetadatas = [NSMutableDictionary dictionary ];
132- _attributeTensorMetadatas = [NSMutableArray arrayWithCapacity : attributeCount];
133- _memoryPlannedBufferSizes = [NSMutableArray arrayWithCapacity : memoryPlannedBufferCount];
134- _backendNames = [NSMutableArray arrayWithCapacity : backendCount];
128+ _inputValueTags = [[ NSMutableArray alloc ] initWithCapacity : inputCount];
129+ _outputValueTags = [[ NSMutableArray alloc ] initWithCapacity : outputCount];
130+ _inputTensorMetadatas = [NSMutableDictionary new ];
131+ _outputTensorMetadatas = [NSMutableDictionary new ];
132+ _attributeTensorMetadatas = [[ NSMutableArray alloc ] initWithCapacity : attributeCount];
133+ _memoryPlannedBufferSizes = [[ NSMutableArray alloc ] initWithCapacity : memoryPlannedBufferCount];
134+ _backendNames = [[ NSMutableArray alloc ] initWithCapacity : backendCount];
135135
136136 for (NSInteger index = 0 ; index < inputCount; ++index) {
137137 auto result = methodMeta.input_tag (index);
@@ -206,7 +206,7 @@ - (nullable instancetype)initWithMethodMetadata:(const MethodMeta &)methodMeta
206206 }
207207 return nil ;
208208 }
209- NSString *backendName = [NSString stringWithUTF8String : result.get ()];
209+ NSString *backendName = [[ NSString alloc ] initWithUTF8String : result.get ()];
210210 [_backendNames addObject: backendName];
211211 }
212212 }
@@ -308,9 +308,9 @@ - (BOOL)isMethodLoaded:(NSString *)methodName {
308308 }
309309 return nil ;
310310 }
311- NSMutableSet <NSString *> *methods = [NSMutableSet setWithCapacity : result->size ()];
311+ NSMutableSet <NSString *> *methods = [[ NSMutableSet alloc ] initWithCapacity : result->size ()];
312312 for (const auto &name : *result) {
313- [methods addObject: (NSString *)@( name.c_str ()) ];
313+ [methods addObject: (NSString *)[[ NSString alloc ] initWithUTF8String: name.c_str ()] ];
314314 }
315315 return methods;
316316}
@@ -343,7 +343,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
343343 }
344344 return nil ;
345345 }
346- NSMutableArray <ExecuTorchValue *> *outputs = [NSMutableArray arrayWithCapacity : result->size ()];
346+ NSMutableArray <ExecuTorchValue *> *outputs = [[ NSMutableArray alloc ] initWithCapacity : result->size ()];
347347 for (const auto &value : *result) {
348348 [outputs addObject: toExecuTorchValue (value)];
349349 }
@@ -354,7 +354,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
354354 withInput : (ExecuTorchValue *)value
355355 error : (NSError **)error {
356356 return [self executeMethod: methodName
357- withInputs: @[ value]
357+ withInputs: [[ NSArray alloc ] initWithObjects: value, nil ]
358358 error: error];
359359}
360360
@@ -368,7 +368,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
368368- (nullable NSArray <ExecuTorchValue *> *)executeMethod : (NSString *)methodName
369369 withTensors : (NSArray <ExecuTorchTensor *> *)tensors
370370 error : (NSError **)error {
371- NSMutableArray <ExecuTorchValue *> *values = [NSMutableArray arrayWithCapacity : tensors.count];
371+ NSMutableArray <ExecuTorchValue *> *values = [[ NSMutableArray alloc ] initWithCapacity : tensors.count];
372372 for (ExecuTorchTensor *tensor in tensors) {
373373 [values addObject: [ExecuTorchValue valueWithTensor: tensor]];
374374 }
@@ -381,7 +381,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
381381 withTensor : (ExecuTorchTensor *)tensor
382382 error : (NSError **)error {
383383 return [self executeMethod: methodName
384- withInputs: @[[ ExecuTorchValue valueWithTensor: tensor]]
384+ withInputs: [[ NSArray alloc ] initWithObjects: [ ExecuTorchValue valueWithTensor: tensor], nil ]
385385 error: error];
386386}
387387
@@ -395,7 +395,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
395395- (nullable NSArray <ExecuTorchValue *> *)forwardWithInput : (ExecuTorchValue *)value
396396 error : (NSError **)error {
397397 return [self executeMethod: @" forward"
398- withInputs: @[ value]
398+ withInputs: [[ NSArray alloc ] initWithObjects: value, nil ]
399399 error: error];
400400}
401401
@@ -407,7 +407,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
407407
408408- (nullable NSArray <ExecuTorchValue *> *)forwardWithTensors : (NSArray <ExecuTorchTensor *> *)tensors
409409 error : (NSError **)error {
410- NSMutableArray <ExecuTorchValue *> *values = [NSMutableArray arrayWithCapacity : tensors.count];
410+ NSMutableArray <ExecuTorchValue *> *values = [[ NSMutableArray alloc ] initWithCapacity : tensors.count];
411411 for (ExecuTorchTensor *tensor in tensors) {
412412 [values addObject: [ExecuTorchValue valueWithTensor: tensor]];
413413 }
@@ -419,7 +419,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
419419- (nullable NSArray <ExecuTorchValue *> *)forwardWithTensor : (ExecuTorchTensor *)tensor
420420 error : (NSError **)error {
421421 return [self executeMethod: @" forward"
422- withInputs: @[[ ExecuTorchValue valueWithTensor: tensor]]
422+ withInputs: [[ NSArray alloc ] initWithObjects: [ ExecuTorchValue valueWithTensor: tensor], nil ]
423423 error: error];
424424}
425425
0 commit comments