octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

octave "Most Wanted" feature


From: John W. Eaton
Subject: octave "Most Wanted" feature
Date: Wed, 29 Nov 2006 03:04:25 -0500

On 27-Nov-2006, robert bristow-johnson wrote:

| The proposed system would, of course, continue this constraint and add a
| new constraint in that index bases for each dimension (the base[]
| vector) would have to be equal for two arrays to be added.

I see no need for this restriction.  I think only the number of
elements should have to agree.

| The
| resulting array would have the same shape and base[] vector as the input
| arrays.

How about the resulting array has base 1 by default, unless declared
otherwise?  Isn't that what Fortran would do?  The dimensions of an
array are a local property.  This would be similar to the way Fortran
works:

      program main
      real a(0:2), b(1:3), c(3), d(2:4)
      a(0) = 0
      a(1) = 1
      a(2) = 2
      b(1) = 1
      b(2) = 2
      b(3) = 3
      c = a + b
      d = a + b
      do i = 1, 3
        print *, c(i), d(i+1)
      enddo
      end

| CONCATINATION:
| 
| This would also be a simple and straight-forward extension of how MATLAB
| presently concatinates arrays.  When we say:
| 
| A = [B C];

Likewise, I think the base of the result should be 1 unless declared
otherwise.

| FUNCTIONS THAT RETURN INDICES (min(), max(), find(), sort(), ind2sub(),
| and any others that I don't know about):
| It must be internally consistent (and certainly can be made to be).  The
| indices returned would be exactly like the 1-based indices returned
| presently in MATLAB except that the base index for the corresponding
| dimension (that defaults to one) would be added to each index.  That is,
| just like now in MATLAB, if:
| 
| [max_value, max_index] = max(A);
| 
| This must mean that A(max_index) is equal to max_value.

These are problematic.  I was thinking that the base should be a local
property, as it is in Fortran.  For example, think of writing a max
function that just returns the max value.  In Fortran it can be
something like this:

  real function madmax (a, n)
  integer n, i
  real a(n)
  madmax = a(1)
  do i = 2, n
    if (a(i) .gt. val)
      madmax = a(i)
    endif
  enddo
  return
  end

and you could call it with an array of any size or shape (even a
multidimensional array, provided that A is full (no leading dimension
problems) and N is the total number of elements.  But there is trouble
if we want to return an index that corresponds to the dimensions
declared in the caller.  If the full dimensions (lower and upper bound
or base plus number of elements) are passed to a function along with
the value, then I think we will have a lot of confusion, or a lot of
work to do.  For example, we will have confusion if all the code that
currently does something like

  function f (a)
    for i = 1:numel (a)
      a(i)
    endfor
  endfunction

fails to work when called like this:

  dimension a0 (0:10)
  f (a0)

and I think it would be unreasonable to expect users to remember to
write

  function f (a)
    n = numel (a);
    dimension a(1:n);
    for i = 1:n
      a(i)
    endfor
  endfunction

(and much work to change all existing functions to work properly if
this were required).

My intial reaction is also that it would be unacceptable to have just
some functions (like min and max) be special and know about the base
of their arguments (so they could return index values that correspond
to the base used in the caller) while others ignored that
information, but imagine that this is possible.  What happens for code
like this:

  function idx = f (a)
    n = numel (a);
    dimension a (10:n+10);
    [dummy, idx] = max (a);  ## IDX in the range 10:n+10
  endfunction

  a = zeros (10, 1);  ## indices in the range 1:10.
  idx = f (a)
  printf ("max of a is: %g\n", a(idx));

?

Maybe problems like this are why others think that this kind of change
is not really a good idea for this language?

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]