3

I see functions like this throughout the torch library's C code:

long THTensor_(storageOffset)(const THTensor *self)
{
  return self->storageOffset;
}

Is this a preprocessor thing, or something lua specific? The idea, I think has something to do with the fact that storageOffset is a method of sorts on the THTensor "class", but I've never seen this kind of syntax.

1

1 Answer 1

8

It is a preprocessor macro

lib/TH/THTensor.h:
#define THTensor_(NAME)   TH_CONCAT_4(TH,Real,Tensor_,NAME)

which leads to...

lib/TH/THGeneral.h.in:
#define TH_CONCAT_4(x,y,z,w) TH_CONCAT_4_EXPAND(x,y,z,w)

and finally...

lib/TH/THGeneral.h.in:
#define TH_CONCAT_4_EXPAND(x,y,z,w) x ## y ## z ## w

Therefore,

long THTensor_(storageOffset)(const THTensor *self)

ultimately becomes this:

long THRealTensor_storageOffset(const THTensor *self)

Aren't preprocessors just grand ?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.