Complex (Re + Im)

Shipping
complex_pack

Fuse two real arrays into one complex array: z = re + i·im (rectangular form)

Signature

Inputs

  • reArray|ScalarrequiredReal component. Must be a real array/scalar of the same length as im.
  • imArray|ScalarrequiredImaginary component. Must be a real array/scalar of the same length as re.

Outputs

  • zArrayComplex array carrying re's physical unit; stored structure-of-arrays as (data=re, imag=im).

Description

Complex (Re + Im) builds a complex-valued array from two real components: it wires re into the real buffer and im into the imaginary buffer, producing . It is the exact inverse of Split Re / Im (complex_unpack) and the rectangular-form sibling of Complex (Mag ∠ Phase) (complex_polar).

Internally a Captyse complex array is stored structure-of-arrays — two parallel f64 buffers (data = re, imag = Some(im)) — so packing is a cheap, lossless interleave with no per-element boxing. The output inherits the physical unit of the re input. The node is stateless: the result depends only on the current inputs.

Because it combines two real components, an already-complex input is a hard error rather than a silent truncation: if re or im themselves carry an imaginary part, the node refuses and asks you to split them first (with real_part / imag_part). The two components must also be equal length; a mismatch is rejected.

Mathematics

Examples

Assemble a phasor array

Wire the array into re and into im. The z output is the complex array . Feed it to Magnitude |z| to recover .

Round trip

complex_pack(re, im) followed by complex_unpack returns the original re and im unchanged — the pack/unpack pair is a lossless structural identity.

Applications

  • Constructing a complex spectrum from separately computed real and imaginary parts before an inverse FFT.
  • Building I/Q (in-phase / quadrature) baseband data from two real channels.
  • Assembling analytic-signal representations where the imaginary part is a Hilbert transform of the real part.

Neat

Complex arrays are stored structure-of-arrays (two parallel f64 buffers), never as interleaved (re, im) pairs, so packing is a metadata-lossless column fuse rather than an allocation-per-element boxing.

The node deliberately errors on an already-complex input instead of dropping its imaginary part — a design choice (issue M4) that trades convenience for scientific safety.

Known issues

Both components must be real; passing an already-complex array to re or im is rejected rather than silently coerced.

The real and imaginary arrays must have identical length — no broadcasting or padding is performed here.

See also

complexrectangularpackiqstateless