MCPcopy Create free account
hub / github.com/alibaba/MNN / getElemSize

Function getElemSize

source/geometry/GeometryTensorArray.cpp:15–38  ·  view source on GitHub ↗

get a pair

Source from the content-addressed store, hash-verified

13namespace MNN {
14// get a pair <ElemOffset, ElemSize>
15static std::pair<int, int> getElemSize(const Tensor* t, int index) {
16 auto des = TensorUtils::getDescribe(t);
17 const auto& shapes = des->tensorArrayAttr->elemShape;
18 int elemSize = 1;
19 if (index < 0) {
20 index = index + shapes.size();
21 }
22 if (!des->tensorArrayAttr->isIdenticalShape && shapes.size() > index) {
23 int offset = 0;
24 for (int i = 0; i <= index; i++) {
25 elemSize = 1;
26 std::for_each(shapes[i].begin(), shapes[i].end(), [&elemSize](int x) { elemSize *= x; });
27 offset += elemSize;
28 }
29 return {offset - elemSize, elemSize};
30 } else if (shapes.size() >= 1) {
31 elemSize = 1;
32 std::for_each(shapes[0].begin(), shapes[0].end(), [&elemSize](int x) { elemSize *= x; });
33 return {index * elemSize, elemSize};
34 } else {
35 MNN_ASSERT(false);
36 return {0, 0};
37 }
38}
39
40static bool isFirstWrite(const Tensor::InsideDescribe::NativeInsideDescribe* des) {
41 if (des->tensorArrayAttr->elemShape.empty()) {

Callers 5

onComputeMethod · 0.85
onComputeMethod · 0.85
onComputeMethod · 0.85
onComputeMethod · 0.85
onComputeMethod · 0.85

Calls 3

sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected