Converts an int32 or int64 1D literal to an int64 vector.
| 253 | |
| 254 | // Converts an int32 or int64 1D literal to an int64 vector. |
| 255 | static Status LiteralToInt64Vector(const xla::LiteralSlice& literal, |
| 256 | std::vector<int64>* out) { |
| 257 | if (literal.shape().rank() != 1) { |
| 258 | return errors::InvalidArgument("value is not 1D, rank: ", |
| 259 | literal.shape().rank()); |
| 260 | } |
| 261 | int64 size = xla::ShapeUtil::ElementsIn(literal.shape()); |
| 262 | if (literal.shape().element_type() == xla::S32) { |
| 263 | for (int64 i = 0; i < size; ++i) { |
| 264 | out->push_back(literal.Get<int32>({i})); |
| 265 | } |
| 266 | } else if (literal.shape().element_type() == xla::S64) { |
| 267 | for (int64 i = 0; i < size; ++i) { |
| 268 | out->push_back(literal.Get<int64>({i})); |
| 269 | } |
| 270 | } else { |
| 271 | return errors::InvalidArgument("value must be either int32 or int64"); |
| 272 | } |
| 273 | return Status::OK(); |
| 274 | } |
| 275 | |
| 276 | Status XlaOpKernelContext::ConstantInputAsIntVector(int index, |
| 277 | std::vector<int64>* out) { |
no test coverage detected