Another sparse indexing "bug"

Kim Hansen kimhanse at gmail.com
Tue Dec 18 06:52:50 CST 2007


On 12/17/07, John W. Eaton <jwe at bevo.che.wisc.edu> wrote:
> In Matlab, given
>
>  x = sparse (42);
>
> the indexing operation
>
>  x(ones(2,2,2))
>
> produces a 2x4 sparse matrix object with all elements set to 42 and
> Octave produces an error.  I'm not sure whether we should make Octave
> compatible in this case since the behavior is inconsistent with what
> happens for full arrays.  I guess the logic is that since sparse
> arrays can only have 2 dimensions, dimensions 2-N of the index are
> collapsed to dimension 2.

I think the error makes more sence than Matlabs collapsing, I would
like sparse matices to be as much as full as possible.

> Should we start collecting these differences and document them so that
> when (not if, I'm sure) people report these "bugs" we can just point
> to the documented differences that we have no plans to fix?

Sounds like a good idea, and with workarounds next to each
incompatability it would be easier to write code that would work on
both Matlab and Octave.

The compatible workaround for this case might be:
  x(ones(2,2,2)(:,:))

-- 
Kim Hansen
Vadgårdsvej 3, 2.tv
2860 Søborg
Fastnet: 3956 2437  --  Mobil: 3091 2437



More information about the Bug-octave mailing list