MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / LiteralToInt64Vector

Function LiteralToInt64Vector

tensorflow/compiler/tf2xla/xla_op_kernel.cc:255–274  ·  view source on GitHub ↗

Converts an int32 or int64 1D literal to an int64 vector.

Source from the content-addressed store, hash-verified

253
254// Converts an int32 or int64 1D literal to an int64 vector.
255static 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
276Status XlaOpKernelContext::ConstantInputAsIntVector(int index,
277 std::vector<int64>* out) {

Calls 5

InvalidArgumentFunction · 0.85
rankMethod · 0.45
shapeMethod · 0.45
element_typeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected