Populate the output layout unless the minor_to_major array contains all -1 value, in which case the layout is considered missing and the API returns false.
| 48 | // value, in which case the layout is considered missing and the API returns |
| 49 | // false. |
| 50 | xla::StatusOr<bool> MakeLayout(absl::Span<const int64> minor_to_major, |
| 51 | xla::Layout* layout) { |
| 52 | if (std::all_of(minor_to_major.begin(), minor_to_major.end(), |
| 53 | [](int64 dim) { return dim == -1; })) { |
| 54 | return false; |
| 55 | } |
| 56 | std::vector<bool> dim_present(minor_to_major.size(), false); |
| 57 | for (auto dim : minor_to_major) { |
| 58 | if (dim < 0 || dim >= minor_to_major.size()) { |
| 59 | return errors::InvalidArgument("Layout dimension out of range: dim=", dim, |
| 60 | " rank=", minor_to_major.size()); |
| 61 | } |
| 62 | if (dim_present[dim]) { |
| 63 | return errors::InvalidArgument("Repeated layout dimension: dim=", dim); |
| 64 | } |
| 65 | dim_present[dim] = true; |
| 66 | } |
| 67 | *layout = xla::LayoutUtil::MakeLayout(minor_to_major); |
| 68 | return true; |
| 69 | } |
| 70 | |
| 71 | Status AssignLayout( |
| 72 | absl::Span<const int64> minor_to_major, |