Hi Hdk!



 Hdk:

I want to do elementwise multiplication of each block of (3,3) with y, so that the resultant tensor would have size same as x.


Here’s a scheme that involves creating an auxiliary block matrix:
>>> x = torch.ones (9, 9)
>>> y = torch.randn (3, 3)
>>> block_prod = (x.unsqueeze (0).unsqueeze (0) * torch.nn.functional.interpolate (y.unsqueeze (0).unsqueeze (0), 9)).squeeze()
>>> print (y)
tensor([[ 0.6211, -0.8269,  0.1364],
        [-0.0908, -1.8126, -0.3683],
        [-1.2883, -0.7424, -1.0893]])
>>> print (block_prod)
tensor([[ 0.6211,  0.6211,  0.6211, -0.8269, -0.8269, -0.8269,  0.1364,  0.1364,
          0.1364],
        [ 0.6211,  0.6211,  0.6211, -0.8269, -0.8269, -0.8269,  0.1364,  0.1364,
          0.1364],
        [ 0.6211,  0.6211,  0.6211, -0.8269, -0.8269, -0.8269,  0.1364,  0.1364,
          0.1364],
        [-0.0908, -0.0908, -0.0908, -1.8126, -1.8126, -1.8126, -0.3683, -0.3683,
         -0.3683],
        [-0.0908, -0.0908, -0.0908, -1.8126, -1.8126, -1.8126, -0.3683, -0.3683,
         -0.3683],
        [-0.0908, -0.0908, -0.0908, -1.8126, -1.8126, -1.8126, -0.3683, -0.3683,
         -0.3683],
        [-1.2883, -1.2883, -1.2883, -0.7424, -0.7424, -0.7424, -1.0893, -1.0893,
         -1.0893],
        [-1.2883, -1.2883, -1.2883, -0.7424, -0.7424, -0.7424, -1.0893, -1.0893,
         -1.0893],
        [-1.2883, -1.2883, -1.2883, -0.7424, -0.7424, -0.7424, -1.0893, -1.0893,
         -1.0893]])

(You don’t actually need to unsqueeze() x, as the element-wise
multiplication (*) will broadcast.  I just put that in to make it a little more
clear what is going on.)
Best.
K. Frank