I have initialized MLMultiArray
using initWithDataPointer
as shown in the code below:
float count = 512 * 384;
double *tempBuffer = malloc(count * sizeof(double));
NSError *error = NULL;
NSArray *shape = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:512],[NSNumber numberWithInt:384], nil];
NSArray *stride = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:1],[NSNumber numberWithInt:1], nil];
MLMultiArray *mlMultiArray = [[MLMultiArray alloc] initWithDataPointer:tempBuffer
shape:shape
dataType:MLMultiArrayDataTypeDouble
strides:stride
deallocator:^(void * _Nonnull bytes) { free(bytes); }
error:&error];
Based on the MLMultiArray
documentation mentioned in this link, subscript
needs to be used for accessing elements.
If I access the elements in the way shown, is it correct?
NSNumber *val = [mlMultiArray objectForKeyedSubscript:[NSArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:1],[NSNumber numberWithInt:1], nil]];