# bug #40105: Logical diagonal matrices are not supported

 Submitted by: David Spies Submitted on: Wed 25 Sep 2013 11:00:56 PM UTC Category: Octave Function Severity: 2 - Minor Priority: 5 - Normal Item Group: Feature Request Status: Confirmed Assigned to: None Originator Name: Open/Closed: Open Release: dev Operating System: GNU/Linux

You are not logged in

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>
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>
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>
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 Files:

Comment:

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 dbateman (Posted a comment)
• -email is unavailable- added by rik5 (Posted a comment)
• -email is unavailable- added by dspyz (Submitted the item)
•

Do you think this task is very important?
This task has 0 encouragements so far.

Only project members can vote.