% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/S3_arithmetic.R
\name{Ops.HDF5Matrix}
\alias{Ops.HDF5Matrix}
\title{Elementwise arithmetic operators for HDF5Matrix objects}
\usage{
\method{Ops}{HDF5Matrix}(e1, e2)
}
\arguments{
\item{e1}{An \code{HDF5Matrix} object (left-hand side)}

\item{e2}{An \code{HDF5Matrix} object (right-hand side)}
}
\value{
A new \code{HDF5Matrix} containing the result, stored in the same
HDF5 file as \code{e1} under a temporary dataset name.
}
\description{
Standard R arithmetic operators applied element-wise to \code{HDF5Matrix}
objects stored on disk. Both operands must be \code{HDF5Matrix} objects
with identical dimensions.
}
\details{
Supported operators:
\describe{
\item{\code{+}}{Element-wise addition}
\item{\code{-}}{Element-wise subtraction}
\item{\code{*}}{Element-wise multiplication (Hadamard product)}
\item{\code{/}}{Element-wise division. Division by zero produces
\code{NaN} or \code{Inf}, matching base R behaviour.}
}

All operations use block-wise processing and optional OpenMP parallelisation,
controlled via \code{\link{hdf5matrix_options}}.

\strong{Broadcasting:} if one operand is a \eqn{1 \times n} or \eqn{n \times 1}
\code{HDF5Matrix} it is treated as a diagonal/vector operand and the
operation is broadcast row- or column-wise (via \code{\link{diag_op}})
rather than applied element-wise. Both operands must be \code{HDF5Matrix}
objects: scalar arithmetic such as \code{A + 5} is not supported.

\strong{Performance settings:}

Global options set via \code{\link{hdf5matrix_options}} are applied.
For explicit control use the R6 methods directly:
\code{A$add(B, paral = TRUE, threads = 4)}.
}
\examples{
\donttest{
fn <- tempfile(fileext = ".h5")
A_hdf5 <- hdf5_create_matrix(fn, "data/A", data = matrix(1:12, 3, 4))
B_hdf5 <- hdf5_create_matrix(fn, "data/B", data = matrix(2, 3, 4))

C <- A_hdf5 + B_hdf5
D <- A_hdf5 - B_hdf5
E <- A_hdf5 * B_hdf5
G <- A_hdf5 / B_hdf5

all.equal(as.matrix(C), matrix(1:12, 3, 4) + 2)

hdf5_close_all()
unlink(fn)
}

}
\seealso{
\code{\link{hdf5matrix_options}} for global performance settings,
\code{HDF5Matrix} for R6 methods with explicit parameters
}
