bugGNU Octave - Bugs: bug #33292, trapz on matrices does not allow a...

 
 

bug #33292: trapz on matrices does not allow a vector as first argument

Submitted by:  Helios De Rosario <heliosdr>
Submitted on:  Wed 11 May 2011 05:02:02 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: FixedAssigned to: Jordi Gutiérrez Hermoso <jordigh>
Originator Name: Helios De RosarioOpen/Closed: Closed
Release: devOperating System: Microsoft Windows

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

(Jump to the original submission Jump to the original submission)

Thu 03 Aug 2017 12:46:17 PM UTC, comment #8:

I pushed the following changeset:

http://hg.savannah.gnu.org/hgweb/octave/rev/3d67c7b99546

Is there a better way?

John W. Eaton <jwe>
Project Administrator
Thu 03 Aug 2017 10:58:35 AM UTC, comment #7:

This bug is still in 4.2.1

produces

Should be: Matlab incompatibility.

Can anyone check that the patch is still valid?

Juan Pablo Carbajal <juanpi>
Project Member
Sat 14 May 2011 05:34:01 PM UTC, comment #6:

Thanks, I was still toiling with this today, but I see your approach is better. At any rate, I think I found a weird bug in bsxfun during my toiling, so it wasn't all in vain!

Jordi Gutiérrez Hermoso <jordigh>
Project AdministratorIn charge of this item.
Sat 14 May 2011 05:22:21 PM UTC, comment #5:

I checked in changes to the stable branch (http://hg.savannah.gnu.org/hgweb/octave/rev/d8aff843a9e9) which correct this bug. To access the changes you will need to download from the Mercurial archives and build from source, or wait for the 3.4.1 release. Instructions for downloading the source code are here (http://www.gnu.org/software/octave/download.html)

For Jordi, I took a slightly different approach from your patch. In your patch the pseudocode was

unwind_protect block
{
expand x to size of y with bsxfun
recursively call trapz with new x, old y matrices
}

If y is a large ND-array, then reproducing x to be the same size as y can be wasteful of memory. I also guessed that the overhead of an unwind_protect block and an extra function call might be heavy. Instead I tried something like this

extra_input_validation (which obviates unwind_protect)
{
reshape x vector to point along correct dimension
use bsxfun to implement trapz computation between a vector and a matrix
}

Benchmarking showed the new approach to take 84% less time. I didn't investigate further, so I still don't know which code construct is actually responsible for the slowdown.

Rik <rik5>
Project Administrator
Thu 12 May 2011 08:04:31 PM UTC, comment #4:

Yes, this works in Matlab. A friend just confirmed it. I'll modify my patch accordingly.

Jordi Gutiérrez Hermoso <jordigh>
Project AdministratorIn charge of this item.
Thu 12 May 2011 07:19:36 PM UTC, comment #3:

trapz is supposed to work for ND-arrays. Could the original poster verify that Matlab accepts vectors for the first argument even when the array is multi-dimensional? The proposed patch doesn't handle this case, but it may not be important if Matlab doesn't as well. Sample test code:

Rik <rik5>
Project Administrator
Wed 11 May 2011 06:55:46 PM UTC, comment #2:

Oops, left some stray debug code in trapz.patch, removed it in attached trapz-2.patch

(file #23390)

Jordi Gutiérrez Hermoso <jordigh>
Project AdministratorIn charge of this item.
Wed 11 May 2011 06:52:18 PM UTC, comment #1:

Confirmed in the dev sources. Attached is a proposed fix that uses bsxfun to expand the first argument to the size of the second. If there are no complaints within a few days, I'll push this fix to the stable branch.

(file #23389)

Jordi Gutiérrez Hermoso <jordigh>
Project AdministratorIn charge of this item.
Wed 11 May 2011 05:02:02 PM UTC, original submission:

According to documentation, the trapz function (and cumtrapz as well) assumes an equally spaced vector as first argument x, if it is ommited in the call. Thus, I expected the function to work when a vector is explicitly entered, even though the second argument is a matrix (whenever its first non-singleton dimension is equal to the lenght of x).

However, that does not work (unlike in MATLAB):

That can be easily solved by automatically expanding x to match the dimensions of y.

Helios De Rosario <heliosdr>

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #23390:  trapz-2.patch added by jordigh (4KiB - text/x-patch)
file #23389:  trapz.patch added by jordigh (4KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by juanpi (Posted a comment)
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by jordigh (Updated the item)
  • -unavailable- added by heliosdr (Submitted the item)
  •  

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

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 7 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sat 14 May 2011 05:22:21 PM UTCrik5StatusPatch Submitted=>Fixed
      Open/ClosedOpen=>Closed
    Wed 11 May 2011 06:55:46 PM UTCjordighAttached File-=>Added trapz-2.patch, #23390
    Wed 11 May 2011 06:52:18 PM UTCjordighAttached File-=>Added trapz.patch, #23389
      StatusNone=>Patch Submitted
      Assigned toNone=>jordigh
      Release3.2.4=>dev

    Back to the top


    Powered by Savane 3.1-cleanup1