Access tensor element in torch c++

Hello,

How do I access tensor element in torch C++ that doesn’t disconnect the graph ? I need to backprop through element access. Is using accessor<> the right way?

thank you!

accessors are not for Autograd but to allow efficient raw memory access, so that doesn’t sound like a good match for what you ask.
Without knowing more (how many elements, what do you want to do with them) it’s hard to tell, but plainly indexing Tensors works well until you hit performance issues. These can occur because indexing will cause the subtensors to be instantiated and connected to the autograd graph, which is a source of overhead.

Best regards

Thomas

Best regards

Thomas