Special case of diagonal matrices not fully handled by internal matrix conversions
Issue #3
new
# A dense and sparse diagonal matrix
D1 <- diag(1.0, nrow = 1)
D2 <- Matrix::Diagonal(n = 1, x = 1.0)
# Both results should be 0.5:
excursions::gaussint(mu = 0, Q.chol = D1, a = 0, b = Inf)$P
#> [1] 0.5
excursions::gaussint(mu = 0, Q.chol = D2, a = 0, b = Inf)$P
#> [1] 0
# The underlying conversion:
excursions:::private.as.dtCMatrix(D1)
#> 1 x 1 sparse Matrix of class "dtCMatrix"
#>
#> [1,] 1
excursions:::private.as.dtCMatrix(D2)
#> 1 x 1 sparse Matrix of class "dtCMatrix" (unitriangular)
#>
#> [1,] 1
# The diagonal is handled in a special way:
str(excursions:::private.as.dtCMatrix(D1))
#> Formal class 'dtCMatrix' [package "Matrix"] with 7 slots
#> ..@ i : int 0
#> ..@ p : int [1:2] 0 1
#> ..@ Dim : int [1:2] 1 1
#> ..@ Dimnames:List of 2
#> .. ..$ : NULL
#> .. ..$ : NULL
#> ..@ x : num 1
#> ..@ uplo : chr "U"
#> ..@ diag : chr "N"
str(excursions:::private.as.dtCMatrix(D2))
#> Formal class 'dtCMatrix' [package "Matrix"] with 7 slots
#> ..@ i : int(0)
#> ..@ p : int [1:2] 0 0
#> ..@ Dim : int [1:2] 1 1
#> ..@ Dimnames:List of 2
#> .. ..$ : NULL
#> .. ..$ : NULL
#> ..@ x : num(0)
#> ..@ uplo : chr "U"
#> ..@ diag : chr "U"
# gaussint uses dtCMatrixU conversion to ensure an upper triagnular matrix
# This has the same issue:
str(excursions:::private.as.dtCMatrixU(D1))
#> Formal class 'dtCMatrix' [package "Matrix"] with 7 slots
#> ..@ i : int 0
#> ..@ p : int [1:2] 0 1
#> ..@ Dim : int [1:2] 1 1
#> ..@ Dimnames:List of 2
#> .. ..$ : NULL
#> .. ..$ : NULL
#> ..@ x : num 1
#> ..@ uplo : chr "U"
#> ..@ diag : chr "N"
str(excursions:::private.as.dtCMatrixU(D2))
#> Formal class 'dtCMatrix' [package "Matrix"] with 7 slots
#> ..@ i : int(0)
#> ..@ p : int [1:2] 0 0
#> ..@ Dim : int [1:2] 1 1
#> ..@ Dimnames:List of 2
#> .. ..$ : NULL
#> .. ..$ : NULL
#> ..@ x : num(0)
#> ..@ uplo : chr "U"
#> ..@ diag : chr "U"
<sup>Created on 2020-04-08 by the reprex package (v0.3.0)</sup>