-
Notifications
You must be signed in to change notification settings - Fork 0
/
instantiate.R
33 lines (31 loc) · 874 Bytes
/
instantiate.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#' Instantiate a matrix
#'
#' This is a generic to represent direct instantiation of an implicitly defined
#' matrix. In general this is a bad idea, because it removes the whole purpose
#' of using an implicit representation.
#'
#' @param x Implicit matrix to directly instantiate.
#' @returns The directly instantiated matrix.
#' @seealso \link{WoodburyMatrix}, \linkS4class{WoodburyMatrix}
#' @export
setGeneric('instantiate', function(x) {
standardGeneric('instantiate')
})
#' @describeIn instantiate Method for general matrices.
#' @export
setMethod(
'instantiate',
c(x = 'GWoodburyMatrix'),
function(x) {
solve(x@A) + x@U %*% solve(x@B, x@V)
}
)
#' @describeIn instantiate Method for symmetric matrices.
#' @export
setMethod(
'instantiate',
c(x = 'SWoodburyMatrix'),
function(x) {
forceSymmetric(solve(x@A) + x@X %*% solve(x@B, t(x@X)))
}
)