úÎÄüÀ;8      !"#$%&'()*+,-./01234567NoneAType of matrices.`Elements can be of any type. Rows and columns are indexed starting by 1. This means that, if  m :: Matrix a and  i,j :: Int, then  m ! (i,j) is the element in the i-th row and j-th column of m.Number of rows.Number of columns.8.Number of columns of the matrix without offset9(Content of the matrix as a plain vector.:/Just a cool way to output the size of a matrix.Display a matrix as a ; using the < instance of its elements. O(rows*cols) . Similar to =<. It copies the matrix content dropping any extra memory.Useful when using  from a big matrix. O(rows*cols)(. Map a function over a row. Example: Œ ( 1 2 3 ) ( 1 2 3 ) ( 4 5 6 ) ( 5 6 7 ) mapRow (\_ x -> x + 1) 2 ( 7 8 9 ) = ( 7 8 9 ) O(rows*cols)+. Map a function over a column. Example: Œ ( 1 2 3 ) ( 1 3 3 ) ( 4 5 6 ) ( 4 6 6 ) mapCol (\_ x -> x + 1) 2 ( 7 8 9 ) = ( 7 9 9 ) O(rows*cols)$. The zero matrix of the given size. €zero n m = n 1 ( 0 0 ... 0 0 ) 2 ( 0 0 ... 0 0 ) ( ... ) ( 0 0 ... 0 0 ) n ( 0 0 ... 0 0 ) O(rows*cols)C. Generate a matrix from a generator function. Example of usage: à ( 1 0 -1 -2 ) ( 3 2 1 0 ) ( 5 4 3 2 ) matrix 4 4 $ \(i,j) -> 2*i - j = ( 7 6 5 4 )  O(rows*cols)%. Identity matrix of the given order. ‚identity n = n 1 ( 1 0 ... 0 0 ) 2 ( 0 1 ... 0 0 ) ( ... ) ( 0 0 ... 1 0 ) n ( 0 0 ... 0 1 ) ]Create a matrix from a non-empty list given the desired size. The list must have at least  rows*cols elements. An example: _ ( 1 2 3 ) ( 4 5 6 ) fromList 3 3 [1..] = ( 7 8 9 ) .Get the elements of a matrix stored in a list. H ( 1 2 3 ) ( 4 5 6 ) toList ( 7 8 9 ) = [1,2,3,4,5,6,7,8,9] qGet the elements of a matrix stored in a list of lists, where each list contains the elements of a single row. [ ( 1 2 3 ) [ [1,2,3] ( 4 5 6 ) , [4,5,6] toLists ( 7 8 9 ) = , [7,8,9] ] =Create a matrix from a non-empty list of non-empty lists. ?Each list must have at least as many elements as the first list. Examples: hfromLists [ [1,2,3] ( 1 2 3 ) , [4,5,6] ( 4 5 6 ) , [7,8,9] ] = ( 7 8 9 ) kfromLists [ [1,2,3 ] ( 1 2 3 ) , [4,5,6,7] ( 4 5 6 ) , [8,9,0 ] ] = ( 8 9 0 )O(1)). Represent a vector as a one row matrix.O(1),. Represent a vector as a one column matrix. O(rows*cols). Permutation matrix. ÿPpermMatrix n i j = i j n 1 ( 1 0 ... 0 ... 0 ... 0 0 ) 2 ( 0 1 ... 0 ... 0 ... 0 0 ) ( ... ... ... ) i ( 0 0 ... 0 ... 1 ... 0 0 ) ( ... ... ... ) j ( 0 0 ... 1 ... 0 ... 0 0 ) ( ... ... ... ) ( 0 0 ... 0 ... 0 ... 1 0 ) n ( 0 0 ... 0 ... 0 ... 0 1 )When i == j it reduces to   n.O(1)1. Get an element of a matrix. Indices range from (1,1) to (n,m). It returns an >. if the requested element is outside of range.O(1). Unsafe variant of , without bounds checking.Short alias for .?Internal alias for . Variant of ( that returns Maybe instead of an error.O(1)$. Get a row of a matrix as a vector.O(rows)'. Get a column of a matrix as a vector.O(min rows cols). Diagonal of a not necessarily square matrix. O(rows*cols). Transform a  to a @ of size  rows*cols?. This is equivalent to get all the rows of the matrix using 0 and then append them, but far more efficient.(Replace the value of a cell in a matrix.Unsafe variant of , without bounds checking. O(rows*cols)(. The transpose of a matrix. Example: _ ( 1 2 3 ) ( 1 4 7 ) ( 4 5 6 ) ( 2 5 8 ) transpose ( 7 8 9 ) = ( 3 6 9 )ŒExtend a matrix to a given size adding a default element. If the matrix already has the required size, nothing happens. The matrix is never reduced in size. Example: £ ( 1 2 3 0 0 ) ( 1 2 3 ) ( 4 5 6 0 0 ) ( 4 5 6 ) ( 7 8 9 0 0 ) extendTo 0 4 5 ( 7 8 9 ) = ( 0 0 0 0 0 )The definition of  is based on : BextendTo e n m a = setSize e (max n $ nrows a) (max m $ ncols a) a}Set the size of a matrix to given parameters. Use a default element for undefined entries if the matrix has been extended.O(1)>. Extract a submatrix given row and column limits. Example: g ( 1 2 3 ) ( 4 5 6 ) ( 2 3 ) submatrix 1 2 2 3 ( 7 8 9 ) = ( 5 6 ) O(rows*cols)6. Remove a row and a column from a matrix. Example: a ( 1 2 3 ) ( 4 5 6 ) ( 1 3 ) minorMatrix 2 2 ( 7 8 9 ) = ( 7 9 ) O(1)›. Make a block-partition of a matrix using a given element as reference. The element will stay in the bottom-right corner of the top-left corner matrix. ÿq ( ) ( | ) ( ) ( ... | ... ) ( x ) ( x | ) splitBlocks i j ( ) = (-------------) , where x = a_{i,j} ( ) ( | ) ( ) ( ... | ... ) ( ) ( | )WNote that some blocks can end up empty. We use the following notation for these blocks: #( TL | TR ) (---------) ( BL | BR )/Where T = Top, B = Bottom, L = Left, R = Right.!$Join blocks of the form detailed in   . Precisely: @joinBlocks (tl,tr,bl,br) = (tl <|> tr) <-> (bl <|> br)")Horizontally join two matrices. Visually: ( A ) <|> ( B ) = ( A | B )Where both matrices A and B have the same number of rows. This condition is not checked.#'Vertically join two matrices. Visually: G ( A ) ( A ) <-> ( B ) = ( - ) ( B )Where both matrices A and B# have the same number of columns. This condition is not checked.$þPerform an operation element-wise. The second matrix must have at least as many rows and columns as the first matrix. If it's bigger, the leftover items will be ignored. If it's smaller, it will cause a run-time error. You may want to use %D if you are definitely sure that a run-time error won't arise.%Unsafe version of $ , but faster.AInternal unsafe addition.BInternal unsafe substraction.&-Standard matrix multiplication by definition.'-Standard matrix multiplication by definition.CNStandard matrix multiplication by definition, without checking if sizes match.D3Strassen's algorithm over square matrices of order 2^n.(!Strassen's matrix multiplication.EStrassen's mixed algorithm.)'Mixed Strassen's matrix multiplication.*-Scale a matrix by a given factor. Example: t ( 1 2 3 ) ( 2 4 6 ) ( 4 5 6 ) ( 8 10 12 ) scaleMatrix 2 ( 7 8 9 ) = ( 14 16 18 )+*Scale a row by a given factor. Example: q ( 1 2 3 ) ( 1 2 3 ) ( 4 5 6 ) ( 8 10 12 ) scaleRow 2 2 ( 7 8 9 ) = ( 7 8 9 ),<Add to one row a scalar multiple of another row. Example: € ( 1 2 3 ) ( 1 2 3 ) ( 4 5 6 ) ( 6 9 12 ) combineRows 2 2 1 ( 7 8 9 ) = ( 7 8 9 )-(Switch two rows of a matrix. Example: n ( 1 2 3 ) ( 4 5 6 ) ( 4 5 6 ) ( 1 2 3 ) switchRows 1 2 ( 7 8 9 ) = ( 7 8 9 ).*Switch two coumns of a matrix. Example: n ( 1 2 3 ) ( 2 1 3 ) ( 4 5 6 ) ( 5 4 6 ) switchCols 1 2 ( 7 8 9 ) = ( 8 7 9 )/Matrix LU decomposition with partial pivoting. The result for a matrix M is given in the format  (U,L,P,d) where:U is an upper triangular matrix.L is an unit lower triangular matrix.P is a permutation matrix.d is the determinant of P.PM = LU.™These properties are only guaranteed when the input matrix is invertible. An additional property matches thanks to the strategy followed for pivoting:L_(i,j) <= 1, for all i,j.„This follows from the maximal property of the selected pivots, which also leads to a better numerical stability of the algorithm.Example: ¹ ( 1 2 0 ) ( 2 0 2 ) ( 1 0 0 ) ( 0 0 1 ) ( 0 2 1 ) ( 0 2 -1 ) ( 1/2 1 0 ) ( 1 0 0 ) luDecomp ( 2 0 2 ) = ( ( 0 0 2 ) , ( 0 1 1 ) , ( 0 1 0 ) , 1 )F+ is returned if no LU decomposition exists.0Unsafe version of /-. It fails when the input matrix is singular.1Matrix LU decomposition with complete pivoting. The result for a matrix M is given in the format  (U,L,P,Q,d,e) where:U is an upper triangular matrix.L is an unit lower triangular matrix.P,Q are permutation matrices.d,e are the determinants of P and Q respectively.PMQ = LU.™These properties are only guaranteed when the input matrix is invertible. An additional property matches thanks to the strategy followed for pivoting:L_(i,j) <= 1, for all i,j.„This follows from the maximal property of the selected pivots, which also leads to a better numerical stability of the algorithm.Example: Ï ( 1 0 ) ( 2 1 ) ( 1 0 0 ) ( 0 0 1 ) ( 0 2 ) ( 0 2 ) ( 0 1 0 ) ( 0 1 0 ) ( 1 0 ) luDecomp' ( 2 1 ) = ( ( 0 0 ) , ( 1/2 -1/4 1 ) , ( 1 0 0 ) , ( 0 1 ) , -1 , 1 )F+ is returned if no LU decomposition exists.2Unsafe version of 1-. It fails when the input matrix is singular.3cSimple Cholesky decomposition of a symmetric, positive definite matrix. The result for a matrix M is a lower triangular matrix L such that:M = LL^T.Example:  ( 2 -1 0 ) ( 1.41 0 0 ) ( -1 2 -1 ) ( -0.70 1.22 0 ) cholDecomp ( 0 -1 2 ) = ( 0.00 -0.81 1.15 )4.Sum of the elements in the diagonal. See also  . Example: 4 ( 1 2 3 ) ( 4 5 6 ) trace ( 7 8 9 ) = 1552Product of the elements in the diagonal. See also  . Example: = ( 1 2 3 ) ( 4 5 6 ) diagProd ( 7 8 9 ) = 456FMatrix determinant using Laplace expansion. If the elements of the  are instance of G and H consider to use 74 in order to obtain better performance. Function 6 is  extremely slow.7^Matrix determinant using LU decomposition. It works even when the input matrix is singular.UIJK89LM:9Function takes the current column as additional argument. Row to map.6Function takes the current row as additional argument.Column to map.RowsColumnsRowsColumnsGenerator function RowsColumnsList of elements Size of the matrix.Permuted row 1.Permuted row 2.Permutation matrix.RowColumnMatrixRowColumnMatrix?N New elementNumber of columns of the matrix Row offset Column offsetPosition to set the new elementMutable vectorO New elementNumber of columns of the matrix Row offset Column offsetPosition to set the new elementMutable vector New value.Position to replace.Original matrix.=Matrix with the given position replaced with the given value. New value.Position to replace.Original matrix.=Matrix with the given position replaced with the given value.Element to add when extending.Minimal number of rows.Minimal number of columns.Default element.Number of rows.Number of columns. Starting row Ending rowStarting column Ending columnRow r to remove.Column c to remove.Original matrix.Matrix with row r and column c removed. Row of the splitting element. Column of the splitting element.Matrix to split. (TL,TR,BL,BR)!"#$%AB&'CPQRD(SE)*+,-Row 1.Row 2.Original matrix."Matrix with rows 1 and 2 switched..Col 1.Col 2.Original matrix."Matrix with cols 1 and 2 switched./TULPd Current row Total rows012UULPQde Current row Total rows34567VWXYZ[\8  !"#$%&'()*+,-./01234567:   "#!$%&'()*+,-./01234567NIJK89LM: ?NO !"#$%AB&'CPQRD(SE)*+,-./T012U34567VWXYZ[\AB]      !"#$%&'()*+,-./0123456789:;<=>?=@ABCD=EFGBCHIJKLM=NOPQR=STUVWXYZ[\]^_`abcdefghimatrix-0.3.4.3 Data.MatrixMatrixnrowsncols prettyMatrix forceMatrixmapRowmapColzeromatrixidentityfromListtoListtoLists fromLists rowVector colVector permMatrixgetElem unsafeGet!safeGetgetRowgetColgetDiaggetMatrixAsVectorsetElem unsafeSet transposeextendTosetSize submatrix minorMatrix splitBlocks joinBlocks<|><-> elementwiseelementwiseUnsafemultStdmultStd2 multStrassenmultStrassenMixed scaleMatrixscaleRow combineRows switchRows switchColsluDecompluDecompUnsafe luDecomp'luDecompUnsafe' cholDecomptracediagProd detLaplacedetLUvcolsmvectsizeStrbaseGHC.BaseStringGHC.ShowShowvector-0.10.12.3 Data.VectorforceGHC.Errerror!.Vector+.-.multStd_strassen strassenMixed Data.MaybeNothingghc-prim GHC.ClassesOrdGHC.Real FractionalM rowOffset colOffsetencodedecodemsetElem unsafeMset multStd__ dotProductfirst strmixFactor recLUDecomp recLUDecomp' $fNumMatrix$fTraversableMatrix$fFoldableMatrix$fFunctorMatrix$fNFDataMatrix $fShowMatrix $fEqMatrix