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:

as for the mpfr class, a "list" of mpfr1 numbers.

Dim:

of class "integer", specifying the array dimension.

Dimnames:

of class "list" and the same length as Dim, each list component either NULL or a character vector of length Dim[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., transforms x into a simple mpfr vector. This is an inverse of t(.) or dim(.) <- * 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 R arrays.

%*%

signature(x = "mpfr", y = "mpfrMatrix"): Compute the matrix/vector product x y when the dimensions (dim) of x and y match. If x is 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 one mpfr and 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"): Computes x'x, i.e., t(x) %*% x, typically more efficiently.

crossprod

signature(x = "mpfr", y = "mpfrMatrix"): Computes x'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"): Computes xx', i.e., x %*% t(x), typically more efficiently.

tcrossprod

signature(x = "mpfrMatrix", y = "mpfrMatrix"): Computes xy', 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"): coerces from to a numeric array of the same dimension.

coerce

signature(from = "mpfrArray", to = "vector"): as for standard arrays, this “drops” the dim (and dimnames), i.e., returns an mpfr vector.

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 of x, see norm or the one in package Matrix.

t

signature(x = "mpfrMatrix"): tranpose the mpfrMatrix.

aperm

signature(a = "mpfrArray"): aperm(a, perm) is a generalization of t(.) to permute the dimensions of an mpfrArray; it has the same semantics as the standard aperm() method for simple R arrays.

Author(s)

Martin Maechler

See Also

mpfrArray, also for more examples.

Examples

 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.