diff liboctave/dMatrix.cc @ 10350:12884915a8e4

merge MArray classes & improve Array interface
author Jaroslav Hajek <highegg@gmail.com>
date Sat, 23 Jan 2010 21:41:03 +0100
parents 07ebe522dac2
children a3635bc1ea19
line wrap: on
line diff
--- a/liboctave/dMatrix.cc
+++ b/liboctave/dMatrix.cc
@@ -214,24 +214,24 @@
 // Matrix class.
 
 Matrix::Matrix (const RowVector& rv)
-  : MArray2<double> (Array2<double> (rv, 1, rv.length ()))
+  : MArray<double> (rv)
 {
 }
 
 Matrix::Matrix (const ColumnVector& cv)
-  : MArray2<double> (Array2<double> (cv, cv.length (), 1))
+  : MArray<double> (cv)
 {
 }
 
 Matrix::Matrix (const DiagMatrix& a)
-  : MArray2<double> (a.rows (), a.cols (), 0.0)
+  : MArray<double> (a.rows (), a.cols (), 0.0)
 {
   for (octave_idx_type i = 0; i < a.length (); i++)
     elem (i, i) = a.elem (i, i);
 }
 
 Matrix::Matrix (const PermMatrix& a)
-  : MArray2<double> (a.rows (), a.cols (), 0.0)
+  : MArray<double> (a.rows (), a.cols (), 0.0)
 {
   const Array<octave_idx_type> ia (a.pvec ());
   octave_idx_type len = a.rows ();
@@ -247,15 +247,12 @@
 // here?
 
 Matrix::Matrix (const boolMatrix& a)
-  : MArray2<double> (a.rows (), a.cols ())
+  : MArray<double> (a)
 {
-  for (octave_idx_type i = 0; i < a.rows (); i++)
-    for (octave_idx_type j = 0; j < a.cols (); j++)
-      elem (i, j) = a.elem (i, j);
 }
 
 Matrix::Matrix (const charMatrix& a)
-  : MArray2<double> (a.rows (), a.cols ())
+  : MArray<double> (a.rows (), a.cols ())
 {
   for (octave_idx_type i = 0; i < a.rows (); i++)
     for (octave_idx_type j = 0; j < a.cols (); j++)
@@ -296,7 +293,7 @@
 Matrix&
 Matrix::insert (const Matrix& a, octave_idx_type r, octave_idx_type c)
 {
-  Array2<double>::insert (a, r, c);
+  Array<double>::insert (a, r, c);
   return *this;
 }
 
@@ -614,13 +611,13 @@
 RowVector
 Matrix::row (octave_idx_type i) const
 {
-  return MArray<double> (index (idx_vector (i), idx_vector::colon));
+  return index (idx_vector (i), idx_vector::colon);
 }
 
 ColumnVector
 Matrix::column (octave_idx_type i) const
 {
-  return MArray<double> (index (idx_vector::colon, idx_vector (i)));
+  return index (idx_vector::colon, idx_vector (i));
 }
 
 Matrix
@@ -734,13 +731,13 @@
     (*current_liboctave_error_handler) ("inverse requires square matrix");
   else
     {
-      Array<octave_idx_type> ipvt (nr);
+      Array<octave_idx_type> ipvt (nr, 1);
       octave_idx_type *pipvt = ipvt.fortran_vec ();
 
       retval = *this;
       double *tmp_data = retval.fortran_vec ();
 
-      Array<double> z(1);
+      Array<double> z(1, 1);
       octave_idx_type lwork = -1;
 
       // Query the optimum work array size.
@@ -749,7 +746,7 @@
 
       lwork = static_cast<octave_idx_type> (z(0));
       lwork = (lwork < 2 *nc ? 2*nc : lwork);
-      z.resize (lwork);
+      z.resize (lwork, 1);
       double *pz = z.fortran_vec ();
 
       info = 0;
@@ -771,7 +768,7 @@
 
           // Now calculate the condition number for non-singular matrix.
           char job = '1';
-          Array<octave_idx_type> iz (nc);
+          Array<octave_idx_type> iz (nc, 1);
           octave_idx_type *piz = iz.fortran_vec ();
           F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
                                      nc, tmp_data, nr, anorm, 
@@ -1006,7 +1003,7 @@
 
   octave_idx_type nn = 4*npts+15;
 
-  Array<Complex> wsave (nn);
+  Array<Complex> wsave (nn, 1);
   Complex *pwsave = wsave.fortran_vec ();
 
   retval = ComplexMatrix (*this);
@@ -1047,7 +1044,7 @@
 
   octave_idx_type nn = 4*npts+15;
 
-  Array<Complex> wsave (nn);
+  Array<Complex> wsave (nn, 1);
   Complex *pwsave = wsave.fortran_vec ();
 
   retval = ComplexMatrix (*this);
@@ -1091,7 +1088,7 @@
 
   octave_idx_type nn = 4*npts+15;
 
-  Array<Complex> wsave (nn);
+  Array<Complex> wsave (nn, 1);
   Complex *pwsave = wsave.fortran_vec ();
 
   retval = ComplexMatrix (*this);
@@ -1110,10 +1107,10 @@
   nsamples = nr;
   nn = 4*npts+15;
 
-  wsave.resize (nn);
+  wsave.resize (nn, 1);
   pwsave = wsave.fortran_vec ();
 
-  Array<Complex> tmp (npts);
+  Array<Complex> tmp (npts, 1);
   Complex *prow = tmp.fortran_vec ();
 
   F77_FUNC (zffti, ZFFTI) (npts, pwsave);
@@ -1157,7 +1154,7 @@
 
   octave_idx_type nn = 4*npts+15;
 
-  Array<Complex> wsave (nn);
+  Array<Complex> wsave (nn, 1);
   Complex *pwsave = wsave.fortran_vec ();
 
   retval = ComplexMatrix (*this);
@@ -1179,10 +1176,10 @@
   nsamples = nr;
   nn = 4*npts+15;
 
-  wsave.resize (nn);
+  wsave.resize (nn, 1);
   pwsave = wsave.fortran_vec ();
 
-  Array<Complex> tmp (npts);
+  Array<Complex> tmp (npts, 1);
   Complex *prow = tmp.fortran_vec ();
 
   F77_FUNC (zffti, ZFFTI) (npts, pwsave);
@@ -1279,9 +1276,9 @@
             }
           else 
             {
-              Array<double> z (3 * nc);
+              Array<double> z (3 * nc, 1);
               double *pz = z.fortran_vec ();
-              Array<octave_idx_type> iz (nc);
+              Array<octave_idx_type> iz (nc, 1);
               octave_idx_type *piz = iz.fortran_vec ();
 
               F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (&job, 1),
@@ -1303,7 +1300,7 @@
 
       if (typ == MatrixType::Full)
         {
-          Array<octave_idx_type> ipvt (nr);
+          Array<octave_idx_type> ipvt (nr, 1);
           octave_idx_type *pipvt = ipvt.fortran_vec ();
 
           Matrix atmp = *this;
@@ -1330,9 +1327,9 @@
                 {
                   // Now calc the condition number for non-singular matrix.
                   char job = '1';
-                  Array<double> z (4 * nc);
+                  Array<double> z (4 * nc, 1);
                   double *pz = z.fortran_vec ();
-                  Array<octave_idx_type> iz (nc);
+                  Array<octave_idx_type> iz (nc, 1);
                   octave_idx_type *piz = iz.fortran_vec ();
 
                   F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
@@ -1395,9 +1392,9 @@
           char uplo = 'U';
           char dia = 'N';
 
-          Array<double> z (3 * nc);
+          Array<double> z (3 * nc, 1);
           double *pz = z.fortran_vec ();
-          Array<octave_idx_type> iz (nc);
+          Array<octave_idx_type> iz (nc, 1);
           octave_idx_type *piz = iz.fortran_vec ();
 
           F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), 
@@ -1423,9 +1420,9 @@
           char uplo = 'L';
           char dia = 'N';
 
-          Array<double> z (3 * nc);
+          Array<double> z (3 * nc, 1);
           double *pz = z.fortran_vec ();
-          Array<octave_idx_type> iz (nc);
+          Array<octave_idx_type> iz (nc, 1);
           octave_idx_type *piz = iz.fortran_vec ();
 
           F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), 
@@ -1468,9 +1465,9 @@
                 }
               else 
                 {
-                  Array<double> z (3 * nc);
+                  Array<double> z (3 * nc, 1);
                   double *pz = z.fortran_vec ();
-                  Array<octave_idx_type> iz (nc);
+                  Array<octave_idx_type> iz (nc, 1);
                   octave_idx_type *piz = iz.fortran_vec ();
 
                   F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (&job, 1),
@@ -1487,16 +1484,16 @@
             {
               octave_idx_type info = 0;
 
-              Array<octave_idx_type> ipvt (nr);
+              Array<octave_idx_type> ipvt (nr, 1);
               octave_idx_type *pipvt = ipvt.fortran_vec ();
 
               if(anorm < 0.)
                 anorm = atmp.abs().sum().
                   row(static_cast<octave_idx_type>(0)).max();
 
-              Array<double> z (4 * nc);
+              Array<double> z (4 * nc, 1);
               double *pz = z.fortran_vec ();
-              Array<octave_idx_type> iz (nc);
+              Array<octave_idx_type> iz (nc, 1);
               octave_idx_type *piz = iz.fortran_vec ();
 
               F77_XFCN (dgetrf, DGETRF, (nr, nr, tmp_data, nr, pipvt, info));
@@ -1567,9 +1564,9 @@
                   char uplo = 'U';
                   char dia = 'N';
 
-                  Array<double> z (3 * nc);
+                  Array<double> z (3 * nc, 1);
                   double *pz = z.fortran_vec ();
-                  Array<octave_idx_type> iz (nc);
+                  Array<octave_idx_type> iz (nc, 1);
                   octave_idx_type *piz = iz.fortran_vec ();
 
                   F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), 
@@ -1667,9 +1664,9 @@
                   char uplo = 'L';
                   char dia = 'N';
 
-                  Array<double> z (3 * nc);
+                  Array<double> z (3 * nc, 1);
                   double *pz = z.fortran_vec ();
-                  Array<octave_idx_type> iz (nc);
+                  Array<octave_idx_type> iz (nc, 1);
                   octave_idx_type *piz = iz.fortran_vec ();
 
                   F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), 
@@ -1773,9 +1770,9 @@
             {
               if (calc_cond)
                 {
-                  Array<double> z (3 * nc);
+                  Array<double> z (3 * nc, 1);
                   double *pz = z.fortran_vec ();
-                  Array<octave_idx_type> iz (nc);
+                  Array<octave_idx_type> iz (nc, 1);
                   octave_idx_type *piz = iz.fortran_vec ();
 
                   F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (&job, 1),
@@ -1825,7 +1822,7 @@
         {
           info = 0;
 
-          Array<octave_idx_type> ipvt (nr);
+          Array<octave_idx_type> ipvt (nr, 1);
           octave_idx_type *pipvt = ipvt.fortran_vec ();
 
           Matrix atmp = *this;
@@ -1833,9 +1830,9 @@
           if(anorm < 0.)
             anorm = atmp.abs().sum().row(static_cast<octave_idx_type>(0)).max();
 
-          Array<double> z (4 * nc);
+          Array<double> z (4 * nc, 1);
           double *pz = z.fortran_vec ();
-          Array<octave_idx_type> iz (nc);
+          Array<octave_idx_type> iz (nc, 1);
           octave_idx_type *piz = iz.fortran_vec ();
 
           F77_XFCN (dgetrf, DGETRF, (nr, nr, tmp_data, nr, pipvt, info));
@@ -2264,13 +2261,13 @@
       double *tmp_data = atmp.fortran_vec ();
 
       double *pretval = retval.fortran_vec ();
-      Array<double> s (minmn);
+      Array<double> s (minmn, 1);
       double *ps = s.fortran_vec ();
 
       // Ask DGELSD what the dimension of WORK should be.
       octave_idx_type lwork = -1;
 
-      Array<double> work (1);
+      Array<double> work (1, 1);
 
       octave_idx_type smlsiz;
       F77_FUNC (xilaenv, XILAENV) (9, F77_CONST_CHAR_ARG2 ("DGELSD", 6),
@@ -2302,7 +2299,7 @@
       octave_idx_type liwork = 3 * minmn * nlvl + 11 * minmn;
       if (liwork < 1)
         liwork = 1;
-      Array<octave_idx_type> iwork (liwork);
+      Array<octave_idx_type> iwork (liwork, 1);
       octave_idx_type* piwork = iwork.fortran_vec ();
 
       F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval, maxmn,
@@ -2347,7 +2344,7 @@
         }
 
       lwork = static_cast<octave_idx_type> (work(0));
-      work.resize (lwork);
+      work.resize (lwork, 1);
 
       F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval,
                                  maxmn, ps, rcon, rank,
@@ -2465,13 +2462,13 @@
       double *tmp_data = atmp.fortran_vec ();
 
       double *pretval = retval.fortran_vec ();
-      Array<double> s (minmn);
+      Array<double> s (minmn, 1);
       double *ps = s.fortran_vec ();
 
       // Ask DGELSD what the dimension of WORK should be.
       octave_idx_type lwork = -1;
 
-      Array<double> work (1);
+      Array<double> work (1, 1);
 
       octave_idx_type smlsiz;
       F77_FUNC (xilaenv, XILAENV) (9, F77_CONST_CHAR_ARG2 ("DGELSD", 6),
@@ -2496,7 +2493,7 @@
       octave_idx_type liwork = 3 * minmn * nlvl + 11 * minmn;
       if (liwork < 1)
         liwork = 1;
-      Array<octave_idx_type> iwork (liwork);
+      Array<octave_idx_type> iwork (liwork, 1);
       octave_idx_type* piwork = iwork.fortran_vec ();
 
       F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval, maxmn,
@@ -2504,7 +2501,7 @@
                                  lwork, piwork, info));
 
       lwork = static_cast<octave_idx_type> (work(0));
-      work.resize (lwork);
+      work.resize (lwork, 1);
 
       F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval,
                                  maxmn, ps, rcon, rank,
@@ -2831,7 +2828,7 @@
 Matrix
 Matrix::diag (octave_idx_type k) const
 {
-  return MArray2<double>::diag (k);
+  return MArray<double>::diag (k);
 }
 
 ColumnVector
@@ -2852,7 +2849,7 @@
   if (nr > 0 && nc > 0)
     {
       result.resize (nr);
-      idx_arg.resize (nr);
+      idx_arg.resize (nr, 1);
 
       for (octave_idx_type i = 0; i < nr; i++)
         {
@@ -2907,7 +2904,7 @@
   if (nr > 0 && nc > 0)
     {
       result.resize (nr);
-      idx_arg.resize (nr);
+      idx_arg.resize (nr, 1);
 
       for (octave_idx_type i = 0; i < nr; i++)
         {
@@ -2962,7 +2959,7 @@
   if (nr > 0 && nc > 0)
     {
       result.resize (nc);
-      idx_arg.resize (nc);
+      idx_arg.resize (1, nc);
 
       for (octave_idx_type j = 0; j < nc; j++)
         {
@@ -3017,7 +3014,7 @@
   if (nr > 0 && nc > 0)
     {
       result.resize (nc);
-      idx_arg.resize (nc);
+      idx_arg.resize (1, nc);
 
       for (octave_idx_type j = 0; j < nc; j++)
         {