Adds a {@link Sampler} that will get run <b>every time an allocation is performed from Java
code</b>. Use this with <b>extreme</b> judiciousness!

@param sampler The sampler to add.
170214
public static void addSampler(Sampler sampler) {
    synchronized (samplerLock) {
      Sampler[] samplers = additionalSamplers;
      /* create a new list of samplers from the old, adding this sampler */
      if (samplers != null) {
        Sampler[] newSamplers = new Sampler[samplers.length + 1];
        System.arraycopy(samplers, 0, newSamplers, 0, samplers.length);
        newSamplers[samplers.length] = sampler;
        additionalSamplers = newSamplers;
      } else {
        Sampler[] newSamplers = new Sampler[1];
        newSamplers[0] = sampler;
        additionalSamplers = newSamplers;
      }
    }
  }
822121
void sampleReceived(SolverAggregatorInterface aggregator,
			SampleMessage sample) {
		if (!this.sampleQueue.offer(sample) && this.warnBufferFull) {
			log.warn("Unable to insert a sample due to a full buffer.");
		}
	}
1295508
public void setSamples(java.util.Collection<Sample> samples) {
        if (samples == null) {
            this.samples = null;
            return;
        }

        this.samples = new java.util.ArrayList<Sample>(samples);
    }
386863
@Override
    public DataSet sample(int numSamples, org.nd4j.linalg.api.rng.Random rng, boolean withReplacement) {
        Set<Integer> added = new HashSet<>();
        List<DataSet> toMerge = new ArrayList<>();
        boolean terminate = false;
        for (int i = 0; i < numSamples && !terminate; i++) {
            int picked = rng.nextInt(numExamples());
            if (!withReplacement) {
                while (added.contains(picked)) {
                    picked = rng.nextInt(numExamples());
                    if(added.size() == numExamples()){
                        terminate = true;
                        break;
                    }
                }
            }
            added.add(picked);
            toMerge.add(get(picked));
        }
        return DataSet.merge(toMerge);
    }
921656
public <R extends BProgramRunnerListener> R addListener(R aListener) {
        listeners.add(aListener);
        return aListener;
    }
774762
@Override
  public final void sample()
  {
    long count = _count.get();
    long lastCount = _lastCount.getAndSet(count);
    
    _value = count - lastCount;
  }
1146290
def sample(self, n_to_sample, **kwargs):
        
        n_to_sample = verify_positive(int(n_to_sample))

        n_remaining = self._max_iter - self.t_

        if n_remaining == 0:
            if (not self.replace) and (self._n_items == self._max_iter):
                raise Exception("All items have already been sampled")
            else:
                raise Exception("No more space available to continue sampling. "
                                "Consider re-initialising with a larger value "
                                "of max_iter.")

        if n_to_sample > n_remaining:
            warnings.warn("Space only remains for {} more iteration(s). "
                          "Setting n_to_sample = {}.".format(n_remaining, \
                          n_remaining))
            n_to_sample = n_remaining

        for _ in range(n_to_sample):
            self._iterate(**kwargs)
1079250
def set_sampler_info(self, sample):
        
        if sample.getSampler() and sample.getDateSampled():
            # Sampler and Date Sampled already set. This is correct
            return True
        sampler = self.get_form_value("Sampler", sample, sample.getSampler())
        sampled = self.get_form_value("getDateSampled", sample,
                                      sample.getDateSampled())
        if not all([sampler, sampled]):
            return False
        sample.setSampler(sampler)
        sample.setDateSampled(DateTime(sampled))
        return True
930824
public void add(final Class<?> clazz) {
		if (this.clazzes.contains(clazz)) {
			throw new IllegalArgumentException(
					"Only one class-instance per benchmark allowed");
		} else {
			this.clazzes.add(clazz);
		}
	}
748712
public synchronized SamplerResult<T> finishSampling(int count)
    {
        List<Counter<T>> results = Collections.EMPTY_LIST;
        long cardinality = 0;
        if (enabled)
        {
            enabled = false;
            results = summary.topK(count);
            cardinality = hll.cardinality();
        }
        return new SamplerResult<T>(results, cardinality);
    }
1050616
def add_sample(self, name, labels, value, timestamp=None, exemplar=None):
        """"""
        self.samples.append(Sample(name, labels, value, timestamp, exemplar))
1023434
public boolean sendSample(SampleMessage sampleMessage) {
    if (!this.canSendSamples) {
      log.warn("Cannot send samples.");
      return false;
    }

    if (this.session.getScheduledWriteMessages() > this.maxOutstandingSamples) {
      log.warn("Buffer full, cannot send sample.");
      return false;
    }
    this.session.write(sampleMessage);
    return true;
  }
680321
@Override
  public final void sample()
  {
    synchronized (_lock) {
      long count = _count.get();
      long lastCount = _lastAvgCount;
      _lastAvgCount = count;

      long sum = _sum.get();
      double lastSum = _lastAvgSum;
      _lastAvgSum = sum;

      if (count == lastCount)
        _value = 0;
      else
        _value = _scale * (sum - lastSum) / (double) (count - lastCount);
    }
  }
1358405
public void submit(final Collection<Sample> samples) {
        for (final SampleProcessor processor : m_processors) {
            m_executor.execute(new Runnable() {

                @Override
                public void run() {
                    processor.submit(samples);
                }
            });
        }
    }
294024
@Override
	public Iterator<T> sample(final Iterator<T> input) {
		if (fraction == 0) {
			return emptyIterable;
		}

		return new SampledIterator<T>() {
			T currentElement;
			int currentCount = 0;

			@Override
			public boolean hasNext() {
				if (currentCount > 0) {
					return true;
				} else {
					samplingProcess();
					if (currentCount > 0) {
						return true;
					} else {
						return false;
					}
				}
			}

			@Override
			public T next() {
				if (currentCount <= 0) {
					samplingProcess();
				}
				currentCount--;
				return currentElement;
			}

			public int poisson_ge1(double p) {
				// sample 'k' from Poisson(p), conditioned to k >= 1.
				double q = Math.pow(Math.E, -p);
				// simulate a poisson trial such that k >= 1.
				double t = q + (1 - q) * random.nextDouble();
				int k = 1;
				// continue standard poisson generation trials.
				t = t * random.nextDouble();
				while (t > q) {
					k++;
					t = t * random.nextDouble();
				}
				return k;
			}

			private void skipGapElements(int num) {
				// skip the elements that occurrence number is zero.
				int elementCount = 0;
				while (input.hasNext() && elementCount < num) {
					currentElement = input.next();
					elementCount++;
				}
			}

			private void samplingProcess() {
				if (fraction <= THRESHOLD) {
					double u = Math.max(random.nextDouble(), EPSILON);
					int gap = (int) (Math.log(u) / -fraction);
					skipGapElements(gap);
					if (input.hasNext()) {
						currentElement = input.next();
						currentCount = poisson_ge1(fraction);
					}
				} else {
					while (input.hasNext()) {
						currentElement = input.next();
						currentCount = poissonDistribution.sample();
						if (currentCount > 0) {
							break;
						}
					}
				}
			}
		};
	}
770567
public double addNewSample(double newSample) {
        final double sample = calculateLog(newSample);
        return Double.longBitsToDouble(valueEncodedAsLong.updateAndGet(value -> {
            return Double.doubleToRawLongBits(sample * newSampleWeight + (1.0 - newSampleWeight) * Double.longBitsToDouble(value));
        }));
    }
348413
public void addExamples(ExampleStatements exampleStatements)
    {
		this.statements.put(exampleStatements.getDatasourceName(), exampleStatements.getClusters());
		if (LOGGER.isDebugEnabled()) {
        	LOGGER.debug("converted json object" + new JSONObject(statements));
        }
    }