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

Function ComputeColumnMajorStrides

cpp/src/arrow/tensor.cc:79–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79Status ComputeColumnMajorStrides(const FixedWidthType& type,
80 const std::vector<int64_t>& shape,
81 std::vector<int64_t>* strides) {
82 const int byte_width = type.byte_width();
83 const size_t ndim = shape.size();
84
85 int64_t total = 0;
86 if (!shape.empty() && shape.back() > 0) {
87 total = byte_width;
88 for (size_t i = 0; i < ndim - 1; ++i) {
89 if (internal::MultiplyWithOverflow(total, shape[i], &total)) {
90 return Status::Invalid(
91 "Column-major strides computed from shape would not fit in 64-bit "
92 "integer");
93 }
94 }
95 }
96
97 if (total == 0) {
98 strides->assign(shape.size(), byte_width);
99 return Status::OK();
100 }
101
102 total = byte_width;
103 for (size_t i = 0; i < ndim - 1; ++i) {
104 strides->push_back(total);
105 total *= shape[i];
106 }
107 strides->push_back(total);
108
109 return Status::OK();
110}
111
112} // namespace internal
113

Callers 4

TESTFunction · 0.85
ToTensorImplFunction · 0.85
MakeRandomTensorFunction · 0.85

Calls 9

MultiplyWithOverflowFunction · 0.85
backMethod · 0.80
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