From bug-octave-request at bevo dot che dot wisc dot edu Thu Jul 24 15:50:00 2003 Subject: Re: ArrayN.cc bug From: Roderick =?iso-8859-1?q?K=F6hle?= To: bug-octave at bevo dot che dot wisc dot edu, Petter Risholm Date: Thu, 24 Jul 2003 22:57:47 +0200 --Boundary-00=_LhEI/lJKH+1aeMz Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline I once started to work on multidimensional arrays for octave version 2.1.40 and got it pretty much working. I gave up though since I have not been able to patch the changes into later CVS versions. The changes I made might be of some help in your effort to get multidimensional arrays working. While it is won't work to patch my changes into the current CVS tree it might assist you in which part of the source code you have to touch. What was missing is the functionality to delete rows/columns of nd-arrays. I did not do any coding regarding the MArrayN class to do math operations, but just having the container class would be pretty helpful. In this mail I attached two diffs, liboctave.diff is a diff against the directory liboctave. A second diff is a patch against the src directory. The patch against the src directory provides only very basic capability to test the liboctave library. Essentially it provides the capability to create a real valued multidimensional array using a extended zeros(n1, n2, n3, ...) function and do assignments. One difficulty I encountered was to do assignments from/to non-scalar datatypes. Without a solid understanding how to resolve mixed type assignments the integration of multidimensional arrays into octave is somewhat challenging. Regards, Roderick Koehle Am Dienstag, 22. Juli 2003 18:36 schrieb Petter Risholm: > Hi, > > I'm working on implementing multidimensional arrays and found a bug in > ArrayN.cc. > > In both resize functions, old_len is initialized too late and as a result > it gets the value of len and not the old value. To fix it, just make > sure the initialization of old_len takes place before: > Array::rep = new typename Array::ArrayRep(len); > > regards > Petter Risholm > > Octave version: 2.1.50 > > ChangeLog entry: > 2003-07-22 Petter Risholm > > * ArrayN.cc (ArrayN::resize(const Array&, const T&)): > * ArrayN.cc (ArrayN::resize(const Array&)): > old_len was initalized too late. > > > *** ArrayN.cc 2003-07-22 18:08:46.000000000 +0200 > --- ../cvs/octave/liboctave/ArrayN.cc 2003-02-14 08:36:26.000000000 > +0100 > *************** ArrayN::resize (const Array& dim > *** 229,236 **** > if (no_change) > return; > > - int old_len = length (); > - > typename Array::ArrayRep *old_rep = Array::rep; > const T *old_data = data (); > > --- 229,234 ---- > *************** ArrayN::resize (const Array& dim > *** 238,243 **** > --- 236,243 ---- > > Array old_dimensions = dimensions; > > + int old_len = length (); > + > dimensions = dims; > > Array ra_idx (dimensions.length (), 0); > *************** ArrayN::resize (const Array& dim > *** 287,300 **** > typename Array::ArrayRep *old_rep = Array::rep; > const T *old_data = data (); > > - int old_len = length (); > - > int len = get_size (dims); > > Array::rep = new typename Array::ArrayRep (len); > > Array old_dimensions = dimensions; > > dimensions = dims; > > Array ra_idx (dimensions.length (), 0); > --- 287,300 ---- > typename Array::ArrayRep *old_rep = Array::rep; > const T *old_data = data (); > > int len = get_size (dims); > > Array::rep = new typename Array::ArrayRep (len); > > Array old_dimensions = dimensions; > > + int old_len = length (); > + > dimensions = dims; > > Array ra_idx (dimensions.length (), 0); > > > > ------------------------------------------------------------- > Octave is freely available under the terms of the GNU GPL. > > Octave's home on the web: http://www.octave.org > How to fund new projects: http://www.octave.org/funding.html > Subscription information: http://www.octave.org/archive.html > ------------------------------------------------------------- --Boundary-00=_LhEI/lJKH+1aeMz Content-Type: text/x-diff; charset="iso-8859-1"; name="liboctave.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="liboctave.diff" ? octave/liboctave/Array-C.d ? octave/liboctave/Array-b.d ? octave/liboctave/Array-ch.d ? octave/liboctave/Array-d.d ? octave/liboctave/Array-flags.d ? octave/liboctave/Array-i.d ? octave/liboctave/Array-idx-vec.d ? octave/liboctave/Array-s.d ? octave/liboctave/Array-str.d ? octave/liboctave/Array.d ? octave/liboctave/Array2.d ? octave/liboctave/Array3.d ? octave/liboctave/ArrayN.d ? octave/liboctave/Bounds.d ? octave/liboctave/CColVector.d ? octave/liboctave/CDiagMatrix.d ? octave/liboctave/CMatrix.d ? octave/liboctave/CRowVector.d ? octave/liboctave/CmplxAEPBAL.d ? octave/liboctave/CmplxCHOL.d ? octave/liboctave/CmplxDET.d ? octave/liboctave/CmplxHESS.d ? octave/liboctave/CmplxLU.d ? octave/liboctave/CmplxQR.d ? octave/liboctave/CmplxQRP.d ? octave/liboctave/CmplxSCHUR.d ? octave/liboctave/CmplxSVD.d ? octave/liboctave/CollocWt.d ? octave/liboctave/DASPK-opts.h ? octave/liboctave/DASPK.d ? octave/liboctave/DASRT-opts.h ? octave/liboctave/DASRT.d ? octave/liboctave/DASSL-opts.h ? octave/liboctave/DASSL.d ? octave/liboctave/DiagArray2.d ? octave/liboctave/EIG.d ? octave/liboctave/FEGrid.d ? octave/liboctave/LPsolve.d ? octave/liboctave/LSODE-opts.h ? octave/liboctave/LSODE.d ? octave/liboctave/LinConst.d ? octave/liboctave/MArray-C.d ? octave/liboctave/MArray-ch.d ? octave/liboctave/MArray-d.d ? octave/liboctave/MArray-i.d ? octave/liboctave/MArray-misc.d ? octave/liboctave/MArray-s.d ? octave/liboctave/MArray.d ? octave/liboctave/MArray2.d ? octave/liboctave/MDiagArray2.d ? octave/liboctave/Makefile ? octave/liboctave/NLEqn-opts.h ? octave/liboctave/NLEqn.d ? octave/liboctave/ODES.d ? octave/liboctave/ODESSA-opts.h ? octave/liboctave/ODESSA.d ? octave/liboctave/Quad-opts.h ? octave/liboctave/Quad.d ? octave/liboctave/Range.d ? octave/liboctave/base-lu.d ? octave/liboctave/boolMatrix.d ? octave/liboctave/chMatrix.d ? octave/liboctave/cmd-edit.d ? octave/liboctave/cmd-hist.d ? octave/liboctave/dColVector.d ? octave/liboctave/dDiagMatrix.d ? octave/liboctave/dMatrix.d ? octave/liboctave/dRowVector.d ? octave/liboctave/data-conv.d ? octave/liboctave/dbleAEPBAL.d ? octave/liboctave/dbleCHOL.d ? octave/liboctave/dbleDET.d ? octave/liboctave/dbleHESS.d ? octave/liboctave/dbleLU.d ? octave/liboctave/dbleQR.d ? octave/liboctave/dbleQRP.d ? octave/liboctave/dbleSCHUR.d ? octave/liboctave/dbleSVD.d ? octave/liboctave/dir-ops.d ? octave/liboctave/f2c-main.d ? octave/liboctave/file-ops.d ? octave/liboctave/file-stat.d ? octave/liboctave/filemode.d ? octave/liboctave/getopt.d ? octave/liboctave/getopt1.d ? octave/liboctave/glob-match.d ? octave/liboctave/idx-vector.d ? octave/liboctave/lo-cieee.d ? octave/liboctave/lo-cutils.d ? octave/liboctave/lo-ieee.d ? octave/liboctave/lo-mappers.d ? octave/liboctave/lo-specfun.d ? octave/liboctave/lo-sysdep.d ? octave/liboctave/lo-utils.d ? octave/liboctave/mach-info.d ? octave/liboctave/mkdir.d ? octave/liboctave/mx-cdm-cm.d ? octave/liboctave/mx-cdm-cs.d ? octave/liboctave/mx-cdm-dm.d ? octave/liboctave/mx-cdm-m.d ? octave/liboctave/mx-cdm-s.d ? octave/liboctave/mx-cm-cdm.d ? octave/liboctave/mx-cm-dm.d ? octave/liboctave/mx-cm-m.d ? octave/liboctave/mx-cm-s.d ? octave/liboctave/mx-cs-cdm.d ? octave/liboctave/mx-cs-dm.d ? octave/liboctave/mx-cs-m.d ? octave/liboctave/mx-dm-cdm.d ? octave/liboctave/mx-dm-cm.d ? octave/liboctave/mx-dm-cs.d ? octave/liboctave/mx-dm-m.d ? octave/liboctave/mx-dm-s.d ? octave/liboctave/mx-m-cdm.d ? octave/liboctave/mx-m-cm.d ? octave/liboctave/mx-m-cs.d ? octave/liboctave/mx-m-dm.d ? octave/liboctave/mx-s-cdm.d ? octave/liboctave/mx-s-cm.d ? octave/liboctave/mx-s-dm.d ? octave/liboctave/oct-alloc.d ? octave/liboctave/oct-env.d ? octave/liboctave/oct-fftw.d ? octave/liboctave/oct-getopt.d ? octave/liboctave/oct-group.d ? octave/liboctave/oct-kpse.d ? octave/liboctave/oct-passwd.d ? octave/liboctave/oct-rl-edit.d ? octave/liboctave/oct-rl-hist.d ? octave/liboctave/oct-shlib.d ? octave/liboctave/oct-syscalls.d ? octave/liboctave/oct-time.d ? octave/liboctave/pathsearch.d ? octave/liboctave/pic ? octave/liboctave/prog-args.d ? octave/liboctave/rename.d ? octave/liboctave/rmdir.d ? octave/liboctave/stamp-prereq ? octave/liboctave/stmp-pic ? octave/liboctave/str-vec.d ? octave/liboctave/strftime.d ? octave/liboctave/strptime.d ? octave/liboctave/tempnam.d ? octave/liboctave/tempname.d ? octave/liboctave/vx-ccv-cv.d ? octave/liboctave/vx-ccv-s.d ? octave/liboctave/vx-crv-rv.d ? octave/liboctave/vx-crv-s.d ? octave/liboctave/vx-cs-cv.d ? octave/liboctave/vx-cs-rv.d ? octave/liboctave/vx-cv-ccv.d ? octave/liboctave/vx-cv-cs.d ? octave/liboctave/vx-rv-crv.d ? octave/liboctave/vx-rv-cs.d ? octave/liboctave/vx-s-ccv.d ? octave/liboctave/vx-s-crv.d Index: octave/liboctave/Array-d.cc =================================================================== RCS file: /cvs/octave/liboctave/Array-d.cc,v retrieving revision 1.14 diff -r1.14 Array-d.cc 62a63,73 > > template int assign (ArrayN&, const ArrayN&); > template int assign (ArrayN&, const ArrayN&); > template int assign (ArrayN&, const ArrayN&); > template int assign (ArrayN&, const ArrayN&); > > template int assign (ArrayN&, const ArrayN&, const double&); > template int assign (ArrayN&, const ArrayN&, const double&); > template int assign (ArrayN&, const ArrayN&, const double&); > template int assign (ArrayN&, const ArrayN&, const double&); > Index: octave/liboctave/ArrayN-idx.h =================================================================== RCS file: /cvs/octave/liboctave/ArrayN-idx.h,v retrieving revision 1.4 diff -r1.4 ArrayN-idx.h 124c124 < for (int i = 0; i < n; i++) --- > if (n) 126,129c126,132 < if (idx(i).orig_empty ()) < { < retval = true; < break; --- > for (int i = 0; i < n; i++) > { > if (idx(i).orig_empty ()) > { > retval = true; > break; > } 131a135,138 > else > { > retval = true; > } 143c150 < for (int i = 0; i < n; i++) --- > if (n) 145c152,154 < if (frozen_lengths(i) == 0) --- > for (int i = 0; i < n; i++) > { > if (frozen_lengths(i) == 0) 149a159,187 > } > } > else > retval = true; > > return retval; > } > > static inline bool > is_scalar (const Array& dim) > { > bool retval = true; > > int n = dim.length (); > > if (n==0) > { > retval = false; > } > else > { > for (int i = 0; i < n; i++) > { > if (dim(i) != 1) > { > retval = false; > break; > } > } 187a226,268 > static inline bool > index_in_bounds (const Array& arr_idx, const Array& dimensions) > { > bool retval = true; > > int n = arr_idx.length (); > > if (n == dimensions.length ()) > { > for (int i = 0; i < n; i++) > { > if (arr_idx(i) < 0 || arr_idx(i) >= dimensions (i)) > { > retval = false; > break; > } > } > } > else > retval = false; > > return retval; > } > > static inline void > increment_index (Array& arr_idx, const Array& dimensions) > { > arr_idx(0)++; > > int n = arr_idx.length () - 1; > > for (int i = 0; i < n; i++) > { > if (arr_idx(i) < dimensions(i)) > break; > else > { > arr_idx(i) = 0; > arr_idx(i+1)++; > } > } > } > 196c277 < retval(i) = idx(result_idx(i)); --- > retval(i) = idx(i).elem(result_idx(i)); 227c308 < else if (all_colon_equiv (arr_idx, frozen_lengths)) --- > else if (all_colon_equiv (arr_idx, dimensions)) 233d313 < #if 0 236c316 < int n = Array::get_size (frozen_lengths); --- > int n = ArrayN::get_size (frozen_lengths); 238a319 > Array elt_idx; 242c323 < Array elt_idx = get_elt_idx (result_idx); --- > elt_idx = get_elt_idx (arr_idx, result_idx); 244,245c325,326 < if (elt_idx > orig_len) < retval.elem (result_idx) = resize_fill_value; --- > if (index_in_bounds(elt_idx, dimensions)) > retval.checkelem (result_idx) = checkelem (elt_idx); 247c328 < retval.elem (result_idx) = elem (elt_idx); --- > retval.checkelem (result_idx) = resize_fill_value; 251d331 < #endif 265c345 < assign (ArrayN&, const ArrayN&, const LT&) --- > assign (ArrayN& lhs, const ArrayN& rhs, const LT& resize_fill_value) 267,268c347,443 < assert (0); < return 0; --- > int retval = 1; > > int n_idx = lhs.index_count (); > > Array lhs_dims = lhs.dimensions; > Array rhs_dims = rhs.dimensions; > > idx_vector *tmp = lhs.get_idx (); > > Array idx(n_idx); > > for (int i=0; i idx(i) = tmp[i]; > > > Array frozen_len = freeze (idx, lhs_dims, liboctave_rre_flag); > > for (int i=0; i idx(i) = tmp[i]; > > bool lhs_is_empty = any_zero_len (lhs_dims); > bool lhs_is_scalar= is_scalar (lhs_dims); > bool rhs_is_empty = any_zero_len (rhs_dims); > bool rhs_is_scalar= is_scalar (rhs_dims); > bool idx_is_empty = any_zero_len (frozen_len); > > if (rhs_is_empty) > { > // row/column deletion > > (*current_liboctave_error_handler) > ("column deletion for nd-arrays not implemented yet"); > retval = 0; > } > else if (rhs_is_scalar) > { > // scalar to matrix assignment > > int n = ArrayN::get_size (frozen_len); > > Array result_idx (lhs_dims.length (), 0); > Array elt_idx; > > RT scalar = *(rhs.data ()); // XXX FIXME XXX > > for (int i = 0; i < n; i++) > { > elt_idx = get_elt_idx (idx, result_idx); > > if (index_in_bounds(elt_idx, lhs_dims)) > lhs.checkelem (elt_idx) = scalar; > else > lhs.checkelem (elt_idx) = resize_fill_value; > > increment_index (result_idx, frozen_len); > } > } > else if (all_colon_equiv (idx, lhs_dims)) > { > // matrix to matrix assignment > > int n = ArrayN::get_size (frozen_len); > > Array result_idx (lhs_dims.length (), 0); > Array elt_idx; > > for (int i = 0; i < n; i++) > { > elt_idx = get_elt_idx (idx, result_idx); > > if (index_in_bounds(elt_idx, lhs_dims)) > lhs.checkelem (elt_idx) = rhs.checkelem(elt_idx); > else > lhs.checkelem (elt_idx) = resize_fill_value; > > increment_index (result_idx, frozen_len); > } > } > else if (idx_is_empty) > { > // assignment to matrix with at one or more empty indices > > if (!rhs_is_empty || !rhs_is_scalar) > { > (*current_liboctave_error_handler) > ("A([], []) = X: X must be an empty matrix or a scalar"); > retval = 0; > } > } > else if (lhs_dims.length() != rhs_dims.length()) > { > (*current_liboctave_error_handler) > ("A(I) = X: X must be a scalar or a matrix with the same size as I"); > retval = 0; > } > > return retval; Index: octave/liboctave/ArrayN.cc =================================================================== RCS file: /cvs/octave/liboctave/ArrayN.cc,v retrieving revision 1.9 diff -r1.9 ArrayN.cc 159,201d158 < static inline bool < index_in_bounds (const Array& arr_idx, const Array& dimensions) < { < bool retval = true; < < int n = arr_idx.length (); < < if (n == dimensions.length ()) < { < for (int i = 0; i < n; i++) < { < if (arr_idx(i) < 0 || arr_idx(i) >= dimensions (i)) < { < retval = false; < break; < } < } < } < else < retval = false; < < return retval; < } < < static inline void < increment_index (Array& arr_idx, const Array& dimensions) < { < arr_idx(0)++; < < int n = arr_idx.length () - 1; < < for (int i = 0; i < n; i++) < { < if (arr_idx(i) < dimensions(i)) < break; < else < { < arr_idx(i) = 0; < arr_idx(i+1)++; < } < } < } < 207a165,180 > // first decide what to do if the dimension changes > if (n != dimensions.length()) { > if (dimensions.length()==0) { > dimensions = dims; > set_max_indices(n); > Array::resize( (int) get_size(dims) ); > > return; > } > > (*current_liboctave_error_handler) > ("can't resize arrays of different dimension"); > return; > } > > // now take care of size changes 246a220,221 > std::cout << '[' << i << "] "; > 361c336 < os << n_dims << "-dimensional array ("; --- > os << n_dims << "-dimensional array"; 363,365c338,345 < for (int i = 0; i < n_dims - 1; i++) < os << dims(i) << "x"; < os << dims(n_dims-1) << ")\n\n"; --- > if (n_dims) > { > os << " ("; > for (int i = 0; i < n_dims - 1; i++) > os << dims(i) << "x"; > os << dims(n_dims-1) << ")"; > } > os << "\n\n"; 367c347,349 < os << "data:\n"; --- > if (n_dims) > { > os << "data:\n"; 369c351,352 < int n = ArrayN::get_size (dims); --- > int n = ArrayN::get_size (dims); > Array arr_idx (dims.length (), 0); 371,372c354,362 < // for (int i = 0; i < n; i++) < // os << a.elem (i) << "\n"; --- > for (int i = 0; i < n; i++) { > if (arr_idx(0)) > os << "\t"; > else > os << "\n"; > os << a.elem (arr_idx); > increment_index(arr_idx, dims); > } > } Index: octave/liboctave/ArrayN.h =================================================================== RCS file: /cvs/octave/liboctave/ArrayN.h,v retrieving revision 1.7 diff -r1.7 ArrayN.h 67c67,69 < ArrayN (void) : Array () { } --- > ArrayN (void) : Array () { > set_max_indices (0); > } --Boundary-00=_LhEI/lJKH+1aeMz Content-Type: text/x-diff; charset="iso-8859-1"; name="src.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="src.diff" ? octave/src/Array-oc.d ? octave/src/Array-os.d ? octave/src/Array-sym.d ? octave/src/Array-tc.d ? octave/src/BaseSLList.d ? octave/src/Cell.d ? octave/src/DASPK-opts.cc ? octave/src/DASRT-opts.cc ? octave/src/DASSL-opts.cc ? octave/src/DLList.d ? octave/src/DOCSTRINGS ? octave/src/LSODE-opts.cc ? octave/src/Makefile ? octave/src/Map-fnc.d ? octave/src/Map-oct-obj.d ? octave/src/Map-tc.d ? octave/src/Map.d ? octave/src/NLEqn-opts.cc ? octave/src/ODESSA-opts.cc ? octave/src/Quad-opts.cc ? octave/src/SLList-expr.d ? octave/src/SLList-misc.d ? octave/src/SLList-plot.d ? octave/src/SLList-tc.d ? octave/src/SLList-tm.d ? octave/src/SLList.d ? octave/src/SLStack-i.d ? octave/src/SLStack-ovl.d ? octave/src/SLStack-pc.d ? octave/src/SLStack-str.d ? octave/src/SLStack-sym.d ? octave/src/SLStack-tok.d ? octave/src/SLStack-ue.d ? octave/src/SLStack-ui.d ? octave/src/SLStack.d ? octave/src/Stack.d ? octave/src/airy.oct ? octave/src/balance.d ? octave/src/balance.df ? octave/src/balance.oct ? octave/src/besselh.oct ? octave/src/besseli.oct ? octave/src/besselj.d ? octave/src/besselj.df ? octave/src/besselj.oct ? octave/src/besselk.oct ? octave/src/bessely.oct ? octave/src/betainc.d ? octave/src/betainc.df ? octave/src/betainc.oct ? octave/src/builtins.cc ? octave/src/builtins.d ? octave/src/c-file-ptr-stream.d ? octave/src/chol.d ? octave/src/chol.df ? octave/src/chol.oct ? octave/src/colloc.d ? octave/src/colloc.df ? octave/src/colloc.oct ? octave/src/comment-list.d ? octave/src/cutils.d ? octave/src/daspk.d ? octave/src/daspk.df ? octave/src/daspk.oct ? octave/src/daspk_options.oct ? octave/src/dasrt.d ? octave/src/dasrt.df ? octave/src/dasrt.oct ? octave/src/dasrt_options.oct ? octave/src/dassl.d ? octave/src/dassl.df ? octave/src/dassl.oct ? octave/src/dassl_options.oct ? octave/src/data.d ? octave/src/data.df ? octave/src/debug.d ? octave/src/debug.df ? octave/src/def-files ? octave/src/defaults.d ? octave/src/defaults.df ? octave/src/defaults.h ? octave/src/defun.d ? octave/src/defun.df ? octave/src/det.d ? octave/src/det.df ? octave/src/det.oct ? octave/src/dirfns.d ? octave/src/dirfns.df ? octave/src/doc-files ? octave/src/dynamic-ld.d ? octave/src/dynamic-ld.df ? octave/src/eig.d ? octave/src/eig.df ? octave/src/eig.oct ? octave/src/endgrent.oct ? octave/src/endpwent.oct ? octave/src/error.d ? octave/src/error.df ? octave/src/expm.d ? octave/src/expm.df ? octave/src/expm.oct ? octave/src/fft.d ? octave/src/fft.df ? octave/src/fft.oct ? octave/src/fft2.d ? octave/src/fft2.df ? octave/src/fft2.oct ? octave/src/file-io.d ? octave/src/file-io.df ? octave/src/filter.d ? octave/src/filter.df ? octave/src/filter.oct ? octave/src/find.d ? octave/src/find.df ? octave/src/find.oct ? octave/src/fn-cache.d ? octave/src/fsolve.d ? octave/src/fsolve.df ? octave/src/fsolve.oct ? octave/src/fsolve_options.oct ? octave/src/gammainc.d ? octave/src/gammainc.df ? octave/src/gammainc.oct ? octave/src/gendoc ? octave/src/gendoc.cc ? octave/src/getgrent.d ? octave/src/getgrent.df ? octave/src/getgrent.oct ? octave/src/getgrgid.oct ? octave/src/getgrnam.oct ? octave/src/getpwent.d ? octave/src/getpwent.df ? octave/src/getpwent.oct ? octave/src/getpwnam.oct ? octave/src/getpwuid.oct ? octave/src/getrusage.d ? octave/src/getrusage.df ? octave/src/getrusage.oct ? octave/src/givens.d ? octave/src/givens.df ? octave/src/givens.oct ? octave/src/gmtime.oct ? octave/src/gripes.d ? octave/src/help.d ? octave/src/help.df ? octave/src/hess.d ? octave/src/hess.df ? octave/src/hess.oct ? octave/src/ifft.d ? octave/src/ifft.df ? octave/src/ifft.oct ? octave/src/ifft2.d ? octave/src/ifft2.df ? octave/src/ifft2.oct ? octave/src/input.d ? octave/src/input.df ? octave/src/inv.d ? octave/src/inv.df ? octave/src/inv.oct ? octave/src/inverse.oct ? octave/src/kron.d ? octave/src/kron.df ? octave/src/kron.oct ? octave/src/lex.cc ? octave/src/lex.d ? octave/src/lex.df ? octave/src/liboctinterp.so.gz ? octave/src/link.sh ? octave/src/load-save.d ? octave/src/load-save.df ? octave/src/localtime.oct ? octave/src/log.d ? octave/src/log.df ? octave/src/log.oct ? octave/src/logm.oct ? octave/src/lp_solve.oct ? octave/src/lp_solve_options.oct ? octave/src/lpsolve.d ? octave/src/lpsolve.df ? octave/src/lpsolve.oct ? octave/src/lsode.d ? octave/src/lsode.df ? octave/src/lsode.oct ? octave/src/lsode_options.oct ? octave/src/lu.d ? octave/src/lu.df ? octave/src/lu.oct ? octave/src/main.d ? octave/src/mappers.d ? octave/src/mappers.df ? octave/src/matherr.d ? octave/src/max.oct ? octave/src/min.oct ? octave/src/minmax.d ? octave/src/minmax.df ? octave/src/minmax.oct ? octave/src/mktime.oct ? octave/src/oct-conf.h ? octave/src/oct-fstrm.d ? octave/src/oct-gperf.h ? octave/src/oct-hist.d ? octave/src/oct-hist.df ? octave/src/oct-iostrm.d ? octave/src/oct-lvalue.d ? octave/src/oct-map.d ? octave/src/oct-obj.d ? octave/src/oct-prcstrm.d ? octave/src/oct-procbuf.d ? octave/src/oct-procbuf.df ? octave/src/oct-stdstrm.d ? octave/src/oct-stream.d ? octave/src/oct-strstrm.d ? octave/src/octave ? octave/src/octave-core ? octave/src/octave.d ? octave/src/odessa.d ? octave/src/odessa.df ? octave/src/odessa.oct ? octave/src/odessa_options.oct ? octave/src/op-b-b.d ? octave/src/op-bm-b.d ? octave/src/op-bm-bm.d ? octave/src/op-cell.d ? octave/src/op-chm.d ? octave/src/op-cm-cm.d ? octave/src/op-cm-cs.d ? octave/src/op-cm-m.d ? octave/src/op-cm-s.d ? octave/src/op-cs-cm.d ? octave/src/op-cs-cs.d ? octave/src/op-cs-m.d ? octave/src/op-cs-s.d ? octave/src/op-da-da.d ? octave/src/op-da-s.d ? octave/src/op-fil-b.d ? octave/src/op-fil-bm.d ? octave/src/op-fil-cm.d ? octave/src/op-fil-cs.d ? octave/src/op-fil-lis.d ? octave/src/op-fil-m.d ? octave/src/op-fil-rec.d ? octave/src/op-fil-s.d ? octave/src/op-fil-str.d ? octave/src/op-list.d ? octave/src/op-m-cm.d ? octave/src/op-m-cs.d ? octave/src/op-m-m.d ? octave/src/op-m-s.d ? octave/src/op-range.d ? octave/src/op-s-cm.d ? octave/src/op-s-cs.d ? octave/src/op-s-da.d ? octave/src/op-s-m.d ? octave/src/op-s-s.d ? octave/src/op-str-str.d ? octave/src/ops.cc ? octave/src/ops.d ? octave/src/ov-base-mat.d ? octave/src/ov-base-nd-array.d ? octave/src/ov-base-scalar.d ? octave/src/ov-base.d ? octave/src/ov-bool-mat.d ? octave/src/ov-bool.d ? octave/src/ov-builtin.d ? octave/src/ov-cell.d ? octave/src/ov-cell.df ? octave/src/ov-ch-mat.d ? octave/src/ov-colon.d ? octave/src/ov-complex.d ? octave/src/ov-cs-list.d ? octave/src/ov-cs-list.df ? octave/src/ov-cx-mat.d ? octave/src/ov-dld-fcn.d ? octave/src/ov-fcn.d ? octave/src/ov-file.d ? octave/src/ov-list.d ? octave/src/ov-list.df ? octave/src/ov-mapper.d ? octave/src/ov-range.d ? octave/src/ov-re-mat.d ? octave/src/ov-re-nd-array.d ? octave/src/ov-scalar.d ? octave/src/ov-str-mat.d ? octave/src/ov-struct.d ? octave/src/ov-typeinfo.d ? octave/src/ov-typeinfo.df ? octave/src/ov-usr-fcn.d ? octave/src/ov-usr-fcn.df ? octave/src/ov-va-args.d ? octave/src/ov.d ? octave/src/ov.df ? octave/src/pager.d ? octave/src/pager.df ? octave/src/parse.cc ? octave/src/parse.d ? octave/src/parse.df ? octave/src/pic ? octave/src/pinv.d ? octave/src/pinv.df ? octave/src/pinv.oct ? octave/src/pr-output.d ? octave/src/pr-output.df ? octave/src/procstream.d ? octave/src/pt-arg-list.d ? octave/src/pt-assign.d ? octave/src/pt-assign.df ? octave/src/pt-binop.d ? octave/src/pt-bp.d ? octave/src/pt-cell.d ? octave/src/pt-check.d ? octave/src/pt-cmd.d ? octave/src/pt-colon.d ? octave/src/pt-const.d ? octave/src/pt-decl.d ? octave/src/pt-decl.df ? octave/src/pt-except.d ? octave/src/pt-exp.d ? octave/src/pt-id.d ? octave/src/pt-idx.d ? octave/src/pt-jump.d ? octave/src/pt-loop.d ? octave/src/pt-mat.d ? octave/src/pt-mat.df ? octave/src/pt-misc.d ? octave/src/pt-plot.d ? octave/src/pt-plot.df ? octave/src/pt-pr-code.d ? octave/src/pt-select.d ? octave/src/pt-stmt.d ? octave/src/pt-unop.d ? octave/src/pt.d ? octave/src/qr.d ? octave/src/qr.df ? octave/src/qr.oct ? octave/src/quad.d ? octave/src/quad.df ? octave/src/quad.oct ? octave/src/quad_options.oct ? octave/src/qz.d ? octave/src/qz.df ? octave/src/qz.oct ? octave/src/rand.d ? octave/src/rand.df ? octave/src/rand.oct ? octave/src/randn.oct ? octave/src/schur.d ? octave/src/schur.df ? octave/src/schur.oct ? octave/src/setgrent.oct ? octave/src/setpwent.oct ? octave/src/sighandlers.d ? octave/src/sighandlers.df ? octave/src/siglist.d ? octave/src/sort.d ? octave/src/sort.df ? octave/src/sort.oct ? octave/src/sqrtm.oct ? octave/src/stamp-oct-links ? octave/src/stamp-prereq ? octave/src/stmp-pic ? octave/src/strcasecmp.d ? octave/src/strfns.d ? octave/src/strfns.df ? octave/src/strftime.oct ? octave/src/strncase.d ? octave/src/strptime.oct ? octave/src/svd.d ? octave/src/svd.df ? octave/src/svd.oct ? octave/src/syl.d ? octave/src/syl.df ? octave/src/syl.oct ? octave/src/symtab.d ? octave/src/symtab.df ? octave/src/syscalls.d ? octave/src/syscalls.df ? octave/src/sysdep.d ? octave/src/sysdep.df ? octave/src/system.d ? octave/src/time.d ? octave/src/time.df ? octave/src/time.oct ? octave/src/token.d ? octave/src/toplev.d ? octave/src/toplev.df ? octave/src/unwind-prot.d ? octave/src/utils.d ? octave/src/utils.df ? octave/src/var-files ? octave/src/variables.d ? octave/src/variables.df ? octave/src/xdiv.d ? octave/src/xpow.d ? octave/src/y.output ? octave/src/y.tab.h ? octave/src/OPERATORS/op-da-da.cc ? octave/src/OPERATORS/op-da-s.cc ? octave/src/OPERATORS/op-s-da.cc Index: octave/src/Makefile.in =================================================================== RCS file: /cvs/octave/src/Makefile.in,v retrieving revision 1.304 diff -r1.304 Makefile.in 108c108 < op-s-s.cc op-str-str.cc --- > op-s-s.cc op-str-str.cc op-s-da.cc op-da-s.cc op-da-da.cc Index: octave/src/data.cc =================================================================== RCS file: /cvs/octave/src/data.cc,v retrieving revision 1.93 diff -r1.93 data.cc 927a928,930 > int ndim = 0; > int type = 0; > Array dims; 929c932,967 < switch (nargin) --- > // check for type information > if (nargin>0 && args(nargin-1).is_string ()) > { > nargin--; > // XXX FIXME XXX > // allow to specify a type for the resulting matrix, e.g. > // zeros(n1, n2, ..., 'real') > // zeros(n1, n2, ..., 'complex') > // type = get_type( args(nargin).string_value () ); > } > > // determine matrix dimension > switch (nargin) { > case 0: > ndim = 0; > type = 0; > break; > > case 1: > get_dimensions(args(0), fcn, dims); > > default: > dims.resize(nargin); > for (int i=0; i { > dims(i) = args(i).is_empty () ? 0 : args(i).nint_value(); > } > if (error_state) > error ("%s: expecting scalar arguments", fcn); > } > ndim = dims.length(); > > check_dimensions(dims, fcn); > > // construct either scalar, matrix or nd-array > switch (ndim) 936,942c974,975 < { < int nr, nc; < get_dimensions (args(0), fcn, nr, nc); < < if (! error_state) < retval = Matrix (nr, nc, val); < } --- > if (! error_state) > retval = Matrix (dims(0), dims(0), val); 946,952c979,980 < { < int nr, nc; < get_dimensions (args(0), args(1), fcn, nr, nc); < < if (! error_state) < retval = Matrix (nr, nc, val); < } --- > if (! error_state) > retval = Matrix (dims(0), dims(1), val); 956c984,987 < print_usage (fcn); --- > if (! error_state) > { > retval = new octave_double_nd_array (ArrayN (dims, val)); > } Index: octave/src/ov-base-nd-array.cc =================================================================== RCS file: /cvs/octave/src/ov-base-nd-array.cc,v retrieving revision 1.6 diff -r1.6 ov-base-nd-array.cc 32a33 > #include "idx-vector.h" 52a54,121 > octave_base_nd_array::subsref (const std::string type, > const SLList& idx) > { > octave_value retval; > > switch (type[0]) > { > case '(': > retval = do_index_op (idx.front ()); > break; > > case '{': > case '.': > { > std::string nm = type_name (); > error ("%s cannot be indexed with %c", nm.c_str (), type[0]); > } > break; > > default: > panic_impossible (); > } > > return retval.next_subsref (type, idx); > } > > template > octave_value > octave_base_nd_array::subsasgn (const std::string type, > const SLList& idx, > const octave_value& rhs) > { > octave_value retval; > > std::cout << "octave_base_nd_array::subsasgn()\n"; > > switch (type[0]) > { > case '(': > { > if (type.length () == 1) > retval = numeric_assign (type, idx, rhs); > else > { > std::string nm = type_name (); > error ("in indexed assignment of %s, last rhs index must be ()", > nm.c_str ()); > } > } > break; > > case '{': > case '.': > { > std::string nm = type_name (); > error ("%s cannot be indexed with %c", nm.c_str (), type[0]); > } > break; > > default: > panic_impossible (); > } > > return retval; > } > > template > octave_value 64,65c133 < retval < = octave_value (new octave_base_nd_array (AT (array.index (i, resize_ok)))); --- > retval = AT (array.index (i, resize_ok)); 71,72c139 < retval < = octave_value (new octave_base_nd_array (AT (array.index (i, resize_ok)))); --- > retval = AT (array.index (i, resize_ok)); 82a150,178 > } > > template > void > octave_base_nd_array::assign (const octave_value_list& idx, const AT& rhs) > { > int len = idx.length (); > > std::cout << "octave_base_nd_array::assign\n"; > > array.clear_index (); > for (int k=0; k { > idx_vector i = idx (k).index_vector (); > array.set_index (i); > } > > switch (len) > { > case 1: > ::assign (array, rhs); > break; > > default: > ::assign (array, rhs); > // error ("invalid number of indices (%d) for indexed assignment", > // len); > break; > } Index: octave/src/ov-base-nd-array.h =================================================================== RCS file: /cvs/octave/src/ov-base-nd-array.h,v retrieving revision 1.5 diff -r1.5 ov-base-nd-array.h 67a68,73 > octave_value subsref (const std::string type, > const SLList& idx); > > octave_value subsasgn (const std::string type, > const SLList& idx, > const octave_value& rhs); 69a76,80 > > octave_value do_index_op (const octave_value_list& idx) > { return do_index_op (idx, 0); } > > void assign (const octave_value_list& idx, const AT& rhs); Index: octave/src/ov-base.cc =================================================================== RCS file: /cvs/octave/src/ov-base.cc,v retrieving revision 1.33 diff -r1.33 ov-base.cc 48a49 > #include "ov-re-nd-array.h" 260a262,269 > ArrayN > octave_base_value::double_nd_array_value (bool) const > { > ArrayN retval; > gripe_wrong_type_arg ("octave_base_value::double_nd_array_value()", type_name ()); > return retval; > } > 407a417,421 > CONVDECLX (double_nd_array_conv) > { > return new octave_double_nd_array (); > } > 417a432,434 > INSTALL_ASSIGNCONV (octave_base_value, octave_scalar, octave_double_nd_array); > INSTALL_ASSIGNCONV (octave_base_value, octave_scalar, octave_double_nd_array); > INSTALL_ASSIGNCONV (octave_base_value, octave_double_nd_array, octave_double_nd_array); 422a440 > INSTALL_WIDENOP (octave_base_value, octave_double_nd_array, double_nd_array_conv); Index: octave/src/ov-base.h =================================================================== RCS file: /cvs/octave/src/ov-base.h,v retrieving revision 1.38 diff -r1.38 ov-base.h 183a184,185 > ArrayN double_nd_array_value (bool = false) const; > Index: octave/src/ov-re-nd-array.cc =================================================================== RCS file: /cvs/octave/src/ov-re-nd-array.cc,v retrieving revision 1.6 diff -r1.6 ov-re-nd-array.cc 43a44 > #include "ov-scalar.h" 55d55 < #if 0 57c57 < octave_matrix::try_narrowing_conversion (void) --- > octave_double_nd_array::try_narrowing_conversion (void) 61,62c61,64 < int nr = matrix.rows (); < int nc = matrix.cols (); --- > for (int i=0; i if (array.dimensions(i) != 1) > return retval; > } 64,65c66 < if (nr == 1 && nc == 1) < retval = new octave_scalar (matrix (0, 0)); --- > retval = new octave_scalar ( *array.data() ); 69a71 > #if 0 71c73 < octave_matrix::assign (const octave_value_list& idx, const Matrix& rhs) --- > octave_double_nd_array::assign (const octave_value_list& idx, const double_nd_array& rhs) 82,83c84,85 < matrix.set_index (i); < matrix.set_index (j); --- > double_nd_array.set_index (i); > double_nd_array.set_index (j); 85c87 < ::assign (matrix, rhs); --- > ::assign (double_nd_array, rhs); 93c95 < matrix.set_index (i); --- > double_nd_array.set_index (i); 95c97 < ::assign (matrix, rhs); --- > ::assign (double_nd_array, rhs); 100c102 < error ("invalid number of indices (%d) for indexed matrix assignment", --- > error ("invalid number of indices (%d) for indexed double_nd_array assignment", 107c109 < octave_matrix::valid_as_scalar_index (void) const --- > octave_double_nd_array::valid_as_scalar_index (void) const 114c116 < octave_matrix::double_value (bool) const --- > octave_double_nd_array::double_value (bool) const 121c123 < retval = matrix (0, 0); --- > retval = double_nd_array (0); 123c125 < gripe_invalid_conversion ("real matrix", "real scalar"); --- > gripe_invalid_conversion ("real double_nd_array", "real scalar"); 129c131 < octave_matrix::complex_value (bool) const --- > octave_double_nd_array::complex_value (bool) const 137c139 < retval = matrix (0, 0); --- > retval = double_nd_array (0); 139c141 < gripe_invalid_conversion ("real matrix", "complex scalar"); --- > gripe_invalid_conversion ("real double_nd_array", "complex scalar"); Index: octave/src/ov-re-nd-array.h =================================================================== RCS file: /cvs/octave/src/ov-re-nd-array.h,v retrieving revision 1.5 diff -r1.5 ov-re-nd-array.h 66d65 < #if 0 68a68,70 > ArrayN double_nd_array_value (bool = false) const { return array; }; > > #if 0 Index: octave/src/ov-scalar.h =================================================================== RCS file: /cvs/octave/src/ov-scalar.h,v retrieving revision 1.19 diff -r1.19 ov-scalar.h 88a89,91 > ArrayN double_nd_array_value (bool = false) const > { return ArrayN (Array (1,1), scalar); } > Index: octave/src/ov.cc =================================================================== RCS file: /cvs/octave/src/ov.cc,v retrieving revision 1.66 diff -r1.66 ov.cc 42a43 > #include "ov-re-nd-array.h" 386a388,394 > octave_value::octave_value (const ArrayN& m) > : rep (new octave_double_nd_array (m)) > { > rep->count = 1; > maybe_mutate (); > } > 1662a1671 > octave_double_nd_array::register_type (); Index: octave/src/ov.h =================================================================== RCS file: /cvs/octave/src/ov.h,v retrieving revision 1.58 diff -r1.58 ov.h 39a40 > #include "ArrayN.h" 166a168 > octave_value (const ArrayN& m); 430a433,435 > > virtual ArrayN double_nd_array_value (bool frc_str_conv = false) const > { return rep->double_nd_array_value (frc_str_conv); } Index: octave/src/utils.cc =================================================================== RCS file: /cvs/octave/src/utils.cc,v retrieving revision 1.150 diff -r1.150 utils.cc 663a664,724 > check_dimensions (Array& dim, const char *warnfor) > { > int i, n; > bool neg = false; > > n = dim.length(); > for (i=0; i if (dim(i) < 0) { > dim(i) = 0; > neg = true; > } > } > > if (neg) { > if (Vtreat_neg_dim_as_zero==0) { > error ("%s: can't create a matrix with negative dimensions", > warnfor); > } else if (Vtreat_neg_dim_as_zero<0) { > warning ("%s: converting negative dimension to zero", > warnfor); > } > } > } > > void > get_dimensions (const octave_value& a, const char *warn_for, > Array& dim) > { > int n, nr, nc; > > if (a.is_scalar_type ()) > { > dim.resize(2); > dim(0) = a.nint_value(); > dim(1) = dim(0); > } > else > { > nr = a.rows (); > nc = a.columns (); > > if (nr ==1 || nc == 1) > { > Array v = a.vector_value (); > > if (error_state) > return; > > n = v.length (); > dim.resize(n); > for (int i=0; i dim(i) = NINT (v (i)); > } > else > warning ("%s (A): use %s (size (A)) instead", warn_for, warn_for); > } > > check_dimensions (dim, warn_for); // May set error_state. > } > > void Index: octave/src/utils.h =================================================================== RCS file: /cvs/octave/src/utils.h,v retrieving revision 1.68 diff -r1.68 utils.h 36a37,42 > > extern std::string search_path_for_file (const std::string&, const std::string&); > extern std::string file_in_path (const std::string&, const std::string&); > extern std::string fcn_file_in_path (const std::string&); > extern std::string oct_file_in_path (const std::string&); > 39a46,48 > > extern void jump_to_top_level (void) GCC_ATTR_NORETURN; > 61a71,77 > > extern void > check_dimensions (Array& dim, const char *warnfor); > > extern void > get_dimensions (const octave_value& a, const char *warn_for, > Array& dim); --Boundary-00=_LhEI/lJKH+1aeMz-- ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------