I am trying to build a CNN
using Torch 7
. I am very new to Lua
. I was trying to follow this link. I encountered something called setmetatable
in the following code block:
setmetatable(train_set,
{
__index = function(t, i)
return {t.data[i], t.label[i]}
end
});
I understand that the second argument acts as the metatable for the table train_set
.
1) Is t
the metatable or is t
just another name for train_set
?
2) Whenever a function is used against __index
, does the interpreter assume the first argument (t
) to be a table (or metatable, depending on answer to first question)? And is the second argument always the key
or index
?
3) My understanding is that if I use train_set.data[1]
, it will invoke the __index
. The answer here says that __index
is invoked when key
does not exist in the table. But is t.data[1]
same as train_set.data[1]
? If so, how does the interpreter know that?