Skip to content

Commit

Permalink
[oneDPL] Transform_if APIs (#547)
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Hoeflinger <[email protected]>
  • Loading branch information
danhoeflinger authored Aug 23, 2024
1 parent fc26560 commit eeac4e8
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions source/elements/oneDPL/source/parallel_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -451,5 +451,37 @@ than an element in the range being searched.

The elements of ``[start, end)`` must be partitioned with respect to the comparator used.

.. code:: cpp
template <typename Policy, typename InputIt, typename OutputIt, typename UnaryOp,
typename UnaryPredicate>
OutputIt
transform_if(Policy&& policy, InputIt start, InputIt end, OutputIt result, UnaryOp op,
UnaryPredicate pred); // (1)
template <typename Policy, typename InputIt1, typename InputIt2, typename OutputIt,
typename BinaryOp, typename BinaryPredicate>
OutputIt
transform_if(Policy&& policy, InputIt1 start1, InputIt1 end1, InputIt2 start2, OutputIt result,
BinaryOp op, BinaryPredicate pred); // (2)
``oneapi::dpl::transform_if`` applies a given function to the elements of the input sequence(s) that
satisfy a given predicate, and stores the result to the output. Depending on the arguments, the algorithm:

1. Evaluates the unary predicate ``pred`` for each position ``i`` of the sequence
``[start, end)`` and if ``pred(start[i]) == true``, it performs the unary operation
``op(start[i])`` and stores the result into ``result[i]``. If
``pred(start[i]) == false``, the data element ``result[i]`` is not modified from its
initial value. The return value is an iterator targeting past the last considered element of
the output sequence, that is, ``result + (end - start)``.

2. Evaluates the binary predicate ``pred`` for each position ``i`` of the sequence
``[start1, end1)`` and if ``pred(start1[i], start2[i]) == true``, it performs the
binary operation ``op(start1[i], start2[i])`` and stores the result into ``result[i]``.
If ``pred(start1[i], start2[i]) == false``, the data element ``result[i]`` is not
modified from its initial value. The return value is an iterator targeting past the last
considered element of the output sequence, that is, ``result + (end1 - start1)``.


.. _`C++ Standard`: https://isocpp.org/std/the-standard
.. _`SYCL`: https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html

0 comments on commit eeac4e8

Please sign in to comment.