# Buggy code
def __add__(self, other):
    from .diag_lazy_tensor import DiagLazyTensor
    from .added_diag_lazy_tensor import AddedDiagLazyTensor

    if isinstance(other, ZeroLazyTensor):
        return self
    elif isinstance(other, DiagLazyTensor):
        return AddedDiagLazyTensor(self, other)
    elif isinstance(other, SumLazyTensor):
        return SumLazyTensor(*(list(self.lazy_tensors) + list(other.lazy_tensors)))
    elif isinstance(other, LazyTensor):
        return SumLazyTensor(*(list(self.lazy_tensors) + [other]))
    elif isinstance(other, Tensor):
        # get broadcast shape, assuming mul broadcasting the same as add broadcasting
        broadcasted_shape = _mul_broadcast_shape(self.shape, other.shape)

        # lazify + broadcast other
        broadcasted_other = lazify(other.expand(broadcasted_shape))

        # update the lazy tensors' shape as well
        if broadcasted_shape != self.shape:
            broadcasted_lts = [
                lt.expand(*broadcasted_shape, 1).squeeze(-1).transpose(-1, -2)
                for lt in self.lazy_tensors
            ]
        else:
            broadcasted_lts = list(self.lazy_tensors)

        return SumLazyTensor(*(broadcasted_lts + [broadcasted_other]))
    else:
        raise AttributeError("other must be a LazyTensor")


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-16-0d626e17adaf> in <module>
----> 1 cmtlt + torch.randn(100, 100)

~/Documents/GitHub/gpytorch/gpytorch/lazy/lazy_tensor.py in __add__(self, other)
1625             other = lazify(other)
1626             shape = _mul_broadcast_shape(self.shape, other.shape)
-> 1627             return SumLazyTensor(self.expand(shape), other.expand(shape))
1628         else:
1629             return SumLazyTensor(self, other)

~/Documents/GitHub/gpytorch/gpytorch/lazy/lazy_tensor.py in expand(self, *sizes)
857             raise RuntimeError("Invalid arguments {} to expand.".format(sizes))
858
--> 859         res = self._expand_batch(batch_shape=shape[:-2])
860         return res
861

~/Documents/GitHub/gpytorch/gpytorch/lazy/constant_mul_lazy_tensor.py in _expand_batch(self, batch_shape)
70     def _expand_batch(self, batch_shape):
---> 71         return self.__class__(self.base_lazy_tensor._expand_batch(batch_shape), self._constant.expand(*batch_shape))
72
73     def _get_indices(self, row_index, col_index, *batch_indices):

TypeError: expand() missing 1 required positional arguments: "size"

# Fixed code
def __add__(self, other):
    from .diag_lazy_tensor import DiagLazyTensor
    from .added_diag_lazy_tensor import AddedDiagLazyTensor

    if isinstance(other, ZeroLazyTensor):
        return self
    elif isinstance(other, DiagLazyTensor):
        return AddedDiagLazyTensor(self, other)
    elif isinstance(other, SumLazyTensor):
        return SumLazyTensor(*(list(self.lazy_tensors) + list(other.lazy_tensors)))
    elif isinstance(other, LazyTensor):
        return SumLazyTensor(*(list(self.lazy_tensors) + [other]))
    elif isinstance(other, Tensor):
        # get broadcast shape, assuming mul broadcasting the same as add broadcasting
        broadcasted_shape = _mul_broadcast_shape(self.shape, other.shape)

        # lazify + broadcast other
        broadcasted_other = lazify(other.expand(broadcasted_shape))

        # update the lazy tensors' shape as well
        new_self = (
            self
            if broadcasted_shape == self.shape
            else self._expand_batch(broadcasted_shape[:-2])
        )

        return SumLazyTensor(*(list(new_self.lazy_tensors) + [broadcasted_other]))
    else:
        raise AttributeError("other must be a LazyTensor")