What if dtype-next had linear algebra and complex numbers?
La Linea extends dtype-next with
linear algebra and complex numbers,
powered by EJML as the computational backend.
The two share the same row-major double[] memory layout, enabling zero-copy interop.
| Website | https://scicloj.github.io/lalinea/ |
| Source | |
| Deps | |
| License | MIT |
| Status | 🛠experimental🛠 |
La Linea embraces dtype-next as the
tensor layer. Matrices are backed by dtype-next tensors and interoperate with the
dtype-next ecosystem — Tablecloth/tech.ml.dataset
datasets accept them as columns, and dtype-next's own dtype/clone, dfn/
reductions, and protocol queries work directly on them. La Linea inherits
dtype-next's lazy, noncaching evaluation — element-wise operations compose
without allocating intermediate arrays. Operations that cross into EJML
materialize at the boundary.
Three namespaces cover most usage:
t/(scicloj.lalinea.tensor) — construct tensors in either field (real or complex)el/(scicloj.lalinea.elementwise) — element-wise math, polymorphic over the fieldla/(scicloj.lalinea.linalg) — linear algebra: products, decompositions, solve
All three are polymorphic — they work uniformly on both real tensors and ComplexTensors.
Field-aware operations like el/re, el/im, el/conj
are identity on reals and meaningful on complex.
Supporting namespaces: tape/ (computation recording),
grad/ (autodiff), ft/ (FFT bridge), vis/ (visualization helpers).
- Construction —
matrix,eye,zeros,ones,diag,column,row,submatrix - Arithmetic —
mmul,mpow,transpose - Properties —
trace,det,norm(Frobenius),dot - Analysis —
rank,condition-number,pinv(pseudoinverse),null-space,col-space - Solve —
solve,lstsq(least squares),invert - Decompositions — eigendecomposition, SVD, QR, Cholesky
- ComplexTensor — interleaved
[re im]layout sharing memory with EJML'sZMatrixRMaj - Complex
mmul,add,sub,scale, conjugatetranspose,invert,solve - Complex
trace,det,norm
scicloj.lalinea.elementwise— 35+ tape-aware functions with complex dispatch- Arithmetic:
+,-,*,/,scale - Complex-aware:
re,im,conj - Powers:
sq,sqrt,pow,cbrt - Exponential:
exp,log,log10,log1p,expm1 - Trigonometric:
sin,cos,tan,asin,acos,atan - Hyperbolic:
sinh,cosh,tanh - Reductions:
abs,sum,prod,mean,reduce-max,reduce-min - Rounding:
floor,ceil,round,clip - Comparison:
>,<,>=,<=,eq,not-eq,min,max
Real and complex tensors print as readable tagged literals:
#la/R [:float64 [2 2]
[[1.000 2.000]
[3.000 4.000]]]
#la/C [:float64 [2 2]
[[1.000 + 5.000 i 2.000 + 6.000 i]
[3.000 + 7.000 i 4.000 + 8.000 i]]]Round-trip through pr-str / read-string.
- Forward/inverse DFT bridging real signals to complex spectra, as well as complex-to-complex
- , DCT, DST, DHT
- Record
t/,la/, andel/operations as a DAG withtape/with-tape - Inspect memory status:
:contiguous,:strided, or:lazy - Detect shared backing arrays between tensors
- Visualize computation graphs as Mermaid flowcharts
- Reverse-mode autodiff via VJP rules on the computation tape
- Differentiable ops:
el/+,el/-,el/scale,la/mmul,la/transpose,la/trace,la/det,la/invert,la/norm,la/dot,el/*,el/sq,el/sum - Compute gradients of scalar functions with respect to matrix inputs
- dtype-next tensor <-> EJML
DMatrixRMaj— samedouble[], no copy - ComplexTensor <-> EJML
ZMatrixRMaj— same interleaveddouble[], no copy - Mutations through either view are immediately visible in the other
- All
dfnelement-wise operations work directly on matrices (they are tensors)
The La Linea book is a set of notebook-based chapters covering:
- Getting started — quickstart
- Core concepts — tensors & EJML interop, complex tensors, Fourier transforms, sharing & mutation, computation tape, automatic differentiation
- Abstract linear algebra — vectors & spaces, maps & structure, inner products & orthogonality, eigenvalues & decompositions
- Applications — linear systems, Markov chains & PageRank, image processing, fractals, decompositions in action, least squares, spectral graph theory
- Validation — algebraic identities
- Reference — API reference
Each chapter includes inline tests via Clay's test generation.
(require '[scicloj.lalinea.tensor :as t]) ; tensor construction, structural ops, EJML interop
(require '[scicloj.lalinea.linalg :as la]) ; arithmetic, decompositions, solve
(require '[scicloj.lalinea.elementwise :as el]) ; element-wise math, comparisons, field ops
(require '[scicloj.lalinea.transform :as ft]) ; FFT / DCT / DST / DHT bridge
(require '[scicloj.lalinea.tape :as tape]) ; computation DAG recording
(require '[scicloj.lalinea.grad :as grad]) ; reverse-mode automatic differentiation
(require '[scicloj.lalinea.vis :as vis]) ; visualization helpers- dtype-next — array/tensor numerics
- EJML — efficient Java matrix library (real + complex)
- fastmath — transforms (FFT, DCT, DST, DHT)
The book notebooks also use
tablecloth,
tableplot, and
kindly (included in the :dev and :test aliases).
clojure -M:dev -m nrepl.cmdline # start REPL
./run_tests.sh # run tests
clojure -T:build ci # test + build JARMIT License
Part of the scicloj ecosystem for scientific computing in Clojure.