This repository was archived by the owner on Nov 17, 2023. It is now read-only.
cpp mx::slice
#19765
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a tensor as (batches, rows, cols, channels) which I want to slice, but I'm slightly confused by the logic for taking a whole axis. I've been managing so far by just knowing the size of the whole axis, thus if I have an input of (16,128,128,3) and I want to get just the middle channel, I could easily do:
mx::Shape begin(0,0,0,1);
mx::Shape end(16,128,128,2);
auto ch = mx::slice( data, begin, end );
But I don't want to have to explicitly state the end for axes that don't change, because it can confuse things when I later want to say, use a different batch size during inference than I did during training.
My impression from the docs was that I could maybe use -1, as in:
mx::Shape begin(0,0,0,1);
mx::Shape end(-1,-1,-1,2);
auto ch = mx::slice( data, begin, end );
but then my output shape seems to be (15,127,127,1) - so I've lost a whole image from my batch, and also a whole row and column from each channel. That suggested to me that maybe I want to use
mx::Shape end(0,0,0,2)but then my output shape is (-1,-1,-1,1).So how do I say "use this whole axis"?
Note, I know I could in this trivial case use
slice_axis, but my real task is more like:mx::Shape step(1,2,2,1);
mx::Shape begin(0,0,0,0);
mx::Shape end(64,128,128,1);
mx::slice( data, begin, end, step );
(I'm also confused by how -ve indices are said to be possible when mx::Shape appears to use t_index as a datatype, and t_index appears to be defined as
typedef unsigned t_index)Beta Was this translation helpful? Give feedback.
All reactions