MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / CopyVectorToTensor

Function CopyVectorToTensor

paddle/phi/kernels/assign_kernel.cc:58–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56
57template <typename T, typename Context>
58typename 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
81template <typename T, typename Context>
82typename std::enable_if<!std::is_same<T, bool>::value>::type CopyVectorToTensor(

Callers

nothing calls this directly

Calls 5

TensorFromVectorFunction · 0.50
TensorFromArrayFunction · 0.50
reserveMethod · 0.45
sizeMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected