| 2104 | } |
| 2105 | |
| 2106 | Status SparseReduceShapeFn(InferenceContext* c) { |
| 2107 | // Input 0: input_indices |
| 2108 | // Input 1: input_values |
| 2109 | // Input 2: input_shape |
| 2110 | // Input 3: reduction_axes |
| 2111 | // Attr: keep_dims |
| 2112 | bool keep_dims = false; |
| 2113 | TF_RETURN_IF_ERROR(c->GetAttr("keep_dims", &keep_dims)); |
| 2114 | |
| 2115 | const Tensor* shape_tensor = c->input_tensor(2); |
| 2116 | const Tensor* axes_tensor = c->input_tensor(3); |
| 2117 | if (shape_tensor != nullptr && axes_tensor != nullptr) { |
| 2118 | auto shape_vec = shape_tensor->flat<int64>(); |
| 2119 | auto axes_vec = axes_tensor->flat<int32>(); |
| 2120 | |
| 2121 | int64 ndims = shape_vec.size(); |
| 2122 | absl::flat_hash_set<int64> axes; |
| 2123 | if (ndims == 0) |
| 2124 | return errors::InvalidArgument( |
| 2125 | "Number of dims in shape tensor must not be 0"); |
| 2126 | for (int i = 0; i < axes_vec.size(); i++) { |
| 2127 | axes.insert((axes_vec(i) + ndims) % ndims); |
| 2128 | } |
| 2129 | |
| 2130 | std::vector<DimensionHandle> dims; |
| 2131 | if (keep_dims) { |
| 2132 | dims.reserve(ndims); |
| 2133 | for (int d = 0; d < ndims; ++d) { |
| 2134 | if (axes.find(d) == axes.end()) { |
| 2135 | dims.push_back(c->MakeDim(shape_vec(d))); |
| 2136 | } else { |
| 2137 | dims.push_back(c->MakeDim(1)); |
| 2138 | } |
| 2139 | } |
| 2140 | } else { |
| 2141 | for (int d = 0; d < ndims; ++d) { |
| 2142 | if (axes.find(d) == axes.end()) { |
| 2143 | dims.push_back(c->MakeDim(shape_vec(d))); |
| 2144 | } |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | c->set_output(0, c->MakeShape(dims)); |
| 2149 | return Status::OK(); |
| 2150 | } |
| 2151 | return UnknownShape(c); |
| 2152 | } |
| 2153 | |
| 2154 | } // namespace shape_inference |
| 2155 |
nothing calls this directly
no test coverage detected