OpenCL-Guide
OpenCL-Guide copied to clipboard
Issue with the example of cpp_for_opencl.md
In chapters/cpp_for_opencl.md there is an example of how to implement a kernel using C++ of complex number arithmetic.
template<typename T>
class complex_t {
T m_re; // Real component.
T m_im; // Imaginary component.
public:
complex_t(T re, T im): m_re{re}, m_im{im} {};
complex_t operator*(const complex_t &other) const
{
return {m_re * other.m_re - m_im * other.m_im,
m_re * other.m_im + m_im * other.m_re};
}
int get_re() const { return m_re; }
int get_im() const { return m_im; }
};
It seems like:
- the get functions should return T type.
- The multiplication operator should return a new instance of the complex_t class rather than a brace-enclosed list.
Here is what I believe is what was intended:
template<typename T>
class complex_t {
T m_re; // Real component.
T m_im; // Imaginary component.
public:
complex_t(T re, T im): m_re{re}, m_im{im} {};
complex_t operator*(const complex_t &other) const
{
return complex_t<T>(m_re * other.m_re - m_im * other.m_im,
m_re * other.m_im + m_im * other.m_re);
}
T get_re() const { return m_re; }
T get_im() const { return m_im; }
};