[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Oct Files Help -- mkoctfile
From: |
John W. Eaton |
Subject: |
Re: Oct Files Help -- mkoctfile |
Date: |
Thu, 10 Jan 2008 14:35:34 -0500 |
On 10-Jan-2008, gOS wrote:
| to figure out if I am calling mxCalcSingleSubscript incorrectly for your mex
| compiler. It does not throw an error, but it returns an incorrect index
| which does not move beyond the first row of the file I'm trying to turn into
| a Cell Array.
|
| Here is a code sample if it helps:
|
| [...]
I checked in the following change to cvs head and the 3.0 branch. I
think mxCalcSingleSubscript should work correctly with this patch.
jwe
src/ChangeLog:
2008-01-10 John W. Eaton <address@hidden>
* mex.cc (calc_single_subscript_internal): New static function.
(mxArray_octave_value::calc_single_subscript): Use it.
(mxArray_matlab::calc_single_subscript): Use it.
Index: src/mex.cc
===================================================================
RCS file: /cvs/octave/src/mex.cc,v
retrieving revision 1.36
diff -u -u -r1.36 mex.cc
--- src/mex.cc 28 Dec 2007 20:56:57 -0000 1.36
+++ src/mex.cc 10 Jan 2008 19:27:17 -0000
@@ -271,6 +271,38 @@
}
};
+static mwIndex
+calc_single_subscript_internal (mwSize ndims, const mwSize *dims,
+ mwSize nsubs, const mwIndex *subs)
+{
+ mwIndex retval = 0;
+
+ switch (nsubs)
+ {
+ case 0:
+ break;
+
+ case 1:
+ retval = subs[0];
+ break;
+
+ default:
+ {
+ // Both nsubs and ndims should be at least 2 here.
+
+ mwSize n = nsubs <= ndims ? nsubs : ndims;
+
+ retval = subs[--n];
+
+ while (--n >= 0)
+ retval = dims[n] * retval + subs[n];
+ }
+ break;
+ }
+
+ return retval;
+}
+
// The object that handles values pass to MEX files from Octave. Some
// methods in this class may set mutate_flag to TRUE to tell the
// mxArray class to convert to the Matlab-style representation and
@@ -605,17 +637,10 @@
mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const
{
- mwIndex retval = 0;
-
// Force ndims, dims to be cached.
get_dimensions ();
- mwIndex n = nsubs <= ndims ? nsubs : ndims;
-
- while (--n > 0)
- retval = retval * dims[n] + subs[n];
-
- return retval;
+ return calc_single_subscript_internal (ndims, dims, nsubs, subs);
}
size_t get_element_size (void) const
@@ -996,14 +1021,7 @@
mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const
{
- mwIndex retval = 0;
-
- mwSize n = nsubs <= ndims ? nsubs : ndims;
-
- while (--n > 0)
- retval = retval * dims[n] + subs[n];
-
- return retval;
+ return calc_single_subscript_internal (ndims, dims, nsubs, subs);
}
size_t get_element_size (void) const
- Oct Files Help -- mkoctfile, gOS, 2008/01/09
- Re: Oct Files Help -- mkoctfile, gOS, 2008/01/09
- Re: Oct Files Help -- mkoctfile, gOS, 2008/01/09
- Re: Oct Files Help -- mkoctfile, Tatsuro MATSUOKA, 2008/01/09
- Re: Oct Files Help -- mkoctfile, Tatsuro MATSUOKA, 2008/01/10
- Re: Oct Files Help -- mkoctfile, gOS, 2008/01/10
- Re: Oct Files Help -- mkoctfile, John W. Eaton, 2008/01/10
- Re: Oct Files Help -- mkoctfile, gOS, 2008/01/10
- Re: Oct Files Help -- mkoctfile,
John W. Eaton <=
Re: Oct Files Help -- mkoctfile, John W. Eaton, 2008/01/09
Re: Oct Files Help -- mkoctfile, Tatsuro MATSUOKA, 2008/01/09
Re: Oct Files Help -- mkoctfile, Tatsuro MATSUOKA, 2008/01/09
Re: Oct Files Help -- mkoctfile, Tatsuro MATSUOKA, 2008/01/09