| 2145 | } |
| 2146 | |
| 2147 | Status 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 | |
| 2182 | Status ConstantFolding::SimplifyStridedSlice(const GraphProperties& properties, |
| 2183 | bool use_shape_info, |
nothing calls this directly
no test coverage detected