Returns the strides for `shape`.
| 181 | |
| 182 | // Returns the strides for `shape`. |
| 183 | std::vector<ssize_t> ByteStridesForShape(const Shape& shape) { |
| 184 | std::vector<ssize_t> strides; |
| 185 | CHECK(shape.IsArray()); |
| 186 | CHECK(shape.has_layout()); |
| 187 | |
| 188 | strides.resize(shape.dimensions_size()); |
| 189 | ssize_t stride = ShapeUtil::ByteSizeOfPrimitiveType(shape.element_type()); |
| 190 | for (int i : shape.layout().minor_to_major()) { |
| 191 | strides.at(i) = stride; |
| 192 | stride *= shape.dimensions(i); |
| 193 | } |
| 194 | return strides; |
| 195 | } |
| 196 | |
| 197 | StatusOr<py::object> LiteralToPython(std::shared_ptr<xla::Literal> literal) { |
| 198 | xla::Literal& m = *literal; |
no test coverage detected