[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #63080] Allow matrix power for sparse empty ma

From: Rik
Subject: [Octave-bug-tracker] [bug #63080] Allow matrix power for sparse empty matrices
Date: Mon, 19 Sep 2022 17:06:03 -0400 (EDT)

Update of bug #63080 (project octave):

                Category:                    None => Interpreter            


Follow-up Comment #2:

I have one small request and one question.

For the request, could you add a BIST test marked with regression indicator
for this bug report?  Something like

%!test <*63080> 
%! A = sparse ([]);
%! assert (A ^ 1, A);
%! assert (A ^ 0, A);
%! assert (A ^ -1, A);

One question is how to handle empty matrices which are not 0x0.  For example,

A = zeros (2,0);
A ^ 1;

In Octave, this returns a 0x0 empty matrix (original dimensions are lost)
while in Matlab this returns an error that the matrix must be square.

With this patch in place, the following code produces an error

A = sparse (zeros (2,0));
A ^ 1
error: for A^b, A must be a square matrix.  Use .^ for elementwise power.

This behavior is compatible with Matlab, but incompatible with Octave for full
matrices.  I would argue that Octave should be consistent with itself and
return the same result for full or sparse matrices.  One way to do that would
be to modify the test condition to

-  if (nr == 0 && nc == 0)
+  if (nr == 0 || nc == 0)

This still won't be completely identical because for full matrices the return
value always has dimensions 0x0.  We could make even that consistent by
returning an empty SparseMatrix.


Reply to this item at:


Message sent via Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]