[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: |
Arun Giridhar |
Subject: |
[Octave-bug-tracker] [bug #63080] Allow matrix power for sparse empty matrices |
Date: |
Mon, 19 Sep 2022 07:04:31 -0400 (EDT) |
URL:
<https://savannah.gnu.org/bugs/?63080>
Summary: Allow matrix power for sparse empty matrices
Project: GNU Octave
Submitter: arungiridhar
Submitted: Mon 19 Sep 2022 07:04:30 AM EDT
Category: None
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Unexpected Error or Warning
Status: None
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Release: dev
Discussion Lock: Any
Operating System: Any
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Mon 19 Sep 2022 07:04:30 AM EDT By: Arun Giridhar <arungiridhar>
Taking the matrix power of an empty sparse matrix fails in certain legal cases
even though passing an empty full matrix works fine:
A = sparse ([]);
A ^ 1
A ^ 0
A ^ -1
Oddly, non-integer exponents work even for sparse empty inputs, like A ^ 1.3
or A ^ -1.3.
The problem turned out to be this input validation in sparse-xpow.cc:
if (nr == 0 || nc == 0 || nr != nc)
error ("for A^b, A must be a square matrix. Use .^ for elementwise
power.");
The following change fixes it for me:
diff -r 6646f2b5a3d1 libinterp/corefcn/sparse-xpow.cc
--- a/libinterp/corefcn/sparse-xpow.cc Sat Sep 17 04:22:38 2022 -0400
+++ b/libinterp/corefcn/sparse-xpow.cc Mon Sep 19 06:46:27 2022 -0400
@@ -66,9 +66,12 @@ xpow (const SparseMatrix& a, double b)
octave_idx_type nr = a.rows ();
octave_idx_type nc = a.cols ();
- if (nr == 0 || nc == 0 || nr != nc)
+ if (nr != nc)
error ("for A^b, A must be a square matrix. Use .^ for elementwise
power.");
+ if (nr == 0 && nc == 0)
+ return a;
+
if (! xisint (b))
error ("use full(a) ^ full(b)");
I will push this after I get a bug number.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?63080>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #63080] Allow matrix power for sparse empty matrices,
Arun Giridhar <=