% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ergonomics.R
\name{shard_apply_matrix}
\alias{shard_apply_matrix}
\title{Apply a Function Over Matrix Columns with Shared Inputs}
\usage{
shard_apply_matrix(
  X,
  MARGIN = 2,
  FUN,
  VARS = NULL,
  workers = NULL,
  ...,
  policy = shard_apply_policy()
)
}
\arguments{
\item{X}{A numeric/integer/logical matrix (or a shared matrix created by \code{\link[=share]{share()}}).}

\item{MARGIN}{Must be 2 (columns).}

\item{FUN}{Function of the form \verb{function(v, ...)} returning a scalar atomic.}

\item{VARS}{Optional named list of extra variables. Large atomic VARS are
auto-shared based on \code{policy$auto_share_min_bytes}.}

\item{workers}{Number of workers (passed to \code{\link[=shard_map]{shard_map()}}).}

\item{...}{Additional arguments forwarded to \code{FUN}.}

\item{policy}{A \code{\link[=shard_apply_policy]{shard_apply_policy()}} object.}
}
\value{
An atomic vector of length \code{ncol(X)} with the results.
}
\description{
A convenience wrapper for the common "per-column apply" pattern. The matrix
is shared once and each worker receives a zero-copy column view when possible.
}
\details{
Current limitation: \code{MARGIN} must be 2 (columns). Row-wise apply would require
strided/gather slicing and is intentionally explicit in shard via views/kernels.
}
\examples{
\donttest{
X <- matrix(rnorm(400), 20, 20)
shard_apply_matrix(X, MARGIN = 2, FUN = mean)
pool_stop()
}
}
