| 35 | } // namespace |
| 36 | |
| 37 | TensorShape TensorShape::from_dims(std::initializer_list<int64_t> dims_init) { |
| 38 | TensorShape shape; |
| 39 | shape.rank = dims_init.size(); |
| 40 | if (shape.rank == 0 || shape.rank > kMaxTensorRank) { |
| 41 | throw std::runtime_error("Tensor rank must be between 1 and 4"); |
| 42 | } |
| 43 | |
| 44 | size_t index = 0; |
| 45 | for (const int64_t dim : dims_init) { |
| 46 | shape.dims[index++] = dim; |
| 47 | } |
| 48 | |
| 49 | ensure_positive_dims(shape); |
| 50 | return shape; |
| 51 | } |
| 52 | |
| 53 | int64_t TensorShape::at(size_t index) const { |
| 54 | if (index >= rank) { |
nothing calls this directly
no test coverage detected