Hi Kof!



 kof123:

I would like to train that tensor but also to have the following constraint:
the tensor sould be symmetric


I would not use a tensor of length 8 and attempt to constrain its first
half to mirror its second.  Just use a tensor of length 4, and use each
of its 4 elements twice in your computations.
Here is an example:
>>> import torch
>>> torch.__version__
'1.7.1'
>>> T = torch.randn (4, requires_grad = True)
>>> v = torch.arange (8).float()
>>> torch.dot (torch.cat ((T, torch.flip (T, (0,)))), v).backward()
>>> T.grad
tensor([7., 7., 7., 7.])

(The business with v and torch.dot() is just to give the example
something to run .backward() on to show that autograd works.)
Best.
K. Frank