/usr/include/thrust/scan.h is in libthrust-dev 1.6.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 | /*
* Copyright 2008-2012 NVIDIA Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*! \file scan.h
* \brief Functions for computing prefix sums
*/
#pragma once
#include <thrust/detail/config.h>
namespace thrust
{
/*! \addtogroup algorithms
*/
/*! \addtogroup prefixsums Prefix Sums
* \ingroup algorithms
* \{
*/
/*! \p inclusive_scan computes an inclusive prefix sum operation. The
* term 'inclusive' means that each result includes the corresponding
* input operand in the partial sum. More precisely, <tt>*first</tt> is
* assigned to <tt>*result</tt> and the sum of <tt>*first</tt> and
* <tt>*(first + 1)</tt> is assigned to <tt>*(result + 1)</tt>, and so on.
* This version of \p inclusive_scan assumes plus as the associative operator.
* When the input and output sequences are the same, the scan is performed
* in-place.
* \p inclusive_scan is similar to \c std::partial_sum in the STL. The primary
* difference between the two functions is that \c std::partial_sum guarantees
* a serial summation order, while \p inclusive_scan requires associativity of
* the binary operation to parallelize the prefix sum.
*
* \param first The beginning of the input sequence.
* \param last The end of the input sequence.
* \param result The beginning of the output sequence.
* \return The end of the output sequence.
*
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
* and \c InputIterator's \c value_type is convertible to
* \c OutputIterator's \c value_type.
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>,
* and if \c x and \c y are objects of \c OutputIterator's
* \c value_type, then <tt>x + y</tt> is defined. If \c T is
* \c OutputIterator's \c value_type, then <tt>T(0)</tt> is
* defined.
*
* The following code snippet demonstrates how to use \p inclusive_scan
*
* \code
* #include <thrust/scan.h>
*
* int data[6] = {1, 0, 2, 2, 1, 3};
*
* thrust::inclusive_scan(data, data + 6, data); // in-place scan
*
* // data is now {1, 1, 3, 5, 6, 9}
* \endcode
*
* \see http://www.sgi.com/tech/stl/partial_sum.html
*
*/
template<typename InputIterator,
typename OutputIterator>
OutputIterator inclusive_scan(InputIterator first,
InputIterator last,
OutputIterator result);
/*! \p inclusive_scan computes an inclusive prefix sum operation. The
* term 'inclusive' means that each result includes the corresponding
* input operand in the partial sum. When the input and output sequences
* are the same, the scan is performed in-place.
*
* \p inclusive_scan is similar to \c std::partial_sum in the STL. The primary
* difference between the two functions is that \c std::partial_sum guarantees
* a serial summation order, while \p inclusive_scan requires associativity of
* the binary operation to parallelize the prefix sum.
*
* \param first The beginning of the input sequence.
* \param last The end of the input sequence.
* \param result The beginning of the output sequence.
* \param binary_op The associatve operator used to 'sum' values.
* \return The end of the output sequence.
*
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
* and \c InputIterator's \c value_type is convertible to
* \c OutputIterator's \c value_type.
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>
* and \c OutputIterator's \c value_type is convertible to
* both \c AssociativeOperator's \c first_argument_type and
* \c second_argument_type.
* \tparam AssociativeOperator is a model of <a href="http://www.sgi.com/tech/stl/BinaryFunction.html">Binary Function</a>
* and \c AssociativeOperator's \c result_type is
* convertible to \c OutputIterator's \c value_type.
*
* The following code snippet demonstrates how to use \p inclusive_scan
*
* \code
* int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
*
* thrust::maximum<int> binary_op;
*
* thrust::inclusive_scan(data, data + 10, data, 1, binary_op); // in-place scan
*
* // data is now {1, 1, 2, 2, 2, 4, 4, 4, 4, 8}
* \endcode
*
* \see http://www.sgi.com/tech/stl/partial_sum.html
*/
template<typename InputIterator,
typename OutputIterator,
typename AssociativeOperator>
OutputIterator inclusive_scan(InputIterator first,
InputIterator last,
OutputIterator result,
AssociativeOperator binary_op);
/*! \p exclusive_scan computes an exclusive prefix sum operation. The
* term 'exclusive' means that each result does not include the
* corresponding input operand in the partial sum. More precisely,
* <tt>0</tt> is assigned to <tt>*result</tt> and the sum of
* <tt>0</tt> and <tt>*first</tt> is assigned to <tt>*(result + 1)</tt>,
* and so on. This version of \p exclusive_scan assumes plus as the
* associative operator and \c 0 as the initial value. When the input and
* output sequences are the same, the scan is performed in-place.
*
* \param first The beginning of the input sequence.
* \param last The end of the input sequence.
* \param result The beginning of the output sequence.
* \return The end of the output sequence.
*
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
* and \c InputIterator's \c value_type is convertible to
* \c OutputIterator's \c value_type.
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>,
* and if \c x and \c y are objects of \c OutputIterator's
* \c value_type, then <tt>x + y</tt> is defined. If \c T is
* \c OutputIterator's \c value_type, then <tt>T(0)</tt> is
* defined.
*
* The following code snippet demonstrates how to use \p exclusive_scan
*
* \code
* #include <thrust/scan.h>
*
* int data[6] = {1, 0, 2, 2, 1, 3};
*
* thrust::exclusive_scan(data, data + 6, data); // in-place scan
*
* // data is now {0, 1, 1, 3, 5, 6}
* \endcode
*
* \see http://www.sgi.com/tech/stl/partial_sum.html
*/
template<typename InputIterator,
typename OutputIterator>
OutputIterator exclusive_scan(InputIterator first,
InputIterator last,
OutputIterator result);
/*! \p exclusive_scan computes an exclusive prefix sum operation. The
* term 'exclusive' means that each result does not include the
* corresponding input operand in the partial sum. More precisely,
* \p init is assigned to <tt>*result</tt> and the sum of \p init and
* <tt>*first</tt> is assigned to <tt>*(result + 1)</tt>, and so on.
* This version of \p exclusive_scan assumes plus as the associative
* operator but requires an initial value \p init. When the input and
* output sequences are the same, the scan is performed in-place.
*
* \param first The beginning of the input sequence.
* \param last The end of the input sequence.
* \param result The beginning of the output sequence.
* \param init The initial value.
* \return The end of the output sequence.
*
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
* and \c InputIterator's \c value_type is convertible to
* \c OutputIterator's \c value_type.
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>,
* and if \c x and \c y are objects of \c OutputIterator's
* \c value_type, then <tt>x + y</tt> is defined.
* \tparam T is convertible to \c OutputIterator's \c value_type.
*
* The following code snippet demonstrates how to use \p exclusive_scan
*
* \code
* #include <thrust/scan.h>
*
* int data[6] = {1, 0, 2, 2, 1, 3};
*
* thrust::exclusive_scan(data, data + 6, data, 4); // in-place scan
*
* // data is now {4, 5, 5, 7, 9, 10}
* \endcode
*
* \see http://www.sgi.com/tech/stl/partial_sum.html
*/
template<typename InputIterator,
typename OutputIterator,
typename T>
OutputIterator exclusive_scan(InputIterator first,
InputIterator last,
OutputIterator result,
T init);
/*! \p exclusive_scan computes an exclusive prefix sum operation. The
* term 'exclusive' means that each result does not include the
* corresponding input operand in the partial sum. More precisely,
* \p init is assigned to <tt>*result</tt> and the value
* <tt>binary_op(init, *first)</tt> is assigned to <tt>*(result + 1)</tt>,
* and so on. This version of the function requires both and associative
* operator and an initial value \p init. When the input and output
* sequences are the same, the scan is performed in-place.
*
* \param first The beginning of the input sequence.
* \param last The end of the input sequence.
* \param result The beginning of the output sequence.
* \param init The initial value.
* \param binary_op The associatve operator used to 'sum' values.
* \return The end of the output sequence.
*
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
* and \c InputIterator's \c value_type is convertible to
* \c OutputIterator's \c value_type.
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>
* and \c OutputIterator's \c value_type is convertible to
* both \c AssociativeOperator's \c first_argument_type and
* \c second_argument_type.
* \tparam T is convertible to \c OutputIterator's \c value_type.
* \tparam AssociativeOperator is a model of <a href="http://www.sgi.com/tech/stl/BinaryFunction.html">Binary Function</a>
* and \c AssociativeOperator's \c result_type is
* convertible to \c OutputIterator's \c value_type.
*
* The following code snippet demonstrates how to use \p exclusive_scan
*
* \code
* #include <thrust/scan.h>
* #include <thrust/functional.h>
*
* int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
*
* thrust::maximum<int> binary_op;
*
* thrust::exclusive_scan(data, data + 10, data, 1, binary_op); // in-place scan
*
* // data is now {1, 1, 1, 2, 2, 2, 4, 4, 4, 4 }
* \endcode
*
* \see http://www.sgi.com/tech/stl/partial_sum.html
*/
template<typename InputIterator,
typename OutputIterator,
typename T,
typename AssociativeOperator>
OutputIterator exclusive_scan(InputIterator first,
InputIterator last,
OutputIterator result,
T init,
AssociativeOperator binary_op);
/*! \addtogroup segmentedprefixsums Segmented Prefix Sums
* \ingroup prefixsums
* \{
*/
/*! \p inclusive_scan_by_key computes an inclusive key-value or 'segmented' prefix
* sum operation. The term 'inclusive' means that each result includes
* the corresponding input operand in the partial sum. The term 'segmented'
* means that the partial sums are broken into distinct segments. In other
* words, within each segment a separate inclusive scan operation is computed.
* Refer to the code sample below for example usage.
*
* This version of \p inclusive_scan_by_key assumes \c equal_to as the binary
* predicate used to compare adjacent keys. Specifically, consecutive iterators
* <tt>i</tt> and <tt>i+1</tt> in the range <tt>[first1, last1)</tt>
* belong to the same segment if <tt>*i == *(i+1)</tt>, and belong to
* different segments otherwise.
*
* This version of \p inclusive_scan_by_key assumes \c plus as the associative
* operator used to perform the prefix sum. When the input and output sequences
* are the same, the scan is performed in-place.
*
* \param first1 The beginning of the key sequence.
* \param last1 The end of the key sequence.
* \param first2 The beginning of the input value sequence.
* \param result The beginning of the output value sequence.
* \return The end of the output sequence.
*
* \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
* \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
* and \c InputIterator2's \c value_type is convertible to \c OutputIterator's \c value_type.
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>,
* and if \c x and \c y are objects of \c OutputIterator's \c value_type, then
* <tt>binary_op(x,y)</tt> is defined.
*
* The following code snippet demonstrates how to use \p inclusive_scan_by_key
*
* \code
* #include <thrust/scan.h>
*
* int data[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
* int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3};
*
* thrust::inclusive_scan_by_key(keys, keys + 10, vals, vals); // in-place scan
*
* // data is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4};
* \endcode
*
* \see inclusive_scan
* \see exclusive_scan_by_key
*
*/
template<typename InputIterator1,
typename InputIterator2,
typename OutputIterator>
OutputIterator inclusive_scan_by_key(InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result);
/*! \p inclusive_scan_by_key computes an inclusive key-value or 'segmented' prefix
* sum operation. The term 'inclusive' means that each result includes
* the corresponding input operand in the partial sum. The term 'segmented'
* means that the partial sums are broken into distinct segments. In other
* words, within each segment a separate inclusive scan operation is computed.
* Refer to the code sample below for example usage.
*
* This version of \p inclusive_scan_by_key uses the binary predicate
* \c pred to compare adjacent keys. Specifically, consecutive iterators
* <tt>i</tt> and <tt>i+1</tt> in the range <tt>[first1, last1)</tt>
* belong to the same segment if <tt>binary_pred(*i, *(i+1))</tt> is true, and belong to
* different segments otherwise.
*
* This version of \p inclusive_scan_by_key assumes \c plus as the associative
* operator used to perform the prefix sum. When the input and output sequences
* are the same, the scan is performed in-place.
*
* \param first1 The beginning of the key sequence.
* \param last1 The end of the key sequence.
* \param first2 The beginning of the input value sequence.
* \param result The beginning of the output value sequence.
* \param binary_pred The binary predicate used to determine equality of keys.
* \return The end of the output sequence.
*
* \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
* \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
* and \c InputIterator2's \c value_type is convertible to \c OutputIterator's \c value_type.
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>,
* and if \c x and \c y are objects of \c OutputIterator's \c value_type, then
* <tt>binary_op(x,y)</tt> is defined.
* \tparam BinaryPredicate is a model of <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">Binary Predicate</a>.
*
* The following code snippet demonstrates how to use \p inclusive_scan_by_key
*
* \code
* #include <thrust/scan.h>
* #include <thrust/functional.h>
*
* int data[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
* int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3};
*
* thrust::equal_to<int> binary_pred;
*
* thrust::inclusive_scan_by_key(keys, keys + 10, vals, vals, binary_pred); // in-place scan
*
* // data is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4};
* \endcode
*
* \see inclusive_scan
* \see exclusive_scan_by_key
*
*/
template<typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename BinaryPredicate>
OutputIterator inclusive_scan_by_key(InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result,
BinaryPredicate binary_pred);
/*! \p inclusive_scan_by_key computes an inclusive key-value or 'segmented' prefix
* sum operation. The term 'inclusive' means that each result includes
* the corresponding input operand in the partial sum. The term 'segmented'
* means that the partial sums are broken into distinct segments. In other
* words, within each segment a separate inclusive scan operation is computed.
* Refer to the code sample below for example usage.
*
* This version of \p inclusive_scan_by_key uses the binary predicate
* \c pred to compare adjacent keys. Specifically, consecutive iterators
* <tt>i</tt> and <tt>i+1</tt> in the range <tt>[first1, last1)</tt>
* belong to the same segment if <tt>binary_pred(*i, *(i+1))</tt> is true, and belong to
* different segments otherwise.
*
* This version of \p inclusive_scan_by_key uses the associative operator
* \c binary_op to perform the prefix sum. When the input and output sequences
* are the same, the scan is performed in-place.
*
* \param first1 The beginning of the key sequence.
* \param last1 The end of the key sequence.
* \param first2 The beginning of the input value sequence.
* \param result The beginning of the output value sequence.
* \param binary_pred The binary predicate used to determine equality of keys.
* \param binary_op The associatve operator used to 'sum' values.
* \return The end of the output sequence.
*
* \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
* \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
* and \c InputIterator2's \c value_type is convertible to \c OutputIterator's \c value_type.
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>,
* and if \c x and \c y are objects of \c OutputIterator's \c value_type, then
* <tt>binary_op(x,y)</tt> is defined.
* \tparam BinaryPredicate is a model of <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">Binary Predicate</a>.
* \tparam AssociativeOperator is a model of <a href="http://www.sgi.com/tech/stl/BinaryFunction.html">Binary Function</a>
* and \c AssociativeOperator's \c result_type is
* convertible to \c OutputIterator's \c value_type.
*
* The following code snippet demonstrates how to use \p inclusive_scan_by_key
*
* \code
* #include <thrust/scan.h>
* #include <thrust/functional.h>
*
* int data[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
* int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3};
*
* thrust::equal_to<int> binary_pred;
* thrust::plus<int> binary_op;
*
* thrust::inclusive_scan_by_key(keys, keys + 10, vals, vals, binary_pred, binary_op); // in-place scan
*
* // data is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4};
* \endcode
*
* \see inclusive_scan
* \see exclusive_scan_by_key
*
*/
template<typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename BinaryPredicate,
typename AssociativeOperator>
OutputIterator inclusive_scan_by_key(InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result,
BinaryPredicate binary_pred,
AssociativeOperator binary_op);
/*! \p exclusive_scan_by_key computes an exclusive segmented prefix
*
* This version of \p exclusive_scan_by_key uses the value \c 0 to
* initialize the exclusive scan operation.
*
* This version of \p exclusive_scan_by_key assumes \c plus as the associative
* operator used to perform the prefix sum. When the input and output sequences
* are the same, the scan is performed in-place.
*
* This version of \p exclusive_scan_by_key assumes \c equal_to as the binary
* predicate used to compare adjacent keys. Specifically, consecutive iterators
* <tt>i</tt> and <tt>i+1</tt> in the range <tt>[first1, last1</tt>
* belong to the same segment if <tt>*i == *(i+1)</tt>, and belong to
* different segments otherwise.
*
* Refer to the most general form of \p exclusive_scan_by_key for additional details.
*
* \param first1 The beginning of the key sequence.
* \param last1 The end of the key sequence.
* \param first2 The beginning of the input value sequence.
* \param result The beginning of the output value sequence.
*
* The following code snippet demonstrates how to use \p exclusive_scan_by_key.
*
* \code
* #include <thrust/scan.h>
*
* int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3};
* int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
*
* thrust::exclusive_scan_by_key(key, key + 10, vals, vals); // in-place scan
*
* // vals is now {0, 1, 2, 0, 1, 0, 0, 1, 2, 3};
* \endcode
*
* \see exclusive_scan
*
*/
template<typename InputIterator1,
typename InputIterator2,
typename OutputIterator>
OutputIterator exclusive_scan_by_key(InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result);
/*! \p exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix
* sum operation. The term 'exclusive' means that each result does not include
* the corresponding input operand in the partial sum. The term 'segmented'
* means that the partial sums are broken into distinct segments. In other
* words, within each segment a separate exclusive scan operation is computed.
* Refer to the code sample below for example usage.
*
* This version of \p exclusive_scan_by_key uses the value \c init to
* initialize the exclusive scan operation.
*
* \param first1 The beginning of the key sequence.
* \param last1 The end of the key sequence.
* \param first2 The beginning of the input value sequence.
* \param result The beginning of the output value sequence.
* \param init The initial of the exclusive sum value.
* \return The end of the output sequence.
*
* The following code snippet demonstrates how to use \p exclusive_scan_by_key
*
* \code
* #include <thrust/scan.h>
* #include <thrust/functional.h>
*
* int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3};
* int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
*
* int init = 5;
*
* thrust::exclusive_scan_by_key(key, key + 10, vals, vals, init); // in-place scan
*
* // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8};
* \endcode
*
* \see exclusive_scan
* \see inclusive_scan_by_key
*
*/
template<typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename T>
OutputIterator exclusive_scan_by_key(InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result,
T init);
/*! \p exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix
* sum operation. The term 'exclusive' means that each result does not include
* the corresponding input operand in the partial sum. The term 'segmented'
* means that the partial sums are broken into distinct segments. In other
* words, within each segment a separate exclusive scan operation is computed.
* Refer to the code sample below for example usage.
*
* This version of \p exclusive_scan_by_key uses the value \c init to
* initialize the exclusive scan operation.
*
* This version of \p exclusive_scan_by_key uses the binary predicate \c binary_pred
* to compare adjacent keys. Specifically, consecutive iterators <tt>i</tt> and
* <tt>i+1</tt> in the range <tt>[first1, last1)</tt> belong to the same segment if
* <tt>binary_pred(*i, *(i+1))</tt> is true, and belong to different segments otherwise.
*
* \param first1 The beginning of the key sequence.
* \param last1 The end of the key sequence.
* \param first2 The beginning of the input value sequence.
* \param result The beginning of the output value sequence.
* \param init The initial of the exclusive sum value.
* \param binary_pred The binary predicate used to determine equality of keys.
* \return The end of the output sequence.
*
* The following code snippet demonstrates how to use \p exclusive_scan_by_key
*
* \code
* #include <thrust/scan.h>
* #include <thrust/functional.h>
*
* int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3};
* int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
*
* int init = 5;
*
* thrust::equal_to<int> binary_pred;
*
* thrust::exclusive_scan_by_key(key, key + 10, vals, vals, init, binary_pred); // in-place scan
*
* // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8};
* \endcode
*
* \see exclusive_scan
* \see inclusive_scan_by_key
*
*/
template<typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename T,
typename BinaryPredicate>
OutputIterator exclusive_scan_by_key(InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result,
T init,
BinaryPredicate binary_pred);
/*! \p exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix
* sum operation. The term 'exclusive' means that each result does not include
* the corresponding input operand in the partial sum. The term 'segmented'
* means that the partial sums are broken into distinct segments. In other
* words, within each segment a separate exclusive scan operation is computed.
* Refer to the code sample below for example usage.
*
* This version of \p exclusive_scan_by_key uses the value \c init to
* initialize the exclusive scan operation.
*
* This version of \p exclusive_scan_by_key uses the binary predicate \c binary_pred
* to compare adjacent keys. Specifically, consecutive iterators <tt>i</tt> and
* <tt>i+1</tt> in the range <tt>[first1, last1)</tt> belong to the same segment if
* <tt>binary_pred(*i, *(i+1))</tt> is true, and belong to different segments otherwise.
*
* This version of \p exclusive_scan_by_key uses the associative operator
* \c binary_op to perform the prefix sum. When the input and output sequences
* are the same, the scan is performed in-place.
*
* \param first1 The beginning of the key sequence.
* \param last1 The end of the key sequence.
* \param first2 The beginning of the input value sequence.
* \param result The beginning of the output value sequence.
* \param init The initial of the exclusive sum value.
* \param binary_pred The binary predicate used to determine equality of keys.
* \param binary_op The associatve operator used to 'sum' values.
* \return The end of the output sequence.
*
* \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
* \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
* and \c InputIterator2's \c value_type is convertible to \c OutputIterator's \c value_type.
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>,
* and if \c x and \c y are objects of \c OutputIterator's \c value_type, then
* <tt>binary_op(x,y)</tt> is defined.
* \tparam T is convertible to \c OutputIterator's \c value_type.
* \tparam BinaryPredicate is a model of <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">Binary Predicate</a>.
* \tparam AssociativeOperator is a model of <a href="http://www.sgi.com/tech/stl/BinaryFunction.html">Binary Function</a>
* and \c AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type.
*
* The following code snippet demonstrates how to use \p exclusive_scan_by_key
*
* \code
* #include <thrust/scan.h>
* #include <thrust/functional.h>
*
* int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3};
* int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
*
* int init = 5;
*
* thrust::equal_to<int> binary_pred;
* thrust::plus<int> binary_op;
*
* thrust::exclusive_scan_by_key(key, key + 10, vals, vals, init, binary_pred, binary_op); // in-place scan
*
* // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8};
* \endcode
*
* \see exclusive_scan
* \see inclusive_scan_by_key
*
*/
template<typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename T,
typename BinaryPredicate,
typename AssociativeOperator>
OutputIterator exclusive_scan_by_key(InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result,
T init,
BinaryPredicate binary_pred,
AssociativeOperator binary_op);
/*! \} // end segmentedprefixsums
*/
/*! \} // end prefix sums
*/
} // end namespace thrust
#include <thrust/detail/scan.inl>
|