\HeaderA{tcrossprod}{Cross-product of transpose}{tcrossprod}
\aliasA{tcrossprod,dgCMatrix,missing-method}{tcrossprod}{tcrossprod,dgCMatrix,missing.Rdash.method}
\aliasA{tcrossprod,dgTMatrix,missing-method}{tcrossprod}{tcrossprod,dgTMatrix,missing.Rdash.method}
\aliasA{tcrossprod-methods}{tcrossprod}{tcrossprod.Rdash.methods}
\keyword{methods}{tcrossprod}
\keyword{algebra}{tcrossprod}
\begin{Description}\relax
Take the cross-product of the transpose of a matrix.
\code{tcrossprod(x)} is formally equivalent to, but faster than, the
call \code{x \%*\% t(x)}, and so is \code{tcrossprod(x, y)} instead of
\code{x \%*\% t(y)}.
\end{Description}
\begin{Usage}
\begin{verbatim}
tcrossprod(x, y = NULL)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a matrix-like object
\item[\code{y}] a matrix-like object or \code{NULL} (by default); the latter
case is formally equivalent to \code{y = x}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
For some classes in the \code{Matrix} package, such as
\code{\LinkA{dgCMatrix}{dgCMatrix.Rdash.class}}, it is much faster to calculate the
cross-product of the transpose directly instead of calculating the
transpose first and then its cross-product.
\end{Details}
\begin{Value}
An object of an appropriate symmetric matrix class.
\end{Value}
\begin{Section}{Methods}
\describe{
\item[x = "dgCMatrix"] method for compressed, sparse,
column-oriented matrices.
}
\end{Section}
\begin{SeeAlso}\relax
\code{\LinkA{crossprod}{crossprod}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
 ## A random sparce "incidence" matrix :
 m <- matrix(0, 400, 500)
 set.seed(12)
 m[runif(314, 0, length(m))] <- 1
 mm <- as(m, "dgCMatrix")
 object.size(m) / object.size(mm) # smaller by a factor of > 200

 ## tcrossprod() is very fast:
 system.time(tCmm <- tcrossprod(mm))# 0   (PIII, 933 MHz)
 system.time(cm <- crossprod(t(m))) # 0.16
 system.time(cm. <- tcrossprod(m))  # 0.02

 stopifnot(cm == as(tCmm, "matrix"))

 ## show sparse sub matrix
 tCmm[1:16, 1:30]
\end{ExampleCode}
\end{Examples}

