Hi,
I am trying to manipulate some data that I receive from a coreml model. To do this I am attempting to use MLShapedArray and MLShapedArraySlice. However, the shaped array slice does not behave as expected.
Here is a small code snippet that initialize a 3D shaped array, prints it, then slices it and prints the slice:
import CoreML
var x = MLShapedArray<Float>(scalars: [0,1,2,3,4,5], shape: [1,3,2])
for i in 0..<x.shape[0] {
for j in 0..<x.shape[1] {
for k in 0..<x.shape[2] {
print("[\(i),\(j),\(k)] = \(x[i,j,k].scalar ?? 0)")
}
}
}
var y = x[0...0,1..<2]
print(y)
for i in 0..<y.shape[0] {
for j in 0..<y.shape[1] {
for k in 0..<y.shape[2] {
print("[\(i),\(j),\(k)] = \(y[i,j,k].scalar ?? 0)")
}
}
}
My expectation is that the slice will yield the second pair of numbers 2,3 but instead I get:
[0,0,0] = 0.0
[0,0,1] = 1.0
[0,1,0] = 2.0
[0,1,1] = 3.0
[0,2,0] = 4.0
[0,2,1] = 5.0
MLShapedArraySlice<Float>(shape: [1, 1, 2], baseShapedArray: 0.0 1.0 2.0 3.0 4.0 5.0 , baseIndices: [], sliceRanges: [Range(0..<1), Range(1..<2), Range(0..<2)], originIndices: [0, 1, 0])
[0,0,0] = 0.0
[0,0,1] = 1.0
As you can see from the details of the printed slice - its shape is correct and it has the proper ranges displayed - yet when I subscript it it yields the same as the original shaped array. This is not what I expected - however I can't find any documentation or examples on how to use the slicing with ranges (or much on the slices at all)
Am I using it wrong or is it just not working correctly?