| 56 | |
| 57 | template <typename T, typename Context> |
| 58 | typename std::enable_if<std::is_same<T, bool>::value>::type CopyVectorToTensor( |
| 59 | const Context& dev_ctx, |
| 60 | const std::vector<Scalar>& values, |
| 61 | DenseTensor* out) { |
| 62 | // If attribute value dtype is vector<bool>, it will be converted to |
| 63 | // vector<int>. at the same time, we can not use vector<bool> to hold |
| 64 | // the value, because the c++ use bit value to replace byte value. |
| 65 | std::vector<int> assign_values; |
| 66 | assign_values.reserve(values.size()); |
| 67 | for (const auto& val : values) { |
| 68 | assign_values.emplace_back(val.to<int>()); |
| 69 | } |
| 70 | TensorFromVector(assign_values, dev_ctx, out); |
| 71 | |
| 72 | // use the array to replace to vector |
| 73 | bool* array_ptr = new T[assign_values.size()]; |
| 74 | for (unsigned int i = 0; i < assign_values.size(); i++) { |
| 75 | array_ptr[i] = static_cast<T>(assign_values[i]); |
| 76 | } |
| 77 | phi::TensorFromArray(array_ptr, assign_values.size(), dev_ctx, out); |
| 78 | delete[] array_ptr; |
| 79 | } |
| 80 | |
| 81 | template <typename T, typename Context> |
| 82 | typename std::enable_if<!std::is_same<T, bool>::value>::type CopyVectorToTensor( |
nothing calls this directly
no test coverage detected