英文:
arrayfire, pointers, and c++
问题
我一直在尝试以程序方式生成一个 arrayfire 数组的数组。
在过去处理其他对象时,我可以像这样做:
className *listName = (className*)malloc(numOfObjects * sizeof(className))
或者
className **listName = (className**)malloc(numOfObjects * sizeof(className*))
然后使用循环来分配列表中的每个对象,并在使用完毕后删除它们。
然而,在处理 arrayfire 时,这种方法不起作用。
我尝试过以下操作:
af::array *Kernels;
Kernels = (af::array*)malloc(Count * sizeof(af::array));
for(int i = 0; i < Count; i++) {
Kernels[i] = af::range(i);
}
稍后我调用:
free(Kernels);
这段代码可以编译,但在运行时会崩溃。
当它崩溃时,我得到以下信息:
terminate called after throwing an instance of 'af::exception'
what(): ArrayFire Exception (Function does not support this data type: 204):
In function af_err af_release_array(af_array)
In file src/api/c/array.cpp:194
Invalid type for argument 0
In function af::array& af::array::operator=(const af::array&)
In file src/api/cpp/array.cpp:771
Aborted (core dumped)
我正在寻找要么正确的语法来实现我尝试做的事情,要么一个替代方法。
我已经在网上搜索了很多,但没有找到我需要的信息。
谢谢。
英文:
I have been trying to procedurally generate an array of arrayfire arrays.
When dealing with other objects in the past I could either so something like:
className * listName = (className*)malloc(numOfObjects*sizeOf(className))
or
className ** listName = (className**)malloc(numOfObjects*sizeOf(className*))
and then use a for loop to allocate each of the things in the lists and delete them when I'm done with them.
This isn't working with arrayfire however.
I have tried to do
af::array *Kernels;
Kernels = (af::array*)malloc(Count*sizeof(af::array));
for(int i = 0; i < Count; i++) {
Kernels[i] = af::range(i);
}
Later I call:
free Kernels
This code compiles but will crash when I run it.
This is what I get when it crashes:
>terminate called after throwing an instance of 'af::exception'
what(): ArrayFire Exception (Function does not support this data type:204):
In function af_err af_release_array(af_array)
In file src/api/c/array.cpp:194
Invalid type for argument 0
>In function af::array& af::array::operator=(const af::array&)
In file src/api/cpp/array.cpp:771
Aborted (core dumped)
I'm looking for either the correct syntax to do what I am trying to do or an alternative.
I have googled around quite a bit and have not found what I am looking for.
Thanks.
答案1
得分: 0
所以似乎我终于找到了一个解决方案。似乎使用这个:std::vector<af::array> Kernels;
可以让我得到我想要的所有功能。原来,使用双指针会编译通过,但arrayfire中的函数不是为处理af::array*对象指针而构建的。
英文:
So it seems like I have finally gotten a solution. It seems like using this: std::vector<af::array> Kernels;
gets me all the functionality I want. It turns out that having a double pointer will compile but the functions in arrayfire are not built to deal with af::array* object pointers.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论