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

Function ShapesAgreeUpToExtending

tensorflow/lite/toco/tooling_util.cc:711–747  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

709}
710
711bool ShapesAgreeUpToExtending(const Shape& shape0, const Shape& shape1) {
712 CheckNonEmptyShapeDimensions(shape0);
713 CheckNonEmptyShapeDimensions(shape1);
714
715 const Shape* longer = &shape0;
716 const Shape* shorter = &shape1;
717 if (shape1.dimensions_count() > shape0.dimensions_count()) {
718 longer = &shape1;
719 shorter = &shape0;
720 }
721
722 // Walk dimensions back to front until we run out of dimensions in the shorter
723 // shape.
724 int longer_index = longer->dimensions_count() - 1;
725 int shorter_index = shorter->dimensions_count() - 1;
726 while (shorter_index >= 0) {
727 const int d_long = longer->dims(longer_index);
728 const int d_short = shorter->dims(shorter_index);
729 // Extending fails if the dimensions are different.
730 if (d_long != d_short) {
731 return false;
732 }
733 longer_index--;
734 shorter_index--;
735 }
736
737 // The remaining dimensions in the longer shape must be 1.
738 while (longer_index >= 0) {
739 const int d_long = longer->dims(longer_index);
740 if (d_long != 1) {
741 return false;
742 }
743 longer_index--;
744 }
745
746 return true;
747}
748
749int RequiredBufferSizeForShape(const Shape& shape) {
750 CheckValidShape(shape);

Callers 3

TEST_PFunction · 0.85
IsReshapeTrivialFunction · 0.85
RunMethod · 0.85

Calls 3

dimensions_countMethod · 0.80
dimsMethod · 0.45

Tested by 1

TEST_PFunction · 0.68