我有一个二维双数组指针。我可以将它转换为u_int8_t
,将其提取到箭头池缓冲区的mutable_data()
,然后构造一个Arrow DoubleArray。但是,当我从数组的Value()
,raw_values()
获取值时,我无法获得正确的数字。有人请看我的代码并帮助我:
double* generateDoubleArray() {
int totalColumns = 200;
int totalRows = 200;
std::random_device r;
std::default_random_engine e1(r());
std::normal_distribution<double> nor_dist(-1, 1);
double *A = static_cast<double *>(malloc(totalColumns * totalRows * sizeof(double *)));
for (int i = 0; i < totalRows; i++) {
for (int j = 0; j < totalColumns; j++) {
A[i*totalColumns + j] = sin(nor_dist(e1)) + exp(sin(nor_dist(e1)) + cos(nor_dist(e1)));
}
}
return A;
}
int main()
{
double* generatedDouble = generateDoubleArray();
uint8_t *ui_generatedDouble = (uint8_t*)generatedDouble;
arrow::MemoryPool* pool_;
pool_ = arrow::default_memory_pool();
auto data = std::make_shared<arrow::PoolBuffer>(pool_);
size_t length = 200 * 200;
const size_t data_nbytes = length * sizeof(double *);
data->Resize(data_nbytes);
*data->mutable_data() = *ui_generatedDouble;
auto out = std::make_shared<arrow::DoubleArray>(data_nbytes, data);
double test_value = out->Value(0); // The returned value is not correct
return 0;
}
谢谢
答案 0 :(得分:0)
以下行不符合您的想法:
*data->mutable_data() = *ui_generatedDouble;
它只复制数据的第一个字节。您想要记忆整个缓冲区:
std::memcpy(data->mutable_data(), ui_generatedDouble, data_nbytes);