Mercurial > hg > octave-lyh
diff liboctave/Array.cc @ 4786:fc316bde0053
[project @ 2004-02-18 12:52:20 by jwe]
author | jwe |
---|---|
date | Wed, 18 Feb 2004 12:52:20 +0000 |
parents | e941e1470d7b |
children | 962457f25a6d |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -931,6 +931,39 @@ Array<T>& Array<T>::insert (const Array<T>& a, int r, int c) { + if (ndims () == 2 && a.ndims () == 2) + insert2 (a, r, c); + else + insertN (a, r, c); + + return *this; +} + + +template <class T> +Array<T>& +Array<T>::insert2 (const Array<T>& a, int r, int c) +{ + int a_rows = a.rows (); + int a_cols = a.cols (); + + if (r < 0 || r + a_rows > rows () || c < 0 || c + a_cols > cols ()) + { + (*current_liboctave_error_handler) ("range error for insert"); + return *this; + } + + for (int j = 0; j < a_cols; j++) + for (int i = 0; i < a_rows; i++) + elem (r+i, c+j) = a.elem (i, j); + + return *this; +} + +template <class T> +Array<T>& +Array<T>::insertN (const Array<T>& a, int r, int c) +{ dim_vector a_dv = a.dims (); int n = a_dv.length ();