cplx_contour_integral — MATH complex op

Data kinds: cpoints × cpointscscalar

Call: import mathops; mathops.cplx_contour_integral(z, fz) (or opsmath.get("cplx_contour_integral"))

Usage

Closed contour integral `∮ f(z) dz` by the chordal trapezoidal rule.

*z* are the contour vertices (closing segment implicit, see

:func:cplx_contour_circle) and *fz* the function sampled at exactly those

points — the op never calls back into Python, so any `f` is allowed as

long as you can sample it. The quadrature is

`sum_k (f_k + f_{k+1})/2 * (z_{k+1} - z_k)`, i.e. the trapezoidal rule

along the *chords*; it is exact for a piecewise-linear integrand and second

order otherwise.

Ground truth it reproduces: `f = 1/(z - a)` around a circle enclosing

`a integrates to 2*pi*i` (Cauchy); measured on the unit circle with

`a = 0, the relative error is 1.0e-4 at n = 256` and

6.3e-6 at `n = 1024` — a factor 16.0 for 4x

refinement, i.e. the `O(n^-2)` rate, *not* the spectral accuracy the

trapezoid rule enjoys when applied in the angle parameter. That difference

is the honest price of accepting an arbitrary point list instead of a

parametrisation.

Orientation follows the sample order: a clockwise contour returns the

negative of the counter-clockwise one.

Raises `ValueError: fewer than 3 points, len(z) != len(fz)`, a

degenerate contour (all points coincide), non-finite/masked input, or a sum

that overflowed (`|f|` near a pole *on* the path).

HALCON: no operator (contour integration is not part of its tuple/XLD API).

Family-wide input contract (fail-closed)

Every mathops op validates its input before computing (nothing slips through silently):

• **complex input raises ValueError** — coercing to float64 silently discards the imaginary part (numpy only emits a ComplexWarning and returns a plausible-looking wrong real number). State .real/.imag/abs() explicitly, or use complexops, which handles complex data.

• **masked arrays with masked elements raise ValueError** — the implicit conversion that peels off the mask and uses the raw values underneath is refused. Say explicitly whether to fill or to drop.

• **NaN/Inf raises ValueError on every input** (refused with the count stated — it propagates through the whole result).

Shapes are strict: 1-D and 2-D are never implicitly promoted or broadcast (a matrix in a vector slot, or a vector in a matrix slot, raises ValueError; reshape explicitly).

Size cap: ops that take a matrix, and the stat_histogram bins, raise ValueError beyond mathops.MAX_ELEMENTS (2^26 ≈ 67 million elements).

Detailed usage guide

math_metrology family guide

References (sample data, literature)

• Sample-data catalog (download URLs / licences) — 2-D uses skimage.data (BSD/public domain) plus synthetic images; 3-D lists download URLs for real data sources (Stanford, PDS, …).

• Operator provenance and references — the sources of the research/methods this op family came from.

• The canonical algorithm (author, year) and its uses are named in the family usage guide above.

Runnable examples (verified samples that actually call this op)

math_complexpy -3.11 examples/math_complex.py

representation_conversionpy -3.11 examples/representation_conversion.py

Ops the type connects to (they accept cscalar as input)

Same category (complex)

cplx_contour_circle · cplx_poly_eval · cplx_winding_number · cplx_cauchy_value · cplx_argument_principle · cplx_laurent_coeffs · cplx_joukowski · cplx_mobius


*Provenance: mathops.py — MATH operator registry. This per-op note is generated by tools/opdocs.py md (do not hand-edit).*

© 2026 Kazufumi Furuse — Fullseye operator documentation. Licensed under Apache-2.0.