| 183 | |
| 184 | template <typename T, typename Context> |
| 185 | void SetValueKernel(const Context& dev_ctx, |
| 186 | const DenseTensor& x, |
| 187 | const IntArray& starts, |
| 188 | const IntArray& ends, |
| 189 | const IntArray& steps, |
| 190 | const std::vector<int64_t>& axes, |
| 191 | const std::vector<int64_t>& decrease_axes, |
| 192 | const std::vector<int64_t>& none_axes, |
| 193 | const std::vector<int64_t>& shape, |
| 194 | const std::vector<Scalar>& values, |
| 195 | DenseTensor* out) { |
| 196 | std::vector<T> assign_values; |
| 197 | assign_values.reserve(values.size()); |
| 198 | for (const auto& val : values) { |
| 199 | assign_values.push_back(val.to<T>()); |
| 200 | } |
| 201 | |
| 202 | bool is_full_set_one_value = false; |
| 203 | std::vector<int64_t> starts_local = starts.GetData(); |
| 204 | std::vector<int64_t> ends_local = ends.GetData(); |
| 205 | std::vector<int64_t> steps_local = steps.GetData(); |
| 206 | if (starts_local.empty() && ends_local.empty() && steps_local.empty() && |
| 207 | shape.size() == 1 && shape[0] == 1 && assign_values.size() == 1) { |
| 208 | is_full_set_one_value = true; |
| 209 | } |
| 210 | if (is_full_set_one_value && std::is_same<T, float>::value) { |
| 211 | dev_ctx.template Alloc<T>(out); |
| 212 | funcs::set_constant(dev_ctx, out, static_cast<float>(assign_values[0])); |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | DenseTensor value_tensor = Empty<T>(dev_ctx, shape); |
| 217 | TensorFromVector(assign_values, dev_ctx, &value_tensor); |
| 218 | value_tensor.Resize(shape); |
| 219 | |
| 220 | SetTensorValueKernel<T, Context>(dev_ctx, |
| 221 | x, |
| 222 | value_tensor, |
| 223 | starts, |
| 224 | ends, |
| 225 | steps, |
| 226 | axes, |
| 227 | decrease_axes, |
| 228 | none_axes, |
| 229 | out); |
| 230 | } |
| 231 | |
| 232 | } // namespace phi |
| 233 |
nothing calls this directly
no test coverage detected