Inplace operation error

I am taking inplace operation error from this code:

def rotate(origin, point, angle):
“”"
Rotate a point counterclockwise by a given angle around a given origin.

    The angle should be given in radians.
    """
    ox, oy = origin
    px, py = point

    qx = ox + math.cos(angle) * (px - ox) - math.sin(angle) * (py - oy)
    qy = oy + math.sin(angle) * (px - ox) + math.cos(angle) * (py - oy)
    #return torch.cat([qx, qy])
    return [qx, qy]

def rotate_traj_with_target_ped(x_seq, angle, PedsList_seq, lookup_seq):
origin = (0, 0)
vectorized_x_seq = x_seq.clone()
for ind, frame in enumerate(x_seq):
for ped in PedsList_seq[ind]:
point = frame[lookup_seq[ped], 0:2]
vectorized_x_seq[ind][lookup_seq[ped], 0] = rotate(origin, point, angle)[0]
#vectorized_x_seq[ind][lookup_seq[ped], 0] = rotated_points[0]
#vectorized_x_seq[ind][lookup_seq[ped], 1] = rotated_points[1]
#return vectorized_x_seq

I am getting this error the last line of uncommented code.Here is the error:


Even I changed the line like this:

vectorized_x_seq[0][0, 0] = 5]
I am getting exactly same error.Thanks for your helps.

Any help will be really appreciated because it is a bit urgent to me.

I’m not 100%, but I suspect the problem is that x_seq is a Variable, so calling clone still points to the same x_seq.data - which you’re attempting to set in place with the slicing. Therefore, accessing storage shared between x_seq and its clone. See here.