Mercurial > octave-nkf
comparison liboctave/Array.cc @ 4765:e941e1470d7b
[project @ 2004-02-16 05:56:50 by jwe]
author | jwe |
---|---|
date | Mon, 16 Feb 2004 05:56:51 +0000 |
parents | bec345670e56 |
children | fc316bde0053 |
comparison
equal
deleted
inserted
replaced
4764:86c748d5f0af | 4765:e941e1470d7b |
---|---|
929 | 929 |
930 template <class T> | 930 template <class T> |
931 Array<T>& | 931 Array<T>& |
932 Array<T>::insert (const Array<T>& a, int r, int c) | 932 Array<T>::insert (const Array<T>& a, int r, int c) |
933 { | 933 { |
934 int a_rows = a.rows (); | 934 dim_vector a_dv = a.dims (); |
935 int a_cols = a.cols (); | 935 |
936 | 936 int n = a_dv.length (); |
937 if (r < 0 || r + a_rows > rows () || c < 0 || c + a_cols > cols ()) | |
938 { | |
939 (*current_liboctave_error_handler) ("range error for insert"); | |
940 return *this; | |
941 } | |
942 | |
943 for (int j = 0; j < a_cols; j++) | |
944 for (int i = 0; i < a_rows; i++) | |
945 elem (r+i, c+j) = a.elem (i, j); | |
946 | |
947 return *this; | |
948 } | |
949 | |
950 template <class T> | |
951 Array<T>& | |
952 Array<T>::insert (const Array<T>& a, const Array<int>& ra_idx) | |
953 { | |
954 int n = ra_idx.length (); | |
955 | 937 |
956 if (n == dimensions.length ()) | 938 if (n == dimensions.length ()) |
957 { | 939 { |
958 dim_vector a_dims = a.dims (); | 940 Array<int> a_ra_idx (a_dv.length (), 0); |
941 | |
942 a_ra_idx.elem (0) = r; | |
943 a_ra_idx.elem (1) = c; | |
959 | 944 |
960 for (int i = 0; i < n; i++) | 945 for (int i = 0; i < n; i++) |
961 { | 946 { |
962 if (ra_idx(i) < 0 || ra_idx(i) + a_dims(i) > dimensions(i)) | 947 if (a_ra_idx (i) < 0 || (a_ra_idx (i) + a_dv (i)) > dimensions (i)) |
963 { | 948 { |
964 (*current_liboctave_error_handler) | 949 (*current_liboctave_error_handler) |
965 ("Array<T>::insert: range error for insert"); | 950 ("Array<T>::insert: range error for insert"); |
966 return *this; | 951 return *this; |
967 } | 952 } |
968 } | 953 } |
954 | |
955 a_ra_idx.elem (0) = 0; | |
956 a_ra_idx.elem (1) = 0; | |
957 | |
958 int n_elt = a.numel (); | |
959 | |
960 for (int i = 0; i < n_elt; i++) | |
961 { | |
962 Array<int> ra_idx = a_ra_idx; | |
963 | |
964 ra_idx.elem (0) = a_ra_idx (0) + r; | |
965 ra_idx.elem (1) = a_ra_idx (1) + c; | |
966 | |
967 elem (ra_idx) = a.elem (a_ra_idx); | |
968 | |
969 increment_index (a_ra_idx, a_dv); | |
970 } | |
971 } | |
972 else | |
973 (*current_liboctave_error_handler) | |
974 ("Array<T>::insert: invalid indexing operation"); | |
975 | |
976 return *this; | |
977 } | |
978 | |
979 template <class T> | |
980 Array<T>& | |
981 Array<T>::insert (const Array<T>& a, const Array<int>& ra_idx) | |
982 { | |
983 int n = ra_idx.length (); | |
984 | |
985 if (n == dimensions.length ()) | |
986 { | |
987 dim_vector a_dims = a.dims (); | |
988 | |
989 for (int i = 0; i < n; i++) | |
990 { | |
991 if (ra_idx(i) < 0 || ra_idx(i) + a_dims(i) > dimensions(i)) | |
992 { | |
993 (*current_liboctave_error_handler) | |
994 ("Array<T>::insert: range error for insert"); | |
995 return *this; | |
996 } | |
997 } | |
998 | |
969 | 999 |
970 #if 0 | 1000 #if 0 |
971 // XXX FIXME XXX -- need to copy elements | 1001 // XXX FIXME XXX -- need to copy elements |
972 | 1002 |
973 for (int j = 0; j < a_cols; j++) | 1003 for (int j = 0; j < a_cols; j++) |
2997 | 3027 |
2998 return retval; | 3028 return retval; |
2999 } | 3029 } |
3000 | 3030 |
3001 template <class T> | 3031 template <class T> |
3002 bool | 3032 bool |
3003 cat_ra (Array<T>& ra_cat, const Array<T>& ra_arg, int dim, int add_dim) | 3033 cat_ra (Array<T>& ra_cat, const Array<T>& ra_arg, int dim, int add_dim) |
3004 { | 3034 { |
3005 bool retval = false; | 3035 bool retval = false; |
3006 | 3036 |
3007 dim_vector dv = ra_arg.dims (); | 3037 dim_vector dv = ra_arg.dims (); |
3008 | 3038 |
3009 Array<int> ra_idx (dv.length (), 0); | 3039 Array<int> ra_idx (dv.length (), 0); |
3010 | 3040 |
3011 for (int i = 0; i < ra_arg.length (); i++) | 3041 for (int i = 0; i < ra_arg.length (); i++) |
3012 { | 3042 { |
3013 if (i != 0) | 3043 if (i != 0) |
3014 increment_index (ra_idx, dv); | 3044 increment_index (ra_idx, dv); |
3015 | 3045 |
3016 Array<int> ra_idx2 = ra_idx; | 3046 Array<int> ra_idx2 = ra_idx; |
3017 | 3047 |
3018 if (dim >= ra_idx2.length ()) | 3048 if (dim >= ra_idx2.length ()) |
3019 { | 3049 { |
3020 ra_idx2.resize_and_fill (dim + 1, 0); | 3050 ra_idx2.resize_and_fill (dim + 1, 0); |
3021 | 3051 |
3022 retval = true; | 3052 retval = true; |
3023 } | 3053 } |
3024 | 3054 |
3025 ra_idx2(dim) = ra_idx2(dim) + add_dim; | 3055 ra_idx2(dim) = ra_idx2(dim) + add_dim; |
3026 | 3056 |
3027 ra_cat(ra_idx2) = ra_arg(ra_idx); | 3057 ra_cat(ra_idx2) = ra_arg(ra_idx); |
3028 } | 3058 } |
3029 | 3059 |