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

Method CreateFromProto

tensorflow/compiler/xla/literal.cc:282–335  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

280}
281
282/* static */ StatusOr<Literal> MutableLiteralBase::CreateFromProto(
283 const LiteralProto& proto, bool prohibit_empty_literal) {
284 if (!proto.has_shape()) {
285 return InvalidArgument("LiteralProto has no shape");
286 }
287 Shape shape(proto.shape());
288 if (ShapeUtil::HasPrimitiveType(shape, OPAQUE_TYPE)) {
289 return InvalidArgument(
290 "Literal shape cannot include OPAQUE_TYPE sub-shape");
291 }
292 if (!LayoutUtil::HasLayout(shape)) {
293 return InvalidArgument("LiteralProto has no layout");
294 }
295
296 TF_RETURN_IF_ERROR(ShapeUtil::ValidateShapeWithOptionalLayout(shape));
297
298 Literal literal(shape);
299
300 TF_RETURN_IF_ERROR(literal.root_piece_->ForEachMutableSubpieceWithStatus(
301 [&](const ShapeIndex& index, Piece* piece) {
302 const LiteralProto* proto_element = &proto;
303 for (int64 i : index) {
304 CHECK(i < proto_element->tuple_literals_size());
305 proto_element = &proto_element->tuple_literals(i);
306 }
307
308 if (piece->subshape().IsTuple()) {
309 if (proto_element->tuple_literals_size() !=
310 ShapeUtil::TupleElementCount(piece->subshape())) {
311 return InvalidArgument(
312 "Expected %d tuple elements in LiteralProto, has %d",
313 ShapeUtil::TupleElementCount(piece->subshape()),
314 proto_element->tuple_literals_size());
315 }
316 return Status::OK();
317 }
318 if (piece->subshape().element_type() == TOKEN) {
319 return Status::OK();
320 }
321
322 CHECK(piece->subshape().IsArray());
323
324 // When prohibit_empty_literal is false (allowing literal with no
325 // values), only copy from proto if the literal proto has values. This
326 // mode is used for a learned cost model.
327 if (prohibit_empty_literal || LiteralProtoHasValues(*proto_element)) {
328 TF_RETURN_IF_ERROR(piece->CopyFromProto(*proto_element));
329 }
330
331 return Status::OK();
332 }));
333
334 return std::move(literal);
335}
336
337std::vector<Literal> Literal::DecomposeTuple() {
338 CHECK(shape().IsTuple());

Callers

nothing calls this directly

Calls 9

InvalidArgumentFunction · 0.85
LiteralProtoHasValuesFunction · 0.85
has_shapeMethod · 0.80
CopyFromProtoMethod · 0.80
shapeMethod · 0.45
IsTupleMethod · 0.45
element_typeMethod · 0.45
IsArrayMethod · 0.45

Tested by

no test coverage detected