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:25:55 -0400

On Thu, May 23, 2013 at 12:39 AM, John W. Eaton <address@hidden> wrote:
On 05/22/2013 10: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?

I think it was intentional but probably also obsolete.

The index operation is const, so I'm not sure what it means to resize. Obviously, indexing can result in an array that is a different size than the array that is indexed.

I can't see where these functions are actually used with resize_ok = true.  If that's actually the case, then I'd be happy to remove these arguments.

I think I misunderstood the purpose of the function. As you say, the method is "const". I had assumed that the function would mutate the original array, but that's not possible because of const-ness. The purpose of the method is obviously not to change the array, but to index out-of-bound without generating an error. If the index is out-of-bound and the indexing is scalar, then you know immediately that the value to return is resize_fill_value.

Thanks for the hints anyway.

Michael.



reply via email to

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