This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function
prefixScanWithFunc
Public Function
std.simd.prefixScanWithFunc
pubfnprefixScanWithFunc(
comptimehop: isize,
vec: anytype,
/// The error type that `func` might return. Set this to `void` if `func` doesn't return an error union.comptimeErrorType: type,
comptimefunc: fn (@TypeOf(vec), @TypeOf(vec)) if (ErrorType == void) @TypeOf(vec) elseErrorType!@TypeOf(vec),
/// When one operand of the operation performed by `func` is this value, the result must equal the other operand./// For example, this should be 0 for addition or 1 for multiplication.comptimeidentity: std.meta.Child(@TypeOf(vec)),
) if (ErrorType == void) @TypeOf(vec) elseErrorType!@TypeOf(vec)
Same as prefixScan, but with a user-provided, mathematically associative function.
Params
hop: isize
vec
ErrorType: type
func: fn (@TypeOf(vec), @TypeOf(vec)) if (ErrorType == void) @TypeOf(vec) elseErrorType!@TypeOf(vec)
pubfnprefixScanWithFunc(
comptimehop: isize,
vec: anytype,
/// The error type that `func` might return. Set this to `void` if `func` doesn't return an error union.comptimeErrorType: type,
comptimefunc: fn (@TypeOf(vec), @TypeOf(vec)) if (ErrorType == void) @TypeOf(vec) elseErrorType!@TypeOf(vec),
/// When one operand of the operation performed by `func` is this value, the result must equal the other operand./// For example, this should be 0 for addition or 1 for multiplication.comptimeidentity: std.meta.Child(@TypeOf(vec)),
) if (ErrorType == void) @TypeOf(vec) elseErrorType!@TypeOf(vec) {
constlen = vectorLength(@TypeOf(vec));
if (hop == 0) @compileError("hop can not be 0; you'd be going nowhere forever!");
constabs_hop = if (hop < 0) -hopelsehop;
varacc = vec;
comptimevari = 0;
inlinewhile ((abs_hop << i) < len) : (i += 1) {
constshifted = if (hop < 0) shiftElementsLeft(acc, abs_hop << i, identity) elseshiftElementsRight(acc, abs_hop << i, identity);
acc = if (ErrorType == void) func(acc, shifted) elsetryfunc(acc, shifted);
}
returnacc;
}
Same as prefixScan, but with a user-provided, mathematically associative function.