Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looking for some way to generate large vectors efficiently #375

Open
newhoggy opened this issue Feb 27, 2020 · 2 comments
Open

Looking for some way to generate large vectors efficiently #375

newhoggy opened this issue Feb 27, 2020 · 2 comments

Comments

@newhoggy
Copy link

newhoggy commented Feb 27, 2020

hedgehog seems to be slow generating large vectors in CI environment. This is perhaps because the CI environment is underpowered compared to my development environment, but the problem of generating a Vector Word64 up to size 16384 100 times doesn't sound like it ought to be too expensive an operation.

The vector generator is:

storableVector :: (MonadGen m, DVS.Storable a) => Range Int -> m a -> m (DVS.Vector a)
storableVector r g = DVS.fromList <$> G.list r g

Here is an example of the above scenario taking 41s:

https://circleci.com/gh/haskell-works/hw-balancedparens/1233

@newhoggy
Copy link
Author

newhoggy commented Feb 27, 2020

The following hacky implementation is proving to be a lot faster:

storableVectorWord64 :: MonadGen m => Range Int -> m (DVS.Vector Word64)
storableVectorWord64 r = fromGenT $ do
  n <- integral_ r
  GenT $ \_ seed ->
    return $ flip (DVS.unfoldrN n) seed $ \s ->
      let (w, sb) = nextWord64 s in Just (w, sb)

@newhoggy
Copy link
Author

It would be nice to have a vector support in hedgehog that can generate vectors fast and can accept an arbitrary generator.

Would there be interest in something like this?

Also would anyone be able to offer some help?

I have confusion around to properly negotiate the monad stack and I haven't been able find examples in the code to make a working example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant