Mercurial > octave-nkf
comparison liboctave/Array.cc @ 5992:4289ed95dde8
[project @ 2006-09-15 20:29:18 by jwe]
author | jwe |
---|---|
date | Fri, 15 Sep 2006 20:29:18 +0000 |
parents | 0dd8428bb260 |
children | 4036e6fca790 |
comparison
equal
deleted
inserted
replaced
5991:265723390e7b | 5992:4289ed95dde8 |
---|---|
2356 return retval; | 2356 return retval; |
2357 } | 2357 } |
2358 | 2358 |
2359 template <class T> | 2359 template <class T> |
2360 Array<T> | 2360 Array<T> |
2361 Array<T>::index (Array<idx_vector>& ra_idx, int resize_ok, const T&) const | 2361 Array<T>::index (Array<idx_vector>& ra_idx, int resize_ok, const T& rfv) const |
2362 { | 2362 { |
2363 // This function handles all calls with more than one idx. | 2363 // This function handles all calls with more than one idx. |
2364 // For (3x3x3), the call can be A(2,5), A(2,:,:), A(3,2,3) etc. | 2364 // For (3x3x3), the call can be A(2,5), A(2,:,:), A(3,2,3) etc. |
2365 | 2365 |
2366 Array<T> retval; | 2366 Array<T> retval; |
2379 if (iidx.capacity () == 1 && trim_trailing_singletons) | 2379 if (iidx.capacity () == 1 && trim_trailing_singletons) |
2380 ra_idx_len--; | 2380 ra_idx_len--; |
2381 else | 2381 else |
2382 trim_trailing_singletons = false; | 2382 trim_trailing_singletons = false; |
2383 | 2383 |
2384 for (octave_idx_type i = 0; i < iidx.capacity (); i++) | 2384 if (! resize_ok) |
2385 if (iidx (i) != 0) | 2385 { |
2386 { | 2386 for (octave_idx_type i = 0; i < iidx.capacity (); i++) |
2387 (*current_liboctave_error_handler) | 2387 if (iidx (i) != 0) |
2388 ("index exceeds N-d array dimensions"); | 2388 { |
2389 | 2389 (*current_liboctave_error_handler) |
2390 return retval; | 2390 ("index exceeds N-d array dimensions"); |
2391 } | 2391 |
2392 return retval; | |
2393 } | |
2394 } | |
2392 } | 2395 } |
2393 | 2396 |
2394 ra_idx.resize (ra_idx_len); | 2397 ra_idx.resize (ra_idx_len); |
2395 | 2398 |
2396 dim_vector new_dims = dims (); | 2399 dim_vector new_dims = dims (); |
2435 { | 2438 { |
2436 elt_idx = get_elt_idx (ra_idx, result_idx); | 2439 elt_idx = get_elt_idx (ra_idx, result_idx); |
2437 | 2440 |
2438 octave_idx_type numelem_elt = get_scalar_idx (elt_idx, new_dims); | 2441 octave_idx_type numelem_elt = get_scalar_idx (elt_idx, new_dims); |
2439 | 2442 |
2440 if (numelem_elt > length () || numelem_elt < 0) | 2443 if (numelem_elt >= length () || numelem_elt < 0) |
2441 (*current_liboctave_error_handler) | 2444 retval.elem (i) = rfv; |
2442 ("invalid N-d array index"); | |
2443 else | 2445 else |
2444 retval.elem (i) = elem (numelem_elt); | 2446 retval.elem (i) = elem (numelem_elt); |
2445 | 2447 |
2446 increment_index (result_idx, frozen_lengths); | 2448 increment_index (result_idx, frozen_lengths); |
2447 | 2449 |