SCM

Forum: help

Monitor Forum | Start New Thread Start New Thread
RE: cBind/rBind of boolean and numeric matrices results with a boolean matrix [ Reply ]
By: Martin Maechler on 2015-03-12 15:47
[forum:42012]
Thank you, Shay!

You are right indeed. I could argue that this is a bug in the underlying CHOLMOD
horzcat() and vertcat() routines:
The current C code decides to only compute numeric "values" if *both* matrices
are *not* patter"n" matrices:

values = values &&
(A->xtype != CHOLMOD_PATTERN) && (B->xtype != CHOLMOD_PATTERN) ;

I will work around this by coercing the "nMatrix" to "l" or "d" before passing it to CHOLMOD.

Thank you again for the bug report (bug indeed),
Martin

cBind/rBind of boolean and numeric matrices results with a boolean matrix [ Reply ]
By: Shay Zakov on 2015-03-12 12:47
[forum:42011]
Hi,

A possible bug report:
Applying cBind or rBind over sparse matrices, when one of the matrices is of type ngCMatrix (i.e. boolean) and the other is not, the resulting matrix takes a boolean form rather than taking the more general form.

Example:

> m1 <- sparseMatrix(1:3, 1:3)
> m1
3 x 3 sparse Matrix of class "ngCMatrix"

[1,] | . .
[2,] . | .
[3,] . . |

> m2 <- sparseMatrix(1:3, 1:3, x = 1:3)
> m2
3 x 3 sparse Matrix of class "dgCMatrix"

[1,] 1 . .
[2,] . 2 .
[3,] . . 3

> cBind(m1, m2)
3 x 6 sparse Matrix of class "ngCMatrix"

[1,] | . . | . .
[2,] . | . . | .
[3,] . . | . . |

This is unexpected, and can be overcome e.g. by multiplying the ngCMatrix matrix by 1, but I guess it would be better to solve it in the package level:

> cBind(m1*1, m2)
3 x 6 sparse Matrix of class "dgCMatrix"

[1,] 1 . . 1 . .
[2,] . 1 . . 2 .
[3,] . . 1 . . 3

Best,

Shay


Thanks to:
Vienna University of Economics and Business Powered By FusionForge