Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/cwrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonan Collobert <ronan@collobert.com>2012-02-08 22:16:51 +0400
committerRonan Collobert <ronan@collobert.com>2012-02-08 22:16:51 +0400
commitf841f6b4bbbace75763040aca3d4d3ea5a0184f4 (patch)
treebc1c9037c4b525cd9514c344ee61077965cac5b5
parentde2b4eb03f1ad6f9c0a2ed5d4253ff9597ad359f (diff)
more dok
-rw-r--r--dok/index.dok57
1 files changed, 50 insertions, 7 deletions
diff --git a/dok/index.dok b/dok/index.dok
index fa0868f..fc7e9dd 100644
--- a/dok/index.dok
+++ b/dok/index.dok
@@ -131,7 +131,8 @@ in ''interface.argtypes[typename]'' must exist, such that ''CInterface''
knows how to handle the specified argument. A lot of types are already
created by default, but the user can define more if needed, by filling
properly the ''argtypes'' table. See the section [[#CInterface.argtypes]]
-for more details about defined types, and how to define additional ones.
+for more details about defined types, and
+[[#CInterface.userargtypes|how to define additional ones]].
Apart the field ''name'', each list describing an argument can contain several optional fields:
@@ -235,12 +236,9 @@ Forget about all the code generated by the ''CInterface'' until now.
{{anchor:CInterface.argtypes}}
Any ''CInterface'' is initialized with a default ''argtypes'' list, at
-creation. This list tells to ''CInterface'' how to handle type names given to
-the [[#CInterface.wrap|wrap()]] method. The user can add more types to this list, if wanted.
-
-arg.i
-arg.__metatable
-arg.args
+creation. This list tells to ''CInterface'' how to handle type names given
+to the [[#CInterface.wrap|wrap()]] method. The user can add more types to
+this list, if wanted (see [[#CInterface.userargtypes|the next section]]).
==== Standard C types ====
Standard type names include ''unsigned char'', ''char'', ''short'',
@@ -284,3 +282,48 @@ present at call time.
==== Torch Tensor types ====
+''CInterface'' also defines **Torch** tensor types: ''ByteTensor'',
+''CharTensor'', ''ShortTensor'', ''IntTensor'', ''LongTensor'',
+''FloatTensor'' and ''DoubleTensor'', which corresponds to their
+''THByteTensor'', etc... counterparts. All of them assume that the
+[[..:luaT|luaT]] Tensor id (here for ByteTensor)
+<file>
+const void *torch_ByteTensor_id;
+</file>
+is defined beforehand, and properly initialized.
+
+Additionally, if you use C-templating style which is present in the TH library, you might want
+to use the ''Tensor'' typename, which assumes that ''THTensor'' is properly defined, as well as
+the macro ''THTensor_()'' and ''torch_()'' (see the TH library for more details).
+
+Another extra typename of interest is ''IndexTensor'', which corresponds to a ''THLongTensor'' in C. Values in this
+LongTensor will be incremented/decremented when going from/to C/Lua to/from Lua/C.
+
+Tensor typenames ''default'' value in [[#CInterface.wrap|wrap()]] can take take two types:
+ * A boolean. If ''true'', the tensor will be initialized as empty, if not present at the Lua function call
+ * A number (index). If not present at the Lua function call, the tensor will be initialized as //pointing// to the argument at the given index (which must be a tensor of same type!).
+For e.g, the list of arguments:
+<file lua>
+{
+ {name=DoubleTensor, default=3},
+ {name=double, default=1.0},
+ {name=DoubleTensor}
+}
+</file>
+The first two arguments are optional. The first one is a DoubleTensor which
+will point on the last (3rd) argument if not given. The second argument
+will be initialized to ''1.0'' if not provided.
+
+Tensor typenames can also take an additional field ''dim'' (a number) which will force a dimension
+check. E.g.,
+<file lua>
+{name=DoubleTensor, dim=2}
+</file>
+expect a matrix of doubles.
+
+===== Adding Your Own Types =====
+{{anchor:CInterface.userargtypes}}
+
+arg.i
+arg.__metatable
+arg.args