def dot(self, y, weights=None):
    """Compute a dot product between two tensors"""
    assert self.size() == y.size(), "Number of elements do not match"
    if weights is not None:
        assert weights.size() == self.size(), "Incorrect number of weights"
        result = self * weights
    else:
        result = self.clone()

    return result.mul(y).sum()