SCM

SCM Repository

[matrix] Annotation of /pkg/R/pMatrix.R
ViewVC logotype

Annotation of /pkg/R/pMatrix.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 650 - (view) (download)

1 : bates 638 #### Permutation Matrices -- Coercion and Methods
2 :    
3 :     setAs("integer", "pMatrix",
4 :     function(from) {
5 :     n <- length(from)
6 :     new("pMatrix", Dim = rep.int(n, 2), perm = from)
7 :     })
8 :    
9 :     setAs("pMatrix", "matrix",
10 :     function(from) {
11 :     fp <- from@perm
12 : bates 650 diag(nrow = length(fp))[fp , ]
13 : bates 638 })
14 :    
15 :     setMethod("solve", signature(a = "pMatrix", b = "missing"),
16 :     function(a, b) {
17 :     bp <- ap <- a@perm
18 :     bp[ap] <- seq(along = ap)
19 :     new("pMatrix", Dim = a@Dim, perm = bp)
20 :     }, valueClass = "pMatrix")
21 :    
22 :     setMethod("%*%", signature(x = "matrix", y = "pMatrix"),
23 : bates 650 function(x, y) x[ , y@perm], valueClass = "matrix")
24 : bates 638
25 :     setMethod("%*%", signature(x = "pMatrix", y = "matrix"),
26 : bates 650 function(x, y) y[x@perm ,], valueClass = "matrix")
27 : bates 638
28 :     setMethod("t", signature(x = "pMatrix"), function(x) solve(x))

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge