Skip to content

Issue with the example of cpp_for_opencl.md #31

@Eldadkro

Description

@Eldadkro

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:

  1. the get functions should return T type.
  2. 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; }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions