MCPcopy Create free account
hub / github.com/apache/arrow / ComputeRowMajorStrides

Function ComputeRowMajorStrides

cpp/src/arrow/tensor.cc:48–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46namespace internal {
47
48Status ComputeRowMajorStrides(const FixedWidthType& type,
49 const std::vector<int64_t>& shape,
50 std::vector<int64_t>* strides) {
51 const int byte_width = type.byte_width();
52 const size_t ndim = shape.size();
53
54 int64_t remaining = 0;
55 if (!shape.empty() && shape.front() > 0) {
56 remaining = byte_width;
57 for (size_t i = 1; i < ndim; ++i) {
58 if (internal::MultiplyWithOverflow(remaining, shape[i], &remaining)) {
59 return Status::Invalid(
60 "Row-major strides computed from shape would not fit in 64-bit integer");
61 }
62 }
63 }
64
65 if (remaining == 0) {
66 strides->assign(shape.size(), byte_width);
67 return Status::OK();
68 }
69
70 strides->push_back(remaining);
71 for (size_t i = 1; i < ndim; ++i) {
72 remaining /= shape[i];
73 strides->push_back(remaining);
74 }
75
76 return Status::OK();
77}
78
79Status ComputeColumnMajorStrides(const FixedWidthType& type,
80 const std::vector<int64_t>& shape,

Callers 10

TESTFunction · 0.85
IsTensorStridesRowMajorFunction · 0.85
ValidateTensorParametersFunction · 0.85
ToTensorImplFunction · 0.85
TensorMethod · 0.85
ConvertMethod · 0.85
BuildMethod · 0.85
MakeRandomTensorFunction · 0.85

Calls 8

MultiplyWithOverflowFunction · 0.85
assignMethod · 0.80
push_backMethod · 0.80
InvalidFunction · 0.70
OKFunction · 0.70
byte_widthMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by 2

TESTFunction · 0.68
MakeRandomTensorFunction · 0.68