MCPcopy Create free account
hub / github.com/BabitMF/bmf / select

Method select

bmf/hmp/src/tensor.cpp:243–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

241}
242
243Tensor Tensor::select(int64_t dim, int64_t index) const {
244 dim = wrap_size(dim, this->dim());
245 HMP_REQUIRE(dim < this->dim(), "select : dim({}) is out of range {}", dim,
246 this->dim());
247
248 index = wrap_size(index, size(dim));
249 HMP_REQUIRE(index < size(dim),
250 "select: index {} is out of range, need less than {}", index,
251 size(dim));
252
253 auto out = slice(dim, index, index + 1);
254
255 // squeeze
256 auto newShape = out.shape();
257 auto newStrides = out.strides();
258 HMP_REQUIRE(newShape[dim] == 1, "select: internal error");
259 newShape.erase(newShape.begin() + dim);
260 newStrides.erase(newStrides.begin() + dim);
261
262 out.tensorInfo()->setSizesAndStrides(newShape, newStrides,
263 out.tensorInfo()->bufferOffset());
264
265 return out;
266}
267
268// factory functions
269Tensor empty(const SizeArray &shape, const TensorOptions &options) {

Callers 12

create_moduleFunction · 0.45
constructMethod · 0.45
stringfyFunction · 0.45
operator[]Method · 0.45
ImageSeqIterMethod · 0.45
imgproc.cppFile · 0.45
foreach_imageFunction · 0.45
foreach_gpu_imageFunction · 0.45
test_select_sliceMethod · 0.45
test_attrsMethod · 0.45
test_viewMethod · 0.45

Calls 5

dimMethod · 0.95
wrap_sizeFunction · 0.85
setSizesAndStridesMethod · 0.80
sizeFunction · 0.50
eraseMethod · 0.45

Tested by 3

test_select_sliceMethod · 0.36
test_attrsMethod · 0.36
test_viewMethod · 0.36