bugGNU Octave - Bugs: bug #59718, Workaround for operators involving...

 
 

bug #59718: Workaround for operators involving a sparse matrix and broadcasting

Submitted by:  None
Submitted on:  Fri 18 Dec 2020 07:46:09 AM UTC  
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  None Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  Open Release:  6.1.0
Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

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

 

Fri 18 Dec 2020 07:46:09 AM UTC, original submission:  

The following has been a bug for over 6 years

bug #41441
bug #55126
bug #55141

q=rand(2);
w=rand(2,1);
q+w;%works fine
sparse(q)+w;%error: mx_el_eq: nonconformant arguments (op1 is 2x2, op2 is 2x1)
sparse(q)+sparse(w);%error: mx_el_eq: nonconformant arguments (op1 is 2x2, op2 is 2x1)
q+sparse(w);%error: mx_el_eq: nonconformant arguments (op1 is 2x2, op2 is 2x1)

The same issue is also present for:
.*
./
.\
.^
==
<=

>=

<

>

!=
|
&

I have attached an incomplete workaround as a proof of concept which could be completed with a few more days work. However,I believe fixing the underlying problem will be a much better solution. I expect to fix the underlying problem the existing sparse class will need to be updated with code which does the same thing as my workaround. Unless the underlying implementation is the worst mess ever written it will probably be quicker to fix it than to finish the attached workaround.

The workaround creates a new class called sparse. The constructor calls the builtin sparse and saves the result into a field. I then overloaded + .* ./ and .\ to perform the operators correctly. The code is almost identical for each operator so a copy and past changing the operator will fix the remaining unimplemented ones.

This workaround then breaks every other built in function. So they all also need to be overridden. I have implemented * to demonstrate this. This task would be much less involved if there was an override for a generic function, something like:

function varargout=fornothingwrongwithexistingsparsefunction(varargin)
  for k=1:nargin()
  if isa(varargin{k},"sparse")
    varargin{k}=varargin{k}.value;
  end
end
varargout=nthargout(1:nargout(),f,varargin{:});
end

I do not know how to get the function f that was called or how to get this function to be called for all functions I have not specifically overridden. See line 100 of the attached code for a working implementation of the above for mtimes.

If overriding everything is the only option, this workaround will require lots of copy and pasting to finish. This task will be difficult to complete without introducing bugs and will break every time a new function is added or renamed. It also introduces unnecessary overhead on all function calls.

Anonymous

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #50507:  sparse.m added by None (4KiB - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

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

Only project members can vote.

 

 

 

Follows 1 latest change.

Date Changed by Updated Field Previous Value => Replaced by
2020-12-18 None Attached File- => Added sparse.m, #50507

Back to the top


Powered by Savane 3.5