Re: [Rd] transpose of complex matrices in R

From: Duncan Murdoch <murdoch.duncan_at_gmail.com>
Date: Fri, 30 Jul 2010 06:13:26 -0400

Robin Hankin wrote:
> Hello everybody
>
> When one is working with complex matrices, "transpose" very nearly
> always means
> *Hermitian* transpose, that is, A[i,j] <- Conj(A[j,i]).
> One often writes A^* for the Hermitian transpose.

>
> I have only once seen a "real-life" case
> where transposition does not occur simultaneously with complex conjugation.
> And I'm not 100% sure that that wasn't a mistake.
>
> Matlab and Octave sort of recognize this, as "A'" means the Hermitian
> transpose of "A".
>
> In R, this issue makes t(), crossprod(), and tcrossprod() pretty much
> useless to me.
>
> OK, so what to do? I have several options:
>
> 1. define functions myt(), and mycrossprod() to get round the problem:
> myt <- function(x){t(Conj(x))}
>
> 2. Try to redefine t.default():
>
> t.default <- function(x){if(is.complex(x)){return(base::t(Conj(x)))}
> else {return(base::t(x))}}
> (This fails because of infinite recursion, but I don't quite understand
> why).
>

You should call base::t.default, not base::t. Then this will work. The same solution fixes the one below, though you won't even need the base:: prefix on t.default.

Duncan Murdoch

> 3. Try to define a t.complex() function:
> t.complex <- function(x){t(Conj(x))}
> (also fails because of recursion)
>
> 4. Try a kludgy workaround:
> t.complex <- function(x){t(Re(x)) - 1i*t(Im(x))}
>
>
> Solution 1 is not good because it's easy to forget to use myt() rather
> than t()
> and it does not seem to be good OO practice.
>
> As Martin Maechler points out, solution 2 (even if it worked as desired)
> would break the code of everyone who writes a myt() function.
>
> Solution 3 fails and solution 4 is kludgy and inefficient.
>
> Does anyone have any better ideas?
>
>
>
>
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 30 Jul 2010 - 10:23:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 30 Jul 2010 - 19:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive