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

Method Shape

tensorflow/compiler/xla/shape.cc:24–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22namespace xla {
23
24Shape::Shape(const ShapeProto& shape_proto) {
25 set_element_type(shape_proto.element_type());
26 dimensions_.reserve(shape_proto.dimensions_size());
27 for (const int64 dimension : shape_proto.dimensions()) {
28 add_dimensions(dimension);
29 }
30 // A malformed proto may have different is_dynamic_dimension_size and
31 // dimensions_size. Since C++ is evil, and we have no good way of bailing out
32 // in a constructor, conservatively trim the is_dynamic_dimension size.
33 // TODO(b/120111794): Make this a hard error when we have a factory method
34 // instead of a constructor.
35 if (shape_proto.dimensions_size() !=
36 shape_proto.is_dynamic_dimension_size()) {
37 if (shape_proto.is_dynamic_dimension_size() != 0) {
38 LOG(ERROR) << "Malformed shape proto: number of is_dynamic_dimension "
39 "fields does not match number of dimension fields";
40 } else {
41 LOG(WARNING) << "Malformed shape proto: is_dynamic_dimension is empty";
42 }
43 }
44 int64 num_dynamic_dimension_fields = std::min(
45 shape_proto.dimensions_size(), shape_proto.is_dynamic_dimension_size());
46 for (int i = 0; i < num_dynamic_dimension_fields; i++) {
47 dynamic_dimensions_[i] = shape_proto.is_dynamic_dimension(i);
48 }
49 tuple_shapes_.reserve(shape_proto.tuple_shapes_size());
50 for (const ShapeProto& element_shape : shape_proto.tuple_shapes()) {
51 *add_tuple_shapes() = Shape(element_shape);
52 }
53 if (shape_proto.has_layout()) {
54 *mutable_layout() = Layout::CreateFromProto(shape_proto.layout());
55 }
56}
57
58ShapeProto Shape::ToProto() const {
59 ShapeProto proto;

Callers

nothing calls this directly

Calls 12

set_element_typeFunction · 0.85
dimensions_sizeMethod · 0.80
is_dynamic_dimensionMethod · 0.80
tuple_shapes_sizeMethod · 0.80
has_layoutMethod · 0.80
ShapeClass · 0.70
minFunction · 0.50
element_typeMethod · 0.45
reserveMethod · 0.45
dimensionsMethod · 0.45
tuple_shapesMethod · 0.45
layoutMethod · 0.45

Tested by

no test coverage detected