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