octave-maintainers
[Top][All Lists]
Advanced

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

Re: Question about Array::index with resizing


From: Michael Goffioul
Subject: Re: Question about Array::index with resizing
Date: Thu, 23 May 2013 07:21:00 -0400

On Thu, May 23, 2013 at 12:14 AM, Daniel J Sebald <address@hidden> wrote:
On 05/22/2013 09:06 PM, Michael Goffioul wrote:
Could anybody enlighten me about the implementation of

Array<T>
Array<T>::index (const Array<idx_vector>& ia,
                  bool resize_ok, const T& rfv) const

I'm trying to use it in the classdef branch, assuming this function
would resize the array is the given index is out of bound. In my case,
"ia" contains only scalars, so the variable "all_scalars" ends up being
true. But then the code does:

           if (all_scalars)
             return Array<T> (dim_vector (1, 1), rfv);

In other words, the code always return an array with a single element
being the resize_fill_value. No resizing or array indexing actually
takes place.

Is it intentional? Unimplemented? Or am I missing something?

My guess is that it's probably intentional in the sense it is the best that can be done without issuing some type of error.  There is resizing, but only provided it can be done properly.

This hunk of code:

      for (int i = 0; i < ial; i++) dvx(i) = ia(i).extent (dv (i));
      if (! (dvx == dv))

verifies that the index arrays are all within proper extent.  If the two vectors don't match, then something was outside of extent.

I have a different interpretation: the above code extent dvx such that it contains dv. If the result dvx is different than dv, this means the given index is out of bound and the array needs indexing.

But it doesn't matter, I think I misunderstood the purpose of the function.

Michael.


reply via email to

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