bugGNU Octave - Bugs: bug #50238, sum, cumsum, etc. mishandle...


bug #50238: sum, cumsum, etc. mishandle integer inputs

Submitted by:  None
Submitted on:  Mon 06 Feb 2017 12:08:57 PM UTC  
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Confirmed Assigned to:  None
Originator Name:  Luke Trowbridge Originator Email:  -email is unavailable-
Open/Closed:  Open Release:  4.2.0
Operating System:  Any

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Mon 06 Feb 2017 04:14:01 PM UTC, comment #2: 

The issue indeed seems to be with cumsum: by default, Octave performs the operation as double while Matlab uses the same class as the input and does not provide a mechanism to change this behavior:

>> a = uint8([150 150]);
>> sum(a)

ans =


>> sum(a,'native')

ans =



>> cumsum(a)

ans =

  1×2 uint8 row vector

   150   255

>> cumsum(a,'native')
Error using cumsum
Invalid option. Option must be 'forward', 'reverse', 'omitnan' or 'includenan'.

Guillaume <gyom>
Mon 06 Feb 2017 01:16:58 PM UTC, comment #1: 

Confirmed.  It looks like we have some issues with the optional argument specifying how the operation should be performed.  Matlab doesn't seem to have this argument for the cumulative functions.  And Octave is returning double for cumsum by default, same as for sum.  I think we need to start with some tests to see exactly what we are aiming for.

John W. Eaton <jwe>
Project Administrator
Mon 06 Feb 2017 12:08:57 PM UTC, original submission:  

I execute the following code:

a = uint8([150 150]);

% Calulate sum
s1 = sum(a);
s2 = a(1) + a(2);

% Calculate cumulative sum
cs1 = cumsum(a);
cs2(1) = a(1);
cs2(2) = a(1) + a(2);

and I get the following output:

s1 =  300
s2 = 255
cs1 =

   150   300

cs2 =

  150  255

I expected s1 to be equivalent to s2, and cs1 to be equivalent to cs2.



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

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by gyom (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-02-06 jwe StatusNone => Confirmed
        Operating SystemMicrosoft Windows => Any
        SummaryFunctions "sum" & "cumsum" handle data types differently than "+" operator => sum, cumsum, etc. mishandle integer inputs

    Back to the top

    Powered by Savane 3.5