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

Function Contract

tensorflow/compiler/tf2xla/lib/data_format.cc:24–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22namespace {
23
24xla::StatusOr<xla::XlaOp> Contract(xla::XlaOp input, int64 dim) {
25 xla::XlaBuilder* builder = input.builder();
26 TF_ASSIGN_OR_RETURN(xla::Shape input_shape, builder->GetShape(input));
27
28 if (input_shape.dimensions().back() != 4) {
29 return errors::InvalidArgument("Expected last dimension to be 4; got ",
30 input_shape.dimensions().back());
31 }
32
33 // Transpose the input so C is directly followed by VECT_C.
34 std::vector<int64> permutation;
35 for (int64 i = 0; i != input_shape.rank() - 1; ++i) {
36 permutation.push_back(i);
37 if (i == dim) {
38 permutation.push_back(input_shape.rank() - 1);
39 }
40 }
41
42 // Now merge the adjacent dimensions with a reshape.
43 std::vector<int64> contracted_shape(input_shape.dimensions().begin(),
44 input_shape.dimensions().end() - 1);
45 contracted_shape[dim] *= 4;
46
47 return xla::Reshape(xla::Transpose(input, permutation), contracted_shape);
48}
49
50xla::StatusOr<xla::XlaOp> Expand(xla::XlaOp input, int64 dim) {
51 xla::XlaBuilder* builder = input.builder();

Callers 1

NCHW_VECT_CToNCHWFunction · 0.85

Calls 10

InvalidArgumentFunction · 0.85
ReshapeFunction · 0.50
TransposeFunction · 0.50
builderMethod · 0.45
backMethod · 0.45
dimensionsMethod · 0.45
rankMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected