La Linea
1 Preface
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.
General info
| Website | https://scicloj.github.io/lalinea/ |
| Source | |
| Deps | |
| License | MIT |
| Status | ๐ experimental๐ |
Design
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).
Features
Real matrices
- 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
Complex matrices
- ComplexTensor โ interleaved
[re im]layout sharing memory with EJMLโsZMatrixRMaj - Complex
mmul,add,sub,scale, conjugatetranspose,invert,solve - Complex
trace,det,norm
Element-wise operations
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
Tagged literals
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.
Fourier transforms
Computation tape
- 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
Automatic differentiation
- 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
Zero-copy interop
- 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)
Documentation
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.
API
(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 helpersBuilt on
- 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).
Development
clojure -M:dev -m nrepl.cmdline # start REPL
./run_tests.sh # run tests
clojure -T:build ci # test + build JARLicense
MIT License
Part of the scicloj ecosystem for scientific computing in Clojure.
source: notebooks/index.clj