@@ -38,7 +38,7 @@ static inline EValue toEValue(ExecuTorchValue *value) {
38
38
return EValue ();
39
39
}
40
40
41
- static inline ExecuTorchValue *toExecuTorchValue (EValue value) {
41
+ static inline ExecuTorchValue *toExecuTorchValue (EValue value) NS_RETURNS_RETAINED {
42
42
if (value.isTensor ()) {
43
43
auto nativeInstance = make_tensor_ptr (value.toTensor ());
44
44
return [ExecuTorchValue valueWithTensor: [[ExecuTorchTensor alloc ] initWithNativeInstance: &nativeInstance]];
@@ -118,20 +118,20 @@ - (nullable instancetype)initWithMethodMetadata:(const MethodMeta &)methodMeta
118
118
error : (NSError **)error {
119
119
self = [super init ];
120
120
if (self) {
121
- _name = @( methodMeta.name ()) ;
121
+ _name = [[ NSString alloc ] initWithUTF8String: methodMeta.name ()] ;
122
122
const NSInteger inputCount = methodMeta.num_inputs ();
123
123
const NSInteger outputCount = methodMeta.num_outputs ();
124
124
const NSInteger attributeCount = methodMeta.num_attributes ();
125
125
const NSInteger memoryPlannedBufferCount = methodMeta.num_memory_planned_buffers ();
126
126
const NSInteger backendCount = methodMeta.num_backends ();
127
127
_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];
135
135
136
136
for (NSInteger index = 0 ; index < inputCount; ++index) {
137
137
auto result = methodMeta.input_tag (index);
@@ -206,7 +206,7 @@ - (nullable instancetype)initWithMethodMetadata:(const MethodMeta &)methodMeta
206
206
}
207
207
return nil ;
208
208
}
209
- NSString *backendName = [NSString stringWithUTF8String : result.get ()];
209
+ NSString *backendName = [[ NSString alloc ] initWithUTF8String : result.get ()];
210
210
[_backendNames addObject: backendName];
211
211
}
212
212
}
@@ -308,9 +308,9 @@ - (BOOL)isMethodLoaded:(NSString *)methodName {
308
308
}
309
309
return nil ;
310
310
}
311
- NSMutableSet <NSString *> *methods = [NSMutableSet setWithCapacity : result->size ()];
311
+ NSMutableSet <NSString *> *methods = [[ NSMutableSet alloc ] initWithCapacity : result->size ()];
312
312
for (const auto &name : *result) {
313
- [methods addObject: (NSString *)@( name.c_str ()) ];
313
+ [methods addObject: (NSString *)[[ NSString alloc ] initWithUTF8String: name.c_str ()] ];
314
314
}
315
315
return methods;
316
316
}
@@ -343,7 +343,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
343
343
}
344
344
return nil ;
345
345
}
346
- NSMutableArray <ExecuTorchValue *> *outputs = [NSMutableArray arrayWithCapacity : result->size ()];
346
+ NSMutableArray <ExecuTorchValue *> *outputs = [[ NSMutableArray alloc ] initWithCapacity : result->size ()];
347
347
for (const auto &value : *result) {
348
348
[outputs addObject: toExecuTorchValue (value)];
349
349
}
@@ -354,7 +354,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
354
354
withInput : (ExecuTorchValue *)value
355
355
error : (NSError **)error {
356
356
return [self executeMethod: methodName
357
- withInputs: @[ value]
357
+ withInputs: [[ NSArray alloc ] initWithObjects: value, nil ]
358
358
error: error];
359
359
}
360
360
@@ -368,7 +368,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
368
368
- (nullable NSArray <ExecuTorchValue *> *)executeMethod : (NSString *)methodName
369
369
withTensors : (NSArray <ExecuTorchTensor *> *)tensors
370
370
error : (NSError **)error {
371
- NSMutableArray <ExecuTorchValue *> *values = [NSMutableArray arrayWithCapacity : tensors.count];
371
+ NSMutableArray <ExecuTorchValue *> *values = [[ NSMutableArray alloc ] initWithCapacity : tensors.count];
372
372
for (ExecuTorchTensor *tensor in tensors) {
373
373
[values addObject: [ExecuTorchValue valueWithTensor: tensor]];
374
374
}
@@ -381,7 +381,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
381
381
withTensor : (ExecuTorchTensor *)tensor
382
382
error : (NSError **)error {
383
383
return [self executeMethod: methodName
384
- withInputs: @[[ ExecuTorchValue valueWithTensor: tensor]]
384
+ withInputs: [[ NSArray alloc ] initWithObjects: [ ExecuTorchValue valueWithTensor: tensor], nil ]
385
385
error: error];
386
386
}
387
387
@@ -395,7 +395,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
395
395
- (nullable NSArray <ExecuTorchValue *> *)forwardWithInput : (ExecuTorchValue *)value
396
396
error : (NSError **)error {
397
397
return [self executeMethod: @" forward"
398
- withInputs: @[ value]
398
+ withInputs: [[ NSArray alloc ] initWithObjects: value, nil ]
399
399
error: error];
400
400
}
401
401
@@ -407,7 +407,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
407
407
408
408
- (nullable NSArray <ExecuTorchValue *> *)forwardWithTensors : (NSArray <ExecuTorchTensor *> *)tensors
409
409
error : (NSError **)error {
410
- NSMutableArray <ExecuTorchValue *> *values = [NSMutableArray arrayWithCapacity : tensors.count];
410
+ NSMutableArray <ExecuTorchValue *> *values = [[ NSMutableArray alloc ] initWithCapacity : tensors.count];
411
411
for (ExecuTorchTensor *tensor in tensors) {
412
412
[values addObject: [ExecuTorchValue valueWithTensor: tensor]];
413
413
}
@@ -419,7 +419,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
419
419
- (nullable NSArray <ExecuTorchValue *> *)forwardWithTensor : (ExecuTorchTensor *)tensor
420
420
error : (NSError **)error {
421
421
return [self executeMethod: @" forward"
422
- withInputs: @[[ ExecuTorchValue valueWithTensor: tensor]]
422
+ withInputs: [[ NSArray alloc ] initWithObjects: [ ExecuTorchValue valueWithTensor: tensor], nil ]
423
423
error: error];
424
424
}
425
425
0 commit comments