d71bc3c8b533c319e49cf6b347d13c48c925ea93,gpytorch/utils/getitem.py,,_compute_getitem_size,#Any#Any#,10

Before Change


    final_shape = []
    first_tensor_idx = None
    tensor_idx_shape = None
    continuous_tensor_index = True
    slice_after_tensor_idx = False

    for i, (size, idx) in enumerate(zip(obj.shape, indices)):
        // Handle slice: that dimension gets downsized
        if isinstance(idx, slice):
            if idx == _noop_index:
                final_shape.append(size)
            else:
                final_shape.append(len(range(*idx.indices(size))))

            // If we don"t have a continuous set of tensor indices, then the tensor indexed part
            // goes to the front
            if first_tensor_idx is not None:
                slice_after_tensor_idx = True

        // Handle int: we "lose" that dimension
        elif isinstance(idx, int):
            if settings.debug.on():
                try:
                    range(size)[idx]
                except IndexError:
                    raise IndexError(
                        "index element {} ({}) is invalid: out of range for obj of size "
                        "{}.".format(i, idx, obj.shape)
                    )

        // Handle tensor index - this one is complicated
        elif torch.is_tensor(idx):
            if tensor_idx_shape is None:
                tensor_idx_shape = idx.numel()
                first_tensor_idx = len(final_shape)
                final_shape.append(tensor_idx_shape)

            // If we don"t have a continuous set of tensor indices, then the tensor indexed part
            // goes to the front
            elif slice_after_tensor_idx:
                continuous_tensor_index = False

            else:
                if settings.debug.on():
                    if idx.numel() != tensor_idx_shape:
                        raise IndexError(
                            "index element {} is an invalid size: expected tensor indices of size {}, got "
                            "{}.".format(i, tensor_idx_shape, idx.numel())
                        )

    // If we don"t have a continuous set of tensor indices, then the tensor indexed part
    // goes to the front
    if not continuous_tensor_index:
        del final_shape[first_tensor_idx]
        final_shape.insert(0, tensor_idx_shape)

    return torch.Size(final_shape)

After Change


    // If we don"t have a continuous set of tensor indices, then the tensor indexed part
    // goes to the front
    if tensor_idx is not None:
        final_shape = final_shape[:tensor_idx] + list(tensor_idx_shape) + final_shape[tensor_idx:]

    return torch.Size(final_shape)

Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 5

Instances


Project Name: cornellius-gp/gpytorch
Commit Name: d71bc3c8b533c319e49cf6b347d13c48c925ea93
Time: 2019-03-18
Author: gpleiss@gmail.com
File Name: gpytorch/utils/getitem.py
Class Name:
Method Name: _compute_getitem_size


Project Name: pandas-dev/pandas
Commit Name: 412554b2f06f3782c9336f5a4dfc5bb890219afd
Time: 2021-01-21
Author: jbrockmendel@gmail.com
File Name: pandas/tests/indexes/datetimes/test_insert.py
Class Name: TestInsert
Method Name: test_insert_invalid_na


Project Name: pandas-dev/pandas
Commit Name: 412554b2f06f3782c9336f5a4dfc5bb890219afd
Time: 2021-01-21
Author: jbrockmendel@gmail.com
File Name: pandas/tests/indexes/timedeltas/test_insert.py
Class Name: TestTimedeltaIndexInsert
Method Name: test_insert_invalid_na