Skip to content

Add scalar Complex boxing/unboxing across the jl2py ABI#4

Merged
jack-champagne merged 1 commit into
masterfrom
scalar-complex
Jun 30, 2026
Merged

Add scalar Complex boxing/unboxing across the jl2py ABI#4
jack-champagne merged 1 commit into
masterfrom
scalar-complex

Conversation

@jack-champagne

Copy link
Copy Markdown
Member

Scalar Complex was the one input/output gap in the otherwise-complete bridge
(arrays of complex already worked). For a quantum-control codebase (Piccolo's
PAULIS/GATES/Hamiltonians are complex) this is first-class, so:

Inputbox_python_value boxes a Python complex → Julia Complex{Float64}
via new C jl2py_box_complex128 (Base.complex(re, im)).

Outputcompute_typetag now emits TAG_COMPLEX128/TAG_COMPLEX64 for scalar
Complex{Float64}/{Float32} (cached at init), and new JuliaComplex128/JuliaComplex64
wrappers expose __complex__ / .real / .imag via new C jl2py_unbox_complex128.

Before: a Python complex arg raised TypeError; a scalar Complex result fell
through to bare JuliaAny (no .real/__complex__; .re/.im worked but un-Pythonic).

Verified locally on Julia 1.12.6 (libjl2py rebuilt clean):

  • existing int/float/str primitives unchanged (regression);
  • complex in/out round-trips; ComplexF32 promoted; complex as a kwarg value;
  • and through a SOURCE-FREE package-image-loaded function (via JuliaStaticData) —
    scalar complex from a runtime-loaded module tags + wraps correctly with no world-age wall.

Adds tests/test_complex.py (numpy-free; mirrors the existing regression-test style).

🤖 Generated with Claude Code

@jack-champagne jack-champagne merged commit 50ba849 into master Jun 30, 2026
1 check passed
@jack-champagne jack-champagne deleted the scalar-complex branch June 30, 2026 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant