f41ae3bce45a4cf2f101d610704838d335b1f586,tensorly/backend/pytorch_backend.py,,where,#Any#Any#Any#,101

Before Change


    try:
        out = torch.zeros_like(x)
    except AttributeError:
        out = x.new(x.size()).zero_()

    // unroll inputs and outputs for ease of iteration through elements
    condition_ = condition.view(N)
    x_ = x.view(N)

After Change


def where(condition, x, y):
    assert condition.shape == x.shape == y.shape, "Dimension mismatch"
    result = zeros_like(condition, **context(x))
    result[condition] = x
    result[~condition] = y
    return result

def all(tensor):
    return torch.sum(tensor != 0)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 4

Instances


Project Name: tensorly/tensorly
Commit Name: f41ae3bce45a4cf2f101d610704838d335b1f586
Time: 2018-02-03
Author: csw@amazon.com
File Name: tensorly/backend/pytorch_backend.py
Class Name:
Method Name: where


Project Name: elbayadm/attn2d
Commit Name: 38e82904d8149b27a9961539b204544aa354abb3
Time: 2019-05-30
Author: myleott@fb.com
File Name: fairseq/optim/nag.py
Class Name: NAG
Method Name: step


Project Name: tensorly/tensorly
Commit Name: f41ae3bce45a4cf2f101d610704838d335b1f586
Time: 2018-02-03
Author: csw@amazon.com
File Name: tensorly/backend/pytorch_backend.py
Class Name:
Method Name: where