Ρ'      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                                  ! " # $ % & 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-normL1 normEuclidean normLp 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.' Rounding rule( Rounding rule' Rounding rule*Round to respectively 0 or 1+ ) a * 1e-12, ) a * 1e-6- ) a * 1e-12. ) a * 1e-6%&'('+(),*+,-.%&'()*%&&'()* %&'('+(),*+,-.Safe1IComponentwise tuple operations TODO : use semilattice properties instead2IComponentwise tuple operations TODO : use semilattice properties instead3integer-indexed ziplist4 ", 2d arrays5 foldr over the results of a fmap6strict left fold7indexed right fold /0123456789:; /0123456789:; 12345670/89:; /0123456789:;Safe<=>?<=>??>=<<=>?Safe @Insert an elementA Lookup a keyBBPpopulate an IM2 from a list of (row index, column index, value) C7Indexed left fold over an IM2, with general accumulatorDIndexed left fold over an IM2E/Left fold over an IM2, with general accumulatorFwInner indices become outer ones and vice versa. No loss of information because both inner and outer IntMaps are nubbed.G+Map over outer IM and filter all inner IM'sH7Specialized filtering : keep only sub-diagonal elementsJ<List of (row, col) indices of (nonzero) subdiagonal elementsL Map over IM2MIndexed map over IM2N Mapping keys@ABCDEFGHIJKLMNOPQRST@ABCDEFGHIJKLMNOTSRQP@ABCDEFGHIJKLMNO@ABCDEFGHIJKLMNOPQRST(C) 2016 Marco ZoccaGPL-3 (see LICENSE)zocca.marco gmail provisionalportableSafe9;<=DR5^,`zeroSM m n` : Empty SpMatrix of size (m, n)`"`eye n` : identity matrix of rank naPermutation 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,1byPermutation 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,0c9`mkSubDiagonal n o xx` creates a square SpMatrix of size n with xx on the oth subdiagonaldDInsert an element in a preexisting Spmatrix at the specified indicese?Add to existing SpMatrix using data from list (row, col, value)f:Create new SpMatrix using data from list (row, col, value)gECreate new SpMatrix assuming contiguous, 0-based indexing of elementshHPopulate list with SpMatrix contents and populate missing entries with 0j`Looks up an element in the matrix with a default (if the element is not found, zero is returned)l3Zero-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)m^Zero-default lookup, infix form ("safe" : throws exception if lookup is outside matrix bounds)`Looks up an element in the matrix with a default (if the element is not found, zero is returned)nIndexed filtering functionobDiagonal, subdiagonal, superdiagonal partitions of a SpMatrix (useful for writing preconditioners)pbDiagonal, subdiagonal, superdiagonal partitions of a SpMatrix (useful for writing preconditioners)qbDiagonal, subdiagonal, superdiagonal partitions of a SpMatrix (useful for writing preconditioners)rfExtract a submatrix given the specified index bounds, rebalancing keys with the two supplied functionss^Extract a submatrix given the specified index bounds NB : subtracts (i1, j1) from the indicest\Extract a submatrix given the specified index bounds NB : submatrix indices are _preserved_uExtract whole rowv!Extract column within a row rangew1Extract column within a row range, rebalance keysxExtract whole columny!Extract column within a row rangez1Extract 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 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] UUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~NUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~UYZ[\]^_`abcdefghijlmknqporstuvwxyz{|}~UVWXOUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~(C) 2016 Marco ZoccaGPL-3 (see LICENSE)zocca.marco gmail provisionalportableSafe9;<=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`sinsert 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 elementConcatenate two sparse vectorsFilterIndexed filter*Generate an arbitrary (not random) vector u such that `v dot u = 0`,!,)(C) 2016 Marco ZoccaGPL-3 (see LICENSE)zocca.marco gmail provisionalportableSafeAInsert 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 SpVectorExtract ith rowExtract jth columnGeneric extraction functionExtract ith row (dense)Extract jth columnExtract the diagonalextract row interval>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)"-./01234  !"#$%&'()*/0123456789:;<=>?@ABCDEFGHIJKLMNOUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~!-./01234 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) v5Givens 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.6Is the k'th the first nonzero column in the row?7,Returns a set of rows {k} that satisfy QR.C1Given 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 elements8,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 = A9oApply 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 WPartition a matrix into strictly subdiagonal, diagonal and strictly superdiagonal parts V`mSsor aa omega` : if `omega = 1` it returns the symmetric Gauss-Seidel preconditioner:one step of TFQMR;one step of BCGone step of CGSHiterate solver until convergence or until max # of iterations is reachedone step of BiCGSTABHiterate solver until convergence or until max # of iterations is reached<GLeast-squares approximation of a rectangular system of equaitons. Uses  \ for the linear solveKLinear solve with _deterministic_ starting vector (every component at 0.1)  \0 : linSolve using the BiCGSTAB method as default=(transform state until a condition is met>0Keep 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 >& but this one runs in the State monad)?Oiterate until convergence is verified or we run out of a fixed iteration budget@convergence check (FIXME)Arun 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 SpMatrixDense SpVector Sparse SpMatrixSparse SpVector_BCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ab5678c9d   e : ;<=>fg?@A)     /      ;BCDEFGHIJKLMNOPQR STUVWXYZ[\]^_`ab5678c9d   e : ;<=>fg?@Ah     !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^__`abcdefghijklmnopqrstuvwxyz{|}~                                    ! " # $ % & ' ( ) * + , - . /0123456789:;<=>?@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 [ \  ] ^ _ ` a b c d e f  g h i j k l m n op4sparse-linear-algebra-0.2.1.0-9udnDu8oXhGAgocVgZxC3kNumeric.LinearAlgebra.Class Numeric.EpsData.Sparse.UtilsData.Sparse.TypesData.Sparse.IntMap2.IntMap2Data.Sparse.SpMatrixData.Sparse.SpVectorData.Sparse.CommonNumeric.LinearAlgebra.SparseSetliftU2liftI2SparsespyHasDataHDDatadat FiniteDimFDSizedimNormednormHilbertdot VectorSpace.*Additivezero^+^one^*^negated^-^lerp hilbertDistSqnormSqnorm1norm2normP normInfty normalizedotLp reciprocalscalewithDimwithDim2EpsilonnearZeroisNz roundZeroroundOne roundZeroOne$fEpsilonCDouble$fEpsilonCFloat$fEpsilonDouble$fEpsilonFloatUBLBmaxTupminTup denseIxArray denseIxArray2foldrMap foldlStrictifoldrinBounds inBounds2 inBounds0 inBounds02IxColIxRowColsRows insertIM2 lookupIM2 fromListIM2 ifoldlIM2' ifoldlIM2foldlIM2 transposeIM2 ifilterIM2 filterSubdiagcountSubdiagonalNZsubdiagIndicesrpairsmapIM2imapIM2 mapKeysIM2 mapColumnIM2$fNormedIntMap$fHilbertIntMap$fVectorSpaceIntMap$fAdditiveIntMap $fSetIntMapSMInfosmNzsmSpySpMatrixSMsmDimsmDatasizeStrzeroSM mkDiagonaleye permutationSM permutPairsSM mkSubDiagonalinsertSpMatrix fromListSM' fromListSMfromListDenseSM toDenseListSMlookupSM lookupWD_SM lookupWD_IM@@!@@filterSMextractSubDiagextractSuperDiag extractDiagextractSubmatrixSMextractSubmatrixRebalanceKeysextractSubmatrix extractRowSMextractSubRowSMextractSubRowSM_RK extractColSMextractSubColSMextractSubColSM_RK isValidIxSM isSquareSM isDiagonalSMisOrthogonalSMimmSMdimSMnelSMnrowsncolsinfoSMnzSMspySMnzRowbwMinSMbwMaxSM bwBoundsSM vertStackSM-=- horizStackSM-||- ifilterSMfoldlSMifoldlSMcountSubdiagonalNZSMsubdiagIndicesSM sparsifyIM2 sparsifySMroundZeroOneSMswapRows swapRowsSafe transposeSMmatScale normFrobeniusmatMat##matMatSparsified#~##^###^ contractSub$fSparseSpMatrixa$fHasDataSpMatrixa$fFiniteDimSpMatrix$fAdditiveSpMatrix $fSetSpMatrix$fFunctorSpMatrix$fShowSpMatrix $fEqSpMatrix $fEqSMInfo $fShowSMInfoSpVectorSVsvDimsvDataspySVnzSV sizeStrSVzeroSV singletonSV mkSpVector mkSpVectorD mkSpVector1fromListDenseSVspVectorDenseIxspVectorDenseLoHi oneHotSVUoneHotSVonesSVzerosSVinsertSpVector fromListSVtoListSV toDenseListSVifoldSVlookupSVlookupDefaultSV lookupDenseSVtailSVheadSVconcatSVfilterSV ifilterSV orthogonalSV$fShowSpVector$fNormedSpVector$fHilbertSpVector$fSparseSpVectora$fHasDataSpVectora$fFiniteDimSpVector$fVectorSpaceSpVector$fAdditiveSpVector$fFoldableSpVector $fSetSpVector$fFunctorSpVector $fEqSpVectorprd insertRowWith insertRow insertColWith insertCol outerProdSV>< diagonalSMsvToSMtoSV extractRow extractColextractVectorDenseWithextractRowDenseextractColDenseextractDiagDense extractSubRowextractSubRow_RK extractSubColextractSubCol_RKmatVec#>vecMat<#$fPrintDenseSpMatrix$fPrintDenseSpVectorLinSolveMethodBICGSTAB _xBicgstabCGS_xBCG_xBcgTFQMR_xTfqCGNE_xCgne sparsifySVconditionNumberSMhhMathhReflgivensqreigsQR eigRayleighcholluilu0diagPartitionsmSsorcgnetfqmrbcgcgsStepcgs bicgstabStepbicgstablinSolve<\>modifyInspectNdiffSqL runAppendN' randArrayrandMatrandVec randSpMat randSpVec$fShowBICGSTAB $fShowCGS $fShowBCG$fEqCGNE $fEqTFQMR$fEqBCG$fEqCGS $fEqBICGSTAB$fEqLinSolveMethod$fShowLinSolveMethod almostZero almostOnebaseGHC.Numabsghc-prim GHC.Classes<= withDefault with2Defaults PrintDense showNonZero toDenseRowtoDenseRowClipnewline printDenseSMtoDenseListClip printDenseSV givensCoeffirstNonZeroColumn candidateRowsgmats onRangeSparse tfqmrStepbcgSteppinv modifyUntil loopUntilAccuntilConvergednormDiffConverged 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_pCgnehypotsignhhVpermutAAcgneStepmeanlnorm2l