Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8104335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:48:41+00:00 2026-06-05T23:48:41+00:00

I am using thrust::sequence(myvector.begin(), myvector.end(), 0, 1) and achieve good ordered list like: 0,

  • 0

I am using

thrust::sequence(myvector.begin(), myvector.end(), 0, 1)

and achieve good ordered list like:

0, 1, 2, 3, 4

My question is how can I achieve such a list below (the best way?)

0, 0, 0, 1, 1, 1, 2, 2 ,2, 3, 3, 3

I know how to make it with functors, so please do not try to answer it with functor. I want to learn if there is an optimized way for it in Thrust, or am I missing a simple way..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:48:42+00:00Added an answer on June 5, 2026 at 11:48 pm

    Something like this:

    thrust::device_vector<int> myvector(N);
    
    thrust::transform( thrust::make_counting_iterator(0),
                       thrust::make_counting_iterator(N),
                       thrust::make_constant_iterator(3),
                       myvector.begin(),
                       thrust::divides<int>() );
    

    (disclaimer, written in browser, never compiled or tested, use at own risk)

    should give you the sequence you are looking for by computing [0..N]//3 and outputting the result on myvector.


    Seeing as you are having trouble compiling your version, here is a complete example which compiles and runs:

    #include <thrust/device_vector.h>
    #include <thrust/transform.h>
    #include <thrust/functional.h>
    #include <thrust/iterator/counting_iterator.h>
    #include <thrust/iterator/constant_iterator.h>
    #include <cstdio>
    
    int main(void)
    {
        const int N = 18, M = 3;
        thrust::device_vector<int> myvector(N);
    
        thrust::transform(  thrust::make_counting_iterator(0),
                            thrust::make_counting_iterator(N),
                            thrust::make_constant_iterator(M),
                            myvector.begin(),
                            thrust::divides<int>() );
    
        for(int i=0; i<N; i++) {
            int val = myvector[i];
            printf("%d %d\n", i, val);
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Flex 3, I would like to take an image snapshot such as this:
Using a restful resource in Rails, I would like to be able to insert
Using PHP, I can convert MySQL data or static table data to csv, Excel,
I am using the thrust partition function to partition array into even and odd
I am trying to time the thrust sort function . Present, i am using
Recently I have been using thrust a lot. I have noticed that in order
I'm trying to find the minimum number in a array using Thrust and CUDA.
I'm trying to compile a block of example code using Thrust in an attempt
I'm trying to modify a simple dynamic vector in CUDA using the thrust library
I'm trying to build a trivial application using Thrust/CUDA 4.0 and get lots of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.