9      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                              ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 Safe<=DR9union binary lift : apply function on _union_ of two SetsGintersection binary lift : apply function on _intersection_ of two Sets inner productmultiplication by a scalarRing zero elementRing +negate the values in a functorsubtract two Additive objectslinear interpolation#`hilbertDistSq x y = || x - y ||^2`Squared 2-norm L1 norm!Euclidean norm"Lp norm (p > 0)# Infinity-norm$"Normalize w.r.t. p-norm (p finite)%Lp inner product (p > 0)& Reciprocal'Scale( unary dimension-checking bracket)!binary dimension-checking bracket*  !"#$%&'()*  !"#$%&'()* !"#$%&' ()     !"#$%&'(),(C) 2016 Marco Zocca, 2012-2015 Edward KmettGPL-3 (see LICENSE)zocca.marco gmail provisionalportableSafe *2Provides a test to see if a quantity is near zero.nearZero (1e-11 :: Double)FalsenearZero (1e-17 :: Double)TruenearZero (1e-5 :: Float)FalsenearZero (1e-7 :: Float)True+%Determine if a quantity is near zero.9 Rounding rule: Rounding rule, Rounding rule/Round to respectively 0 or 10 ; a < 1e-121 ; a < 1e-62 ; a < 1e-123 ; a < 1e-6*+9:,=-.>/0123*+,-./*++,-./ *+9:,=-.>/0123None65Wrap a function with a null check, returning in Maybe7IComponentwise tuple operations TODO : use semilattice properties instead8IComponentwise tuple operations TODO : use semilattice properties instead9integer-indexed ziplist: ", 2d arrays; foldr over the results of a fmap<strict left fold=indexed right fold456789:;<=>?@ABC456789:;<=>?@ABC6789:;<=54>?@ABC456789:;<=>?@ABCSafeDEFGDEFGGFEDDEFGSafeHInsert an elementI Lookup a keyJLookup with default 0KAPopulate an IM2 from a list of (row index, column index, value) L7Indexed left fold over an IM2, with general accumulatorMIndexed left fold over an IM2N/Left fold over an IM2, with general accumulatorOwInner indices become outer ones and vice versa. No loss of information because both inner and outer IntMaps are nubbed.P+Map over outer IM and filter all inner IM'sQ7Specialized filtering : keep only sub-diagonal elementsS<List of (row, col) indices of (nonzero) subdiagonal elementsU Map over IM2VIndexed map over IM2W Mapping keysHIJKLMNOPQRSTUVWXYZ[\]HIJKLMNOPQRSTUVWX]\[ZYHIJKLMNOPQRSTUVWXHIJKLMNOPQRSTUVWXYZ[\](C) 2016 Marco ZoccaGPL-3 (see LICENSE)zocca.marco gmail provisionalportableNone9;<=DR3g,`zeroSM m n` : Empty SpMatrix of size (m, n)i"`eye n` : identity matrix of rank njPermutation matrix from a (possibly incomplete) list of row swaps starting from row 0 e.g. `permutationSM 5 [1,3]` first swaps rows (0, 1) and then rows (1, 3) :  0,1,0,0,0 0,0,0,1,0 0,0,1,0,0 1,0,0,0,0 0,0,0,0,1kyPermutation matrix from a (possibly incomplete) list of row pair swaps e.g. `permutPairs 5 [(2,4)]` swaps rows 2 and 4 :  1,0,0,0,0 0,1,0,0,0 0,0,0,0,1 0,0,0,1,0 0,0,1,0,0l9`mkSubDiagonal n o xx` creates a square SpMatrix of size n with xx on the oth subdiagonalmDInsert an element in a preexisting Spmatrix at the specified indicesn?Add to existing SpMatrix using data from list (row, col, value)o:Create new SpMatrix using data from list (row, col, value)pECreate new SpMatrix assuming contiguous, 0-based indexing of elementsqHPopulate list with SpMatrix contents and populate missing entries with 0s`Looks up an element in the matrix with a default (if the element is not found, zero is returned)t3Zero-default lookup, infix form (no bound checking)`Looks up an element in the matrix with a default (if the element is not found, zero is returned)uIndexed filtering functionvbDiagonal, subdiagonal, superdiagonal partitions of a SpMatrix (useful for writing preconditioners)wbDiagonal, subdiagonal, superdiagonal partitions of a SpMatrix (useful for writing preconditioners)xbDiagonal, subdiagonal, superdiagonal partitions of a SpMatrix (useful for writing preconditioners)yfExtract a submatrix given the specified index bounds, rebalancing keys with the two supplied functionsz^Extract a submatrix given the specified index bounds NB : subtracts (i1, j1) from the indices{\Extract a submatrix given the specified index bounds NB : submatrix indices are _preserved_|Extract whole column}!Extract column within a row range~1Extract column within a row range, rebalance keys.Are the supplied indices within matrix bounds?Is the matrix square?Is the matrix diagonal?%Is the matrix lower/upper triangular?%Is the matrix lower/upper triangular?,Is the matrix orthogonal? i.e. Q^t ## Q == I/Data in internal representation (do not export)#(Number of rows, Number of columns)&Number of rows times number of columnsNumber of rowsNumber of columnsVertical stackingVertical stackingHorizontal stackingHorizontal stackingLeft fold over SpMatrixIndexed left fold over SpMatrixCount sub-diagonal nonzeros`Filter the index subset that lies below the diagonal (used in the QR decomposition, for example)Sparsify an SpMatrix3Round almost-0 and almost-1 to 0 and 1 respectively0Swap two rows of a SpMatrix (bounds not checked).Swap two rows of a SpMatrix (bounds checked) transposeSM : Matrix transposeRemoves all elements x for which `| x | <= eps`)Removes all elements x for which `| x | <= eps`)A^T BA B^T Contract row i of A with column j of B up to an index nD, i.e. summing over repeated indices: Aij Bjk , for j in [0 .. n] S^_`abcdefghijklmnopqrstuvwxyz{|}~K^_`abcdefghijklmnopqrstuvwxyz{|}~Sbcdefghijklmnopqrstuxwvyz{|}~^_`aM^_`abcdefghijklmnopqrstuvwxyz{|}~(C) 2016 Marco ZoccaGPL-3 (see LICENSE)zocca.marco gmail provisionalportableNone9;<=DRSpVector sparsityNumber of nonzeros*empty sparse vector (length n, no entries)"singleton sparse vector (length 1)Qcreate a sparse vector from an association list while discarding all zero entries3", from logically dense array (consecutive indices)>Create new sparse vector, assumin 0-based, contiguous indexing^Map a function over a range of indices and filter the result (indices and values) to fit in a n-long SpVector0", using just the integer bounds of the interval_one-hot encoding : `oneHotSV n k` produces a SpVector of length n having 1 at the k-th positionDENSE vector of `1`sDENSE vector of `0`s3Populate a SpVector with the contents of a Vector. jPopulate a Vector with the entries of a SpVector, discarding the indices (NB: loses sparsity information).Z- | Populate a Vector with the entries of a SpVector, replacing the missing entries with 0insert element x at index i in a preexisting SpVectorTo dense list (default = 0)Indexed fold over SpVectorLookup an index in a SpVector7Lookup an index, return a default value if lookup fails8Lookup an index in a SpVector, returns 0 if lookup fails Tail elements Head element2Keep the first n components of the SpVector (like ? for lists)LDiscard the first n components of the SpVector and rebalance the keys (like @ for lists)2Keep the first n components of the SpVector (like ? for lists)Concatenate two sparse vectorsFilterIndexed filter*Generate an arbitrary (not random) vector u such that `v dot u = 0`2&2/(C) 2016 Marco ZoccaGPL-3 (see LICENSE)zocca.marco gmail provisionalportableNoneA2modify the size of a SpVector. Do not use directlyAInsert row , using the provided row index transformation functionInsert row CInsert column, using the provided row index transformation function Insert column#Outer product (all-with-all matrix)#Outer product (all-with-all matrix)AFill the diagonal of a SpMatrix with the components of a SpVectorpromote a SV to SM.Demote (n x 1) or (1 x n) SpMatrix to SpVectorRLookup a row in a SpMatrix; returns an SpVector with the row, if this is non-emptyExtract ith rowExtract jth columnGeneric extraction functionExtract ith row (dense)Extract jth columnExtract the diagonal&extract row interval (all entries between columns j1 and j2, INCLUDED, are returned) extractSubRow :: SpMatrix a -> IxRow -> (IxCol, IxCol) -> SpVector a extractSubRow m i (j1, j2) = case lookupRowSM m i of Nothing -> zeroSV (ncols m) Just rv -> ifilterSV (j _ -> j >= j1 && j <= j2) rv", returning in Maybe extractSubRow :: SpMatrix a -> IxRow -> (Int, Int) -> Maybe (SpVector a) extractSubRow m i (j1, j2) = resizeSV (j2 - j1) . ifilterSV (j _ -> j >= j1 && j  =j2) <$ lookupRowSM m iExtract an interval of SpVector components, changing accordingly the resulting SpVector size. Keys are _not_ rebalanced, i.e. components are still labeled according with respect to the source matrix.>extract row interval, rebalance keys by subtracting lowest oneextract column intervalAextract column interval, rebalance keys by subtracting lowest oneMatrix-on-vectorMatrix-on-vector>Vector-on-matrix (FIXME : transposes matrix: more costly than  , I think)>Vector-on-matrix (FIXME : transposes matrix: more costly than  , I think)6Pack a V.Vector of SpVectors as columns of an SpMatrix&BACDEFGHIJ  !"#$%&'()*+,-./456789:;<=>?@ABCDEFG^_`abcdefghijklmnopqrstuvwxyz{|}~%BACDEFGHIJ None 9:;<=DR(Sparsify an SpVector+uses the R matrix from the QR factorization a vector xS uniquely defines an orthogonal plane; the Householder operator reflects any point v3 with respect to this plane: v' = (I - 2 x >< x) vKGivens coefficients (using stable algorithm shown in Anderson, Edward (4 December 2000). "Discontinuous Plane Rotations and the Symmetric Eigenvalue Problem". LAPACK Working Note)zGivens method, row version: choose other row index i' s.t. i' is : * below the diagonal * corresponding element is nonzeroQR.C1 ) To zero out entry A(i, j) we must find row k such that A(k, j) is non-zero but A has zeros in row k for all columns less than j.LNB: the current version is quite inefficient in that: 1. the Givens' matrix G_iC is different from Identity only in 4 entries 2. at each iteration i we multiply G_i by the previous partial result M0. Since this corresponds to a rotation, and the KQ function already computes the value of the resulting non-zero component (output r@), `G_i ## M` can be simplified by just changing two entries of M3 (i.e. zeroing one out and changing the other into r).L,Returns a set of rows {k} that satisfy QR.C1MIs the k'th the first nonzero column in the row?Given a matrix A, returns a pair of matrices (Q, R) such that Q R = A, Q is orthogonal and R is upper triangular. Applies Givens rotation iteratively to zero out sub-diagonal elementsN,Givens matrices in order [G1, G2, .. , G_N ]`eigsQR n mm` performs n* iterations of the QR algorithm on matrix mm3, and returns a SpVector containing all eigenvalues`eigsRayleigh n mm` performs n0 iterations of the Rayleigh algorithm on matrix mm and returns the eigenpair closest to the initialization. It displays cubic-order convergence, but it also requires an educated guess on the initial eigenpair eigRayleigh :: Int -- max # iterations -> SpMatrix Double -- matrix -> (SpVector Double, Double) -- initial guess of (eigenvector, eigenvalue) -> (SpVector Double, Double) -- final estimate of (eigenvector, eigenvalue)_Given a positive semidefinite matrix A, returns a lower-triangular matrix L such that L L^T = AEGiven a matrix A, returns a pair of matrices (L, U) such that L U = AOoApply a function over a range of integer indices, zip the result with it and filter out the almost-zero entries+used for Incomplete LU : remove entries in m" corresponding to zero entries in m2(Given a matrix A and a positive integer n-, this procedure finds the basis of an order n Krylov subspace (as the columns of matrix Q), along with an upper Hessenberg matrix H, such that A = Q^T H Q. At the i`th iteration, it finds (i + 1) coefficients (the i`th column of the Hessenberg matrix H) and the (i + 1)`th Krylov vector.WPartition a matrix into strictly subdiagonal, diagonal and strictly superdiagonal partsV`mSsor aa omega` : if `omega = 1` it returns the symmetric Gauss-Seidel preconditionerGDirect solver based on a triangular factorization of the system matrix.PNB in the computation of xi. we must rebalance the subrow indices because N does that too, in order to take the inner product with consistent index pairsQone step of TFQMRRone step of BCG one step of CGS!Hiterate solver until convergence or until max # of iterations is reached"one step of BiCGSTAB#Hiterate solver until convergence or until max # of iterations is reachedSGLeast-squares approximation of a rectangular system of equaitons. Uses  \ for the linear solve$KLinear solve with _deterministic_ starting vector (every component at 0.1) % \0 : linSolve using the BiCGSTAB method as defaultT(transform state until a condition is metU0Keep a moving window buffer (length 2) of state xw to assess convergence, stop when either a condition on that list is satisfied or when max # of iterations is reached &0Keep a moving window buffer (length 2) of state x to assess convergence, stop when either a condition on that list is satisfied or when max # of iterations is reached (i.e. same thing as U& but this one runs in the State monad)(Oiterate until convergence is verified or we run out of a fixed iteration budgetVconvergence check (FIXME)Wrun niter! iterations and append the state x to a list xs, stop when either the xs satisfies a predicate q or when the counter reaches 0)", NO convergence check +Dense SpMatrix,Dense SpVector -Sparse SpMatrix.Sparse SpVectorbXYZ[\]^_`abcd efgh i jklmnopqrs t uvwxKLMNyOzP{QR !"#S$%TU&|}'(VW)*+,-./01,      !"#$%&'()*+,-.1$%#!    "     *+,-.&)('>XYZ[\]^_`abcd efgh i jklmnopqrs t uvwxKLMNyOzP{QR !"#S$%TU&|}'(VW)*+,-./01~     !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghhijklmnopqrstuvwxyz{|}~                        ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ ABCDEFGHIJKDLMDLNOPQRSTUVWX Y Z [ \ ] ^ _ ` a b c d e f g h i j  k l  m n o  p q r s  t u v w x y z { | }  ~        4sparse-linear-algebra-0.2.1.1-LiHhIkAT3IWCzxI9rzGemANumeric.LinearAlgebra.Class Numeric.EpsData.Sparse.UtilsData.Sparse.TypesData.Sparse.IntMap2.IntMap2Data.Sparse.SpMatrixData.Sparse.SpVectorData.Sparse.CommonNumeric.LinearAlgebra.Sparse SpContainerScIxscInsertscLookup@@SetliftU2liftI2SparsespyHasDataHDDatadat FiniteDimFDSizedimNormednormHilbertdot VectorSpace.*Additivezero^+^one^*^negated^-^lerp hilbertDistSqnormSqnorm1norm2normP normInfty normalizedotLp reciprocalscalewithDimwithDim2EpsilonnearZeroisNz roundZeroroundOne roundZeroOne$fEpsilonCDouble$fEpsilonCFloat$fEpsilonDouble$fEpsilonFloatUBLBharnessmaxTupminTup denseIxArray denseIxArray2foldrMap foldlStrictifoldrinBounds inBounds2 inBounds0 inBounds02head'tail'IxColIxRowColsRows insertIM2 lookupIM2 lookupWD_IM fromListIM2 ifoldlIM2' ifoldlIM2foldlIM2 transposeIM2 ifilterIM2 filterSubdiagcountSubdiagonalNZsubdiagIndicesrpairsmapIM2imapIM2 mapKeysIM2 mapColumnIM2$fNormedIntMap$fHilbertIntMap$fVectorSpaceIntMap$fAdditiveIntMap $fSetIntMapSMInfosmNzsmSpySpMatrixSMsmDimsmDatasizeStrzeroSM mkDiagonaleye permutationSM permutPairsSM mkSubDiagonalinsertSpMatrix fromListSM' fromListSMfromListDenseSM toDenseListSMlookupSM lookupWD_SM@@!filterSMextractSubDiagextractSuperDiag extractDiagextractSubmatrixSMextractSubmatrixRebalanceKeysextractSubmatrix extractColSMextractSubColSMextractSubColSM_RK isValidIxSM isSquareSM isDiagonalSM isLowerTriSM isUpperTriSMisOrthogonalSMimmSMdimSMnelSMnrowsncolsinfoSMnzSMspySMnzRowbwMinSMbwMaxSM bwBoundsSM vertStackSM-=- horizStackSM-||- ifilterSMfoldlSMifoldlSMcountSubdiagonalNZSMsubdiagIndicesSM sparsifyIM2 sparsifySMroundZeroOneSMswapRows swapRowsSafe transposeSMmatScale normFrobeniusmatMat##matMatSparsified#~##^###^ contractSub$fSpContainerSpMatrixa$fSparseSpMatrixa$fHasDataSpMatrixa$fFiniteDimSpMatrix$fAdditiveSpMatrix $fSetSpMatrix$fFunctorSpMatrix$fShowSpMatrix $fEqSpMatrix $fEqSMInfo $fShowSMInfoSpVectorSVsvDimsvDataspySVnzSV sizeStrSVzeroSV singletonSV mkSpVector mkSpVectorD mkSpVector1fromListDenseSVspVectorDenseIxspVectorDenseLoHi oneHotSVUoneHotSVonesSVzerosSV fromVectortoVector toVectorDenseinsertSpVector fromListSVtoListSV toDenseListSVifoldSVlookupSVlookupDefaultSV lookupDenseSVtailSVheadSVtakeSVdropSVconcatSVfilterSV ifilterSV orthogonalSV$fShowSpVector$fNormedSpVector$fHilbertSpVector$fSpContainerSpVectora$fSparseSpVectora$fHasDataSpVectora$fFiniteDimSpVector$fVectorSpaceSpVector$fAdditiveSpVector$fFoldableSpVector $fSetSpVector$fFunctorSpVector $fEqSpVectorprd insertRowWith insertRow insertColWith insertCol outerProdSV>< diagonalSMsvToSMtoSV lookupRowSM extractRow extractColextractVectorDenseWithextractRowDenseextractColDenseextractDiagDense extractSubRowextractSubRow_RK extractSubColextractSubCol_RKmatVec#>vecMat<#fromCols$fPrintDenseSpMatrix$fPrintDenseSpVectorLinSolveMethodBICGSTAB _xBicgstabCGS_xBCG_xBcgTFQMR_xTfqCGNE_xCgne sparsifySVconditionNumberSMhhMathhReflgivensqreigsQR eigRayleighcholluilu0arnoldidiagPartitionsmSsorluSolvecgnetfqmrbcgcgsStepcgs bicgstabStepbicgstablinSolve<\>modifyInspectNdiffSqLuntilConverged runAppendN' randArrayrandMatrandVec randSpMat randSpVec$fShowBICGSTAB $fShowCGS $fShowBCG$fEqCGNE $fEqTFQMR$fEqBCG$fEqCGS $fEqBICGSTAB$fEqLinSolveMethod$fShowLinSolveMethod almostZero almostOnebaseGHC.Numabsghc-prim GHC.Classes<= withDefault with2DefaultsGHC.ListtakedropresizeSV PrintDense mapKeysSV showNonZero toDenseRowtoDenseRowClipnewline printDenseSMtoDenseListClip printDenseSV givensCoef candidateRowsfirstNonZeroColumngmats onRangeSparse lubwSolve tfqmrStepbcgSteppinv modifyUntil loopUntilAccnormDiffConverged runAppendNCGNE_TFQMR_BCG_CGS_ BICGSTAB_ _rBicgstab _pBicgstab_r_p_u_rBcg_rHatBcg_pBcg_pHatBcg_wTfq_uTfq_vTfq_dTfq_mTfq_tauTfq _thetaTfq_etaTfq_rhoTfq _alphaTfq_rCgne_pCgnehypotsignhhV lufwSolvecgneStepmeanlnorm2l