| 77 | } |
| 78 | |
| 79 | Status 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 | |