bugGNU Octave - Bugs: bug #47287, accumarray unable to handle empty...

 
 

bug #47287: accumarray unable to handle empty list of subscripts

Submitter:  Carnë Draug <carandraug>
Submitted:  Sat 27 Feb 2016 06:23:12 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 05 Mar 2016 01:33:06 AM UTC, comment #2: 

I have pushed the following 2 commits:

http://hg.savannah.gnu.org/hgweb/octave/rev/2f402f7c1a0b

http://hg.savannah.gnu.org/hgweb/octave/rev/8cfc50637511

I'm not super happy with the first one, as I don't think it handles with the issue elegantly and adds a special case for n == 0. Still, it fixes the issue.

Carnë Draug <carandraug>
Group Member
Sun 28 Feb 2016 06:39:25 PM UTC, comment #1: 

I have attached a file that fixes this issue. It has two csets, fixing two different bug related bugs.

I found that this was not an issue for the special cases of sum, max, and min because they use a special code path. I still added test cases for them to avoid regressions in the future.

I don't really like the fix. I couldn't find an elegant way to do it, and had to resort to a "n != 0". If anyone has a better plan that would be great.

The second cset fixes a related issue which is being able to automatically find the output size when list of subscript is empty.

This whole thing introduce a Matlab incompatibility though (I guess it could be considered a Matlab bug). It was not on purpose but came out as a side effect of fixing the support for empty SUBS.

When FUNC returns a cell element, and SUBS is empty, we are now returning a cell array (previously we would error).  This makes sense to me, FUNC is meant to create a cell array. Matlab seems to always return an array of doubles.  However, we still only do this for the general case of '@(x) {x}'.


>> accumarray (zeros (0, 1), zeros (0, 1), [0 1] , @(x) {x})
ans = {}(0x1)
>> accumarray (zeros (0, 1), zeros (0, 1), [0 1] , @(x) {x+1})
ans = [](0x1)


(file #36499)

Carnë Draug <carandraug>
Group Member
Sat 27 Feb 2016 06:23:12 PM UTC, original submission:  

accumarray() does not handle an empty list of subscripts. Example:


>> accumarray (zeros (0, 1), zeros (0, 1), [0 1] , @(x) {x})
error: accumarray: subscript indices must be either positive integers less than 2^31 or logicals


I would expect to get back an empty matrix.

Carnë Draug <carandraug>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #36499:  accumarray-zero-length-dims.cset added by carandraug (3KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by carandraug (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-03-05 carandraug StatusNone Fixed
        Open/ClosedOpen Closed
        Release4.0.0 dev
    2016-02-28 carandraug Attached File- Added accumarray-zero-length-dims.cset, #36499

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code