kicad2ems.mom25d.half

mom25d.half - a complex-symmetric matrix kept by its lower half, by block
columns, and its LDL^T factor without pivoting (host side; the GPU's is
gpu_ldl.py, on the same layout).

MoM's Z is complex symmetric (Z = Z^T). Its lower half by block columns of nb:
block column J holds columns [J nb, J nb + w_J) of the rows [J nb, N), column
major (its leading dimension ld_J = N - J nb), the blocks one after another in
one flat array. In Z's C-ordered terms that is block row J's right part
(rows [J nb, J nb + w_J), columns [J nb, N)), so `block(J)` (w_J x ld_J,
C order) is Z[J0:J1, J0:] and its transpose the block column. The diagonal
blocks are held whole (both triangles); about N^2 / 2 + N nb / 2 numbers.

    H = Half(n)                     # zeros, complex64
    H = Half.pack(Z, dsc)           # Z (full, C order) equilibrated by dsc
    Y = H.matvec(X)                 # Z X (X: n or n x k)
    ldl_factor(H)                   # in place: L below the diagonal, D on it
    X = ldl_solve(H, B)             # Z^-1 B

The factor is right-looking by block columns: the diagonal block's L11 D1
L11^T, the panel's W = A21 L11^-T and L21 = W D1^-1, and each later block
column's rows from its own start updated by W L21^T (the lower half alone:
half an LU's work and numbers). Without pivoting it relies on the
equilibrated matrix's diagonal; a zero pivot raises ZeroDivisionError, a
non-finite factor FloatingPointError (tools/mom25d_ldl_trial.py: it
preconditions as the LU does on mom25d's boards).
class kicad2ems.mom25d.half.Half(n, nb=256, dtype=<class 'numpy.complex64'>, data=None)[source]
The lower half of a symmetric n x n matrix by block columns of nb (the
module's docstring). data: the flat array (None: zeros of dtype,
'empty': uninitialised).
add_sparse(S)[source]
Z += S's symmetric part (S + S^T) / 2 where the half keeps it;
returns the rest, (S - S^T) / 2 (sparse; None where S is
symmetric): the products' to add (matvec does not).
block(J)[source]
Block row J: Z[J0:J1, J0:] (w_J x ld_J, C order, a view).
border(B, C)[source]
The via (and holes', sides') rows and columns: Z[:Ne, Ne:] = B,
Z[Ne:, :Ne] = B^T, Z[Ne:, Ne:] = C, where the half keeps them (B: Ne
x Nv, C: Nv x Nv; Ne = n - Nv).
static bytes(n, nb=256, itemsize=8)[source]
The bytes of an n x n Half (itemsize: 8 complex64, 16 complex128).
classmethod compact(Z, nb=256)[source]
A complex64 or complex128 Z (C order) as a Half in its own memory
(the compiled core's compact_half: no second matrix); Z is that
Half's from then on, its tail unused: given back to the system where
Z is zeros_mapped's (madvise).
diagonal()[source]
Z's diagonal (a copy).
loop_transform(W, chunk=512)[source]
Z <- T^T Z T in place, T = I + W (W: n x n sparse, nonzero in some
columns V, on rows R outside V: the sides' verticals as loops, the
via chains' fan paths): only V's rows and columns change. Y = Z[:, V]
+ Z[:, R] W[R, V] (R's rows chunk at a time), Y[V] += W[:, V]^T Y,
then rows V := Y^T. Its peak beside the half: Y (n x |V|).
matvec(X)[source]
Z X, X: n or n x k (in the matrix's precision, or double for a
complex64 matrix's double right-hand side: the products are
BLAS's): the block rows' Z[J0:J1, J0:] X[J0:] and their transposes'
X[J0:J1] into the rows below the diagonal block.
classmethod pack(Z, dsc=None, dtype=<class 'numpy.complex64'>, nb=256, threads=None)[source]
Z's upper half by block rows (= its lower half by block columns),
times dsc[i] dsc[j] where given, as dtype (complex64 from a C-ordered
Z: the compiled core's pack_half, one pass).
panel(J, out=None)[source]
Rows J0 .. J1 of the matrix whole (w x n, C order): block J's own
(its columns from J0) and before J0 the earlier blocks' columns J0 ..
J1 transposed (the matrix symmetric: their mirror).
rows()[source]
(rowptr, c0) of each row r: its first stored number's index in
data and that number's column (the compiled core's fills).
rows_of(idx)[source]
The matrix's rows idx whole (len(idx) x n), any rows.
scale(d, threads=None)[source]
In place: entry (i, j) times d[i] d[j] (d real, or complex for a
complex matrix: the loop/tree basis's sqrt(jw)).
set_rows(idx, R)[source]
The matrix's rows idx whole set to R (len(idx) x n; R's block idx x
idx symmetric), where the half keeps them: each pair's one place,
and in a diagonal block both.
to_full()[source]
The whole symmetric matrix (n x n, C order): for checks.
kicad2ems.mom25d.half.inverse_lower(L)[source]
The unit lower L's inverse (LAPACK's trtri), its dtype.
kicad2ems.mom25d.half.ldl_factor(H)[source]
L D L^T of the Half H in place (complex64 or complex128): right-looking
by block columns, the diagonal block in double (ldl_small), each later
block column's update one BLAS GEMM on BLAS's threads (W and L21 kept
in C order, so that the rows a block column takes, a suffix, are
contiguous: SciPy's wrappers copy a strided operand, and hold the GIL, so
that block columns on threads of their own ran on one core). Returns H.
kicad2ems.mom25d.half.ldl_mul(H, X)[source]
L D L^T X with ldl_factor's H: the factored matrix's products from its
factor (the double fallback's, whose Z the factor overwrote), X n or n x
k, in the factor's precision, complex128 out.
kicad2ems.mom25d.half.ldl_small(A, leaf=32)[source]
L D L^T of a small dense symmetric A (its lower triangle; complex128
or complex64), not in place: (L unit lower, Fortran order; d). Recursive
halves, the leaves unblocked, the rest BLAS on one thread: 2.2 ms at 256
(the GPU factor's diagonal blocks; OpenBLAS's threads made it 90 ms).
kicad2ems.mom25d.half.ldl_solve(H, B)[source]
Z^-1 B with ldl_factor's H (B: n or n x k): L y = B, z = y / D, L^T x
= z, by blocks; in the factor's precision, complex128 out.
kicad2ems.mom25d.half.zeros_mapped(n, dtype=<class 'complex'>)[source]
An n x n matrix of zeros in an anonymous mapping of its own (mmap: the
pages zero till touched), so that Half.compact can give the half it no
longer needs back to the system (the loop/tree basis's transform and the
sides' loops need the whole matrix; the solve after them its half).