bugGNU Octave - Bugs: bug #40105, Logical diagonal matrices are not...

 
 

bug #40105: Logical diagonal matrices are not supported

Submitted by:  David Spies <dspyz>
Submitted on:  Wed 25 Sep 2013 11:00:56 PM UTC  
 
Category: Octave FunctionSeverity: 2 - Minor
Priority: 5 - NormalItem Group: Feature Request
Status: ConfirmedAssigned to: None
Originator Name: Open/Closed: Open
Release: devOperating System: GNU/Linux

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

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

 

Tue 22 Oct 2013 06:08:56 PM UTC, comment #4:

You can always use spdiags. For example

and sparse matrices are on both sides of the multiplication operator, and the conversion to a full matrix never happens. THis has the advantage of working similarly with matlab.

I agree it might be nice to have this but it seems a hell of a lot of effort to introduce a new type for this an instaniate all of the operators between thix new type and the existing types.

David

David Bateman <dbateman>
Project Member
Mon 21 Oct 2013 11:25:39 PM UTC, comment #3:

Logical matrix multiplication comes up quite a lot. Of course, I could just convert to a matrix of doubles, but that would be a workaround.

As an example, suppose I have a logical matrix A where each row represents a set (and all sets are unique). Now suppose I want to remove any set which is a subset of another row (such as when finding all maximal cliques in an undirected graph).

cardinality = sum(A,2);
coincidence = A * A'; %Logical matrix multiplication
subsets = any(coincidence == cardinality, 2); % Using automatic broadcasting with ==
A = A(~subsets,:);

As an example of where logical diagonal matrix multiplication comes in handy, suppose I want to mux the rows from matrices A and B according to a logical column vector s

res = (diag(~s) * A) | (diag(s) * B);

David Spies <dspyz>
Sun 20 Oct 2013 07:33:34 PM UTC, comment #2:

Matlab doesn't have diagonal matrices at all, and should you really be trying to multiply logical matrices. These seems like a nice to have option but really quite a low priority

D.

David Bateman <dbateman>
Project Member
Thu 26 Sep 2013 05:00:32 PM UTC, comment #1:

I think the problem is actually that diag doesn't support logical matrices. If I break the problem up I can see that the multiplication is between a SPARSE matrix and a FULL matrix and the rules are that the SPARSE matrix is coerced into a full matrix.

On the other hand, If I use double values which diag() does support in the special diagonal matrix class then I get the right result.

I'm going to re-title the report to indicate that logical diagonal matrices are not supported.

Simple test code for this is

which should return "logical diagonal matrix".

Rik <rik5>
Project Administrator
Wed 25 Sep 2013 11:00:56 PM UTC, original submission:

When multiplying a logical sparse matrix by a logical diagonal matrix, the result is a full matrix

logical(speye(3)) * diag(logical([1,1,1]))

ans =

1 0 0
0 1 0
0 0 1

It should be a sparse matrix

David Spies <dspyz>

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by dbateman (Posted a comment)
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by dspyz (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 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 20 Oct 2013 07:33:34 PM UTCdbatemanItem GroupIncorrect Result=>Feature Request
    Thu 26 Sep 2013 05:00:32 PM UTCrik5Severity3 - Normal=>2 - Minor
      StatusNone=>Confirmed
      SummaryMultiplying a logical sparse matrix by a logical diagonal matrix gives a full matrix=>Logical diagonal matrices are not supported

    Back to the top


    Powered by Savane 3.1-cleanup