octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #61690] Behavior of sum() with empty inputs


From: Nicholas Jankowski
Subject: [Octave-bug-tracker] [bug #61690] Behavior of sum() with empty inputs
Date: Mon, 4 Apr 2022 20:26:38 -0400 (EDT)

Follow-up Comment #4, bug #61690 (project octave):

i'm not set up to compile c-code, so haven't checked your patch, but looking
at sum, and having played with some other functions that have odd outputs from
different empty inputs, the following are also expected by matlab (2021b):


>> sum([],1)
ans =
  1×0 empty double row vector

>> sum([],2)
ans =
  0×1 empty double column vector

>> sum(ones(0,0),1)
ans =
  1×0 empty double row vector

>> sum(ones(0,0),2)
ans =
  0×1 empty double column vector

>> sum(ones(1,0),2)
ans =
     0

>> sum(ones(3,0),2)
ans =
     0
     0
     0

>> sum(ones(1,0),1)
ans =
  1×0 empty double row vector

>> sum(ones(3,0),1)
ans =
  1×0 empty double row vector

>> sum(ones(1,0),2)
ans =
     0

>> sum(ones(3,0),2)
ans =
     0
     0
     0

>> sum(ones(3,0),3)
ans =
  3×0 empty double matrix

>> sum(ones(3,0,4,2),3)
ans =
  3×0×1×2 empty double array


what it appears to be doing is pre-casting the output with something like


size_output = size(input);
size_output(dim) = 1;
output = zeros(size_output);


how does your fix address or change sum for inputs like those?  (i didn't test
them against Octave, so maybe they already work? I see now that sum already
has a number of empty input tests in /libinterp/corefcn/data.cc, but strangely
none for a [] input. so you should verify that your fix doesn't break any of
those tests, and add BISTs to data.cc that capture this fix.) 

and do any other functions than sum rely on this function in mx-inlines.cc?
would want to make sure it doesn't change or break any other functions while
trying to fix sum.

for commit messages, use imperative tense, not past tense (tell what happens
when i apply the patch, not what you did in creating it.) So "Resolve" not
"Resolved",  Extend" not "Extended", etc.


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?61690>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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