compute compressed sparse row and column forms
sparse Matrix with hardware data type
optional equations controlling the details of the computation
form = row or form = column
This option determines whether the compressed sparse column form or the compressed sparse row form is returned. The default is compressed sparse column form.
output = CB or R or X or a list of these values
If output is set to CB, then only CB is returned. Similarly for R and X. If a list of these values is selected, then Maple returns the corresponding values in that order, as an expression sequence. The default value is [CB, R, X]: return the sequence of all three Vectors.
cbbase = posint
rbase = posint
These options determines at what number Maple starts numbering the rows and columns. The default is 1, corresponding to the standard Maple convention. Other values, in particular 0, are mainly useful if the result is passed to external code.
The setting of cbbase changes the values in CB: it changes the start of indexing into R and X. The setting of rbase changes the values in R: it changes the start of indexing into A.
length0 = true or length0 = false
Maple has no problems working with Vectors of length 0, but some external tools do. If length0 is set to false, and A has no nonzero entries, then Maple returns values pretending that the [1, 1] entry is stored and has value 0. This and the includediagonal and structuralsymmetry options below are the only cases in which X contains a zero value.
includediagonal = true or includediagonal = false
If the includediagonal option is set to true, then Maple includes all diagonal entries in the result, even if their value is zero. If it is set to false (the default), then Maple omits all zero entries, including if they occur on the diagonal. The former is useful when preparing input for some external tools.
structuralsymmetry = true or structuralsymmetry = false
If the structuralsymmetry option is set to true, then Maple ensures that, whenever a value Ai,j is included in the result, then Aj,i is also included, even if it is zero. If it is set to false (the default), then Maple does not do this. The former is useful when preparing input for some external tools.
The structuralsymmetry option can only be used if A is a square Matrix.
The CompressedSparseForm function computes either the compressed sparse row form or the compressed sparse column form of the input Matrix A, which needs to have one of the hardware data types. It thus performs the opposite function to FromCompressedSparseForm.
The compressed sparse column form of an n by m Matrix A with k nonzero entries consists of three Vectors, CB, R, and X. These are obtained by sorting the k nonzero entries of A first by column, and then within each column sorting the entries by row. Now X is the k-element Vector of these nonzero values in A in this order, and R is the k-element Vector of row indices at which these values occur. CB is an n+1-element Vector; CBi is the index in both X and R where the ith column starts. We always have CB1=1 and CBn+1=k+1, so that the entries in column i have indices CBi up to, but not including, CBi+1. (If the cbbase option below is used, then CB1=cbbase and CBn+1=k+cbbase and a similar statement holds.)
The compressed sparse row form is very similar, but with the roles of rows and columns interchanged. Specifically, we first sort A by row and then within each row by column; X is still the nonzero values occurring in A. However, R is the k-element Vector of column indices. Similarly, CBi is the index in X and R where the ith row starts.
The compressed sparse forms are most useful for sparse Matrices. If A does not have sparse storage (as determined by rtable_option⁡X,storage being either sparse or sparseupper or sparselower), then a sparse storage copy is made before determining the compressed sparse form.
If A has any indexing functions (as determined by rtable_indfns⁡A), then these are bypassed when determining the compressed sparse row or column form: since CompressedSparseForm is a low-level command, Maple returns the compressed sparse form of the stored entries only. For example, if a Matrix is defined with option shape=symmetric and storage=sparseupper, then only one of each pair of off-diagonal entries will be represented in the compressed sparse form. However, if A has indexing functions but no sparse storage, then the copy made to give it sparse storage, as explained above, typically gets rid of the indexing function and stores all nonzero entries.
The code for CompressedSparseForm relies on A being a NAG-sparse Matrix (potentially after copying it to give it sparse storage); that is, its datatype as returned by rtable_options needs to be one of these values:
Let us examine the compressed sparse row and column form of an arbitrary matrix.
m ≔ Matrix⁡6,6,1,2=−81,2,3=−55,2,4=−15,3,1=−46,3,3=−17,3,4=99,3,5=−61,4,2=18,4,5=−78,5,6=22,datatype=integer4
Setting cbbase=0 causes the entries of CB to be reduced by 1.
Setting rbase=0 causes the entries of R to be reduced by 1.
Using the includediagonal option ensures that all 6 diagonal entries are included, even though most of them are 0.
m2 ≔ Matrix⁡0,1,0,2,0,0,3,0,4,5,6,7,'datatype=float'
cb,r,x ≔ CompressedSparseForm⁡m2
We can obtain the entries of r corresponding to the second column as follows.
column ≔ 2
Similarly for the entries of x.
We will omit the last row of m2 and illustrate the includediagonal and structuralsymmetry options. First, this is what the result looks like without these options.
m3 ≔ m21..3
Adding the structuralsymmetry option makes Maple include the entry for m31,3, even though it is 0, because m33,1 is nonzero.
Adding the includediagonal option makes Maple include the entries for m31,1 and m32,2, even though they are 0.
Adding both of these options makes Maple include the entries for m31,1, m32,2, and m31,3.
CompressedSparseForm does not work with Matrices that are not of a hardware data type.
m4 ≔ Matrix⁡3,3,i,j→i−j
Error, (in LinearAlgebra:-CompressedSparseForm) cannot compute compressed sparse form of a Matrix with non-hardware datatype anything
To make this work, we need to recreate m4 with, for example, option datatype=integer4.
m4 ≔ Matrix⁡m4,datatype=integer4
cb,r,x ≔ CompressedSparseForm⁡m4
Here is an example of the antisymmetric indexing function being ignored.
m5 ≔ Matrix⁡6,datatype=integer4,shape=antisymmetric,storage=sparselower,i,j→`if`⁡irem⁡i+j,2=1,i−j,0
The LinearAlgebra[CompressedSparseForm] command was introduced in Maple 17.
For more information on Maple 17 changes, see Updates in Maple 17.
The LinearAlgebra[CompressedSparseForm] command was updated in Maple 2022.
The length0, includediagonal and structuralsymmetry options were introduced in Maple 2022.
For more information on Maple 2022 changes, see Updates in Maple 2022.
Download Help Document