MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Slice

Method Slice

tensorflow/core/framework/tensor.cc:910–935  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

908};
909
910Tensor Tensor::Slice(int64 start, int64 limit) const {
911 CHECK_GE(dims(), 1);
912 CHECK_LE(0, start);
913 CHECK_LE(start, limit);
914 int64 dim0_size = shape_.dim_size(0);
915 CHECK_LE(limit, dim0_size);
916 if ((start == 0) && (limit == dim0_size)) {
917 return *this;
918 }
919 Tensor ret;
920 ret.shape_ = shape_;
921 ret.set_dtype(dtype());
922 ret.buf_ = nullptr;
923 if (dim0_size > 0) {
924 const int64 elems_per_dim0 = NumElements() / dim0_size;
925 const int64 delta = start * elems_per_dim0;
926 dim0_size = limit - start;
927 ret.shape_.set_dim(0, dim0_size);
928 const int64 num_elems = dim0_size * elems_per_dim0;
929 if (buf_) {
930 DataType dt = dtype();
931 CASES(dt, ret.buf_ = new SubBuffer<T>(buf_, delta, num_elems));
932 }
933 }
934 return ret;
935}
936
937Tensor Tensor::SubSlice(int64 index) const {
938 CHECK_GE(dims(), 1); // Crash ok.

Callers 3

TESTFunction · 0.45
TESTFunction · 0.45
ChunkAliasMethod · 0.45

Calls 6

dimsFunction · 0.85
dtypeFunction · 0.50
NumElementsFunction · 0.50
dim_sizeMethod · 0.45
set_dtypeMethod · 0.45
set_dimMethod · 0.45

Tested by 2

TESTFunction · 0.36
TESTFunction · 0.36