a7d92f7020dfe8854430ef13ed2923b2606a6262,torchsample/utils.py,,th_random_choice,#Any#Any#Any#Any#,374

Before Change


    samples : 1-D ndarray, shape (size,)
        The generated random samples
    
    if size is None:
        size = 1

    if isinstance(a, int):
        a = th.arange(0, a)

    if p is None:

After Change


        if replace:
            idx = th.floor(th.rand(n_samples)*a.size(0)).long()
        else:
            idx = th.randperm(len(a))[:n_samples]
    else:
        if abs(1.0-sum(p)) > 1e-3:
            raise ValueError("p must sum to 1.0")
        if not replace:
            raise ValueError("replace must equal true if probabilities given")
        idx_vec = th.cat([th.zeros(round(p[i]*1000))+i for i in range(len(p))])
        idx = (th.floor(th.rand(n_samples)*999)).long()
        idx = idx_vec[idx].long()
    selection = a[idx]
    if n_samples == 1:
        selection = selection[0]
    return selection


def save_transform(file, transform):
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 3

Instances


Project Name: ncullen93/torchsample
Commit Name: a7d92f7020dfe8854430ef13ed2923b2606a6262
Time: 2017-05-11
Author: ncullen.th@dartmouth.edu
File Name: torchsample/utils.py
Class Name:
Method Name: th_random_choice


Project Name: PIQuIL/QuCumber
Commit Name: 2a9426c16412f2adadf5253c0b39ed0e45218bea
Time: 2018-07-30
Author: gtorlai@uwaterloo.ca
File Name: qucumber/quantum_reconstruction.py
Class Name: QuantumReconstruction
Method Name: fit


Project Name: OpenNMT/OpenNMT-py
Commit Name: cc80175c2704c0dbbfe908f6b678c84ef1741a56
Time: 2017-03-22
Author: bryan.mccann.is@gmail.com
File Name: onmt/Dataset.py
Class Name: Dataset
Method Name: shuffle