-
Notifications
You must be signed in to change notification settings - Fork 338
OSX #610
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
Merged
Merged
OSX #610
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
af7b197
Skip matrix transpose example on Apple CPU devices
jszuppe 968056c
Adapt command queue test to different devices
jszuppe e199304
Turn off inplace_reduce and radix_sort tests on Apple
jszuppe 6412cb2
Fix typos in test_lambda.cpp
jszuppe 38b75f9
Fix boost::compute::discrete_distribution constructor
jszuppe 0fe1ab3
Add type checks for distributions
jszuppe 57ea7d8
Skipping resize_throw_exception test on Apple
jszuppe 13e173c
Failures not allowed on OSX Travis-CI build
jszuppe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,9 @@ | |
#ifndef BOOST_COMPUTE_RANDOM_DISCRETE_DISTRIBUTION_HPP | ||
#define BOOST_COMPUTE_RANDOM_DISCRETE_DISTRIBUTION_HPP | ||
|
||
#include <boost/type_traits.hpp> | ||
#include <boost/static_assert.hpp> | ||
|
||
#include <boost/compute/command_queue.hpp> | ||
#include <boost/compute/function.hpp> | ||
#include <boost/compute/algorithm/accumulate.hpp> | ||
|
@@ -42,8 +45,8 @@ class discrete_distribution | |
/// the range [\p first, \p last) | ||
template<class InputIterator> | ||
discrete_distribution(InputIterator first, InputIterator last) | ||
: m_n(std::distance(first, last)), | ||
m_probabilities(std::distance(first, last)) | ||
: m_n((std::max)(size_t(1), static_cast<size_t>(std::distance(first, last)))), | ||
m_probabilities((std::max)(size_t(1), static_cast<size_t>(std::distance(first, last)))) | ||
{ | ||
double sum = 0; | ||
|
||
|
@@ -52,9 +55,14 @@ class discrete_distribution | |
sum += *iter; | ||
} | ||
|
||
for(size_t i=0; i<m_n; i++) | ||
InputIterator iter = first; | ||
m_probabilities[0] = (*iter)/sum; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this could be invalid if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, yeah, you're right. I'll fix it. |
||
iter++; | ||
|
||
for(size_t i = 1; i < m_n; i++) | ||
{ | ||
m_probabilities[i] = m_probabilities[i-1] + first[i]/sum; | ||
m_probabilities[i] = m_probabilities[i-1] + (*iter)/sum; | ||
iter++; | ||
} | ||
} | ||
|
||
|
@@ -109,6 +117,11 @@ class discrete_distribution | |
private: | ||
size_t m_n; | ||
::std::vector<double> m_probabilities; | ||
|
||
BOOST_STATIC_ASSERT_MSG( | ||
boost::is_integral<IntType>::value, | ||
"Template argument must be integral" | ||
); | ||
}; | ||
|
||
} // end compute namespace | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still need to handle the case where
first == last
better. Looking at the documentation for std::discrete_distribution, when the input range is empty (or calling the default constructor), we should just initialize with a single probability of1
. But this is currently not implemented, and we don't have to do it in this pull request. I'll open a separate bug for this.