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

Is it possible for sample to not return vectors? #821

Closed
drelatgithub opened this issue Aug 1, 2022 · 2 comments
Closed

Is it possible for sample to not return vectors? #821

drelatgithub opened this issue Aug 1, 2022 · 2 comments

Comments

@drelatgithub
Copy link

Currently, using sample function with many samples returns a vector with all the sample results. I might be overlooking the documents, but I'm looking for a way to "consume" each sample result in-place without building the resulting vector, while still enjoying the benefit of preprocessing. My use case is similar to the following:

nitems = 100
nsamples = 10000
w = Weights(rand(nitems))
counts = zeros(nitems)

# Is it possible to not generate the 10000-element intermediate vector?
for eachsample in sample(1:nitems, w, nsamples)
    counts[eachsample] += 1
end

# Alternatively, this seems not to utilize preprocessing.
for _ in 1:nsamples
    counts[sample(1:nitems, w)] += 1
end

Is there a way to achieve it? Thank you!

@nalimilan
Copy link
Member

Please use the Discourse forum for questions, and keep GitHub for bug reports. Thanks!

@drelatgithub
Copy link
Author

Sorry about that! I've opened a topic in discourse. Thanks for the time.

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

2 participants