Mercurial > hg > octave-lyh
comparison liboctave/Array.cc @ 4656:e3da702f7502
[project @ 2003-11-24 23:59:12 by jwe]
author | jwe |
---|---|
date | Mon, 24 Nov 2003 23:59:12 +0000 |
parents | 14ab7b05a572 |
children | a585a2dfca6c |
comparison
equal
deleted
inserted
replaced
4655:c8829691db47 | 4656:e3da702f7502 |
---|---|
2544 if (n_idx == 0) | 2544 if (n_idx == 0) |
2545 (*current_liboctave_error_handler) | 2545 (*current_liboctave_error_handler) |
2546 ("number of indices is zero"); | 2546 ("number of indices is zero"); |
2547 else if (n_idx == 1) | 2547 else if (n_idx == 1) |
2548 { | 2548 { |
2549 Array<int> one_arg_temp (1, 0); | 2549 idx_vector iidx = idx(0); |
2550 | 2550 |
2551 RT scalar = rhs.elem (one_arg_temp); | 2551 if (liboctave_wfi_flag |
2552 | 2552 && ! (iidx.is_colon () |
2553 lhs.fill (scalar); | 2553 || (iidx.one_zero_only () |
2554 && iidx.orig_dimensions () == lhs.dims ()))) | |
2555 (*current_liboctave_warning_handler) | |
2556 ("single index used for n-d array"); | |
2557 | |
2558 int lhs_len = lhs.length (); | |
2559 | |
2560 int len = iidx.freeze (lhs_len, "n-d arrray"); | |
2561 | |
2562 if (iidx) | |
2563 { | |
2564 if (len == 0) | |
2565 { | |
2566 if (! (rhs_dims.all_ones () || rhs_dims.all_zero ())) | |
2567 (*current_liboctave_error_handler) | |
2568 ("A([]) = X: X must be an empty matrix or scalar"); | |
2569 } | |
2570 else if (len <= lhs_len) | |
2571 { | |
2572 RT scalar = rhs.elem (0); | |
2573 | |
2574 for (int i = 0; i < len; i++) | |
2575 { | |
2576 int ii = iidx.elem (i); | |
2577 | |
2578 lhs.elem (ii) = scalar; | |
2579 } | |
2580 } | |
2581 else | |
2582 { | |
2583 (*current_liboctave_error_handler) | |
2584 ("A(I) = X: X must be a scalar or a matrix with the same size as I"); | |
2585 | |
2586 retval = 0; | |
2587 } | |
2588 } | |
2589 // idx_vector::freeze() printed an error message for us. | |
2554 } | 2590 } |
2555 else if (n_idx < lhs_dims.length ()) | 2591 else if (n_idx < lhs_dims.length ()) |
2556 { | 2592 { |
2557 // Number of indices is less than dimensions. | 2593 // Number of indices is less than dimensions. |
2558 | 2594 |
2753 { | 2789 { |
2754 elt_idx = get_elt_idx (idx, result_idx); | 2790 elt_idx = get_elt_idx (idx, result_idx); |
2755 | 2791 |
2756 if (index_in_bounds (elt_idx, lhs_inc)) | 2792 if (index_in_bounds (elt_idx, lhs_inc)) |
2757 { | 2793 { |
2758 int s = compute_index (result_rhs_idx,rhs_dims); | 2794 int s = compute_index (result_rhs_idx, rhs_dims); |
2759 | 2795 |
2760 lhs.checkelem (elt_idx) = rhs.elem (s); | 2796 lhs.checkelem (elt_idx) = rhs.elem (s); |
2761 | 2797 |
2762 increment_index (result_rhs_idx, frozen_rhs); | 2798 increment_index (result_rhs_idx, frozen_rhs); |
2763 } | 2799 } |