% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/S3_operations.R
\name{apply_function}
\alias{apply_function}
\title{Apply a statistical or algebraic function to HDF5 datasets (generic)}
\usage{
apply_function(x, ...)
}
\arguments{
\item{x}{An \code{HDF5Matrix}.}

\item{...}{Additional arguments forwarded to the method.}
}
\value{
Named list with elements \code{filename}, \code{out_group},
\code{func}, \code{datasets}.
}
\description{
Generic S3 function that applies a predefined algebraic or statistical
operation to one or more \strong{named datasets within the HDF5 group} of
\code{x}, writing the results to \code{out_group}.

\strong{This function is not equivalent to \code{base::apply()}.}
It does not apply an arbitrary R function row- or column-wise to the matrix
data of \code{x}. Instead, it dispatches one of several built-in C++
operations (QR, cross-product, Cholesky, etc.) to a batch of datasets
stored in the HDF5 file, which need not be open as \code{HDF5Matrix}
objects.
}
\details{
\strong{Two access patterns are available:}
\itemize{
\item \code{apply_function(x, datasets = c("A","B"), func = "QR")} —
use when you have an open \code{HDF5Matrix}; \code{x} provides the
file and group context.
\item \code{\link{hdf5_apply}(filename, group, datasets, func)} —
use when you only have the file path and group name.
}

Valid \code{func} values: \code{"QR"}, \code{"CrossProd"},
\code{"tCrossProd"}, \code{"invChol"}, \code{"blockmult"},
\code{"CrossProd_double"}, \code{"tCrossProd_double"}, \code{"solve"},
\code{"normalize"}, \code{"sdmean"}, \code{"descChol"}.
}
\examples{
\donttest{
fn <- tempfile(fileext = ".h5")

# Create two datasets in the same group
hdf5_create_matrix(fn, "data/A", data = matrix(rnorm(50), 5, 10))
hdf5_create_matrix(fn, "data/B", data = matrix(rnorm(50), 5, 10))

# Apply CrossProd to all datasets in the group
X   <- hdf5_matrix(fn, "data/A")
res <- apply_function(X, func = "CrossProd", out_group = "RESULTS")

hdf5_close_all()
unlink(fn)
}

}
\seealso{
\code{\link{hdf5_apply}} for the standalone file-path version;
\code{\link{crossprod.HDF5Matrix}}, \code{\link{qr.HDF5Matrix}} for
single-dataset S3 equivalents of the most common operations.
}
