| Title: | Manipulation of (Large) Memory-Mapped Objects (Vectors, Matrices and Arrays) |
|---|---|
| Description: | Manipulate data through memory-mapped files, as vectors, matrices or arrays. Basic arithmetic functions are implemented, but currently no matrix arithmetic. Can write and read descriptor files for compatibility with the 'bigmemory' package. |
| Authors: | Hervé Perdry [aut, cre], Juliette Meyniel [aut] |
| Maintainer: | Hervé Perdry <[email protected]> |
| License: | CeCILL-2 |
| Version: | 0.1.1 |
| Built: | 2026-05-21 08:47:06 UTC |
| Source: | https://github.com/cran/houba |
This method generalizes 'base::apply' to mmatrix objects
## S4 method for signature 'mmatrix' apply(X, MARGIN, FUN, ..., simplify = TRUE)## S4 method for signature 'mmatrix' apply(X, MARGIN, FUN, ..., simplify = TRUE)
X |
a mmatrix |
MARGIN |
an integer giving the subscript which the function will be applied over |
FUN |
the function to be applied |
... |
extra arguments for 'FUN' |
simplify |
a logical indicating whether the results should be simplified |
If 'simplify' is TRUE the result will be a vector or a matrix, depending
on the size of the values returned by 'FUN'. If the size of this object is greater
than houba(max.size), then it will be memory-mapped (i.e., either a mvector
or a mmatrix). If 'simplify' is FALSE, the result is a list.
The function extracts the rows or the columns of 'X' one by one, to a R object, which is passed to 'FUN'.
If 'simplify' is TRUE, a matrix (or a mmatrix) or a vector (or a mvector). If 'simplify' is FALSE, a list.
a <- matrix(1:6, 2, 3) A <- as.mmatrix(a) apply(A, 1, var) apply(A, 2, var)a <- matrix(1:6, 2, 3) A <- as.mmatrix(a) apply(A, 1, var) apply(A, 2, var)
Arithmetic operators for memory mapped objects
## S4 method for signature 'mmatrixOrMarray,mvectorOrNumeric' e1 + e2 ## S4 method for signature 'mvectorOrNumeric,mmatrixOrMarray' e1 + e2 ## S4 method for signature 'mmatrixOrMarray,array' e1 + e2 ## S4 method for signature 'array,mmatrixOrMarray' e1 + e2 ## S4 method for signature 'mmatrixOrMarray,mmatrixOrMarray' e1 + e2 ## S4 method for signature 'mmatrixOrMarray,mvectorOrNumeric' e1 - e2 ## S4 method for signature 'mvectorOrNumeric,mmatrix' e1 - e2 ## S4 method for signature 'mvectorOrNumeric,marray' e1 - e2 ## S4 method for signature 'mmatrixOrMarray,array' e1 - e2 ## S4 method for signature 'matrix,mmatrix' e1 - e2 ## S4 method for signature 'array,marray' e1 - e2 ## S4 method for signature 'mmatrixOrMarray,mmatrixOrMarray' e1 - e2 ## S4 method for signature 'mmatrixOrMarray,missing' e1 - e2 ## S4 method for signature 'mmatrixOrMarray,mvectorOrNumeric' e1 * e2 ## S4 method for signature 'mvectorOrNumeric,mmatrixOrMarray' e1 * e2 ## S4 method for signature 'mmatrixOrMarray,array' e1 * e2 ## S4 method for signature 'array,mmatrixOrMarray' e1 * e2 ## S4 method for signature 'mmatrixOrMarray,mmatrixOrMarray' e1 * e2 ## S4 method for signature 'mmatrixOrMarray,mvectorOrNumeric' e1 / e2 ## S4 method for signature 'mvectorOrNumeric,mmatrix' e1 / e2 ## S4 method for signature 'mvectorOrNumeric,marray' e1 / e2 ## S4 method for signature 'mmatrixOrMarray,array' e1 / e2 ## S4 method for signature 'matrix,mmatrix' e1 / e2 ## S4 method for signature 'array,marray' e1 / e2 ## S4 method for signature 'mmatrixOrMarray,mmatrixOrMarray' e1 / e2 ## S4 method for signature 'mvector,mvectorOrNumeric' e1 + e2 ## S4 method for signature 'numeric,mvector' e1 + e2 ## S4 method for signature 'mvector,mvectorOrNumeric' e1 - e2 ## S4 method for signature 'numeric,mvector' e1 - e2 ## S4 method for signature 'mvector,missing' e1 - e2 ## S4 method for signature 'mvector,mvectorOrNumeric' e1 * e2 ## S4 method for signature 'numeric,mvector' e1 * e2 ## S4 method for signature 'mvector,mvectorOrNumeric' e1 / e2 ## S4 method for signature 'numeric,mvector' e1 / e2## S4 method for signature 'mmatrixOrMarray,mvectorOrNumeric' e1 + e2 ## S4 method for signature 'mvectorOrNumeric,mmatrixOrMarray' e1 + e2 ## S4 method for signature 'mmatrixOrMarray,array' e1 + e2 ## S4 method for signature 'array,mmatrixOrMarray' e1 + e2 ## S4 method for signature 'mmatrixOrMarray,mmatrixOrMarray' e1 + e2 ## S4 method for signature 'mmatrixOrMarray,mvectorOrNumeric' e1 - e2 ## S4 method for signature 'mvectorOrNumeric,mmatrix' e1 - e2 ## S4 method for signature 'mvectorOrNumeric,marray' e1 - e2 ## S4 method for signature 'mmatrixOrMarray,array' e1 - e2 ## S4 method for signature 'matrix,mmatrix' e1 - e2 ## S4 method for signature 'array,marray' e1 - e2 ## S4 method for signature 'mmatrixOrMarray,mmatrixOrMarray' e1 - e2 ## S4 method for signature 'mmatrixOrMarray,missing' e1 - e2 ## S4 method for signature 'mmatrixOrMarray,mvectorOrNumeric' e1 * e2 ## S4 method for signature 'mvectorOrNumeric,mmatrixOrMarray' e1 * e2 ## S4 method for signature 'mmatrixOrMarray,array' e1 * e2 ## S4 method for signature 'array,mmatrixOrMarray' e1 * e2 ## S4 method for signature 'mmatrixOrMarray,mmatrixOrMarray' e1 * e2 ## S4 method for signature 'mmatrixOrMarray,mvectorOrNumeric' e1 / e2 ## S4 method for signature 'mvectorOrNumeric,mmatrix' e1 / e2 ## S4 method for signature 'mvectorOrNumeric,marray' e1 / e2 ## S4 method for signature 'mmatrixOrMarray,array' e1 / e2 ## S4 method for signature 'matrix,mmatrix' e1 / e2 ## S4 method for signature 'array,marray' e1 / e2 ## S4 method for signature 'mmatrixOrMarray,mmatrixOrMarray' e1 / e2 ## S4 method for signature 'mvector,mvectorOrNumeric' e1 + e2 ## S4 method for signature 'numeric,mvector' e1 + e2 ## S4 method for signature 'mvector,mvectorOrNumeric' e1 - e2 ## S4 method for signature 'numeric,mvector' e1 - e2 ## S4 method for signature 'mvector,missing' e1 - e2 ## S4 method for signature 'mvector,mvectorOrNumeric' e1 * e2 ## S4 method for signature 'numeric,mvector' e1 * e2 ## S4 method for signature 'mvector,mvectorOrNumeric' e1 / e2 ## S4 method for signature 'numeric,mvector' e1 / e2
e1 |
first operand |
e2 |
second operand |
The usual operations are performed. Values are recycled if necessary. There's no type promotion: if one of the operands is a R object and the other is a memory-mapped object, the result will be a memory mapped object with same data type as the operand. If both operand are memory mapped objects with different data types, the result will be a memory mapped object with the same data type than the left operand.
an object of class mvector, mmatrix or marray depending on the operand classes.
x <- as.mvector(2**(1:4)) y <- 2*x x <- x/2 x + c(1,2) / yx <- as.mvector(2**(1:4)) y <- 2*x x <- x/2 x + c(1,2) / y
Converting memory-mapped objects to R objects
## S3 method for class 'marray' as.array(x, ...) ## S3 method for class 'marray' as.vector(x, mode = "any") ## S3 method for class 'mmatrix' as.matrix(x, ...) ## S3 method for class 'mmatrix' as.vector(x, mode = "any") ## S3 method for class 'mvector' as.vector(x, mode = "any")## S3 method for class 'marray' as.array(x, ...) ## S3 method for class 'marray' as.vector(x, mode = "any") ## S3 method for class 'mmatrix' as.matrix(x, ...) ## S3 method for class 'mmatrix' as.vector(x, mode = "any") ## S3 method for class 'mvector' as.vector(x, mode = "any")
x |
memory-mapped object to convert |
... |
extra parameters (ignored) |
mode |
the mode oh the created vector |
an array
a <- array( 1:24, c(2,3,4) ) A <- as.marray(a) all(as.array(A) == a) as.vector(A)a <- array( 1:24, c(2,3,4) ) A <- as.marray(a) all(as.array(A) == a) as.vector(A)
Conversion of R objects to memory mapped objects
as.marray(x, datatype, filename) ## S4 method for signature 'array' as.marray(x, datatype, filename) as.mmatrix(x, datatype, filename) ## S4 method for signature 'matrix' as.mmatrix(x, datatype, filename) as.mvector(x, datatype, filename) ## S4 method for signature 'numeric' as.mvector(x, datatype, filename)as.marray(x, datatype, filename) ## S4 method for signature 'array' as.marray(x, datatype, filename) as.mmatrix(x, datatype, filename) ## S4 method for signature 'matrix' as.mmatrix(x, datatype, filename) as.mvector(x, datatype, filename) ## S4 method for signature 'numeric' as.mvector(x, datatype, filename)
x |
an r object |
datatype |
(optional) type of the memory mapped object |
filename |
(optional) path to file |
If 'filename' is a path to an existing file, the function will raise an error. If you need to overwrite a file, unlink it first.
A memmory-mapped object, of class 'mvector', 'mmatrix' or 'marray'
a <- matrix(1:6, 2) A <- as.mmatrix(a) B <- as.mmatrix(a, "float") A Ba <- matrix(1:6, 2) A <- as.mmatrix(a) B <- as.mmatrix(a, "float") A B
Methods generalizing the base methods to mmatrix objects
## S4 method for signature 'mmatrix' colMeans(x, output.type) ## S4 method for signature 'mmatrix' colSums(x, output.type) ## S4 method for signature 'mmatrix' rowMeans(x, output.type) ## S4 method for signature 'mmatrix' rowSums(x, output.type)## S4 method for signature 'mmatrix' colMeans(x, output.type) ## S4 method for signature 'mmatrix' colSums(x, output.type) ## S4 method for signature 'mmatrix' rowMeans(x, output.type) ## S4 method for signature 'mmatrix' rowSums(x, output.type)
x |
a dual matrix or array |
output.type |
type of the result, if it's a mvector (see details) |
If the size of the result is greater
than houba(max.size), then it will be a mvector instead of R object.
In this case its type will be determined using 'output.type'. If 'output.type'
is missing, a coherent choice will be made (integer or double).
a mvector or a R vector, depending on the size of the result.
a <- matrix(1:20, 4, 5) A <- as.mmatrix(a, "float") colMeans(A) rowSums(A)a <- matrix(1:20, 4, 5) A <- as.mmatrix(a, "float") colMeans(A) rowSums(A)
Copy memory mapped object
copy(x, filename) ## S4 method for signature 'mvector' copy(x, filename) ## S4 method for signature 'mmatrix' copy(x, filename) ## S4 method for signature 'marray' copy(x, filename)copy(x, filename) ## S4 method for signature 'mvector' copy(x, filename) ## S4 method for signature 'mmatrix' copy(x, filename) ## S4 method for signature 'marray' copy(x, filename)
x |
a memory mapped object |
filename |
(optional) a file name for the new object |
Creates a new memory mapped object, identical to x.
A memory mapped object.
a <- as.mvector(1:4) b <- copy(a) a ba <- as.mvector(1:4) b <- copy(a) a b
Copy values to memory mapped object
copy.values(x, values) ## S4 method for signature 'memoryMapped,numericOrArray' copy.values(x, values) ## S4 method for signature 'memoryMapped,memoryMapped' copy.values(x, values)copy.values(x, values) ## S4 method for signature 'memoryMapped,numericOrArray' copy.values(x, values) ## S4 method for signature 'memoryMapped,memoryMapped' copy.values(x, values)
x |
a memory mapped object |
values |
a R object or a memory mmaped object |
Copy values to x, recycling if necessary. This
function modifies x in-place.
None.
A <- mvector("double", 3) copy.values(A, 1:3) B <- mvector("double", 6) copy.values(B, A) BA <- mvector("double", 3) copy.values(A, 1:3) B <- mvector("double", 6) copy.values(B, A) B
Descriptor file
descriptor.file(object) ## S4 method for signature 'mmatrix' descriptor.file(object) ## S4 method for signature 'mvector' descriptor.file(object) ## S4 method for signature 'marray' descriptor.file(object)descriptor.file(object) ## S4 method for signature 'mmatrix' descriptor.file(object) ## S4 method for signature 'mvector' descriptor.file(object) ## S4 method for signature 'marray' descriptor.file(object)
object |
a memory mapped object |
Creates a descriptor file, similar to the descriptor files of the package 'bigmemomry'. This descriptor allows to map the object with the package bigmemory, or the read.descriptor function in this package. Its name is obtained by appending ".desc' to the name of the file mapped by 'object'.
A method is available for marrays as well, but the resulting descriptor can't be read by 'bigmemory' as this package doesn't handle arrays. The function 'read.descriptor' in houba can read it.
None.
read.descriptor
A <- mmatrix("short", 10, 20) A[] <- sample.int(200) # create descriptor file dsc <- descriptor.file(A) # linking file to other object B <- read.descriptor(dsc, readonly = FALSE) all(as.matrix(A) == as.matrix(B)) # TRUE B[1:10] <- 0 all(A[1:10] == 0) # TRUEA <- mmatrix("short", 10, 20) A[] <- sample.int(200) # create descriptor file dsc <- descriptor.file(A) # linking file to other object B <- read.descriptor(dsc, readonly = FALSE) all(as.matrix(A) == as.matrix(B)) # TRUE B[1:10] <- 0 all(A[1:10] == 0) # TRUE
Change object dimensions
## S4 replacement method for signature 'memoryMapped,numeric' dim(x) <- value ## S4 replacement method for signature 'memoryMapped,NULL' dim(x) <- value## S4 replacement method for signature 'memoryMapped,numeric' dim(x) <- value ## S4 replacement method for signature 'memoryMapped,NULL' dim(x) <- value
x |
a memory mapped object |
value |
or |
The new dimensions must match the object size. This function can change the class of the object, e.g. from mvector to mmatrix or the reverse.
If the value is NULL, then x is turned into a mvector.
x <- as.mvector(1:6) x dim(x) <- 2:3 x dim(x) <- NULL xx <- as.mvector(1:6) x dim(x) <- 2:3 x dim(x) <- NULL x
Read/write access to memory-mapped objects
## S4 replacement method for signature 'marray,numeric,numeric,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'marray,missing,numeric,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'marray,numeric,missing,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'marray,missing,missing,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'marray,numeric,numeric,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'marray,missing,numeric,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'marray,numeric,missing,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'marray,missing,missing,memoryMapped' x[i, j, ...] <- value ## S4 method for signature 'marray,numeric,numeric' x[i, j, ..., drop = TRUE] ## S4 method for signature 'marray,missing,numeric' x[i, j, ..., drop = TRUE] ## S4 method for signature 'marray,numeric,missing' x[i, j, ..., drop = TRUE] ## S4 method for signature 'marray,missing,missing' x[i, j, ..., drop = TRUE] ## S4 replacement method for signature 'mmatrix,numeric,numeric,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'mmatrix,missing,numeric,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'mmatrix,numeric,missing,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'mmatrix,missing,missing,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'mmatrix,numeric,numeric,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'mmatrix,missing,numeric,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'mmatrix,numeric,missing,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'mmatrix,missing,missing,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'mvector,numeric,missing,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'mvector,missing,missing,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'mvector,numeric,missing,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'mvector,missing,missing,memoryMapped' x[i, j, ...] <- value ## S4 method for signature 'mmatrix,numeric,numeric' x[i, j, ..., drop = TRUE] ## S4 method for signature 'mmatrix,missing,numeric' x[i, j, ..., drop = TRUE] ## S4 method for signature 'mmatrix,numeric,missing' x[i, j, ..., drop = TRUE] ## S4 method for signature 'mmatrix,missing,missing' x[i, j, ..., drop = TRUE] ## S4 method for signature 'mvector,numeric,missing' x[i, j, ..., drop = TRUE] ## S4 method for signature 'mvector,missing,missing' x[i, j, ..., drop = TRUE]## S4 replacement method for signature 'marray,numeric,numeric,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'marray,missing,numeric,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'marray,numeric,missing,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'marray,missing,missing,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'marray,numeric,numeric,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'marray,missing,numeric,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'marray,numeric,missing,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'marray,missing,missing,memoryMapped' x[i, j, ...] <- value ## S4 method for signature 'marray,numeric,numeric' x[i, j, ..., drop = TRUE] ## S4 method for signature 'marray,missing,numeric' x[i, j, ..., drop = TRUE] ## S4 method for signature 'marray,numeric,missing' x[i, j, ..., drop = TRUE] ## S4 method for signature 'marray,missing,missing' x[i, j, ..., drop = TRUE] ## S4 replacement method for signature 'mmatrix,numeric,numeric,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'mmatrix,missing,numeric,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'mmatrix,numeric,missing,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'mmatrix,missing,missing,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'mmatrix,numeric,numeric,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'mmatrix,missing,numeric,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'mmatrix,numeric,missing,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'mmatrix,missing,missing,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'mvector,numeric,missing,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'mvector,missing,missing,numeric' x[i, j, ...] <- value ## S4 replacement method for signature 'mvector,numeric,missing,memoryMapped' x[i, j, ...] <- value ## S4 replacement method for signature 'mvector,missing,missing,memoryMapped' x[i, j, ...] <- value ## S4 method for signature 'mmatrix,numeric,numeric' x[i, j, ..., drop = TRUE] ## S4 method for signature 'mmatrix,missing,numeric' x[i, j, ..., drop = TRUE] ## S4 method for signature 'mmatrix,numeric,missing' x[i, j, ..., drop = TRUE] ## S4 method for signature 'mmatrix,missing,missing' x[i, j, ..., drop = TRUE] ## S4 method for signature 'mvector,numeric,missing' x[i, j, ..., drop = TRUE] ## S4 method for signature 'mvector,missing,missing' x[i, j, ..., drop = TRUE]
x |
memory-mapped object |
i, j
|
indices of elements to extract or replace |
... |
supplementary indices (for arrays) |
value |
replacement value |
drop |
for dual matrices or array. |
a R object or a memory-mapped object (depending on houba("max.size"))
a <- matrix(1:6, 2, 3) A <- as.mmatrix(a) A[1,] A[2,] <- A[1,] * 2 A[,3] <- 6:7 Aa <- matrix(1:6, 2, 3) A <- as.mmatrix(a) A[1,] A[2,] <- A[1,] * 2 A[,3] <- 6:7 A
Sync makes sure that the data written to the file linked with the object.
flush(con) ## S4 method for signature 'memoryMapped' flush(con)flush(con) ## S4 method for signature 'memoryMapped' flush(con)
con |
a memory mapped object |
An error will be raised if the object is read-only, or if the operation failed.
None
x <- as.mvector(1:50) x <- x + 1 flush(x)x <- as.mvector(1:50) x <- x + 1 flush(x)
Options for package houba
houba(...)houba(...)
... |
options to be defined, using 'name = value', or name(s) of option(s) to get. |
houba() sends back the list of all options. houba(option = value)
sets the option value. houba("option") sends back the value of an option.
Currently the only supported option is "max.size". Use houba("max.size") to
to get its value and, for example, houba(max.size = 1e3), to set it to 1000.
When subsetting an mvector or an mmatrix, if the size of the resulting object is greater than 'max.size', then the result will be a memory mapped object (mvector or mmatrix), else if will be a R object (vector or matrix). The default value is 1e6. Set 'max.size' to '0' to always get a memory mapped object and to 'Inf' to always get a R object.
a named list with options values, or a single option value.
houba() houba("maxsize")houba() houba("maxsize")
In-place arithmetic operations
inplace.inverse(x) inplace.opposite(x) inplace.sum(x, y) ## S4 method for signature 'memoryMapped,numeric' inplace.sum(x, y) ## S4 method for signature 'memoryMapped,memoryMapped' inplace.sum(x, y) inplace.minus(x, y) ## S4 method for signature 'memoryMapped,numeric' inplace.minus(x, y) ## S4 method for signature 'memoryMapped,memoryMapped' inplace.minus(x, y) inplace.prod(x, y) ## S4 method for signature 'memoryMapped,numeric' inplace.prod(x, y) ## S4 method for signature 'memoryMapped,memoryMapped' inplace.prod(x, y) inplace.div(x, y) ## S4 method for signature 'memoryMapped,numeric' inplace.div(x, y) ## S4 method for signature 'memoryMapped,memoryMapped' inplace.div(x, y)inplace.inverse(x) inplace.opposite(x) inplace.sum(x, y) ## S4 method for signature 'memoryMapped,numeric' inplace.sum(x, y) ## S4 method for signature 'memoryMapped,memoryMapped' inplace.sum(x, y) inplace.minus(x, y) ## S4 method for signature 'memoryMapped,numeric' inplace.minus(x, y) ## S4 method for signature 'memoryMapped,memoryMapped' inplace.minus(x, y) inplace.prod(x, y) ## S4 method for signature 'memoryMapped,numeric' inplace.prod(x, y) ## S4 method for signature 'memoryMapped,memoryMapped' inplace.prod(x, y) inplace.div(x, y) ## S4 method for signature 'memoryMapped,numeric' inplace.div(x, y) ## S4 method for signature 'memoryMapped,memoryMapped' inplace.div(x, y)
x |
a memory mapped object |
y |
a R object or a memory mapped object |
These functions will modify x in-place, performing
the operation indicated by their name.
None
x <- as.mvector( 2**(1:3) ) inplace.inverse(x) inplace.opposite(x) inplace.sum(x, 0.5) inplace.prod(x, 8) x y <- copy(x) inplace.prod(x, y) xx <- as.mvector( 2**(1:3) ) inplace.inverse(x) inplace.opposite(x) inplace.sum(x, 0.5) inplace.prod(x, 8) x y <- copy(x) inplace.prod(x, y) x
returns the length of a mvector
## S4 method for signature 'mvector' length(x)## S4 method for signature 'mvector' length(x)
x |
mvector |
an integer
These functions create memory mapped vectors, matrices or arrays,
possibly from an existing file. It is also possible to create objects in memory,
by passing the argument filename = "".
marray( datatype = c("double", "float", "integer", "short"), dim, filename, readonly ) mmatrix( datatype = c("double", "float", "integer", "short"), nrow, ncol, filename, readonly ) mvector( datatype = c("double", "float", "integer", "short"), length, filename, readonly )marray( datatype = c("double", "float", "integer", "short"), dim, filename, readonly ) mmatrix( datatype = c("double", "float", "integer", "short"), nrow, ncol, filename, readonly ) mvector( datatype = c("double", "float", "integer", "short"), length, filename, readonly )
datatype |
the data type |
dim |
dimension of marray |
filename |
(optional) path to file |
readonly |
(optional) if |
nrow |
number of rows of mmatrix |
ncol |
number of columns of mmatrix |
length |
length of mvector |
Currently datatype can only be double, float, int, or short. Short will always be a 16 bits
integer (int16_t).
If filename is missing, a temporary filename will be generated using tempfile.
If it is an empty string, the object will be created by allocating memory.
Otherwise, filename must be a valid path file;
if the file exists, it will be opened (if its size is compatible with the dimension
of the object); if the file does not exist, it will be created.
If readonly is missing, it will be set to TRUE when opening an existing file, and
to FALSE when the file is created by the function.
a memory mapped object, of class 'mvector', 'mmatrix' or 'marray'
a <- mmatrix("float", 4, 3) a[] <- 1:12 a[1,]a <- mmatrix("float", 4, 3) a[] <- 1:12 a[1,]
"marray"
S4 class for manipulating memory-mapped files as arrays
ptrexternalptr to an instance of the C++ MMatrix class
filecharacter with the path (absolute) of the file used to store the marray.
dimAn integer vector giving the dimensions of the marray.
datatypecharacter giving the C++ underlying datatype.
readonlylogical Indicates if the array if read-only.
Objects can be created by calling marray.
"mmatrix"
S4 class for manipulating memory-mapped files as matrices
ptrexternalptr to an instance of the C++ MMatrix class
filecharacter with the path (absolute) of the file used to store the mmatrix
dimAn integer vector giving the dimensions of the mmatrix
datatypecharacter giving the C++ underlying datatype.
readonlylogical Indicates if the array is read-only.
Objects can be created by calling mmatrix.
mvector
S4 class for manipulating memory-mapped files as vectors
ptrexternalptr to an instance of the C++ MMatrix class
filecharacter with the path (absolute) of the file used to store the mvector
lengthAn integer giving the length of the mvector
datatypecharacter giving the C++ underlying datatype.
readonlylogical Indicates if the vector if read-only.
Objects can be created by calling mvector.
Read big memory descriptor file
read.descriptor(descriptor, readonly)read.descriptor(descriptor, readonly)
descriptor |
name of descriptor file |
readonly |
|
Creates a memory-mapped object by reading a 'bigmemory'-like descriptor file.
a mvector or a mmatrix
A <- mmatrix("short", 10, 20) A[] <- sample.int(200) # create descriptor file dsc <- descriptor.file(A) # linking file to other object B <- read.descriptor(dsc, readonly = FALSE) all(as.matrix(A) == as.matrix(B)) # TRUE B[1:10] <- 0 all(A[1:10] == 0) # TRUEA <- mmatrix("short", 10, 20) A[] <- sample.int(200) # create descriptor file dsc <- descriptor.file(A) # linking file to other object B <- read.descriptor(dsc, readonly = FALSE) all(as.matrix(A) == as.matrix(B)) # TRUE B[1:10] <- 0 all(A[1:10] == 0) # TRUE
When the external pointer is broken, attempt to recreate a valid object, if the file still exists.
restore(object) ## S4 method for signature 'marray' restore(object) ## S4 method for signature 'mmatrix' restore(object) ## S4 method for signature 'mvector' restore(object)restore(object) ## S4 method for signature 'marray' restore(object) ## S4 method for signature 'mmatrix' restore(object) ## S4 method for signature 'mvector' restore(object)
object |
a memory mapped matrix |
a memory-mapped object
a <- matrix(1:24, 4, 6) A <- as.mmatrix(a, "float") rdsfile <- tempfile(fileext = ".rds") saveRDS(A, rdsfile) A <- readRDS(rdsfile) A A <- restore(A) Aa <- matrix(1:24, 4, 6) A <- as.mmatrix(a, "float") rdsfile <- tempfile(fileext = ".rds") saveRDS(A, rdsfile) A <- readRDS(rdsfile) A A <- restore(A) A
Type of a memory-mapped object
type(x) ## S4 method for signature 'memoryMapped' type(x)type(x) ## S4 method for signature 'memoryMapped' type(x)
x |
a memory mapped object |
Sends back the stored data type (currently "double", "float", "integer" or "short").
a string
x <- mvector("integer", 6) type(x)x <- mvector("integer", 6) type(x)