def Sample(self):
    sample = self.sample
    state = self.state
    use_lightspeed = False
    if use_lightspeed:  # Do sampling on cpu.
      temp = self.expanded_batch
      state.sum(axis=0, target=self.temp)
      state.div_by_row(self.temp, target=temp)
      probs_cpu = temp.asarray().astype(np.float64)
      numsamples = self.NN.asarray()
      samples_cpu = lightspeed.SampleSoftmax(probs_cpu, numsamples)
      sample.overwrite(samples_cpu.astype(np.float32))
    else:
      if self.proto.hyperparams.adaptive_prior > 0:
        sample.assign(0)
        temp_sample = self.expanded_batch
        numsamples = int(self.proto.hyperparams.adaptive_prior)
        for i in range(numsamples):
          state.perturb_prob_for_softmax_sampling(target=temp_sample)
          temp_sample.choose_max_and_accumulate(sample)
      else:
        NN = self.NN.asarray().reshape(-1)
        numdims, batchsize = self.state.shape
        max_samples = self.big_sample_matrix.shape[1]
        for i in range(batchsize):
          nn = NN[i]
          factor = 1
          if nn > max_samples:
            nn = max_samples
            factor = float(nn) / max_samples
          samples = self.big_sample_matrix.slice(0, nn)
          samples.assign(0)
          samples.add_col_vec(self.state.slice(i, i+1))
          samples.perturb_prob_for_softmax_sampling()
          samples.choose_max(axis=0)
          samples.sum(axis=1, target=sample.slice(i, i+1))
          if factor > 1:
            sample.slice(i, i+1).mult(factor)
dataset/ETHPy150Open nitishsrivastava/deepnet/deepnet/replicated_softmax_layer.py/ReplicatedSoftmaxLayer.Sample/original