Design: %cplx complex arrays + /lib/complex (BLAS-interleaved)#45
Open
sigilante wants to merge 3 commits into
Open
Design: %cplx complex arrays + /lib/complex (BLAS-interleaved)#45sigilante wants to merge 3 commits into
sigilante wants to merge 3 commits into
Conversation
Design proposal (lagoon/CPLX-DESIGN.md) for a complex-number Lagoon kind and a
pure-Hoon /lib/complex, with an atom layout bit-identical to SoftBLAS complex
arrays so the eventual jet is a zero-conversion cast. Motivating consumer:
eigenvalues/eigenvectors in Saloon (complex eigenvalues require complex arrays).
Grounded in the vendored SoftBLAS (complex{16,32,64,128}_t = {real;imag},
interleaved, Level-1 + dotc only, no complex GEMM) and the Lagoon jet's
bloq->floatN_t cast marshalling.
Core decision: bloq = log2 of the total complex element width (one element =
one complexN_t; bloq6=complex32, bloq7=complex64), real in the low half / imag
in the high half, so an array of slots IS a BLAS interleaved complex array.
Layout + arithmetic validated on ~hex ((1+2i)(3+4i)=-5+10i).
Covers: /lib/complex arm set (no total order -> gth/lth crash), Lagoon's six
dispatch sites, dot (unconjugated) vs dotc (Hermitian, maps to SoftBLAS *dotc),
mmul via real-GEMM decomposition for the future jet, open decisions, and a
three-phase plan ending in Saloon eig.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Fold in resolved review decisions: dedicated complex aura family @ch/@cs/@cd/@cq (parallel to @r); gth/lth crash (no total order); add %conj to the ops union; ship @cs (bloq6) + @cd (bloq7) first. dot-conjugation and %cplx->real change semantics remain under discussion (§7). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Resolve the last review decisions: - dot is bilinear (numpy @/BLAS *dotu, consistent with mmul); add a separate Hermitian dotc (numpy vdot/BLAS *dotc) for norms and Saloon eig. - change out of complex (cplx->real) refuses as lossy; conversions into complex and between complex widths are defined. Modulus stays via abs. - We own the vendored SoftBLAS, so the jet plan adds the missing complex primitives there (*dotu, cgemm/zgemm via 4-real-GEMM / Karatsuba over the real kernels) instead of decomposing Lagoon-side; Level-1 already exists. All design decisions settled; doc ready to implement against. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Design proposal (
lagoon/CPLX-DESIGN.md) — not an implementation. Adds acomplex-number Lagoon kind
%cplxand a pure-Hoon/lib/complex, with an atomlayout bit-identical to SoftBLAS / BLAS complex arrays so the eventual jet
is a zero-conversion cast. The motivating consumer is eigenvalues /
eigenvectors in Saloon — the eigenvalues of a real matrix are generally
complex, so Saloon's
eigis blocked until Lagoon can carry complex arrays.Grounded in the actual code
Researched the vendored SoftBLAS (
vere/ext/softblas) and the Lagoon jet C(
lagoon/vere/noun/jets/i/lagoon.c):complex{16,32,64,128}_t=struct {real; imag}(real-first), interleaved[re0 im0 re1 im1 …].c/i/z/vaxpy/copy/dotc/scal/swap/rot);*dotcis the conjugate dot, there's no*dotu, and there is nocomplex GEMM.
2^(bloq-3)bytes/element and castsstraight to
floatN_t*bybloq.Core decision
bloq= log₂ of the total complex element width (one element = onecomplexN_t): bloq6 =complex32(2×@rs, 64b), bloq7 =complex64(2×
@rd, 128b). Real in the low2^(bloq-1)bits, imag in the high — so anarray of slots is a BLAS interleaved complex array and the jet is a pure cast.
meta.tailunused (all derives frombloq).Layout + arithmetic validated on ~hex before writing:
(1+2i)·(3+4i) = -5+10i,(1+2i)+(3+4i) = 4+6iwith real-low/imag-high@rscomponents.What the doc covers
/lib/complexarm set (add/sub/mul/div-via-Smith/neg/conj/abs-via-hypot/equ/neq); ℂ has no total order →
gth/lthcrash, onlyequ/neq.%int2/%unum/%fixp), comparisonsreturning complex
one/zero, a proposed%conjop.dot(unconjugated, cross-kind-consistent) vs newdotc(Hermitian, maps to SoftBLAS
*dotc);mmulpure-Hoon now, jet later via4-real-GEMM / 3M-Karatsuba over
sgemm/dgemm(no complex GEMM exists);no exact accumulator (rounds per op, like
%i754).eig(Hessenberg + shifted QR).
Open questions for review (§7)
ordering (crash vs modulus) ·
dotconjugation · add%conjtoops·which widths first ·
changesemantics.No code in
desk/changes here —%cplxstays commented out until Phase 1, sonothing builds against it yet.
🤖 Generated with Claude Code