Learn R Programming

flint (version 0.1.0)

flint-class: Class of FLINT-Type Vectors

Description

Class flint is a virtual class representing vectors of any FLINT C type. The C type is determined by the class attribute and interfaced exactly using R's external pointer type.

Usage

## Class generator functions

flint(class, ...)

flint.array(class, ...)

Value

An object of class class generated by the corresponding class generator function. For example,

flint("ulong", ...) returns

ulong(...) and

flint.array("slong", ...) returns

slong.array(...).

Arguments

class

a character string giving the name of a nonvirtual subclass of flint, one of "ulong", "slong", "fmpz", "fmpq", "mag", "arf", "acf", "arb", and "acb".

...

arguments passed to the class generator function corresponding to class.

Slots

.xData

an external pointer. The protected field is an integer vector of length 1 or 2 storing the object length whose size is 32 or 64 bits depending on the ABI; see flintABI. The pointer field contains the address of a block of allocated memory of size greater than or equal to the object length times the size of the FLINT C type. It is a null pointer if and only if the object length is zero.

Methods for initialize set a finalizer on .xData (see reg.finalizer) to ensure that allocated memory is freed before .xData is itself freed by the garbage collector.

dim

either NULL, indicating that the object is not an array, or an integer vector of length d greater than 0 and with product equal to the object length, indicating that the object is a d-dimensional array with dimensions dim. Array entries are stored in colexicographic order, meaning that the first subscript moves fastest.

dimnames

either NULL, indicating that the object is not an array or is an array whose dimensions are not named, or a list of length d equal to length(dim) such that dimnames[[i]] is either NULL or a character vector of length dim[[i]], for all i in 1L:d.

names

either NULL, indicating that the object is not named, or a character vector of length equal to the object length. A corollary is that objects whose length exceeds the maximum length of a character vector cannot have names.

Methods

$, $<-

signature(x = "flint"):
signals an error as x is “atomic-like” and in any case not recursive or NULL.

[

signature(x = "flint", i = "ANY", j = "ANY"):
signature(x = "ANY", i = "flint", j = "ANY"):
signature(x = "ANY", i = "ANY", j = "flint"):
returns a traditional vector or flint vector containing the elements of x indexed by (i, j, ...) (the “subscript”). The components of the subscript can be missing, NULL, logical, integer, double, character, ulong, slong, fmpz, or fmpq. Methods for signatures with x = "flint" signal an error for NA and out of bounds subscripts, as the C types interfaced by flint vectors have no representation for missing values. Note that [ does not perform S4 dispatch if its first positional argument is not an S4 object. If it is known that i is a flint vector and not known whether x is a flint vector, then one option is to call [ as `[`(i = i, x = x) rather than as x[i]. However, it is not guaranteed that such usage of [, which is mostly undocumented, continues to work in future versions of R.

[<-

signature(x = "flint", i = "ANY", j = "ANY", value = "ANY"):
signature(x = "ANY", i = "flint", j = "ANY", value = "ANY"):
signature(x = "ANY", i = "ANY", j = "flint", value = "ANY"):
signature(x = "ANY", i = "ANY", j = "ANY", value = "flint"):
returns the traditional vector or flint vector obtained by replacing the elements of x indexed by (i, j, ...) (the “subscript”) with elements of value, which are recycled as necessary. The components of the subscript can be missing, NULL, logical, integer, double, character, ulong, slong, fmpz, or fmpq. The class of the return value is determined following strict rules from the classes of x and value, which are promoted to the value class as necessary. If the value class is a subclass of flint, then an error is signaled for NA and out of bounds subscripts, as the C types interfaced by flint vectors have no representation for missing values. Note that [<- does not perform S4 dispatch if its first positional argument is not an S4 object. If it is known that i is a flint vector and not known whether x is a flint vector, then one option is to call [<- as `[`(i = i, x = x) <- value rather than as x[i] <- value. However, it is not guaranteed that such usage of [<-, which is mostly undocumented, continues to work in future versions of R.

[[

signature(x = "flint", i = "ANY", j = "ANY"):
signature(x = "ANY", i = "flint", j = "ANY"):
signature(x = "ANY", i = "ANY", j = "flint"):
similar to [, with differences as documented in Extract, particularly for recursive x.

[[<-

signature(x = "flint", i = "ANY", j = "ANY", value = "ANY"):
signature(x = "ANY", i = "flint", j = "ANY", value = "ANY"):
signature(x = "ANY", i = "ANY", j = "flint", value = "ANY"):
signature(x = "ANY", i = "ANY", j = "ANY", value = "flint"):
similar to [<-, with differences as documented in Extract, particularly for recursive x.

all.equal

signature(x = "flint", y = "flint"):
signature(x = "flint", y = "ANY"):
signature(x = "ANY", y = "flint"):
returns either TRUE, indicating that there is no meaningful difference between x and y, or a character vector describing differences. The implementation (including optional arguments) is adapted from all.equal.numeric, hence see its documentation. Notably, comparison of objects inheriting from different subclasses of virtual class flint and comparison with objects (typically atomic vectors) coercible to virtual class flint are supported with check.class = FALSE. See the method for identical for much stricter comparison of flint objects.

anyDuplicated

signature(x = "flint"):
returns anyDuplicated(mtfrm(x), ...).

as.raw, as.logical, as.integer, as.numeric, as.complex

signature(x = "flint"):
returns the value of as.vector(x, mode = *). Methods for as.vector must be defined for subclasses of flint. Note that as.double dispatches internally the method for as.numeric, so there is no method for as.double; see also as.numeric, section ‘S4 Methods’.

as.matrix, as.array, as.Date, as.POSIXct, as.POSIXlt

signature(x = "flint"):
coerces the argument with as.vector, restores dimensions, dimension names, and names, and dispatches. as.matrix and as.array obtain the same result more efficiently.

as.data.frame

signature(x = "flint"):
behaves as as.data.frame.vector, as.data.frame.matrix, or as.data.frame.array, depending on the length of the dim slot. It enables the construction of data frames containing flint vectors using as.data.frame and functions that call it such as data.frame and cbind.data.frame.

c

signature(x = "flint"):
returns c.flint(x, ...), the concatenation of the arguments. Function c.flint is exported to work around the fact that c(x, ...) dispatches only on x.

cbind2

signature(x = "flint", y = "flint"):
signature(x = "flint", y = "ANY"):
signature(x = "ANY", y = "flint"):
returns cbind.flint(x, y, ...), the horizontal concatenation of x and y. These methods are dispatched by cbind in case of S3 dispatch ambiguities; see cbind2.

coerce

signature(from = "ANY", to = "flint"):
coerces atomic (except character) vectors from to the most specific subclass of flint whose range contains the range of typeof(from).

cut

signature(x = "flint"):
returns findInterval(x=x, vec=breaks, left.open=right, rightmost.closed=include.lowest), hence see below. The behaviour is consistent with the default method for cut with argument labels set to FALSE, provided that breaks is sorted and no element of x is out of bounds.

diag

signature(x = "flint"):
if x is a matrix, then returns a flint vector containing the diagonal entries of x; otherwise, returns a diagonal matrix with diagonal entries taken from x. Optional arguments nrow, ncol, and names are handled as by the base function, hence see diag.

diag<-

signature(x = "flint", value = "ANY"):
returns x, which must be a matrix, after setting its main diagonal to value, whose length must be equal to 1 or the length of x. Arguments x and value are coerced to a common class following the rules used for general subassignment; see the methods for [<- and [[<-.

dim

signature(x = "flint"):
returns the dim slot of x.

dim<-

signature(x = "flint", value = "NULL"):
returns x with dim and dimnames slots set to NULL.

dim<-

signature(x = "flint", value = "numeric"):
returns x with dim slot set to value and dimnames slot set to NULL. value of double type is coerced to integer.

dimnames

signature(x = "flint"):
returns the dimnames slot of x.

dimnames<-

signature(x = "flint", value = "NULL"):
returns x with dimnames slot set to NULL.

dimnames<-

signature(x = "flint", value = "list"):
returns x with dimnames slot set to value. Elements of value of a vector type are coerced to character using as.character.default. Exceptionally, factors are coerced to character using as.character.factor.

drop

signature(x = "flint"):
returns x with dim, dimnames, and names slots modified following the documented behaviour of the base function, hence see drop.

duplicated

signature(x = "flint"):
returns duplicated(mtfrm(x), ...).

findInterval

returns a ulong vector of length equal to the length of x, following the documented behaviour of the base function, hence see findInterval. A caveat is that an error is signaled if x contains NaN, because ulong has no representation for R's missing value NA_integer_.

identical

signature(x = "flint", y = "flint"):
returns a logical indicating if x and y are “exactly equal”. Compared to the default method (which is the base function, hence see identical), this method handles the .xData slots of x and y specially: by default (if extptr.as.ref is FALSE), it does not test for equality of the stored pointers but rather for entrywise equality of the pointed to arrays. Hence by default the .xData slots are compared as if they were traditional numeric or complex vectors.

is.array

signature(x = "flint"):
returns a logical indicating if x has a non-NULL dim slot.

is.matrix

signature(x = "flint"):
returns a logical indicating if x has a dim slot of length 2.

is.na<-

signature(x = "flint"):
returns the value of x after x[value] <- na, where na is an NA of integer, double, or complex type, depending on the class of x.

isSymmetric

signature(x = "flint"):
returns a logical indicating if x is a Hermitian matrix or if x is a symmetric matrix, depending on optional argument trans, following the documented behaviour of the S3 method for traditional matrices, hence see isSymmetric.

length

signature(x = "flint"):
returns flintLength(x, exact = FALSE).

length<-

signature(x = "flint"):
returns a flint vector of length given by the second argument value. The first min(length(x), value) elements are copied from x and the remaining elements are initialized to zero.

match

signature(x = "flint", table = "flint"):
signature(x = "flint", table = "ANY"):
signature(x = "ANY", table = "flint"):
returns an integer vector matching x to table after coercing to a common class then “match transforming” with mtfrm. The behaviour is parallel to that of the default method, hence see match.

mtfrm

signature(x = "flint"):
returns format(x, base = 62L, digits = 0L), a character vector representing the elements of x exactly in base 62 (chosen over smaller bases to reduce the number of characters in the output); see also format-methods.

names

signature(x = "flint"):
returns the value of the names slot.

names<-

signature(x = "flint", value = "NULL"):
returns x with names slot set to NULL.

names<-

signature(x = "flint", value = "character"):
returns x with names slot set to value. Attributes of value are stripped. NA_character_ are appended to value if its length is less than the length of x. An error is signaled if its length is greater.

norm

signature(x = "flint"):
returns the matrix norm of x as a flint vector of length 1. The class of the return value can depend on the norm type indicated by argument type; see norm.

print

signature(x = "flint"):
prints format(x) without quotes and returns x invisibly. The output has a header listing the class and length of x and the address stored by its .xData slot. If the output might be differenced by Rdiff, then one can set optional argument Rdiff to TRUE to indicate that the address should be formatted as <pointer: 0x...> rather than as 0x..., as the longer format is recognized and ignored by Rdiff. The default value NULL is equivalent to getOption("flint.Rdiff", FALSE). For greater control over output, consider doing print(format(x, ...), ...) instead of print(x, ...).

quantile

signature(x = "flint"):
returns a flint vector containing sample quantiles computed according to additional arguments probs and type; see quantile. Currently, an error is is signaled for x of length zero and x containing NaN.

rbind2

signature(x = "flint", y = "flint"):
signature(x = "flint", y = "ANY"):
signature(x = "ANY", y = "flint"):
returns rbind.flint(x, y, ...), the vertical concatenation of x and y. These methods are dispatched by rbind in case of S3 dispatch ambiguities; see rbind2.

rep

signature(x = "flint"):
repeats x (or elements of x) according to optional arguments times, length.out, and each. The behaviour is parallel to that of the internal default method, hence see rep. One difference is that rep(0-length, length.out=nonzero) signals an error, because the underlying C types have no representation for missing values.

rep.int, rep_len

signature(x = "flint"):
analogues of rep(x, times=) and rep(x, length.out=) not preserving names, faster than rep when x has names.

seq

signature(... = "flint"):
generates flint vectors whose elements are equally spaced. This method is dispatched by calls to seq or seq.int in which the first positional argument is a flint vector. Accepted usage is any of

seq(length.out=)
seq(length.out=, by=)
seq(from=, to=)
seq(from=, to=, by=)
seq(from=, to=, length.out=)
seq(from=, by=, length.out=)
seq(to=, by=, length.out=)

where length.out=n and along.with=x are equivalent for x of length n. Good users name all arguments.

sequence

signature(nvec = "flint"):
returns the concatenation of seq(from = from[i], by = by[i], length.out = nvec[i]) after recycling arguments nvec, from, and by to a common length.

show

signature(object = "flint"):
prints format(object) and returns NULL invisibly.

summary

signature(object = "flint"):
returns a flint vector containing the minimum, first quartile, median, mean, third quartile, maximum, and (if nonzero) the number of NaN, unless object is complex (inherits from acf or acb) or x has error bounds (inherits from arb or acb) or optional argument triple is TRUE, in which case the value is just flintTriple() with names.

t

signature(x = "flint"):
returns the transpose of x if x is a matrix, handling non-array x as length(x)-by-1 matrices.

unique

signature(x = "flint"):
returns x[!duplicated(x, ...)].

Methods are on purpose not defined for generic functions whose default methods correctly handle objects inheriting from virtual class flint, typically by calling other generic functions for which methods are defined. Examples are as.character, as.list, diff, rev, seq.int, sort, and split.

See Also

The nonvirtual subclasses: ulong, slong, fmpz, fmpq, mag, arf, acf, arb, and acb.

Examples

Run this code
showClass("flint")
showMethods(classes = "flint")

Run the code above in your browser using DataLab