Printing (non-zero elements) of sparse matrices and summarizing the sparsity structure thereof.

# S4 method for spam
print(x, ...)
# S4 method for spam
summary(object, ...)

Arguments

x

matrix of class spam or spam.chol.method.

object

matrix of class spam or spam.chol.method.

...

any other arguments passed to print.default. If the non-standard argument minimal is set to FALSE, an extended spam print is available with logical argument rowpointer to print rowpointers, and zerosymbol defining the character to display the zero element.

Value

NULL for print, because the information is printed with cat there is no real need to pass any object back.
A list containing the non-zero elements and the density for summary for class spam.
A list containing the non-zero elements of the factor, the density and the fill-in for summary for class spam.chol.NgPeyton.

Details

getOption('spam.printsize') determines if the sparse matrix is coerced into a matrix and the printed as an array or if only the non-zero elements of the matrix are given.

See also

display or image for a graphical visualization; spam.options

Author

Reinhard Furrer

Examples

set.seed(13) smat <- spam_random(8) par(mfcol=c(1,2),pty='s') options(spam.printsize=1000) print(smat)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] #> [1,] 0 0 0 1 1 1 1 1 #> [2,] 1 1 1 0 0 0 0 0 #> [3,] 0 0 0 1 1 0 1 1 #> [4,] 1 0 0 0 0 1 0 0 #> [5,] 1 0 1 1 1 1 0 1 #> [6,] 0 0 0 1 0 0 0 0 #> [7,] 0 0 0 0 1 1 1 1 #> [8,] 0 1 1 0 1 0 1 1 #> Class 'spam' (32-bit)
options(spam.printsize=10) print(smat)
#> [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 #> Class 'spam' (32-bit)
summary(smat)
#> Matrix object of class 'spam' of dimension 8x8, #> with 30 (row-wise) nonzero elements. #> Density of the matrix is 46.9%. #> Class 'spam' (32-bit)
summary(smat)$nnz
#> [1] 30
smat@entries[1:5] <- 0 print(smat, minimal = FALSE)
#> Matrix of dimension 8x8 with (row-wise) nonzero elements: #> 1 2 3 4 5 6 7 8 #> ---------------- #> 1| ' ' ' 0 0 0 0 0 #> 2| 1 1 1 ' ' ' ' ' #> 3| ' ' ' 1 1 ' 1 1 #> 4| 1 ' ' ' ' 1 ' ' #> 5| 1 ' 1 1 1 1 ' 1 #> 6| ' ' ' 1 ' ' ' ' #> 7| ' ' ' ' 1 1 1 1 #> 8| ' 1 1 ' 1 ' 1 1 #> class: spam (32-bit) #> Class 'spam' (32-bit)
print(smat, minimal = FALSE, rowpointer = TRUE)
#> Matrix of dimension 8x8 with (row-wise) nonzero elements, #> number left of the vertical bars denote the respective rowpointer: #> 1 2 3 4 5 6 7 8 #> ---------------- #> 1| ' ' ' 0 0 0 0 0 #> 6| 1 1 1 ' ' ' ' ' #> 9| ' ' ' 1 1 ' 1 1 #> 13| 1 ' ' ' ' 1 ' ' #> 15| 1 ' 1 1 1 1 ' 1 #> 21| ' ' ' 1 ' ' ' ' #> 22| ' ' ' ' 1 1 1 1 #> 26| ' 1 1 ' 1 ' 1 1 #> class: spam (32-bit) #> Class 'spam' (32-bit)
smat@rowpointers
#> [1] 1 6 9 13 15 21 22 26 31
print_nnzpos(smat)
#> Matrix of dimension 8x8 with (row-wise) nonzero elements: #> 1 2 3 4 5 6 7 8 #> ------------------------ #> 1| ' ' ' 1 2 3 4 5 #> 2| 6 7 8 ' ' ' ' ' #> 3| ' ' ' 9 10 ' 11 12 #> 4| 13 ' ' ' ' 14 ' ' #> 5| 15 ' 16 17 18 19 ' 20 #> 6| ' ' ' 21 ' ' ' ' #> 7| ' ' ' ' 22 23 24 25 #> 8| ' 26 27 ' 28 ' 29 30 #> class: spam (32-bit) #> Class 'spam' (32-bit)