Enabled validation checking of MxMatrices
[openmx:openmx.git] / R / IdenMatrix.R
1 setClass(Class = "IdenMatrix",
2         representation = representation(),
3         contains = "MxNonSymmetricMatrix")
4         
5 setMethod("initialize", "IdenMatrix",
6         function(.Object, name, values, specification, nrow, ncol, byrow, free) {
7                 if (!single.na(values)) {
8                         warning("Ignoring values matrix for IdenMatrix construction")
9                 }
10                 if (!single.na(specification)) {
11                         warning("Ignoring specification matrix for IdenMatrix construction")
12                 }
13                 if (free) {
14                         warning("Ignoring \'free\' parameter for IdenMatrix construction")
15                 }               
16                 if (nrow != ncol) {
17                         stop("Non-square matrix attempted for IdenMatrix constructor")
18                 }
19                 specification <- new("MxSparseMatrix", 0, nrow, ncol)
20                 values <- Matrix(diag(nrow))
21                 return(callNextMethod(.Object, specification, values, name))
22         }
23 )
24
25 setMethod("omxVerifyMatrix", "IdenMatrix",
26         function(.Object) {
27                 callNextMethod(.Object)
28                 verifySquare(.Object)
29                 if(nnzero(.Object@specification) > 0) { stop("Specification matrix is not empty") } 
30                 if(!suppressWarnings(all(.Object@values == diag(nrow(.Object@values))))) 
31                         { stop("Values matrix is not the identity matrix") }
32         }
33 )