Mercurial > hg > octave-nkf
changeset 8614:5114ea5a41b5
use shallow copying in Matrix/RowVector/ColumnVector conversions
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 28 Jan 2009 09:33:27 +0100 |
parents | 38482007c834 |
children | 7baacb6a8a65 |
files | liboctave/CMatrix.cc liboctave/ChangeLog liboctave/dMatrix.cc liboctave/fCMatrix.cc liboctave/fMatrix.cc |
diffstat | 5 files changed, 41 insertions(+), 120 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/CMatrix.cc +++ b/liboctave/CMatrix.cc @@ -279,17 +279,13 @@ } ComplexMatrix::ComplexMatrix (const ComplexRowVector& rv) - : MArray2<Complex> (1, rv.length (), 0.0) + : MArray2<Complex> (Array2<Complex> (rv, 1, rv.length ())) { - for (octave_idx_type i = 0; i < rv.length (); i++) - elem (0, i) = rv.elem (i); } ComplexMatrix::ComplexMatrix (const ComplexColumnVector& cv) - : MArray2<Complex> (cv.length (), 1, 0.0) + : MArray2<Complex> (Array2<Complex> (cv, cv.length (), 1)) { - for (octave_idx_type i = 0; i < cv.length (); i++) - elem (i, 0) = cv.elem (i); } ComplexMatrix::ComplexMatrix (const ComplexDiagMatrix& a) @@ -957,35 +953,13 @@ ComplexRowVector ComplexMatrix::row (octave_idx_type i) const { - octave_idx_type nc = cols (); - if (i < 0 || i >= rows ()) - { - (*current_liboctave_error_handler) ("invalid row selection"); - return ComplexRowVector (); - } - - ComplexRowVector retval (nc); - for (octave_idx_type j = 0; j < cols (); j++) - retval.xelem (j) = elem (i, j); - - return retval; + return MArray<Complex> (index (idx_vector (i), idx_vector::colon)); } ComplexColumnVector ComplexMatrix::column (octave_idx_type i) const { - octave_idx_type nr = rows (); - if (i < 0 || i >= cols ()) - { - (*current_liboctave_error_handler) ("invalid column selection"); - return ComplexColumnVector (); - } - - ComplexColumnVector retval (nr); - for (octave_idx_type j = 0; j < nr; j++) - retval.xelem (j) = elem (j, i); - - return retval; + return MArray<Complex> (index (idx_vector::colon, idx_vector (i))); } ComplexMatrix
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,28 @@ +2009-01-28 Jaroslav Hajek <highegg@gmail.com> + + * dMatrix.cc (Matrix::Matrix (const RowVector&)): Use shallow copy. + (Matrix::Matrix (const ColumnVector&)): Dtto. + (Matrix::row): Dtto. + (Matrix::column): Dtto. + + * fMatrix.cc (FloatMatrix::FloatMatrix (const FloatRowVector&)): Use + shallow copy. + (FloatMatrix::FloatMatrix (const FloatColumnVector&)): Dtto. + (FloatMatrix::row): Dtto. + (FloatMatrix::column): Dtto. + + * CMatrix.cc (ComplexMatrix::ComplexMatrix (const ComplexRowVector&)): + Use shallow copy. + (ComplexMatrix::ComplexMatrix (const ComplexColumnVector&)): Dtto. + (ComplexMatrix::row): Dtto. + (ComplexMatrix::column): Dtto. + + * fCMatrix.cc (FloatComplexMatrix::FloatComplexMatrix (const FloatComplexRowVector&)): + Use shallow copy. + (FloatComplexMatrix::FloatComplexMatrix (const FloatComplexColumnVector&)): Dtto. + (FloatComplexMatrix::row): Dtto. + (FloatComplexMatrix::column): Dtto. + 2009-01-27 Benjamin Lindner <lindnerb@users.sourceforge.net> * Makefile.in (LINK_DEPS): Include ARPACK_LIBS and REGEX_LIBS in
--- a/liboctave/dMatrix.cc +++ b/liboctave/dMatrix.cc @@ -229,17 +229,13 @@ // Matrix class. Matrix::Matrix (const RowVector& rv) - : MArray2<double> (1, rv.length (), 0.0) + : MArray2<double> (Array2<double> (rv, 1, rv.length ())) { - for (octave_idx_type i = 0; i < rv.length (); i++) - elem (0, i) = rv.elem (i); } Matrix::Matrix (const ColumnVector& cv) - : MArray2<double> (cv.length (), 1, 0.0) + : MArray2<double> (Array2<double> (cv, cv.length (), 1)) { - for (octave_idx_type i = 0; i < cv.length (); i++) - elem (i, 0) = cv.elem (i); } Matrix::Matrix (const DiagMatrix& a) @@ -641,35 +637,13 @@ RowVector Matrix::row (octave_idx_type i) const { - octave_idx_type nc = cols (); - if (i < 0 || i >= rows ()) - { - (*current_liboctave_error_handler) ("invalid row selection"); - return RowVector (); - } - - RowVector retval (nc); - for (octave_idx_type j = 0; j < nc; j++) - retval.xelem (j) = elem (i, j); - - return retval; + return MArray<double> (index (idx_vector (i), idx_vector::colon)); } ColumnVector Matrix::column (octave_idx_type i) const { - octave_idx_type nr = rows (); - if (i < 0 || i >= cols ()) - { - (*current_liboctave_error_handler) ("invalid column selection"); - return ColumnVector (); - } - - ColumnVector retval (nr); - for (octave_idx_type j = 0; j < nr; j++) - retval.xelem (j) = elem (j, i); - - return retval; + return MArray<double> (index (idx_vector::colon, idx_vector (i))); } Matrix
--- a/liboctave/fCMatrix.cc +++ b/liboctave/fCMatrix.cc @@ -273,17 +273,13 @@ } FloatComplexMatrix::FloatComplexMatrix (const FloatComplexRowVector& rv) - : MArray2<FloatComplex> (1, rv.length (), 0.0) + : MArray2<FloatComplex> (Array2<FloatComplex> (rv, 1, rv.length ())) { - for (octave_idx_type i = 0; i < rv.length (); i++) - elem (0, i) = rv.elem (i); } FloatComplexMatrix::FloatComplexMatrix (const FloatComplexColumnVector& cv) - : MArray2<FloatComplex> (cv.length (), 1, 0.0) + : MArray2<FloatComplex> (Array2<FloatComplex> (cv, cv.length (), 1)) { - for (octave_idx_type i = 0; i < cv.length (); i++) - elem (i, 0) = cv.elem (i); } FloatComplexMatrix::FloatComplexMatrix (const FloatComplexDiagMatrix& a) @@ -951,35 +947,13 @@ FloatComplexRowVector FloatComplexMatrix::row (octave_idx_type i) const { - octave_idx_type nc = cols (); - if (i < 0 || i >= rows ()) - { - (*current_liboctave_error_handler) ("invalid row selection"); - return FloatComplexRowVector (); - } - - FloatComplexRowVector retval (nc); - for (octave_idx_type j = 0; j < cols (); j++) - retval.xelem (j) = elem (i, j); - - return retval; + return MArray<FloatComplex> (index (idx_vector (i), idx_vector::colon)); } FloatComplexColumnVector FloatComplexMatrix::column (octave_idx_type i) const { - octave_idx_type nr = rows (); - if (i < 0 || i >= cols ()) - { - (*current_liboctave_error_handler) ("invalid column selection"); - return FloatComplexColumnVector (); - } - - FloatComplexColumnVector retval (nr); - for (octave_idx_type j = 0; j < nr; j++) - retval.xelem (j) = elem (j, i); - - return retval; + return MArray<FloatComplex> (index (idx_vector::colon, idx_vector (i))); } FloatComplexMatrix
--- a/liboctave/fMatrix.cc +++ b/liboctave/fMatrix.cc @@ -228,17 +228,13 @@ // Matrix class. FloatMatrix::FloatMatrix (const FloatRowVector& rv) - : MArray2<float> (1, rv.length (), 0.0) + : MArray2<float> (Array2<float> (rv, 1, rv.length ())) { - for (octave_idx_type i = 0; i < rv.length (); i++) - elem (0, i) = rv.elem (i); } FloatMatrix::FloatMatrix (const FloatColumnVector& cv) - : MArray2<float> (cv.length (), 1, 0.0) + : MArray2<float> (Array2<float> (cv, cv.length (), 1)) { - for (octave_idx_type i = 0; i < cv.length (); i++) - elem (i, 0) = cv.elem (i); } FloatMatrix::FloatMatrix (const FloatDiagMatrix& a) @@ -640,35 +636,13 @@ FloatRowVector FloatMatrix::row (octave_idx_type i) const { - octave_idx_type nc = cols (); - if (i < 0 || i >= rows ()) - { - (*current_liboctave_error_handler) ("invalid row selection"); - return FloatRowVector (); - } - - FloatRowVector retval (nc); - for (octave_idx_type j = 0; j < nc; j++) - retval.xelem (j) = elem (i, j); - - return retval; + return MArray<float> (index (idx_vector (i), idx_vector::colon)); } FloatColumnVector FloatMatrix::column (octave_idx_type i) const { - octave_idx_type nr = rows (); - if (i < 0 || i >= cols ()) - { - (*current_liboctave_error_handler) ("invalid column selection"); - return FloatColumnVector (); - } - - FloatColumnVector retval (nr); - for (octave_idx_type j = 0; j < nr; j++) - retval.xelem (j) = elem (j, i); - - return retval; + return MArray<float> (index (idx_vector::colon, idx_vector (i))); } FloatMatrix