[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
x(idx)=y(idx) for empty idx
From: |
John W. Eaton |
Subject: |
x(idx)=y(idx) for empty idx |
Date: |
Fri, 5 Mar 2004 10:40:49 -0600 |
On 3-Mar-2004, Paul Kienzle <address@hidden> wrote:
| Consider:
|
| y = rand(100);
| idx = y>1;
| y(idx) = y(idx)-1;
|
| With warn_fortran_indexing=1, this prints:
|
| warning: A(idx) = []: expecting A to be row or column vector or scalar
|
| As a result we have a bunch of code like this:
|
| idx = condition;
| if any ( idx (:))
| A(idx) = f(A(idx));
| end
|
| instead of:
|
| idx = condition;
| A(idx) = f(A(idx));
Please try the following patch. It eliminates the warning you see
above and also fixes a bug (if the warning flag was set, deleting
elements didn't work at all).
You will still see a warning about "single index used for matrix" in
the 2-d case. For N-d arrays, there is no warning.
Yes, we should be consistent here. I hope that all the different
indexing and indexed assignment functions will eventually be combined
so we only have one of each. But first, I think the N-d versions
could use some more work.
Thanks,
jwe
2004-03-05 John W. Eaton <address@hidden>
* Array.cc (Array<T>::maybe_delete_elements_2):
Omit Fortran-indexing warning.
Index: liboctave/Array.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/liboctave/Array.cc,v
retrieving revision 1.108
diff -u -r1.108 Array.cc
--- liboctave/Array.cc 5 Mar 2004 16:19:11 -0000 1.108
+++ liboctave/Array.cc 5 Mar 2004 16:34:03 -0000
@@ -1270,14 +1270,6 @@
n = nr * nc;
nr = 1;
nc = n;
-
- if (liboctave_wfi_flag)
- {
- (*current_liboctave_warning_handler)
- ("A(idx) = []: expecting A to be row or column vector or scalar");
-
- return;
- }
}
if (idx_arg.is_colon_equiv (n, 1))