REQUIRE_TRUE(begin.size()==x_rank,0,"begin array should have length of [%i] but got [%i] instead",x_rank,begin.size());
REQUIRE_TRUE(sz.size()==x_rank,0,"size array should have length of [%i] but got [%i] instead",x_rank,sz.size());
std::vector<Nd4jLong>indices(2*x_rank);
autoempty=false;
for(inte=0;e<x_rank;e++){
intsize=sz[e];
intstart=begin[e];
REQUIRE_TRUE(start>=0,0,"Slice: start index should not be negative");
REQUIRE_TRUE(start<=input->sizeAt(e),0,"Index %i is invalid for dimension %i with size %i.",start,e,input->shapeInfo()[e+1]);
if(size==-1){
size=input->sizeAt(e)-start;
}
REQUIRE_TRUE(size>=0,0,"Slice: interval for dimension %i is less then 1");
REQUIRE_TRUE(start+size<=input->sizeAt(e),0,"Slice: interval [%i, %i] is out of bounds for dimension %i with size %i",start,start+size,e,input->sizeAt(e));
if(start==input->sizeAt(e)||size==0){
empty=true;
//Don't break to perform input validation on other dims
}
indices[2*e]=start;
indices[2*e+1]=start+size;
}
if(empty){
REQUIRE_TRUE(output->isEmpty(),0,"Slice: empty array indices requested, but output array is not empty");
returnStatus::OK();
}
autosub=(*input)(indices,true);
output->assign(sub);
STORE_RESULT(output);
returnStatus::OK();
}
DECLARE_TYPES(slice){
getOpDescriptor()
->setAllowedInputTypes(nd4j::DataType::ANY)
->setSameMode(true);
}
DECLARE_SHAPE_FN(slice){
autoinShape=inputShape->at(0);
autox_rank=shape::rank(inShape);
std::vector<int>begin;
std::vector<int>sz;
if(block.width()==3){
autob=INPUT_VARIABLE(1);
autoe=INPUT_VARIABLE(2);
begin=b->templateasVectorT<int>();
sz=e->templateasVectorT<int>();
}else{
REQUIRE_TRUE(block.numI()>=x_rank*2,0,"Number of IArgs should be equal to [%i] but got [%i] instead",x_rank*2,block.numI());
REQUIRE_TRUE(begin.size()==x_rank,0,"Begin array should have length of [%i] but got [%i] instead",x_rank,begin.size());
REQUIRE_TRUE(sz.size()==x_rank,0,"Size array should have length of [%i] but got [%i] instead",x_rank,sz.size());
std::vector<Nd4jLong>shape;
autoempty=false;
for(inte=0;e<x_rank;e++){
autosize=sz[e];
autostart=begin[e];
if(size==-1){
size=inShape[e+1]-start;
}
//Bounds checking. Note that begin[i] == size[i] means empty array
REQUIRE_TRUE(start>=0&&start<=inShape[e+1],0,"Invalid begin[%i] value: Begin must satisfy 0 <= begin <= size[i], got begin=%i for dimension size %i",e,start,inShape[e+1]);
REQUIRE_TRUE(size==-1||size>=0,0,"Invalid size[%i] value: must be positive (or -1 for 'all remaining'), got %i",e,size,inShape[e+1]);
REQUIRE_TRUE(start>=0&&start<=inShape[e+1],0,"Invalid begin[%i] value: Begin must satisfy 0 <= begin <= size[i], got begin=%i for dimension size %i",e,start,inShape[e+1]);
REQUIRE_TRUE(start+size<=inShape[e+1],0,"Slice: interval [%i, %i] is out of bounds for dimension %i with size %i",start,start+size,e,inShape[e+1]);