KhronosGroup / KhronosGroup/OpenCL-Guide

Issue with the example of cpp_for_opencl.md

Open Beginner friendly
#31 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
CMake
Stars
711
Forks
70
PR merge metrics
No merged PRs in 30d

Description

In chapters/cpp_for_opencl.md there is an example of how to implement a kernel using C++ of complex number arithmetic.
```CPP
template
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:

```CPP
template
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(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; }
};

```

Contributor guide

Open the contributing guide

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.