Skip to content
Merged
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
4 changes: 2 additions & 2 deletions varopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Varopt struct {
// passed in separately.
type Sample interface{}

var ErrInvalidWeight = fmt.Errorf("Negative, zero, or NaN weight")
var ErrInvalidWeight = fmt.Errorf("Negative, Zero, Inf or NaN weight")

// New returns a new Varopt sampler with given capacity (i.e.,
// reservoir size) and random number generator.
Expand Down Expand Up @@ -78,7 +78,7 @@ func (s *Varopt) Add(sample Sample, weight float64) (Sample, error) {
Weight: weight,
}

if weight <= 0 || math.IsNaN(weight) {
if weight <= 0 || math.IsNaN(weight) || math.IsInf(weight, 1) {
return nil, ErrInvalidWeight
}

Expand Down