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

Method SimplifySlice

tensorflow/core/grappler/optimizers/constant_folding.cc:2147–2180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2145}
2146
2147Status ConstantFolding::SimplifySlice(const GraphProperties& properties,
2148 bool use_shape_info,
2149 GraphDef* optimized_graph,
2150 NodeDef* node) {
2151 if (!use_shape_info || !IsSlice(*node)) return Status::OK();
2152 Tensor begin;
2153 Tensor size;
2154 if (properties.HasInputProperties(node->name()) &&
2155 GetTensorFromConstNode(node->input(1), &begin) &&
2156 GetTensorFromConstNode(node->input(2), &size)) {
2157 const auto& input = properties.GetInputProperties(node->name())[0];
2158 // The node is replaceable iff unknown_rank == false &&
2159 // begin == 0 && (size == -1 || size == input_shape) for all dimensions
2160 bool replaceable = !input.shape().unknown_rank();
2161 for (int j = 0; replaceable && j < input.shape().dim_size(); ++j) {
2162 if (begin.dtype() == DT_INT32) {
2163 replaceable &= begin.vec<int>()(j) == 0;
2164 } else {
2165 replaceable &= begin.vec<int64>()(j) == 0;
2166 }
2167 if (size.dtype() == DT_INT32) {
2168 replaceable &= (size.vec<int>()(j) == -1 ||
2169 size.vec<int>()(j) == input.shape().dim(j).size());
2170 } else {
2171 replaceable &= (size.vec<int64>()(j) == -1 ||
2172 size.vec<int64>()(j) == input.shape().dim(j).size());
2173 }
2174 }
2175 if (replaceable) {
2176 ReplaceOperationWithIdentity(0, properties, node, optimized_graph);
2177 }
2178 }
2179 return Status::OK();
2180}
2181
2182Status ConstantFolding::SimplifyStridedSlice(const GraphProperties& properties,
2183 bool use_shape_info,

Callers

nothing calls this directly

Calls 10

IsSliceFunction · 0.85
HasInputPropertiesMethod · 0.80
unknown_rankMethod · 0.80
nameMethod · 0.65
inputMethod · 0.45
shapeMethod · 0.45
dim_sizeMethod · 0.45
dtypeMethod · 0.45
sizeMethod · 0.45
dimMethod · 0.45

Tested by

no test coverage detected