Permalink
Browse files

Documentation for element_index

  • Loading branch information...
1 parent cab03ea commit ea910dda30915b526c5c73f07891fe4dd11b8914 @ddemidov committed Dec 28, 2012
Showing with 17 additions and 0 deletions.
  1. +7 −0 README.md
  2. +3 −0 vexcl/operations.hpp
  3. +7 −0 vexcl/vexcl.hpp
View
@@ -96,6 +96,13 @@ Y = 42;
Z = sqrt(2 * X) + cos(Y);
```
+If values of vector elements should depend on their positions in the vector,
+then you can use `element_index()` function in vector expresion. For example,
+to assign one period of sine function to a vector, you could
+```C++
+X = sin(2 * M_PI / X.size() * element_index());
+```
+
You can copy the result back to host or you can use `vector::operator[]` to
read (or write) vector elements directly. Though latter technique is very
ineffective and should be used for debugging purposes only.
View
@@ -55,6 +55,7 @@ THE SOFTWARE.
/// Vector expression template library for OpenCL.
namespace vex {
+/// \cond INTERNAL
struct elem_index {
size_t offset;
@@ -65,7 +66,9 @@ template <>
inline std::string type_name<elem_index>() {
return type_name<size_t>();
}
+/// \endcond
+/// When used in vector expression, returns current element index plus offset.
inline typename boost::proto::result_of::as_expr<elem_index>::type
element_index(size_t offset = 0) {
return boost::proto::as_expr(elem_index(offset));
View
@@ -113,6 +113,13 @@ Y = 42;
Z = sqrt(2 * X) + cos(Y);
\endcode
+If values of vector elements should depend on their positions in the vector,
+then you can use element_index() function in vector expresion. For example,
+to assign one period of sine function to a vector, you could
+\code
+X = sin(2 * M_PI / X.size() * element_index());
+\endcode
+
You can copy the result back to host or you can use vector::operator[] to
read (or write) vector elements directly. Though latter technique is very
ineffective and should be used for debugging purposes only.

0 comments on commit ea910dd

Please sign in to comment.