SCM

[#6728] Missing row/column name in 1X1 matrix after multiplication

Date:
2021-06-10 08:04
Priority:
3
State:
Closed
Submitted by:
Øyvind Langsrud (olangsrud)
Assigned to:
Nobody (None)
Hardware:
None
Product:
None
Operating System:
None
Component:
None
Version:
None
Severity:
None
Resolution:
None
URL:
Summary:
Missing row/column name in 1X1 matrix after multiplication

Detailed description
I would expect the result of all four lines below to give myrow and mycol as row and column names, but the first two lines give only row name and the last two lines give only column name (Windows 10 x64, R x64 4.2.0 Pre-release, Matrix_1.3-4).

Matrix(0, dimnames = list("myrow", NULL)) %*% Matrix(0, dimnames = list(NULL, "mycol"))

Matrix(1, dimnames = list("myrow", NULL)) %*% Matrix(0, dimnames = list(NULL, "mycol"))

Matrix(0, dimnames = list("myrow", NULL)) %*% Matrix(1, dimnames = list(NULL, "mycol"))

Matrix(1, dimnames = list("myrow", NULL)) %*% Matrix(1, dimnames = list(NULL, "mycol"))

Comments:

Message  ↓
Date: 2022-09-25 00:41
Sender: Mikael Jagan

Fixed now, with r3670, for all products involving diagonalMatrix or indMatrix. It is likely that there are other products with similar problems. I hope to get to those in time. Thanks for the report.

Date: 2022-08-21 13:00
Sender: Øyvind Langsrud

Thanks, I will continue with a workaround in my code where problems occur for 1*1 matrices. In the case of a%*%b where b is diagonal, I think it is a good solution that a's column names are kept if b has none. So the base R solution might not be the best either.

Date: 2022-08-20 20:21
Sender: Mikael Jagan

Yes, many of our product methods involving diagonalMatrix do not currently (r3596) respect the conventional handling of 'dimnames' by base::`%*%`. This can be improved, but probably not in time for Matrix 1.4-2. For reference:

> selectMethod("%*%", c("diagonalMatrix", "diagonalMatrix"))
Method Definition:

function (x, y)
{
dimCheck(x, y)
if (x@diag != "U") {
if (y@diag != "U") {
nx <- x@x * y@x
if (is.numeric(nx) && !is.numeric(x@x))
x <- ..diag2d(x)
x@x <- as.double(nx)
}
x
}
else y
}
<bytecode: 0x15bcd2a20>
<environment: namespace:Matrix>

Signatures:
x y
target "diagonalMatrix" "diagonalMatrix"
defined "diagonalMatrix" "diagonalMatrix"

Attached Files:

Changes

Field Old Value Date By
status_idOpen2022-09-25 00:41jaganmn
close_dateNone2022-09-25 00:41jaganmn
Thanks to:
Vienna University of Economics and Business Powered By FusionForge