[Rd] qr.coef and complex numbers - still busted for non-square case? (PR#13305)
whorfin at pixar.com
whorfin at pixar.com
Wed Nov 19 19:50:09 CET 2008
Full_Name: Rick Sayre
Version: 2.8.0
OS: windows, linux, os x
Submission from: (NULL) (138.72.153.166)
PR#8476 and PR#8478
http://bugs.r-project.org/cgi-bin/R/Models-fixed?id=8478
http://bugs.r-project.org/cgi-bin/R/Models-fixed?id=8476
discuss fixing qr.coef to handle complex matrices correctly
But it appears the solution now "shipping" only handles square matrices.
In 2.8.0 [linux, windows, and os x] non-square complex arguments cause
an error.
> qr.solve(cbind(1:11,1),2*(20:30))
[1] 2 38
> qr.solve(cbind(as.complex(1:11),as.complex(1)),as.complex(2*(20:30)))
Error in coef[qr$pivot, ] <- .Call("qr_coef_cmplx", qr, y, PACKAGE = "base") :
number of items to replace is not a multiple of replacement length
If I change the section shown by context below from qr.coef as follows:
if (is.complex(qr$qr)) {
if (!is.complex(y))
y[] <- as.complex(y)
coef <- matrix(NA_complex_, nrow = p, ncol = ny)
#coef[qr$pivot, ] <- .Call("qr_coef_cmplx", qr, y, PACKAGE = "base")
coef[qr$pivot, ] <- .Call("qr_coef_cmplx", qr, y, PACKAGE = "base")[1:p,]
return(if (im) coef else c(coef))
}
then i get goodness:
my.qr.solve(cbind(as.complex(1:11),as.complex(1)),as.complex(2*(20:30)))
[1] 2+0i 38+0i
I do not pretend to fully understand the afflicted code, so it is very likely
"I'm doing it wrong". What I just did above is exactly what Chris
proposed in #8478, but it appears this was declared to be incorrect and
changed.
The current code in qr.coef seems to handle square complex matrices, but as you
see above, it does not handle non-square conditions.
More information about the R-devel
mailing list