octave-maintainers
[Top][All Lists]
Advanced

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

questions about recent changes


From: John W. Eaton
Subject: questions about recent changes
Date: Thu, 26 Mar 2009 12:29:16 -0400

You made the following change to Array.h:

  -  dim_vector dims (void) const { return dimensions; }
  +  // Return a const-reference so that dims ()(i) works efficiently.
  +  const dim_vector& dims (void) const { return dimensions; }

I'm not opposed to making a change like this, but we could make
similar changes to many other functions in Octave, so maybe we should
defer this until we can look at doing it more globally.  It seems odd
to me to just make the change in this one place.  Also, I'm not sure I
see the need to do this at all since dim_vectors are reference counted
and copying them should be fairly fast (copy a pointer and increment a
reference count).  Also, how often is "dims()(i)" actually used?  Does
making this change have a noticeable effect on performance?

You also changed dim_vecctor::numel so that it is now

  octave_idx_type numel (int n = 0) const
  {
    int n_dims = length ();

    octave_idx_type retval = 1;

    for (int i = n; i < n_dims; i++)
      retval *= elem (i);

    return retval;
  }

With this definition and an object with dimensions [1, 0, 2, 3],
dims.numel(2) will return 6.  Is that what you want?  I suppose this
could help with doing things like

  x = zeros (1, 0, 2, 3)
  x(1,:,:)
    => [](1,0,6)

Is it used anywhere yet?

Should the Array::numel and octave_value::numel functions also accept
an optional argument to specify the starting dimension?  Maybe it
would be helpful to add a comment explaining the intent of N here.

jwe


reply via email to

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