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 11:23:40 -0400

On Thu, May 23, 2013 at 1:31 AM, John W. Eaton <address@hidden> wrote:
On 05/23/2013 01:15 AM, John W. Eaton wrote:
On 05/23/2013 12:39 AM, John W. Eaton wrote:

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 did some more digging and I do see that it is used in ov-class.cc, at
least.

Also through the "auto_add" parameter of the octave_value::subsref that was apparently added by Jaroslav.  That's set to true in one case in tree_index_expression::lvalue.

Given the comments in Array.h:

  // Indexing with possible resizing and fill
  // FIXME -- this is really a corner case, that should better be
  // handled directly in liboctinterp.

maybe we should fix libinterp now so that it handles the special cases and eliminate them from the Array class index functions?
 
Actually I've another question concerning that method. I've changed my code in classdef, but found another issue.

Let's say my Array object is 2x2x2. Then I try to index it with (2,2) (no 3rd index). My current code is first trying to perform the index operation (with resize_ok = true) and if the returned cdef_object is invalid, meaning the index is out-of-bound, it creates a new object and assign into the array.

If you follow the code in Array::index (line 1086 in Array.cc):
- "tmp" is initially 2x2x2
- "ial" == 2 (only 2 indices given)
- "dv" is [2, 4] (3rd dimension folded into the second)
- "dvx" is [2, 4], even after extension
- so for the test "! (dvx == dv)", "dvx" and "dv" are the same and the if-block is skipped

And this is were the problem occurs. For the next if-test, "tmp.dimensions != dvx", "tmp" is still 2x2x2 and it doesn't match "dvx", so the whole method returns an empty array. Is that the right thing to do? At that point, there's no way the if-test can succeed if the number of indices given in "ia" doesn't match the number of dimensions in the array. However, the indexing can still be in-bound and "valid", like:

x = rand(2,2,2)
x(2,2) => returns the element at position (2,2,1)

As a side note, what I'm trying to achieve here is to check whether a given index-list corresponds to an existing element in the array, without generating an out-of-bound error. Maybe there's another way to do it?

Michael.


reply via email to

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