Function mean

Computes the arithmetic mean of one selected logical raster plane.

RasterMeanResult!Result mean(Accumulator, Result, Sample)(
  scope RasterView!Sample source,
  size_t planeIndex
) nothrow @nogc @safe
if (isSupportedRasterMeanTriple!(Sample, Accumulator, Result));

Accumulator and Result are both explicit:

source.mean!(Accumulator, Result)(planeIndex)

The accumulation phase is exactly sum!Accumulator() and therefore inherits its strict row-major order, checked integer-overflow behavior and floating NaN/infinity semantics.

Legal pipelines:

Integer Sample: - use any legal integer Accumulator accepted by sum(); - Result must be double.

Floating Sample: - float -> float accumulator -> float or double Result; - float -> double accumulator -> double Result; - double -> double accumulator -> double Result.

There is no implicit default accumulator or result type.

For integer accumulation, the checked integer sum is converted once to double before the final division. Large exact integer sums/counts may round during this documented binary64 conversion; no hidden wider floating type is used.

For floating accumulation, Result may preserve or widen the accumulator but never narrow it.

The logical count is width * height. It is checked before accumulation and must fit size_t exactly.

Failure order: 1. invalid plane; 2. empty input; 3. count overflow; 4. accumulator overflow from sum().

Floating NaN/infinity are successful numerical results, not failures.

The operation allocates nothing, retains no source, and introduces no alternate reduction graph or hidden scheduling.

Example

Example compiling ordinary and UFCS mean forms.

import raster;

RasterView!float source;

const ordinary =
    mean!(
        double,
        double
    )(
        source,
        0
    );

const ufcs =
    source.mean!(
        double,
        double
    )(
        0
    );

assert(!ordinary.ok);
assert(!ufcs.ok);

assert(
    ordinary.error
    == RasterMeanError.invalidPlane
);

assert(ufcs.error == ordinary.error);