Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions sampling/include/var_opt_sketch_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,9 +724,11 @@ std::string var_opt_sketch<T,S,A>::items_to_string() const {

template<typename T, typename S, typename A>
void var_opt_sketch<T,S,A>::update(const T& item, double weight, bool mark) {
if (weight <= 0.0) {
throw std::invalid_argument("Item weights must be strictly positive. Found: "
if (weight < 0.0 || std::isnan(weight) || std::isinf(weight)) {
throw std::invalid_argument("Item weights must be nonnegativge and finite. Found: "
+ std::to_string(weight));
} else if (weight == 0.0) {
return;
}
++n_;

Expand Down
4 changes: 4 additions & 0 deletions sampling/test/var_opt_sketch_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ class var_opt_sketch_test: public CppUnit::TestFixture {
CPPUNIT_ASSERT_THROW_MESSAGE("update() accepted a negative weight",
sk.update("invalid_weight", -1.0),
std::invalid_argument);

// should not throw but sketch shoulds till be empty
sk.update("zero weight", 0.0);
CPPUNIT_ASSERT(sk.is_empty());
}

void corrupt_serialized_weight() {
Expand Down