MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / span_spec

Method span_spec

dnn/src/common/tensor_format.cpp:146–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146TensorLayout::Span DefaultTensorFormat::span_spec(const TensorLayout& layout) const {
147 assert_valid(layout);
148 if (layout.ndim == 0)
149 return {0, 0, 0, 0, 0, 0};
150
151 ptrdiff_t low_elem = 0;
152 size_t high_elem = 0;
153 for (size_t i = 0; i < layout.ndim; ++i) {
154 auto shape_val = layout.shape[i];
155 if (!shape_val) {
156 return {0, 0, 0, 0, 0, 0};
157 }
158 auto stride_val = layout.stride[i];
159 if (stride_val > 0) {
160 high_elem += (shape_val - 1) * stride_val;
161 } else {
162 low_elem += (shape_val - 1) * stride_val;
163 }
164 }
165 ++high_elem;
166 ptrdiff_t low_byte;
167 if (low_elem < 0) {
168 low_byte = low_elem * layout.dtype.size();
169 } else {
170 low_byte = 0;
171 }
172 size_t high_byte = layout.dtype.size(high_elem);
173 return TensorLayout::Span(
174 low_elem, low_byte, high_elem, high_byte, high_elem, high_byte);
175}
176
177std::string DefaultTensorFormat::to_string() const {
178 return "default{}";

Callers 1

spanMethod · 0.80

Calls 6

image_heightFunction · 0.85
image_row_pitchFunction · 0.85
size_logMethod · 0.80
collapse_contiguousMethod · 0.80
SpanClass · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected