Issue with the example of cpp_for_opencl.md

Open Beginner friendly
#31 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
72/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Stale
Tech stack
cpp
Domain
documentation

Research direction

Open chapters/cpp_for_opencl.md and inspect the complex_t example. Check the getter return types and multiplication operator against the issue's proposed correction, then update the example so it is internally consistent. Done means the documented C++ code uses T for the getters and returns a complex_t instance from multiplication.

Written by the indexing model from the issue text.

Description

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; }
};

Dominant language
CMake
Stars
710
Forks
69
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from KhronosGroup/OpenCL-Guide

All issues in KhronosGroup/OpenCL-Guide

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.