see https://github.com/torch/nn/blob/master/generic/tanh.c
for example,
static int nn_(tanh_updateoutput)(lua_state *l) { thtensor *input = luat_checkudata(l, 2, torch_tensor); thtensor *output = luat_getfieldcheckudata(l, 1, "output", torch_tensor); thtensor_(resizeas)(output, input); if (input->ndimension == 1 || !thtensor_(iscontiguous)(input) || !thtensor_(iscontiguous)(output)) { th_tensor_apply2(real, output, real, input, \ *output_data = tanh(*input_data);); } else { real* ptr_output = thtensor_(data)(output); real* ptr_input = thtensor_(data)(input); long i; #pragma omp parallel private(i) for(i = 0; < thtensor_(nelement)(input); i++) ptr_output[i] = tanh(ptr_input[i]); } return 1; } first, don't know how interpret first line:
static int nn_(tanh_updateoutput)(lua_state *l) what arguments here? tanh_updateoutput refer to? "nn_" have special meaning?
second, "th_tensor_apply2" , "thtensor_(...)" both used don't see defined? there no other includes in file?
nn_ macro. can find definition searching repository "#define nn_"; it's in init.c:
#define nn_(name) th_concat_3(nn_, real, name) you can keep following chain of macro definitions, , you'll end token pasting thing makes nn_(tanh_updateoutput) expand name of function.
(it's weird generic/tanh.c doesn't have includes; generic/tanh.c must included other file. that's unusual .c files.)
Comments
Post a Comment