bugGNU Octave - Bugs: bug #40813, atan2, fmod, hypot returns no...

 
 

bug #40813: atan2, fmod, hypot returns no results for sparse matrices

Submitter:  Rik <rik5>
Submitted:  Thu 05 Dec 2013 01:14:41 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 04 Jun 2014 05:13:27 PM UTC, comment #8: 

Well, there's not much left from my original patch - so thanks for keeping the author name. :)

Stefan Mahr <dac922>
Mon 02 Jun 2014 05:15:42 PM UTC, comment #7: 

@Stefan: I compacted your Sparse-Sparse implementation and checked it in on the stable branche here (http://hg.savannah.gnu.org/hgweb/octave/rev/658d23da2c46).

Next, I added my modifications for the scalar-Sparse, Sparse-scalar routines (http://hg.savannah.gnu.org/hgweb/octave/rev/dccbc8bff5cb).  I also added built-in self-tests (%!tests) which was part of the problem.  The issue with the original changeset back in 3.2.X would have been caught if there had been tests for the sparse implementations.

Finally, I marked the atan2 functions which are part of the Sparse class as deprecated.  They will be deleted in Octave 4.4.  Nothing in the core is using these implementations, since everything is piped through binmap.  However, there might be someone out there who is using atan2 directly in an oct-file so I thought I would give them some warning before removing the code.


Rik <rik5>
Group administrator
Sun 01 Jun 2014 03:27:42 PM UTC, comment #6: 

Rik, if you have time to review my patch, please use the latest one from here:
http://inversethought.com/hg/octave-nkf/graph/nkf-ready

Since I can't push to Jordis hg server, I attach my latest patch for the binmap - sparse/sparse problem


(file #31482)

Stefan Mahr <dac922>
Sun 01 Jun 2014 03:25:04 PM UTC, comment #5: 

The problems with this section of code just keep expanding.  In addition to no results, and infinite loops, the following code will cause a segfault.


hypot (sparse ([0 0]), sparse ([0 1]))


I've re-written the scalar-Sparse and Sparse-scalar functions.  It looks like Sparse-Sparse needs to be re-written as well.

Rik <rik5>
Group administrator
Thu 29 May 2014 07:47:53 PM UTC, comment #4: 

Yes, the infinite loop problem is located somewhere in the for-loop around oct-binmap.h:258

Stefan Mahr <dac922>
Thu 29 May 2014 03:25:13 PM UTC, comment #3: 

Using Mercurial I have traced the problem back to changeset 6a271334750c.  In that changeset the implementation of atan2, fmod, and hypot were switched over to binmap().

Indeed, the first problem that I reported with atan2 also exists for fmod.


fmod (sparse (11), sparse ([2 3]))
ans =

Compressed Column Sparse (rows = 1, cols = 2, nnz = 0 [0%])

BUT

fmod (sparse ([11 11]), sparse ([2 3]))
ans =

Compressed Column Sparse (rows = 1, cols = 2, nnz = 2 [100%])

  (1, 1) ->  1
  (1, 2) ->  2


So part of the problem seems to be that a scalar is not expanded in the same way as it would be for a full matrix.  I won't have time to look at this or the submitted patch until the weekend.



Rik <rik5>
Group administrator
Mon 20 Jan 2014 05:12:20 PM UTC, comment #2: 

While debugging if found, this code ends in an infinite loop


atan2(sparse([1 0]),sparse([0 1]))


Stefan Mahr <dac922>
Mon 20 Jan 2014 04:54:57 PM UTC, comment #1: 

Attached a possible fix. Don't know if 'copy_or_memcopy' is ok here, but seems the be the fastest solution.

One option would be to copy the whole sparse matrix using existing method, but then data is copied for nothing. Other possibility is to rewrite column and row index within for loop, but this is slow. Third option: Create new method?

Also, MATLABs behaviour differs a little bit. This is also fixed with the attached patch.

This is the MATLAB result:

>>     x=sparse([1 2]);
>>     atan2(x,x)
ans =
   (1,1)            0.785398163397448
   (1,2)            0.785398163397448
>>     atan2(x,2)
ans =
   (1,1)            0.463647609000806
   (1,2)            0.785398163397448
>>     atan2(x,[1 2])
ans =
   (1,1)            0.785398163397448
   (1,2)            0.785398163397448
>>
>>     atan2(2,x)
ans =
          1.10714871779409         0.785398163397448
>>     atan2([1 2],x)
ans =
         0.785398163397448         0.785398163397448



(file #30320)

Stefan Mahr <dac922>
Thu 05 Dec 2013 01:14:41 AM UTC, original submission:  

atan2 seems to have been broken in the transition from 3.2 (works) to 3.4.

The following simple call to atan2 should work, but returns nothing instead.


x = sparse ([1 2]);
atan2 (x, 2)
ans =

Compressed Column Sparse (rows = 1, cols = 2, nnz = 0 [0%])


For possible reference, there is atan2 code in liboctave/array/dSparse.cc but it is never called.  Using gdb I found that the pathway is actually to the Sparse-Scalar template in liboctave/util/oct-binmap.h

Rik <rik5>
Group administrator

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #31482:  binmap.diff added by dac922 (4KiB - text/x-patch)
file #30320:  atan2_spare.patch added by dac922 (2KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dac922 (Updated the item)
  • -email is unavailable- added by rik5 (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 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-06-02 rik5 StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2014-06-01 dac922 Attached File- Added binmap.diff, #31482
    2014-06-01 rik5 StatusNone In Progress
    2014-05-29 rik5 Summaryatan2 returns no results for sparse matrices atan2, fmod, hypot returns no results for sparse matrices
    2014-01-20 dac922 Attached File- Added atan2_spare.patch, #30320

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code