python - 在pyopencl中编写可以转换类型的函数
问题描述
我正在尝试为 pyopencl 中的 COMPLEX (cfloat_t) 类型编写一些附加函数。我几乎没有使用 OpenCL 的经验,并且有点被语法所困扰。我想编写一些可以接受 REAL 输入(在本例中为浮点数)并将它们转换为 COMPLEX 类型的基本函数。例如,欧拉公式 e^ix = cos(x) + isin(x) 将 x 作为 REAL 输入
我以为这会像
#include <pyopencl-complex.h>
#define REAL float
#define COMPLEX cfloat_t
COMPLEX c_exp_i(REAL x) {return (COMPLEX)(cos(x), sin(x));}
但是当我尝试运行它时,我看到一条错误消息
error: cast to union type from type 'float' not present in union
解决方案
阅读 pyopencl-complex.h 后,我意识到有一个 cfloat_new() 函数可以解决所有问题
COMPLEX c_exp_i(REAL x) {return cfloat_new(cos(x), sin(x));}
推荐阅读
- artificial-intelligence - 有没有办法在 Jason/AgentSpeak 中“抑制”“没有为……生成失败事件”警告/错误?
- javascript - WordPress 版本 5.2。和 Ajax 错误请求 400
- dsl - MPS 中的自定义编辑器
- java - 如何匹配Java中的元组字符串?
- java - Tomcat 安装目录无效。它缺少预期的文件或文件夹 tcruntime-ctl.sh
- java - NetworkBoundResource 类中 MediatorLiveData 的使用
- django - 将自定义 url 操作参数添加到 django-cms
- python - 框架内的 Python 网格管理器
- cakephp - CakePHP 3:[ManyToMany] 使用多个特定标签获取书签
- python - 将同一天的所有数据收集到一行