arrayfire / arrayfire/arrayfire
Create array from vector<long>
- 主要语言
- C++
- 星标
- 4.9k
- 派生
- 555
- 平均合并
- 1 小时 24 分钟
- 30 天内合并 PR
- 1
描述
Currently, this code will not link (using 3.6.1):
#include
int main() {
std::vector v{1, 2, 3};
auto a = af::array(v.size(), v.data());
}
/*
error: undefined reference to 'af::array::array(long long, long const*, af_source)'
clang-7.0: error: linker command failed with exit code 1 (use -v to see invocation)
*/
Indeed, I can't see any safe way to convert a `std::vector` to an `af::array` without copying the vector first. Trying something like this:
static_assert(sizeof(long) == sizeof(long long));
auto a = af::array(v.size(), reinterpret_cast(v.data()));
is unsafe due to strict aliasing rules. Same thing with using `af_create_array` or `af_write_array` if `long*` is passed.
On my platform `int64_t` is typedef'd to `long`, so I run into the same issue with `std::vector`. This is unfortunate since the correspondence between `int64_t` and `af::dtype::s64` is suggestive.
Is there any way around this issue, besides just copying the vector?
贡献指南
评估
这个 Issue 还没有评估数据。