scilab: fix arrays_global (<> => isequal)

This commit is contained in:
Simon Marchetto 2014-03-17 11:57:24 +01:00
commit d1dface31c
4 changed files with 55 additions and 8 deletions

View file

@ -12,7 +12,7 @@ function testArray(arrayName, arraySetFunc, arrayGetFunc, in_values, ..
if type(out_values) <> type(expected_out_values) then
swigtesterror("wrong values type returned from " + arrayName + "_get()");
end
if out_values <> expected_out_values then
if ~isequal(out_values, expected_out_values) then
swigtesterror("wrong values returned from " + arrayName + "_get()");
end
catch
@ -20,8 +20,8 @@ function testArray(arrayName, arraySetFunc, arrayGetFunc, in_values, ..
end
endfunction
m = [10, 20];
um = [-10, 20];
m = [-10, 20];
um = [10, 20];
testArray("array_c", array_c_set, array_c_get, ['ab'], ['ab']);
testArray("array_sc", array_sc_set, array_sc_get, m, m);
testArray("array_sc", array_sc_set, array_sc_get, int8(m), m);
@ -35,7 +35,7 @@ testArray("array_ui", array_ui_set, array_ui_get, uint32(um), uint32(um));
testArray("array_l", array_l_set, array_l_get, m, m);
testArray("array_l", array_l_set, array_l_get, int32(m), m);
testArray("array_ul", array_ul_set, array_ul_get, uint32(um), uint32(um));
testArray("array_f", array_f_set, array_f_get, [-10.5, 20.4], [-10.5, 20.4]);
testArray("array_f", array_f_set, array_f_get, [-2.5, 2.5], [-2.5, 2.5]);
testArray("array_d", array_d_set, array_d_get, [-10.5, 20.4], [-10.5, 20.4]);
if array_const_i_get() <> [10, 20] then swigtesterror(); end

View file

@ -167,8 +167,8 @@
*/
%scilab_asarrayandsize_withcopy(varin, SWIG_SciDoubleOrInt32_AsIntArrayAndSize, long[ANY], int);
%typemap(varout, noblock=1, fragment="SWIG_SciDouble_FromIntArrayAndSize") long[ANY] {
%set_output(SWIG_SciDouble_FromIntArrayAndSize(pvApiCtx, $result, 1, $1_dim0, (const int*) $1));
%typemap(varout, noblock=1, fragment="SWIG_SciDouble_FromLongArrayAndSize") long[ANY] {
%set_output(SWIG_SciDouble_FromLongArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1));
}
%apply SWIGTYPE[] { long[] }; /* long[] variables managed as pointers */
%scilab_asarray_withcopy(in, SWIG_SciDoubleOrInt32_AsIntArrayAndSize, long[], int);
@ -179,8 +179,8 @@
*/
%scilab_asarrayandsize_withcopy(varin, SWIG_SciUint32_AsUnsignedIntArrayAndSize, unsigned long[ANY], unsigned int);
%typemap(varout, noblock=1, fragment="SWIG_SciUint32_AsUnsignedIntArrayAndSize") unsigned long[ANY] {
%set_output(SWIG_SciUint32_FromUnsignedIntArrayAndSize(pvApiCtx, $result, 1, $1_dim0, (unsigned int*) $1));
%typemap(varout, noblock=1, fragment="SWIG_SciUint32_FromUnsignedLongArrayAndSize") unsigned long[ANY] {
%set_output(SWIG_SciUint32_FromUnsignedLongArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1));
}
%apply SWIGTYPE[] { unsigned long[] }; /* long[] variables managed as pointers */
%scilab_asarray_withcopy(in, SWIG_SciUint32_AsUnsignedIntArrayAndSize, unsigned long[], unsigned int);

View file

@ -97,3 +97,27 @@ SWIG_SciDouble_FromLong(void *_pvApiCtx, int _iVarOut, long _lValue, char *_fnam
}
}
%fragment("SWIG_SciDouble_FromLongArrayAndSize", "header") {
SWIGINTERN int
SWIG_SciDouble_FromLongArrayAndSize(void *_pvApiCtx, int _iVarOut, int _iRows, int _iCols, const long *_plData) {
SciErr sciErr;
int i;
double *pdValues = NULL;
pdValues = (double*) malloc(_iRows * _iCols * sizeof(double));
for (i=0; i<_iRows * _iCols; i++) {
pdValues[i] = _plData[i];
}
sciErr = createMatrixOfDouble(_pvApiCtx, SWIG_NbInputArgument(_pvApiCtx) + _iVarOut, _iRows, _iCols, pdValues);
if (sciErr.iErr) {
printError(&sciErr, 0);
free(pdValues);
return SWIG_ERROR;
}
free(pdValues);
return SWIG_OK;
}
}

View file

@ -27,3 +27,26 @@ SWIG_UnsignedInt_FromUnsignedLong(void *_pvApiCtx, int _iVarOut, unsigned long _
return SWIG_From_unsigned_SS_int((unsigned int)_ulValue);
}
}
%fragment("SWIG_SciUint32_FromUnsignedLongArrayAndSize", "header") {
SWIGINTERN int
SWIG_SciUint32_FromUnsignedLongArrayAndSize(void *_pvApiCtx, int _iVarOut, int _iRows, int _iCols, const unsigned long *_pulData) {
SciErr sciErr;
int i;
unsigned int *puiValues = NULL;
puiValues = (unsigned int*) malloc(_iRows * _iCols * sizeof(unsigned int));
for (i=0; i<_iRows * _iCols; i++) {
puiValues[i] = _pulData[i];
}
sciErr = createMatrixOfUnsignedInteger32(_pvApiCtx, SWIG_NbInputArgument(_pvApiCtx) + _iVarOut, _iRows, _iCols, puiValues);
if (sciErr.iErr) {
printError(&sciErr, 0);
free(puiValues);
return SWIG_ERROR;
}
free(puiValues);
return SWIG_OK;
}
}