Repository navigation
This is a major release. The breaking changes:
- Every function that can fail has two forms: a
pureone withouterr, and one with a mandatoryerr(#100, the API style of #44). detand.det.return 0 for an exactly singular matrix (#113).lstsqreturnssize(a,2)rows (#82).- Fifteen public specific BLAS/LAPACK procedure names are renamed: 5 BLAS (#81), 6 LAPACK (#83) and 4 mixed-precision (#85).
- The generated sources are
.F90, andqpcode compiles only with thequadfeature, which is on by default (#92). la_xerblaandla_xerbla_arrayare removed (#107).- Some LAPACK
infocodes change error flag (#102). - Fortran 2018 is the minimum standard (#114).
Changed
- The BLAS sources are generated from kind-templated fypp topic modules
instead of six per-kind modules:la_blas_auxplusla_blas_level1,
la_blas_level2_{ban,gen,pac,sym,tri}andla_blas_level3_{gen,sym,tri}.
Thela_blasgeneric interfaces are unchanged. - Five BLAS specific names that kept the kind letter of the precision they
were copied from are corrected:la_qsdot,la_qzasum,la_qznrm2,
la_wdrotandla_wdscalbecomela_qddot,la_qwasum,la_qwnrm2,
la_wqrotandla_wqscal. None of them is reachable through a generic
interface. scripts/fypp_deploy.pyreplacesscripts/preprocess.shfor regenerating
the committed sources, and has a--checkmode.- The LAPACK auxiliary and base routines are generated from kind-templated
fypp topic modules instead of the six per-kind monoliths:la_lapack_aux
andla_lapack_auxiliary,la_lapack_blas_like_{base,l1,l2,l3,scalar,mnorm},
la_lapack_solve_aux,la_lapack_givens_jacobi_rotand
la_lapack_householder_reflectors. Thela_lapackgeneric interfaces are
unchanged. - Six LAPACK specific names that kept the kind letter of the precision they
were copied from are corrected:la_qlag2s,la_qlat2s,la_qzsum1,
la_wdrscl,la_wlag2candla_wlat2cbecomela_qlag2d,la_qlat2d,
la_qwsum1,la_wqrscl,la_wlag2zandla_wlat2z. None of them is
reachable through a generic interface. - The LAPACK solve family is generated from kind-templated fypp topic modules
instead of the six per-kind monoliths:la_lapack_solve_tri_comp,
la_lapack_solve_{chol,lu}_comp,la_lapack_solve_lu,
la_lapack_solve_ldl_comp{,2,3,4},la_lapack_solve_{chol,ldl}and
la_lapack_others_sm. Thela_lapackgeneric interfaces are unchanged. - Four mixed-precision LAPACK drivers whose name kept the kind letter of the
precision they were copied from are corrected:la_qsgesv,la_qsposv,
la_wcgesvandla_wcposvbecomela_qdgesv,la_qdposv,la_wzgesvand
la_wzposv. None of them is reachable through a generic interface. - The LAPACK orthogonal factorizations, cosine-sine decomposition and
bidiagonal singular-value kernels are generated from kind-templated fypp
topic modules instead of the six per-kind monoliths:
la_lapack_orthogonal_factors_{qr,rz,ql},la_lapack_cosine_sine,
la_lapack_lsq_constrained,la_lapack_svd_comp2,
la_lapack_svd_bidiag_qr,la_lapack_eigv_gen_auxand
la_lapack_eigv_gen_hess. Thela_lapackgeneric interfaces are unchanged. - The LAPACK eigenvalue, singular-value and least-squares drivers are
generated from kind-templated fypp topic modules instead of the six per-kind
monoliths:la_lapack_eigv_sym{,_comp},la_lapack_eigv_tridiag{,2,3},
la_lapack_eigv_comp{,2},la_lapack_eigv_gen{,2,3},
la_lapack_eigv_svd_{drivers,drivers2,bidiag_dc},la_lapack_svd_comp,
la_lapack_lsqandla_lapack_lsq_aux. Thela_lapackgeneric interfaces
are unchanged. - Removed the six per-kind LAPACK modules
la_lapack_{s,d,q,c,z,w}. Every
routine they held now lives in one of the 47 kind-templated topic modules,
which thela_lapackumbrella imports directly. - The
la_lapackumbrella is generated frominclude/la_lapack_interfaces.fypp,
a data table of its 498 generic interfaces and their 1524 external-library
stubs, the wayla_blasalready was.src/la_lapack.f90and
src/la_lapack_aux.f90are renamedsrc/la_lapack.F90and
src/la_lapack_aux.F90: both carry cpp directives, so they now follow the
extension rule the rest of the generated tree follows. Build files that list
either source by name need the new spelling. - The
generated-sourcescontinuous-integration job runs
scripts/fypp_deploy.py --checkand fails on any drift between a template
and its committed output. - The BLAS and LAPACK backend is
pure, apart from the 26 LAPACK functions
that take anintent(out)argument, which a pure function cannot have, and
?lacon, which keeps its state insavevariables and has no callers
(LAPACK replaced it with?lacn2). The 26 functions keep their interface;
every caller inside the library uses their pure subroutine twins instead.
WithLA_EXTERNAL_LAPACK, the external interfaces of the routines that
became pure are declaredpureas well. - The high-level procedures that waited for a pure backend are
pure: the
subroutineseig,eigh,svd,pseudoinvert,invert,schur,
schur_space,solve_lstsq,solve_weighted_lstsq,
solve_constrained_lstsqandconstrained_lstsq_space, the forms of
eigvalsandeigvalshwithouterr, and the operators.inv.and
.pinv..mnormcalls the purelange_sub. A function that takes anerr
argument stays impure, since a pure function cannot. - The generalized
eigvals(a, b)takesbasintent(in). It was declared
intent(inout)but never modified, so a constant or an expression can now
be passed. - A new module
la_infodecodes theinfoexit code of the LAPACK routines
the high-level procedures call: oneelementalhandler per routine,
handle_<routine>, that takes the caller's name first and reports it
aswhere_at. It replaces the private copies and the inline decodes of the
topic modules, andlinear_algebradoes not re-export it. Every routine now
follows one classification: an invalid dimension of the user's data is
LINALG_VALUE_ERROR, an invalid argument the library chose (a job
character, a triangle, a workspace size) isLINALG_INTERNAL_ERROR, a
failure thatinfo > 0reports isLINALG_ERROR, and a code LAPACK does
not document isLINALG_INTERNAL_ERROR. The flags that change:solve,solve_lu: an invalidldbfromgesv(info = -7),
LINALG_ERRORtoLINALG_VALUE_ERROR.det,.det.: an invalid size fromgetrf,LINALG_ERRORto
LINALG_VALUE_ERROR; an undocumented negative code,LINALG_ERRORto
LINALG_INTERNAL_ERROR.invert,inv,.inv., andmatrix_powerof a negative power: an
invalid size fromgetrforgetri,LINALG_ERRORto
LINALG_VALUE_ERROR; an invalidlworkfromgetri(info = -6) and an
undocumented negative code,LINALG_ERRORtoLINALG_INTERNAL_ERROR.slogdet: an invalid size fromgetrf,LINALG_INTERNAL_ERRORto
LINALG_VALUE_ERROR.cond: an invalid size fromgetrf,getriorgecon,
LINALG_INTERNAL_ERRORtoLINALG_VALUE_ERROR;getriwith
info > 0, andgeconwithinfo = 1(a reference LAPACK that reports a
NaN or infinite estimate),LINALG_INTERNAL_ERRORtoLINALG_ERROR.expm,matrix_exp: an invalidnrhs,ldaorldbfromgesv
(info = -2, -4, -7),LINALG_INTERNAL_ERRORtoLINALG_VALUE_ERROR.solve_lower_chol,solve_upper_chol:potrswithinfo > 0, which
LAPACK does not document,LINALG_ERRORtoLINALG_INTERNAL_ERROR.qr,qr_space: an invalidlworkfromgeqrf,geqp3or
orgqr/ungqr,LINALG_ERRORtoLINALG_INTERNAL_ERROR; an invalidk
fromorgqr/ungqr(info = -3),LINALG_INTERNAL_ERRORto
LINALG_VALUE_ERROR;orgqr/ungqrwithinfo = -4, which LAPACK does
not return,LINALG_VALUE_ERRORtoLINALG_INTERNAL_ERROR.schur,schur_space: an invalidldvsfrom the complexgees
(info = -10),LINALG_INTERNAL_ERRORtoLINALG_VALUE_ERROR;
info > n+2,LINALG_ERRORtoLINALG_INTERNAL_ERROR.eig,eigvals: an invalidldvlorldvrfrom the complexgeev
(info = -8, -10) or the complexggev(info = -11, -13),
LINALG_INTERNAL_ERRORtoLINALG_VALUE_ERROR;ggevwith
info > n+2,LINALG_ERRORtoLINALG_INTERNAL_ERROR.lstsq,solve_lstsq,weighted_lstsq,solve_weighted_lstsq: an
invalidlworkfromgelsd(info = -12) and an undocumented negative
code,LINALG_VALUE_ERRORtoLINALG_INTERNAL_ERROR.constrained_lstsq,solve_constrained_lstsq,constrained_lstsq_space:
an invalidldaorldbfromgglse(info = -5, -7),
LINALG_INTERNAL_ERRORtoLINALG_VALUE_ERROR.solve_generalized_lstsq,generalized_lstsq: an invalidnorlda
frompotrf(info = -2, -4),LINALG_INTERNAL_ERRORto
LINALG_VALUE_ERROR.
- Breaking: every function that can fail has the two forms of the API
style decided in #44: apureform withouterr, and a form whoseerr
is mandatory, which is notpure.solve,inv,det,lstsq,pinv,
svdvalsandmnormhad one form with an optionalerr; each is split in
two, asnorm,eigvalsandeigvalshalready were, and both forms call
the samepuresubroutine.cholhad only thepureform and gains
chol(a [, lower] [, other_zeroed], err).weighted_lstsqand
constrained_lstsq, new in this release, have the same two forms. What a
caller has to change:- An
errthat is itself an absent optional argument can no longer be
passed through to a function: the form witherrneeds it present. Call
the form withouterr, or the subroutine, when it may be absent. - The form without
errtakes its matrices asintent(in), so it has no
overwrite_a(overwrite_matricesforconstrained_lstsq) and no
rankoutput.solve(a, b, overwrite_a=...),det(a, overwrite_a=...),
lstsq(a, b, overwrite_a=..., rank=...)and the like resolve only with
err; the subroutinessolve_lu,solve_lstsq,solve_weighted_lstsq
andsolve_constrained_lstsqkeep these arguments. In exchange,solve,
detandlstsqwithouterraccept a constant or an expression fora. .inv.stops on a singular matrix instead of returning a 0x0 matrix.
.inv.and.det.are the forms ofinvanddetwithouterr.solveandinvwitherrreturn an empty array on any error, as
lstsqdoes. For a singular matrix,solvereturned an array of the
shape ofb, andinvthen x nmatrix thatinvertoverwrote, both
with undefined values.
- An
- Breaking:
detand.det.return 0 for an exactly singular matrix,
with no error: the form witherrno longer returns aLINALG_ERROR,
and the form withouterrand.det.no longer stop.slogdetalready
returnedsign = 0for one. - Fortran 2018 is the minimum language standard: a
pureprocedure stops on
an error witherror stop, whichla_statealready relied on. - The
fypptemplates of the high-level modules regenerate their committed
sources byte for byte again. scripts/fypp_deploy.pydeploys every template underfypp/srcand
fypp/test. The exclusion list that held the ten high-level modules back is
gone, so--checknow covers the whole generated tree.- Every generated source under
src/is renamed from.f90to.F90: they
all carry cpp directives now, so they follow the extension rule the tree
already used forla_blas.F90andla_lapack.F90. Build files that list the
sources by name need the new spelling; fpm consumers list nothing. real(qp)andcomplex(qp)code compiles only whenLA_WITH_QPis defined,
which thequadfeature does. A build that defines neither macro carries
spanddpalone.qr_spacetakesaasintent(in): only its shape is read.
Added
pseudoinvert(a, pinva [, rtol] [, overwrite_a] [, err]): with
overwrite_a=.true.the SVD works onaitself instead of a copy, as in
svd,eigandeigh.ais left unchanged by default, as it always was.
.pinv.uses it on its own copy of the operand, so it copies once. A call
that passederrby position now needserr=.- A
puresubroutine twin for each LAPACK function with anintent(out)
argument: the matrix norms?langb,?lange,?lanhb,?lanhe,?lanhf,
?lanhp,?lanhs,?lansb,?lansf,?lansp,?lansy,?lantb,
?lantpand?lantr, and the extra-precise refinement helpers
?la_gbrcond,?la_gercond,?la_porcond,?la_syrcond, their_c
variants,?la_hercond_c,?la_herpvgrw,?la_porpvgrwand
?la_syrpvgrw.la_?lange_sub(norm, m, n, a, lda, work, res)takes the
arguments ofla_?langeand returns its value inres.la_lapackexposes
them as the genericslange_suband so on, bound to the bundled code in
every build,LA_EXTERNAL_LAPACKincluded. - Linear-algebra test suite ported from the Fortran standard library
(test-drive dev-dependency). solve_lu(a, b, x [, pivot] [, overwrite_a] [, err]), apuresubroutine form
ofsolvethat writes into a caller-provided solution array and can reuse a
caller-provided pivot array, so a repeated solve of the same size allocates
nothing.operator(.det.):.det. ais thepuredeterminant of a square matrix, with
nooverwrite_aflag and no error argument.invert(a, inva [, pivot] [, err]), which writes the inverse into a second
matrix instead of overwritinga, and an optionalpivotargument on both
forms ofinvert.la_lapackexposes seven more kind-agnostic generics, whose specifics were
already there for all six kinds:geqp3,ggev3,gges3,gghd3,geevx,
geesxandgesvx. As for every other generic, the quadruple-precision
procedures stay outside theLA_EXTERNAL_LAPACKselection.solve_chol(a, b, x [, lower] [, overwrite_a] [, err])factorizes a symmetric
or Hermitian positive definite matrix and solves in one call, and
solve_lower_chol(l, b, x [, err])/solve_upper_chol(u, b, x [, err])solve
from a Cholesky factor computed earlier. All three arepureand take one or
many right-hand sides.scripts/templatize.py --add-lapack-generic <name>...builds the interface
table entry of a generic from the declarations of its specifics and inserts it
in alphabetical order, soinclude/la_lapack_interfaces.fyppnever needs to be
written by hand.- Seven matrix property predicates in the new
la_matrix_property_checks
module:is_square,is_diagonal,is_symmetric,is_skew_symmetric,
is_hermitian,is_triangular(a, uplo)andis_hessenberg(a, uplo). trace(a),outer_product(u, v),cross_product(a, b),
kronecker_product(a, b)andhermitian(a), allpure, for every real and
complex kind.diaggains three overloads:diag(v, k)places a vector on thek-th
diagonal of a larger matrix, anddiag(a)/diag(a, k)extract a diagonal
of a matrix as a vector.lstsq_space(a, b, lrwork, liwork [, lcwork]), the workspace query of the
least-squares solver, which used to be a private routine.solve_lstsq(a, b, x [, real_storage] [, int_storage] [, cmpl_storage] [, cond] [, singvals] [, overwrite_a] [, rank] [, err]), the subroutine form
oflstsq. Given the working arrays it allocates nothing, and it can return
the singular values.weighted_lstsq(w, a, b, ...)andsolve_weighted_lstsq(w, a, b, x, ...),
which minimize||D(b - Ax)||withD = diag(sqrt(w)).constrained_lstsq(a, b, c, d, ...)and
solve_constrained_lstsq(a, b, c, d, x, ...), which minimize||b - Ax||
subject toCx = dthrough LAPACK'sgglse, with the matching
constrained_lstsq_space(a, c, lwork [, err])workspace query.- The optional precisions are fpm features.
quadcarries the 128-bit kinds
qp/wand is part of thedefaultprofile, so a plainfpm buildand
every consumer that asks for nothing keep the kinds they had.--profile lean
drops them, and with them a third of the library's source lines.xdpcarries
the 80-bit extended
kindsxdp/x/y; it is never a default, because 80-bit reals exist on x86
and x86_64 only.--profile allkindsturns both on. See the new
"Precision kinds and fpm features" section of the README. external-blasandexternal-lapackare features too, and--profile externalreplaces the--flag "-DLA_EXTERNAL_..."pair the continuous
integration used to spell out.- 80-bit extended-precision instances of every BLAS and LAPACK routine and of
the whole high-level API, initialsxfor real andyfor complex, behind
LA_WITH_XDP.xdpsits abovedpas a branch of its own, soqpkeeps
dpbelow it andla_qdgesv,la_qlag2d,la_dlag2q,la_wzgesv,
la_zlag2wandla_wlag2zkeep their names and their meaning. la_xddot, the extended-precision accumulation dot product, is public from
la_blas_level1but is not part of thesdotgeneric: its dummy arguments
arereal(dp), exactly those ofla_qddot, so a generic interface could not
tell the two apart.la_constantsexportsxdpalongsidesp,dpandqp, and the logical
parametersla_with_qpandla_with_xdp. An optional kind that a build left
out is-1, so code that imports the kind number still compiles.scripts/guard_kinds.pywrites the cpp fences into the templates and has a
--checkmode thegenerated-sourcesjob runs.la_statemessages format array arguments of any rank from 2 to 14: the elements in
array element order, then the shape, as in[1 2 3 4] (2x2). Only scalars and vectors
were formatted before.- The matrix exponential, ported from the Fortran standard library, in the new
la_matrix_functionsmodule:expm(a [, order])ispure,expm(a [, order], err)
returns the error state instead, andmatrix_exp(a [, order] [, work] [, iwork] [, err])/
matrix_exp(a, e [, order] [, work] [, iwork] [, err])arepuresubroutines that
overwriteaor write intoe. Givenworkandiwork, sized with
expm_space(a, lwork, liwork), they allocate no work arrays. Every real and complex
kind;orderis the Padé order, 10 by default. - Generalized least squares, ported from the Fortran standard library: minimize
(b - Ax)^H W^-1 (b - Ax)for observations with correlated errors, whose covariance
matrixWis symmetric (Hermitian) positive definite, through LAPACK'sggglm.
generalized_lstsq(w, a, b [, prefactored_w])ispure, and
generalized_lstsq(w, a, b [, prefactored_w], err)returns the error state instead.
solve_generalized_lstsq(w, a, b, x [, storage] [, prefactored_w] [, overwrite_a] [, overwrite_w] [, err])is thepuresubroutine form. Givenstorage, sized with
generalized_lstsq_space(a, lwork [, err]), and both overwrite flags, it allocates
nothing. Withprefactored_w=.true.,wis any square rootBof the covariance,
W = B B^H, instead of the covariance itself. Every real and complex kind. - QR factorization with column pivoting, ported from the Fortran standard library:
qr(a, q, r, pivots [, overwrite_a] [, storage] [, err])is apureoverload ofqr
that permutes the columns ofaso that|diag(R)|does not increase, with
a(:, pivots) = matmul(q, r), through LAPACK'sgeqp3.qr_space(a, lwork, pivoting [, err])sizes itsstorage. Full and reducedQandRas forqr. Every real and
complex kind. - Matrix rank, condition number, log-determinant and matrix power, for every real and
complex kind. The functions have apurespecific withouterrand a specific with a
mandatoryerr:matrix_rank(a [, rtol] [, atol] [, err])inla_svd: the number of singular values
abovemax(atol, rtol*smax), withrtol = max(m,n)*epsilonandatol = 0by default.cond(a [, order] [, err])inla_norms: the 2-norm condition number from the
singular values, for any shape, by default; the 1- and infinity-norm ones as LAPACK's
geconestimates; the Frobenius one from the explicit inverse.orderis spelled as
fornorm, and2is the spectral norm. A singular matrix gives+inf.slogdet(a, sign, logabsdet [, overwrite_a] [, err])inla_determinant, apure
subroutine:det(a) = sign*exp(logabsdet), with a unit-modulussignfor complex
matrices. A singular matrix givessign = 0andlogabsdet = -inf, not an error.matrix_power(a, n [, err])inla_matrix_functions:a**nby repeated squaring;
n = 0gives the identity, and a negativena power of the inverse.
Removed
la_xerblaandla_xerbla_array, public inla_blas_auxand re-exported
byla_blas. They did nothing: apureerror handler can neither print nor
stop. The BLAS and LAPACK routines no longer call them, and every routine
still returns the sameinfofor an invalid argument.
Fixed
eigandeigvalsno longer leak memory on a real matrix: the real and
imaginary parts of the eigenvalues were allocated as pointers and never
freed, 2n values per call.la_dgesddno longer writespath 5tto standard output on one of its
execution paths.la_claunhr_col_getrfnp2declares itscabs1statement function
real(sp), matching the precision of the data it works on.- Removed
la_ilaqiag, an unreachable misnamed copy ofla_iladiag. - Removed
la_qlag2qandla_wlag2w, unreachable converters between a kind
and itself. - The external BLAS interfaces for
snrm2anddnrm2declared no result
type, so any build withLA_EXTERNAL_BLASfailed to compile. - The test suite seeds its random-number generator, so its results are
reproducible from one run to the next. qrnow writes the whole orthogonal factor:?orgqr/?ungqris asked for
size(q,2)columns instead ofsize(a,2), so columnsn+1:mof a fullQare
no longer left undefined.qr_spacesizes its query for the same column count.mnorm(a, order, dim)handles any pair of dimensions of a rank-3 or higher
array. The permuted copy is allocated before it is written and is built with the
inverse permutation, sodim(1)/=1no longer writes through a null pointer and
dim=[1,k]withk>2no longer collapses the wrong axes.- Behaviour change:
lstsqreturns a solution of sizesize(a,2), as its
interface documents, instead of one the size of the right-hand side. The values
are unchanged; code that read the leadingsize(a,2)entries keeps working, code
that sized a receiving array frombhas to be updated. lstsqfrees its internal copy of the coefficient matrix, and no longer
deallocates the caller's matrix whenoverwrite_ais set.la_eye_sis part of theeyegeneric interface, soeye(m, mold=0.0_sp)
resolves.mnormacceptsfroas a spelling of the Frobenius (Euclidean) order.test_la_choleskycompiles, andla_testsruns it.qrrejects the shapes ofqandrit cannot fill: more rows thana, more
columns thanainr, or more thansize(a,1)columns inqor rows inr. Those
passed the size check before and came back with undefined or misplaced values.qrfrees its copy ofawhen thestorageit is given is too small.mnorm(a, order, dim)of an array of rank 3 or more returns an empty array on an
invalidorder, as it does on an invaliddim, instead of an unallocated result.