I have found a function in the header file, whitch is
TH_API real *THTensor_(data)(const THTensor *self).
But its input is const type,I want to know if I can change the data of THTensor by it? Thanks!
What exactly are you trying to do?
The short answer is yes. It’s returning a real *
and you can do whatever you want to memory addressed by pointers.
Thank you too much for you answer! I want to try to implement my own layer in c interface, so I need to know how to visit tensor’s data in c.But I see that its input is const, I am confused if ifs returning pointer can be changed.
So you mean that I can reallocate the space or change the value in the space whitch is pointed by the pointer?
You can change the value in the space pointed to by the pointer. I wouldn’t recommend doing this directly, though. There are helper methods like THTensor_getNd
(where N
is 1, 2, or 3) and THTensor_setNd
.