// Sample takes on whatever value is passed in as a sample.
976490
func (g *Gauge) Sample(sample float64, sampleRate float32) {
	g.value = sample
}
230352
func (s *adaptiveSampler) Sample() bool {
	// adjust sampling rate whenever sample size is reached.
	var currentRate int
	if atomic.AddUint32(&s.counter, 1) == s.sampleSize { // exact match prevents
		atomic.StoreUint32(&s.counter, 0) // race is ok
		s.Lock()
		{
			d := time.Since(s.start).Seconds()
			r := float64(s.sampleSize) / d
			currentRate = int((float64(s.maxSamplingRate) * adaptiveUpperBoundFloat) / r)
			if currentRate > adaptiveUpperBoundInt {
				currentRate = adaptiveUpperBoundInt
			} else if currentRate < 1 {
				currentRate = 1
			}
			s.start = time.Now()
		}
		s.Unlock()
		atomic.StoreInt64(&s.lastRate, int64(currentRate))
	} else {
		currentRate = int(atomic.LoadInt64(&s.lastRate))
	}

	// currentRate is never zero.
	return currentRate == adaptiveUpperBoundInt || rand.Intn(adaptiveUpperBoundInt) < currentRate
}
617349
func (c *FakeSamples) Create(sample *v1alpha1.Sample) (result *v1alpha1.Sample, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewCreateAction(samplesResource, c.ns, sample), &v1alpha1.Sample{})

	if obj == nil {
		return nil, err
	}
	return obj.(*v1alpha1.Sample), err
}
346993
func (s *UniformSample) Min() int64 {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	return SampleMin(s.values)
}
9692
func (c *samples) Create(sample *v1alpha1.Sample) (result *v1alpha1.Sample, err error) {
	result = &v1alpha1.Sample{}
	err = c.client.Post().
		Namespace(c.ns).
		Resource("samples").
		Body(sample).
		Do().
		Into(result)
	return
}
1312215
func (s Samples) Less(i, j int) bool {
	switch {
	case s[i].Metric.Before(s[j].Metric):
		return true
	case s[j].Metric.Before(s[i].Metric):
		return false
	case s[i].Timestamp.Before(s[j].Timestamp):
		return true
	default:
		return false
	}
}
1030064
func (s Sample) Copy() *Sample {
	xs := make([]float64, len(s.Xs))
	copy(xs, s.Xs)

	weights := []float64(nil)
	if s.Weights != nil {
		weights = make([]float64, len(s.Weights))
		copy(weights, s.Weights)
	}

	return &Sample{xs, weights, s.Sorted}
}
41106
func (samplerOptions) SamplingRefreshInterval(samplingRefreshInterval time.Duration) SamplerOption {
	return func(o *samplerOptions) {
		o.samplingRefreshInterval = samplingRefreshInterval
	}
}
1075853
func (g *Gain) Stream(samples [][2]float64) (n int, ok bool) {
	n, ok = g.Streamer.Stream(samples)
	for i := range samples[:n] {
		samples[i][0] *= 1 + g.Gain
		samples[i][1] *= 1 + g.Gain
	}
	return n, ok
}
1070418
func (s Sample) Bounds() (min float64, max float64) {
	if len(s.Xs) == 0 || (!s.Sorted && s.Weights == nil) {
		return Bounds(s.Xs)
	}

	if s.Sorted {
		if s.Weights == nil {
			return s.Xs[0], s.Xs[len(s.Xs)-1]
		}
		min, max = math.NaN(), math.NaN()
		for i, w := range s.Weights {
			if w != 0 {
				min = s.Xs[i]
				break
			}
		}
		if math.IsNaN(min) {
			return
		}
		for i := range s.Weights {
			if s.Weights[len(s.Weights)-i-1] != 0 {
				max = s.Xs[len(s.Weights)-i-1]
				break
			}
		}
	} else {
		min, max = math.Inf(1), math.Inf(-1)
		for i, x := range s.Xs {
			w := s.Weights[i]
			if x < min && w != 0 {
				min = x
			}
			if x > max && w != 0 {
				max = x
			}
		}
		if math.IsInf(min, 0) {
			min, max = math.NaN(), math.NaN()
		}
	}
	return
}
795802
func SampleEvery(stats Stats, t time.Duration) {
	c := time.Tick(t)
	for _ = range c {
		r := newRuntimeSample()
		r.drain(stats)
	}
}
897810
func (sample *Sample) key() sampleKey {
	ids := make([]string, len(sample.Location))
	for i, l := range sample.Location {
		ids[i] = strconv.FormatUint(l.ID, 16)
	}

	labels := make([]string, 0, len(sample.Label))
	for k, v := range sample.Label {
		labels = append(labels, fmt.Sprintf("%q%q", k, v))
	}
	sort.Strings(labels)

	numlabels := make([]string, 0, len(sample.NumLabel))
	for k, v := range sample.NumLabel {
		numlabels = append(numlabels, fmt.Sprintf("%q%x%x", k, v, sample.NumUnit[k]))
	}
	sort.Strings(numlabels)

	return sampleKey{
		strings.Join(ids, "|"),
		strings.Join(labels, ""),
		strings.Join(numlabels, ""),
	}
}
786153
func (c *FakeSamples) Get(name string, options v1.GetOptions) (result *v1alpha1.Sample, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewGetAction(samplesResource, c.ns, name), &v1alpha1.Sample{})

	if obj == nil {
		return nil, err
	}
	return obj.(*v1alpha1.Sample), err
}
1140115
func (h FrameHeader) Samples() int {
	if len(h) < 4 {
		return 0
	}
	ftype, ok := samplesPerFrame[h.Version()]
	if !ok {
		return 0
	}
	return ftype[h.Layer()]
}
1133780
func sampleFormat(p *profile.Profile, sampleIndex string, mean bool) (value, meanDiv sampleValueFunc, v *profile.ValueType, err error) {
	if len(p.SampleType) == 0 {
		return nil, nil, nil, fmt.Errorf("profile has no samples")
	}
	index, err := p.SampleIndexByName(sampleIndex)
	if err != nil {
		return nil, nil, nil, err
	}
	value = valueExtractor(index)
	if mean {
		meanDiv = valueExtractor(0)
	}
	v = p.SampleType[index]
	return
}
1244708
func SampleMax(values []int64) int64 {
	if 0 == len(values) {
		return 0
	}
	var max int64 = math.MinInt64
	for _, v := range values {
		if max < v {
			max = v
		}
	}
	return max
}
873172
func (s *Sample) Sort() *Sample {
	if s.Sorted || sort.Float64sAreSorted(s.Xs) {
		// All set
	} else if s.Weights == nil {
		sort.Float64s(s.Xs)
	} else {
		sort.Sort(&sampleSorter{s.Xs, s.Weights})
	}
	s.Sorted = true
	return s
}