| 238 | |
| 239 | template <typename Backend> |
| 240 | void SetLayout( |
| 241 | Tensor<Backend> &t, |
| 242 | const std::optional<std::string> &layout_str, |
| 243 | bool clear_if_none = true) { |
| 244 | if (layout_str && !layout_str->empty()) { |
| 245 | TensorLayout layout = *layout_str; |
| 246 | if (t.ndim() != layout.ndim()) { |
| 247 | throw py::value_error(make_string( |
| 248 | "A non-empty layout must have the same number of dimensions as the " |
| 249 | "number of dimensions of the Tensor.\n" |
| 250 | "Got: ", layout.ndim(), " (", layout, ")\n", |
| 251 | "Expected: ", t.ndim(), ".")); |
| 252 | } |
| 253 | t.SetLayout(layout); |
| 254 | } else if (clear_if_none) { |
| 255 | t.SetLayout({}); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | template <typename Backend> |
| 260 | void SetLayout( |
no test coverage detected