| mpfrMatrix {Rmpfr} | R Documentation |
Classes "mpfrMatrix" and "mpfrArray"
Description
The classes "mpfrMatrix" and "mpfrArray" are,
analogously to the base matrix and array
functions and classes simply “numbers” of class
mpfr with an additional Dim and
Dimnames slot.
Objects from the Class
Objects should typically be created by mpfrArray(), but
can also be created by
new("mpfrMatrix", ...) or new("mpfrArray", ...), or also
by t(x), dim(x) <- dd, or mpfr2array(x,
dim=dd) where x is a an mpfr
“number vector”.
A (slightly more flexible) alternative to dim(x) <- dd is
mpfr2array(x, dd, dimnames).
Slots
.Data:Dim:of class
"integer", specifying the array dimension.Dimnames:of class
"list"and the same length asDim, each list component eitherNULLor acharactervector of lengthDim[j].
Extends
Class "mpfrMatrix" extends "mpfrArray", directly.
Class "mpfrArray" extends
class "mpfr", by class "mpfrArray", distance 2;
class "list", by class "mpfrArray", distance 3;
class "vector", by class "mpfrArray", distance 4.
Methods
- Arith
signature(e1 = "mpfr", e2 = "mpfrArray"): ...- Arith
signature(e1 = "numeric", e2 = "mpfrArray"): ...- Arith
signature(e1 = "mpfrArray", e2 = "mpfrArray"): ...- Arith
signature(e1 = "mpfrArray", e2 = "mpfr"): ...- Arith
signature(e1 = "mpfrArray", e2 = "numeric"): ...- as.vector
signature(x = "mpfrArray", mode = "missing"): drops the dimension ‘attribute’, i.e., transformsxinto a simplempfrvector. This is an inverse oft(.)ordim(.) <- *on such a vector.- atan2
signature(y = "ANY", x = "mpfrArray"): ...- atan2
signature(y = "mpfrArray", x = "mpfrArray"): ...- atan2
signature(y = "mpfrArray", x = "ANY"): ...- [<-
signature(x = "mpfrArray", i = "ANY", j = "ANY", value = "ANY"): ...- [
signature(x = "mpfrArray", i = "ANY", j = "ANY", drop = "ANY"): ...- [
signature(x = "mpfrArray", i = "ANY", j = "missing", drop = "missing"):"mpfrArray"s can be subset (“indexed”) as regular Rarrays.- %*%
signature(x = "mpfr", y = "mpfrMatrix"): Compute the matrix/vector productx ywhen the dimensions (dim) ofxandymatch. Ifxis not a matrix, it is treated as a 1-row or 1-column matrix (aka “row vector” or “column vector”) depending on which one makes sense, see the documentation of the base function%*%.- %*%
signature(x = "mpfr", y = "Mnumber"): method definition for cases with onempfrand any “number-like” argument are to use MPFR arithmetic as well.- %*%
signature(x = "mpfrMatrix", y = "mpfrMatrix"),- %*%
signature(x = "mpfrMatrix", y = "mpfr"), etc. Further method definitions with identical semantic.- crossprod
signature(x = "mpfr", y = "missing"): Computesx'x, i.e.,t(x) %*% x, typically more efficiently.- crossprod
signature(x = "mpfr", y = "mpfrMatrix"): Computesx'y, i.e.,t(x) %*% y, typically more efficiently.- crossprod
signature(x = "mpfrMatrix", y = "mpfrMatrix"): ...- crossprod
signature(x = "mpfrMatrix", y = "mpfr"): ...- tcrossprod
signature(x = "mpfr", y = "missing"): Computesxx', i.e.,x %*% t(x), typically more efficiently.- tcrossprod
signature(x = "mpfrMatrix", y = "mpfrMatrix"): Computesxy', i.e.,x %*% t(y), typically more efficiently.- tcrossprod
signature(x = "mpfrMatrix", y = "mpfr"): ...- tcrossprod
signature(x = "mpfr", y = "mpfrMatrix"): ...- coerce
signature(from = "mpfrArray", to = "array"): coercesfromto a numeric array of the same dimension.- coerce
signature(from = "mpfrArray", to = "vector"): as for standardarrays, this “drops” thedim(anddimnames), i.e., returns anmpfrvector.- Compare
signature(e1 = "mpfr", e2 = "mpfrArray"): ...- Compare
signature(e1 = "numeric", e2 = "mpfrArray"): ...- Compare
signature(e1 = "mpfrArray", e2 = "mpfr"): ...- Compare
signature(e1 = "mpfrArray", e2 = "numeric"): ...- dim
signature(x = "mpfrArray"): ...- dimnames<-
signature(x = "mpfrArray"): ...- dimnames
signature(x = "mpfrArray"): ...- show
signature(object = "mpfrArray"): ...- sign
signature(x = "mpfrArray"): ...- norm
signature(x = "mpfrMatrix", type = "character"): computes the matrix norm ofx, seenormor the one in package Matrix.- t
signature(x = "mpfrMatrix"): tranpose the mpfrMatrix.- aperm
signature(a = "mpfrArray"):aperm(a, perm)is a generalization oft(.)to permute the dimensions of an mpfrArray; it has the same semantics as the standardaperm()method for simple Rarrays.
Author(s)
Martin Maechler
See Also
mpfrArray, also for more examples.
Examples
showClass("mpfrMatrix")
validObject(mm <- new("mpfrMatrix"))
validObject(aa <- new("mpfrArray"))
v6 <- mpfr(1:6, 128)
m6 <- new("mpfrMatrix", v6, Dim = c(2L, 3L))
validObject(m6)
m6
which(m6 == 3, arr.ind = TRUE) # |--> (1, 2)
## Coercion back to "vector": Both of these work:
stopifnot(identical(as(m6, "mpfr"), v6),
identical(as.vector(m6), v6)) # < but this is a "coincidence"
S2 <- m6[,-3] # 2 x 2
S3 <- rbind(m6, c(1:2,10)) ; s3 <- asNumeric(S3)
det(S2)
str(determinant(S2))
det(S3)
stopifnot(all.equal(det(S2), det(asNumeric(S2)), tol=1e-15),
all.equal(det(S3), det(s3), tol=1e-15))
## 2-column matrix indexing and replacement:
(sS <- S3[i2 <- cbind(1:2, 2:3)])
stopifnot(identical(asNumeric(sS), s3[i2]))
C3 <- S3; c3 <- s3
C3[i2] <- 10:11
c3[i2] <- 10:11
stopifnot(identical(asNumeric(C3), c3))
AA <- new("mpfrArray", as.vector(cbind(S3, -S3)), Dim=c(3L,3:2))
stopifnot(identical(AA[,,1] , S3), identical(AA[,,2] , -S3))
aa <- asNumeric(AA)
i3 <- cbind(3:1, 1:3, c(2L, 1:2))
ii3 <- Rmpfr:::.mat2ind(i3, dim(AA), dimnames(AA))
stopifnot(aa[i3] == new("mpfr", getD(AA)[ii3]))
stopifnot(identical(aa[i3], asNumeric(AA[i3])))
CA <- AA; ca <- aa
ca[i3] <- ca[i3] ^ 3
CA[i3] <- CA[i3] ^ 3
## scale():
S2. <- scale(S2)
stopifnot(all.equal(abs(as.vector(S2.)), rep(sqrt(1/mpfr(2, 128)), 4),
tol = 1e-30))
## norm() :
norm(S2)
stopifnot(identical(norm(S2), norm(S2, "1")),
norm(S2, "I") == 6,
norm(S2, "M") == 4,
abs(norm(S2, "F") - 5.477225575051661) < 1e-15)