From ed36fb862a94ae47f44205fec169461da147d5e3 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Fri, 14 Mar 2014 11:04:47 +0100 Subject: [PATCH] scilab: in doc, add notes on double => int conversion & column major order, change arrays example --- Doc/Manual/Scilab.html | 67 ++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/Doc/Manual/Scilab.html b/Doc/Manual/Scilab.html index 777be9536..01d104e0d 100644 --- a/Doc/Manual/Scilab.html +++ b/Doc/Manual/Scilab.html @@ -764,8 +764,8 @@ The following table give for each C/C++ primitive type the equivalent Scilab typ unsigned intuint32 longdouble or int32 unsigned longuint32 -signed long longnot supported with Scilab 5.x -unsigned long longnot supported with Scilab 5.x +signed long longnot supported in Scilab 5.x +unsigned long longnot supported in Scilab 5.x floatdouble doubledouble char* or char[]string @@ -775,13 +775,16 @@ The following table give for each C/C++ primitive type the equivalent Scilab typ

Notes:

@@ -802,34 +805,52 @@ Typemaps are available by default for arrays. Primitive type arrays are automati

-The type mappings used for arrays is the same for primtive types, described here. -It means that, if needed, a Scilab double vector is converted in input into a C int array. -And this C int array is automatically converted in output to a Scilab double vector. +In input, the matrix is usually one-dimensional (it can be either a row or column vector). But it can be also a two-dimensional matrix. +Warning: in Scilab, the values are column-major orderered, unlike in C, in which there are row-major ordered.

-This example illustrates this:

+The type mappings used for arrays is the same for primtive types, described here. +It means that, if needed, a Scilab double vector is converted in input into a C int array. +And this C int array is automatically converted in output to a Scilab double vector. +Note that unlike scalars, no control is done for arrays when a double is converted to integer. +

+ +

+

+ +

+This example illustrates all this:

 %module example
 
+%#include <stdio.h>
+
 %inline %{
 
-int sumArray(int values[], int len) {
-  int s = 0;
+void printArray(int values[], int len) {
   int i = 0;
-  for (i=0; i < len; i++)
-    s += values[i];
-  return s;
+  for (i = 0; i < len; i++) {
+    printf("%s %d %s", i==0?"[":"", values[i], i==len-1?"]\n":"");
+  }
+}
 %}
 

---> sum([1. 2. 3. 5.], 4);
- ans  =
+--> printArray([0 1 2 3], 4)
+[ 0  1  2  3 ]
 
-    11.
+-->printArray([0.2; -1.8; 2; 3.7], 4)
+[ 0  -1  2  3 ]
+
+--> printArray([0 1; 2 3], 4)
+[ 0  2  1  3 ]
+
+--> printArray([0; 1; 2; 3], 4)
+[ 0  1  2  3 ]
 

@@ -986,6 +1007,14 @@ void absolute(int *matrix, int matrixNbRow, int matrixNbCol,

+

+The remarks made for arrays remain here: +

+

+

37.5 Module