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 6151565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:47:08+00:00 2026-05-23T19:47:08+00:00

The Data.Vector API provides an efficient backpermute function, which basically applies a index-mapping σ

  • 0

The Data.Vector API provides an efficient backpermute function, which basically applies a index-mapping σ-vector to a vector v, i.e. v'[j] = v[σ[j]].

Or expressed in list-syntax (for simplicity):

backpermute :: [Int] -> [a] -> [a]
backpermute σ v = map (v !!) σ

Which can have O(n) complexity if !! has O(1) complexity (which I assume for Data.Vector). Now I want the inverse “forward” permute operation (or alternatively a function for inverting the σ-vector itself), i.e. something like (again in list-syntax):

permute :: [Int] -> [a] -> [a]
permute σ = map snd . sortBy (comparing fst) . zip σ

invperm :: [Int] -> [Int]
invperm σ = permute σ [0..]

Alas, the code above is not O(n) due to sortBy. But since σ is assumed to be a permutation of a prefix of [0..] permute should be expressible as a O(n) algorithm with the Data.Vector API.

So, how can I implement an efficient O(n) permute (or alternatively an O(n) invperm) in terms of the Data.Vector.* APIs?

  • 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-05-23T19:47:09+00:00Added an answer on May 23, 2026 at 7:47 pm

    Monadic initialization, perhaps?

    invSigma :: Vector Int -> Vector Int
    invSigma s = create $ 
                 do v <- new n
                    zipWithM_ (write v) s (enumFromN 0 n)
                    return v
      where n = V.length s
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with a function which yields some data as a std::vector<char> and another
I'm writing a Haskell library which uses Data.Vector 's. I successfully wrote library function,
Is it possible to implement a function to access a private data vector foo
I have to apply regression function progressively to a time series data (vector time
Vector's new method data() provides a const and non-const version. However string's data() method
I want to store a very large amount of vector data on a server
Say I have a vector: (def data [Hello World Test This]) And I want
I'd like a generic method for retrieving the data from a vector. I have
I have some data structures: all_unordered_m is a big vector containing all the strings
I'm having some trouble reading data from a file into a vector of Orders.

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.