bigmemory/0000755000175100001440000000000013600200214012246 5ustar hornikusersbigmemory/NAMESPACE0000644000175100001440000000216013577165463013521 0ustar hornikusers# Generated by roxygen2: do not edit by hand export(GetMatrixSize) export(as.big.matrix) export(attach.big.matrix) export(big.matrix) export(deepcopy) export(dir.name) export(file.name) export(filebacked.big.matrix) export(flush) export(is.big.matrix) export(is.filebacked) export(is.float) export(is.nil) export(is.readonly) export(is.separated) export(is.shared) export(is.sub.big.matrix) export(morder) export(morderCols) export(mpermute) export(mpermuteCols) export(mwhich) export(read.big.matrix) export(shared.name) export(sub.big.matrix) export(write.big.matrix) exportClasses(big.matrix) exportClasses(big.matrix.descriptor) exportMethods("[") exportMethods("[<-") exportMethods("dimnames<-") exportMethods(as.matrix) exportMethods(attach.resource) exportMethods(describe) exportMethods(dim) exportMethods(dimnames) exportMethods(head) exportMethods(length) exportMethods(ncol) exportMethods(nrow) exportMethods(print) exportMethods(tail) exportMethods(typeof) import(Rcpp) import(bigmemory.sri) import(methods) importFrom(stats,na.omit) importFrom(utils,head) importFrom(utils,tail) useDynLib(bigmemory, .registration = TRUE) bigmemory/man/0000755000175100001440000000000013576750523013052 5ustar hornikusersbigmemory/man/big.matrix.descriptor-class.Rd0000644000175100001440000000433613577164364020676 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \docType{class} \name{descriptor-class} \alias{descriptor-class} \alias{big.matrix.descriptor-class} \alias{sub.big.matrix,big.matrix.descriptor-method} \alias{attach.resource,character-method} \alias{attach.resource,big.matrix.descriptor-method} \title{Class "big.matrix.descriptor"} \usage{ \S4method{sub.big.matrix}{big.matrix.descriptor}( x, firstRow = 1, lastRow = NULL, firstCol = 1, lastCol = NULL, backingpath = NULL ) \S4method{attach.resource}{character}(obj, ...) \S4method{attach.resource}{big.matrix.descriptor}(obj, ...) } \arguments{ \item{x}{A descriptor object} \item{firstRow}{the first row of the submatrix} \item{lastRow}{the last row of the submatrix if not NULL} \item{firstCol}{the first column of the submatrix} \item{lastCol}{of the submatrix if not NULL} \item{backingpath}{required path to the filebacked object, if applicable} \item{obj}{The filename of the descriptor for a filebacked matrix, assumed to be in the directory specified} \item{...}{possibly \code{path} which gives the path where the descriptor and/or filebacking can be found.} } \description{ An object of this class contains necessary and sufficient information to ``attach'' a shared or filebacked \code{\link{big.matrix}}. } \note{ We provide \code{attach.resource} for convenience, but expect most users will prefer \code{\link{attach.big.matrix}}. } \section{Objects from the Class}{ Objects should not be created by calls of the form \code{new("big.matrix.descriptor", ...)}, but should use the \code{\link{describe}} function. } \section{Slots}{ \describe{ \item{\code{description}:}{Object of class \code{"list"}; details omitted.} } } \section{Extends}{ Class \code{"\linkS4class{descriptor}"}, directly. } \section{Methods}{ \describe{ \item{attach.resource}{\code{signature(obj = "big.matrix.descriptor")}: ... } \item{sub.big.matrix}{\code{signature(x = "big.matrix.descriptor")}: ... } } } \examples{ showClass("big.matrix.descriptor") } \references{ Other types of descriptors are defined in package \pkg{synchronicity}. } \seealso{ See also \code{\link{attach.big.matrix}}. } \author{ John W. Emerson and Michael J. Kane } \keyword{classes} bigmemory/man/ncol-methods.Rd0000644000175100001440000000101113576750523015726 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \docType{methods} \name{ncol,big.matrix-method} \alias{ncol,big.matrix-method} \alias{nrow,big.matrix-method} \title{The Number of Rows/Columns of a big.matrix} \usage{ \S4method{ncol}{big.matrix}(x) \S4method{nrow}{big.matrix}(x) } \arguments{ \item{x}{A big.matrix object} } \value{ An integer of length 1 } \description{ \code{nrow} and \code{ncol} return the number of rows or columns present in a \code{big.matrix} object. } bigmemory/man/big.matrix-class.Rd0000644000175100001440000001170413577164364016516 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \docType{class} \name{big.matrix-class} \alias{big.matrix-class} \title{Class "big.matrix"} \description{ The \code{big.matrix} class is designed for matrices with elements of type \code{double}, \code{integer}, \code{short}, or \code{char}. A \code{big.matrix} acts much like a traditional \R matrix, but helps protect the user from many inadvertent memory-consuming pitfalls of traditional \R matrices and data frames. The objects are allocated to shared memory, and if file-backing is used they may exceed virtual memory in size. Sadly, 32-bit operating system constraints -- largely Windows and some MacOS versions --will be a limiting factor with file-backed matrices; 64-bit operating systems are recommended. } \section{Objects from the Class}{ Unlike many \R objects, objects should not be created by calls of the form \code{new("big.matrix", ...)}. The functions \code{big.matrix()} and \code{filebacked.big.matrix()} are intended for the user. } \section{Slots}{ \describe{\item{\code{address}:}{Object of class \code{"externalptr"} points to the memory location of the \acronym{C++} data structure.}} } \section{Methods}{ \describe{ As you would expect: \item{[<-}{\code{signature(x = "big.matrix", i = "ANY", j = "ANY")}: ... } \item{[<-}{\code{signature(x = "big.matrix", i = "ANY", j = "missing")}: ... } \item{[<-}{\code{signature(x = "big.matrix", i = "missing", j = "ANY")}: ... } \item{[<-}{\code{signature(x = "big.matrix", i = "missing", j = "missing")}: ... } \item{[<-}{\code{signature(x = "big.matrix", i = "matrix", j = "missing")}: ... } \item{[}{\code{signature(x = "big.matrix", i = "ANY", j = "ANY", drop = "missing")}: ... } \item{[}{\code{signature(x = "big.matrix", i = "ANY", j = "ANY", drop = "logical")}: ... } \item{[}{\code{signature(x = "big.matrix", i = "ANY", j = "missing", drop = "missing")}: ... } \item{[}{\code{signature(x = "big.matrix", i = "ANY", j = "missing", drop = "logical")}: ... } \item{[}{\code{signature(x = "big.matrix", i = "matrix", j = "missing", drop = "logical")}: ... } \item{[}{\code{signature(x = "big.matrix", i = "missing", j = "ANY", drop = "missing")}: ... } \item{[}{\code{signature(x = "big.matrix", i = "missing", j = "ANY", drop = "logical")}: ... } \item{[}{\code{signature(x = "big.matrix", i = "missing", j = "missing", drop = "missing")}: ... } \item{[}{\code{signature(x = "big.matrix", i = "missing", j = "missing", drop = "logical")}: ... } The following are probably more interesting: \item{describe}{\code{signature(x = "big.matrix")}: provide necessary and sufficient information for the sharing or re-attaching of the object. } \item{dim}{\code{signature(x = "big.matrix")}: returns the dimension of the \code{big.matrix}. } \item{length}{\code{signature(x = "big.matrix")}: returns the product of the dimensions of the \code{big.matrix}. } \item{dimnames<-}{\code{signature(x = "big.matrix", value = "list")}: set the row and column names, prohibited by default (see \code{\link{bigmemory}} to override). } \item{dimnames}{\code{signature(x = "big.matrix")}: get the row and column names. } \item{head}{\code{signature(x = "big.matrix")}: get the first 6 (or \code{n}) rows. } \item{as.matrix}{\code{signature(x = "big.matrix")}: coerce a \code{big.matrix} to a \code{matrix}. } \item{is.big.matrix}{\code{signature(x = "big.matrix")}: return \code{TRUE} if it's a \code{big.matrix}. } \item{is.filebacked}{\code{signature(x = "big.matrix")}: return \code{TRUE} if there is a file-backing. } \item{is.separated}{\code{signature(x = "big.matrix") }: return \code{TRUE} if the \code{big.matrix} is organized as a separated column vectors.} \item{is.sub.big.matrix}{\code{signature(x = "big.matrix")}: return \code{TRUE} if this is a sub-matrix of a \code{big.matrix}. } \item{ncol}{\code{signature(x = "big.matrix")}: returns the number of columns. } \item{nrow}{\code{signature(x = "big.matrix")}: returns the number of rows. } \item{print}{\code{signature(x = "big.matrix")}: a traditional \code{print()} is intentionally disabled, and returns \code{head(x)} unless \code{options()$bm.print.warning==FALSE}; in this case, \code{print(x[,])} is the result, which could be very big! } \item{sub.big.matrix}{\code{signature(x = "big.matrix")}: for contiguous submatrices. } \item{tail}{\code{signature(x = "big.matrix")}: returns the last 6 (or \code{n}) rows. } \item{typeof}{\code{signature(x = "big.matrix")}: return the type of the atomic elements of the \code{big.matrix}.} \item{write.big.matrix}{\code{signature(bigMat = "big.matrix", fileName = "character")}: produce an ASCII file from the \code{big.matrix}.} \item{apply}{\code{signature(x = "big.matrix")}: \code{apply()} where \code{MARGIN} may only be 1 or 2, but otherwise conforming to what you would expect from \code{apply()}.} } } \examples{ showClass("big.matrix") } \seealso{ \code{\link{big.matrix}} } \author{ Michael J. Kane and John W. Emerson \email{} } \keyword{classes} bigmemory/man/extract-methods.Rd0000644000175100001440000000721113577164364016460 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \docType{methods} \name{Extract,big.matrix} \alias{Extract,big.matrix} \alias{[,big.matrix,ANY,ANY,missing-method} \alias{[<-,big.matrix,ANY,ANY,ANY-method} \alias{[,big.matrix,ANY,ANY,logical-method} \alias{[,big.matrix,missing,ANY,missing-method} \alias{[,big.matrix,missing,ANY,logical-method} \alias{[,big.matrix,ANY,missing,missing-method} \alias{[,big.matrix,ANY,missing,logical-method} \alias{[,big.matrix,missing,missing,missing-method} \alias{[,big.matrix,missing,missing,logical-method} \alias{[,big.matrix,matrix,missing,missing-method} \alias{[<-,big.matrix,numeric,numeric,ANY-method} \alias{[<-,big.matrix,numeric,logical,ANY-method} \alias{[<-,big.matrix,logical,numeric,ANY-method} \alias{[<-,big.matrix,logical,logical,ANY-method} \alias{[<-,big.matrix,logical,character,ANY-method} \alias{[<-,big.matrix,numeric,character,ANY-method} \alias{[<-,big.matrix,missing,missing,ANY-method} \alias{[<-,big.matrix,missing,numeric,ANY-method} \alias{[<-,big.matrix,missing,logical,ANY-method} \alias{[<-,big.matrix,numeric,missing,numeric-method} \alias{[<-,big.matrix,logical,missing,numeric-method} \alias{[<-,big.matrix,numeric,missing,matrix-method} \alias{[<-,big.matrix,logical,missing,matrix-method} \alias{[<-,big.matrix,character,character,ANY-method} \alias{[<-,big.matrix,missing,character,ANY-method} \alias{[<-,big.matrix,character,missing,ANY-method} \alias{[<-,big.matrix,missing,missing,numeric-method} \alias{[<-,big.matrix,matrix,missing,numeric-method} \title{Extract or Replace} \usage{ \S4method{[}{big.matrix,ANY,ANY,missing}(x, i, j, drop) \S4method{[}{big.matrix,ANY,ANY,logical}(x, i, j, drop) \S4method{[}{big.matrix,missing,ANY,missing}(x, i, j, drop) \S4method{[}{big.matrix,missing,ANY,logical}(x, i, j, drop) \S4method{[}{big.matrix,ANY,missing,missing}(x, i, j, ..., drop = TRUE) \S4method{[}{big.matrix,ANY,missing,logical}(x, i, j, drop) \S4method{[}{big.matrix,missing,missing,missing}(x, i, j, drop) \S4method{[}{big.matrix,missing,missing,logical}(x, i, j, drop) \S4method{[}{big.matrix,matrix,missing,missing}(x, i, j, drop) \S4method{[}{big.matrix,numeric,numeric,ANY}(x, i, j) <- value \S4method{[}{big.matrix,numeric,logical,ANY}(x, i, j) <- value \S4method{[}{big.matrix,logical,numeric,ANY}(x, i, j) <- value \S4method{[}{big.matrix,logical,logical,ANY}(x, i, j) <- value \S4method{[}{big.matrix,logical,character,ANY}(x, i, j) <- value \S4method{[}{big.matrix,numeric,character,ANY}(x, i, j) <- value \S4method{[}{big.matrix,missing,missing,ANY}(x, i, j) <- value \S4method{[}{big.matrix,missing,numeric,ANY}(x, i, j) <- value \S4method{[}{big.matrix,missing,logical,ANY}(x, i, j) <- value \S4method{[}{big.matrix,numeric,missing,numeric}(x, i, j, ...) <- value \S4method{[}{big.matrix,logical,missing,numeric}(x, i, j, ...) <- value \S4method{[}{big.matrix,numeric,missing,matrix}(x, i, j, ...) <- value \S4method{[}{big.matrix,logical,missing,matrix}(x, i, j, ...) <- value \S4method{[}{big.matrix,character,character,ANY}(x, i, j) <- value \S4method{[}{big.matrix,missing,character,ANY}(x, j) <- value \S4method{[}{big.matrix,character,missing,ANY}(x, i) <- value \S4method{[}{big.matrix,missing,missing,numeric}(x, i, j) <- value \S4method{[}{big.matrix,matrix,missing,numeric}(x, i, j) <- value } \arguments{ \item{x}{A \code{big.matrix object}} \item{i}{Indices specifying the rows} \item{j}{Indices specifying the columns} \item{drop}{Logical indication if reduce to minimum dimensions} \item{...}{Additional arguments} \item{value}{typically an array-like R object of similar class} } \description{ Extract or replace big.matrix elements } bigmemory/man/bigmemory-package.Rd0000644000175100001440000001310213576750523016721 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/hello-bigmemory.R \docType{package} \name{bigmemory-package} \alias{bigmemory-package} \alias{bigmemory} \title{Manage massive matrices with shared memory and memory-mapped files.} \description{ Create, store, access, and manipulate massive matrices. Matrices are, by default, allocated to shared memory and may use memory-mapped files. Packages \pkg{biganalytics}, \pkg{synchronicity}, \pkg{bigalgebra}, and \pkg{bigtabulate} provide advanced functionality. Access to and manipulation of a \code{\link{big.matrix}} object is exposed in an S4 class whose interface is similar to that of a \code{\link{matrix}}. Use of these packages in parallel environments can provide substantial speed and memory efficiencies. \pkg{bigmemory} also provides a \acronym{C++} framework for the development of new tools that can work both with \code{big.matrix} and native \code{matrix} objects. } \details{ Index of functions/methods (grouped in a friendly way): \preformatted{ big.matrix, filebacked.big.matrix, as.big.matrix is.big.matrix, is.separated, is.filebacked describe, attach.big.matrix, attach.resource sub.big.matrix, is.sub.big.matrix dim, dimnames, nrow, ncol, print, head, tail, typeof, length read.big.matrix, write.big.matrix mwhich morder, mpermute deepcopy flush } Multi-gigabyte data sets challenge and frustrate users, even on well-equipped hardware. Use of \acronym{C/C++} can provide efficiencies, but is cumbersome for interactive data analysis and lacks the flexibility and power of 's rich statistical programming environment. The package \pkg{bigmemory} and associated packages \pkg{biganalytics}, \pkg{synchronicity}, \pkg{bigtabulate}, and \pkg{bigalgebra} bridge this gap, implementing massive matrices and supporting their manipulation and exploration. The data structures may be allocated to shared memory, allowing separate processes on the same computer to share access to a single copy of the data set. The data structures may also be file-backed, allowing users to easily manage and analyze data sets larger than available RAM and share them across nodes of a cluster. These features of the Bigmemory Project open the door for powerful and memory-efficient parallel analyses and data mining of massive data sets. This project (\pkg{bigmemory} and its sister packages) is still actively developed, although the design and current features can be viewed as "stable." Please feel free to email us with any questions: bigmemoryauthors@gmail.com. } \note{ Various options are available. \code{options(bigmemory.typecast.warning)} can be set to avoid annoying warnings that might occur if, for example, you assign objects (typically type double) to char, short, or integer \code{\link{big.matrix}} objects. \code{options(bigmemory.print.warning)} protects against extracting and printing a massive matrix (which would involve the creation of a second massive copy of the matrix). \code{options(bigmemory.allow.dimnames)} by default prevents the setting of \code{dimnames} attributes, because they aren't allocated to shared memory and changes will not be visible across processes. \code{options(bigmemory.default.type)} is \code{"double"} be default (a change in default behavior as of 4.1.1) but may be changed by the user. Note that you can't simply use a \code{big.matrix} with many (most) existing functions (e.g. \code{\link{lm}}, \code{\link{kmeans}}). One nice exception is \code{\link{split}}, because this function only accesses subsets of the matrix. } \section{Memory considerations}{ For obvious reasons memory that the \code{big.matrix} uses is managed outside the R memory pool available to the garbage collector and the memory occupied by the \code{big.matrix} is not visible to the R. This has subtle implications: \itemize{ \item Memory usage is not visible via general R functions (e.g. the \code{gc()} function) \item Garbage collector is mislead by the very small memory footprint of the \code{big.matrix} object (which acts merely as a pointer to the external memory structure), which can result in much less eagerness to garbage-collect the unused \code{big.memory} objects. After removing a last reference to a big \code{big.matrix}, user should manually run \code{gc()} to reclaim the memory. \item Attaching the description of already finalized \code{big.matrix} and accessing this object will result in undefined behavior, which simply means it will crash the current R session with no hope of saving the data in it. To prevent R from de-allocating (finalizing) the matrices, user should keep at least one \code{big.memory} object somewhere in R memory in at least one R session on the current machine. \item Abruptly closed R (using e.g. task manager) will not have a chance to finalize the \code{big.matrix} objects, which will result in a memory leak, as the \code{big.matrices} will remain in the memory (perhaps under obfuscated names) with no easy way to reconnect R to them. } } \examples{ # Our examples are all trivial in size, rather than burning huge amounts # of memory. x <- big.matrix(5, 2, type="integer", init=0, dimnames=list(NULL, c("alpha", "beta"))) x x[1:2,] x[,1] <- 1:5 x[,"alpha"] colnames(x) options(bigmemory.allow.dimnames=TRUE) colnames(x) <- NULL x[,] } \references{ \url{http://www.bigmemory.org} } \seealso{ For example, \code{\link{big.matrix}}, \code{\link{mwhich}}, \code{\link{read.big.matrix}} } \author{ Michael J. Kane, John W. Emerson, Peter Haverty, and Charles Determan Jr. Maintainers: Michael J. Kane \href{mailto:bigmemoryauthors@gmail.com}{bigmemoryauthors@gmail.com} } \keyword{package} bigmemory/man/print-big.matrix-method.Rd0000644000175100001440000000110313577164364020013 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \name{print,big.matrix-method} \alias{print,big.matrix-method} \title{Print Values} \usage{ \S4method{print}{big.matrix}(x) } \arguments{ \item{x}{A \code{big.matrix} object} } \description{ \code{print} will print out the elements within a \code{big.matrix} object. } \note{ By default, this will only return the \code{head} of a big.matrix to prevent console overflow. If you turn off the bigmemory.print.warning option then it will convert to a base R matrix and print all elements. } bigmemory/man/mwhich.Rd0000644000175100001440000000717313577164364014633 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \name{mwhich} \alias{mwhich} \title{Expanded ``which''-like functionality.} \usage{ mwhich(x, cols, vals, comps, op = "AND") } \arguments{ \item{x}{a \code{\link{big.matrix}} (or a numeric matrix; see below).} \item{cols}{a vector of column indices or names.} \item{vals}{a list (one component for each of \code{cols}) of vectors of length 1 or 2; length 1 is used to test equality (or inequality), while vectors of length 2 are used for checking values in the range (\code{-Inf} and \code{Inf} are allowed). If a scalar or vector of length 2 is provided instead of a list, it will be replicated \code{length(cols)} times.} \item{comps}{a list of operators (one component for each of \code{cols}), including \code{'eq'}, \code{'neq'}, \code{'le'}, \code{'lt'}, \code{'ge'} and \code{'gt'}. If a single operator, it will be replicated \code{length(cols)} times.} \item{op}{the comparison operator for combining the results of the individual tests, either \code{'AND'} or \code{'OR'}.} } \value{ a vector of row indices satisfying the criteria. } \description{ Implements \code{\link{which}}-like functionality for a \code{\link{big.matrix}}, with additional options for efficient comparisons (executed in \acronym{C++}); also works for regular numeric matrices without the memory overhead. } \details{ To improve performance and avoid the creation of massive temporary vectors in \R when doing comparisons, \code{mwhich()} efficiently executes column-by-column comparisons of values to the specified values or ranges, and then returns the row indices satisfying the comparison specified by the \code{op} operator. More advanced comparisons are then possible (and memory-efficient) in \R by doing set operations (\code{\link{union}} and \code{\link{intersect}}, for example) on the results of multiple \code{mwhich()} calls. Note that \code{NA} is a valid argument in conjunction with \code{'eq'} or \code{'neq'}, replacing traditional \code{is.na()} calls. And both \code{-Inf} and \code{Inf} can be used for one-sided inequalities. If \code{mwhich()} is used with a regular numeric \R \code{matrix}, we access the data directly and thus incur no memory overhead. Interested developers might want to look at our code for this case, which uses a handy pointer trick (accessor) in \acronym{C++}. } \examples{ x <- as.big.matrix(matrix(1:30, 10, 3)) options(bigmemory.allow.dimnames=TRUE) colnames(x) <- c("A", "B", "C") x[,] x[mwhich(x, 1:2, list(c(2,3), c(11,17)), list(c('ge','le'), c('gt', 'lt')), 'OR'),] x[mwhich(x, c("A","B"), list(c(2,3), c(11,17)), list(c('ge','le'), c('gt', 'lt')), 'AND'),] # These should produce the same answer with a regular matrix: y <- matrix(1:30, 10, 3) y[mwhich(y, 1:2, list(c(2,3), c(11,17)), list(c('ge','le'), c('gt', 'lt')), 'OR'),] y[mwhich(y, -3, list(c(2,3), c(11,17)), list(c('ge','le'), c('gt', 'lt')), 'AND'),] x[1,1] <- NA mwhich(x, 1:2, NA, 'eq', 'OR') mwhich(x, 1:2, NA, 'neq', 'AND') # Column 1 equal to 4 and/or column 2 less than or equal to 16: mwhich(x, 1:2, list(4, 16), list('eq', 'le'), 'OR') mwhich(x, 1:2, list(4, 16), list('eq', 'le'), 'AND') # Column 2 less than or equal to 15: mwhich(x, 2, 15, 'le') # No NAs in either column, and column 2 strictly less than 15: mwhich(x, c(1:2,2), list(NA, NA, 15), list('neq', 'neq', 'lt'), 'AND') x <- big.matrix(4, 2, init=1, type="double") x[1,1] <- Inf mwhich(x, 1, Inf, 'eq') mwhich(x, 1, 1, 'gt') mwhich(x, 1, 1, 'le') } \seealso{ \code{\link{big.matrix}}, \code{\link{which}} } \author{ John W. Emerson \email{} } \keyword{methods} bigmemory/man/GetMatrixSize.Rd0000644000175100001440000000046713576750523016107 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/RcppExports.R \name{GetMatrixSize} \alias{GetMatrixSize} \title{big.matrix size} \usage{ GetMatrixSize(bigMat) } \arguments{ \item{bigMat}{a \code{big.matrix} object} } \description{ Returns the size of the created matrix in bytes } bigmemory/man/deepcopy.Rd0000644000175100001440000000466413577164364015166 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \name{deepcopy} \alias{deepcopy} \title{Produces a physical copy of a ``big.matrix''} \usage{ deepcopy( x, cols = NULL, rows = NULL, y = NULL, type = NULL, separated = NULL, backingfile = NULL, backingpath = NULL, descriptorfile = NULL, binarydescriptor = FALSE, shared = options()$bigmemory.default.shared ) } \arguments{ \item{x}{a \code{\link{big.matrix}}.} \item{cols}{possible subset of columns for the deepcopy; could be numeric, named, or logical.} \item{rows}{possible subset of rows for the deepcopy; could be numeric, named, or logical.} \item{y}{optional destination object (\code{matrix} or \code{big.matrix}); if not specified, a \code{big.matrix} will be created.} \item{type}{preferably specified, \code{"integer"} for example.} \item{separated}{use separated column organization of the data instead of column-major organization; use with caution if the number of columns is large.} \item{backingfile}{the root name for the file(s) for the cache of \code{x}.} \item{backingpath}{the path to the directory containing the file-backing cache.} \item{descriptorfile}{we recommend specifying this for file-backing.} \item{binarydescriptor}{the flag to specify if the binary RDS format should be used for the backingfile description, for subsequent use with \code{\link{attach.big.matrix}}; if \code{NULL} of \code{FALSE}, the \code{dput()} file format is used.} \item{shared}{\code{TRUE} by default, and always \code{TRUE} if the \code{big.matrix} is file-backed. For a non-filebacked \code{big.matrix}, \code{shared=FALSE} uses non-shared memory, which can be more stable for large (say, >50\\% of RAM) objects. Shared memory allocation can sometimes fail in such cases due to exhausted shared-memory resources in the system.} } \value{ a \code{\link{big.matrix}}. } \description{ This is needed to make a duplicate of a \code{big.matrix}, with the new copy optionally filebacked. } \details{ This is needed to make a duplicate of a \code{\link{big.matrix}}, because traditional syntax would only copy the object (the pointer to the \code{\link{big.matrix}} rather than the \code{\link{big.matrix}} itself). It can also make a copy of only a subset of columns. } \examples{ x <- as.big.matrix(matrix(1:30, 10, 3)) y <- deepcopy(x, -1) # Don't include the first column. x y head(x) head(y) } \seealso{ \code{\link{big.matrix}} } \keyword{methods} bigmemory/man/sub.big.matrix.Rd0000644000175100001440000000363313577164364016205 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \name{is.sub.big.matrix} \alias{is.sub.big.matrix} \alias{is.sub.big.matrix,big.matrix-method} \alias{sub.big.matrix} \alias{sub.big.matrix,big.matrix-method} \title{Submatrix support} \usage{ is.sub.big.matrix(x) \S4method{is.sub.big.matrix}{big.matrix}(x) sub.big.matrix( x, firstRow = 1, lastRow = NULL, firstCol = 1, lastCol = NULL, backingpath = NULL ) \S4method{sub.big.matrix}{big.matrix}( x, firstRow = 1, lastRow = NULL, firstCol = 1, lastCol = NULL, backingpath = NULL ) } \arguments{ \item{x}{either a \code{\link{big.matrix}} or a descriptor.} \item{firstRow}{the first row of the submatrix.} \item{lastRow}{the last row of the submatrix if not \code{NULL}.} \item{firstCol}{the first column of the submatrix.} \item{lastCol}{the last column of the submatrix if not \code{NULL}.} \item{backingpath}{required path to the filebacked object, if applicable.} } \value{ A \code{\link{big.matrix}} which is actually a submatrix of a larger \code{big.matrix}. It is not a physical copy. Only contiguous blocks may form a submatrix. } \description{ This doesn't create a copy, it just provides a new version of the class which provides behavior for a contiguous submatrix of the big.matrix. Non-contiguous submatrices are not supported. } \details{ The \code{sub.big.matrix} function allows a user to create a \code{big.matrix} object that references a contiguous set of columns and rows of another \code{big.matrix} object. The \code{is.sub.big.matrix} function returns \code{TRUE} if the specified argument is a \code{sub.big.matrix} object and return \code{FALSE} otherwise. } \examples{ x <- big.matrix(10, 5, init=0, type="double") x[,] <- 1:50 y <- sub.big.matrix(x, 2, 9, 2, 3) y[,] y[1,1] <- -99 x[,] rm(x) } \seealso{ \code{\link{big.matrix}} } \author{ John W. Emerson and Michael J. Kane } \keyword{methods} bigmemory/man/as.matrix-big.matrix-method.Rd0000644000175100001440000000060113577164364020567 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \name{as.matrix,big.matrix-method} \alias{as.matrix,big.matrix-method} \title{Convert to base R matrix} \usage{ \S4method{as.matrix}{big.matrix}(x) } \arguments{ \item{x}{A big.matrix object} } \description{ Extract values from a \code{big.matrix} object and convert to a base R matrix object } bigmemory/man/attach.big.matrix.Rd0000644000175100001440000000456513577164364016665 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \name{describe,big.matrix-method} \alias{describe,big.matrix-method} \alias{attach.big.matrix} \alias{describe} \alias{attach.resource} \title{The basic ``big.matrix'' operations for sharing and re-attaching.} \usage{ \S4method{describe}{big.matrix}(x) attach.big.matrix(obj, ...) } \arguments{ \item{x}{a \code{\link{big.matrix}} object} \item{obj}{an object as returned by \code{describe()} or, optionally, the filename of the descriptor for a filebacked matrix, assumed to be in the directory specified by the \code{path} (if one is provided)} \item{...}{possibly \code{path} which gives the path where the descriptor and/or filebacking can be found} } \value{ \code{describe} returns a list of of the information needed to attach to a \code{big.matrix} object. \code{attach.big.matrix} return a new instance of type \code{big.matrix} corresponding to a shared-memory or file-backed \code{big.matrix}. } \description{ The \code{describe} function returns the information needed by \code{attach.big.matrix} to reference a shared or file-backed \code{big.matrix} object. The \code{attach.big.matrix} and \code{attach.resource} functions create a new \code{big.matrix} object based on the descriptor information referencing previously allocated shared-memory or file-backed matrices. } \details{ The \code{describe} function returns a list of the information needed to attach to a \code{big.matrix} object. A descriptor file is automatically created when a new filebacked \code{big.matrix} is created. } \examples{ # The example is quite silly, as you wouldn't likely do this in a # single R session. But if zdescription were passed to another R session # via SNOW, foreach, or even by a simple file read/write, # then the attach of the second R process would give access to the # same object in memory. Please see the package vignette for real examples. z <- big.matrix(3, 3, type='integer', init=3) z[,] dim(z) z[1,1] <- 2 z[,] zdescription <- describe(z) zdescription y <- attach.big.matrix(zdescription) y[,] y z zz <- attach.resource(zdescription) zz[1,1] <- -100 y[,] z[,] } \seealso{ \code{\link{bigmemory}}, \code{\link{big.matrix}}, or the class documentation \code{\linkS4class{big.matrix}}. } \author{ Michael J. Kane and John W. Emerson \email{} } \keyword{classes} \keyword{methods} bigmemory/man/is.float.Rd0000644000175100001440000000046313576750523015063 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \name{is.float} \alias{is.float} \title{Check if Float} \usage{ is.float(x) } \arguments{ \item{x}{An object to be evaluated if float} } \description{ Check to see if the elements of a big.matrix object are floats. } bigmemory/man/write.big.matrix.Rd0000644000175100001440000001273713577164364016553 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \name{write.big.matrix} \alias{write.big.matrix} \alias{write.big.matrix,big.matrix,character-method} \alias{read.big.matrix} \alias{read.big.matrix,character-method} \title{File interface for a ``big.matrix''} \usage{ write.big.matrix(x, filename, row.names = FALSE, col.names = FALSE, sep = ",") \S4method{write.big.matrix}{big.matrix,character}(x, filename, row.names = FALSE, col.names = FALSE, sep = ",") read.big.matrix( filename, sep = ",", header = FALSE, col.names = NULL, row.names = NULL, has.row.names = FALSE, ignore.row.names = FALSE, type = NA, skip = 0, separated = FALSE, backingfile = NULL, backingpath = NULL, descriptorfile = NULL, binarydescriptor = FALSE, extraCols = NULL, shared = options()$bigmemory.default.shared ) \S4method{read.big.matrix}{character}( filename, sep = ",", header = FALSE, col.names = NULL, row.names = NULL, has.row.names = FALSE, ignore.row.names = FALSE, type = NA, skip = 0, separated = FALSE, backingfile = NULL, backingpath = NULL, descriptorfile = NULL, binarydescriptor = FALSE, extraCols = NULL, shared = options()$bigmemory.default.shared ) } \arguments{ \item{x}{a \code{\link{big.matrix}}.} \item{filename}{the name of an input/output file.} \item{row.names}{a vector of names, use them even if row names appear to exist in the file.} \item{col.names}{a vector of names, use them even if column names exist in the file.} \item{sep}{a field delimiter.} \item{header}{if \code{TRUE}, the first line (after a possible skip) should contain column names.} \item{has.row.names}{if \code{TRUE}, then the first column contains row names.} \item{ignore.row.names}{if \code{TRUE} when \code{has.row.names==TRUE}, the row names will be ignored.} \item{type}{preferably specified, \code{"integer"} for example.} \item{skip}{number of lines to skip at the head of the file.} \item{separated}{use separated column organization of the data instead of column-major organization.} \item{backingfile}{the root name for the file(s) for the cache of \code{x}.} \item{backingpath}{the path to the directory containing the file backing cache.} \item{descriptorfile}{the file to be used for the description of the filebacked matrix.} \item{binarydescriptor}{the flag to specify if the binary RDS format should be used for the backingfile description, for subsequent use with \code{\link{attach.big.matrix}}; if \code{NULL} of \code{FALSE}, the \code{dput()} file format is used.} \item{extraCols}{the optional number of extra columns to be appended to the matrix for future use.} \item{shared}{if \code{TRUE}, the resulting \code{big.matrix} can be shared across processes.} } \value{ a \code{\link{big.matrix}} object is returned by \code{read.big.matrix}, while \code{write.big.matrix} creates an output file (a path could be part of \code{filename}). } \description{ Create a \code{\link{big.matrix}} by reading from a suitably-formatted ASCII file, or write the contents of a \code{\link{big.matrix}} to a file. } \details{ Files must contain only one atomic type (all \code{integer}, for example). You, the user, should know whether your file has row and/or column names, and various combinations of options should be helpful in obtaining the desired behavior. When reading from a file, if \code{type} is not specified we try to make a reasonable guess for you without making any guarantees at this point. Unless you have really large integer values, we recommend you consider \code{"short"}. If you have something that is essentially categorical, you might even be able use \code{"char"}, with huge memory savings for large data sets. Any non-numeric entry will be ignored and replaced with \code{NA}, so reading something that traditionally would be a \code{data.frame} won't cause an error. A warning is issued. Wishlist: we'd like to provide an option to ignore specified columns while doing reads. Or perhaps to specify columns targeted for factor or character conversion to numeric values. Would you use such features? Email us and let us know! } \examples{ # Without specifying the type, this big.matrix x will hold integers. x <- as.big.matrix(matrix(1:10, 5, 2)) x[2,2] <- NA x[,] temp_dir = tempdir() if (!dir.exists(temp_dir)) dir.create(temp_dir) write.big.matrix(x, file.path(temp_dir, "foo.txt")) # Just for fun, I'll read it back in as character (1-byte integers): y <- read.big.matrix(file.path(temp_dir, "foo.txt"), type="char") y[,] # Other examples: w <- as.big.matrix(matrix(1:10, 5, 2), type='double') w[1,2] <- NA w[2,2] <- -Inf w[3,2] <- Inf w[4,2] <- NaN w[,] write.big.matrix(w, file.path(temp_dir, "bar.txt")) w <- read.big.matrix(file.path(temp_dir, "bar.txt"), type="double") w[,] w <- read.big.matrix(file.path(temp_dir, "bar.txt"), type="short") w[,] # Another example using row names (which we don't like). x <- as.big.matrix(as.matrix(iris), type='double') rownames(x) <- as.character(1:nrow(x)) head(x) write.big.matrix(x, file.path(temp_dir, 'IrisData.txt'), col.names=TRUE, row.names=TRUE) y <- read.big.matrix(file.path(temp_dir, "IrisData.txt"), header=TRUE, has.row.names=TRUE) head(y) # The following would fail with a dimension mismatch: if (FALSE) y <- read.big.matrix(file.path(temp_dir, "IrisData.txt"), header=TRUE) } \seealso{ \code{\link{big.matrix}} } \author{ John W. Emerson and Michael J. Kane \email{} } \keyword{methods} bigmemory/man/morder.Rd0000644000175100001440000000606413577164364014642 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \name{morder} \alias{morder} \alias{morderCols} \alias{mpermute} \alias{mpermuteCols} \title{Ordering and Permuting functions for \verb{big.matrix'' and }matrix'' objects} \usage{ morder(x, cols, na.last = TRUE, decreasing = FALSE) morderCols(x, rows, na.last = TRUE, decreasing = FALSE) mpermute(x, order = NULL, cols = NULL, allow.duplicates = FALSE, ...) mpermuteCols(x, order = NULL, rows = NULL, allow.duplicates = FALSE, ...) } \arguments{ \item{x}{A \code{big.matrix} or \code{matrix} object with numeric values.} \item{cols}{The columns of \code{x} to get the ordering for or reorder on} \item{na.last}{for controlling the treatment of \code{NA}s. If \code{TRUE}, missing values in the data are put last; if \code{FALSE}, they are put first; if \code{NA}, they are removed.} \item{decreasing}{logical. Should the sort order be increasing or decreasing?} \item{rows}{The rows of \code{x} to get the ordering for or reorder on} \item{order}{A vector specifying the reordering of rows, i.e. the result of a call to \code{order} or \code{morder}.} \item{allow.duplicates}{ff \code{TRUE}, allows a row to be duplicated in the resulting \code{big.matrix} or \code{matrix} (i.e. in this case, \code{order} would not need to be a permutation of \code{1:nrow(x)}).} \item{...}{optional parameters to pass to \code{morder} when \code{cols} is specified instead of just using \code{order}.} } \value{ \code{morder} returns an ordering vector. \code{mpermute} returns nothing but does change the contents of \code{x}. This type of a side-effect is generally frowned upon in \R, but we ``break'' the rules here to avoid memory overhead and improve performance. } \description{ The \code{morder} function returns a permutation of row indices which can be used to rearrange an object according to the values in the specified columns (a multi-column ordering). The \code{mpermute} function actually reorders the rows of a \code{big.matrix} or \code{matrix} based on an order vector or a desired ordering on a set of columns. } \details{ The \code{morder} function behaves similar to \code{order}, returning a permutation of \code{1:nrow(x)} which rearranges objects according to the values in the specified columns. However, \code{morder} takes a \code{big.matrix} or an \R \code{matrix} (with numeric type) and a set of columns (\code{cols}) with which to determine the ordering; \code{morder} does not incur the same memory overhead required by \code{order}, and runs more quickly. The \code{mpermute} function changes the row ordering of a \code{big.matrix} or \code{matrix} based on a vector \code{order} or an ordering based on a set of columns specified by \code{cols}. It should be noted that this function has side-effects, that is \code{x} is changed when this function is called. } \examples{ m = matrix(as.double(as.matrix(iris)), nrow=nrow(iris)) morder(m, 1) order(m[,1]) m[order(m[,1]), 2] mpermute(m, cols=1) m[,2] } \seealso{ \code{\link{order}} } \author{ Michael J. Kane \email{} } bigmemory/man/length-big.matrix-method.Rd0000644000175100001440000000053413577164364020147 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \name{length,big.matrix-method} \alias{length,big.matrix-method} \title{Length of a big.matrix object} \usage{ \S4method{length}{big.matrix}(x) } \arguments{ \item{x}{A \code{big.matrix} object} } \description{ Get the length of a \code{big.matrix} object } bigmemory/man/big.matrix.Rd0000644000175100001440000002313013577164364015407 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \name{big.matrix} \alias{big.matrix} \alias{filebacked.big.matrix} \alias{as.big.matrix} \alias{is.big.matrix} \alias{is.big.matrix,big.matrix-method} \alias{is.big.matrix,ANY-method} \alias{is.separated} \alias{is.separated,big.matrix-method} \alias{is.filebacked} \alias{is.filebacked,big.matrix-method} \alias{shared.name} \alias{shared.name,big.matrix-method} \alias{file.name} \alias{file.name,big.matrix-method} \alias{dir.name} \alias{dir.name,big.matrix-method} \alias{is.shared} \alias{is.shared,big.matrix-method} \alias{is.readonly} \alias{is.readonly,big.matrix-method} \alias{is.nil} \title{The core "big.matrix" operations.} \usage{ big.matrix( nrow, ncol, type = options()$bigmemory.default.type, init = NULL, dimnames = NULL, separated = FALSE, backingfile = NULL, backingpath = NULL, descriptorfile = NULL, binarydescriptor = FALSE, shared = options()$bigmemory.default.shared ) filebacked.big.matrix( nrow, ncol, type = options()$bigmemory.default.type, init = NULL, dimnames = NULL, separated = FALSE, backingfile = NULL, backingpath = NULL, descriptorfile = NULL, binarydescriptor = FALSE ) as.big.matrix( x, type = NULL, separated = FALSE, backingfile = NULL, backingpath = NULL, descriptorfile = NULL, binarydescriptor = FALSE, shared = options()$bigmemory.default.shared ) is.big.matrix(x) \S4method{is.big.matrix}{big.matrix}(x) \S4method{is.big.matrix}{ANY}(x) is.separated(x) \S4method{is.separated}{big.matrix}(x) is.filebacked(x) \S4method{is.filebacked}{big.matrix}(x) shared.name(x) \S4method{shared.name}{big.matrix}(x) file.name(x) \S4method{file.name}{big.matrix}(x) dir.name(x) \S4method{dir.name}{big.matrix}(x) is.shared(x) \S4method{is.shared}{big.matrix}(x) is.readonly(x) \S4method{is.readonly}{big.matrix}(x) is.nil(address) } \arguments{ \item{nrow}{number of rows.} \item{ncol}{number of columns.} \item{type}{the type of the atomic element (\code{options()$bigmemory.default.type} by default -- \code{"double"} -- but can be changed by the user to \code{"integer"}, \code{"short"}, or \code{"char"}).} \item{init}{a scalar value for initializing the matrix (\code{NULL} by default to avoid unnecessary time spent doing the initializing).} \item{dimnames}{a list of the row and column names; use with caution for large objects.} \item{separated}{use separated column organization of the data; see details.} \item{backingfile}{the root name for the file(s) for the cache of \code{x}.} \item{backingpath}{the path to the directory containing the file backing cache.} \item{descriptorfile}{the name of the file to hold the backingfile description, for subsequent use with \code{\link{attach.big.matrix}}; if \code{NULL}, the \code{backingfile} is used as the root part of the descriptor file name. The descriptor file is placed in the same directory as the backing files.} \item{binarydescriptor}{the flag to specify if the binary RDS format should be used for the backingfile description, for subsequent use with \code{\link{attach.big.matrix}}; if \code{NULL} of \code{FALSE}, the \code{dput()} file format is used.} \item{shared}{\code{TRUE} by default, and always \code{TRUE} if the \code{big.matrix} is file-backed. For a non-filebacked \code{big.matrix}, \code{shared=FALSE} uses non-shared memory, which can be more stable for large (say, >50\% of RAM) objects. Shared memory allocation can sometimes fail in such cases due to exhausted shared-memory resources in the system.} \item{x}{a \code{matrix}, \code{vector}, or \code{data.frame} for \code{as.big.matrix}; if a vector, a one-column\cr \code{big.matrix} is created by \code{as.big.matrix}; if a \code{data.frame}, see details. For the \code{is.*} functions, \code{x} is likely a \code{big.matrix}.} \item{address}{an \code{externalptr}, so \code{is.nil(x@address)} might be a sensible thing to want to check, but it's pretty obscure.} } \value{ A \code{big.matrix} is returned (for \code{big.matrix} and \code{filebacked.big.matrix}, and\cr \code{as.big.matrix}), and \code{TRUE} or \code{FALSE} for \code{is.big.matrix} and the other functions. } \description{ Create a \code{big.matrix} (or check to see if an object is a \code{big.matrix}, or create a \code{big.matrix} from a \code{\link{matrix}}, and so on). The \code{big.matrix} may be file-backed. } \details{ A \code{big.matrix} consists of an object in \R that does nothing more than point to the data structure implemented in \acronym{C++}. The object acts much like a traditional \R matrix, but helps protect the user from many inadvertent memory-consuming pitfalls of traditional \R matrices and data frames. There are two \code{big.matrix} types which manage data in different ways. A standard, shared \code{big.matrix} is constrained to available \acronym{RAM}, and may be shared across separate \R processes. A file-backed \code{big.matrix} may exceed available \acronym{RAM} by using hard drive space, and may also be shared across processes. The atomic types of these matrices may be \code{double}, \code{integer}, \code{short}, or \code{char} (8, 4, 2, and 1 bytes, respectively). If \code{x} is a \code{big.matrix}, then \code{x[1:5,]} is returned as an R \code{matrix} containing the first five rows of \code{x}. If \code{x} is of type \code{double}, then the result will be \code{numeric}; otherwise, the result will be an \code{integer} \R matrix. The expression \code{x} alone will display information about the \R object (e.g. the external pointer) rather than evaluating the matrix itself (the user should try \code{x[,]} with extreme caution, recognizing that a huge \R \code{matrix} will be created). If \code{x} has a huge number of rows and/or columns, then the use of \code{rownames} and/or \code{colnames} will be extremely memory-intensive and should be avoided. If \code{x} has a huge number of columns and \code{separated=TRUE} is used (this isn't typically recommended), the user might want to store the transpose as there is overhead of a pointer for each column in the matrix. If \code{separated} is \code{TRUE}, then the memory is allocated into separate vectors for each column. Use this option with caution if you have a large number of columns, as shared-memory segments are limited by OS and hardware combinations. If \code{separated} is \code{FALSE}, the matrix is stored in traditional column-major format. The function \code{is.separated()} returns the separation type of the \code{big.matrix}. When a \code{big.matrix}, \code{x}, is passed as an argument to a function, it is essentially providing call-by-reference rather than call-by-value behavior. If the function modifies any of the values of \code{x}, the changes are not limited in scope to a local copy within the function. This introduces the possibility of side-effects, in contrast to standard \R behavior. A file-backed \code{big.matrix} may exceed available \acronym{RAM} in size by using a file cache (or possibly multiple file caches, if \code{separated=TRUE}). This can incur a substantial performance penalty for such large matrices, but less of a penalty than most other approaches for handling such large objects. A side-effect of creating a file-backed object is not only the file-backing(s), but a descriptor file (in the same directory) that is needed for subsequent attachments (see \code{\link{attach.big.matrix}}). Note that we do not allow setting or changing the \code{dimnames} attributes by default; such changes would not be reflected in the descriptor objects or in shared memory. To override this, set \code{options(bigmemory.allow.dimnames=TRUE)}. It should also be noted that a user can create an ``anonymous'' file-backed \code{big.matrix} by specifying "" as the \code{filebacking} argument. In this case, the backing resides in the temporary directory and a descriptor file is not created. These should be used with caution since even anonymous backings use disk space which could eventually fill the hard drive. Anonymous backings are removed either manually, by a user, or automatically, when the operating system deems it appropriate. Finally, note that \code{as.big.matrix} can coerce data frames. It does this by making any character columns into factors, and then making all factors numeric before forming the \code{big.matrix}. Level labels are not preserved and must be managed by the user if desired. } \examples{ library(bigmemory) x <- big.matrix(10, 2, type='integer', init=-5) options(bigmemory.allow.dimnames=TRUE) colnames(x) <- c("alpha", "beta") is.big.matrix(x) dim(x) colnames(x) rownames(x) x[,] x[1:8,1] <- 11:18 colnames(x) <- NULL x[,] # The following shared memory example is quite silly, as you wouldn't # likely do this in a single R session. But if zdescription were # passed to another R session via SNOW, foreach, or even by a # simple file read/write, then the attach.big.matrix() within the # second R process would give access to the same object in memory. # Please see the package vignette for real examples. z <- big.matrix(3, 3, type='integer', init=3) z[,] dim(z) z[1,1] <- 2 z[,] zdescription <- describe(z) zdescription y <- attach.big.matrix(zdescription) y[,] y z y[1,1] <- -100 y[,] z[,] } \references{ The Bigmemory Project: \url{http://www.bigmemory.org/}. } \seealso{ \code{\link{bigmemory}}, and perhaps the class documentation of \code{\linkS4class{big.matrix}}; \code{\link{attach.big.matrix}} and \code{\link{describe}}. Sister packages \pkg{biganalytics}, \pkg{bigtabulate}, \pkg{synchronicity}, and \pkg{bigalgebra} provide advanced functionality. } \author{ John W. Emerson and Michael J. Kane \email{} } \keyword{classes} \keyword{methods} bigmemory/man/dimnames-methods.Rd0000644000175100001440000000077713576750523016612 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \docType{methods} \name{dimnames,big.matrix-method} \alias{dimnames,big.matrix-method} \alias{dimnames<-,big.matrix,list-method} \title{Dimnames of a big.matrix Object} \usage{ \S4method{dimnames}{big.matrix}(x) \S4method{dimnames}{big.matrix,list}(x) <- value } \arguments{ \item{x}{A big.matrix object} \item{value}{A possible value for \code{dimnames(x)}} } \description{ Retrieve or set the dimnames of an object } bigmemory/man/mwhich-methods.Rd0000644000175100001440000000227213577164364016267 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \docType{methods} \name{mwhich-methods} \alias{mwhich-methods} \alias{mwhich,big.matrix,ANY,ANY,ANY,character-method} \alias{mwhich,big.matrix,ANY,ANY,ANY,missing-method} \alias{mwhich,matrix,ANY,ANY,ANY,character-method} \alias{mwhich,matrix,ANY,ANY,ANY,missing-method} \title{Expanded ``which''-like functionality.} \description{ Implements \code{\link{which}}-like functionality for a \code{\link{big.matrix}}, with additional options for efficient comparisons (executed in \acronym{C++}); also works for regular numeric matrices without the memory overhead. test } \section{Methods}{ \describe{ \item{signature(x = "big.matrix=", cols = "ANY", vals = "ANY",", " comps = "ANY", op = "character")}{ ... } \item{signature(x = "big.matrix", cols = "ANY", vals = "ANY",", " comps = "ANY", op = "missing")}{ ... } \item{signature(x = "matrix", cols = "ANY", vals = "ANY",", " comps = "ANY", op = "character")}{ ... } \item{signature(x = "matrix", cols = "ANY", vals = "ANY",", " comps = "ANY", op = "missing")}{ ... } } } \seealso{ \code{\link{big.matrix}}, \code{\link{which}}, \code{\link{mwhich}} } \keyword{methods} bigmemory/man/dim-big.matrix-method.Rd0000644000175100001440000000054013577164364017434 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \name{dim,big.matrix-method} \alias{dim,big.matrix-method} \title{Dimensions of a big.matrix object} \usage{ \S4method{dim}{big.matrix}(x) } \arguments{ \item{x}{A \code{big.matrix} object} } \description{ Retrieve the dimensions of a \code{big.matrix} object } bigmemory/man/typeof-big.matrix-method.Rd0000644000175100001440000000056613577164364020201 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \name{typeof,big.matrix-method} \alias{typeof,big.matrix-method} \title{The Type of a big.matrix Object} \usage{ \S4method{typeof}{big.matrix}(x) } \arguments{ \item{x}{A \code{big.matrix} object} } \description{ \code{typeof} returns the storage type of a \code{big.matrix} object } bigmemory/man/flush-methods.Rd0000644000175100001440000000227313577164364016132 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \docType{methods} \name{flush} \alias{flush} \alias{flush,big.matrix-method} \title{Updating a big.matrix filebacking.} \usage{ flush(con) \S4method{flush}{big.matrix}(con) } \arguments{ \item{con}{filebacked \code{\link{big.matrix}}.} } \value{ \code{TRUE} or \code{FALSE} (invisible), indicating whether or not the flush was successful. } \description{ For a file-backed \code{big.matrix} object, \code{flush()} forces any modified information to be written to the file-backing. } \details{ This function flushes any modified data (in \acronym{RAM}) of a file-backed \code{big.matrix} to disk. This may be useful for improving performance in cases where allowing the operating system to decide on flushing creates a bottleneck (likely near the threshold of available \acronym{RAM}). } \examples{ temp_dir = tempdir() if (!dir.exists(temp_dir)) dir.create(temp_dir) x <- big.matrix(nrow=3, ncol=3, backingfile='flushtest.bin', descriptorfile='flushtest.desc', backingpath=temp_dir, type='integer') x[1,1] <- 0 flush(x) } \author{ John W. Emerson and Michael J. Kane } \keyword{methods} bigmemory/man/as.big.matrix-methods.Rd0000644000175100001440000000156713577164364017464 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \docType{methods} \name{as.big.matrix-methods} \alias{as.big.matrix-methods} \alias{as.big.matrix,matrix-method} \alias{as.big.matrix,vector-method} \alias{as.big.matrix,data.frame-method} \title{Create a ``big.matrix'' from a matrix or vector.} \description{ Create a \code{\link{big.matrix}} from a \code{matrix} or \code{vector} or \code{\link{data.frame}}; a \code{vector} will result in a \code{\link{big.matrix}} with one column. A data frame will have character vectors converted to factors, and then all factors converted to numeric factor levels. All labels or character values will be lost. } \section{Methods}{ \describe{ \item{\code{signature(x = "matrix")}}{ ... } \item{\code{signature(x = "vector")}}{ ... } \item{\code{signature(x = "data.frame")}}{ ... } } } \keyword{methods} bigmemory/man/is.float-numeric-method.Rd0000644000175100001440000000046513577164364020006 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \name{is.float,numeric-method} \alias{is.float,numeric-method} \title{Is Float?} \usage{ \S4method{is.float}{numeric}(x) } \arguments{ \item{x}{A numeric value} } \description{ Check if R numeric value has float flag } bigmemory/man/head-methods.Rd0000644000175100001440000000102013576750523015674 0ustar hornikusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bigmemory.R \docType{methods} \name{head,big.matrix-method} \alias{head,big.matrix-method} \alias{tail,big.matrix-method} \title{Return First or Last Part of a big.matrix Object} \usage{ \S4method{head}{big.matrix}(x, n = 6) \S4method{tail}{big.matrix}(x, n = 6) } \arguments{ \item{x}{A big.matrix object} \item{n}{A single integer for the number of rows to return} } \description{ Returns the first or last parts of a \code{big.matrix} object. } bigmemory/DESCRIPTION0000644000175100001440000000216113600200214013754 0ustar hornikusersPackage: bigmemory Version: 4.5.36 Title: Manage Massive Matrices with Shared Memory and Memory-Mapped Files Author: Michael J. Kane , John W. Emerson , Peter Haverty , and Charles Determan Jr. Maintainer: Michael J. Kane Contact: Mike, Jay, and Charles Depends: R (>= 3.2.0), Imports: methods, Rcpp, utils, bigmemory.sri Enhances: biganalytics, bigtabulate LinkingTo: BH, Rcpp Description: Create, store, access, and manipulate massive matrices. Matrices are allocated to shared memory and may use memory-mapped files. Packages 'biganalytics', 'bigtabulate', 'synchronicity', and 'bigalgebra' provide advanced functionality. License: LGPL-3 | Apache License 2.0 URL: https://github.com/kaneplusplus/bigmemory BugReports: https://github.com/kaneplusplus/bigmemory/issues LazyLoad: yes Biarch: yes Suggests: testthat RoxygenNote: 7.0.2 NeedsCompilation: yes Packaged: 2019-12-23 00:36:34 UTC; mike Repository: CRAN Date/Publication: 2019-12-23 17:59:40 UTC bigmemory/tests/0000755000175100001440000000000013576750523013441 5ustar hornikusersbigmemory/tests/testthat/0000755000175100001440000000000013600200214015250 5ustar hornikusersbigmemory/tests/testthat/test_read.R0000644000175100001440000001002013576750523017367 0ustar hornikuserslibrary("bigmemory") context("read") test_that("test_read", { mat = matrix(1:9, ncol = 3, nrow = 3, dimnames = list(letters[1:3], LETTERS[1:3])) retList = list(mat, rownames(mat), colnames(mat)) matnull = matrix(1:9, ncol = 3, nrow = 3) retListNull = list(mat, NULL, NULL) bm = as.big.matrix(mat) bmnull = as.big.matrix(matnull) expect_identical(bm[2, 2], mat[2, 2], info = "scalar with names") expect_identical(bmnull[2, 2], matnull[2, 2], info = "scalar without names") expect_identical(bm[2, ], mat[2, ], info = "row with names") expect_identical(bmnull[2, ], matnull[2, ], info = "row without names") expect_identical(bm[, 2], mat[, 2], info = "column with names") expect_identical(bmnull[, 2], matnull[, 2], info = "column without names") expect_identical(bm[2, 2, drop = FALSE], mat[2, 2, drop = FALSE], info = "drop is FALSE scalar with names") expect_identical(bmnull[2, 2, drop = FALSE], matnull[2, 2, drop = FALSE], info = "drop is FALSE scalar without names") expect_identical(bm[2, , drop = FALSE], mat[2, , drop = FALSE], info = "drop is FALSE row with names") expect_identical(bmnull[2, , drop = FALSE], matnull[2, , drop = FALSE], info = "drop is FALSE row without names") expect_identical(bm[, 2, drop = FALSE], mat[, 2, drop = FALSE], info = "drop is FALSE column with names") expect_identical(bmnull[, 2, drop = FALSE], matnull[, 2, drop = FALSE], info = "drop is FALSE column without names") expect_identical(bm[1:2, 2:3], mat[1:2, 2:3], info = "partial matrix with names") expect_identical(bmnull[1:2, 2:3], matnull[1:2, 2:3], info = "partial matrix without names") expect_identical(bm[, ], mat[, ], info = "full matrix with names") expect_identical(bmnull[, ], matnull[, ], info = "full matrix without names") expect_identical(bm[2:5], mat[2:5], info = "continous element specific access") expect_identical(bm[c(2,4,5)], mat[c(2,4,5)], info = "non-continous element specific access") mat.list = list(mat[2, , drop = FALSE], mat[, 2, drop = FALSE]) for (mat in mat.list) { matnull = unname(mat) bm = as.big.matrix(mat) bmnull = as.big.matrix(matnull) expect_identical(bm[1, 1], mat[1, 1], info = "scalar with names") expect_identical(bmnull[1, 1], matnull[1, 1], info = "scalar without names") expect_identical(bm[1, ], mat[1, ], info = "row with names") expect_identical(bmnull[1, ], matnull[1, ], info = "row without names") expect_identical(bm[, 1], mat[, 1], info = "column with names") expect_identical(bmnull[, 1], matnull[, 1], info = "column without names") expect_identical(bm[1, 1, drop = FALSE], mat[1, 1, drop = FALSE], info = "drop is FALSE scalar with names") expect_identical(bmnull[1, 1, drop = FALSE], matnull[1, 1, drop = FALSE], info = "drop is FALSE scalar without names") expect_identical(bm[1, , drop = FALSE], mat[1, , drop = FALSE], info = "drop is FALSE row with names") expect_identical(bmnull[1, , drop = FALSE], matnull[1, , drop = FALSE], info = "drop is FALSE row without names") expect_identical(bm[, 1, drop = FALSE], mat[, 1, drop = FALSE], info = "drop is FALSE column with names") expect_identical(bmnull[, 1, drop = FALSE], matnull[, 1, drop = FALSE], info = "drop is FALSE column without names") expect_identical(bm[, ], mat[, ], info = "full matrix with names") expect_identical(bmnull[, ], matnull[, ], info = "full matrix without names") } }) bigmemory/tests/testthat/test_assignment.R0000644000175100001440000001013313576750523020631 0ustar hornikuserslibrary("bigmemory") context("big.matrix assignment") set.seed(123) z <- filebacked.big.matrix(3, 3, type='double', init=123.0, backingfile="example.bin", descriptorfile="example.desc", dimnames=list(c('a','b','c'), c('d', 'e', 'f'))) mat <- matrix(1:9, ncol = 3, nrow = 3, dimnames = list(letters[1:3], LETTERS[1:3])) bm <- as.big.matrix(mat, type = "double") z[] <- mat test_that("Able to assign individual elements", { tmp <- bm[] # element assign bm[1,3] <- 15.123 z[1,3] <- 15.123 mat[1,3] <- 15.123 expect_equivalent(bm[1,3], 15.123) expect_equivalent(z[1,3], 15.123) bm[] <- tmp z[] <- tmp }) test_that("Able to assign non-contiguous individual elements", { tmp <- bm[] # element assign bm[c(1,3,5)] <- 15.123 z[c(1,3,5)] <- 15.123 mat[c(1,3,5)] <- 15.123 expect_equivalent(bm[], mat) expect_equivalent(z[], mat) bm[] <- tmp z[] <- tmp }) test_that("Able to assign rowwise elements", { row <- rnorm(3) tmp <- bm[] # row assign bm[2,] <- row z[2,] <- row mat[2,] <- row expect_equivalent(bm[], mat) expect_equivalent(z[], mat) bm[] <- tmp z[] <- tmp }) test_that("Able to assign columnwise elements", { col <- rnorm(3) tmp <- bm[] # column assign bm[,3] <- col z[,3] <- col mat[,3] <- col expect_equivalent(bm[], mat) expect_equivalent(z[], mat) bm[] <- tmp z[] <- tmp }) test_that("Able to assign non-contiguous columns", { tmp <- bm[] # column assign bm[,c(1,3)] <- mat[,c(1,3)] z[,c(1,3)] <- mat[,c(1,3)] mat[,c(1,3)] <- mat[,c(1,3)] expect_equivalent(bm[], mat) expect_equivalent(z[], mat) bm[] <- tmp z[] <- tmp }) test_that("Able to assign matrix to rows", { tmp <- bm[] newmat <- matrix(1:6, 2, 3) bm[1:2,] <- newmat[1:2,] z[1:2,] <- newmat[1:2,] mat[1:2,] <- newmat[1:2,] expect_equivalent(bm[], mat) expect_equivalent(z[], mat) bm[] <- tmp z[] <- tmp mat <- tmp }) test_that("Able to assign row-wise using logical vectors", { tmp <- bm[] bm[c(TRUE,FALSE,TRUE),] <- 123 z[c(TRUE,FALSE,TRUE),] <- 123 mat[c(TRUE,FALSE,TRUE),] <- 123 expect_equivalent (bm[], mat) expect_equivalent (z[], mat) bm[] <- tmp z[] <- tmp mat <- tmp }) test_that("Able to assign column-wise using logical vectors", { tmp <- bm[] bm[,c(TRUE,FALSE,TRUE)] <- 123 z[,c(TRUE,FALSE,TRUE)] <- 123 mat[,c(TRUE,FALSE,TRUE)] <- 123 expect_equivalent (bm[], mat) expect_equivalent (z[], mat) bm[] <- tmp z[] <- tmp mat <- tmp }) test_that("Able to assign logical vectors for column and vector indices", { tmp <- bm[] bm[c(TRUE,FALSE,FALSE),c(TRUE,FALSE,TRUE)] <- 123 z[c(TRUE,FALSE,FALSE),c(TRUE,FALSE,TRUE)] <- 123 mat[c(TRUE,FALSE,FALSE),c(TRUE,FALSE,TRUE)] <- 123 expect_equivalent (bm[], mat) expect_equivalent (z[], mat) bm[] <- tmp z[] <- tmp mat <- tmp }) test_that("Able to assign row-wise using logical vectors and numeric", { tmp <- bm[] bm[c(TRUE,FALSE,TRUE),1:2] <- 123 z[c(TRUE,FALSE,TRUE),1:2] <- 123 mat[c(TRUE,FALSE,TRUE),1:2] <- 123 expect_equivalent (bm[], mat) expect_equivalent (z[], mat) bm[] <- tmp z[] <- tmp mat <- tmp }) test_that("Able to assign column-wise using logical vectors and numeric", { tmp <- bm[] bm[1:2,c(TRUE,FALSE,TRUE)] <- 123 z[1:2,c(TRUE,FALSE,TRUE)] <- 123 mat[1:2,c(TRUE,FALSE,TRUE)] <- 123 expect_equivalent (bm[], mat) expect_equivalent (z[], mat) bm[] <- tmp z[] <- tmp mat <- tmp }) test_that("Able to assign based on row names and column names", { z[c('a', 'b'), c('d', 'e')] <- 1 }) test_that("Able to assign based on row names", { z[c('a', 'b'),] <- 1 }) test_that("Able to assign based on column names", { z[, c('d', 'e')] <- 1 }) test_that("Able to assign based on logical rows and column names", { z[c(TRUE, TRUE, FALSE), c('d', 'e')] <- 1 }) test_that("Able to assign based on integer rows and column names", { z[2:3, c('d', 'e')] <- 1 }) rm(z) gc() file.remove('example.bin') file.remove('example.desc') bigmemory/tests/testthat/test_matrix_manips.R0000644000175100001440000000425713576750523021346 0ustar hornikuserslibrary("bigmemory") context("Matrix Manipulations") test_that("assignment across columns", { N <- 1000 K <- 26 x <- big.matrix(N, K, type="char") # Some interesting points, here... options(bigmemory.typecast.warning=FALSE) options(bigmemory.allow.dimnames=TRUE) # The do some basic things with the natural R syntax: x[1:2, 1:2] <- 1:4 # Simple assignment rm(x) }) z <- filebacked.big.matrix(3, 3, type='integer', init=123, backingfile="example.bin", descriptorfile="example.desc", dimnames=list(c('a','b','c'), c('d', 'e', 'f'))) mat <- matrix(1:9, ncol = 3, nrow = 3, dimnames = list(letters[1:3], LETTERS[1:3])) bm <- as.big.matrix(mat) df <- as.data.frame(mat) l <- as.list(seq(3)) vec <- seq(3) test_that("warnings returned", { expect_warning( as.big.matrix(vec), regexp="*Coercing vector to a single-column matrix.") expect_warning( as.big.matrix(df), regexp="*Coercing data.frame to matrix via factor level numberings.") }) test_that("is.big.matrix recognizes objects correctly", { expect_true(is.big.matrix(bm)) expect_false(is.big.matrix(mat), info="matrix interpreted as big.matrix") expect_false(is.big.matrix("hello"), info="character interpreted as big.matrix") expect_false(is.big.matrix(l), info="list interpreted as list") }) test_that("as.big.matrix converts types correctly",{ expect_is(as.big.matrix(mat), "big.matrix") expect_is(suppressWarnings(as.big.matrix(vec)), "big.matrix") expect_is(suppressWarnings(as.big.matrix(df)), "big.matrix") expect_equivalent(as.big.matrix(mat)[,], mat) expect_equivalent(suppressWarnings(as.big.matrix(vec))[,], vec) expect_true(all(suppressWarnings(as.big.matrix(df))[,] == df)) }) test_that("flush works correctly",{ expect_true(flush(z)) if (Sys.info()['sysname'] != "Darwin") expect_warning(flush(bm), info="You cannot call flush on a non-filebacked big.matrix") }) rm(z) gc() file.remove('example.bin') file.remove('example.desc') bigmemory/tests/testthat/test_readonly.R0000644000175100001440000001126713576750523020307 0ustar hornikuserslibrary("bigmemory") context("read_only") rownames = letters[1:3] colnames = LETTERS[1:3] back.dir = tempdir() fbm.file = "fbm" fbm.desc.file = "fbm.desc" fbm.desc.path = file.path(back.dir,fbm.desc.file) fbm.data.path = file.path(back.dir,fbm.file) # fbm = filebacked.big.matrix(3,3,dimnames=list(rownames,colnames),backingpath=back.dir, backingfile=fbm.file, descriptorfile=paste(fbm.file,".desc",sep="")) # fbm[,] = 1:9 bm = big.matrix(3,3,dimnames=list(rownames,colnames)) test_that("test_readonly", { mat = matrix(1:9, ncol = 3, dimnames = list(rownames, colnames)) bm = big.matrix(3, 3, dimnames = list(rownames, colnames)) bm[, ] = mat bm2 = attach.big.matrix(describe(bm), readonly = TRUE, shared=FALSE) bm3 = attach.big.matrix(describe(bm), readonly = FALSE, shared=FALSE) expect_false(is.readonly(bm), info = "bm should not be readonly") expect_true(is.readonly(bm2), info = "bm2 should be readonly") expect_false(is.readonly(bm3), info = "bm3 should be readonly") expect_equal(mat[2, 2], bm2[2, 2], info = "Read big.matrix attached as read-only is OK") expect_error({ bm2[1, 1] = 100 }, info = "Writing to a big.matrix made read-only by FS before attached gives error") expect_error({ bm2[1, ] = 100 }, info = "Writing row to a big.matrix made read-only by FS before attached gives error") expect_error({ bm2[, 1] = 100 }, info = "Writing column to a big.matrix made read-only by FS before attached gives error") expect_error({ bm2[, ] = 100 }, info = "Writing to full matrix a big.matrix made read-only by FS before attached gives error") expect_error({ bm2[matrix(c(1, 2, 2, 2), ncol = 2), ] = 100 }, info = "Writing subset by matrix to a big.matrix made read-only by FS before attached gives error") # in order to reuse, must remove prior objects # rm(fbm) # gc() # file.remove(file.path(back.dir, fbm.file)) # file.remove(file.path(back.dir, fbm.desc.file)) if (file.exists(file.path(back.dir, fbm.file))) { unlink(c(file.path(back.dir, fbm.file), file.path(back.dir, fbm.desc.file))) } fbm = filebacked.big.matrix(3, 3, dimnames=list(rownames, colnames), backingpath=back.dir, backingfile=fbm.file, descriptorfile=fbm.desc.file) fbm[, ] = mat[, ] = 1:9 fbm2 = attach.big.matrix(describe(fbm), path = back.dir, readonly = TRUE) fbm3 = attach.big.matrix(describe(fbm), path = back.dir, readonly = FALSE) expect_false(is.readonly(fbm), info = "fbm should not be readonly") expect_true(is.readonly(fbm2), info = "fbm2 should be readonly") expect_false(is.readonly(fbm3), info = "fbm3 should not be readonly") Sys.chmod(fbm.data.path, "0444") expect_warning(attach.big.matrix(fbm.desc.path, readonly = FALSE), info = "big.matrix object could only be opened read-only.") expect_true(suppressWarnings( is.readonly(attach.big.matrix(fbm.desc.path, readonly = FALSE))), info = "FBM should be readonly if readonly on FS, even if requested read/write") Sys.chmod(fbm.data.path, "0644") expect_true(is.readonly(attach.big.matrix(fbm.desc.path, readonly = TRUE)), info = "FBM should not be readonly if you ask for that.") expect_equal(mat[2, 2], fbm2[2, 2], info = "Read big.matrix attached as read-only is OK") expect_error({ fbm2[1, 1] = 100 }, info = "Writing to a big.matrix made read-only by FS before attached gives error") expect_error({ fbm2[1, ] = 100 }, info = "Writing row to a big.matrix made read-only by FS before attached gives error") expect_error({ fbm2[, 1] = 100 }, info = "Writing column to a big.matrix made read-only by FS before attached gives error") expect_error({ fbm2[, ] = 100 }, info = "Writing to full matrix a big.matrix made read-only by FS before attached gives error") expect_error({ fbm2[matrix(c(1, 2, 2, 2), ncol = 2), ] = 100 }, info = "Writing subset by matrix to a big.matrix made read-only by FS before attached gives error") expect_equal(mat[, ], fbm2[, ], info = "Writing to a big.matrix made read-only by FS before attached does nothing") expect_error({ fbm3 = attach.big.matrix(fbm.desc.path, readonly = TRUE) fbm3[1, 1] = 100 }, info = "Should give error if you ask for a readonly matrix and try to write to it.") return(TRUE) rm(fbm, fbm2, fbm3) gc() file.remove(file.path(back.dir, fbm.file)) file.remove(file.path(back.dir, fbm.desc.file)) }) bigmemory/tests/testthat/test_morder.R0000644000175100001440000000202213576750523017747 0ustar hornikuserslibrary("bigmemory") context("morder/mpermute") data(iris,package='datasets') m = matrix(as.double(as.matrix(iris[,1:4])), nrow=nrow(iris[,1:4])) n = m mm <- m[1:4,1:4] colnames(mm) <- letters[1:4] bm <- as.big.matrix(mm) test_that("morder equivalent to order",{ expect_identical(morder(m, 1), as.numeric(order(m[,1]))) }) test_that("mpermute changes elements order",{ expect_false(all(m == mpermute(m, cols=1))) expect_true(all(n == m[morder(m,1),])) }) test_that("column reording works", { mpermuteCols(bm, order = c(3,4,1,2)) expect_equivalent(bm[], mm[,c('c','d','a','b')]) expect_equivalent(colnames(bm), c('c','d','a','b')) mpermuteCols(mm, order = c(3,4,1,2)) expect_equivalent(colnames(mm), c('c','d','a','b')) expect_equivalent(bm[], mm) mpermuteCols(bm, rows = 1) mpermuteCols(mm, rows = 1) expect_equivalent(bm[], mm) }) test_that("morderCols works",{ expect_true(all(order(mm[1,]) == morderCols(bm, rows = 1))) expect_true(all(order(mm[2,]) == morderCols(mm, rows = 2))) }) rm(bm) gc() bigmemory/tests/testthat/test_deepcopy.R0000644000175100001440000000126313576750523020275 0ustar hornikuserslibrary("bigmemory") context("deepcopy") mat <- matrix(1:9, ncol = 3, nrow = 3, dimnames = list(letters[1:3], LETTERS[1:3])) bm <- as.big.matrix(mat) dm <- deepcopy(bm) dbbm <- deepcopy(bm, type="double") test_that("addresses are not the same", { expect_false(identical(dm@address ,bm@address)) }) test_that("contents equivalent",{ expect_equivalent(bm[,], dm[,]) }) test_that("type is correctly set",{ expect_true(typeof(bm) == typeof(dm)) expect_true(typeof(bm) != typeof(dbbm)) expect_true(typeof(dbbm) == "double") }) test_that("sharing type is correct",{ expect_true(is.shared(bm) && is.shared(dm)) }) bigmemory/tests/testthat/test_create.R0000644000175100001440000000324113576750523017726 0ustar hornikuserslibrary("bigmemory") context("big.matrix creation") z <- filebacked.big.matrix(3, 3, type='integer', init=123, backingfile="example.bin", descriptorfile="example.desc", dimnames=list(c('a','b','c'), c('d', 'e', 'f'))) mat <- matrix(1:9, ncol = 3, nrow = 3, dimnames = list(letters[1:3], LETTERS[1:3])) bm <- as.big.matrix(mat) test_that("filebacked matrix created successfully",{ expect_true(file.exists("example.bin")) expect_true(file.exists("example.desc")) expect_true(all(z[,] == 123)) }) test_that("describe returns correct data", { desc <- describe(bm) expect_is(desc, "big.matrix.descriptor") expect_true(length(desc@description$rowOffset) == 2) expect_true(length(desc@description$colOffset) == 2) expect_true(typeof(bm) == desc@description$type) }) test_that("attach methods successful",{ zdescription <- describe(z) bmdescription <- describe(bm) expect_is(zdescription, "big.matrix.descriptor") expect_is(bmdescription, "big.matrix.descriptor") y <- attach.big.matrix(zdescription) expect_false(identical(z@address, y@address)) expect_identical(z[,], y[,]) x <- attach.big.matrix(bmdescription) expect_false(identical(z@address, y@address)) expect_identical(bm[,], x[,]) }) test_that("We can prepare for writing a bigmatrix", { expect_warning(bigmemory:::to_int_checked(1.1)) expect_silent(bigmemory:::to_int_checked(1.0)) expect_equal(bigmemory:::to_int_checked(c(1.0,3.0)), c(1L,3L)) }) rm(z) gc() file.remove('example.bin') file.remove('example.desc') bigmemory/tests/testthat/test_mwhich.R0000644000175100001440000000234013576750523017741 0ustar hornikuserslibrary("bigmemory") context("mwhich") # global objects x <- as.big.matrix(matrix(1:30, 10, 3)) options(bigmemory.allow.dimnames=TRUE) colnames(x) <- c("A", "B", "C") x1 <- x[mwhich(x, 1:2, list(c(2,3), c(11,17)), list(c('ge','le'), c('gt', 'lt')), 'OR'),] x2 <- x[mwhich(x, c("A","B"), list(c(2,3), c(11,17)), list(c('ge','le'), c('gt', 'lt')), 'AND'),] y <- matrix(1:30, 10, 3) colnames(y) <- c("A", "B", "C") y1 <- y[mwhich(y, 1:2, list(c(2,3), c(11,17)), list(c('ge','le'), c('gt', 'lt')), 'OR'),] y2 <- y[mwhich(y, -3, list(c(2,3), c(11,17)), list(c('ge','le'), c('gt', 'lt')), 'AND'),] test_that("mwhich indices correct",{ expect_identical(x[2:6,], x1) expect_identical(x[2:3,], x2) }) test_that("mwhich works for regular 'matrix'",{ expect_identical(y1, x1) expect_identical(y2, x2) }) test_that("mwhich recognizes NA", { x[1,1] <- NA expect_identical(mwhich(x, 1:2, NA, 'eq', 'OR'), 1) expect_identical(mwhich(x, 1:2, NA, 'neq', 'AND'), as.numeric(2:10)) }) test_that("mwhich recognizes Inf",{ x <- big.matrix(4, 2, init=1, type="double") x[1,1] <- Inf mwhich(x, 1, Inf, 'eq') mwhich(x, 1, 1, 'gt') mwhich(x, 1, 1, 'le') })bigmemory/tests/testthat/test_float_type.R0000644000175100001440000000350513576750523020634 0ustar hornikuserslibrary("bigmemory") context("big.matrix float type") options(bigmemory.typecast.warning=FALSE) set.seed(123) z <- filebacked.big.matrix(3, 3, type='float', init=123.0, backingfile="example.bin", descriptorfile="example.desc", dimnames=list(c('a','b','c'), c('d', 'e', 'f'))) mat <- matrix(1:9, ncol = 3, nrow = 3, dimnames = list(letters[1:3], LETTERS[1:3])) dmat <- matrix(rnorm(9), ncol = 3, nrow = 3, dimnames = list(letters[1:3], LETTERS[1:3])) fmat <- big.matrix(3,3, type="float", init = 13.123) bm <- as.big.matrix(dmat, type="float") test_that("filebacked matrix created successfully",{ expect_true(file.exists("example.bin")) expect_true(file.exists("example.desc")) expect_true(all(z[,] == 123.0)) expect_true(typeof(z) == "float") }) test_that("RAM matrix created successfully",{ expect_equal(bm[,], dmat, tolerance = 1e-7) expect_true(typeof(bm) == "float") }) test_that("Able to access and assign elements", { fmat[1,3] <- 15.123 expect_equivalent(fmat[1,3], 15.123) newRow <- rnorm(3) fmat[1,] <- newRow expect_equal(fmat[1,], newRow, tolerance = 1e-07) newCol <- rnorm(3) fmat[,1] <- newCol expect_equal(fmat[,1], newCol, tolerance = 1e-07) }) # Float data types are not typical in R # The default warning is a sanity check to realize that # any double (i.e. numeric) values passed are down cast to float options(bigmemory.typecast.warning=TRUE) test_that("Proper warning returned", { expect_warning(as.big.matrix(dmat, type="float"), info="Not warning about float type downcast") }) rm(z) gc() file.remove('example.bin') file.remove('example.desc') bigmemory/tests/testthat/test_raw.R0000644000175100001440000000214613600005751017237 0ustar hornikuserslibrary("bigmemory") context("raw data") m<-big.matrix(10,1,type='raw') f<-big.matrix(10,1,type='raw',backingpath = tempfile(fileext = '.bin')) test_that("Reading and writing byte<128 on memory-backed file",{ m[3,1]<-as.raw(10) expect_equal(m[3,1],as.raw(10)) }) test_that("Reading and writing byte>=128 on memory-backed file",{ m[4,1]<-as.raw(130) expect_equal(m[4,1],as.raw(130)) }) test_that("Reading and writing byte<128 on file-backed file",{ f[5,1]<-as.raw(10) expect_equal(f[5,1],as.raw(10)) }) test_that("Reading and writing byte>=128 on memory-backed file",{ f[6,1]<-as.raw(130) expect_equal(f[6,1],as.raw(130)) }) test_that("Making sure the 'char' matrix behaves like signed byte", { mchar<-big.matrix(3,1,type='char') mchar[1,1]<- 40 mchar[2,1]<- -123 mchar[3,1]<- 190 expect_equal(mchar[1:3,1],c(40,-123,NA)) }) test_that("Testing for as.big.matrix for raw", { x <- matrix(as.raw(seq(0,255, length.out = 16)), 4, 4) expect_equal(typeof(x), 'raw') expect_equal(class(x)[1], 'matrix') m<-as.big.matrix(x, type = "raw") expect_equal(x[1,], as.raw(c(0,68,136,204))) }) bigmemory/tests/testthat/test_misc.R0000644000175100001440000000310213576750523017412 0ustar hornikuserslibrary("bigmemory") context("miscellaneous") z <- filebacked.big.matrix(3, 3, type='integer', init=123, backingfile="example.bin", descriptorfile="example.desc", dimnames=list(c('a','b','c'), c('A', 'B', 'C'))) mat <- matrix(1:9, ncol = 3, nrow = 3, dimnames = list(letters[1:3], LETTERS[1:3])) bm <- as.big.matrix(mat) test_that("is.nil works appropriately",{ expect_error(is.nil("hello"), info="address is not an externalptr") expect_false(is.nil(bm@address)) }) test_that("file.name works appropriately",{ if (Sys.info()['sysname'] != "Darwin") { expect_error(file.name(bm), info="The argument is not a file backed big.matrix.") } expect_identical(file.name(z), 'example.bin') }) test_that("basic matrix metrics work",{ expect_equivalent(ncol(bm), 3L) expect_equivalent(nrow(bm), 3L) expect_equivalent(dim(bm), c(3L, 3L)) expect_equivalent(ncol(z), 3L) expect_equivalent(nrow(z), 3L) expect_equivalent(dim(z), c(3L, 3L)) }) test_that("dimnames returned are correct", { expect_is(dimnames(mat), "list") expect_identical(dimnames(mat), dimnames(bm), info = "dimnames don't match between big.matrix and matrix") expect_identical(dimnames(mat), dimnames(z), info = "dimnames don't match between filebacked.big.matrix and matrix") }) rm(z) gc() file.remove('example.bin') file.remove('example.desc') bigmemory/tests/testthat/test_shared.R0000644000175100001440000000044313576750523017732 0ustar hornikuserslibrary("bigmemory") context("shared option") X1 <- big.matrix(10, 10) opt.save <- options(bigmemory.default.shared=FALSE) X2 <- big.matrix(10, 10) options(opt.save) test_that("Default shared parameter is read from options",{ expect_true(is.shared(X1)) expect_false(is.shared(X2)) }) bigmemory/tests/testthat/test_attach_path.R0000644000175100001440000000434113576750523020745 0ustar hornikuserslibrary("bigmemory") context("backingpath option when attaching") tmp <- tempfile() tmp.dir <- dirname(tmp) tmp.file <- basename(tmp) desc.path <- paste0(tmp.file, ".desc") X <- big.matrix(10, 10, backingfile = tmp.file, backingpath = tmp.dir, descriptorfile = desc.path, init = 0) X.desc <- describe(X) test_that("Format_path puts an '/' at the end if there isn't", { expect_equal(format_path("test"), "test/") expect_equal(format_path("test/"), "test/") expect_equal(format_path("test/test/"), "test/test/") }) test_that("New element 'dirname' in description", { expect_equal(X.desc@description$dirname, format_path(tmp.dir)) }) test_that("you can attach from a full path", { X2 <- attach.big.matrix(file.path(tmp.dir, desc.path)) expect_false(is.nil(X2@address), info = "the matrix exists") X2[] <- 1 expect_equal(X[,], matrix(1, 10, 10), info = "modifying X2 modifies also X") }) test_that("you can attach from a composed path", { X3 <- attach.big.matrix(desc.path, backingpath = tmp.dir) expect_false(is.nil(X3@address), info = "the matrix exists") X3[] <- 2 expect_equal(X[,], matrix(2, 10, 10), info = "modifying X3 modifies also X") }) test_that("you can attach with or without backingpath", { X4 <- attach.big.matrix(X.desc) expect_false(is.nil(X4@address), info = "the matrix exists") X4[] <- 3 expect_equal(X[,], matrix(3, 10, 10), info = "modifying X4 modifies also X") X5 <- attach.big.matrix(X.desc, backingpath = tmp.dir) expect_false(is.nil(X5@address), info = "the matrix exists") X5[] <- 4 expect_equal(X[,], matrix(4, 10, 10), info = "modifying X5 modifies also X") }) test_that("you can sub with or without backingpath", { X6 <- sub.big.matrix(X.desc, lastCol = 5) expect_false(is.nil(X6@address), info = "the matrix exists") X6[] <- 1 expect_equal(X[,], cbind(matrix(1, 10, 5), matrix(4, 10, 5)), info = "modifying X6 modifies also X") X7 <- sub.big.matrix(X.desc, firstCol = 6, backingpath = tmp.dir) expect_false(is.nil(X7@address), info = "the matrix exists") X7[] <- 2 expect_equal(X[,], cbind(matrix(1, 10, 5), matrix(2, 10, 5)), info = "modifying X7 modifies also X") }) bigmemory/tests/testthat.R0000644000175100001440000000007613576750523015427 0ustar hornikuserslibrary(testthat) library(bigmemory) test_check("bigmemory") bigmemory/src/0000755000175100001440000000000013600006022013036 5ustar hornikusersbigmemory/src/util.cpp0000644000175100001440000000226513576750523014554 0ustar hornikusers//#include //#include #include #include "bigmemory/util.h" vector RChar2StringVec( SEXP charVec ) { vector ret = Rcpp::as >(charVec); return ret; } vector RChar2StringVec( SEXP charVec, const vector &indices ) { vector ret( indices.size() ); vector::size_type i; for (i=0; i < indices.size(); ++i) { ret[i] = string(CHAR(STRING_ELT(charVec, indices[i]-1))); } return ret; } std::string RChar2String(SEXP str) { return string(CHAR(STRING_ELT(str, 0))); } //SEXP StringVec2RChar( const vector &strVec ) //{ // if (strVec.empty()) // return NULL_USER_OBJECT; //// SEXP ret = PROTECT(allocVector(STRSXP, strVec.size())); //// vector::size_type i; //// for (i=0; i < strVec.size(); ++i) //// { //// SET_STRING_ELT(ret, i, mkChar(strVec[i].c_str())); //// } // // vector ret(strVec.size()); // vector::size_type i; // for (i=0; i < strVec.size(); ++i) // { // ret[i] = strVec[i]; // } // return Rcpp::wrap(ret); //} SEXP String2RChar(const std::string &str) { return Rcpp::wrap(str); } bigmemory/src/bigmemory.cpp0000644000175100001440000032023013576750523015564 0ustar hornikusers #include //#include #include #include "bigmemory/BigMatrix.h" #include "bigmemory/MatrixAccessor.hpp" #include "bigmemory/isna.hpp" #include "bigmemory/util.h" #define R_BYTE_MIN (0) #define R_BYTE_MAX (255) #define NA_BYTE (0) using namespace Rcpp; /* Notes * R does not natively contain float type objects * Therefore, every time you pass object to see they will initially be * double unless they are already within a C/C++ object. * * For example, the SetMatrixElements function * Normally the function looks like this: * SetMatrixElements >(... * Where both the CType and RType are double but with float * types R is still passing only double. Trying to pass RType * as float will result in all NA values. So the function ultimately * must still pass double like so: * SetMatrixElements >(... */ template string ttos(T i) { stringstream s; s.precision(16); s << i; return s.str(); } template<> string ttos(unsigned char i) { stringstream s; s << static_cast(i); return s.str(); } template<> string ttos(char i) { stringstream s; s << static_cast(i); return s.str(); } bool TooManyRIndices( index_type val ) { return double(val) > pow(2.0, 31.0)-1.0; } template void SetMatrixElements( BigMatrix *pMat, SEXP col, SEXP row, SEXP values, double NA_C, double C_MIN, double C_MAX, double NA_R) { BMAccessorType mat( *pMat ); double *pCols = REAL(col); index_type numCols = Rf_length(col); double *pRows = REAL(row); index_type numRows = Rf_length(row); VecPtr vec_ptr; RType *pVals = vec_ptr(values); index_type valLength = Rf_length(values); index_type i=0; index_type j=0; index_type k=0; CType *pColumn; index_type kIndex; for (i=0; i < numCols; ++i) { pColumn = mat[static_cast(pCols[i])-1]; for (j=0; j < numRows; ++j) { kIndex = k++%valLength; pColumn[static_cast(pRows[j])-1] = ((pVals[kIndex] < C_MIN || pVals[kIndex] > C_MAX) ? static_cast(NA_C) : static_cast(pVals[kIndex])); } } } // Function contributed by Peter Haverty at Genentech. template SEXP GetIndivMatrixElements( BigMatrix *pMat, double NA_C, double NA_R, NumericVector col, NumericVector row) { BMAccessorType mat(*pMat); index_type numCols = col.size(); RcppType retVec(numCols); index_type i; for (i=0; i < numCols; ++i) { CType element = mat[static_cast(col[i])-1][static_cast(row[i])-1]; retVec[i] = element == static_cast(NA_C) ? static_cast(NA_R) : element; } return(retVec); } // Function contributed by Charles Detemran Jr. template SEXP GetIndivVectorMatrixElements( BigMatrix *pMat, double NA_C, double NA_R, NumericVector elems) { BMAccessorType mat(*pMat); index_type numElems = elems.size(); RcppType retVec(numElems); index_type i = 0; int idx = 0; for (index_type j = 0; j < elems.size(); j++){ CType element = mat[i][static_cast(elems[j])-1]; retVec[idx] = element == static_cast(NA_C) ? static_cast(NA_R) : element; idx += 1; } return(retVec); } // Function contributed by Charles Detemran Jr. template void SetIndivVectorMatrixElements( BigMatrix *pMat, double NA_C, double NA_R, NumericVector elems, NumericVector inVec) { BMAccessorType mat(*pMat); index_type i = 0; for (index_type j = 0; j < elems.size(); j++){ mat[i][static_cast(elems[j])-1] = inVec[j]; } } // Function contributed by Peter Haverty at Genentech. template void SetIndivMatrixElements( BigMatrix *pMat, SEXP col, SEXP row, SEXP values, double NA_C, double C_MIN, double C_MAX, double NA_R) { BMAccessorType mat( *pMat ); double *pCols = REAL(col); index_type numCols = Rf_length(col); double *pRows = REAL(row); VecPtr vec_ptr; RType *pVals = vec_ptr(values); index_type i=0; CType *pColumn; for (i=0; i < numCols; ++i) { pColumn = mat[static_cast(pCols[i])-1]; pColumn[static_cast(pRows[i])-1] = ((pVals[i] < C_MIN || pVals[i] > C_MAX) ? static_cast(NA_C) : static_cast(pVals[i])); } } template void SetMatrixAll( BigMatrix *pMat, SEXP values, double NA_C, double C_MIN, double C_MAX, double NA_R) { BMAccessorType mat( *pMat ); index_type numCols = pMat->ncol(); index_type numRows = pMat->nrow(); VecPtr vec_ptr; RType *pVals = vec_ptr(values); index_type valLength = Rf_length(values); index_type i=0; index_type j=0; index_type k=0; CType *pColumn; index_type kIndex; for (i=0; i < numCols; ++i) { pColumn = mat[i]; for (j=0; j < numRows; ++j) { kIndex = k++%valLength; pColumn[j] = ((pVals[kIndex] < C_MIN || pVals[kIndex] > C_MAX) ? static_cast(NA_C) : static_cast(pVals[kIndex])); } } } template void SetMatrixCols( BigMatrix *pMat, SEXP col, SEXP values, double NA_C, double C_MIN, double C_MAX, double NA_R) { BMAccessorType mat( *pMat ); double *pCols = REAL(col); index_type numCols = Rf_length(col); index_type numRows = pMat->nrow(); VecPtr vec_ptr; RType *pVals = vec_ptr(values); index_type valLength = Rf_length(values); index_type i=0; index_type j=0; index_type k=0; CType *pColumn; index_type kIndex; for (i=0; i < numCols; ++i) { pColumn = mat[static_cast(pCols[i])-1]; for (j=0; j < numRows; ++j) { kIndex = k++%valLength; pColumn[j] = ((pVals[kIndex] < C_MIN || pVals[kIndex] > C_MAX) ? static_cast(NA_C) : static_cast(pVals[kIndex])); } } } template void SetMatrixRows( BigMatrix *pMat, SEXP row, SEXP values, double NA_C, double C_MIN, double C_MAX, double NA_R) { BMAccessorType mat( *pMat ); index_type numCols = pMat->ncol(); double *pRows = REAL(row); index_type numRows = Rf_length(row); VecPtr vec_ptr; RType *pVals = vec_ptr(values); index_type valLength = Rf_length(values); index_type i=0; index_type j=0; index_type k=0; CType *pColumn; index_type kIndex; for (i=0; i < numCols; ++i) { pColumn = mat[i]; for (j=0; j < numRows; ++j) { kIndex = k++%valLength; pColumn[static_cast(pRows[j])-1] = ((pVals[kIndex] < C_MIN || pVals[kIndex] > C_MAX) ? static_cast(NA_C) : static_cast(pVals[kIndex])); } } } template void SetAllMatrixElements( BigMatrix *pMat, SEXP value, double NA_C, double C_MIN, double C_MAX, double NA_R) { BMAccessorType mat( *pMat ); double val = REAL(value)[0]; index_type i=0; index_type j=0; index_type ncol = pMat->ncol(); index_type nrow = pMat->nrow(); //bool outOfRange=false; if (val < C_MIN || val > C_MAX || isna(val)) { if (!isna(val)) { //outOfRange=true; Rf_warning("The value given is out of range, elements will be set to NA."); } val = NA_C; } for (i=0; i < ncol; ++i) { CType *pColumn = mat[i]; for (j=0; j < nrow; ++j) { pColumn[j] = static_cast(val); } } } template SEXP GetMatrixElements( BigMatrix *pMat, double NA_C, double NA_R, SEXP col, SEXP row, SEXPTYPE sxpType) { VecPtr vec_ptr; BMAccessorType mat(*pMat); double *pCols = REAL(col); double *pRows = REAL(row); index_type numCols = Rf_length(col); index_type numRows = Rf_length(row); /* if (TooManyRIndices(numCols*numRows)) { Rf_error("Too many indices (>2^31-1) for extraction."); return R_NilValue; } */ SEXP ret = Rf_protect(Rf_allocVector(VECSXP, 3)); int protectCount = 1; SET_VECTOR_ELT( ret, 1, R_NilValue ); SET_VECTOR_ELT( ret, 2, R_NilValue ); SEXP retMat; if (numCols == 1 || numRows == 1) { retMat = Rf_protect( Rf_allocVector(sxpType, numRows * numCols) ); } else { retMat = Rf_protect( Rf_allocMatrix(sxpType, numRows, numCols) ); } ++protectCount; SET_VECTOR_ELT(ret, 0, retMat); //SEXP ret = Rf_protect( new_vec(numCols*numRows) ); RType *pRet = vec_ptr(retMat); CType *pColumn; index_type k=0; index_type i,j; for (i=0; i < numCols; ++i) { if (isna(pCols[i])) { for (j=0; j < numRows; ++j) { pRet[k] = static_cast(NA_R); } } else { pColumn = mat[static_cast(pCols[i])-1]; for (j=0; j < numRows; ++j) { if (isna(pRows[j])) { pRet[k] = static_cast(NA_R); } else { pRet[k] = (pColumn[static_cast(pRows[j])-1] == static_cast(NA_C)) ? static_cast(NA_R) : (static_cast(pColumn[static_cast(pRows[j])-1])); } ++k; } } } Names colNames = pMat->column_names(); if (!colNames.empty()) { ++protectCount; SEXP rCNames = Rf_protect(Rf_allocVector(STRSXP, numCols)); for (i=0; i < numCols; ++i) { if (!isna(pCols[i])) SET_STRING_ELT( rCNames, i, Rf_mkChar(colNames[static_cast(pCols[i])-1].c_str()) ); } SET_VECTOR_ELT(ret, 2, rCNames); } Names rowNames = pMat->row_names(); if (!rowNames.empty()) { ++protectCount; SEXP rRNames = Rf_protect(Rf_allocVector(STRSXP, numRows)); for (i=0; i < numRows; ++i) { if (!isna(pRows[i])) { SET_STRING_ELT( rRNames, i, Rf_mkChar(rowNames[static_cast(pRows[i])-1].c_str()) ); } } SET_VECTOR_ELT(ret, 1, rRNames); } Rf_unprotect(protectCount); return ret; } // Function by Florian Prive // [[Rcpp::export]] SEXP to_int_checked(SEXP x) { if (TYPEOF(x) == INTSXP) return x; NumericVector nv(x); int i, n = nv.size(); IntegerVector res(n); for (i = 0; i < n; i++) { res[i] = nv[i]; if (nv[i] != res[i]) { warning("Value changed when converting to integer type."); break; } } for (; i < n; i++) res[i] = nv[i]; return res; } // Function contributed by Peter Haverty at Genentech. // [[Rcpp::export]] SEXP GetIndivMatrixElements(SEXP bigMatAddr, SEXP col, SEXP row) { BigMatrix *pMat = reinterpret_cast(R_ExternalPtrAddr(bigMatAddr)); if (pMat->separated_columns()) { switch(pMat->matrix_type()) { case 1: return GetIndivMatrixElements, IntegerVector >( pMat, NA_CHAR, NA_INTEGER, col, row); case 2: return GetIndivMatrixElements, IntegerVector >( pMat, NA_SHORT, NA_INTEGER, col, row); case 3: return GetIndivMatrixElements, IntegerVector >( pMat, NA_BYTE, NA_INTEGER, col, row); case 4: return GetIndivMatrixElements, IntegerVector >( pMat, NA_INTEGER, NA_INTEGER, col, row); case 6: return GetIndivMatrixElements, NumericVector >( pMat, NA_FLOAT, NA_FLOAT, col, row); case 8: return GetIndivMatrixElements, NumericVector >( pMat, NA_REAL, NA_REAL, col, row); } } else { switch(pMat->matrix_type()) { case 1: return GetIndivMatrixElements, IntegerVector >( pMat, NA_CHAR, NA_INTEGER, col, row); case 2: return GetIndivMatrixElements, IntegerVector >( pMat, NA_SHORT, NA_INTEGER, col, row); case 3: return GetIndivMatrixElements, IntegerVector >( pMat, NA_BYTE, NA_INTEGER, col, row); case 4: return GetIndivMatrixElements, IntegerVector >( pMat, NA_INTEGER, NA_INTEGER, col, row); case 6: return GetIndivMatrixElements, NumericVector >( pMat, NA_FLOAT, NA_FLOAT, col, row); case 8: return GetIndivMatrixElements, NumericVector >( pMat, NA_REAL, NA_REAL, col, row); } } return R_NilValue; } // Function contributed by Charles Determan Jr. // [[Rcpp::export]] SEXP GetIndivVectorMatrixElements(SEXP bigMatAddr, NumericVector elems) { BigMatrix *pMat = reinterpret_cast(R_ExternalPtrAddr(bigMatAddr)); if (pMat->separated_columns()) { switch(pMat->matrix_type()) { case 1: return GetIndivVectorMatrixElements, IntegerVector >( pMat, NA_CHAR, NA_INTEGER, elems); case 2: return GetIndivVectorMatrixElements, IntegerVector >( pMat, NA_SHORT, NA_INTEGER, elems); case 3: return GetIndivVectorMatrixElements, IntegerVector >( pMat, NA_BYTE, NA_INTEGER, elems); case 4: return GetIndivVectorMatrixElements, IntegerVector >( pMat, NA_INTEGER, NA_INTEGER, elems); case 6: return GetIndivVectorMatrixElements, NumericVector >( pMat, NA_FLOAT, NA_FLOAT, elems); case 8: return GetIndivVectorMatrixElements, NumericVector >( pMat, NA_REAL, NA_REAL, elems); } } else { switch(pMat->matrix_type()) { case 1: return GetIndivVectorMatrixElements, IntegerVector >( pMat, NA_CHAR, NA_INTEGER, elems); case 2: return GetIndivVectorMatrixElements, IntegerVector >( pMat, NA_SHORT, NA_INTEGER, elems); case 3: return GetIndivVectorMatrixElements, IntegerVector >( pMat, NA_BYTE, NA_INTEGER, elems); case 4: return GetIndivVectorMatrixElements, IntegerVector >( pMat, NA_INTEGER, NA_INTEGER, elems); case 6: return GetIndivVectorMatrixElements, NumericVector >( pMat, NA_FLOAT, NA_FLOAT, elems); case 8: return GetIndivVectorMatrixElements, NumericVector >( pMat, NA_REAL, NA_REAL, elems); } } return R_NilValue; } template SEXP GetMatrixRows( BigMatrix *pMat, double NA_C, double NA_R, SEXP row, SEXPTYPE sxpType) { VecPtr vec_ptr; BMAccessorType mat(*pMat); double *pRows=REAL(row); index_type numRows = Rf_length(row); index_type numCols = pMat->ncol(); /* if (TooManyRIndices(numCols*numRows)) { Rf_error("Too many indices (>2^31-1) for extraction."); return R_NilValue; } */ SEXP ret = Rf_protect(Rf_allocVector(VECSXP, 3)); int protectCount = 1; SET_VECTOR_ELT( ret, 1, R_NilValue ); SET_VECTOR_ELT( ret, 2, R_NilValue ); SEXP retMat; if (numCols == 1 || numRows == 1) { retMat = Rf_protect( Rf_allocVector(sxpType, numCols*numRows) ); } else { retMat = Rf_protect( Rf_allocMatrix(sxpType, numRows, numCols) ); } ++protectCount; SET_VECTOR_ELT(ret, 0, retMat); RType *pRet = vec_ptr(retMat); CType *pColumn = NULL; index_type k=0; index_type i,j; for (i=0; i < numCols; ++i) { pColumn = mat[i]; for (j=0; j < numRows; ++j) { if (isna(pRows[j])) { pRet[k] = static_cast(NA_R); } else { pRet[k] = (pColumn[static_cast(pRows[j])-1] == static_cast(NA_C)) ? static_cast(NA_R) : (static_cast(pColumn[static_cast(pRows[j])-1])); } ++k; } } Names colNames = pMat->column_names(); if (!colNames.empty()) { ++protectCount; SEXP rCNames = Rf_protect(Rf_allocVector(STRSXP, numCols)); for (i=0; i < numCols; ++i) { SET_STRING_ELT( rCNames, i, Rf_mkChar(colNames[i].c_str()) ); } SET_VECTOR_ELT(ret, 2, rCNames); } Names rowNames = pMat->row_names(); if (!rowNames.empty()) { ++protectCount; SEXP rRNames = Rf_protect(Rf_allocVector(STRSXP, numRows)); for (i=0; i < numRows; ++i) { if (!isna(pRows[i])) { SET_STRING_ELT( rRNames, i, Rf_mkChar(rowNames[static_cast(pRows[i])-1].c_str()) ); } } SET_VECTOR_ELT(ret, 1, rRNames); } Rf_unprotect(protectCount); return ret; } template SEXP GetMatrixCols( BigMatrix *pMat, double NA_C, double NA_R, SEXP col, SEXPTYPE sxpType) { VecPtr vec_ptr; BMAccessorType mat(*pMat); double *pCols=REAL(col); index_type numCols = Rf_length(col); index_type numRows = pMat->nrow(); /* if (TooManyRIndices(numCols*numRows)) { Rf_error("Too many indices (>2^31-1) for extraction."); return R_NilValue; } */ SEXP ret = Rf_protect(Rf_allocVector(VECSXP, 3)); int protectCount = 1; SET_VECTOR_ELT( ret, 1, R_NilValue ); SET_VECTOR_ELT( ret, 2, R_NilValue ); SEXP retMat; if (numCols == 1 || numRows == 1) { retMat = Rf_protect( Rf_allocVector(sxpType, numRows*numCols) ); } else { retMat = Rf_protect( Rf_allocMatrix(sxpType, numRows, numCols) ); } ++protectCount; SET_VECTOR_ELT(ret, 0, retMat); //SEXP ret = Rf_protect( new_vec(numCols*numRows) ); RType *pRet = vec_ptr(retMat); CType *pColumn = NULL; index_type k=0; index_type i,j; for (i=0; i < numCols; ++i) { if (isna(pCols[i])) { for (j=0; j < numRows; ++j) { pRet[k] = static_cast(NA_R); } } else { pColumn = mat[static_cast(pCols[i])-1]; for (j=0; j < numRows; ++j) { pRet[k] = (pColumn[j] == static_cast(NA_C)) ? static_cast(NA_R) : (static_cast(pColumn[j])); ++k; } } } Names colNames = pMat->column_names(); if (!colNames.empty()) { ++protectCount; SEXP rCNames = Rf_protect(Rf_allocVector(STRSXP, numCols)); for (i=0; i < numCols; ++i) { if (!isna(pCols[i])) SET_STRING_ELT( rCNames, i, Rf_mkChar(colNames[static_cast(pCols[i])-1].c_str()) ); } SET_VECTOR_ELT(ret, 2, rCNames); } Names rowNames = pMat->row_names(); if (!rowNames.empty()) { ++protectCount; SEXP rRNames = Rf_protect(Rf_allocVector(STRSXP, numRows)); for (i=0; i < numRows; ++i) { SET_STRING_ELT( rRNames, i, Rf_mkChar(rowNames[i].c_str()) ); } SET_VECTOR_ELT(ret, 1, rRNames); } Rf_unprotect(protectCount); return ret; } template SEXP GetMatrixAll( BigMatrix *pMat, double NA_C, double NA_R, SEXPTYPE sxpType) { VecPtr vec_ptr; BMAccessorType mat(*pMat); index_type numCols = pMat->ncol(); index_type numRows = pMat->nrow(); /* if (TooManyRIndices(numCols*numRows)) { Rf_error("Too many indices (>2^31-1) for extraction."); return R_NilValue; } */ SEXP ret = Rf_protect(Rf_allocVector(VECSXP, 3)); int protectCount = 1; SET_VECTOR_ELT( ret, 1, R_NilValue ); SET_VECTOR_ELT( ret, 2, R_NilValue ); SEXP retMat; if (numCols == 1 || numRows == 1) { retMat = Rf_protect( Rf_allocVector(sxpType, numRows * numCols) ); } else { retMat = Rf_protect( Rf_allocMatrix(sxpType, numRows, numCols) ); } ++protectCount; SET_VECTOR_ELT(ret, 0, retMat); //SEXP ret = Rf_protect( new_vec(numCols*numRows) ); RType *pRet = vec_ptr(retMat); CType *pColumn = NULL; index_type k=0; index_type i,j; for (i=0; i < numCols; ++i) { pColumn = mat[i]; for (j=0; j < numRows; ++j) { pRet[k] = (pColumn[j] == static_cast(NA_C)) ? static_cast(NA_R) : (static_cast(pColumn[j])); ++k; } } Names colNames = pMat->column_names(); if (!colNames.empty()) { ++protectCount; SEXP rCNames = Rf_protect(Rf_allocVector(STRSXP, numCols)); for (i=0; i < numCols; ++i) { SET_STRING_ELT( rCNames, i, Rf_mkChar(colNames[i].c_str()) ); } SET_VECTOR_ELT(ret, 2, rCNames); } Names rowNames = pMat->row_names(); if (!rowNames.empty()) { ++protectCount; SEXP rRNames = Rf_protect(Rf_allocVector(STRSXP, numRows)); for (i=0; i < numRows; ++i) { SET_STRING_ELT( rRNames, i, Rf_mkChar(rowNames[i].c_str()) ); } SET_VECTOR_ELT(ret, 1, rRNames); } Rf_unprotect(protectCount); return ret; } template SEXP ReadMatrix(SEXP fileName, BigMatrix *pMat, SEXP firstLine, SEXP numLines, SEXP numCols, SEXP separator, SEXP hasRowNames, SEXP useRowNames, double C_NA, double posInf, double negInf, double notANumber) { BMAccessorType mat(*pMat); SEXP ret = Rf_protect(Rf_allocVector(LGLSXP, 1)); LOGICAL(ret)[0] = (Rboolean)0; index_type fl = static_cast(REAL(firstLine)[0]); index_type nl = static_cast(REAL(numLines)[0]); string sep(CHAR(STRING_ELT(separator,0))); index_type i=0,j; bool rowSizeReserved = false; //double val; ifstream file; string lc, element; file.open(CHAR(Rf_asChar(fileName))); if (!file.is_open()) { Rf_unprotect(1); return ret; } for (i=0; i < fl; ++i) { std::getline(file, lc); } Names rn; index_type offset = static_cast(LOGICAL(hasRowNames)[0]); double d; int charRead; char *pEnd; for (i=0; i < nl; ++i) { // getline may be slow std::getline(file, lc); string::size_type first=0, last=0; j=0; while (first < lc.size() && last < lc.size()) { last = lc.find_first_of(sep, first); element = lc.substr(first, last-first); if (LOGICAL(hasRowNames)[0] && 0==j) { if (LOGICAL(useRowNames)[0]) { if (!rowSizeReserved) { rn.reserve(nl); rowSizeReserved = true; } std::size_t pos; while ( (pos = element.find("\"", 0)) != string::npos ) { element = element.replace(pos, 1, ""); } while ( (pos = element.find("'", 0)) != string::npos ) { element = element.replace(pos, 1, ""); } rn.push_back(element); } } else { if (j-offset < pMat->ncol()+1) { d = strtod(element.c_str(), &pEnd); if (pEnd != element.c_str()) { if (isna(d)) { mat[j-offset][i] = static_cast(C_NA); } else if (std::isinf(d) && d > 0) { mat[j-offset][i] = static_cast(posInf); } else if (std::isinf(d) && d < 0) { mat[j-offset][i] = static_cast(negInf); } else { mat[j-offset][i] = static_cast(d); } } else { charRead = sscanf(element.c_str(), "%lf", &d); if (charRead == static_cast(element.size())) { mat[j-offset][i] = static_cast(d); } else if (element == "NA") { mat[j-offset][i] = static_cast(C_NA); } else if (element == "inf" || element == "Inf") { mat[j-offset][i] = static_cast(posInf); } else if (element == "-inf" || element == "-Inf") { mat[j-offset][i] = static_cast(negInf); } else if (element == "NaN") { mat[j-offset][i] = static_cast(notANumber); } else if (element =="") { mat[j-offset][i] = static_cast(C_NA); } else { mat[j-offset][i] = static_cast(C_NA); } } } else { Rf_warning( (string("Incorrect number of entries in row ")+ttos(j)).c_str()); } } first = last+1; ++j; } if (j-offset < pMat->ncol()) { // warning( (string("Incorrect number of entries in row ")+ttos(j)).c_str()); while (j-offset < pMat->ncol()) { mat[j++ - offset][i] = static_cast(C_NA); } } } pMat->row_names( rn ); file.close(); LOGICAL(ret)[0] = (Rboolean)1; Rf_unprotect(1); return ret; } template void WriteMatrix( BigMatrix *pMat, SEXP fileName, SEXP rowNames, SEXP colNames, SEXP sep, double C_NA ) { BMAccessorType mat(*pMat); FILE *FP = fopen(CHAR(Rf_asChar(fileName)), "w"); index_type i,j; string s; string sepString = string(CHAR(STRING_ELT(sep, 0))); Names cn = pMat->column_names(); Names rn = pMat->row_names(); if (LOGICAL(colNames)[0] == Rboolean(TRUE) && !cn.empty()) { for (i=0; i < (int) cn.size(); ++i) s += "\"" + cn[i] + "\"" + (((int)cn.size()-1 == i) ? "\n" : sepString); } fprintf(FP, "%s", s.c_str()); s.clear(); for (i=0; i < pMat->nrow(); ++i) { if ( LOGICAL(rowNames)[0] == Rboolean(TRUE) && !rn.empty()) { s += "\"" + rn[i] + "\"" + sepString; } for (j=0; j < pMat->ncol(); ++j) { if ( isna(mat[j][i]) ) { s += "NA"; } else { s += ttos(mat[j][i]); } if (j < pMat->ncol()-1) { s += sepString; } else { s += "\n"; } } fprintf(FP, "%s", s.c_str()); s.clear(); } fclose(FP); } template struct NAMaker; template<> struct NAMaker {unsigned char operator()() const {return NA_BYTE;}}; template<> struct NAMaker {char operator()() const {return NA_CHAR;}}; template<> struct NAMaker {short operator()() const {return NA_SHORT;}}; template<> struct NAMaker {int operator()() const {return NA_INTEGER;}}; template<> struct NAMaker {double operator()() const {return NA_REAL;}}; // Note: naLast should be passed as an integer. template struct SecondLess : public std::binary_function { SecondLess( const bool naLast ) : _naLast(naLast) {} bool operator()(const PairType &lhs, const PairType &rhs) const { if (_naLast) { if (isna(lhs.second) || isna(rhs.second)) return false; return lhs.second < rhs.second; } else { if (isna(lhs.second)) return true; if (isna(rhs.second)) return false; return lhs.second < rhs.second; } } bool _naLast; }; template struct SecondGreater : public std::binary_function { SecondGreater(const bool naLast ) : _naLast(naLast) {} bool operator()(const PairType &lhs, const PairType &rhs) const { if (_naLast) { if (isna(lhs.second) || isna(rhs.second)) return false; return lhs.second > rhs.second; } else { if (isna(lhs.second)) return true; if (isna(rhs.second)) return false; return lhs.second > rhs.second; } } bool _naLast; }; template struct SecondIsNA : public std::unary_function { bool operator()( const PairType &val ) const { return isna(val.second); } }; template void reorder_matrix( MatrixAccessorType m, SEXP orderVec, index_type numColumns, FileBackedBigMatrix *pfbm ) { double *pov = REAL(orderVec); typedef typename MatrixAccessorType::value_type ValueType; typedef std::vector Values; Values vs(m.nrow()); index_type i,j; for (i=0; i < numColumns; ++i) { for (j=0; j < m.nrow(); ++j) { vs[j] = m[i][static_cast(pov[j])-1]; } std::copy( vs.begin(), vs.end(), m[i] ); if (pfbm) pfbm->flush(); } } // Function to reorder columns // It likely could use improvement as it just goes element by element // Added 9-17-2015 by Charles Determan template void reorder_matrix2( MatrixAccessorType m, Rcpp::IntegerVector pov, index_type numRows, FileBackedBigMatrix *pfbm ) { // double *pov = REAL(orderVec); typedef typename MatrixAccessorType::value_type ValueType; typedef std::vector Values; Values vs(m.ncol()); index_type i,j; for (j=0; j < numRows; ++j) { for (i=0; i < m.ncol(); ++i) { vs[i] = m[static_cast(pov[i])-1][j]; } for(i = 0; i < m.ncol(); ++i) { m[i][j] = vs[i]; } if (pfbm) pfbm->flush(); } } template SEXP get_order( MatrixAccessorType m, SEXP columns, SEXP naLast, SEXP decreasing ) { typedef typename MatrixAccessorType::value_type ValueType; typedef typename std::pair PairType; typedef std::vector OrderVecs; std::size_t i; index_type k; index_type col; OrderVecs ov; ov.reserve(m.nrow()); typename OrderVecs::iterator it; ValueType val; for (k=Rf_length(columns)-1; k >= 0; --k) { col = static_cast(REAL(columns)[k]-1); if (k==Rf_length(columns)-1) { if (isna(Rf_asInteger(naLast))) { for (i=0; i < static_cast(m.nrow()); ++i) { val = m[col][i]; if (!isna(val)) { ov.push_back( std::make_pair( static_cast(i), val) ); } } } else { ov.resize(m.nrow()); for (i=0; i < static_cast(m.nrow()); ++i) { val = m[col][i]; ov[i].first = i; ov[i].second = val; } } } else // not the first column we've looked at { if (isna(Rf_asInteger(naLast))) { i=0; while (i < ov.size()) { val = m[col][static_cast(ov[i].first)]; if (!isna(val)) { ov[i++].second = val; } else { ov.erase(ov.begin()+i); } } } else { for (i=0; i < static_cast(m.nrow()); ++i) { ov[i].second = m[col][static_cast(ov[i].first)]; } } } if (LOGICAL(decreasing)[0] == 0) { std::stable_sort(ov.begin(), ov.end(), SecondLess(Rf_asInteger(naLast)) ); } else { std::stable_sort(ov.begin(), ov.end(), SecondGreater(Rf_asInteger(naLast))); } } SEXP ret = Rf_protect(Rf_allocVector(REALSXP,ov.size())); double *pret = REAL(ret); for (i=0, it=ov.begin(); it < ov.end(); ++it, ++i) { pret[i] = it->first+1; } Rf_unprotect(1); return ret; } template SEXP get_order2( MatrixAccessorType m, SEXP rows, SEXP naLast, SEXP decreasing ) { typedef typename MatrixAccessorType::value_type ValueType; typedef typename std::pair PairType; typedef std::vector OrderVecs; std::size_t i; index_type k; index_type row; OrderVecs ov; ov.reserve(m.ncol()); typename OrderVecs::iterator it; ValueType val; for (k=Rf_length(rows)-1; k >= 0; --k) { row = static_cast(REAL(rows)[k]-1); if (k==Rf_length(rows)-1) { if (isna(Rf_asInteger(naLast))) { for (i=0; i < static_cast(m.ncol()); ++i) { val = m[row][i]; if (!isna(val)) { ov.push_back( std::make_pair( static_cast(i), val) ); } } } else { ov.resize(m.ncol()); for (i=0; i < static_cast(m.ncol()); ++i) { val = m[i][row]; ov[i].first = i; ov[i].second = val; } } } else // not the first column we've looked at { if (isna(Rf_asInteger(naLast))) { i=0; while (i < ov.size()) { val = m[static_cast(ov[i].first)][row]; if (!isna(val)) { ov[i++].second = val; } else { ov.erase(ov.begin()+i); } } } else { for (i=0; i < static_cast(m.ncol()); ++i) { ov[i].second = m[static_cast(ov[i].first)][row]; } } } if (LOGICAL(decreasing)[0] == 0) { std::stable_sort(ov.begin(), ov.end(), SecondLess(Rf_asInteger(naLast)) ); } else { std::stable_sort(ov.begin(), ov.end(), SecondGreater(Rf_asInteger(naLast))); } } SEXP ret = Rf_protect(Rf_allocVector(REALSXP,ov.size())); double *pret = REAL(ret); for (i=0, it=ov.begin(); it < ov.end(); ++it, ++i) { pret[i] = it->first+1; } Rf_unprotect(1); return ret; } // Rcpp Functions // [[Rcpp::export]] void ReorderRIntMatrix( SEXP matrixVector, SEXP nrow, SEXP ncol, SEXP orderVec ) { return reorder_matrix( MatrixAccessor(INTEGER(matrixVector), static_cast(Rf_asInteger(nrow))), orderVec, static_cast(Rf_asInteger(ncol)), NULL ); } // [[Rcpp::export]] void ReorderRNumericMatrix( SEXP matrixVector, SEXP nrow, SEXP ncol, SEXP orderVec ) { return reorder_matrix( MatrixAccessor(REAL(matrixVector), static_cast(Rf_asInteger(nrow))), orderVec, static_cast(Rf_asInteger(ncol)), NULL ); } // [[Rcpp::export]] void ReorderBigMatrix( SEXP address, SEXP orderVec ) { BigMatrix *pMat = reinterpret_cast(R_ExternalPtrAddr(address)); if (pMat->separated_columns()) { switch (pMat->matrix_type()) { case 1: return reorder_matrix( SepMatrixAccessor(*pMat), orderVec, pMat->ncol(), dynamic_cast(pMat) ); case 2: return reorder_matrix( SepMatrixAccessor(*pMat), orderVec, pMat->ncol(), dynamic_cast(pMat) ); case 3: return reorder_matrix( SepMatrixAccessor(*pMat), orderVec, pMat->ncol(), dynamic_cast(pMat) ); case 4: return reorder_matrix( SepMatrixAccessor(*pMat),orderVec, pMat->ncol(), dynamic_cast(pMat) ); case 6: return reorder_matrix( SepMatrixAccessor(*pMat),orderVec, pMat->ncol(), dynamic_cast(pMat) ); case 8: return reorder_matrix( SepMatrixAccessor(*pMat),orderVec, pMat->ncol(), dynamic_cast(pMat) ); } } else { switch (pMat->matrix_type()) { case 1: return reorder_matrix( MatrixAccessor(*pMat),orderVec, pMat->ncol(), dynamic_cast(pMat) ); case 2: return reorder_matrix( MatrixAccessor(*pMat),orderVec, pMat->ncol(), dynamic_cast(pMat) ); case 3: return reorder_matrix( MatrixAccessor(*pMat),orderVec, pMat->ncol(), dynamic_cast(pMat) ); case 4: return reorder_matrix( MatrixAccessor(*pMat),orderVec, pMat->ncol(), dynamic_cast(pMat) ); case 6: return reorder_matrix( MatrixAccessor(*pMat),orderVec, pMat->ncol(), dynamic_cast(pMat) ); case 8: return reorder_matrix( MatrixAccessor(*pMat),orderVec, pMat->ncol(), dynamic_cast(pMat) ); } } } // [[Rcpp::export]] void ReorderRIntMatrixCols( Rcpp::IntegerMatrix matrixVector, SEXP nrow, SEXP ncol, Rcpp::IntegerVector orderVec ) { reorder_matrix2( MatrixAccessor(INTEGER(matrixVector), static_cast(Rf_asInteger(nrow)), static_cast(Rf_asInteger(ncol))), orderVec, static_cast(Rf_asInteger(nrow)), NULL ); Rcpp::CharacterVector cols = colnames(matrixVector); colnames(matrixVector) = cols[orderVec - 1]; return; } // [[Rcpp::export]] void ReorderRNumericMatrixCols( Rcpp::NumericMatrix matrixVector, SEXP nrow, SEXP ncol, Rcpp::IntegerVector orderVec ) { reorder_matrix2( MatrixAccessor(REAL(matrixVector), static_cast(Rf_asInteger(nrow)), static_cast(Rf_asInteger(ncol))), orderVec, static_cast(Rf_asInteger(nrow)), NULL ); Rcpp::CharacterVector cols = colnames(matrixVector); colnames(matrixVector) = cols[orderVec - 1]; return; } // [[Rcpp::export]] void ReorderRRawMatrixCols( Rcpp::RawMatrix matrixVector, SEXP nrow, SEXP ncol, Rcpp::IntegerVector orderVec ) { reorder_matrix2( MatrixAccessor(REAL(matrixVector), static_cast(Rf_asInteger(nrow)), static_cast(Rf_asInteger(ncol))), orderVec, static_cast(Rf_asInteger(nrow)), NULL ); Rcpp::CharacterVector cols = colnames(matrixVector); colnames(matrixVector) = cols[orderVec - 1]; return; } // [[Rcpp::export]] void ReorderBigMatrixCols( SEXP address, SEXP orderVec ) { BigMatrix *pMat = reinterpret_cast(R_ExternalPtrAddr(address)); if (pMat->separated_columns()) { switch (pMat->matrix_type()) { case 1: return reorder_matrix2( SepMatrixAccessor(*pMat), orderVec, pMat->nrow(), dynamic_cast(pMat) ); case 2: return reorder_matrix2( SepMatrixAccessor(*pMat), orderVec, pMat->nrow(), dynamic_cast(pMat) ); case 3: return reorder_matrix2( SepMatrixAccessor(*pMat), orderVec, pMat->nrow(), dynamic_cast(pMat) ); case 4: return reorder_matrix2( SepMatrixAccessor(*pMat),orderVec, pMat->nrow(), dynamic_cast(pMat) ); case 6: return reorder_matrix2( SepMatrixAccessor(*pMat),orderVec, pMat->nrow(), dynamic_cast(pMat) ); case 8: return reorder_matrix2( SepMatrixAccessor(*pMat),orderVec, pMat->nrow(), dynamic_cast(pMat) ); } } else { switch (pMat->matrix_type()) { case 1: return reorder_matrix2( MatrixAccessor(*pMat),orderVec, pMat->nrow(), dynamic_cast(pMat) ); case 2: return reorder_matrix2( MatrixAccessor(*pMat),orderVec, pMat->nrow(), dynamic_cast(pMat) ); case 3: return reorder_matrix2( MatrixAccessor(*pMat),orderVec, pMat->nrow(), dynamic_cast(pMat) ); case 4: return reorder_matrix2( MatrixAccessor(*pMat),orderVec, pMat->nrow(), dynamic_cast(pMat) ); case 6: return reorder_matrix2( MatrixAccessor(*pMat),orderVec, pMat->nrow(), dynamic_cast(pMat) ); case 8: return reorder_matrix2( MatrixAccessor(*pMat),orderVec, pMat->nrow(), dynamic_cast(pMat) ); } } } // [[Rcpp::export]] SEXP OrderRIntMatrix( SEXP matrixVector, SEXP nrow, SEXP columns, SEXP naLast, SEXP decreasing ) { return get_order( MatrixAccessor(INTEGER(matrixVector), static_cast(Rf_asInteger(nrow))), columns, naLast, decreasing ); } // [[Rcpp::export]] SEXP OrderRNumericMatrix( SEXP matrixVector, SEXP nrow, SEXP columns, SEXP naLast, SEXP decreasing ) { return get_order( MatrixAccessor(REAL(matrixVector), static_cast(Rf_asInteger(nrow))), columns, naLast, decreasing ); } // [[Rcpp::export]] SEXP OrderBigMatrix(SEXP address, SEXP columns, SEXP naLast, SEXP decreasing) { BigMatrix *pMat = reinterpret_cast(R_ExternalPtrAddr(address)); if (pMat->separated_columns()) { switch (pMat->matrix_type()) { case 1: return get_order( SepMatrixAccessor(*pMat), columns, naLast, decreasing ); case 2: return get_order( SepMatrixAccessor(*pMat), columns, naLast, decreasing ); case 3: return get_order( SepMatrixAccessor(*pMat), columns, naLast, decreasing ); case 4: return get_order( SepMatrixAccessor(*pMat), columns, naLast, decreasing ); case 6: return get_order( SepMatrixAccessor(*pMat), columns, naLast, decreasing ); case 8: return get_order( SepMatrixAccessor(*pMat), columns, naLast, decreasing ); } } else { switch (pMat->matrix_type()) { case 1: return get_order( MatrixAccessor(*pMat), columns, naLast, decreasing ); case 2: return get_order( MatrixAccessor(*pMat), columns, naLast, decreasing ); case 3: return get_order( MatrixAccessor(*pMat), columns, naLast, decreasing ); case 4: return get_order( MatrixAccessor(*pMat), columns, naLast, decreasing ); case 6: return get_order( MatrixAccessor(*pMat), columns, naLast, decreasing ); case 8: return get_order( MatrixAccessor(*pMat), columns, naLast, decreasing ); } } return R_NilValue; } // [[Rcpp::export]] SEXP OrderRIntMatrixCols( SEXP matrixVector, SEXP nrow, SEXP ncol, SEXP rows, SEXP naLast, SEXP decreasing ) { return get_order2( MatrixAccessor(INTEGER(matrixVector), static_cast(Rf_asInteger(nrow)), static_cast(Rf_asInteger(ncol))), rows, naLast, decreasing ); } // [[Rcpp::export]] SEXP OrderRNumericMatrixCols( SEXP matrixVector, SEXP nrow, SEXP ncol, SEXP rows, SEXP naLast, SEXP decreasing ) { return get_order2( MatrixAccessor(REAL(matrixVector), static_cast(Rf_asInteger(nrow)), static_cast(Rf_asInteger(ncol))), rows, naLast, decreasing ); } // [[Rcpp::export]] SEXP OrderBigMatrixCols(SEXP address, SEXP rows, SEXP naLast, SEXP decreasing) { BigMatrix *pMat = reinterpret_cast(R_ExternalPtrAddr(address)); if (pMat->separated_columns()) { switch (pMat->matrix_type()) { case 1: return get_order2( SepMatrixAccessor(*pMat), rows, naLast, decreasing ); case 2: return get_order2( SepMatrixAccessor(*pMat), rows, naLast, decreasing ); case 3: return get_order2( SepMatrixAccessor(*pMat), rows, naLast, decreasing ); case 4: return get_order2( SepMatrixAccessor(*pMat), rows, naLast, decreasing ); case 6: return get_order2( SepMatrixAccessor(*pMat), rows, naLast, decreasing ); case 8: return get_order2( SepMatrixAccessor(*pMat), rows, naLast, decreasing ); } } else { switch (pMat->matrix_type()) { case 1: return get_order2( MatrixAccessor(*pMat), rows, naLast, decreasing ); case 2: return get_order2( MatrixAccessor(*pMat), rows, naLast, decreasing ); case 3: return get_order2( MatrixAccessor(*pMat), rows, naLast, decreasing ); case 4: return get_order2( MatrixAccessor(*pMat), rows, naLast, decreasing ); case 6: return get_order2( MatrixAccessor(*pMat), rows, naLast, decreasing ); case 8: return get_order2( MatrixAccessor(*pMat), rows, naLast, decreasing ); } } return R_NilValue; } // [[Rcpp::export]] SEXP CCleanIndices(SEXP indices, SEXP rc) { typedef std::vector Indices; double *pIndices = REAL(indices); index_type numIndices = Rf_length(indices); double maxrc = REAL(rc)[0]; int protectCount=1; SEXP ret = Rf_protect(Rf_allocVector(VECSXP, 2)); index_type negIndexCount=0; index_type posIndexCount=0; index_type zeroIndexCount=0; Indices::size_type i,j; // See if the indices are within range, negative, positive, zero, or mixed. for (i=0; i < static_cast(numIndices); ++i) { if (static_cast(pIndices[i]) == 0) { ++zeroIndexCount; } if (static_cast(pIndices[i]) < 0) { ++negIndexCount; } if (static_cast(pIndices[i]) > 0) { ++posIndexCount; } if ( labs(static_cast(pIndices[i])) > maxrc ) { SET_VECTOR_ELT(ret, 0, R_NilValue); SET_VECTOR_ELT(ret, 1, R_NilValue); Rf_unprotect(protectCount); return ret; } } if ( (zeroIndexCount == numIndices) && (numIndices > 0) ) { protectCount += 2; SEXP returnCond = Rf_protect(Rf_allocVector(LGLSXP,1)); LOGICAL(returnCond)[0] = (Rboolean)1; SEXP newIndices = Rf_protect(Rf_allocVector(REALSXP,0)); SET_VECTOR_ELT(ret, 0, returnCond); SET_VECTOR_ELT(ret, 1, newIndices); Rf_unprotect(protectCount); return ret; } if (posIndexCount > 0 && negIndexCount > 0) { SET_VECTOR_ELT(ret, 0, R_NilValue); SET_VECTOR_ELT(ret, 1, R_NilValue); Rf_unprotect(protectCount); return ret; } if (zeroIndexCount > 0) { protectCount += 2; SEXP returnCond = Rf_protect(Rf_allocVector(LGLSXP,1)); LOGICAL(returnCond)[0] = (Rboolean)1; SEXP newIndices = Rf_protect(Rf_allocVector(REALSXP,posIndexCount)); double *newPIndices = REAL(newIndices); j=0; for (i=0; i < static_cast(numIndices); ++i) { if (static_cast(pIndices[i]) != 0) { newPIndices[j++] = pIndices[i]; } } SET_VECTOR_ELT(ret, 0, returnCond); SET_VECTOR_ELT(ret, 1, newIndices); Rf_unprotect(protectCount); return ret; } else if (negIndexCount > 0) { // It might be better to use a data-structure other than a vector // (sequential ordering). Indices ind; try { ind.reserve(static_cast(maxrc)); } catch(...) { SET_VECTOR_ELT(ret, 0, R_NilValue); SET_VECTOR_ELT(ret, 1, R_NilValue); Rf_unprotect(protectCount); return ret; } for (i=1; i <= static_cast(maxrc); ++i) { ind.push_back(i); } Indices::iterator it; for (i=0; i < static_cast(numIndices); ++i) { it = std::lower_bound(ind.begin(), ind.end(), static_cast(-1*pIndices[i])); if ( it != ind.end() && *it == -1*static_cast(pIndices[i]) ) { ind.erase(it); } } /* if (TooManyRIndices(ind.size())) { SET_VECTOR_ELT(ret, 0, R_NilValue); SET_VECTOR_ELT(ret, 1, R_NilValue); Rf_unprotect(protectCount); return ret; } */ protectCount +=2; SEXP returnCond = Rf_protect(Rf_allocVector(LGLSXP,1)); LOGICAL(returnCond)[0] = (Rboolean)1; SEXP newIndices = Rf_protect(Rf_allocVector(REALSXP,ind.size())); double *newPIndices = REAL(newIndices); for (i=0; i < ind.size(); ++i) { newPIndices[i] = static_cast(ind[i]); } SET_VECTOR_ELT(ret, 0, returnCond); SET_VECTOR_ELT(ret, 1, newIndices); Rf_unprotect(protectCount); return ret; } protectCount += 1; SEXP returnCond = Rf_protect(Rf_allocVector(LGLSXP,1)); LOGICAL(returnCond)[0] = (Rboolean)0; SET_VECTOR_ELT(ret, 0, returnCond); SET_VECTOR_ELT(ret, 1, R_NilValue); Rf_unprotect(protectCount); return ret; } // [[Rcpp::export]] SEXP HasRowColNames(SEXP address) { BigMatrix *pMat = (BigMatrix*)R_ExternalPtrAddr(address); SEXP ret = Rf_protect(Rf_allocVector(LGLSXP,2)); LOGICAL(ret)[0] = pMat->row_names().empty() ? Rboolean(0) : Rboolean(1); LOGICAL(ret)[1] = pMat->column_names().empty() ? Rboolean(0) : Rboolean(1); Rf_unprotect(1); return ret; } // Not currently used?!?! // [[Rcpp::export]] SEXP GetIndexRowNames(SEXP address, SEXP indices_) { BigMatrix *pMat = (BigMatrix*)R_ExternalPtrAddr(address); Names rn = pMat->row_names(); Rcpp::IntegerVector indices = Rcpp::as(indices_); Rcpp::CharacterVector rcpp_rn = Rcpp::wrap(rn); return rcpp_rn[indices-1]; // vector c_idx = Rcpp::as >(indices); // return StringVec2RChar(rn, c_idx, indices.size()); } // Not currently used?!?! // [[Rcpp::export]] SEXP GetIndexColNames(SEXP address, SEXP indices_) { BigMatrix *pMat = (BigMatrix*)R_ExternalPtrAddr(address); Names cn = pMat->column_names(); Rcpp::IntegerVector indices = Rcpp::as(indices_); Rcpp::CharacterVector rcpp_cn = Rcpp::wrap(cn); return rcpp_cn[indices-1]; // vector c_idx = Rcpp::as >(indices); // return StringVec2RChar(cn, c_idx, indices.size()); } // [[Rcpp::export]] SEXP GetColumnNamesBM(SEXP address) { BigMatrix *pMat = (BigMatrix*)R_ExternalPtrAddr(address); Names cn = pMat->column_names(); return Rcpp::wrap(cn); } // [[Rcpp::export]] SEXP GetRowNamesBM(SEXP address) { BigMatrix *pMat = (BigMatrix*)R_ExternalPtrAddr(address); Names rn = pMat->row_names(); return Rcpp::wrap(rn); } // [[Rcpp::export]] void SetColumnNames(SEXP address, SEXP columnNames) { BigMatrix *pMat = (BigMatrix*) R_ExternalPtrAddr(address); Names cn; index_type i; for (i=0; i < Rf_length(columnNames); ++i) cn.push_back(string(CHAR(STRING_ELT(columnNames, i)))); pMat->column_names(cn); } // [[Rcpp::export]] void SetRowNames(SEXP address, SEXP rowNames) { BigMatrix *pMat = (BigMatrix*) R_ExternalPtrAddr(address); Names rn; index_type i; for (i=0; i < Rf_length(rowNames); ++i) rn.push_back(string(CHAR(STRING_ELT(rowNames, i)))); pMat->row_names(rn); } // [[Rcpp::export]] SEXP IsReadOnly(SEXP bigMatAddr) { BigMatrix *pMat = reinterpret_cast(R_ExternalPtrAddr(bigMatAddr)); SEXP ret = Rf_protect(Rf_allocVector(LGLSXP,1)); LOGICAL(ret)[0] = (pMat->read_only() ? (Rboolean) 1 : (Rboolean) 0); Rf_unprotect(1); return ret; } // [[Rcpp::export]] SEXP CIsSubMatrix(SEXP bigMatAddr) { BigMatrix *pMat = reinterpret_cast(R_ExternalPtrAddr(bigMatAddr)); SEXP ret = Rf_protect(Rf_allocVector(LGLSXP,1)); if ( pMat->col_offset() > 0 || pMat->row_offset() > 0 || pMat->nrow() < pMat->total_rows() || pMat->ncol() < pMat->total_columns() ) { LOGICAL(ret)[0] = (Rboolean) 1; } else { LOGICAL(ret)[0] = (Rboolean) 0; } Rf_unprotect(1); return ret; } // [[Rcpp::export]] SEXP CGetNrow(SEXP bigMatAddr) { BigMatrix *pMat = (BigMatrix*)R_ExternalPtrAddr(bigMatAddr); SEXP ret = Rf_protect(Rf_allocVector(REALSXP,1)); REAL(ret)[0] = (double)pMat->nrow(); Rf_unprotect(1); return(ret); } // [[Rcpp::export]] SEXP CGetNcol(SEXP bigMatAddr) { BigMatrix *pMat = (BigMatrix*)R_ExternalPtrAddr(bigMatAddr); SEXP ret = Rf_protect(Rf_allocVector(REALSXP,1)); REAL(ret)[0] = (double)pMat->ncol(); Rf_unprotect(1); return(ret); } // [[Rcpp::export]] SEXP CGetType(SEXP bigMatAddr) { Rcpp::XPtr pMat(bigMatAddr); int ret = pMat->matrix_type(); return Rcpp::wrap(ret); } // not currently used?!?!?! // [[Rcpp::export]] SEXP IsSharedMemoryBigMatrix(SEXP bigMatAddr) { BigMatrix *pMat = (BigMatrix*)R_ExternalPtrAddr(bigMatAddr); SEXP ret = Rf_protect(Rf_allocVector(LGLSXP,1)); LOGICAL(ret)[0] = dynamic_cast(pMat) == NULL ? static_cast(0) : static_cast(1); Rf_unprotect(1); return ret; } // [[Rcpp::export]] SEXP IsFileBackedBigMatrix(SEXP bigMatAddr) { BigMatrix *pMat = (BigMatrix*)R_ExternalPtrAddr(bigMatAddr); SEXP ret = Rf_protect(Rf_allocVector(LGLSXP,1)); LOGICAL(ret)[0] = dynamic_cast(pMat) == NULL ? static_cast(0) : static_cast(1); Rf_unprotect(1); return ret; } // [[Rcpp::export]] SEXP IsSeparated(SEXP bigMatAddr) { BigMatrix *pMat = (BigMatrix*)R_ExternalPtrAddr(bigMatAddr); SEXP ret = Rf_protect(Rf_allocVector(LGLSXP,1)); LOGICAL(ret)[0] = pMat->separated_columns() ? (Rboolean)1 : (Rboolean)0; Rf_unprotect(1); return(ret); } // removed extern C because doesn't appear necessary // Rcpp attributes can be used for R calls and the others // are only used in the C code // only called in C code void CDestroyBigMatrix(SEXP bigMatrixAddr) { BigMatrix *pm=(BigMatrix*)(R_ExternalPtrAddr(bigMatrixAddr)); delete pm; R_ClearExternalPtr(bigMatrixAddr); } // only called in C code inline bool Lcomp(double a, double b, int op) { return(op==0 ? a<=b : a=b : a>b); } template SEXP MWhichMatrix( MatrixType mat, index_type nrow, SEXP selectColumn, SEXP minVal, SEXP maxVal, SEXP chkMin, SEXP chkMax, SEXP opVal, double C_NA ) { index_type numSc = Rf_length(selectColumn); double *sc = REAL(selectColumn); double *min = REAL(minVal); double *max = REAL(maxVal); int *chkmin = INTEGER(chkMin); int *chkmax = INTEGER(chkMax); double minV, maxV; int ov = Rf_asInteger(opVal); index_type count = 0; index_type i,j; double val; for (i=0; i < nrow; ++i) { for (j=0; j < numSc; ++j) { minV = min[j]; maxV = max[j]; if (isna(minV)) { minV = static_cast(C_NA); maxV = static_cast(C_NA); } val = (double) mat[(index_type)sc[j]-1][i]; if (chkmin[j]==-1) { // this is an 'neq' if (ov==1) { // OR with 'neq' if ( (minV!=val) || ( (isna(val) && !isna(minV)) || (!isna(val) && isna(minV)) ) ) { ++count; break; } } else { // AND with 'neq' // if they are equal, then break out. if ( (minV==val) || (isna(val) && isna(minV)) ) break; } } else { // not a 'neq' // If it's an OR operation and it's true for one, it's true for the // whole row. if ( ( (Gcomp(val, minV, chkmin[j]) && Lcomp(val, maxV, chkmax[j])) || (isna(val) && isna(minV))) && ov==1 ) { ++count; break; } // If it's an AND operation and it's false for one, it's false for // the whole row. if ( ( (Lcomp(val, minV, 1-chkmin[j]) || Gcomp(val, maxV, 1-chkmax[j])) || (isna(val) && !isna(minV)) || (!isna(val) && isna(minV)) ) && ov == 0 ) break; } } // If it's an AND operation and it's true for each column, it's true // for the entire row. if (j==numSc && ov == 0) ++count; } if (count==0) return Rf_allocVector(INTSXP,0); SEXP ret = Rf_protect(Rf_allocVector(REALSXP,count)); double *retVals = REAL(ret); index_type k = 0; for (i=0; i < nrow; ++i) { for (j=0; j < numSc; ++j) { minV = min[j]; maxV = max[j]; if (isna(minV)) { minV = static_cast(C_NA); maxV = static_cast(C_NA); } val = (double) mat[(index_type)sc[j]-1][i]; if (chkmin[j]==-1) { // this is an 'neq' if (ov==1) { // OR with 'neq' if ( (minV!=val) || ( (isna(val) && !isna(minV)) || (!isna(val) && isna(minV)) ) ) { retVals[k++] = i+1; break; } } else { // AND with 'neq' // if they are equal, then break out. if ( (minV==val) || (isna(val) && isna(minV)) ) break; } } else { // not a 'neq' if ( ( (Gcomp(val, minV, chkmin[j]) && Lcomp(val, maxV, chkmax[j])) || (isna(val) && isna(minV))) && ov==1 ) { retVals[k++] = i+1; break; } if (((Lcomp(val, minV, 1-chkmin[j]) || Gcomp(val, maxV, 1-chkmax[j])) || (isna(val) && !isna(minV)) || (!isna(val) && isna(minV)) ) && ov == 0 ) break; } } // end j loop if (j==numSc && ov == 0) retVals[k++] = i+1; } // end i loop Rf_unprotect(1); return(ret); } template SEXP CreateRAMMatrix(SEXP row, SEXP col, SEXP colnames, SEXP rownames, SEXP typeLength, SEXP ini, SEXP separated) { T *pMat=NULL; try { pMat = new T(); if (!pMat->create( static_cast(REAL(row)[0]), static_cast(REAL(col)[0]), Rf_asInteger(typeLength), static_cast(LOGICAL(separated)[0]))) { delete pMat; return R_NilValue; } if (colnames != R_NilValue) { pMat->column_names(RChar2StringVec(colnames)); } if (rownames != R_NilValue) { pMat->row_names(RChar2StringVec(rownames)); } if (Rf_length(ini) != 0) { if (pMat->separated_columns()) { switch (pMat->matrix_type()) { case 1: SetAllMatrixElements >( pMat, ini, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_REAL); break; case 2: SetAllMatrixElements >( pMat, ini, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_REAL); break; case 3: SetAllMatrixElements >( pMat, ini, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_REAL); break; case 4: SetAllMatrixElements >( pMat, ini, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_REAL); break; case 6: SetAllMatrixElements >( pMat, ini, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_REAL); break; case 8: SetAllMatrixElements >( pMat, ini, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } else { switch (pMat->matrix_type()) { case 1: SetAllMatrixElements >( pMat, ini, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_REAL ); break; case 2: SetAllMatrixElements >( pMat, ini, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_REAL ); break; case 3: SetAllMatrixElements >( pMat, ini, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_REAL ); break; case 4: SetAllMatrixElements >( pMat, ini, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_REAL ); break; case 6: SetAllMatrixElements >( pMat, ini, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_REAL ); break; case 8: SetAllMatrixElements >( pMat, ini, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } } SEXP address = R_MakeExternalPtr( dynamic_cast(pMat), R_NilValue, R_NilValue); R_RegisterCFinalizerEx(address, (R_CFinalizer_t) CDestroyBigMatrix, (Rboolean) TRUE); return address; } catch(std::exception &e) { Rprintf("%s\n", e.what()); } catch(...) { Rprintf("Exception caught while trying to create shared matrix."); } delete(pMat); Rf_error("The shared matrix could not be created\n"); return(R_NilValue); } // Rcpp functions // [[Rcpp::export]] void SetRowOffsetInfo( SEXP bigMatAddr, SEXP rowOffset, SEXP numRows ) { BigMatrix *pMat = reinterpret_cast(R_ExternalPtrAddr(bigMatAddr)); pMat->row_offset(static_cast(REAL(rowOffset)[0])); pMat->nrow(static_cast(REAL(numRows)[0])); } // [[Rcpp::export]] void SetColumnOffsetInfo( SEXP bigMatAddr, SEXP colOffset, SEXP numCols ) { BigMatrix *pMat = reinterpret_cast(R_ExternalPtrAddr(bigMatAddr)); pMat->col_offset(static_cast(REAL(colOffset)[0])); pMat->ncol(static_cast(REAL(numCols)[0])); } // [[Rcpp::export]] SEXP GetRowOffset( SEXP bigMatAddr ) { Rcpp::XPtr pMat(bigMatAddr); Rcpp::NumericVector ret(2); ret[0] = pMat->row_offset(); ret[1] = pMat->nrow(); return ret; } // [[Rcpp::export]] Rcpp::NumericVector GetColOffset( SEXP bigMatAddr ) { Rcpp::XPtr pMat(bigMatAddr); Rcpp::NumericVector ret(2); ret[0] = pMat->col_offset(); ret[1] = pMat->ncol(); return ret; } // [[Rcpp::export]] SEXP GetTotalColumns( SEXP bigMatAddr ) { Rcpp::XPtr pMat(bigMatAddr); int ret = pMat->total_columns(); return Rcpp::wrap(ret); } // [[Rcpp::export]] SEXP GetTotalRows( SEXP bigMatAddr ) { Rcpp::XPtr pMat(bigMatAddr); int ret = pMat->total_rows(); return Rcpp::wrap(ret); } template std::string type_name(); // simplifed to use Rcpp tools 04/13/2015 -- Charles Determan Jr. // [[Rcpp::export]] Rcpp::String GetTypeString( SEXP bigMatAddr ) { Rcpp::XPtr pMat(bigMatAddr); switch(pMat->matrix_type()) { case 1: return "char"; case 2: return "short"; case 3: return "raw"; case 4: return "integer"; case 6: return "float"; case 8: return "double"; default: throw Rcpp::exception("unknown type detected for big.matrix object!"); } } /* Added by Charles Determan Jr. 04/20/2015 * quick function to access big.matrix sizes * possibly convert in to a method for object.size??? */ //' @title big.matrix size //' @description Returns the size of the created matrix in bytes //' @param bigMat a \code{big.matrix} object //' @export // [[Rcpp::export]] SEXP GetMatrixSize( SEXP bigMat ) { // declare as S4 object Rcpp::S4 As4(bigMat); // pull address slot SEXP BM_address = As4.slot("address"); // declare as external pointer Rcpp::XPtr pMat(BM_address); // return the matrix size (in bytes) return Rcpp::wrap(pMat->allocation_size()); } // [[Rcpp::export]] SEXP MWhichBigMatrix( SEXP bigMatAddr, SEXP selectColumn, SEXP minVal, SEXP maxVal, SEXP chkMin, SEXP chkMax, SEXP opVal ) { Rcpp::XPtr pMat(bigMatAddr); if (pMat->separated_columns()) { switch (pMat->matrix_type()) { case 1: return MWhichMatrix( SepMatrixAccessor(*pMat), pMat->nrow(), selectColumn, minVal, maxVal, chkMin, chkMax, opVal, NA_CHAR); case 2: return MWhichMatrix( SepMatrixAccessor(*pMat), pMat->nrow(), selectColumn, minVal, maxVal, chkMin, chkMax, opVal, NA_SHORT); case 3: return MWhichMatrix( SepMatrixAccessor(*pMat), pMat->nrow(), selectColumn, minVal, maxVal, chkMin, chkMax, opVal, NA_BYTE); case 4: return MWhichMatrix( SepMatrixAccessor(*pMat), pMat->nrow(), selectColumn, minVal, maxVal, chkMin, chkMax, opVal, NA_INTEGER); case 6: return MWhichMatrix( SepMatrixAccessor(*pMat), pMat->nrow(), selectColumn, minVal, maxVal, chkMin, chkMax, opVal, NA_FLOAT); case 8: return MWhichMatrix( SepMatrixAccessor(*pMat), pMat->nrow(), selectColumn, minVal, maxVal, chkMin, chkMax, opVal, NA_REAL); } } else { switch (pMat->matrix_type()) { case 1: return MWhichMatrix( MatrixAccessor(*pMat), pMat->nrow(), selectColumn, minVal, maxVal, chkMin, chkMax, opVal, NA_CHAR); case 2: return MWhichMatrix( MatrixAccessor(*pMat), pMat->nrow(), selectColumn, minVal, maxVal, chkMin, chkMax, opVal, NA_SHORT); case 3: return MWhichMatrix( MatrixAccessor(*pMat), pMat->nrow(), selectColumn, minVal, maxVal, chkMin, chkMax, opVal, NA_BYTE); case 4: return MWhichMatrix( MatrixAccessor(*pMat), pMat->nrow(), selectColumn, minVal, maxVal, chkMin, chkMax, opVal, NA_INTEGER); case 6: return MWhichMatrix( MatrixAccessor(*pMat), pMat->nrow(), selectColumn, minVal, maxVal, chkMin, chkMax, opVal, NA_FLOAT); case 8: return MWhichMatrix( MatrixAccessor(*pMat), pMat->nrow(), selectColumn, minVal, maxVal, chkMin, chkMax, opVal, NA_REAL); } } return R_NilValue; } // [[Rcpp::export]] SEXP MWhichRIntMatrix( SEXP matrixVector, SEXP nrow, SEXP selectColumn, SEXP minVal, SEXP maxVal, SEXP chkMin, SEXP chkMax, SEXP opVal ) { index_type numRows = static_cast(Rf_asInteger(nrow)); MatrixAccessor mat(INTEGER(matrixVector), numRows); return MWhichMatrix >(mat, numRows, selectColumn, minVal, maxVal, chkMin, chkMax, opVal, NA_INTEGER); } // [[Rcpp::export]] SEXP MWhichRNumericMatrix( SEXP matrixVector, SEXP nrow, SEXP selectColumn, SEXP minVal, SEXP maxVal, SEXP chkMin, SEXP chkMax, SEXP opVal ) { index_type numRows = static_cast(Rf_asInteger(nrow)); MatrixAccessor mat(REAL(matrixVector), numRows); return MWhichMatrix >(mat, numRows, selectColumn, minVal, maxVal, chkMin, chkMax, opVal, NA_REAL); } // [[Rcpp::export]] SEXP CCountLines(SEXP fileName) { FILE *FP; double lineCount = 0; char readChar; FP = fopen(CHAR(Rf_asChar(fileName)), "r"); SEXP ret = Rf_protect(Rf_allocVector(REALSXP,1)); REAL(ret)[0] = -1; if (FP == NULL) { Rf_unprotect(1); return(ret); } do { readChar = fgetc(FP); if ('\n' == readChar) ++lineCount; } while( readChar != EOF ); fclose(FP); REAL(ret)[0] = lineCount; Rf_unprotect(1); return(ret); } // [[Rcpp::export]] SEXP ReadMatrix(SEXP fileName, SEXP bigMatAddr, SEXP firstLine, SEXP numLines, SEXP numCols, SEXP separator, SEXP hasRowNames, SEXP useRowNames) { Rcpp::XPtr pMat(bigMatAddr); if (pMat->separated_columns()) { switch (pMat->matrix_type()) { case 1: return ReadMatrix >( fileName, pMat, firstLine, numLines, numCols, separator, hasRowNames, useRowNames, NA_CHAR, NA_CHAR, NA_CHAR, NA_CHAR); case 2: return ReadMatrix >( fileName, pMat, firstLine, numLines, numCols, separator, hasRowNames, useRowNames, NA_SHORT, NA_SHORT, NA_SHORT, NA_SHORT); case 3: return ReadMatrix >( fileName, pMat, firstLine, numLines, numCols, separator, hasRowNames, useRowNames, NA_BYTE, NA_BYTE, NA_BYTE, NA_BYTE); case 4: return ReadMatrix >( fileName, pMat, firstLine, numLines, numCols, separator, hasRowNames, useRowNames, NA_INTEGER, NA_INTEGER, NA_INTEGER, NA_INTEGER); case 6: return ReadMatrix >( fileName, pMat, firstLine, numLines, numCols, separator, hasRowNames, useRowNames, NA_FLOAT, NA_FLOAT, NA_FLOAT, NA_FLOAT); case 8: return ReadMatrix >( fileName, pMat, firstLine, numLines, numCols, separator, hasRowNames, useRowNames, NA_REAL, R_PosInf, R_NegInf, R_NaN); } } else { switch (pMat->matrix_type()) { case 1: return ReadMatrix >( fileName, pMat, firstLine, numLines, numCols, separator, hasRowNames, useRowNames, NA_CHAR, NA_CHAR, NA_CHAR, NA_CHAR); case 2: return ReadMatrix >( fileName, pMat, firstLine, numLines, numCols, separator, hasRowNames, useRowNames, NA_SHORT, NA_SHORT, NA_SHORT, NA_SHORT); case 3: return ReadMatrix >( fileName, pMat, firstLine, numLines, numCols, separator, hasRowNames, useRowNames, NA_BYTE, NA_BYTE, NA_BYTE, NA_BYTE); case 4: return ReadMatrix >( fileName, pMat, firstLine, numLines, numCols, separator, hasRowNames, useRowNames, NA_INTEGER, NA_INTEGER, NA_INTEGER, NA_INTEGER); case 6: return ReadMatrix >( fileName, pMat, firstLine, numLines, numCols, separator, hasRowNames, useRowNames, NA_FLOAT, NA_FLOAT, NA_FLOAT, NA_FLOAT); case 8: return ReadMatrix >( fileName, pMat, firstLine, numLines, numCols, separator, hasRowNames, useRowNames, NA_REAL, R_PosInf, R_NegInf, R_NaN); } } return R_NilValue; } // [[Rcpp::export]] void WriteMatrix( SEXP bigMatAddr, SEXP fileName, SEXP rowNames, SEXP colNames, SEXP sep ) { Rcpp::XPtr pMat(bigMatAddr); if (pMat->separated_columns()) { switch (pMat->matrix_type()) { case 1: WriteMatrix >( pMat, fileName, rowNames, colNames, sep, NA_CHAR); break; case 2: WriteMatrix >( pMat, fileName, rowNames, colNames, sep, NA_SHORT); break; case 3: WriteMatrix >( pMat, fileName, rowNames, colNames, sep, NA_BYTE); break; case 4: WriteMatrix >( pMat, fileName, rowNames, colNames, sep, NA_INTEGER); break; case 6: WriteMatrix >( pMat, fileName, rowNames, colNames, sep, NA_FLOAT); break; case 8: WriteMatrix >( pMat, fileName, rowNames, colNames, sep, NA_REAL); } } else { switch (pMat->matrix_type()) { case 1: WriteMatrix >( pMat, fileName, rowNames, colNames, sep, NA_CHAR); break; case 2: WriteMatrix >( pMat, fileName, rowNames, colNames, sep, NA_SHORT); break; case 3: WriteMatrix >( pMat, fileName, rowNames, colNames, sep, NA_BYTE); break; case 4: WriteMatrix >( pMat, fileName, rowNames, colNames, sep, NA_INTEGER); break; case 6: WriteMatrix >( pMat, fileName, rowNames, colNames, sep, NA_FLOAT); break; case 8: WriteMatrix >( pMat, fileName, rowNames, colNames, sep, NA_REAL); } } } // [[Rcpp::export]] SEXP GetMatrixElements(SEXP bigMatAddr, SEXP col, SEXP row) { Rcpp::XPtr pMat(bigMatAddr); if (pMat->separated_columns()) { switch(pMat->matrix_type()) { case 1: return GetMatrixElements > (pMat, NA_CHAR, NA_INTEGER, col, row, INTSXP); case 2: return GetMatrixElements > (pMat, NA_SHORT, NA_INTEGER, col, row, INTSXP); case 3: return GetMatrixElements > (pMat, NA_BYTE, NA_INTEGER, col, row, RAWSXP); case 4: return GetMatrixElements > (pMat, NA_INTEGER, NA_INTEGER, col, row, INTSXP); case 6: // possibly area of problem (REALSXP -> FLOATSXP???) but I think okay return GetMatrixElements > (pMat, NA_FLOAT, NA_FLOAT, col, row, REALSXP); case 8: return GetMatrixElements >( pMat, NA_REAL, NA_REAL, col, row, REALSXP); } } else { switch(pMat->matrix_type()) { case 1: return GetMatrixElements >( pMat, NA_CHAR, NA_INTEGER, col, row, INTSXP); case 2: return GetMatrixElements >( pMat, NA_SHORT, NA_INTEGER, col, row, INTSXP); case 3: return GetMatrixElements >( pMat, NA_BYTE, NA_INTEGER, col, row, RAWSXP); case 4: return GetMatrixElements >( pMat, NA_INTEGER, NA_INTEGER, col, row, INTSXP); case 6: return GetMatrixElements >( pMat, NA_FLOAT, NA_FLOAT, col, row, REALSXP); case 8: return GetMatrixElements > (pMat, NA_REAL, NA_REAL, col, row, REALSXP); } } return R_NilValue; } // [[Rcpp::export]] SEXP GetMatrixRows(SEXP bigMatAddr, SEXP row) { Rcpp::XPtr pMat(bigMatAddr); if (pMat->separated_columns()) { switch(pMat->matrix_type()) { case 1: return GetMatrixRows > (pMat, NA_CHAR, NA_INTEGER, row, INTSXP); case 2: return GetMatrixRows > (pMat, NA_SHORT, NA_INTEGER, row, INTSXP); case 3: return GetMatrixRows > (pMat, NA_BYTE, NA_INTEGER, row, RAWSXP); case 4: return GetMatrixRows > (pMat, NA_INTEGER, NA_INTEGER, row, INTSXP); case 6: return GetMatrixRows > (pMat, NA_FLOAT, NA_FLOAT, row, REALSXP); case 8: return GetMatrixRows >( pMat, NA_REAL, NA_REAL, row, REALSXP); } } else { switch(pMat->matrix_type()) { case 1: return GetMatrixRows >( pMat, NA_CHAR, NA_INTEGER, row, INTSXP); case 2: return GetMatrixRows >( pMat, NA_SHORT, NA_INTEGER, row, INTSXP); case 3: return GetMatrixRows >( pMat, NA_BYTE, NA_INTEGER, row, RAWSXP); case 4: return GetMatrixRows >( pMat, NA_INTEGER, NA_INTEGER, row, INTSXP); case 6: return GetMatrixRows >( pMat, NA_FLOAT, NA_FLOAT, row, REALSXP); case 8: return GetMatrixRows > (pMat, NA_REAL, NA_REAL, row, REALSXP); } } return R_NilValue; } // [[Rcpp::export]] SEXP GetMatrixCols(SEXP bigMatAddr, SEXP col) { Rcpp::XPtr pMat(bigMatAddr); if (pMat->separated_columns()) { switch(pMat->matrix_type()) { case 1: return GetMatrixCols > (pMat, NA_CHAR, NA_INTEGER, col, INTSXP); case 2: return GetMatrixCols > (pMat, NA_SHORT, NA_INTEGER, col, INTSXP); case 3: return GetMatrixCols > (pMat, NA_BYTE, NA_INTEGER, col, RAWSXP); case 4: return GetMatrixCols > (pMat, NA_INTEGER, NA_INTEGER, col, INTSXP); case 6: return GetMatrixCols > (pMat, NA_FLOAT, NA_FLOAT, col, REALSXP); case 8: return GetMatrixCols >( pMat, NA_REAL, NA_REAL, col, REALSXP); } } else { switch(pMat->matrix_type()) { case 1: return GetMatrixCols >( pMat, NA_CHAR, NA_INTEGER, col, INTSXP); case 2: return GetMatrixCols >( pMat, NA_SHORT, NA_INTEGER, col, INTSXP); case 3: return GetMatrixCols >( pMat, NA_BYTE, NA_INTEGER, col, RAWSXP); case 4: return GetMatrixCols >( pMat, NA_INTEGER, NA_INTEGER, col, INTSXP); case 6: return GetMatrixCols >( pMat, NA_FLOAT, NA_FLOAT, col, REALSXP); case 8: return GetMatrixCols > (pMat, NA_REAL, NA_REAL, col, REALSXP); } } return R_NilValue; } // remove col because not used // [[Rcpp::export]] SEXP GetMatrixAll(SEXP bigMatAddr) { Rcpp::XPtr pMat(bigMatAddr); if (pMat->separated_columns()) { switch(pMat->matrix_type()) { case 1: return GetMatrixAll > (pMat, NA_CHAR, NA_INTEGER, INTSXP); case 2: return GetMatrixAll > (pMat, NA_SHORT, NA_INTEGER, INTSXP); case 3: return GetMatrixAll > (pMat, NA_BYTE, NA_INTEGER, RAWSXP); case 4: return GetMatrixAll > (pMat, NA_INTEGER, NA_INTEGER, INTSXP); case 6: return GetMatrixAll > (pMat, NA_FLOAT, NA_FLOAT, REALSXP); case 8: return GetMatrixAll >( pMat, NA_REAL, NA_REAL, REALSXP); } } else { switch(pMat->matrix_type()) { case 1: return GetMatrixAll >( pMat, NA_CHAR, NA_INTEGER, INTSXP); case 2: return GetMatrixAll >( pMat, NA_SHORT, NA_INTEGER, INTSXP); case 3: return GetMatrixAll >( pMat, NA_BYTE, NA_INTEGER, RAWSXP); case 4: return GetMatrixAll >( pMat, NA_INTEGER, NA_INTEGER, INTSXP); case 6: return GetMatrixAll >( pMat, NA_FLOAT, NA_REAL, REALSXP); case 8: return GetMatrixAll > (pMat, NA_REAL, NA_REAL, REALSXP); } } return R_NilValue; } // [[Rcpp::export]] void SetMatrixElements(SEXP bigMatAddr, SEXP col, SEXP row, SEXP values) { Rcpp::XPtr pMat(bigMatAddr); if (pMat->separated_columns()) { switch (pMat->matrix_type()) { case 1: SetMatrixElements >( pMat, col, row, values, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_INTEGER); break; case 2: SetMatrixElements >( pMat, col, row, values, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_INTEGER); break; case 3: SetMatrixElements >( pMat, col, row, values, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_INTEGER); break; case 4: SetMatrixElements >( pMat, col, row, values, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_INTEGER); break; case 6: SetMatrixElements >( pMat, col, row, values, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_FLOAT); break; case 8: SetMatrixElements >( pMat, col, row, values, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } else { switch (pMat->matrix_type()) { case 1: SetMatrixElements >( pMat, col, row, values, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_INTEGER); break; case 2: SetMatrixElements >( pMat, col, row, values, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_INTEGER); break; case 3: SetMatrixElements >( pMat, col, row, values, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_INTEGER); break; case 4: SetMatrixElements >( pMat, col, row, values, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_INTEGER); break; case 6: SetMatrixElements >( pMat, col, row, values, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_FLOAT); break; case 8: SetMatrixElements >( pMat, col, row, values, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } } // Function contributed by Charles Determan Jr. // [[Rcpp::export]] void SetIndivVectorMatrixElements( SEXP bigMatAddr, NumericVector elems, NumericVector inVec) { BigMatrix *pMat = reinterpret_cast(R_ExternalPtrAddr(bigMatAddr)); if (pMat->separated_columns()) { switch(pMat->matrix_type()) { case 1: SetIndivVectorMatrixElements, IntegerVector >( pMat, NA_CHAR, NA_INTEGER, elems, inVec); break; case 2: SetIndivVectorMatrixElements, IntegerVector >( pMat, NA_SHORT, NA_INTEGER, elems, inVec); break; case 3: SetIndivVectorMatrixElements, IntegerVector >( pMat, NA_BYTE, NA_INTEGER, elems, inVec); break; case 4: SetIndivVectorMatrixElements, IntegerVector >( pMat, NA_INTEGER, NA_INTEGER, elems, inVec); break; case 6: SetIndivVectorMatrixElements, NumericVector >( pMat, NA_FLOAT, NA_FLOAT, elems, inVec); break; case 8: SetIndivVectorMatrixElements, NumericVector >( pMat, NA_REAL, NA_REAL, elems, inVec); break; } } else { switch(pMat->matrix_type()) { case 1: SetIndivVectorMatrixElements, IntegerVector >( pMat, NA_CHAR, NA_INTEGER, elems, inVec); break; case 2: SetIndivVectorMatrixElements, IntegerVector >( pMat, NA_SHORT, NA_INTEGER, elems, inVec); break; case 3: SetIndivVectorMatrixElements, IntegerVector >( pMat, NA_BYTE, NA_INTEGER, elems, inVec); break; case 4: SetIndivVectorMatrixElements, IntegerVector >( pMat, NA_INTEGER, NA_INTEGER, elems, inVec); break; case 6: SetIndivVectorMatrixElements, NumericVector >( pMat, NA_FLOAT, NA_FLOAT, elems, inVec); break; case 8: SetIndivVectorMatrixElements, NumericVector >( pMat, NA_REAL, NA_REAL, elems, inVec); break; } } } // Function contributed by Peter Haverty at Genentech. // [[Rcpp::export]] void SetIndivMatrixElements(SEXP bigMatAddr, SEXP col, SEXP row, SEXP values) { Rcpp::XPtr pMat(bigMatAddr); if (pMat->separated_columns()) { switch (pMat->matrix_type()) { case 1: SetIndivMatrixElements >( pMat, col, row, values, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_INTEGER); break; case 2: SetIndivMatrixElements >( pMat, col, row, values, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_INTEGER); break; case 3: SetIndivMatrixElements >( pMat, col, row, values, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_INTEGER); break; case 4: SetIndivMatrixElements >( pMat, col, row, values, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_INTEGER); break; case 6: SetIndivMatrixElements >( pMat, col, row, values, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_FLOAT); break; case 8: SetIndivMatrixElements >( pMat, col, row, values, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } else { switch (pMat->matrix_type()) { case 1: SetIndivMatrixElements >( pMat, col, row, values, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_INTEGER); break; case 2: SetIndivMatrixElements >( pMat, col, row, values, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_INTEGER); break; case 3: SetIndivMatrixElements >( pMat, col, row, values, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_INTEGER); break; case 4: SetIndivMatrixElements >( pMat, col, row, values, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_INTEGER); break; case 6: SetIndivMatrixElements >( pMat, col, row, values, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_FLOAT); break; case 8: SetIndivMatrixElements >( pMat, col, row, values, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } } // [[Rcpp::export]] void SetMatrixAll(SEXP bigMatAddr, SEXP values) { Rcpp::XPtr pMat(bigMatAddr); if (pMat->separated_columns()) { switch (pMat->matrix_type()) { case 1: SetMatrixAll >( pMat, values, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_INTEGER); break; case 2: SetMatrixAll >( pMat, values, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_INTEGER); break; case 3: SetMatrixAll >( pMat, values, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_INTEGER); break; case 4: SetMatrixAll >( pMat, values, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_INTEGER); break; case 6: SetMatrixAll >( pMat, values, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_FLOAT); break; case 8: SetMatrixAll >( pMat, values, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } else { switch (pMat->matrix_type()) { case 1: SetMatrixAll >( pMat, values, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_INTEGER); break; case 2: SetMatrixAll >( pMat, values, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_INTEGER); break; case 3: SetMatrixAll >( pMat, values, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_INTEGER); break; case 4: SetMatrixAll >( pMat, values, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_INTEGER); break; case 6: SetMatrixAll >( pMat, values, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_FLOAT); break; case 8: SetMatrixAll >( pMat, values, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } } // [[Rcpp::export]] void SetMatrixCols(SEXP bigMatAddr, SEXP col, SEXP values) { Rcpp::XPtr pMat(bigMatAddr); if (pMat->separated_columns()) { switch (pMat->matrix_type()) { case 1: SetMatrixCols >( pMat, col, values, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_INTEGER); break; case 2: SetMatrixCols >( pMat, col, values, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_INTEGER); break; case 3: SetMatrixCols >( pMat, col, values, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_INTEGER); break; case 4: SetMatrixCols >( pMat, col, values, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_INTEGER); break; case 6: SetMatrixCols >( pMat, col, values, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_FLOAT); break; case 8: SetMatrixCols >( pMat, col, values, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } else { switch (pMat->matrix_type()) { case 1: SetMatrixCols >( pMat, col, values, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_INTEGER); break; case 2: SetMatrixCols >( pMat, col, values, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_INTEGER); break; case 3: SetMatrixCols >( pMat, col, values, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_INTEGER); break; case 4: SetMatrixCols >( pMat, col, values, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_INTEGER); break; case 6: SetMatrixCols >( pMat, col, values, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_FLOAT); break; case 8: SetMatrixCols >( pMat, col, values, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } } // [[Rcpp::export]] void SetMatrixRows(SEXP bigMatAddr, SEXP row, SEXP values) { Rcpp::XPtr pMat(bigMatAddr); if (pMat->separated_columns()) { switch (pMat->matrix_type()) { case 1: SetMatrixRows >( pMat, row, values, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_INTEGER); break; case 2: SetMatrixRows >( pMat, row, values, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_INTEGER); break; case 3: SetMatrixRows >( pMat, row, values, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_INTEGER); break; case 4: SetMatrixRows >( pMat, row, values, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_INTEGER); break; case 6: SetMatrixRows >( pMat, row, values, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_FLOAT); break; case 8: SetMatrixRows >( pMat, row, values, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } else { switch (pMat->matrix_type()) { case 1: SetMatrixRows >( pMat, row, values, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_INTEGER); break; case 2: SetMatrixRows >( pMat, row, values, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_INTEGER); break; case 3: SetMatrixRows >( pMat, row, values, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_INTEGER); break; case 4: SetMatrixRows >( pMat, row, values, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_INTEGER); break; case 6: SetMatrixRows >( pMat, row, values, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_FLOAT); break; case 8: SetMatrixRows >( pMat, row, values, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } } // [[Rcpp::export]] SEXP CreateSharedMatrix(SEXP row, SEXP col, SEXP colnames, SEXP rownames, SEXP typeLength, SEXP ini, SEXP separated) { return CreateRAMMatrix(row, col, colnames, rownames, typeLength, ini, separated); } // [[Rcpp::export]] SEXP CreateLocalMatrix(SEXP row, SEXP col, SEXP colnames, SEXP rownames, SEXP typeLength, SEXP ini, SEXP separated) { return CreateRAMMatrix(row, col, colnames, rownames, typeLength, ini, separated); } // [[Rcpp::export]] SEXP CreateFileBackedBigMatrix(SEXP fileName, SEXP filePath, SEXP row, SEXP col, SEXP colnames, SEXP rownames, SEXP typeLength, SEXP ini, SEXP separated) { try { FileBackedBigMatrix *pMat = new FileBackedBigMatrix(); string fn; string path = ((filePath == R_NilValue) ? "" : RChar2String(filePath)); if (Rf_isNull(fileName)) { fn=pMat->uuid()+".bin"; } else { fn = RChar2String(fileName); } if (!pMat->create( fn, RChar2String(filePath), static_cast(REAL(row)[0]), static_cast(REAL(col)[0]), Rf_asInteger(typeLength), static_cast(LOGICAL(separated)[0]))) { delete pMat; Rf_error("Problem creating filebacked matrix."); return R_NilValue; } if (colnames != R_NilValue) { pMat->column_names(RChar2StringVec(colnames)); } if (rownames != R_NilValue) { pMat->row_names(RChar2StringVec(rownames)); } if (Rf_length(ini) != 0) { if (pMat->separated_columns()) { switch (pMat->matrix_type()) { case 1: SetAllMatrixElements >( pMat, ini, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_REAL); break; case 2: SetAllMatrixElements >( pMat, ini, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_REAL); break; case 3: SetAllMatrixElements >( pMat, ini, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_REAL); break; case 4: SetAllMatrixElements >( pMat, ini, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_REAL); break; case 6: SetAllMatrixElements >( pMat, ini, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_REAL); break; case 8: SetAllMatrixElements >( pMat, ini, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } else { switch (pMat->matrix_type()) { case 1: SetAllMatrixElements >( pMat, ini, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_REAL); break; case 2: SetAllMatrixElements >( pMat, ini, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_REAL); break; case 3: SetAllMatrixElements >( pMat, ini, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_REAL); break; case 4: SetAllMatrixElements >( pMat, ini, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_REAL); break; case 6: SetAllMatrixElements >( pMat, ini, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_REAL); break; case 8: SetAllMatrixElements >( pMat, ini, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } } SEXP address = R_MakeExternalPtr( dynamic_cast(pMat), R_NilValue, R_NilValue); R_RegisterCFinalizerEx(address, (R_CFinalizer_t) CDestroyBigMatrix, (Rboolean) TRUE); return address; } catch(std::exception &e) { Rprintf("%s\n", e.what()); } catch(...) { Rprintf("Unspecified problem trying to create big.matrix\n"); } return R_NilValue; } // [[Rcpp::export]] SEXP CAttachSharedBigMatrix(SEXP sharedName, SEXP rows, SEXP cols, SEXP rowNames, SEXP colNames, SEXP typeLength, SEXP separated, SEXP readOnly) { SharedMemoryBigMatrix *pMat = new SharedMemoryBigMatrix(); bool connected = pMat->connect( string(CHAR(STRING_ELT(sharedName,0))), static_cast(REAL(rows)[0]), static_cast(REAL(cols)[0]), Rf_asInteger(typeLength), static_cast(LOGICAL(separated)[0]), static_cast(LOGICAL(readOnly)[0])); if (!connected) { delete pMat; return R_NilValue; } if (Rf_length(colNames) > 0) { pMat->column_names(RChar2StringVec(colNames)); } if (Rf_length(rowNames) > 0) { pMat->row_names(RChar2StringVec(rowNames)); } SEXP address = R_MakeExternalPtr( dynamic_cast(pMat), R_NilValue, R_NilValue); R_RegisterCFinalizerEx(address, (R_CFinalizer_t) CDestroyBigMatrix, (Rboolean) TRUE); return address; } // [[Rcpp::export]] SEXP CAttachFileBackedBigMatrix(SEXP fileName, SEXP filePath, SEXP rows, SEXP cols, SEXP rowNames, SEXP colNames, SEXP typeLength, SEXP separated, SEXP readOnly) { FileBackedBigMatrix *pMat = new FileBackedBigMatrix(); bool connected = pMat->connect( string(CHAR(STRING_ELT(fileName,0))), string(CHAR(STRING_ELT(filePath,0))), static_cast(REAL(rows)[0]), static_cast(REAL(cols)[0]), Rf_asInteger(typeLength), static_cast(LOGICAL(separated)[0]), static_cast(LOGICAL(readOnly)[0])); if (!connected) { delete pMat; return R_NilValue; } if (Rf_length(colNames) > 0) { pMat->column_names(RChar2StringVec(colNames)); } if (Rf_length(rowNames) > 0) { pMat->row_names(RChar2StringVec(rowNames)); } SEXP address = R_MakeExternalPtr( dynamic_cast(pMat), R_NilValue, R_NilValue); R_RegisterCFinalizerEx(address, (R_CFinalizer_t) CDestroyBigMatrix, (Rboolean) TRUE); return address; } // [[Rcpp::export]] SEXP SharedName( SEXP address ) { BigMatrix *pMat = (BigMatrix*)R_ExternalPtrAddr(address); SharedMemoryBigMatrix *psmbm = dynamic_cast(pMat); if (psmbm) return String2RChar(psmbm->shared_name()); Rf_error("Object is not a shared memory big.matrix."); return R_NilValue; } // [[Rcpp::export]] SEXP FileName( SEXP address ) { BigMatrix *pMat = (BigMatrix*)R_ExternalPtrAddr(address); FileBackedBigMatrix *pfbbm = dynamic_cast(pMat); if (pfbbm) return String2RChar(pfbbm->file_name()); Rf_error("Object is not a filebacked big.matrix."); return R_NilValue; } // [[Rcpp::export]] SEXP DirName( SEXP address ) { BigMatrix *pMat = (BigMatrix*)R_ExternalPtrAddr(address); FileBackedBigMatrix *pfbbm = dynamic_cast(pMat); if (pfbbm) return String2RChar(pfbbm->file_path()); Rf_error("Object is not a filebacked big.matrix."); return R_NilValue; } // [[Rcpp::export]] SEXP Flush( SEXP address ) { FileBackedBigMatrix *pMat = reinterpret_cast(R_ExternalPtrAddr(address)); FileBackedBigMatrix *pfbbm = dynamic_cast(pMat); SEXP ret = Rf_protect(Rf_allocVector(LGLSXP,1)); if (pfbbm) { LOGICAL(ret)[0] = pfbbm->flush() ? (Rboolean)TRUE : Rboolean(FALSE); } else { LOGICAL(ret)[0] = (Rboolean)FALSE; Rf_error("Object is not a filebacked big.matrix"); } Rf_unprotect(1); return ret; } // [[Rcpp::export]] SEXP IsShared( SEXP address ) { FileBackedBigMatrix *pMat = reinterpret_cast(R_ExternalPtrAddr(address)); SEXP ret = Rf_protect(Rf_allocVector(LGLSXP,1)); LOGICAL(ret)[0] = pMat->shared() ? (Rboolean)TRUE : Rboolean(FALSE); Rf_unprotect(1); return ret; } // [[Rcpp::export]] SEXP isnil(SEXP address) { void *ptr = R_ExternalPtrAddr(address); SEXP ret = Rf_protect(Rf_allocVector(LGLSXP,1)); LOGICAL(ret)[0] = (ptr==NULL) ? (Rboolean)TRUE : Rboolean(FALSE); Rf_unprotect(1); return(ret); } // removed extern C because doesn't appear necessary // Rcpp attributes can be used for R calls and the others // are only used in the C code // WHERE IS THIS CALLED FROM? Maybe only from C, not from R? // We might like to be able to do this recycling efficiently in other // cases? I thought we did. void SetAllMatrixElements(SEXP bigMatAddr, SEXP value) { Rcpp::XPtr pMat(bigMatAddr); if (pMat->separated_columns()) { switch (pMat->matrix_type()) { case 1: SetAllMatrixElements >( pMat, value, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_REAL); break; case 2: SetAllMatrixElements >( pMat, value, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_REAL); break; case 3: SetAllMatrixElements >( pMat, value, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_REAL); break; case 4: SetAllMatrixElements >( pMat, value, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_REAL); break; case 6: SetAllMatrixElements >( pMat, value, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_REAL); break; case 8: SetAllMatrixElements >( pMat, value, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } else { switch (pMat->matrix_type()) { case 1: SetAllMatrixElements >( pMat, value, NA_CHAR, R_CHAR_MIN, R_CHAR_MAX, NA_REAL); break; case 2: SetAllMatrixElements >( pMat, value, NA_SHORT, R_SHORT_MIN, R_SHORT_MAX, NA_REAL); break; case 3: SetAllMatrixElements >( pMat, value, NA_BYTE, R_BYTE_MIN, R_BYTE_MAX, NA_REAL); break; case 4: SetAllMatrixElements >( pMat, value, NA_INTEGER, R_INT_MIN, R_INT_MAX, NA_REAL); break; case 6: SetAllMatrixElements >( pMat, value, NA_FLOAT, R_FLT_MIN, R_FLT_MAX, NA_REAL); break; case 8: SetAllMatrixElements >( pMat, value, NA_REAL, R_DOUBLE_MIN, R_DOUBLE_MAX, NA_REAL); } } } // This doesn't appear to be used anywhere?!?! void* GetDataPtr(SEXP address) { SharedBigMatrix *pMat = reinterpret_cast(R_ExternalPtrAddr(address)); return pMat->data_ptr(); } bigmemory/src/RcppExports.cpp0000644000175100001440000013145013577164344016070 0ustar hornikusers// Generated by using Rcpp::compileAttributes() -> do not edit by hand // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #include using namespace Rcpp; // to_int_checked SEXP to_int_checked(SEXP x); RcppExport SEXP _bigmemory_to_int_checked(SEXP xSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type x(xSEXP); rcpp_result_gen = Rcpp::wrap(to_int_checked(x)); return rcpp_result_gen; END_RCPP } // GetIndivMatrixElements SEXP GetIndivMatrixElements(SEXP bigMatAddr, SEXP col, SEXP row); RcppExport SEXP _bigmemory_GetIndivMatrixElements(SEXP bigMatAddrSEXP, SEXP colSEXP, SEXP rowSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type col(colSEXP); Rcpp::traits::input_parameter< SEXP >::type row(rowSEXP); rcpp_result_gen = Rcpp::wrap(GetIndivMatrixElements(bigMatAddr, col, row)); return rcpp_result_gen; END_RCPP } // GetIndivVectorMatrixElements SEXP GetIndivVectorMatrixElements(SEXP bigMatAddr, NumericVector elems); RcppExport SEXP _bigmemory_GetIndivVectorMatrixElements(SEXP bigMatAddrSEXP, SEXP elemsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< NumericVector >::type elems(elemsSEXP); rcpp_result_gen = Rcpp::wrap(GetIndivVectorMatrixElements(bigMatAddr, elems)); return rcpp_result_gen; END_RCPP } // ReorderRIntMatrix void ReorderRIntMatrix(SEXP matrixVector, SEXP nrow, SEXP ncol, SEXP orderVec); RcppExport SEXP _bigmemory_ReorderRIntMatrix(SEXP matrixVectorSEXP, SEXP nrowSEXP, SEXP ncolSEXP, SEXP orderVecSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type matrixVector(matrixVectorSEXP); Rcpp::traits::input_parameter< SEXP >::type nrow(nrowSEXP); Rcpp::traits::input_parameter< SEXP >::type ncol(ncolSEXP); Rcpp::traits::input_parameter< SEXP >::type orderVec(orderVecSEXP); ReorderRIntMatrix(matrixVector, nrow, ncol, orderVec); return R_NilValue; END_RCPP } // ReorderRNumericMatrix void ReorderRNumericMatrix(SEXP matrixVector, SEXP nrow, SEXP ncol, SEXP orderVec); RcppExport SEXP _bigmemory_ReorderRNumericMatrix(SEXP matrixVectorSEXP, SEXP nrowSEXP, SEXP ncolSEXP, SEXP orderVecSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type matrixVector(matrixVectorSEXP); Rcpp::traits::input_parameter< SEXP >::type nrow(nrowSEXP); Rcpp::traits::input_parameter< SEXP >::type ncol(ncolSEXP); Rcpp::traits::input_parameter< SEXP >::type orderVec(orderVecSEXP); ReorderRNumericMatrix(matrixVector, nrow, ncol, orderVec); return R_NilValue; END_RCPP } // ReorderBigMatrix void ReorderBigMatrix(SEXP address, SEXP orderVec); RcppExport SEXP _bigmemory_ReorderBigMatrix(SEXP addressSEXP, SEXP orderVecSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); Rcpp::traits::input_parameter< SEXP >::type orderVec(orderVecSEXP); ReorderBigMatrix(address, orderVec); return R_NilValue; END_RCPP } // ReorderRIntMatrixCols void ReorderRIntMatrixCols(Rcpp::IntegerMatrix matrixVector, SEXP nrow, SEXP ncol, Rcpp::IntegerVector orderVec); RcppExport SEXP _bigmemory_ReorderRIntMatrixCols(SEXP matrixVectorSEXP, SEXP nrowSEXP, SEXP ncolSEXP, SEXP orderVecSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< Rcpp::IntegerMatrix >::type matrixVector(matrixVectorSEXP); Rcpp::traits::input_parameter< SEXP >::type nrow(nrowSEXP); Rcpp::traits::input_parameter< SEXP >::type ncol(ncolSEXP); Rcpp::traits::input_parameter< Rcpp::IntegerVector >::type orderVec(orderVecSEXP); ReorderRIntMatrixCols(matrixVector, nrow, ncol, orderVec); return R_NilValue; END_RCPP } // ReorderRNumericMatrixCols void ReorderRNumericMatrixCols(Rcpp::NumericMatrix matrixVector, SEXP nrow, SEXP ncol, Rcpp::IntegerVector orderVec); RcppExport SEXP _bigmemory_ReorderRNumericMatrixCols(SEXP matrixVectorSEXP, SEXP nrowSEXP, SEXP ncolSEXP, SEXP orderVecSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< Rcpp::NumericMatrix >::type matrixVector(matrixVectorSEXP); Rcpp::traits::input_parameter< SEXP >::type nrow(nrowSEXP); Rcpp::traits::input_parameter< SEXP >::type ncol(ncolSEXP); Rcpp::traits::input_parameter< Rcpp::IntegerVector >::type orderVec(orderVecSEXP); ReorderRNumericMatrixCols(matrixVector, nrow, ncol, orderVec); return R_NilValue; END_RCPP } // ReorderRRawMatrixCols void ReorderRRawMatrixCols(Rcpp::RawMatrix matrixVector, SEXP nrow, SEXP ncol, Rcpp::IntegerVector orderVec); RcppExport SEXP _bigmemory_ReorderRRawMatrixCols(SEXP matrixVectorSEXP, SEXP nrowSEXP, SEXP ncolSEXP, SEXP orderVecSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< Rcpp::RawMatrix >::type matrixVector(matrixVectorSEXP); Rcpp::traits::input_parameter< SEXP >::type nrow(nrowSEXP); Rcpp::traits::input_parameter< SEXP >::type ncol(ncolSEXP); Rcpp::traits::input_parameter< Rcpp::IntegerVector >::type orderVec(orderVecSEXP); ReorderRRawMatrixCols(matrixVector, nrow, ncol, orderVec); return R_NilValue; END_RCPP } // ReorderBigMatrixCols void ReorderBigMatrixCols(SEXP address, SEXP orderVec); RcppExport SEXP _bigmemory_ReorderBigMatrixCols(SEXP addressSEXP, SEXP orderVecSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); Rcpp::traits::input_parameter< SEXP >::type orderVec(orderVecSEXP); ReorderBigMatrixCols(address, orderVec); return R_NilValue; END_RCPP } // OrderRIntMatrix SEXP OrderRIntMatrix(SEXP matrixVector, SEXP nrow, SEXP columns, SEXP naLast, SEXP decreasing); RcppExport SEXP _bigmemory_OrderRIntMatrix(SEXP matrixVectorSEXP, SEXP nrowSEXP, SEXP columnsSEXP, SEXP naLastSEXP, SEXP decreasingSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type matrixVector(matrixVectorSEXP); Rcpp::traits::input_parameter< SEXP >::type nrow(nrowSEXP); Rcpp::traits::input_parameter< SEXP >::type columns(columnsSEXP); Rcpp::traits::input_parameter< SEXP >::type naLast(naLastSEXP); Rcpp::traits::input_parameter< SEXP >::type decreasing(decreasingSEXP); rcpp_result_gen = Rcpp::wrap(OrderRIntMatrix(matrixVector, nrow, columns, naLast, decreasing)); return rcpp_result_gen; END_RCPP } // OrderRNumericMatrix SEXP OrderRNumericMatrix(SEXP matrixVector, SEXP nrow, SEXP columns, SEXP naLast, SEXP decreasing); RcppExport SEXP _bigmemory_OrderRNumericMatrix(SEXP matrixVectorSEXP, SEXP nrowSEXP, SEXP columnsSEXP, SEXP naLastSEXP, SEXP decreasingSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type matrixVector(matrixVectorSEXP); Rcpp::traits::input_parameter< SEXP >::type nrow(nrowSEXP); Rcpp::traits::input_parameter< SEXP >::type columns(columnsSEXP); Rcpp::traits::input_parameter< SEXP >::type naLast(naLastSEXP); Rcpp::traits::input_parameter< SEXP >::type decreasing(decreasingSEXP); rcpp_result_gen = Rcpp::wrap(OrderRNumericMatrix(matrixVector, nrow, columns, naLast, decreasing)); return rcpp_result_gen; END_RCPP } // OrderBigMatrix SEXP OrderBigMatrix(SEXP address, SEXP columns, SEXP naLast, SEXP decreasing); RcppExport SEXP _bigmemory_OrderBigMatrix(SEXP addressSEXP, SEXP columnsSEXP, SEXP naLastSEXP, SEXP decreasingSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); Rcpp::traits::input_parameter< SEXP >::type columns(columnsSEXP); Rcpp::traits::input_parameter< SEXP >::type naLast(naLastSEXP); Rcpp::traits::input_parameter< SEXP >::type decreasing(decreasingSEXP); rcpp_result_gen = Rcpp::wrap(OrderBigMatrix(address, columns, naLast, decreasing)); return rcpp_result_gen; END_RCPP } // OrderRIntMatrixCols SEXP OrderRIntMatrixCols(SEXP matrixVector, SEXP nrow, SEXP ncol, SEXP rows, SEXP naLast, SEXP decreasing); RcppExport SEXP _bigmemory_OrderRIntMatrixCols(SEXP matrixVectorSEXP, SEXP nrowSEXP, SEXP ncolSEXP, SEXP rowsSEXP, SEXP naLastSEXP, SEXP decreasingSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type matrixVector(matrixVectorSEXP); Rcpp::traits::input_parameter< SEXP >::type nrow(nrowSEXP); Rcpp::traits::input_parameter< SEXP >::type ncol(ncolSEXP); Rcpp::traits::input_parameter< SEXP >::type rows(rowsSEXP); Rcpp::traits::input_parameter< SEXP >::type naLast(naLastSEXP); Rcpp::traits::input_parameter< SEXP >::type decreasing(decreasingSEXP); rcpp_result_gen = Rcpp::wrap(OrderRIntMatrixCols(matrixVector, nrow, ncol, rows, naLast, decreasing)); return rcpp_result_gen; END_RCPP } // OrderRNumericMatrixCols SEXP OrderRNumericMatrixCols(SEXP matrixVector, SEXP nrow, SEXP ncol, SEXP rows, SEXP naLast, SEXP decreasing); RcppExport SEXP _bigmemory_OrderRNumericMatrixCols(SEXP matrixVectorSEXP, SEXP nrowSEXP, SEXP ncolSEXP, SEXP rowsSEXP, SEXP naLastSEXP, SEXP decreasingSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type matrixVector(matrixVectorSEXP); Rcpp::traits::input_parameter< SEXP >::type nrow(nrowSEXP); Rcpp::traits::input_parameter< SEXP >::type ncol(ncolSEXP); Rcpp::traits::input_parameter< SEXP >::type rows(rowsSEXP); Rcpp::traits::input_parameter< SEXP >::type naLast(naLastSEXP); Rcpp::traits::input_parameter< SEXP >::type decreasing(decreasingSEXP); rcpp_result_gen = Rcpp::wrap(OrderRNumericMatrixCols(matrixVector, nrow, ncol, rows, naLast, decreasing)); return rcpp_result_gen; END_RCPP } // OrderBigMatrixCols SEXP OrderBigMatrixCols(SEXP address, SEXP rows, SEXP naLast, SEXP decreasing); RcppExport SEXP _bigmemory_OrderBigMatrixCols(SEXP addressSEXP, SEXP rowsSEXP, SEXP naLastSEXP, SEXP decreasingSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); Rcpp::traits::input_parameter< SEXP >::type rows(rowsSEXP); Rcpp::traits::input_parameter< SEXP >::type naLast(naLastSEXP); Rcpp::traits::input_parameter< SEXP >::type decreasing(decreasingSEXP); rcpp_result_gen = Rcpp::wrap(OrderBigMatrixCols(address, rows, naLast, decreasing)); return rcpp_result_gen; END_RCPP } // CCleanIndices SEXP CCleanIndices(SEXP indices, SEXP rc); RcppExport SEXP _bigmemory_CCleanIndices(SEXP indicesSEXP, SEXP rcSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type indices(indicesSEXP); Rcpp::traits::input_parameter< SEXP >::type rc(rcSEXP); rcpp_result_gen = Rcpp::wrap(CCleanIndices(indices, rc)); return rcpp_result_gen; END_RCPP } // HasRowColNames SEXP HasRowColNames(SEXP address); RcppExport SEXP _bigmemory_HasRowColNames(SEXP addressSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); rcpp_result_gen = Rcpp::wrap(HasRowColNames(address)); return rcpp_result_gen; END_RCPP } // GetIndexRowNames SEXP GetIndexRowNames(SEXP address, SEXP indices_); RcppExport SEXP _bigmemory_GetIndexRowNames(SEXP addressSEXP, SEXP indices_SEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); Rcpp::traits::input_parameter< SEXP >::type indices_(indices_SEXP); rcpp_result_gen = Rcpp::wrap(GetIndexRowNames(address, indices_)); return rcpp_result_gen; END_RCPP } // GetIndexColNames SEXP GetIndexColNames(SEXP address, SEXP indices_); RcppExport SEXP _bigmemory_GetIndexColNames(SEXP addressSEXP, SEXP indices_SEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); Rcpp::traits::input_parameter< SEXP >::type indices_(indices_SEXP); rcpp_result_gen = Rcpp::wrap(GetIndexColNames(address, indices_)); return rcpp_result_gen; END_RCPP } // GetColumnNamesBM SEXP GetColumnNamesBM(SEXP address); RcppExport SEXP _bigmemory_GetColumnNamesBM(SEXP addressSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); rcpp_result_gen = Rcpp::wrap(GetColumnNamesBM(address)); return rcpp_result_gen; END_RCPP } // GetRowNamesBM SEXP GetRowNamesBM(SEXP address); RcppExport SEXP _bigmemory_GetRowNamesBM(SEXP addressSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); rcpp_result_gen = Rcpp::wrap(GetRowNamesBM(address)); return rcpp_result_gen; END_RCPP } // SetColumnNames void SetColumnNames(SEXP address, SEXP columnNames); RcppExport SEXP _bigmemory_SetColumnNames(SEXP addressSEXP, SEXP columnNamesSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); Rcpp::traits::input_parameter< SEXP >::type columnNames(columnNamesSEXP); SetColumnNames(address, columnNames); return R_NilValue; END_RCPP } // SetRowNames void SetRowNames(SEXP address, SEXP rowNames); RcppExport SEXP _bigmemory_SetRowNames(SEXP addressSEXP, SEXP rowNamesSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); Rcpp::traits::input_parameter< SEXP >::type rowNames(rowNamesSEXP); SetRowNames(address, rowNames); return R_NilValue; END_RCPP } // IsReadOnly SEXP IsReadOnly(SEXP bigMatAddr); RcppExport SEXP _bigmemory_IsReadOnly(SEXP bigMatAddrSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); rcpp_result_gen = Rcpp::wrap(IsReadOnly(bigMatAddr)); return rcpp_result_gen; END_RCPP } // CIsSubMatrix SEXP CIsSubMatrix(SEXP bigMatAddr); RcppExport SEXP _bigmemory_CIsSubMatrix(SEXP bigMatAddrSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); rcpp_result_gen = Rcpp::wrap(CIsSubMatrix(bigMatAddr)); return rcpp_result_gen; END_RCPP } // CGetNrow SEXP CGetNrow(SEXP bigMatAddr); RcppExport SEXP _bigmemory_CGetNrow(SEXP bigMatAddrSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); rcpp_result_gen = Rcpp::wrap(CGetNrow(bigMatAddr)); return rcpp_result_gen; END_RCPP } // CGetNcol SEXP CGetNcol(SEXP bigMatAddr); RcppExport SEXP _bigmemory_CGetNcol(SEXP bigMatAddrSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); rcpp_result_gen = Rcpp::wrap(CGetNcol(bigMatAddr)); return rcpp_result_gen; END_RCPP } // CGetType SEXP CGetType(SEXP bigMatAddr); RcppExport SEXP _bigmemory_CGetType(SEXP bigMatAddrSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); rcpp_result_gen = Rcpp::wrap(CGetType(bigMatAddr)); return rcpp_result_gen; END_RCPP } // IsSharedMemoryBigMatrix SEXP IsSharedMemoryBigMatrix(SEXP bigMatAddr); RcppExport SEXP _bigmemory_IsSharedMemoryBigMatrix(SEXP bigMatAddrSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); rcpp_result_gen = Rcpp::wrap(IsSharedMemoryBigMatrix(bigMatAddr)); return rcpp_result_gen; END_RCPP } // IsFileBackedBigMatrix SEXP IsFileBackedBigMatrix(SEXP bigMatAddr); RcppExport SEXP _bigmemory_IsFileBackedBigMatrix(SEXP bigMatAddrSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); rcpp_result_gen = Rcpp::wrap(IsFileBackedBigMatrix(bigMatAddr)); return rcpp_result_gen; END_RCPP } // IsSeparated SEXP IsSeparated(SEXP bigMatAddr); RcppExport SEXP _bigmemory_IsSeparated(SEXP bigMatAddrSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); rcpp_result_gen = Rcpp::wrap(IsSeparated(bigMatAddr)); return rcpp_result_gen; END_RCPP } // SetRowOffsetInfo void SetRowOffsetInfo(SEXP bigMatAddr, SEXP rowOffset, SEXP numRows); RcppExport SEXP _bigmemory_SetRowOffsetInfo(SEXP bigMatAddrSEXP, SEXP rowOffsetSEXP, SEXP numRowsSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type rowOffset(rowOffsetSEXP); Rcpp::traits::input_parameter< SEXP >::type numRows(numRowsSEXP); SetRowOffsetInfo(bigMatAddr, rowOffset, numRows); return R_NilValue; END_RCPP } // SetColumnOffsetInfo void SetColumnOffsetInfo(SEXP bigMatAddr, SEXP colOffset, SEXP numCols); RcppExport SEXP _bigmemory_SetColumnOffsetInfo(SEXP bigMatAddrSEXP, SEXP colOffsetSEXP, SEXP numColsSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type colOffset(colOffsetSEXP); Rcpp::traits::input_parameter< SEXP >::type numCols(numColsSEXP); SetColumnOffsetInfo(bigMatAddr, colOffset, numCols); return R_NilValue; END_RCPP } // GetRowOffset SEXP GetRowOffset(SEXP bigMatAddr); RcppExport SEXP _bigmemory_GetRowOffset(SEXP bigMatAddrSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); rcpp_result_gen = Rcpp::wrap(GetRowOffset(bigMatAddr)); return rcpp_result_gen; END_RCPP } // GetColOffset Rcpp::NumericVector GetColOffset(SEXP bigMatAddr); RcppExport SEXP _bigmemory_GetColOffset(SEXP bigMatAddrSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); rcpp_result_gen = Rcpp::wrap(GetColOffset(bigMatAddr)); return rcpp_result_gen; END_RCPP } // GetTotalColumns SEXP GetTotalColumns(SEXP bigMatAddr); RcppExport SEXP _bigmemory_GetTotalColumns(SEXP bigMatAddrSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); rcpp_result_gen = Rcpp::wrap(GetTotalColumns(bigMatAddr)); return rcpp_result_gen; END_RCPP } // GetTotalRows SEXP GetTotalRows(SEXP bigMatAddr); RcppExport SEXP _bigmemory_GetTotalRows(SEXP bigMatAddrSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); rcpp_result_gen = Rcpp::wrap(GetTotalRows(bigMatAddr)); return rcpp_result_gen; END_RCPP } // GetTypeString Rcpp::String GetTypeString(SEXP bigMatAddr); RcppExport SEXP _bigmemory_GetTypeString(SEXP bigMatAddrSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); rcpp_result_gen = Rcpp::wrap(GetTypeString(bigMatAddr)); return rcpp_result_gen; END_RCPP } // GetMatrixSize SEXP GetMatrixSize(SEXP bigMat); RcppExport SEXP _bigmemory_GetMatrixSize(SEXP bigMatSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMat(bigMatSEXP); rcpp_result_gen = Rcpp::wrap(GetMatrixSize(bigMat)); return rcpp_result_gen; END_RCPP } // MWhichBigMatrix SEXP MWhichBigMatrix(SEXP bigMatAddr, SEXP selectColumn, SEXP minVal, SEXP maxVal, SEXP chkMin, SEXP chkMax, SEXP opVal); RcppExport SEXP _bigmemory_MWhichBigMatrix(SEXP bigMatAddrSEXP, SEXP selectColumnSEXP, SEXP minValSEXP, SEXP maxValSEXP, SEXP chkMinSEXP, SEXP chkMaxSEXP, SEXP opValSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type selectColumn(selectColumnSEXP); Rcpp::traits::input_parameter< SEXP >::type minVal(minValSEXP); Rcpp::traits::input_parameter< SEXP >::type maxVal(maxValSEXP); Rcpp::traits::input_parameter< SEXP >::type chkMin(chkMinSEXP); Rcpp::traits::input_parameter< SEXP >::type chkMax(chkMaxSEXP); Rcpp::traits::input_parameter< SEXP >::type opVal(opValSEXP); rcpp_result_gen = Rcpp::wrap(MWhichBigMatrix(bigMatAddr, selectColumn, minVal, maxVal, chkMin, chkMax, opVal)); return rcpp_result_gen; END_RCPP } // MWhichRIntMatrix SEXP MWhichRIntMatrix(SEXP matrixVector, SEXP nrow, SEXP selectColumn, SEXP minVal, SEXP maxVal, SEXP chkMin, SEXP chkMax, SEXP opVal); RcppExport SEXP _bigmemory_MWhichRIntMatrix(SEXP matrixVectorSEXP, SEXP nrowSEXP, SEXP selectColumnSEXP, SEXP minValSEXP, SEXP maxValSEXP, SEXP chkMinSEXP, SEXP chkMaxSEXP, SEXP opValSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type matrixVector(matrixVectorSEXP); Rcpp::traits::input_parameter< SEXP >::type nrow(nrowSEXP); Rcpp::traits::input_parameter< SEXP >::type selectColumn(selectColumnSEXP); Rcpp::traits::input_parameter< SEXP >::type minVal(minValSEXP); Rcpp::traits::input_parameter< SEXP >::type maxVal(maxValSEXP); Rcpp::traits::input_parameter< SEXP >::type chkMin(chkMinSEXP); Rcpp::traits::input_parameter< SEXP >::type chkMax(chkMaxSEXP); Rcpp::traits::input_parameter< SEXP >::type opVal(opValSEXP); rcpp_result_gen = Rcpp::wrap(MWhichRIntMatrix(matrixVector, nrow, selectColumn, minVal, maxVal, chkMin, chkMax, opVal)); return rcpp_result_gen; END_RCPP } // MWhichRNumericMatrix SEXP MWhichRNumericMatrix(SEXP matrixVector, SEXP nrow, SEXP selectColumn, SEXP minVal, SEXP maxVal, SEXP chkMin, SEXP chkMax, SEXP opVal); RcppExport SEXP _bigmemory_MWhichRNumericMatrix(SEXP matrixVectorSEXP, SEXP nrowSEXP, SEXP selectColumnSEXP, SEXP minValSEXP, SEXP maxValSEXP, SEXP chkMinSEXP, SEXP chkMaxSEXP, SEXP opValSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type matrixVector(matrixVectorSEXP); Rcpp::traits::input_parameter< SEXP >::type nrow(nrowSEXP); Rcpp::traits::input_parameter< SEXP >::type selectColumn(selectColumnSEXP); Rcpp::traits::input_parameter< SEXP >::type minVal(minValSEXP); Rcpp::traits::input_parameter< SEXP >::type maxVal(maxValSEXP); Rcpp::traits::input_parameter< SEXP >::type chkMin(chkMinSEXP); Rcpp::traits::input_parameter< SEXP >::type chkMax(chkMaxSEXP); Rcpp::traits::input_parameter< SEXP >::type opVal(opValSEXP); rcpp_result_gen = Rcpp::wrap(MWhichRNumericMatrix(matrixVector, nrow, selectColumn, minVal, maxVal, chkMin, chkMax, opVal)); return rcpp_result_gen; END_RCPP } // CCountLines SEXP CCountLines(SEXP fileName); RcppExport SEXP _bigmemory_CCountLines(SEXP fileNameSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type fileName(fileNameSEXP); rcpp_result_gen = Rcpp::wrap(CCountLines(fileName)); return rcpp_result_gen; END_RCPP } // ReadMatrix SEXP ReadMatrix(SEXP fileName, SEXP bigMatAddr, SEXP firstLine, SEXP numLines, SEXP numCols, SEXP separator, SEXP hasRowNames, SEXP useRowNames); RcppExport SEXP _bigmemory_ReadMatrix(SEXP fileNameSEXP, SEXP bigMatAddrSEXP, SEXP firstLineSEXP, SEXP numLinesSEXP, SEXP numColsSEXP, SEXP separatorSEXP, SEXP hasRowNamesSEXP, SEXP useRowNamesSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type fileName(fileNameSEXP); Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type firstLine(firstLineSEXP); Rcpp::traits::input_parameter< SEXP >::type numLines(numLinesSEXP); Rcpp::traits::input_parameter< SEXP >::type numCols(numColsSEXP); Rcpp::traits::input_parameter< SEXP >::type separator(separatorSEXP); Rcpp::traits::input_parameter< SEXP >::type hasRowNames(hasRowNamesSEXP); Rcpp::traits::input_parameter< SEXP >::type useRowNames(useRowNamesSEXP); rcpp_result_gen = Rcpp::wrap(ReadMatrix(fileName, bigMatAddr, firstLine, numLines, numCols, separator, hasRowNames, useRowNames)); return rcpp_result_gen; END_RCPP } // WriteMatrix void WriteMatrix(SEXP bigMatAddr, SEXP fileName, SEXP rowNames, SEXP colNames, SEXP sep); RcppExport SEXP _bigmemory_WriteMatrix(SEXP bigMatAddrSEXP, SEXP fileNameSEXP, SEXP rowNamesSEXP, SEXP colNamesSEXP, SEXP sepSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type fileName(fileNameSEXP); Rcpp::traits::input_parameter< SEXP >::type rowNames(rowNamesSEXP); Rcpp::traits::input_parameter< SEXP >::type colNames(colNamesSEXP); Rcpp::traits::input_parameter< SEXP >::type sep(sepSEXP); WriteMatrix(bigMatAddr, fileName, rowNames, colNames, sep); return R_NilValue; END_RCPP } // GetMatrixElements SEXP GetMatrixElements(SEXP bigMatAddr, SEXP col, SEXP row); RcppExport SEXP _bigmemory_GetMatrixElements(SEXP bigMatAddrSEXP, SEXP colSEXP, SEXP rowSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type col(colSEXP); Rcpp::traits::input_parameter< SEXP >::type row(rowSEXP); rcpp_result_gen = Rcpp::wrap(GetMatrixElements(bigMatAddr, col, row)); return rcpp_result_gen; END_RCPP } // GetMatrixRows SEXP GetMatrixRows(SEXP bigMatAddr, SEXP row); RcppExport SEXP _bigmemory_GetMatrixRows(SEXP bigMatAddrSEXP, SEXP rowSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type row(rowSEXP); rcpp_result_gen = Rcpp::wrap(GetMatrixRows(bigMatAddr, row)); return rcpp_result_gen; END_RCPP } // GetMatrixCols SEXP GetMatrixCols(SEXP bigMatAddr, SEXP col); RcppExport SEXP _bigmemory_GetMatrixCols(SEXP bigMatAddrSEXP, SEXP colSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type col(colSEXP); rcpp_result_gen = Rcpp::wrap(GetMatrixCols(bigMatAddr, col)); return rcpp_result_gen; END_RCPP } // GetMatrixAll SEXP GetMatrixAll(SEXP bigMatAddr); RcppExport SEXP _bigmemory_GetMatrixAll(SEXP bigMatAddrSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); rcpp_result_gen = Rcpp::wrap(GetMatrixAll(bigMatAddr)); return rcpp_result_gen; END_RCPP } // SetMatrixElements void SetMatrixElements(SEXP bigMatAddr, SEXP col, SEXP row, SEXP values); RcppExport SEXP _bigmemory_SetMatrixElements(SEXP bigMatAddrSEXP, SEXP colSEXP, SEXP rowSEXP, SEXP valuesSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type col(colSEXP); Rcpp::traits::input_parameter< SEXP >::type row(rowSEXP); Rcpp::traits::input_parameter< SEXP >::type values(valuesSEXP); SetMatrixElements(bigMatAddr, col, row, values); return R_NilValue; END_RCPP } // SetIndivVectorMatrixElements void SetIndivVectorMatrixElements(SEXP bigMatAddr, NumericVector elems, NumericVector inVec); RcppExport SEXP _bigmemory_SetIndivVectorMatrixElements(SEXP bigMatAddrSEXP, SEXP elemsSEXP, SEXP inVecSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< NumericVector >::type elems(elemsSEXP); Rcpp::traits::input_parameter< NumericVector >::type inVec(inVecSEXP); SetIndivVectorMatrixElements(bigMatAddr, elems, inVec); return R_NilValue; END_RCPP } // SetIndivMatrixElements void SetIndivMatrixElements(SEXP bigMatAddr, SEXP col, SEXP row, SEXP values); RcppExport SEXP _bigmemory_SetIndivMatrixElements(SEXP bigMatAddrSEXP, SEXP colSEXP, SEXP rowSEXP, SEXP valuesSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type col(colSEXP); Rcpp::traits::input_parameter< SEXP >::type row(rowSEXP); Rcpp::traits::input_parameter< SEXP >::type values(valuesSEXP); SetIndivMatrixElements(bigMatAddr, col, row, values); return R_NilValue; END_RCPP } // SetMatrixAll void SetMatrixAll(SEXP bigMatAddr, SEXP values); RcppExport SEXP _bigmemory_SetMatrixAll(SEXP bigMatAddrSEXP, SEXP valuesSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type values(valuesSEXP); SetMatrixAll(bigMatAddr, values); return R_NilValue; END_RCPP } // SetMatrixCols void SetMatrixCols(SEXP bigMatAddr, SEXP col, SEXP values); RcppExport SEXP _bigmemory_SetMatrixCols(SEXP bigMatAddrSEXP, SEXP colSEXP, SEXP valuesSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type col(colSEXP); Rcpp::traits::input_parameter< SEXP >::type values(valuesSEXP); SetMatrixCols(bigMatAddr, col, values); return R_NilValue; END_RCPP } // SetMatrixRows void SetMatrixRows(SEXP bigMatAddr, SEXP row, SEXP values); RcppExport SEXP _bigmemory_SetMatrixRows(SEXP bigMatAddrSEXP, SEXP rowSEXP, SEXP valuesSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type bigMatAddr(bigMatAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type row(rowSEXP); Rcpp::traits::input_parameter< SEXP >::type values(valuesSEXP); SetMatrixRows(bigMatAddr, row, values); return R_NilValue; END_RCPP } // CreateSharedMatrix SEXP CreateSharedMatrix(SEXP row, SEXP col, SEXP colnames, SEXP rownames, SEXP typeLength, SEXP ini, SEXP separated); RcppExport SEXP _bigmemory_CreateSharedMatrix(SEXP rowSEXP, SEXP colSEXP, SEXP colnamesSEXP, SEXP rownamesSEXP, SEXP typeLengthSEXP, SEXP iniSEXP, SEXP separatedSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type row(rowSEXP); Rcpp::traits::input_parameter< SEXP >::type col(colSEXP); Rcpp::traits::input_parameter< SEXP >::type colnames(colnamesSEXP); Rcpp::traits::input_parameter< SEXP >::type rownames(rownamesSEXP); Rcpp::traits::input_parameter< SEXP >::type typeLength(typeLengthSEXP); Rcpp::traits::input_parameter< SEXP >::type ini(iniSEXP); Rcpp::traits::input_parameter< SEXP >::type separated(separatedSEXP); rcpp_result_gen = Rcpp::wrap(CreateSharedMatrix(row, col, colnames, rownames, typeLength, ini, separated)); return rcpp_result_gen; END_RCPP } // CreateLocalMatrix SEXP CreateLocalMatrix(SEXP row, SEXP col, SEXP colnames, SEXP rownames, SEXP typeLength, SEXP ini, SEXP separated); RcppExport SEXP _bigmemory_CreateLocalMatrix(SEXP rowSEXP, SEXP colSEXP, SEXP colnamesSEXP, SEXP rownamesSEXP, SEXP typeLengthSEXP, SEXP iniSEXP, SEXP separatedSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type row(rowSEXP); Rcpp::traits::input_parameter< SEXP >::type col(colSEXP); Rcpp::traits::input_parameter< SEXP >::type colnames(colnamesSEXP); Rcpp::traits::input_parameter< SEXP >::type rownames(rownamesSEXP); Rcpp::traits::input_parameter< SEXP >::type typeLength(typeLengthSEXP); Rcpp::traits::input_parameter< SEXP >::type ini(iniSEXP); Rcpp::traits::input_parameter< SEXP >::type separated(separatedSEXP); rcpp_result_gen = Rcpp::wrap(CreateLocalMatrix(row, col, colnames, rownames, typeLength, ini, separated)); return rcpp_result_gen; END_RCPP } // CreateFileBackedBigMatrix SEXP CreateFileBackedBigMatrix(SEXP fileName, SEXP filePath, SEXP row, SEXP col, SEXP colnames, SEXP rownames, SEXP typeLength, SEXP ini, SEXP separated); RcppExport SEXP _bigmemory_CreateFileBackedBigMatrix(SEXP fileNameSEXP, SEXP filePathSEXP, SEXP rowSEXP, SEXP colSEXP, SEXP colnamesSEXP, SEXP rownamesSEXP, SEXP typeLengthSEXP, SEXP iniSEXP, SEXP separatedSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type fileName(fileNameSEXP); Rcpp::traits::input_parameter< SEXP >::type filePath(filePathSEXP); Rcpp::traits::input_parameter< SEXP >::type row(rowSEXP); Rcpp::traits::input_parameter< SEXP >::type col(colSEXP); Rcpp::traits::input_parameter< SEXP >::type colnames(colnamesSEXP); Rcpp::traits::input_parameter< SEXP >::type rownames(rownamesSEXP); Rcpp::traits::input_parameter< SEXP >::type typeLength(typeLengthSEXP); Rcpp::traits::input_parameter< SEXP >::type ini(iniSEXP); Rcpp::traits::input_parameter< SEXP >::type separated(separatedSEXP); rcpp_result_gen = Rcpp::wrap(CreateFileBackedBigMatrix(fileName, filePath, row, col, colnames, rownames, typeLength, ini, separated)); return rcpp_result_gen; END_RCPP } // CAttachSharedBigMatrix SEXP CAttachSharedBigMatrix(SEXP sharedName, SEXP rows, SEXP cols, SEXP rowNames, SEXP colNames, SEXP typeLength, SEXP separated, SEXP readOnly); RcppExport SEXP _bigmemory_CAttachSharedBigMatrix(SEXP sharedNameSEXP, SEXP rowsSEXP, SEXP colsSEXP, SEXP rowNamesSEXP, SEXP colNamesSEXP, SEXP typeLengthSEXP, SEXP separatedSEXP, SEXP readOnlySEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type sharedName(sharedNameSEXP); Rcpp::traits::input_parameter< SEXP >::type rows(rowsSEXP); Rcpp::traits::input_parameter< SEXP >::type cols(colsSEXP); Rcpp::traits::input_parameter< SEXP >::type rowNames(rowNamesSEXP); Rcpp::traits::input_parameter< SEXP >::type colNames(colNamesSEXP); Rcpp::traits::input_parameter< SEXP >::type typeLength(typeLengthSEXP); Rcpp::traits::input_parameter< SEXP >::type separated(separatedSEXP); Rcpp::traits::input_parameter< SEXP >::type readOnly(readOnlySEXP); rcpp_result_gen = Rcpp::wrap(CAttachSharedBigMatrix(sharedName, rows, cols, rowNames, colNames, typeLength, separated, readOnly)); return rcpp_result_gen; END_RCPP } // CAttachFileBackedBigMatrix SEXP CAttachFileBackedBigMatrix(SEXP fileName, SEXP filePath, SEXP rows, SEXP cols, SEXP rowNames, SEXP colNames, SEXP typeLength, SEXP separated, SEXP readOnly); RcppExport SEXP _bigmemory_CAttachFileBackedBigMatrix(SEXP fileNameSEXP, SEXP filePathSEXP, SEXP rowsSEXP, SEXP colsSEXP, SEXP rowNamesSEXP, SEXP colNamesSEXP, SEXP typeLengthSEXP, SEXP separatedSEXP, SEXP readOnlySEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type fileName(fileNameSEXP); Rcpp::traits::input_parameter< SEXP >::type filePath(filePathSEXP); Rcpp::traits::input_parameter< SEXP >::type rows(rowsSEXP); Rcpp::traits::input_parameter< SEXP >::type cols(colsSEXP); Rcpp::traits::input_parameter< SEXP >::type rowNames(rowNamesSEXP); Rcpp::traits::input_parameter< SEXP >::type colNames(colNamesSEXP); Rcpp::traits::input_parameter< SEXP >::type typeLength(typeLengthSEXP); Rcpp::traits::input_parameter< SEXP >::type separated(separatedSEXP); Rcpp::traits::input_parameter< SEXP >::type readOnly(readOnlySEXP); rcpp_result_gen = Rcpp::wrap(CAttachFileBackedBigMatrix(fileName, filePath, rows, cols, rowNames, colNames, typeLength, separated, readOnly)); return rcpp_result_gen; END_RCPP } // SharedName SEXP SharedName(SEXP address); RcppExport SEXP _bigmemory_SharedName(SEXP addressSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); rcpp_result_gen = Rcpp::wrap(SharedName(address)); return rcpp_result_gen; END_RCPP } // FileName SEXP FileName(SEXP address); RcppExport SEXP _bigmemory_FileName(SEXP addressSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); rcpp_result_gen = Rcpp::wrap(FileName(address)); return rcpp_result_gen; END_RCPP } // DirName SEXP DirName(SEXP address); RcppExport SEXP _bigmemory_DirName(SEXP addressSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); rcpp_result_gen = Rcpp::wrap(DirName(address)); return rcpp_result_gen; END_RCPP } // Flush SEXP Flush(SEXP address); RcppExport SEXP _bigmemory_Flush(SEXP addressSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); rcpp_result_gen = Rcpp::wrap(Flush(address)); return rcpp_result_gen; END_RCPP } // IsShared SEXP IsShared(SEXP address); RcppExport SEXP _bigmemory_IsShared(SEXP addressSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); rcpp_result_gen = Rcpp::wrap(IsShared(address)); return rcpp_result_gen; END_RCPP } // isnil SEXP isnil(SEXP address); RcppExport SEXP _bigmemory_isnil(SEXP addressSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type address(addressSEXP); rcpp_result_gen = Rcpp::wrap(isnil(address)); return rcpp_result_gen; END_RCPP } // CDeepCopy SEXP CDeepCopy(SEXP inAddr, SEXP outAddr, SEXP rowInds, SEXP colInds, SEXP typecast_warning); RcppExport SEXP _bigmemory_CDeepCopy(SEXP inAddrSEXP, SEXP outAddrSEXP, SEXP rowIndsSEXP, SEXP colIndsSEXP, SEXP typecast_warningSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< SEXP >::type inAddr(inAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type outAddr(outAddrSEXP); Rcpp::traits::input_parameter< SEXP >::type rowInds(rowIndsSEXP); Rcpp::traits::input_parameter< SEXP >::type colInds(colIndsSEXP); Rcpp::traits::input_parameter< SEXP >::type typecast_warning(typecast_warningSEXP); rcpp_result_gen = Rcpp::wrap(CDeepCopy(inAddr, outAddr, rowInds, colInds, typecast_warning)); return rcpp_result_gen; END_RCPP } static const R_CallMethodDef CallEntries[] = { {"_bigmemory_to_int_checked", (DL_FUNC) &_bigmemory_to_int_checked, 1}, {"_bigmemory_GetIndivMatrixElements", (DL_FUNC) &_bigmemory_GetIndivMatrixElements, 3}, {"_bigmemory_GetIndivVectorMatrixElements", (DL_FUNC) &_bigmemory_GetIndivVectorMatrixElements, 2}, {"_bigmemory_ReorderRIntMatrix", (DL_FUNC) &_bigmemory_ReorderRIntMatrix, 4}, {"_bigmemory_ReorderRNumericMatrix", (DL_FUNC) &_bigmemory_ReorderRNumericMatrix, 4}, {"_bigmemory_ReorderBigMatrix", (DL_FUNC) &_bigmemory_ReorderBigMatrix, 2}, {"_bigmemory_ReorderRIntMatrixCols", (DL_FUNC) &_bigmemory_ReorderRIntMatrixCols, 4}, {"_bigmemory_ReorderRNumericMatrixCols", (DL_FUNC) &_bigmemory_ReorderRNumericMatrixCols, 4}, {"_bigmemory_ReorderRRawMatrixCols", (DL_FUNC) &_bigmemory_ReorderRRawMatrixCols, 4}, {"_bigmemory_ReorderBigMatrixCols", (DL_FUNC) &_bigmemory_ReorderBigMatrixCols, 2}, {"_bigmemory_OrderRIntMatrix", (DL_FUNC) &_bigmemory_OrderRIntMatrix, 5}, {"_bigmemory_OrderRNumericMatrix", (DL_FUNC) &_bigmemory_OrderRNumericMatrix, 5}, {"_bigmemory_OrderBigMatrix", (DL_FUNC) &_bigmemory_OrderBigMatrix, 4}, {"_bigmemory_OrderRIntMatrixCols", (DL_FUNC) &_bigmemory_OrderRIntMatrixCols, 6}, {"_bigmemory_OrderRNumericMatrixCols", (DL_FUNC) &_bigmemory_OrderRNumericMatrixCols, 6}, {"_bigmemory_OrderBigMatrixCols", (DL_FUNC) &_bigmemory_OrderBigMatrixCols, 4}, {"_bigmemory_CCleanIndices", (DL_FUNC) &_bigmemory_CCleanIndices, 2}, {"_bigmemory_HasRowColNames", (DL_FUNC) &_bigmemory_HasRowColNames, 1}, {"_bigmemory_GetIndexRowNames", (DL_FUNC) &_bigmemory_GetIndexRowNames, 2}, {"_bigmemory_GetIndexColNames", (DL_FUNC) &_bigmemory_GetIndexColNames, 2}, {"_bigmemory_GetColumnNamesBM", (DL_FUNC) &_bigmemory_GetColumnNamesBM, 1}, {"_bigmemory_GetRowNamesBM", (DL_FUNC) &_bigmemory_GetRowNamesBM, 1}, {"_bigmemory_SetColumnNames", (DL_FUNC) &_bigmemory_SetColumnNames, 2}, {"_bigmemory_SetRowNames", (DL_FUNC) &_bigmemory_SetRowNames, 2}, {"_bigmemory_IsReadOnly", (DL_FUNC) &_bigmemory_IsReadOnly, 1}, {"_bigmemory_CIsSubMatrix", (DL_FUNC) &_bigmemory_CIsSubMatrix, 1}, {"_bigmemory_CGetNrow", (DL_FUNC) &_bigmemory_CGetNrow, 1}, {"_bigmemory_CGetNcol", (DL_FUNC) &_bigmemory_CGetNcol, 1}, {"_bigmemory_CGetType", (DL_FUNC) &_bigmemory_CGetType, 1}, {"_bigmemory_IsSharedMemoryBigMatrix", (DL_FUNC) &_bigmemory_IsSharedMemoryBigMatrix, 1}, {"_bigmemory_IsFileBackedBigMatrix", (DL_FUNC) &_bigmemory_IsFileBackedBigMatrix, 1}, {"_bigmemory_IsSeparated", (DL_FUNC) &_bigmemory_IsSeparated, 1}, {"_bigmemory_SetRowOffsetInfo", (DL_FUNC) &_bigmemory_SetRowOffsetInfo, 3}, {"_bigmemory_SetColumnOffsetInfo", (DL_FUNC) &_bigmemory_SetColumnOffsetInfo, 3}, {"_bigmemory_GetRowOffset", (DL_FUNC) &_bigmemory_GetRowOffset, 1}, {"_bigmemory_GetColOffset", (DL_FUNC) &_bigmemory_GetColOffset, 1}, {"_bigmemory_GetTotalColumns", (DL_FUNC) &_bigmemory_GetTotalColumns, 1}, {"_bigmemory_GetTotalRows", (DL_FUNC) &_bigmemory_GetTotalRows, 1}, {"_bigmemory_GetTypeString", (DL_FUNC) &_bigmemory_GetTypeString, 1}, {"_bigmemory_GetMatrixSize", (DL_FUNC) &_bigmemory_GetMatrixSize, 1}, {"_bigmemory_MWhichBigMatrix", (DL_FUNC) &_bigmemory_MWhichBigMatrix, 7}, {"_bigmemory_MWhichRIntMatrix", (DL_FUNC) &_bigmemory_MWhichRIntMatrix, 8}, {"_bigmemory_MWhichRNumericMatrix", (DL_FUNC) &_bigmemory_MWhichRNumericMatrix, 8}, {"_bigmemory_CCountLines", (DL_FUNC) &_bigmemory_CCountLines, 1}, {"_bigmemory_ReadMatrix", (DL_FUNC) &_bigmemory_ReadMatrix, 8}, {"_bigmemory_WriteMatrix", (DL_FUNC) &_bigmemory_WriteMatrix, 5}, {"_bigmemory_GetMatrixElements", (DL_FUNC) &_bigmemory_GetMatrixElements, 3}, {"_bigmemory_GetMatrixRows", (DL_FUNC) &_bigmemory_GetMatrixRows, 2}, {"_bigmemory_GetMatrixCols", (DL_FUNC) &_bigmemory_GetMatrixCols, 2}, {"_bigmemory_GetMatrixAll", (DL_FUNC) &_bigmemory_GetMatrixAll, 1}, {"_bigmemory_SetMatrixElements", (DL_FUNC) &_bigmemory_SetMatrixElements, 4}, {"_bigmemory_SetIndivVectorMatrixElements", (DL_FUNC) &_bigmemory_SetIndivVectorMatrixElements, 3}, {"_bigmemory_SetIndivMatrixElements", (DL_FUNC) &_bigmemory_SetIndivMatrixElements, 4}, {"_bigmemory_SetMatrixAll", (DL_FUNC) &_bigmemory_SetMatrixAll, 2}, {"_bigmemory_SetMatrixCols", (DL_FUNC) &_bigmemory_SetMatrixCols, 3}, {"_bigmemory_SetMatrixRows", (DL_FUNC) &_bigmemory_SetMatrixRows, 3}, {"_bigmemory_CreateSharedMatrix", (DL_FUNC) &_bigmemory_CreateSharedMatrix, 7}, {"_bigmemory_CreateLocalMatrix", (DL_FUNC) &_bigmemory_CreateLocalMatrix, 7}, {"_bigmemory_CreateFileBackedBigMatrix", (DL_FUNC) &_bigmemory_CreateFileBackedBigMatrix, 9}, {"_bigmemory_CAttachSharedBigMatrix", (DL_FUNC) &_bigmemory_CAttachSharedBigMatrix, 8}, {"_bigmemory_CAttachFileBackedBigMatrix", (DL_FUNC) &_bigmemory_CAttachFileBackedBigMatrix, 9}, {"_bigmemory_SharedName", (DL_FUNC) &_bigmemory_SharedName, 1}, {"_bigmemory_FileName", (DL_FUNC) &_bigmemory_FileName, 1}, {"_bigmemory_DirName", (DL_FUNC) &_bigmemory_DirName, 1}, {"_bigmemory_Flush", (DL_FUNC) &_bigmemory_Flush, 1}, {"_bigmemory_IsShared", (DL_FUNC) &_bigmemory_IsShared, 1}, {"_bigmemory_isnil", (DL_FUNC) &_bigmemory_isnil, 1}, {"_bigmemory_CDeepCopy", (DL_FUNC) &_bigmemory_CDeepCopy, 5}, {NULL, NULL, 0} }; RcppExport void R_init_bigmemory(DllInfo *dll) { R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); R_useDynamicSymbols(dll, FALSE); } bigmemory/src/BigMatrix.cpp0000644000175100001440000011021713576750523015462 0ustar hornikusers#include #include #include #include //#include // to remove files #include // to truncate files #include #include #include #include #include #include #include #include #include #include #include "bigmemory/BigMatrix.h" //#include "uuid/uuid.h" #define COND_EXCEPTION_PRINT(bYes) \ if (bYes) \ { \ Rprintf("%s\n", e.what()); \ Rprintf("%s line %d\n", __FILE__, __LINE__); \ } \ #define COND_PRINT(bYes, str, format) \ if (bYes) Rprintf(str, format); #define DEBUG false using namespace std; using namespace boost; using namespace boost::interprocess; template std::string ttos(T i) { stringstream s; s << i; return s.str(); } template void CreateLocalMatrix( const index_type &nrow, const index_type &ncol, void* &p, index_type &allocationSize ) { allocationSize = nrow*ncol*sizeof(T); p = new char[allocationSize]; } template void CreateLocalSepMatrix( const index_type &nrow, const index_type &ncol, void* &p, index_type &allocationSize ) { char** pt = new char*[ncol]; index_type vecAllocSize = nrow*sizeof(T); allocationSize = ncol*vecAllocSize; index_type i; bool fail=false; try { for (i=0; i < ncol; ++i) { pt[i] = new char[vecAllocSize]; } p = reinterpret_cast(pt); } catch(std::exception &e) { COND_EXCEPTION_PRINT(DEBUG); while(i > 1) { delete [] pt[--i]; } delete [] pt; fail=true; } if (!fail) { p = reinterpret_cast(pt); } else { p = NULL; allocationSize = 0; } } bool LocalBigMatrix::create(const index_type numRow, const index_type numCol, const int matrixType, const bool sepCols) { try { _nrow = numRow; _totalRows = _nrow; _ncol = numCol; _totalCols = _ncol; _matType = matrixType; _sepCols = sepCols; if (_sepCols) { switch(_matType) { case 1: CreateLocalSepMatrix(_nrow, _ncol, _pdata, _allocationSize); break; case 2: CreateLocalSepMatrix(_nrow, _ncol, _pdata, _allocationSize); break; case 3: CreateLocalSepMatrix(_nrow, _ncol, _pdata, _allocationSize); break; case 4: CreateLocalSepMatrix(_nrow, _ncol, _pdata, _allocationSize); break; case 6: CreateLocalSepMatrix(_nrow, _ncol, _pdata, _allocationSize); break; case 8: CreateLocalSepMatrix(_nrow, _ncol, _pdata, _allocationSize); } } else { switch(_matType) { case 1: CreateLocalMatrix(_nrow, _ncol, _pdata, _allocationSize); break; case 2: CreateLocalMatrix(_nrow, _ncol, _pdata, _allocationSize); break; case 3: CreateLocalMatrix(_nrow, _ncol, _pdata, _allocationSize); break; case 4: CreateLocalMatrix(_nrow, _ncol, _pdata, _allocationSize); break; case 6: CreateLocalMatrix(_nrow, _ncol, _pdata, _allocationSize); break; case 8: CreateLocalMatrix(_nrow, _ncol, _pdata, _allocationSize); } } if (_pdata == NULL) { return false; } return true; } catch(std::exception &e) { COND_EXCEPTION_PRINT(DEBUG); return false; } } bool LocalBigMatrix::destroy() { try { if (_sepCols) { char** p = reinterpret_cast(_pdata); index_type i; for (i=0; i < _ncol; ++i) { delete [] p[i]; } delete [] p; } else { delete [] reinterpret_cast(_pdata); } return true; } catch(std::exception &e) { COND_EXCEPTION_PRINT(DEBUG); return false; } } bool SharedBigMatrix::create_uuid() { size_t string_len = 24; std::string letters("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); Rcpp::NumericVector inds= Rcpp::runif(string_len, -0.49, letters.size()-0.51); _uuid.clear(); for (unsigned int i=0; i < string_len; ++i) { _uuid.push_back(letters[round(inds[i])]); } #ifdef DARWIN // Darwin has a limit on the size of share memory names. _uuid.resize(5); #endif /* uuid_t u; char c[40]; uuid_generate_time(u); uuid_unparse_lower(u, c); _uuid = c; #ifdef DARWIN _uuid.resize(5); #endif */ return true; } template void CreateSharedSepMatrix( const std::string &sharedName, MappedRegionPtrs &dataRegionPtrs, const index_type nrow, const index_type ncol, void* &p, index_type &allocationSize) { T** pMat = new T*[ncol]; index_type i; dataRegionPtrs.resize(ncol); bool fail = false; for (i=0; i < ncol; ++i) { try { shared_memory_object::remove( (sharedName+"_column_"+ttos(i)).c_str() ); shared_memory_object shm(create_only, (sharedName + "_column_" + ttos(i)).c_str(), read_write); shm.truncate( nrow*sizeof(T) ); dataRegionPtrs[i] = MappedRegionPtr( new MappedRegion(shm, read_write) ); pMat[i] = reinterpret_cast( dataRegionPtrs[i]->get_address()); } catch (interprocess_exception &e) { COND_EXCEPTION_PRINT(DEBUG); index_type j; for (j=0; j < i; ++j) { shared_memory_object::remove( (sharedName+"_column_"+ttos(j)).c_str()); } delete[] pMat; fail = true; } } if (!fail) { allocationSize = ncol*nrow*sizeof(T); p = reinterpret_cast(pMat); } else { allocationSize = 0; p = NULL; } } template void CreateSharedMatrix( const std::string &sharedName, MappedRegionPtrs &dataRegionPtrs, const index_type nrow, const index_type ncol, void* &p, index_type &allocationSize) { //shared_memory_object::remove( (sharedName.c_str()) ); shared_memory_object shm(create_only, sharedName.c_str(), read_write); shm.truncate( nrow*ncol*sizeof(T) ); dataRegionPtrs.push_back( MappedRegionPtr(new MappedRegion(shm, read_write))); allocationSize = nrow*ncol*sizeof(T); p = dataRegionPtrs[0]->get_address(); } bool SharedMemoryBigMatrix::create(const index_type numRow, const index_type numCol, const int matrixType, const bool sepCols) { using namespace boost::interprocess; unsigned int retry=0; try { do { if (!create_uuid()) { return false; } try { _pdata = NULL; _nrow = numRow; _totalRows = _nrow; _ncol = numCol; _totalCols = _ncol; _matType = matrixType; _sepCols = sepCols; _sharedName=_uuid; #ifndef INTERLOCKED_EXCHANGE_HACK // Create the associated mutex and counter; named_mutex mutex(open_or_create, (_sharedName+"_bigmemory_counter_mutex").c_str()); mutex.lock(); #endif _counter.init( _sharedName+"_counter" ); #ifndef INTERLOCKED_EXCHANGE_HACK mutex.unlock(); named_mutex::remove((_sharedName+"_bigmemory_counter_mutex").c_str()); #endif if (_sepCols) { switch(_matType) { case 1: CreateSharedSepMatrix(_sharedName, _dataRegionPtrs, _nrow, _ncol, _pdata, _allocationSize); break; case 2: CreateSharedSepMatrix(_sharedName, _dataRegionPtrs, _nrow, _ncol, _pdata, _allocationSize); break; case 3: CreateSharedSepMatrix(_sharedName, _dataRegionPtrs, _nrow, _ncol, _pdata, _allocationSize); break; case 4: CreateSharedSepMatrix(_sharedName, _dataRegionPtrs, _nrow, _ncol, _pdata, _allocationSize); break; case 6: CreateSharedSepMatrix(_sharedName, _dataRegionPtrs, _nrow, _ncol, _pdata, _allocationSize); break; case 8: CreateSharedSepMatrix(_sharedName, _dataRegionPtrs, _nrow, _ncol, _pdata, _allocationSize); } } else { switch(_matType) { case 1: CreateSharedMatrix(_sharedName, _dataRegionPtrs, _nrow, _ncol, _pdata, _allocationSize); break; case 2: CreateSharedMatrix(_sharedName, _dataRegionPtrs, _nrow, _ncol, _pdata, _allocationSize); break; case 3: CreateSharedMatrix(_sharedName, _dataRegionPtrs, _nrow, _ncol, _pdata, _allocationSize); break; case 4: CreateSharedMatrix(_sharedName, _dataRegionPtrs, _nrow, _ncol, _pdata, _allocationSize); break; case 6: CreateSharedMatrix(_sharedName, _dataRegionPtrs, _nrow, _ncol, _pdata, _allocationSize); break; case 8: CreateSharedMatrix(_sharedName, _dataRegionPtrs, _nrow, _ncol, _pdata, _allocationSize); } } if (_pdata == NULL) { return false; } return true; } catch(interprocess_exception &e) { COND_EXCEPTION_PRINT(DEBUG); if (string(e.what()) != string("File exists") && string(e.what()) != string("The file exists.") && string(e.what()) != string("Die Datei ist vorhanden.")) { // It's a problem. Rethrow. throw e; } _counter.reset(); named_mutex::remove((_sharedName+"_counter_mutex").c_str()); } } while(++retry < 200); } catch(std::exception &e) { COND_EXCEPTION_PRINT(DEBUG); return false; } if (retry == 10) Rprintf("Could create a shared memory name."); return false; } template void* ConnectSharedSepMatrix(const std::string &uuid, MappedRegionPtrs &dataRegionPtrs, const index_type ncol, const bool readOnly=false) { T** pMat = new T*[ncol]; index_type i; try { for (i=0; i < ncol; ++i) { shared_memory_object shm(open_only, (uuid + "_column_" + ttos(i)).c_str(), (readOnly ? read_only : read_write)); dataRegionPtrs.push_back( MappedRegionPtr(new MappedRegion(shm, (readOnly ? read_only : read_write)))); pMat[i] = reinterpret_cast(dataRegionPtrs[i]->get_address()); } return reinterpret_cast(pMat); } catch(boost::interprocess::bad_alloc &e) { COND_EXCEPTION_PRINT(DEBUG); dataRegionPtrs.resize(0); delete[] pMat; return NULL; } } template void* ConnectSharedMatrix( const std::string &sharedName, MappedRegionPtrs &dataRegionPtrs, SharedCounter &counter, const bool readOnly=false) { using namespace boost::interprocess; try { shared_memory_object shm(open_only, sharedName.c_str(), (readOnly ? read_only : read_write)); dataRegionPtrs.push_back( MappedRegionPtr(new MappedRegion(shm, (readOnly ? read_only : read_write)))); return reinterpret_cast(dataRegionPtrs[0]->get_address()); } catch(boost::interprocess::bad_alloc &e) { COND_EXCEPTION_PRINT(DEBUG); dataRegionPtrs.resize(0); return NULL; } } bool SharedMemoryBigMatrix::connect( const std::string &uuid, const index_type numRow, const index_type numCol, const int matrixType, const bool sepCols, const bool readOnly ) { using namespace boost::interprocess; try { _uuid=uuid; _sharedName=_uuid; _nrow=numRow; _totalRows=_nrow; _ncol=numCol; _totalCols=_ncol; _matType=matrixType; _sepCols=sepCols; _readOnly=readOnly; _allocationSize=0; #ifndef INTERLOCKED_EXCHANGE_HACK // Attach to the associated mutex and counter; named_mutex mutex(open_or_create, (_sharedName+"_bigmemory_counter_mutex").c_str()); mutex.lock(); #endif _counter.init( _sharedName+"_counter" ); #ifndef INTERLOCKED_EXCHANGE_HACK mutex.unlock(); named_mutex::remove((_sharedName+"_bigmemory_counter_mutex").c_str()); #endif if (_sepCols) { switch(_matType) { case 1: try { _pdata = ConnectSharedSepMatrix(_sharedName, _dataRegionPtrs, _ncol, _readOnly); _allocationSize = _ncol*_nrow*sizeof(char); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectSharedSepMatrix(_sharedName, _dataRegionPtrs, _ncol, _readOnly); } } break; case 2: try { _pdata = ConnectSharedSepMatrix(_sharedName, _dataRegionPtrs, _ncol, _readOnly); _allocationSize = _ncol*_nrow*sizeof(short); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectSharedSepMatrix(_sharedName, _dataRegionPtrs, _ncol, _readOnly); } } break; case 3: try { _pdata = ConnectSharedSepMatrix(_sharedName, _dataRegionPtrs, _ncol, _readOnly); _allocationSize = _ncol*_nrow*sizeof(unsigned char); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectSharedSepMatrix(_sharedName, _dataRegionPtrs, _ncol, _readOnly); } } break; case 4: try { _pdata = ConnectSharedSepMatrix(_sharedName, _dataRegionPtrs, _ncol, _readOnly); _allocationSize = _ncol*_nrow*sizeof(int); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectSharedSepMatrix(_sharedName, _dataRegionPtrs, _ncol, _readOnly); } } break; case 6: try { _pdata = ConnectSharedSepMatrix(_sharedName, _dataRegionPtrs, _ncol, _readOnly); _allocationSize = _ncol*_nrow*sizeof(float); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectSharedSepMatrix(_sharedName, _dataRegionPtrs, _ncol, _readOnly); } } break; case 8: try { _pdata = ConnectSharedSepMatrix(_sharedName, _dataRegionPtrs, _ncol, _readOnly); _allocationSize = _ncol*_nrow*sizeof(double); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectSharedSepMatrix(_sharedName, _dataRegionPtrs, _ncol, _readOnly); } } } } else { switch(_matType) { case 1: try { _pdata = ConnectSharedMatrix(_sharedName, _dataRegionPtrs, _counter, _readOnly); _allocationSize = _ncol*_nrow*sizeof(char); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectSharedMatrix(_sharedName, _dataRegionPtrs, _counter, _readOnly); } } break; case 2: try { _pdata = ConnectSharedMatrix(_sharedName, _dataRegionPtrs, _counter, _readOnly); _allocationSize = _ncol*_nrow*sizeof(short); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectSharedMatrix(_sharedName, _dataRegionPtrs, _counter, _readOnly); } } break; case 3: try { _pdata = ConnectSharedMatrix(_sharedName, _dataRegionPtrs, _counter, _readOnly); _allocationSize = _ncol*_nrow*sizeof(char); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectSharedMatrix(_sharedName, _dataRegionPtrs, _counter, _readOnly); } } break; case 4: try { _pdata = ConnectSharedMatrix(_sharedName, _dataRegionPtrs, _counter, _readOnly); _allocationSize = _ncol*_nrow*sizeof(int); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectSharedMatrix(_sharedName, _dataRegionPtrs, _counter, _readOnly); } } break; case 6: try { _pdata = ConnectSharedMatrix(_sharedName, _dataRegionPtrs, _counter, _readOnly); _allocationSize = _ncol*_nrow*sizeof(float); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectSharedMatrix(_sharedName, _dataRegionPtrs, _counter, _readOnly); } } break; case 8: try { _pdata = ConnectSharedMatrix(_sharedName, _dataRegionPtrs, _counter, _readOnly); _allocationSize = _ncol*_nrow*sizeof(double); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectSharedMatrix(_sharedName, _dataRegionPtrs, _counter, _readOnly); } } } } if (!_pdata) { return false; } return true; } catch(std::exception &e) { COND_EXCEPTION_PRINT(DEBUG); return false; } } void DestroySharedSepMatrix( const std::string &uuid, const index_type ncol ) { index_type i; for (i=0; i < ncol; ++i) { try { shared_memory_object::remove((uuid+ "_column_" + ttos(i)).c_str()); } catch(std::exception &e) { COND_EXCEPTION_PRINT(DEBUG); } } } bool SharedMemoryBigMatrix::destroy() { using namespace boost::interprocess; #ifndef INTERLOCKED_EXCHANGE_HACK named_mutex mutex(open_or_create, (_sharedName+"_bigmemory_counter_mutex").c_str()); mutex.lock(); #endif bool destroyThis = (1==_counter.get()) ? true : false; try { _dataRegionPtrs.resize(0); // If this is the last shared memory big matrix destroy it and the // associated mutex. The counter will destroy itself. if (_sepCols) { if (destroyThis) { DestroySharedSepMatrix(_uuid, _totalCols); } if (_pdata) { delete [] reinterpret_cast(_pdata); } } else { if (destroyThis) { shared_memory_object::remove(_uuid.c_str()); } } #ifndef INTERLOCKED_EXCHANGE_HACK mutex.unlock(); if (destroyThis) { named_mutex::remove((_sharedName+"_bigmemory_counter_mutex").c_str()); } #endif return true; } catch(std::exception &e) { COND_EXCEPTION_PRINT(DEBUG); #ifndef INTERLOCKED_EXCHANGE_HACK mutex.unlock(); if (destroyThis) { named_mutex::remove((_sharedName+"_bigmemory_counter_mutex").c_str()); } #endif return false; } } template void* ConnectFileBackedSepMatrix( const std::string &sharedName, const std::string &filePath, MappedRegionPtrs &dataRegionPtrs, const index_type ncol, const bool readOnly=false) { T** pMat = new T*[ncol]; index_type i; dataRegionPtrs.resize(ncol); for (i=0; i < ncol; ++i) { std::string columnName = filePath + sharedName + "_column_" + ttos(i); // Map the file to this process. try { file_mapping mFile(columnName.c_str(), (readOnly ? read_only : read_write)); dataRegionPtrs[i] = MappedRegionPtr(new MappedRegion(mFile, (readOnly ? read_only : read_write))); pMat[i] = reinterpret_cast(dataRegionPtrs[i]->get_address()); } catch (std::bad_alloc &e) { COND_EXCEPTION_PRINT(DEBUG); dataRegionPtrs.resize(0); delete [] pMat; return NULL; } } return reinterpret_cast(pMat); } template void* CreateFileBackedSepMatrix( const std::string &fileName, const std::string &filePath, MappedRegionPtrs &dataRegionPtrs, const index_type nrow, const index_type ncol ) { #ifdef LINUX index_type i; for (i=0; i < ncol; ++i) { std::string columnName = filePath + fileName + "_column_" + ttos(i); FILE *fp = fopen( columnName.c_str(), "wb"); if (!fp) { COND_PRINT(DEBUG, "Problem creating file %s.\n", columnName.c_str()) return NULL; } if ( -1 == ftruncate( fileno(fp), nrow*sizeof(T) ) ) { COND_PRINT(DEBUG, "Problem creating file %s.\n", columnName.c_str()) index_type j; for (j=0; j < i; ++j) { columnName = filePath + fileName + "_column_" + ttos(j); unlink( columnName.c_str() ); return NULL; } } fclose(fp); } #else // WINDOWS or Mac index_type i; for (i=0; i < ncol; ++i) { std::string columnName = filePath + fileName + "_column_" + ttos(i); // Create the files. std::filebuf fbuf; if (!fbuf.open( columnName.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc | std::ios_base::binary )) { return NULL; } fbuf.pubseekoff( nrow*sizeof(T), std::ios_base::beg); // I'm not sure if I need this next line fbuf.sputc(0); fbuf.close(); } #endif return ConnectFileBackedSepMatrix(fileName, filePath, dataRegionPtrs, ncol); } template void* ConnectFileBackedMatrix( const std::string &fileName, const std::string &filePath, MappedRegionPtrs &dataRegionPtrs, const bool readOnly=false ) { //COND_PRINT(DEBUG, "Connecting to file %s\n", (filePath + fileName).c_str()) try { file_mapping mFile((filePath+fileName).c_str(), (readOnly ? read_only : read_write)); dataRegionPtrs.push_back( MappedRegionPtr(new MappedRegion(mFile, (readOnly ? read_only : read_write)))); } catch (std::bad_alloc &e) { COND_EXCEPTION_PRINT(DEBUG); dataRegionPtrs.resize(0); return NULL; } return reinterpret_cast(dataRegionPtrs[0]->get_address()); } template void* CreateFileBackedMatrix(const std::string &fileName, const std::string &filePath, MappedRegionPtrs &dataRegionPtrs, const index_type nrow, const index_type ncol) { // Create the file. std::string fullFileName = filePath+fileName; //COND_PRINT(DEBUG, "Writing %s\n", fullFileName.c_str()) #ifdef LINUX FILE *fp = fopen( fullFileName.c_str(), "wb"); if (!fp) { COND_PRINT(DEBUG, "Problem creating file %s.\n", fullFileName.c_str()); return NULL; } if (-1 == ftruncate( fileno(fp), nrow*ncol*sizeof(T) ) ) { COND_PRINT(DEBUG, "Error: %s\n", strerror(errno)); fclose(fp); return NULL; } fclose(fp); #else // Windows or Mac std::filebuf fbuf; if (!fbuf.open( (filePath+fileName).c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc | std::ios_base::binary )) { return NULL; } fbuf.pubseekoff(nrow*ncol*sizeof(T), std::ios_base::beg); // I'm not sure if I need this next line fbuf.sputc(0); fbuf.close(); #endif return ConnectFileBackedMatrix(fileName, filePath, dataRegionPtrs); } bool FileBackedBigMatrix::create(const std::string &fileName, const std::string &filePath, const index_type numRow, const index_type numCol, const int matrixType, const bool sepCols) { if (!create_uuid()) { return false; } try { //COND_PRINT(DEBUG, "create %s\n", (filePath + fileName).c_str()) _fileName = fileName; _filePath = filePath; _nrow = numRow; _totalRows = _nrow; _ncol = numCol; _totalCols = _ncol; _matType = matrixType; _sepCols = sepCols; if (_sepCols) { switch(_matType) { case 1: _pdata = CreateFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _nrow, _ncol); break; case 2: _pdata = CreateFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _nrow, _ncol); break; case 3: _pdata = CreateFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _nrow, _ncol); break; case 4: _pdata = CreateFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _nrow, _ncol); break; case 6: _pdata = CreateFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _nrow, _ncol); break; case 8: _pdata = CreateFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _nrow, _ncol); } } else { switch(_matType) { case 1: _pdata = CreateFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _nrow, _ncol); break; case 2: _pdata = CreateFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _nrow, _ncol); break; case 3: _pdata = CreateFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _nrow, _ncol); break; case 4: _pdata = CreateFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _nrow, _ncol); break; case 6: _pdata = CreateFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _nrow, _ncol); break; case 8: _pdata = CreateFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _nrow, _ncol); } } if (!_pdata) { return false; } return true; } catch(std::exception &e) { COND_EXCEPTION_PRINT(DEBUG); return false; } } bool FileBackedBigMatrix::connect( const std::string &fileName, const std::string &filePath, const index_type numRow, const index_type numCol, const int matrixType, const bool sepCols, const bool readOnly) { try { _fileName = fileName; _filePath = filePath; _nrow = numRow; _totalRows = _nrow; _ncol = numCol; _totalCols = _ncol; _matType = matrixType; _sepCols = sepCols; _readOnly = readOnly; if (_sepCols) { switch(_matType) { case 1: try { _pdata = ConnectFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _ncol, _readOnly); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _ncol, _readOnly); } } break; case 2: try { _pdata = ConnectFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _ncol, _readOnly); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _ncol, _readOnly); } } break; case 3: try { _pdata = ConnectFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _ncol, _readOnly); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _ncol, _readOnly); } } break; case 4: try { _pdata = ConnectFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _ncol, _readOnly); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _ncol, _readOnly); } } break; case 6: try { _pdata = ConnectFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _ncol, _readOnly); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _ncol, _readOnly); } } break; case 8: try { _pdata = ConnectFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _ncol, _readOnly); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectFileBackedSepMatrix(_fileName, filePath, _dataRegionPtrs, _ncol, _readOnly); } } } } else { switch(_matType) { case 1: try { _pdata = ConnectFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _readOnly); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _readOnly); } } break; case 2: try { _pdata = ConnectFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _readOnly); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _readOnly); } } break; case 3: try { _pdata = ConnectFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _readOnly); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _readOnly); } } break; case 4: try { _pdata = ConnectFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _readOnly); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _readOnly); } } break; case 6: try { _pdata = ConnectFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _readOnly); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _readOnly); } } break; case 8: try { _pdata = ConnectFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _readOnly); } catch(boost::interprocess::interprocess_exception &e) { if (!_readOnly) { _readOnly=true; _pdata = ConnectFileBackedMatrix(_fileName, filePath, _dataRegionPtrs, _readOnly); } } } } if (!_pdata) { return false; } return true; } catch(std::exception &e) { COND_EXCEPTION_PRINT(DEBUG); return false; } } void DestroyFileBackedSepMatrix( const std::string &sharedName, const index_type ncol) { index_type i; for (i=0; i < ncol; ++i) { // try // { // shared_memory_object::remove((sharedName + "_column_" + ttos(i)).c_str()); // } // catch(std::exception &e) // { // COND_EXCEPTION_PRINT(DEBUG); // } } } bool FileBackedBigMatrix::destroy() { try { _dataRegionPtrs.resize(0); if (_sepCols) { DestroyFileBackedSepMatrix(_fileName, _totalCols); if (_pdata) { switch(_matType) { case 1: delete [] reinterpret_cast(_pdata); break; case 2: delete [] reinterpret_cast(_pdata); break; case 3: delete [] reinterpret_cast(_pdata); break; case 4: delete [] reinterpret_cast(_pdata); break; case 6: delete [] reinterpret_cast(_pdata); break; case 8: delete [] reinterpret_cast(_pdata); } } } else // not _sepCols { // try // { // shared_memory_object::remove(_fileName.c_str()); // } // catch(std::exception &e) // { // COND_EXCEPTION_PRINT(DEBUG); // } } // In all cases, do the following: _colNames.clear(); _rowNames.clear(); return true; } // end of the try catch(std::exception &e) { COND_EXCEPTION_PRINT(DEBUG); return false; } } bool FileBackedBigMatrix::flush() { std::size_t i; try { for (i=0; i < _dataRegionPtrs.size(); ++i) { // Perform a synchronous flush. if ( !(_dataRegionPtrs[i])->flush(0, 0, false) ) return false; } } catch(std::exception &e) { COND_EXCEPTION_PRINT(DEBUG); return false; } return true; } bigmemory/src/deepcopy.cpp0000644000175100001440000001102013576750523015374 0ustar hornikusers#include #include #include #include #include #include #include "bigmemory/BigMatrix.h" #include "bigmemory/MatrixAccessor.hpp" #include "bigmemory/isna.hpp" template void DeepCopy(BigMatrix *pInMat, BigMatrix *pOutMat, SEXP rowInds, SEXP colInds) { in_BMAccessorType inMat( *pInMat ); out_BMAccessorType outMat( *pOutMat ); double *pRows = REAL(rowInds); double *pCols = REAL(colInds); index_type nRows = Rf_length(rowInds); index_type nCols = Rf_length(colInds); if (nRows != pOutMat->nrow()) Rf_error("length of row indices does not equal # of rows in new matrix"); if (nCols != pOutMat->ncol()) Rf_error("length of col indices does not equal # of cols in new matrix"); index_type i = 0; index_type j = 0; in_CType *pInColumn; out_CType *pOutColumn; for (i = 0; i < nCols; ++i) { pInColumn = inMat[static_cast(pCols[i])-1]; pOutColumn = outMat[i]; for (j = 0; j < nRows; ++j) { pOutColumn[j] = static_cast( pInColumn[static_cast(pRows[j])-1]); } } return; } // [[Rcpp::export]] SEXP CDeepCopy(SEXP inAddr, SEXP outAddr, SEXP rowInds, SEXP colInds, SEXP typecast_warning) { #define CALL_DEEP_COPY_2(IN_CTYPE, IN_ACCESSOR, OUT_ACCESSOR) \ switch(pOutMat->matrix_type()) \ { \ case 1: \ DeepCopy, char, OUT_ACCESSOR >( \ pInMat, pOutMat, rowInds, colInds); \ break; \ case 2: \ DeepCopy, short, OUT_ACCESSOR >( \ pInMat, pOutMat, rowInds, colInds); \ break; \ case 3: \ DeepCopy, unsigned char, OUT_ACCESSOR >( \ pInMat, pOutMat, rowInds, colInds); \ break; \ case 4: \ DeepCopy, int, OUT_ACCESSOR >( \ pInMat, pOutMat, rowInds, colInds); \ break; \ case 8: \ DeepCopy, double, OUT_ACCESSOR >( \ pInMat, pOutMat, rowInds, colInds); \ break; \ } #define CALL_DEEP_COPY_1(IN_ACCESSOR, OUT_ACCESSOR) \ switch(pInMat->matrix_type()) \ { \ case 1: \ CALL_DEEP_COPY_2(char, IN_ACCESSOR, OUT_ACCESSOR) \ break; \ case 2: \ CALL_DEEP_COPY_2(short, IN_ACCESSOR, OUT_ACCESSOR) \ break; \ case 3: \ CALL_DEEP_COPY_2(unsigned char, IN_ACCESSOR, OUT_ACCESSOR) \ break; \ case 4: \ CALL_DEEP_COPY_2(int, IN_ACCESSOR, OUT_ACCESSOR) \ break; \ case 8: \ CALL_DEEP_COPY_2(double, IN_ACCESSOR, OUT_ACCESSOR) \ break; \ } BigMatrix *pInMat = reinterpret_cast( R_ExternalPtrAddr(inAddr)); BigMatrix *pOutMat = reinterpret_cast( R_ExternalPtrAddr(outAddr)); if ((pOutMat->matrix_type() < pInMat->matrix_type()) & (Rf_asLogical(typecast_warning) == (Rboolean)TRUE)) { string type_names[9] = { "", "char", "short", "raw", "integer", "", "", "", "double"}; std::string warnMsg = string("Assignment will down cast from ") + type_names[pInMat->matrix_type()] + string(" to ") + type_names[pOutMat->matrix_type()] + string("\n") + string("Hint: To remove this warning type: ") + string("options(bigmemory.typecast.warning=FALSE)"); Rf_warning(warnMsg.c_str()); } // Not sure if there is a better way to do these function calls if (pInMat->separated_columns() && pOutMat->separated_columns()) { CALL_DEEP_COPY_1(SepMatrixAccessor, SepMatrixAccessor) } else if(pInMat->separated_columns() && !(pOutMat->separated_columns())) { CALL_DEEP_COPY_1(SepMatrixAccessor, MatrixAccessor) } else if(!(pInMat->separated_columns()) && pOutMat->separated_columns()) { CALL_DEEP_COPY_1(MatrixAccessor, SepMatrixAccessor) } else { CALL_DEEP_COPY_1(MatrixAccessor, MatrixAccessor) } return R_NilValue; } bigmemory/src/SharedCounter.cpp0000644000175100001440000000267713576750523016354 0ustar hornikusers#include #include "bigmemory/SharedCounter.h" bool SharedCounter::reset() { if (_pVal) { --(*_pVal); if (get() == 0) { boost::interprocess::shared_memory_object::remove(_resourceName.c_str()); _resourceName=""; } delete _pRegion; } _pVal = NULL; _resourceName = ""; return true; } bool SharedCounter::init( const std::string &resourceName ) { _resourceName = resourceName; // See if we are connecting for the first time. try { boost::interprocess::shared_memory_object shm( boost::interprocess::create_only, _resourceName.c_str(), boost::interprocess::read_write); // It's a new counter. shm.truncate( sizeof(index_type) ); _pRegion = new boost::interprocess::mapped_region(shm, boost::interprocess::read_write); _pVal = reinterpret_cast(_pRegion->get_address()); *_pVal = 1; } catch(std::exception &ex) { // We are connecting to an existing counter. boost::interprocess::shared_memory_object shm( boost::interprocess::open_only, _resourceName.c_str(), boost::interprocess::read_write); _pRegion = new boost::interprocess::mapped_region(shm, boost::interprocess::read_write); _pVal = reinterpret_cast(_pRegion->get_address()); ++(*_pVal); } return true; } index_type SharedCounter::get() const { return _pVal == NULL ? 0 : *_pVal; } bigmemory/NEWS0000644000175100001440000000534613577226064013005 0ustar hornikusers# # NEWS for R package bigmemory # # See also the Bigmemory Project: # http://www.bigmemory.org # Jay and Mike # # Jay Emerson # Mike Kane # Charles Determan 2019-12-20 Michael Kane * Updated type checking to accomodate new `matrix` inheritance. 2017-11-19 Michael Kane * Re-added functions to assign based on column and row names. 2017-11-08 Michael Kane * Memory leak problem solved. 2016-09-21 Adam Ryczkowski * Fixed a bug with handling raw bytes. Now it is possible to use big.matrix to store arbitrary R object (using serialization). If you want to make sure that bigmemory big.matrix handles raw data, add "bigmemory (>=4.5.21)" to the Depends stanza in the Description. 2014-04-15 Mike and Charles * Enabled use of Rcpp package to simply code and create smaller barrier to adding additional extensions. * Added new method to big.matrix objects, allocation_size, to easily check the size of the object in memory. * Float type matrices have now been added to enable single precision analytics. 2013-03-09 Jay and Mike * We missed a NEWS entry. Windows support is temporarily suspended due to issues with the Boost headers. * We now depend on bigmemory.sri (a trivial dependency relating to our big.matrix descriptors) and new package BH (for Boost headers). 2011-06-29 Jay and Mike * Modified deepcopy() with C code (thanks to Zarrar for this) * Added -fpermissive to possibly address a compilation issue in Linux * Added -lm to address a linking problem with math.h * Fixed a problem with reading all 0's in a column in read.big.matrix() * We note that there may be an inconsistency with read.big.matrix() and write.big.matrix() that needs to be addressed. 2010-10-30 Jay * Modified configure to handle a Solaris problem. * Added definition of __C99FEATURES__ to isna.hpp; hopefully won't break anything. 2010-05-16 Jay * Set proper default value op='AND' for mwhich() 2010-05-08 Jay * The configuration process has been streamlined to avoid warnings and allow for support of Sun Studio compiler on Linux. 2010-05-06 Jay and Mike * bigmemory >= 2.2.0 is accompanied by sister packages biganalytics and bigtabulate; mutexes (locking) are abstracted to package synchronicity, available now on R-Forge and soon to be uploaded to CRAN. Package bigalgebra is on R-Forge as a beta version while we sort through the range of library configuration options. bigmemory/configure.win0000755000175100001440000000042713576750523015005 0ustar hornikusers#################################################################### # configure for package bigmemory # John W. Emerson and Michael Kane # FLAGS="PKG_CPPFLAGS=-I../inst/include -std=c++0x" echo "Windows" FLAGS="${FLAGS} -DWINDOWS -DLENGTH_HACK" echo "${FLAGS}" > src/Makevars bigmemory/R/0000755000175100001440000000000013577172277012505 5ustar hornikusersbigmemory/R/zzz.R0000644000175100001440000000076513576750523013470 0ustar hornikusers.onLoad <- function(libname, pkgname) { options(bigmemory.print.warning=TRUE) options(bigmemory.typecast.warning=TRUE) options(bigmemory.allow.dimnames=FALSE) options(bigmemory.default.type="double") options(bigmemory.default.shared=TRUE) } .onUnload <- function(libpath) { options(bigmemory.print.warning=NULL) options(bigmemory.typecast.warning=NULL) options(bigmemory.allow.dimnames=NULL) options(bigmemory.default.type=NULL) options(bigmemory.default.shared=NULL) } bigmemory/R/bigmemory.R0000644000175100001440000021360413577164310014615 0ustar hornikusers#' @useDynLib bigmemory, .registration = TRUE #' @import methods bigmemory.sri Rcpp #' @importFrom utils head tail # puts an '/' at the end if there isn't format_path <- function(path) { paste0(sub(file.path("", "$"), "", path), .Platform$file.sep) } ############################################################################# # This function is used to match up a vector of column names to the # entire set of column names, providing the proper column indices. # The name choice was based on the phrase "multiple map" though # perhaps we should have made a different choice. mmap <- function(x, y) { if (is.null(x)) return(NULL) ans <- match(x, y) if (any(is.na(ans))) stop("Couldn't find a match to one of the arguments.") return(ans) } checkReadOnly <- function(x) { if (is.readonly(x)) { stop("you may not modify a read-only big.matrix object") } } ############################################################################# #' @template big.matrix_class_template #' @export setClass('big.matrix', representation(address='externalptr')) #' @rdname big.matrix.descriptor-class setClass('descriptor', representation(description='list')) #' @template big.matrix.descriptor_class_template #' @rdname big.matrix.descriptor-class #' @export setClass('big.matrix.descriptor', contains='descriptor') # Here, x is a big.matrix, and the result is a descriptor. # Here, x is a descriptor, and the result is the description which is # the relevant data needed for the attach. setGeneric('description', function(x) standardGeneric('description')) #' @rdname attach.big.matrix #' @export setMethod('describe', signature(x='big.matrix'), function(x) { return(new('big.matrix.descriptor', description=DescribeBigMatrix(x))) }) #' @template core_template #' @export big.matrix <- function(nrow, ncol, type=options()$bigmemory.default.type, init=NULL, dimnames=NULL, separated=FALSE, backingfile=NULL, backingpath=NULL, descriptorfile=NULL, binarydescriptor=FALSE, shared=options()$bigmemory.default.shared) { if (!is.null(backingfile)) { if (!shared) warning("All filebacked objects are shared.") return(filebacked.big.matrix(nrow=nrow, ncol=ncol, type=type, init=init, dimnames=dimnames, separated=separated, backingfile=backingfile, backingpath=backingpath, descriptorfile=descriptorfile, binarydescriptor=binarydescriptor)) } if (nrow < 1 | ncol < 1) stop('A big.matrix must have at least one row and one column') typeVal <- NULL if (type == 'integer') typeVal <- 4 if (type == 'float') typeVal <- 6 if (type == 'double') typeVal <- 8 if (type == 'short') typeVal <- 2 if (type == 'char') typeVal <- 1 if (type == 'raw' || type == 'byte') typeVal <- 3 if (is.null(typeVal)) stop('invalid type') if (!is.null(dimnames)) { rownames <- dimnames[[1]] colnames <- dimnames[[2]] } else { rownames <- NULL colnames <- NULL } if (is.null(init)) init <- NA if (shared) { address <- CreateSharedMatrix(as.double(nrow), as.double(ncol),as.character(colnames),as.character(rownames), as.integer(typeVal), as.double(init), as.logical(separated)) } else { address <- CreateLocalMatrix(as.double(nrow), as.double(ncol), as.character(colnames), as.character(rownames), as.integer(typeVal), as.double(init), as.logical(separated)) } if (is.null(address)) { stop(paste("Error: memory could not be allocated for instance", "of type big.matrix")) } x <- new("big.matrix", address=address) if (is.null(x)) { stop("Error encountered when creating instance of type big.matrix") } return(x) } #' @rdname big.matrix #' @export filebacked.big.matrix <- function(nrow, ncol, type=options()$bigmemory.default.type, init=NULL, dimnames=NULL, separated=FALSE, backingfile=NULL, backingpath=NULL, descriptorfile=NULL, binarydescriptor=FALSE) { if (nrow < 1 | ncol < 1) stop('A big.matrix must have at least one row and one column') typeVal <- NULL if (type == 'integer') typeVal <- 4 if (type == 'float') typeVal <- 6 if (type == 'double') typeVal <- 8 if (type == 'short') typeVal <- 2 if (type == 'char') typeVal <- 1 if (type == 'raw' || type == 'byte') typeVal <- 3 if (is.null(typeVal)) stop('invalid type') if (!is.null(dimnames)) { rownames <- dimnames[[1]] colnames <- dimnames[[2]] } else { rownames <- NULL colnames <- NULL } if (is.null(backingfile)) { stop('You must specify a backing file') } anon.backing <- ifelse( backingfile == '', TRUE, FALSE ) if (anon.backing) { backingfile <- tempfile() backingpath <- "" } if (is.null(descriptorfile) && !anon.backing) { warning(paste("No descriptor file given, it will be named", paste(backingfile, '.desc', sep=''))) descriptorfile <- paste(backingfile, '.desc', sep='') } if ( !anon.backing && ((basename(backingfile) != backingfile) || (basename(descriptorfile) != descriptorfile)) ) { stop(paste("The path to the descriptor and backing file are", "specified with the backingpath option")) } if (is.null(backingpath)) backingpath <- '' backingpath <- path.expand(backingpath) if (backingpath != "") { backingpath <- paste(backingpath, '', sep=.Platform$file.sep) } if(file.exists(paste(backingpath, backingfile, sep=.Platform$file.sep))){ stop("Backing file already exists! Either remove or specify different backing file") } if (backingpath == "" && dirname(backingfile) == ".") { backingpath <- paste(getwd(), "", sep=.Platform$file.sep) } address <- CreateFileBackedBigMatrix(as.character(backingfile), as.character(backingpath), as.double(nrow), as.double(ncol), as.character(colnames), as.character(rownames), as.integer(typeVal), as.double(init), as.logical(separated)) if (is.null(address)) { stop("Error encountered when creating instance of type big.matrix") } x <- new("big.matrix", address=address) if (is.null(x)) { stop("Error encountered when creating instance of type big.matrix") } if (is.null(descriptorfile) && !anon.backing) { warning(paste("A descriptor file has not been specified. ", "A descriptor named ", backingfile, ".desc will be created.", sep='')) descriptorfile <- paste(backingfile, ".desc", sep='' ) } if (!anon.backing) { descriptorfilepath <- paste(backingpath, descriptorfile, sep=.Platform$file.sep) if(binarydescriptor) { saveRDS(describe(x), file=descriptorfilepath) } else { dput(describe(x), descriptorfilepath) } } x } #' @rdname big.matrix #' @export setGeneric('as.big.matrix', function(x, type=NULL, separated=FALSE, backingfile=NULL, backingpath=NULL, descriptorfile=NULL, binarydescriptor=FALSE, shared=options()$bigmemory.default.shared) { standardGeneric('as.big.matrix') }) #' @title Convert to base R matrix #' @description Extract values from a \code{big.matrix} object #' and convert to a base R matrix object #' @param x A big.matrix object #' @export setMethod('as.matrix', signature(x='big.matrix'), function(x) return(x[,])) #' @template as.big.matrix_methods_template NULL setMethod('as.big.matrix', signature(x='matrix'), function(x, type, separated, backingfile, backingpath, descriptorfile, binarydescriptor, shared) { if (!is.numeric(x) && !is.raw(x)) { warning("Casting to numeric type") x <- matrix(as.numeric(x), nrow=nrow(x), dimnames=dimnames(x)) } if (is.null(type)) type <- typeof(x) if (type %in% c("integer","double", "short", "char", "float", "raw")) { y <- big.matrix(nrow=nrow(x), ncol=ncol(x), type=type, init=NULL, dimnames=dimnames(x), separated=separated, backingfile=backingfile, backingpath=backingpath, descriptorfile=descriptorfile, binarydescriptor=binarydescriptor, shared=shared) y[seq_len(nrow(x)),seq_len(ncol(x))] <- x junk <- gc() } else stop('bigmemory: that type is not implemented.') return(y) }) setMethod('as.big.matrix', signature(x='data.frame'), function(x, type, separated, backingfile, backingpath, descriptorfile, binarydescriptor, shared) { warning(paste("Coercing data.frame to matrix via factor", "level numberings.")) if (is.null(type)) type <- options()$bigmemory.default.type if (type %in% c("integer","double", "short", "char", "raw", "float")) { y <- big.matrix(nrow=nrow(x), ncol=ncol(x), type=type, init=NULL, dimnames=dimnames(x), separated=separated, backingfile=backingfile, backingpath=backingpath, descriptorfile=descriptorfile, binarydescriptor=binarydescriptor, shared=shared) oldbtw <- options()$bigmemory.typecast.warning options(bigmemory.typecast.warning=FALSE) for (i in seq_len(ncol(x))) { if (is.character(x[,i])) x[,i] <- factor(x[,i]) if (is.factor(x[,i])) x[,i] <- as.numeric(x[,i]) y[,i] <- x[,i] } options(bigmemory.typecast.warning=oldbtw) junk <- gc() } else stop('bigmemory: that type is not implemented.') return(y) }) setMethod('as.big.matrix', signature(x='vector'), function(x, type, separated, backingfile, backingpath, descriptorfile, binarydescriptor, shared) { if (!is.numeric(x)) { warning("Casting to numeric type") x <- as.numeric(x) } x <- matrix(x, length(x), 1) warning("Coercing vector to a single-column matrix.") return(as.big.matrix(x, type, separated, backingfile, backingpath, descriptorfile, binarydescriptor, shared)) }) #' @rdname big.matrix #' @export setGeneric('is.big.matrix', function(x) standardGeneric('is.big.matrix')) #' @rdname big.matrix setMethod('is.big.matrix', signature(x='big.matrix'), function(x) return(TRUE)) #' @rdname big.matrix setMethod('is.big.matrix', definition=function(x) return(FALSE)) colnames.bm <- function(x) { ret <- GetColumnNamesBM(x@address) if (length(ret)==0) return(NULL) return(ret) } rownames.bm <- function(x) { ret <- GetRowNamesBM(x@address) if (length(ret)==0) return(NULL) return(ret) } assign('colnames.bm<-', function(x, value) { checkReadOnly(x) if (is.character(value)) { if (any(value=="")) { stop("empty strings prohibited in column names") } } else { if (!is.null(value)) { value <- as.character(value) warning("column names coerced to character") } } if (!is.null(value) & length(value) != ncol(x)) stop("length of 'colnames' not equal to array extent.") SetColumnNames(x@address, value) return(x) }) assign('rownames.bm<-', function(x,value) { checkReadOnly(x) if (is.character(value)) { if (any(value=="")) { stop("empty strings prohibited in row names") } } else { if (!is.null(value)) { value <- as.character(value) warning("row names coerced to character") } } if (length(value) != nrow(x) & !is.null(value)) stop("length of 'rownames' not equal to array extent.") SetRowNames(x@address, value) return(x) }) #' @title The Number of Rows/Columns of a big.matrix #' @description \code{nrow} and \code{ncol} return the number of #' rows or columns present in a \code{big.matrix} object. #' @param x A big.matrix object #' @return An integer of length 1 #' @docType methods #' @rdname ncol-methods #' @export setMethod('ncol', signature(x="big.matrix"), function(x) return(CGetNcol(x@address))) #' @rdname ncol-methods #' @export setMethod('nrow', signature(x="big.matrix"), function(x) return(CGetNrow(x@address))) #' @title Dimensions of a big.matrix object #' @description Retrieve the dimensions of a \code{big.matrix} object #' @param x A \code{big.matrix} object #' @export setMethod('dim', signature(x="big.matrix"), function(x) return(c(nrow(x), ncol(x)))) #' @title Length of a big.matrix object #' @description Get the length of a \code{big.matrix} object #' @param x A \code{big.matrix} object #' @export setMethod('length', signature(x="big.matrix"), function(x) return(prod(dim(x)))) GetElements.bm <- function(x, i, j, drop=TRUE) { if (!is.numeric(i) & !is.character(i) & !is.logical(i)) stop("row indices must be numeric, logical, or character vectors.") if (!is.numeric(j) & !is.character(j) & !is.logical(j)) stop("column indices must be numeric, logical, or character vectors.") if (is.character(i)) if (is.null(rownames(x))) stop("row names do not exist.") else i <- mmap(i, rownames(x)) if (is.character(j)) if (is.null(colnames(x))) stop("column names do not exist.") else j <- mmap(j, colnames(x)) if (is.logical(i)) { if (length(i) != nrow(x)) stop("row vector length must match the number of rows of the matrix.") i <- which(i) } if (is.logical(j)) { if (length(j) != ncol(x)) stop(paste("column vector length must match the number of", "columns of the matrix.")) j <- which(j) } tempi <- CCleanIndices(as.double(i), as.double(nrow(x))) if (is.null(tempi[[1]])) stop("Illegal row index usage in extraction.\n") if (tempi[[1]]) i <- tempi[[2]] tempj <- CCleanIndices(as.double(j), as.double(ncol(x))) if (is.null(tempj[[1]])) stop("Illegal column index usage in extraction.\n") if (tempj[[1]]) j <- tempj[[2]] retList <- GetMatrixElements(x@address, as.double(j), as.double(i)) mat <- .addDimnames(retList, length(i), length(j), drop) return(mat) } # Function contributed by Peter Haverty at Genentech. GetIndivElements.bm <- function(x,i) { # Check i if (is.logical(i)) { stop("Logical indices not allowed when subsetting by a matrix.") } if (ncol(i) != 2) { stop("When subsetting with a matrix, it must have two columns.") } if (is.character(i)) { if (is.null(rownames(x))) stop("row names do not exist.") if (is.null(colnames(x))) stop("column names do not exist.") i <- matrix(c(mmap(i[,1], rownames(x)), mmap(i[,2], colnames(x))), ncol=2) } tempi <- CCleanIndices(as.double(i[,1]), as.double(nrow(x))) if (is.null(tempi[[1]])) stop("Illegal row index usage in assignment.\n") if (tempi[[1]]) i[,1] <- tempi[[2]] tempj <- CCleanIndices(as.double(i[,2]), as.double(ncol(x))) if (is.null(tempj[[1]])) stop("Illegal column index usage in assignment.\n") if (tempj[[1]]) i[,2] <- tempj[[2]] return(GetIndivMatrixElements(x@address, as.double(i[,2]), as.double(i[,1]))) } # Function contributed by Charles Determan Jr. GetIndivVectorElements.bm <- function(x,i) { # Check i if (is.logical(i)) { stop("Logical indices not allowed when subsetting by a matrix.") } if(any(i > length(x))){ stop("indices out of range.") } return(GetIndivVectorMatrixElements(x@address, as.integer(i))) } GetCols.bm <- function(x, j, drop=TRUE) { if (!is.numeric(j) & !is.character(j) & !is.logical(j)) stop("column indices must be numeric, logical, or character vectors.") if (is.character(j)) if (is.null(colnames(x))) stop("column names do not exist.") else j <- mmap(j, colnames(x)) if (is.logical(j)) { if (length(j) != ncol(x)) stop(paste("column vector length must match the number of", "columns of the matrix.")) j <- which(j) } tempj <- CCleanIndices(as.double(j), as.double(ncol(x))) if (is.null(tempj[[1]])) stop("Illegal column index usage in extraction.\n") if (tempj[[1]]) j <- tempj[[2]] retList <- GetMatrixCols(x@address, as.double(j)) mat <- .addDimnames(retList, nrow(x), length(j), drop) return(mat) } GetRows.bm <- function(x, i, drop=TRUE) { if (!is.numeric(i) & !is.character(i) & !is.logical(i)) stop("row indices must be numeric, logical, or character vectors.") if (is.character(i)) if (is.null(rownames(x))) stop("row names do not exist.") else i <- mmap(i, rownames(x)) if (is.logical(i)) { if (length(i) != nrow(x)) stop("row vector length must match the number of rows of the matrix.") i <- which(i) } tempi <- CCleanIndices(as.double(i), as.double(nrow(x))) if (is.null(tempi[[1]])) stop("Illegal row index usage in extraction.\n") if (tempi[[1]]) i <- tempi[[2]] retList <- GetMatrixRows(x@address, as.double(i)) mat <- .addDimnames(retList, length(i), ncol(x), drop) return(mat) } GetAll.bm <- function(x, drop=TRUE) { retList <- GetMatrixAll(x@address) mat <- .addDimnames(retList, nrow(x), ncol(x), drop) return(mat) } #' @title Extract or Replace #' @description Extract or replace big.matrix elements #' @name Extract,big.matrix #' @param x A \code{big.matrix object} #' @param i Indices specifying the rows #' @param j Indices specifying the columns #' @param drop Logical indication if reduce to minimum dimensions #' @param value typically an array-like R object of similar class #' @param ... Additional arguments #' @docType methods #' @rdname extract-methods #' @aliases [,big.matrix,ANY,ANY,missing-method #' @aliases [<-,big.matrix,ANY,ANY,ANY-method #' @export setMethod("[", signature(x = "big.matrix", drop = "missing"), function(x, i, j, drop) return(GetElements.bm(x, i, j))) #' @rdname extract-methods #' @export setMethod("[", signature(x = "big.matrix", drop = "logical"), function(x, i, j, drop) return(GetElements.bm(x, i, j, drop))) #' @rdname extract-methods #' @export setMethod("[", signature(x = "big.matrix", i="missing", drop = "missing"), function(x, i, j, drop) return(GetCols.bm(x, j))) #' @rdname extract-methods #' @export setMethod("[", signature(x = "big.matrix", i="missing", drop = "logical"), function(x, i, j, drop) return(GetCols.bm(x, j, drop))) #' @rdname extract-methods #' @export setMethod("[", signature(x = "big.matrix", j="missing", drop = "missing"), function(x, i, j, ..., drop){ # print(nargs()) if(nargs() == 2){ return(GetIndivVectorElements.bm(x,i)) }else{ return(GetRows.bm(x, i)) } }) #' @rdname extract-methods #' @export setMethod("[", signature(x = "big.matrix", j="missing", drop = "logical"), function(x, i, j, drop) return(GetRows.bm(x, i, drop))) #' @rdname extract-methods #' @export setMethod("[", signature(x = "big.matrix", i="missing", j="missing", drop = "missing"), function(x, i, j, drop) return(GetAll.bm(x))) #' @rdname extract-methods #' @export setMethod("[", signature(x = "big.matrix", i="missing", j="missing", drop = "logical"), function(x, i, j, drop) return(GetAll.bm(x, drop))) # Function contributed by Peter Haverty at Genentech. #' @rdname extract-methods #' @export setMethod('[', signature(x = "big.matrix",i="matrix",j="missing",drop="missing"), function(x, i, j, drop) return(GetIndivElements.bm(x, i))) #' @importFrom stats na.omit SetElements.bm <- function(x, i, j, value) { checkReadOnly(x) if (!is.numeric(i) & !is.character(i) & !is.logical(i)) stop("row indices must be numeric, logical, or character vectors.") if (!is.numeric(j) & !is.character(j) & !is.logical(j)) stop("column indices must be numeric, logical, or character vectors.") if (is.character(i)) if (is.null(rownames(x))) stop("row names do not exist.") else i <- mmap(i, rownames(x)) if (is.character(j)) if (is.null(colnames(x))) stop("column names do not exist.") else j <- mmap(j, colnames(x)) if (is.logical(i)) { if (length(i) != nrow(x)) stop("row vector length must match the number of rows of the matrix.") i <- which(i) } if (is.logical(j)) { if (length(j) != ncol(x)) stop(paste("column vector length must match the number of", "columns of the matrix.")) j <- which(j) } tempi <- CCleanIndices(as.double(i), as.double(nrow(x))) if (is.null(tempi[[1]])) stop("Illegal row index usage in assignment.\n") if (tempi[[1]]) i <- tempi[[2]] tempj <- CCleanIndices(as.double(j), as.double(ncol(x))) if (is.null(tempj[[1]])) stop("Illegal column index usage in assignment.\n") if (tempj[[1]]) j <- tempj[[2]] if ( options()$bigmemory.typecast.warning && ((typeof(value) == "double") && (typeof(x) != "double") || (typeof(value) == "integer" && (typeof(x) != "double" && typeof(x) != "float" && typeof(x) != "integer")) || (typeof(value) == "double" && (typeof(x) == "float")) || (typeof(value) == "raw" && (typeof(x) != "raw")) )) { warning(paste0("Assignment will down cast from ", typeof(value), " to ", typeof(x), "\nHint: To remove this warning type: ", "options(bigmemory.typecast.warning=FALSE)\n", sep='')) } totalts <- as.double(length(i)) * as.double(length(j)) # If we are assigning from a matrix, make sure the dimensions agree. if (is.matrix(value)) { if (ncol(value) != length(j) || nrow(value) != length(i)) { stop("Matrix dimensions do not agree with big.matrix instance set size.") } } else if (length(value) != totalts) { # Otherwise, make sure we are assigning the correct number of things # (rep if necessary) numReps <- totalts / length(value) if (numReps != round(numReps)) { stop("number of items to replace is not a multiple of replacement length") } } switch(typeof(x), 'double' = {SetMatrixElements(x@address, as.double(j), as.double(i), as.double(value))}, 'float' = {SetMatrixElements(x@address, as.double(j), as.double(i), as.double(value))}, #Don't convert raw before assigning them 'raw' = {SetMatrixElements(x@address, as.double(j), as.double(i), value)}, SetMatrixElements(x@address, as.double(j), as.double(i), to_int_checked(value)) ) x } SetIndivElements.bm <- function(x, i, value) { # Check i checkReadOnly(x) if (is.logical(i)) { stop("Logical indices not allowed when subsetting by a matrix.") } if (ncol(i) != 2) { stop("When subsetting with a matrix, it must have two columns.") } if (is.character(i)) { if (is.null(rownames(x))) stop("row names do not exist.") if (is.null(colnames(x))) stop("column names do not exist.") i <- matrix(c(mmap(i[,1], rownames(x)), mmap(i[,2], colnames(x))), ncol=2) } tempi <- CCleanIndices(as.double(i[,1]), as.double(nrow(x))) if (is.null(tempi[[1]])) stop("Illegal row index usage in assignment.\n") if (tempi[[1]]) i[,1] <- tempi[[2]] tempj <- CCleanIndices(as.double(i[,2]), as.double(ncol(x))) if (is.null(tempj[[1]])) stop("Illegal column index usage in assignment.\n") if (tempj[[1]]) i[,2] <- tempj[[2]] # Check value length, rep as necessary if (length(value) > nrow(i) || nrow(i) %% length(value) != 0) { stop("number of items to replace is not a multiple of replacement length") } if (length(value) < nrow(i)) { value <- rep(value, nrow(i) %/% length(value)) } # Give typecast warning if necessary if ( options()$bigmemory.typecast.warning && ((typeof(value) == "double") && (typeof(x) != "double") || (typeof(value) == "integer" && (typeof(x) != "double" && typeof(x) != "integer"))) || (typeof(value) == "double" && (typeof(x) == "float")) || (typeof(value) == "raw" && (typeof(x) != "raw"))) { warning(cat("Assignment will down cast from ", typeof(value), " to ", typeof(x), "\nHint: To remove this warning type: ", "options(bigmemory.typecast.warning=FALSE)\n", sep='')) } switch(typeof(x), 'double' = {SetIndivMatrixElements(x@address, as.double(i[,2]), as.double(i[,1]), as.double(value))}, 'float' = {SetIndivMatrixElements(x@address, as.double(i[,2]), as.double(i[,1]), as.single(value))}, #Don't convert raw before assigning them 'raw' = {SetIndivMatrixElements(x@address, as.double(i[,2]), as.double(i[,1]), value)}, SetIndivMatrixElements(x@address, as.double(i[,2]), as.double(i[,1]), as.integer(value))) x } # Function contributed by Charles Determan Jr. SetIndivVectorElements.bm <- function(x, i, value) { # Check i if (is.logical(i)) { stop("Logical indices not allowed when subsetting by a matrix.") } if(any(i > length(x))){ stop("indices out of range.") } if(length(value) > length(i)) { stop("value elements longer than indices") } if(length(value) < length(i)) { if(length(value) != 1){ stop("value must be of length equal to 'i' or 1") } } if(length(value) == 1) { value <- rep(value, length(i)) } SetIndivVectorMatrixElements(x@address, as.integer(i), value) x } #' @importFrom stats na.omit SetCols.bm <- function(x, j, value) { checkReadOnly(x) if (!is.numeric(j) & !is.character(j) & !is.logical(j)) stop("column indices must be numeric, logical, or character vectors.") if (is.character(j)) if (is.null(colnames(x))) stop("column names do not exist.") else j <- mmap(j, colnames(x)) if (is.logical(j)) { if (length(j) != ncol(x)) stop(paste("column vector length must match the number of", "columns of the matrix.")) j <- which(j) } tempj <- CCleanIndices(as.double(j), as.double(ncol(x))) if (is.null(tempj[[1]])) stop("Illegal column index usage in extraction.\n") if (tempj[[1]]) j <- tempj[[2]] if ( options()$bigmemory.typecast.warning && ((typeof(value) == "double") && (typeof(x) != "double") || (typeof(value) == "integer" && (typeof(x) != "double" && typeof(x) != "integer")) || (typeof(value) == "double" && (typeof(x) == "float"))) || (typeof(value) == "raw" && (typeof(x) != "raw"))) { warning(cat("Assignment will down cast from ", typeof(value), " to ", typeof(x), "\nHint: To remove this warning type: ", "options(bigmemory.typecast.warning=FALSE)\n", sep='')) } totalts <- as.double(nrow(x)) * as.double(length(j)) # If we are assigning from a matrix, make sure the dimensions agree. if (is.matrix(value)) { if (ncol(value) != length(j) | nrow(value) != nrow(x)) { stop("Matrix dimensions do not agree with big.matrix instance set size.") } } else if (length(value) != totalts) { # Otherwise, make sure we are assigning the correct number of things # (rep if necessary) numReps <- totalts / length(value) if (numReps != round(numReps)) { stop(paste("number of items to replace is not a multiple of", "replacement length")) } } if (typeof(x) != 'double') { integerVals <- na.omit(as.integer(value)) if ( sum(integerVals == na.omit(as.integer(value))) != length(integerVals) | is.factor(value)) { warning("non-integer (possibly Inf or -Inf) typecast to integer") } } switch(typeof(x), 'double' = {SetMatrixCols(x@address, as.double(j), as.double(value))}, 'float' = {SetMatrixCols(x@address, as.double(j), as.single(value))}, #Don't convert raw before assigning them 'raw' = {SetMatrixCols(x@address, as.double(j), value)}, SetMatrixCols(x@address, as.double(j), as.integer(value))) x } #' @importFrom stats na.omit SetRows.bm <- function(x, i, value) { checkReadOnly(x) if (!is.numeric(i) & !is.character(i) & !is.logical(i)) stop("row indices must be numeric, logical, or character vectors.") if (is.character(i)) if (is.null(rownames(x))) stop("row names do not exist.") else i <- mmap(i, rownames(x)) if (is.logical(i)) { if (length(i) != nrow(x)) { stop("row vector length must match the number of rows of the matrix.") } i <- which(i) } tempi <- CCleanIndices(as.double(i), as.double(nrow(x))) if (is.null(tempi[[1]])) stop("Illegal row index usage in extraction.\n") if (tempi[[1]]) i <- tempi[[2]] if ( options()$bigmemory.typecast.warning && ((typeof(value) == "double") && (typeof(x) != "double") || (typeof(value) == "integer" && (typeof(x) != "double" && typeof(x) != "integer")) || (typeof(value) == "double" && (typeof(x) == "float"))) || (typeof(value) == "raw" && (typeof(x) != "raw"))) { warning(cat("Assignment will down cast from ", typeof(value), " to ", typeof(x), "\nHint: To remove this warning type: ", "options(bigmemory.typecast.warning=FALSE)\n", sep='')) } # Note: i may be a mwhich statement in which case we _must_ ensure # that we disable read locking before it is evaluated or we will # have a race condition. - Jay and Mike. totalts <- as.double(length(i)) * as.double(ncol(x)) # If we are assigning from a matrix, make sure the dimensions agree. if (is.matrix(value)) { if (ncol(value) != ncol(x) | nrow(value) != length(i)) { stop("Matrix dimensions do not agree with big.matrix instance set size.") } } else if (length(value) != totalts) { # Otherwise, make sure we are assigning the correct number of things # (rep if necessary) numReps <- totalts / length(value) if (numReps != round(numReps)) { stop(paste("number of items to replace is not a multiple of", "replacement length")) } } if (typeof(x) != 'double') { integerVals <- na.omit(as.integer(value)) if ( sum(integerVals == na.omit(as.integer(value))) != length(integerVals) | is.factor(value)) { warning("non-integer (possibly Inf or -Inf) typecast to integer") } } switch(typeof(x), 'double' = {SetMatrixRows(x@address, as.double(i), as.double(value))}, 'float' = {SetMatrixRows(x@address, as.double(i), as.single(value))}, #Don't convert raw before assigning them 'raw' = {SetMatrixRows(x@address, as.double(i), value)}, SetMatrixRows(x@address, as.double(i), as.integer(value))) x } #' @importFrom stats na.omit SetAll.bm <- function(x, value) { checkReadOnly(x) if ( options()$bigmemory.typecast.warning && ((typeof(value) == "double") && (typeof(x) != "double") || (typeof(value) == "integer" && (typeof(x) != "double" && typeof(x) != "integer")) || (typeof(value) == "double" && (typeof(x) == "float"))) || (typeof(value) == "raw" && (typeof(x) != "raw"))) { warning(cat("Assignment will down cast from ", typeof(value), " to ", typeof(x), "\nHint: To remove this warning type: ", "options(bigmemory.typecast.warning=FALSE)\n", sep='')) } totalts <- as.double(nrow(x)) * as.double(ncol(x)) # If we are assigning from a matrix, make sure the dimensions agree. if (is.matrix(value)) { if (ncol(value) != ncol(x) | nrow(value) != nrow(x)) { stop("Matrix dimensions do not agree with big.matrix instance set size.") } } else if (length(value) != totalts) { # Otherwise, make sure we are assigning the correct number of things # (rep if necessary) numReps <- totalts / length(value) if (numReps != round(numReps)) { stop(paste("number of items to replace is not a multiple of", "replacement length")) } } if (typeof(x) != 'double') { integerVals <- na.omit(as.integer(value)) if ( sum(integerVals == na.omit(as.integer(value))) != length(integerVals) | is.factor(value)) { warning("non-integer (possibly Inf or -Inf) typecast to integer") } } switch(typeof(x), 'double' = {SetMatrixAll(x@address, as.double(value))}, 'float' = {SetMatrixAll(x@address, as.single(value))}, #Don't convert raw before assigning them 'raw' = {SetMatrixAll(x@address, value)}, SetMatrixAll(x@address, as.integer(value))) x } #' @rdname extract-methods #' @export setMethod('[<-', signature(x = "big.matrix", i = "numeric", j = "numeric"), function(x, i, j, value) return(SetElements.bm(x, i, j, value))) #' @rdname extract-methods #' @export setMethod('[<-', signature(x = "big.matrix", i = "numeric", j = "logical"), function(x, i, j, value) return(SetElements.bm(x, i, j, value))) #' @rdname extract-methods #' @export setMethod('[<-', signature(x = "big.matrix", i = "logical", j = "numeric"), function(x, i, j, value) return(SetElements.bm(x, i, j, value))) #' @rdname extract-methods #' @export setMethod('[<-', signature(x = "big.matrix", i = "logical", j = "logical"), function(x, i, j, value) return(SetElements.bm(x, i, j, value))) #' @rdname extract-methods #' @export setMethod('[<-', signature(x = "big.matrix", i = "logical", j = "character"), function(x, i, j, value) { if (any(duplicated(j))) { stop("Column names can't be duplicated.") } ms <- match(j, colnames(x)) if (any(is.na(ms))) { stop("Column names don't appear in the big.matrix.") } return(SetElements.bm(x, i, ms, value)) }) #' @rdname extract-methods #' @export setMethod('[<-', signature(x = "big.matrix", i = "numeric", j = "character"), function(x, i, j, value) { if (any(duplicated(j))) { stop("Column names can't be duplicated.") } ms <- match(j, colnames(x)) if (any(is.na(ms))) { stop("Column names don't appear in the big.matrix.") } return(SetElements.bm(x, i, ms, value)) }) #' @rdname extract-methods #' @export setMethod('[<-', signature(x = "big.matrix", i = "missing", j = "missing"), function(x, i, j, value){ i <- seq(nrow(x)) j <- seq(ncol(x)) return(SetElements.bm(x, i, j, value)) }) #' @rdname extract-methods #' @export setMethod('[<-', signature(x = "big.matrix", i="missing", j = "numeric"), function(x, i, j, value) return(SetCols.bm(x, j, value))) #' @rdname extract-methods #' @export setMethod('[<-', signature(x = "big.matrix", i="missing", j = "logical"), function(x, i, j, value) return(SetCols.bm(x, j, value))) #' @rdname extract-methods #' @export setMethod('[<-', signature(x = "big.matrix", i = "numeric", j="missing", value = "numeric"), function(x, i, j, ..., value){ if (nargs() == 3){ SetIndivVectorElements.bm(x, i, value) } else { SetRows.bm(x, i, value) } }) #' @rdname extract-methods #' @export setMethod('[<-', signature(x = "big.matrix", i = "logical", j="missing", value = "numeric"), function(x, i, j, ..., value){ if (nargs() == 3) { SetIndivVectorElements.bm(x, i, value) } else { SetRows.bm(x, i, value) } }) #' @rdname extract-methods #' @export setMethod('[<-', signature(x = "big.matrix", i = "numeric", j="missing", value = "matrix"), function(x, i, j, ..., value){ if (nargs() == 3) { SetIndivVectorElements.bm(x, i, value) } else { SetRows.bm(x, i, value) } }) #' @rdname extract-methods #' @export setMethod('[<-', signature(x = "big.matrix", i = "logical", j="missing", value = "matrix"), function(x, i, j, ..., value){ if (nargs() == 3) { SetIndivVectorElements.bm(x, i, value) } else { SetRows.bm(x, i, value) } }) #' @rdname extract-methods #' @export setMethod('[<-', signature(x="big.matrix", i="character", j="character"), function(x, i, j, value) return(SetElements.bm(x, i, j, value))) #' @rdname extract-methods #' @export setMethod('[<-', signature(x="big.matrix", i="missing", j="character"), function(x, j, value) return(SetCols.bm(x, j, value))) #' @rdname extract-methods #' @export setMethod('[<-', signature(x="big.matrix", i="character", j="missing"), function(x, i, value) return(SetRows.bm(x, i, value))) #' @rdname extract-methods #' @export setMethod('[<-', signature(x = "big.matrix", i="missing", j="missing", value = "numeric"), function(x, i, j, value) SetAll.bm(x, value)) # Function contributed by Peter Haverty at Genentech. #' @rdname extract-methods #' @export setMethod('[<-', signature(x = "big.matrix",i="matrix",j="missing", value = "numeric"), function(x, i, j, value) SetIndivElements.bm(x, i, value)) #' @title The Type of a big.matrix Object #' @description \code{typeof} returns the storage type of a #' \code{big.matrix} object #' @param x A \code{big.matrix} object #' @export setMethod('typeof', signature(x="big.matrix"), function(x) { GetTypeString(x@address) }) #' @title Check if Float #' @description Check to see if the elements of a big.matrix object are floats. #' @param x An object to be evaluated if float #' @export setGeneric('is.float', function(x) standardGeneric('is.float')) #' @title Is Float? #' @description Check if R numeric value has float flag #' @param x A numeric value setMethod('is.float', signature(x='numeric'), function(x){ if (is.null(attr(x, 'Csingle'))) { FALSE } else { bool <- attr(x, 'Csingle') bool } }) #' @title Return First or Last Part of a big.matrix Object #' @description Returns the first or last parts of a \code{big.matrix} #' object. #' @param x A big.matrix object #' @param n A single integer for the number of rows to return #' @docType methods #' @rdname head-methods #' @export setMethod('head', signature(x="big.matrix"), function(x, n = 6) { n <- min(as.integer(n), nrow(x)) if ( n < 1 | n > nrow(x) ) { stop("n must be between 1 and nrow(x)") } return(x[seq_len(n),]) }) #' @rdname head-methods #' @export setMethod('tail', signature(x="big.matrix"), function(x, n = 6) { n <- min(as.integer(n), nrow(x)) if ( n < 1 | n > nrow(x) ) { stop("n must be between 1 and nrow(x)") } return(x[(nrow(x)-n+1):nrow(x),]) }) #' @title Print Values #' @description \code{print} will print out the elements within #' a \code{big.matrix} object. #' @note By default, this will only return the \code{head} of a big.matrix #' to prevent console overflow. If you turn off the bigmemory.print.warning #' option then it will convert to a base R matrix and print all elements. #' @param x A \code{big.matrix} object #' @export setMethod('print', signature(x='big.matrix'), function(x) { if (options()$bigmemory.print.warning==TRUE) { cat("Warning: This is not advised. Here is the head of the matrix:\n") print(head(x)) } else { # Should change this to a C print function, unfortunately, for proper # formatting, this means we would also have to pass the terminal # width. print(x[,]) } }) ################################################################### # mwhich() # # x big.matrix # cols is.numeric or is.character # vals list of scalar or 2-vectors otherwise # comps could be missing, in which case we'll fill in 'eq' in signature, # a list of comparisons matching dim of associated vals component #' @template mwhich_template #' @export setGeneric('mwhich', function(x, cols, vals, comps, op = 'AND') standardGeneric('mwhich')) # add mwhich-methods roxygen # setting to NULL avoids the redundant usage statements #' @template mwhich_methods_template NULL setMethod('mwhich', signature(x='big.matrix', op='character'), function(x, cols, vals, comps, op) { return(mwhich.internal(x, cols, vals, comps, op, MWhichBigMatrix)) }) # @rdname mwhich-methods setMethod('mwhich', signature(x='matrix', op='character'), function(x, cols, vals, comps, op) { if (is.integer(x)) { mwhich.internal(x, cols, vals, comps, op, MWhichRIntMatrix) } else if (is.numeric(x)) { mwhich.internal(x, cols, vals, comps, op, MWhichRNumericMatrix) } else { stop("Unsupported matrix type given to mwhich") } }) # @rdname mwhich-methods setMethod('mwhich', signature(x='big.matrix', op='missing'), function(x, cols, vals, comps) return(mwhich.internal(x, cols, vals, comps, op='AND', whichFuncName=MWhichBigMatrix))) # @rdname mwhich-methods setMethod('mwhich', signature(x='matrix', op='missing'), function(x, cols, vals, comps) { if (is.integer(x)) return(mwhich.internal(x, cols, vals, comps, op='AND', whichFuncName=MWhichRIntMatrix)) if (is.numeric(x)) return(mwhich.internal(x, cols, vals, comps, op='AND', whichFuncName=MWhichRNumericMatrix)) stop("Unsupported matrix type given to mwhich") }) mwhich.internal <- function(x, cols, vals, comps, op, whichFuncName) { cols <- cleanupcols(cols, ncol(x), colnames(x)) if (length(setdiff(cols, seq_len(ncol(x)))) > 0) stop('Invalid column(s) in which()') # if vals or comps are not lists but are length 1 or 2, make them # trivial lists. if ( !is.list(vals) & (length(vals)==1 || length(vals)==2) ) { vals <- list(vals) } else { if (!is.list(vals)) stop('vals should be a list') } if ( !is.list(comps) & (length(comps)==1 || length(comps)==2)) { comps <- list(comps) } else { if (!is.list(comps)) stop('comps should be a list') } # Replicate vals or comps if appropriate. if (length(cols)!=length(vals)) { if (length(vals)==1) { vals <- data.frame(matrix(unlist(vals), length(vals), length(cols))) } else stop('length(vals) must be 1 or length(cols)') } if (length(cols)!=length(comps)) { if (length(comps)==1) { comps <- data.frame(matrix(unlist(comps), length(comps), length(cols)), stringsAsFactors=FALSE) } else stop('length(comps) must be 1 or length(cols)') } if (length(comps)!=length(vals)) stop('length of comps must equal length of vals') if (any(!unlist(lapply(comps, is.character))) || any(!(unlist(comps) %in% c('eq', 'neq', 'le', 'lt', 'ge', 'gt')))) { stop('comps must contain eq, neq, le, lt, ge, or gt') } testCol <- cols opVal <- 0 if (op == 'OR') opVal <- 1 minVal <- rep(NA, length(cols)) maxVal <- rep(NA, length(cols)) chkmin <- rep(0, length(cols)) chkmax <- rep(0, length(cols)) for (i in seq_len(length(cols))) { if (length(vals[[i]])==1) { # Here, we have the easy comparisons. if (is.na(vals[[i]]) && (comps[[i]]!='eq' && comps[[i]]!='neq')) stop('NA comparison limited to eq and neq, not le, lt, gt, or ge') if (length(comps[[i]])==1) { if (comps[[i]]=='eq' || comps[[i]]=='neq') { minVal[i] <- vals[[i]] maxVal[i] <- vals[[i]] } if (comps[[i]]=='neq') { chkmin[i] <- -1 chkmax[i] <- -1 # Not used, but.... } if (comps[[i]]=='ge' || comps[[i]]=='gt') { minVal[i] <- vals[[i]] maxVal[i] <- Inf if (comps[[i]]=='gt') chkmin[i] <- 1 } if (comps[[i]]=='le' || comps[[i]]=='lt') { minVal[i] <- -Inf maxVal[i] <- vals[[i]] if (comps[[i]]=='lt') chkmax[i] <- 1 } } else stop('vals/comps must be componentwise of same dimension') } else { # Here, we have two vals and two comps if (any(is.na(vals[[i]]))) stop('NAs not allowed in interval comparison') minVal[i] <- vals[[i]][1] maxVal[i] <- vals[[i]][2] if (comps[[i]][1]=='gt') chkmin[i] <- 1 if (comps[[i]][2]=='lt') chkmax[i] <- 1 if (comps[[i]][1]!='gt' && comps[[i]][1]!='ge') stop('invalid comparison of lower bound') if (comps[[i]][2]!='lt' && comps[[i]][2]!='le') stop('invalid comparison of upper bound') } } # End of the for loop ##### The new C function has new vectors chkmin and chkmax; ##### the value 0 indicates comparison with equality, ##### the value 1 indicates a strict inequality, ##### the value -1 indicates a 'neq' check; ##### if is.na checking is required, only the minVal needs to be ##### used, with chkmin = 0 being is.na and chkmin = 1 being !is.na. ret <- NULL if (is.big.matrix(x)) { ret <- whichFuncName(x@address, as.double(testCol), as.double(minVal), as.double(maxVal), as.integer(chkmin), as.integer(chkmax), as.integer(opVal)) } else { ret <- whichFuncName(x, nrow(x), as.double(testCol), as.double(minVal), as.double(maxVal), as.integer(chkmin), as.integer(chkmax), as.integer(opVal)) } ret } #' @title Dimnames of a big.matrix Object #' @description Retrieve or set the dimnames of an object #' @param x A big.matrix object #' @param value A possible value for \code{dimnames(x)} #' @docType methods #' @rdname dimnames-methods #' @export setMethod('dimnames', signature(x = "big.matrix"), function(x) return(list(rownames.bm(x), colnames.bm(x)))) #' @rdname dimnames-methods #' @export setMethod('dimnames<-', signature(x = "big.matrix", value='list'), function(x, value) { if (options()$bigmemory.allow.dimnames) { rownames.bm(x) <- value[[1]] colnames.bm(x) <- value[[2]] } else { stop(paste("Changing dimnames is not allowed; to override, please set", "options(bigmemory.allow.dimnames=TRUE).")) } return(x) }) #' @template write.big.matrix_template #' @export setGeneric('write.big.matrix', function(x, filename, row.names=FALSE, col.names=FALSE, sep=",") standardGeneric('write.big.matrix')) #' @rdname write.big.matrix setMethod('write.big.matrix', signature(x='big.matrix',filename='character'), function(x, filename, row.names, col.names, sep) { if (is.character(row.names)) stop("You must set the row names before writing.\n") if (is.character(col.names)) stop("You must set the column names before writing.\n") if (row.names & !HasRowColNames(x@address)[1]) { row.names <- FALSE warning(paste("No row names exist, overriding your", "row.names option.\n")) } if (col.names & !HasRowColNames(x@address)[2]) { col.names <- FALSE warning(paste("No column names exist, overriding your", "col.names option.\n")) } WriteMatrix(x@address, filename, as.logical(row.names), as.logical(col.names), sep) invisible(NULL) }) #' @rdname write.big.matrix #' @export setGeneric('read.big.matrix', function(filename, sep=',', header=FALSE, col.names=NULL, row.names=NULL, has.row.names=FALSE, ignore.row.names=FALSE, type=NA, skip=0, separated=FALSE, backingfile=NULL, backingpath=NULL, descriptorfile=NULL, binarydescriptor=FALSE, extraCols=NULL, shared=options()$bigmemory.default.shared) standardGeneric('read.big.matrix')) #' @importFrom stats na.omit #' @rdname write.big.matrix setMethod('read.big.matrix', signature(filename='character'), function(filename, sep, header, col.names, row.names, has.row.names, ignore.row.names, type, skip, separated, backingfile, backingpath, descriptorfile, binarydescriptor, extraCols, shared=options()$bigmemory.default.shared) { if (!is.logical(header)) stop("header argument must be logical") if (is.logical(col.names) || is.logical(row.names)) stop(paste("row.names and col.names, if used, must only be vectors", "of names (not logicals).")) if ( (header || is.character(col.names)) && is.numeric(extraCols) ) { stop(paste("When column names are specified, extraCols must be the names", "of the extra columns.")) } if (!header && is.null(col.names) && is.character(extraCols)) stop(paste("No header and no column names were specified, so extraCols", "must be an integer.")) if (!file.exists(filename)) stop(paste("The file", filename, "could not be found")) headerOffset <- as.numeric(header) colNames <- NULL if (header) { colNames <- unlist(strsplit( scan(filename, what='character', skip=skip, nlines=1, sep="\n", quiet=TRUE), split=sep)) colNames <- gsub("\"", "", colNames, perl=TRUE) colNames <- gsub("\'", "", colNames, perl=TRUE) if (is.na(colNames[1])) colNames <- colNames[-1] if (is.character(col.names)) { warning("Using supplied column names and skipping the header row.\n") colNames <- col.names } else { if (!is.null(col.names)) { stop(paste("Invalid header/col.names usage (col.names must be", "a vector of names if used).\n")) } } } else { if (is.character(col.names)) colNames <- col.names } # Get the first line of data firstLine <- scan(filename, what='character', skip=(skip+headerOffset), nlines=1, sep="\n", quiet=TRUE) firstLineVals <- unlist(strsplit(firstLine, split=sep)) numFields <- length(firstLineVals) firstLineVals[firstLineVals=="NA"] <- NA if (length(firstLineVals) < numFields) { firstLineVals <- c(firstLineVals, NA) } # At this point, we assume there are length(colNames) columns of data if # available, otherwise, figure it out. if (!is.null(colNames)) numCols <- length(colNames) else { numCols <- length(firstLineVals) - has.row.names } if (length(firstLineVals) - has.row.names != numCols) stop("Dimension mismatch between header row and first data row.\n") rowNames <- NULL if (!is.null(row.names)) { if (is.character(row.names)) { rowNames <- row.names ignore.row.names <- TRUE } else { stop("Invalid row.names (must be a vector of names if used).\n") } } if (is.na(type)) { type <- 'double' if (has.row.names) firstLineVals <- firstLineVals[-1] if (sum(na.omit(as.integer(firstLineVals)) == na.omit(as.double(firstLineVals))) == numCols ) { type <- 'integer' } warning(paste("Because type was not specified, we chose", type, "based on the first line of data.")) } lineCount <- CCountLines(filename) - skip - headerOffset numRows <- lineCount createCols <- numCols if (is.numeric(extraCols)) createCols <- createCols + extraCols if (is.character(extraCols)) { createCols <- createCols + length(extraCols) colNames <- c(colNames, extraCols) } bigMat <- big.matrix(nrow=numRows, ncol=createCols, type=type, dimnames=list(rowNames, colNames), init=NULL, separated=separated, backingfile=backingfile, backingpath=backingpath, descriptorfile=descriptorfile, binarydescriptor=binarydescriptor, shared=options()$bigmemory.default.shared) # has.row.names indicates whether or not there are row names; # we take ignore.row.names from the user, but pass (essentially) # use.row.names (which is !ignore.row.names) to C: ReadMatrix( as.character(filename), bigMat@address, as.double(skip+headerOffset), as.double(numRows), as.double(numCols), as.character(sep), as.logical(has.row.names), as.logical(!ignore.row.names)) bigMat }) #' @rdname big.matrix #' @export setGeneric('is.separated', function(x) standardGeneric('is.separated')) #' @rdname big.matrix setMethod('is.separated', signature(x='big.matrix'), function(x) return(IsSeparated(x@address))) cleanupcols <- function(cols=NULL, nc=NULL, colnames=NULL) { if (is.null(cols)) cols <- 1:nc else { if (!is.numeric(cols) & !is.character(cols) & !is.logical(cols)) stop("column indices must be numeric, logical, or character vectors.") if (is.character(cols)) if (is.null(colnames)) stop("column names do not exist.") else cols <- mmap(cols, colnames) if (is.logical(cols)) { if (length(cols) != nc) stop(paste("column vector length must match the number of", "columns of the matrix.")) cols <- which(cols) } tempj <- CCleanIndices(as.double(cols), as.double(nc)) if (is.null(tempj[[1]])) stop("Illegal column index usage in extraction.\n") if (tempj[[1]]) cols <- tempj[[2]] } return(cols) } cleanuprows <- function(rows=NULL, nr=NULL, rownames=NULL) { if (is.null(rows)) rows <- 1:nr else { if (!is.numeric(rows) & !is.character(rows) & !is.logical(rows)) stop("column indices must be numeric, logical, or character vectors.") if (is.character(rows)) if (is.null(rownames)) stop("row names do not exist.") else rows <- mmap(rows, rownames) if (is.logical(rows)) { if (length(rows) != nr) stop(paste("row vector length must match the number of", "rows of the matrix.")) rows <- which(rows) } tempj <- CCleanIndices(as.double(rows), as.double(nr)) if (is.null(tempj[[1]])) stop("Illegal row index usage in extraction.\n") if (tempj[[1]]) rows <- tempj[[2]] } return(rows) } #' @template deepcopy_template #' @export deepcopy <- function(x, cols=NULL, rows=NULL, y=NULL, type=NULL, separated=NULL, backingfile=NULL, backingpath=NULL, descriptorfile=NULL, binarydescriptor=FALSE, shared=options()$bigmemory.default.shared) { cols <- cleanupcols(cols, ncol(x), colnames(x)) rows <- cleanuprows(rows, nrow(x), rownames(x)) if (nrow(x) > 2^31-1) stop(paste("Too many rows to copy at this point in time;", "this may be fixed in the future.")) if (is.null(type)) type <- typeof(x) if (is.big.matrix(x)) { if (is.null(separated)) separated <- is.separated(x) } else { separated <- FALSE } if (is.null(y)) { y <- big.matrix(nrow=length(rows), ncol=length(cols), type=type, init=NULL, dimnames=dimnames(x), separated=separated, backingfile=backingfile, backingpath=backingpath, descriptorfile=descriptorfile, binarydescriptor=binarydescriptor, shared) } if (is.big.matrix(x) && is.big.matrix(y)) { CDeepCopy(x@address, y@address, as.double(rows), as.double(cols), getOption("bigmemory.typecast.warning")) } else { for (i in seq_len(length(cols))) y[,i] <- x[rows,cols[i]] } return(y) } # Following the R convention we are going to assume Unix directory # separators '/' as opposed to the Windows convention '\'. #' @rdname sub.big.matrix #' @export setGeneric('is.sub.big.matrix', function(x) standardGeneric('is.sub.big.matrix')) #' @rdname sub.big.matrix setMethod('is.sub.big.matrix', signature(x='big.matrix'), function(x) return(CIsSubMatrix(x@address)) ) # For now a submatrix only goes over a range of columns and a range # of row. This could be made more sophiticated but it would probably # take a lot of work. #' @template sub.big.matrix_template #' @export setGeneric('sub.big.matrix', function(x, firstRow=1, lastRow=NULL, firstCol=1, lastCol=NULL, backingpath=NULL) standardGeneric('sub.big.matrix')) #' @rdname sub.big.matrix setMethod('sub.big.matrix', signature(x='big.matrix'), function(x, firstRow, lastRow, firstCol, lastCol, backingpath) { return(sub.big.matrix(describe(x), firstRow, lastRow, firstCol, lastCol, backingpath)) }) #' @rdname big.matrix.descriptor-class #' @param x A descriptor object #' @param firstRow the first row of the submatrix #' @param lastRow the last row of the submatrix if not NULL #' @param firstCol the first column of the submatrix #' @param lastCol of the submatrix if not NULL #' @param backingpath required path to the filebacked object, if applicable setMethod('sub.big.matrix', signature(x='big.matrix.descriptor'), function( x, firstRow, lastRow, firstCol, lastCol, backingpath) { rowOffset <- firstRow-1 colOffset <- firstCol-1 rbm <- attach.resource(x, path=backingpath) if (is.null(lastRow)) lastRow <- nrow(rbm) if (is.null(lastCol)) lastCol <- ncol(rbm) numCols <- lastCol-firstCol+1 numRows <- lastRow-firstRow+1 if (colOffset < 0 || rowOffset < 0 || numCols < 1 || numRows < 1 || colOffset+numCols > ncol(rbm) || rowOffset+numRows > nrow(rbm)) { rm(rbm) stop(paste("A sub.big.matrix object could not be created", "with the specified parameters")) } SetRowOffsetInfo(rbm@address, as.double(rowOffset + GetRowOffset(rbm@address)), as.double(numRows) ) SetColumnOffsetInfo(rbm@address, as.double(colOffset + GetColOffset(rbm@address)), as.double(numCols)) return(rbm) }) setMethod('description', signature(x='big.matrix.descriptor'), function(x) return(x@description)) DescribeBigMatrix <- function(x) { if (!is.filebacked(x)) { if (is.shared(x)) { list(sharedType = 'SharedMemory', sharedName = shared.name(x), totalRows = GetTotalRows(x@address), totalCols = GetTotalColumns(x@address), rowOffset = GetRowOffset(x@address), colOffset = GetColOffset(x@address), nrow=nrow(x), ncol=ncol(x), rowNames=rownames(x), colNames=colnames(x), type=typeof(x), separated=is.separated(x)) } else { stop("you can't describe a non-shared big.matrix.") } } else { list(sharedType = 'FileBacked', filename = file.name(x), dirname = format_path(dir.name(x)), # need extra '/' on Windows totalRows = GetTotalRows(x@address), totalCols = GetTotalColumns(x@address), rowOffset = GetRowOffset(x@address), colOffset = GetColOffset(x@address), nrow=nrow(x), ncol=ncol(x), rowNames=rownames(x), colNames=colnames(x), type=typeof(x), separated=is.separated(x)) } } #' @template attach.big.matrix_template # @rdname attach.big.matrix #' @export attach.big.matrix <- function(obj, ...) { back <- list(...)[['backingpath']] if (is.null(back)) { attach.resource(obj, ...) } else { attach.resource(obj, path = back, ...) } } #' @rdname big.matrix.descriptor-class #' @param obj The filename of the descriptor for a filebacked matrix, #' assumed to be in the directory specified #' @param ... possibly \code{path} which gives the path where the descriptor #' and/or filebacking can be found. #' @export setMethod('attach.resource', signature(obj = 'character'), function(obj, ...) { path <- list(...)[['path']] if (is.null(path) || path == "") { # unspecified path extra argument fileWithPath <- path.expand(obj) } else { if (dirname(obj) != ".") { # path also specified in obj warning(paste("Two paths were specified in attach.resource.", "The one associated with the file will be used.", sep="\n")) fileWithPath <- path.expand(obj) } else { fileWithPath <- path.expand(file.path(path, obj)) } } if (!file.exists(fileWithPath)) stop( paste("The file", fileWithPath, "could not be found") ) if (dir.exists(fileWithPath)) stop( paste(fileWithPath, "is a directory") ) info <- tryCatch(readRDS(fileWithPath), error = function(er) dget(fileWithPath)) if (info@description$sharedType == "FileBacked") { info@description$dirname <- format_path(dirname(fileWithPath)) } attach.resource(info, path = NULL, ...) }) #' @rdname big.matrix.descriptor-class #' @export setMethod('attach.resource', signature(obj='big.matrix.descriptor'), function(obj, ...) { # path <- list(...)[['path']] info <- description(obj) typeLength <- NULL if (info$type == 'char') typeLength <- 1 if (info$type == 'short') typeLength <- 2 if (info$type == 'integer') typeLength <- 4 if (info$type == 'float') typeLength <- 6 if (info$type == 'double') typeLength <- 8 if (info$type == 'raw' ) typeLength <- 3 if (is.null(typeLength)) stop('invalid type') readonly <- list(...)[['readonly']] readOnly <- `if`(is.null(readonly), FALSE, readonly) if (!is.logical(readOnly)) { stop("The readOnly argument must be of type logical") } if (info$sharedType == 'SharedMemory') { address <- CAttachSharedBigMatrix(as.character(info$sharedName), as.double(info$totalRows), as.double(info$totalCols), as.character(info$rowNames), as.character(info$colNames), as.integer(typeLength), as.logical(info$separated), as.logical(readOnly)) } else { file <- file.path(info$dirname, info$filename) if (!info$separated) { if (!file.exists(file)) { stop(paste("The backing file", file, "could not be found")) } } else { # It's separated and we need to check for each column. fn <- paste0(file, "_column_", 1:info$ncol - 1) noexists <- which(!file.exists(fn)) if (length(noexists)) # report the first non-existing stop(paste("The backing file", fn[noexists[1]], "could not be found")) } address <- CAttachFileBackedBigMatrix( as.character(info$filename), as.character(info$dirname), as.double(info$totalRows), as.double(info$totalCols), as.character(info$rowNames), as.character(info$colNames), as.integer(typeLength), as.logical(info$separated), as.logical(readOnly)) } if (!is.null(address)) { SetRowOffsetInfo(address, info$rowOffset, info$nrow) SetColumnOffsetInfo(address, info$colOffset, info$ncol) ret <- new('big.matrix', address=address) # If the user did not specify read-only but the big matrix could # only be opened read-only then issue a warning. if (readOnly != is.readonly(ret)) { warning("big.matrix object could only be opened read-only.") } } else { stop("Fatal error in attach: big.matrix could not be attached.") } return(ret) }) #' @rdname big.matrix #' @export setGeneric('is.filebacked', function(x) standardGeneric('is.filebacked')) #' @rdname big.matrix setMethod('is.filebacked', signature(x='big.matrix'), function(x) return(IsFileBackedBigMatrix(x@address))) #' @rdname big.matrix #' @export setGeneric('shared.name', function(x) standardGeneric('shared.name')) #' @rdname big.matrix setMethod('shared.name', signature(x='big.matrix'), function(x) return(SharedName(x@address))) #' @rdname big.matrix #' @export setGeneric('file.name', function(x) standardGeneric('file.name')) #' @rdname big.matrix setMethod('file.name', signature(x='big.matrix'), function(x) { if (!is.filebacked(x)) { stop("The argument is not a file backed big.matrix.") } return(FileName(x@address)) }) #' @rdname big.matrix #' @export setGeneric('dir.name', function(x) standardGeneric('dir.name')) #' @rdname big.matrix setMethod('dir.name', signature(x='big.matrix'), function(x) { if (!is.filebacked(x)) { stop("The argument is not a file backed big.matrix.") } return(DirName(x@address)) }) #' @template flush_template #' @export setGeneric('flush', function(con) standardGeneric('flush')) #' @rdname flush-methods setMethod('flush', signature(con='big.matrix'), function(con) { if (!is.filebacked(con)) { warning("You cannot call flush on a non-filebacked big.matrix") return(invisible(TRUE)) } return(invisible(Flush(con@address))) }) #' @rdname big.matrix #' @export setGeneric('is.shared', function(x) standardGeneric('is.shared')) #' @rdname big.matrix setMethod('is.shared', signature(x='big.matrix'), function(x) return(IsShared(x@address))) #' @template morder_template #' @export morder <- function(x, cols, na.last=TRUE, decreasing = FALSE) { if (is.character(cols)) cols <- mmap( cols, colnames(x) ) if (sum(cols > ncol(x)) > 0 | sum(cols < 1) > 0 | sum(is.na(cols) > 0)) { stop("Bad column indices.") } switch(class(x)[1], "big.matrix"=OrderBigMatrix(x@address, as.double(cols), as.integer(na.last), as.logical(decreasing) ), "matrix" = switch(typeof(x), 'integer'=OrderRIntMatrix(x, nrow(x), as.double(cols), as.integer(na.last), as.logical(decreasing) ), 'double'=OrderRNumericMatrix(x, nrow(x), as.double(cols), as.integer(na.last), as.logical(decreasing) ), stop("Unsupported matrix value type.")), stop("unsupported matrix type") ) } #' @rdname morder #' @export morderCols <- function(x, rows, na.last=TRUE, decreasing = FALSE) { if (is.character(rows)) rows <- mmap( rows, rownames(x) ) if (sum(rows > nrow(x)) > 0 | sum(rows < 1) > 0 | sum(is.na(rows) > 0)) { stop("Bad row indices.") } switch(class(x)[1], "big.matrix"=OrderBigMatrixCols(x@address, as.double(rows), as.integer(na.last), as.logical(decreasing) ), "matrix"=switch(typeof(x), 'integer'=OrderRIntMatrixCols(x, nrow(x), ncol(x), as.double(rows), as.integer(na.last), as.logical(decreasing) ), 'double'=OrderRNumericMatrixCols(x, nrow(x), ncol(x), as.double(rows), as.integer(na.last), as.logical(decreasing) ), 'raw' = OrderRIntMatrixCols(x, nrow(x), ncol(x), as.double(rows), as.integer(na.last), as.logical(decreasing) ), stop("Unsupported matrix value type.")), stop("unsupported matrix type")) } #' @rdname morder #' @export mpermute <- function(x, order=NULL, cols=NULL, allow.duplicates=FALSE, ...) { if (is.null(order) && is.null(cols)) stop("You must specify either order or cols.") if (!is.null(order) && !is.null(cols)) stop("You must specify either order or cols.") if (!is.null(order)) { if (length(order) != nrow(x)) stop("order parameter must have the same length as nrow(x)") if (!allow.duplicates && sum(duplicated(order)) > 0) stop("order parameter contains duplicated entries.") r <- range(order) if (is.na(r[1])) stop("order parameter contains NAs") if (r[1] < 1 || r[2] > nrow(x)) stop("order parameter contains values that are out-of-range.") } else { order <- morder(x, cols, ...) } switch(class(x)[1], "big.matrix" = ReorderBigMatrix(x@address, order), "matrix" = switch(typeof(x), 'integer' = ReorderRIntMatrix(x, nrow(x), ncol(x), order), 'double' = ReorderRNumericMatrix(x, nrow(x), ncol(x), order), 'raw' = ReorderRIntMatrix(x, nrow(x), ncol(x), order), stop("Unsupported matrix value type.")), stop("invalid class") ) return(invisible(TRUE)) } #' @rdname morder #' @export mpermuteCols <- function(x, order=NULL, rows=NULL, allow.duplicates=FALSE, ...) { if (is.null(order) && is.null(rows)) stop("You must specify either order or cols.") if (!is.null(order) && !is.null(rows)) stop("You must specify either order or cols.") if (!is.null(order)) { if (length(order) != ncol(x)) stop("order parameter must have the same length as ncol(x)") if (!allow.duplicates && sum(duplicated(order)) > 0) stop("order parameter contains duplicated entries.") r <- range(order) if (is.na(r[1])) stop("order parameter contains NAs") if (r[1] < 1 || r[2] > nrow(x)) stop("order parameter contains values that are out-of-range.") } else { order <- morderCols(x, rows, ...) } switch(class(x)[1], "big.matrix" = { ReorderBigMatrixCols(x@address, order) SetColumnNames(x@address, colnames(x)[order]) }, "matrix" = { switch(typeof(x), 'integer' = ReorderRIntMatrixCols(x, nrow(x), ncol(x), order), 'raw' = ReorderRRawMatrixCols(x, nrow(x), ncol(x), order), 'double' = ReorderRNumericMatrixCols(x, nrow(x), ncol(x), order), stop("Unsupported matrix value type.")) }, stop("unimplemented class") ) invisible(TRUE) } #' @rdname big.matrix #' @export setGeneric('is.readonly', function(x) standardGeneric('is.readonly')) #' @rdname big.matrix setMethod('is.readonly', signature(x='big.matrix'), function(x) IsReadOnly(x@address)) #' @rdname big.matrix #' @export is.nil <- function(address) { if (class(address)!="externalptr") { stop("address is not an externalptr.") } isnil(address) } getCType <- function(x) { if (!inherits(x, "big.matrix")) stop("getCType takes a big.matrix as an argument.") CGetType(x@address) } .addDimnames <- function(retList, nrow, ncol, drop) { if (drop && !is.matrix(retList[[1]]) ) { if (length(retList[[1]]) > 1) { if (ncol == 1) { thesenames <- retList[[2]] } else if (nrow == 1) thesenames <- retList[[3]] } else { thesenames <- NULL } if (!is.null(thesenames)) { names(retList[[1]]) <- thesenames } } else { if (!is.matrix(retList[[1]])) { dim(retList[[1]]) <- c(nrow, ncol) } if (!is.null(retList[[2]]) || !is.null(retList[[3]])) { dimnames(retList[[1]]) <- list( retList[[2]], retList[[3]] ) } } return(retList[[1]]) } bigmemory/R/RcppExports.R0000644000175100001440000002216613577164344015124 0ustar hornikusers# Generated by using Rcpp::compileAttributes() -> do not edit by hand # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 to_int_checked <- function(x) { .Call(`_bigmemory_to_int_checked`, x) } GetIndivMatrixElements <- function(bigMatAddr, col, row) { .Call(`_bigmemory_GetIndivMatrixElements`, bigMatAddr, col, row) } GetIndivVectorMatrixElements <- function(bigMatAddr, elems) { .Call(`_bigmemory_GetIndivVectorMatrixElements`, bigMatAddr, elems) } ReorderRIntMatrix <- function(matrixVector, nrow, ncol, orderVec) { invisible(.Call(`_bigmemory_ReorderRIntMatrix`, matrixVector, nrow, ncol, orderVec)) } ReorderRNumericMatrix <- function(matrixVector, nrow, ncol, orderVec) { invisible(.Call(`_bigmemory_ReorderRNumericMatrix`, matrixVector, nrow, ncol, orderVec)) } ReorderBigMatrix <- function(address, orderVec) { invisible(.Call(`_bigmemory_ReorderBigMatrix`, address, orderVec)) } ReorderRIntMatrixCols <- function(matrixVector, nrow, ncol, orderVec) { invisible(.Call(`_bigmemory_ReorderRIntMatrixCols`, matrixVector, nrow, ncol, orderVec)) } ReorderRNumericMatrixCols <- function(matrixVector, nrow, ncol, orderVec) { invisible(.Call(`_bigmemory_ReorderRNumericMatrixCols`, matrixVector, nrow, ncol, orderVec)) } ReorderRRawMatrixCols <- function(matrixVector, nrow, ncol, orderVec) { invisible(.Call(`_bigmemory_ReorderRRawMatrixCols`, matrixVector, nrow, ncol, orderVec)) } ReorderBigMatrixCols <- function(address, orderVec) { invisible(.Call(`_bigmemory_ReorderBigMatrixCols`, address, orderVec)) } OrderRIntMatrix <- function(matrixVector, nrow, columns, naLast, decreasing) { .Call(`_bigmemory_OrderRIntMatrix`, matrixVector, nrow, columns, naLast, decreasing) } OrderRNumericMatrix <- function(matrixVector, nrow, columns, naLast, decreasing) { .Call(`_bigmemory_OrderRNumericMatrix`, matrixVector, nrow, columns, naLast, decreasing) } OrderBigMatrix <- function(address, columns, naLast, decreasing) { .Call(`_bigmemory_OrderBigMatrix`, address, columns, naLast, decreasing) } OrderRIntMatrixCols <- function(matrixVector, nrow, ncol, rows, naLast, decreasing) { .Call(`_bigmemory_OrderRIntMatrixCols`, matrixVector, nrow, ncol, rows, naLast, decreasing) } OrderRNumericMatrixCols <- function(matrixVector, nrow, ncol, rows, naLast, decreasing) { .Call(`_bigmemory_OrderRNumericMatrixCols`, matrixVector, nrow, ncol, rows, naLast, decreasing) } OrderBigMatrixCols <- function(address, rows, naLast, decreasing) { .Call(`_bigmemory_OrderBigMatrixCols`, address, rows, naLast, decreasing) } CCleanIndices <- function(indices, rc) { .Call(`_bigmemory_CCleanIndices`, indices, rc) } HasRowColNames <- function(address) { .Call(`_bigmemory_HasRowColNames`, address) } GetIndexRowNames <- function(address, indices_) { .Call(`_bigmemory_GetIndexRowNames`, address, indices_) } GetIndexColNames <- function(address, indices_) { .Call(`_bigmemory_GetIndexColNames`, address, indices_) } GetColumnNamesBM <- function(address) { .Call(`_bigmemory_GetColumnNamesBM`, address) } GetRowNamesBM <- function(address) { .Call(`_bigmemory_GetRowNamesBM`, address) } SetColumnNames <- function(address, columnNames) { invisible(.Call(`_bigmemory_SetColumnNames`, address, columnNames)) } SetRowNames <- function(address, rowNames) { invisible(.Call(`_bigmemory_SetRowNames`, address, rowNames)) } IsReadOnly <- function(bigMatAddr) { .Call(`_bigmemory_IsReadOnly`, bigMatAddr) } CIsSubMatrix <- function(bigMatAddr) { .Call(`_bigmemory_CIsSubMatrix`, bigMatAddr) } CGetNrow <- function(bigMatAddr) { .Call(`_bigmemory_CGetNrow`, bigMatAddr) } CGetNcol <- function(bigMatAddr) { .Call(`_bigmemory_CGetNcol`, bigMatAddr) } CGetType <- function(bigMatAddr) { .Call(`_bigmemory_CGetType`, bigMatAddr) } IsSharedMemoryBigMatrix <- function(bigMatAddr) { .Call(`_bigmemory_IsSharedMemoryBigMatrix`, bigMatAddr) } IsFileBackedBigMatrix <- function(bigMatAddr) { .Call(`_bigmemory_IsFileBackedBigMatrix`, bigMatAddr) } IsSeparated <- function(bigMatAddr) { .Call(`_bigmemory_IsSeparated`, bigMatAddr) } SetRowOffsetInfo <- function(bigMatAddr, rowOffset, numRows) { invisible(.Call(`_bigmemory_SetRowOffsetInfo`, bigMatAddr, rowOffset, numRows)) } SetColumnOffsetInfo <- function(bigMatAddr, colOffset, numCols) { invisible(.Call(`_bigmemory_SetColumnOffsetInfo`, bigMatAddr, colOffset, numCols)) } GetRowOffset <- function(bigMatAddr) { .Call(`_bigmemory_GetRowOffset`, bigMatAddr) } GetColOffset <- function(bigMatAddr) { .Call(`_bigmemory_GetColOffset`, bigMatAddr) } GetTotalColumns <- function(bigMatAddr) { .Call(`_bigmemory_GetTotalColumns`, bigMatAddr) } GetTotalRows <- function(bigMatAddr) { .Call(`_bigmemory_GetTotalRows`, bigMatAddr) } GetTypeString <- function(bigMatAddr) { .Call(`_bigmemory_GetTypeString`, bigMatAddr) } #' @title big.matrix size #' @description Returns the size of the created matrix in bytes #' @param bigMat a \code{big.matrix} object #' @export GetMatrixSize <- function(bigMat) { .Call(`_bigmemory_GetMatrixSize`, bigMat) } MWhichBigMatrix <- function(bigMatAddr, selectColumn, minVal, maxVal, chkMin, chkMax, opVal) { .Call(`_bigmemory_MWhichBigMatrix`, bigMatAddr, selectColumn, minVal, maxVal, chkMin, chkMax, opVal) } MWhichRIntMatrix <- function(matrixVector, nrow, selectColumn, minVal, maxVal, chkMin, chkMax, opVal) { .Call(`_bigmemory_MWhichRIntMatrix`, matrixVector, nrow, selectColumn, minVal, maxVal, chkMin, chkMax, opVal) } MWhichRNumericMatrix <- function(matrixVector, nrow, selectColumn, minVal, maxVal, chkMin, chkMax, opVal) { .Call(`_bigmemory_MWhichRNumericMatrix`, matrixVector, nrow, selectColumn, minVal, maxVal, chkMin, chkMax, opVal) } CCountLines <- function(fileName) { .Call(`_bigmemory_CCountLines`, fileName) } ReadMatrix <- function(fileName, bigMatAddr, firstLine, numLines, numCols, separator, hasRowNames, useRowNames) { .Call(`_bigmemory_ReadMatrix`, fileName, bigMatAddr, firstLine, numLines, numCols, separator, hasRowNames, useRowNames) } WriteMatrix <- function(bigMatAddr, fileName, rowNames, colNames, sep) { invisible(.Call(`_bigmemory_WriteMatrix`, bigMatAddr, fileName, rowNames, colNames, sep)) } GetMatrixElements <- function(bigMatAddr, col, row) { .Call(`_bigmemory_GetMatrixElements`, bigMatAddr, col, row) } GetMatrixRows <- function(bigMatAddr, row) { .Call(`_bigmemory_GetMatrixRows`, bigMatAddr, row) } GetMatrixCols <- function(bigMatAddr, col) { .Call(`_bigmemory_GetMatrixCols`, bigMatAddr, col) } GetMatrixAll <- function(bigMatAddr) { .Call(`_bigmemory_GetMatrixAll`, bigMatAddr) } SetMatrixElements <- function(bigMatAddr, col, row, values) { invisible(.Call(`_bigmemory_SetMatrixElements`, bigMatAddr, col, row, values)) } SetIndivVectorMatrixElements <- function(bigMatAddr, elems, inVec) { invisible(.Call(`_bigmemory_SetIndivVectorMatrixElements`, bigMatAddr, elems, inVec)) } SetIndivMatrixElements <- function(bigMatAddr, col, row, values) { invisible(.Call(`_bigmemory_SetIndivMatrixElements`, bigMatAddr, col, row, values)) } SetMatrixAll <- function(bigMatAddr, values) { invisible(.Call(`_bigmemory_SetMatrixAll`, bigMatAddr, values)) } SetMatrixCols <- function(bigMatAddr, col, values) { invisible(.Call(`_bigmemory_SetMatrixCols`, bigMatAddr, col, values)) } SetMatrixRows <- function(bigMatAddr, row, values) { invisible(.Call(`_bigmemory_SetMatrixRows`, bigMatAddr, row, values)) } CreateSharedMatrix <- function(row, col, colnames, rownames, typeLength, ini, separated) { .Call(`_bigmemory_CreateSharedMatrix`, row, col, colnames, rownames, typeLength, ini, separated) } CreateLocalMatrix <- function(row, col, colnames, rownames, typeLength, ini, separated) { .Call(`_bigmemory_CreateLocalMatrix`, row, col, colnames, rownames, typeLength, ini, separated) } CreateFileBackedBigMatrix <- function(fileName, filePath, row, col, colnames, rownames, typeLength, ini, separated) { .Call(`_bigmemory_CreateFileBackedBigMatrix`, fileName, filePath, row, col, colnames, rownames, typeLength, ini, separated) } CAttachSharedBigMatrix <- function(sharedName, rows, cols, rowNames, colNames, typeLength, separated, readOnly) { .Call(`_bigmemory_CAttachSharedBigMatrix`, sharedName, rows, cols, rowNames, colNames, typeLength, separated, readOnly) } CAttachFileBackedBigMatrix <- function(fileName, filePath, rows, cols, rowNames, colNames, typeLength, separated, readOnly) { .Call(`_bigmemory_CAttachFileBackedBigMatrix`, fileName, filePath, rows, cols, rowNames, colNames, typeLength, separated, readOnly) } SharedName <- function(address) { .Call(`_bigmemory_SharedName`, address) } FileName <- function(address) { .Call(`_bigmemory_FileName`, address) } DirName <- function(address) { .Call(`_bigmemory_DirName`, address) } Flush <- function(address) { .Call(`_bigmemory_Flush`, address) } IsShared <- function(address) { .Call(`_bigmemory_IsShared`, address) } isnil <- function(address) { .Call(`_bigmemory_isnil`, address) } CDeepCopy <- function(inAddr, outAddr, rowInds, colInds, typecast_warning) { .Call(`_bigmemory_CDeepCopy`, inAddr, outAddr, rowInds, colInds, typecast_warning) } bigmemory/R/hello-bigmemory.R0000644000175100001440000001351213576750523015720 0ustar hornikusers#' Manage massive matrices with shared memory and memory-mapped files. #' #' Create, store, access, and manipulate massive matrices. Matrices are, by #' default, allocated to shared memory and may use memory-mapped files. #' Packages \pkg{biganalytics}, \pkg{synchronicity}, \pkg{bigalgebra}, and #' \pkg{bigtabulate} provide advanced functionality. Access to and #' manipulation of a \code{\link{big.matrix}} object is exposed in an S4 #' class whose interface is similar to that of a \code{\link{matrix}}. Use of #' these packages in parallel environments can provide substantial speed and #' memory efficiencies. \pkg{bigmemory} also provides a \acronym{C++} #' framework for the development of new tools that can work both with #' \code{big.matrix} and native \code{matrix} objects. #' #' Index of functions/methods (grouped in a friendly way): \preformatted{ #' big.matrix, filebacked.big.matrix, as.big.matrix #' #' is.big.matrix, is.separated, is.filebacked #' #' describe, attach.big.matrix, attach.resource #' #' sub.big.matrix, is.sub.big.matrix #' #' dim, dimnames, nrow, ncol, print, head, tail, typeof, length #' #' read.big.matrix, write.big.matrix #' #' mwhich #' #' morder, mpermute #' #' deepcopy #' #' flush } #' #' Multi-gigabyte data sets challenge and frustrate users, even on #' well-equipped hardware. Use of \acronym{C/C++} can provide efficiencies, but #' is cumbersome for interactive data analysis and lacks the flexibility and #' power of 's rich statistical programming environment. The package #' \pkg{bigmemory} and associated packages \pkg{biganalytics}, #' \pkg{synchronicity}, \pkg{bigtabulate}, and \pkg{bigalgebra} bridge #' this gap, implementing massive matrices and supporting their manipulation #' and exploration. The data #' structures may be allocated to shared memory, allowing separate processes on #' the same computer to share access to a single copy of the data set. The #' data structures may also be file-backed, allowing users to easily manage and #' analyze data sets larger than available RAM and share them across nodes of a #' cluster. These features of the Bigmemory Project open the door for powerful #' and memory-efficient parallel analyses and data mining of massive data sets. #' #' This project (\pkg{bigmemory} and its sister packages) is still actively #' developed, although the design and current features can be viewed as #' "stable." Please feel free to email us with any questions: #' bigmemoryauthors@gmail.com. #' #' @name bigmemory-package #' @aliases bigmemory-package bigmemory #' @docType package #' @note Various options are available. #' \code{options(bigmemory.typecast.warning)} can be set to avoid annoying #' warnings that might occur if, for example, you assign objects (typically #' type double) to char, short, or integer \code{\link{big.matrix}} objects. #' \code{options(bigmemory.print.warning)} protects against extracting and #' printing a massive matrix (which would involve the creation of a second #' massive copy of the matrix). \code{options(bigmemory.allow.dimnames)} by #' default prevents the setting of \code{dimnames} attributes, because they #' aren't allocated to shared memory and changes will not be visible across #' processes. \code{options(bigmemory.default.type)} is \code{"double"} be #' default (a change in default behavior as of 4.1.1) but may be changed by the #' user. #' #' Note that you can't simply use a \code{big.matrix} with many (most) existing #' functions (e.g. \code{\link{lm}}, \code{\link{kmeans}}). One nice exception #' is \code{\link{split}}, because this function only accesses subsets of the #' matrix. #' #' @section Memory considerations: #' #' For obvious reasons memory that the \code{big.matrix} uses is managed outside #' the R memory pool available to the garbage collector and the memory occupied #' by the \code{big.matrix} is not visible to the R. #' This has subtle implications: #' #' \itemize{ #' \item Memory usage is not visible via general R functions (e.g. the \code{gc()} function) #' \item Garbage collector is mislead by the very small memory footprint of the \code{big.matrix} #' object (which acts merely as a pointer to the external memory structure), which can result #' in much less eagerness to garbage-collect the unused \code{big.memory} objects. #' After removing a last reference to a big \code{big.matrix}, user should manually run #' \code{gc()} to reclaim the memory. #' \item Attaching the description of already finalized \code{big.matrix} and accessing this object #' will result in undefined behavior, which simply means it will crash the current R session #' with no hope of saving the data in it. To prevent R from de-allocating (finalizing) the #' matrices, user should keep at least one \code{big.memory} object somewhere in R memory in at #' least one R session on the current machine. #' \item Abruptly closed R (using e.g. task manager) will not have a chance to finalize the #' \code{big.matrix} objects, which will result in a memory leak, as the \code{big.matrices} #' will remain in the memory (perhaps under obfuscated names) with no easy way to reconnect R to them. #' #' } #' #' @author Michael J. Kane, John W. Emerson, Peter Haverty, and Charles Determan Jr. #' #' Maintainers: Michael J. Kane #' @seealso For example, \code{\link{big.matrix}}, \code{\link{mwhich}}, #' \code{\link{read.big.matrix}} #' #' @references \url{http://www.bigmemory.org} #' #' @keywords package #' @examples #' #' #' # Our examples are all trivial in size, rather than burning huge amounts #' # of memory. #' #' x <- big.matrix(5, 2, type="integer", init=0, #' dimnames=list(NULL, c("alpha", "beta"))) #' x #' x[1:2,] #' x[,1] <- 1:5 #' x[,"alpha"] #' colnames(x) #' options(bigmemory.allow.dimnames=TRUE) #' colnames(x) <- NULL #' x[,] #' #' NULL bigmemory/MD50000644000175100001440000000677513600200214012575 0ustar hornikusers0de7ca7375b744319e599c47bfe85f64 *DESCRIPTION 8b9e12007e354ccc8f2d7a63a2f54531 *NAMESPACE 2d924c166f92e96f6caddd1076843ddb *NEWS a98bc9d4ab596031420b54fc50b0e3f4 *R/RcppExports.R d9620ed6861bff3b74a06c3e8b5cb4f3 *R/bigmemory.R c9960d9f1aaf1f02dcb9010f2e160fca *R/hello-bigmemory.R 84920654d0bd038e9743baaf9898b37f *R/zzz.R cff4b0071fbcb3165aaf35c802b46b34 *cleanup eb219c5b9917fe3022b63e0296e61953 *configure fc5c8f75e424213609b3e3cd9b57f5bf *configure.win 0cd9765e8adee62083d32a17a6b9aa07 *inst/CITATION 558ed71dd4adb6ecd1ec2ae0010a53b9 *inst/include/bigmemory/BigMatrix.h 3b3220d76af2054057b4c9edda832f48 *inst/include/bigmemory/MatrixAccessor.hpp f7a48cd4c3554011d0d50f95cb8df982 *inst/include/bigmemory/SharedCounter.h 43c04af1cba05a7180f1cb55309cbc73 *inst/include/bigmemory/bigmemoryDefines.h 81dbc472eacc2cbed71a5d0afe99d785 *inst/include/bigmemory/isna.hpp 2e85b8c55605709799a8abbbaedaaa80 *inst/include/bigmemory/util.h 2cdf46f5bcfe04ab0be48c72827c6348 *man/GetMatrixSize.Rd 0b6369ee9d822424e77ce6abc1ec5d80 *man/as.big.matrix-methods.Rd 302a54c3720b0d9ac037d1cf9cbb17d7 *man/as.matrix-big.matrix-method.Rd 5aec69acc1dc2cd8ac248439c23475cc *man/attach.big.matrix.Rd 3a4f77c8e2a1ad88d93642a656c98624 *man/big.matrix-class.Rd 2d5427d6fd1a2b1a1c0f803b56d24b15 *man/big.matrix.Rd 768f7128c7bf897d91751c080d125d34 *man/big.matrix.descriptor-class.Rd f45d33ff523f9b2cb1df0552f61bf354 *man/bigmemory-package.Rd 1541a1bcaad82f656a1b1981223fdb1e *man/deepcopy.Rd 699aa7b4bf748e82d4c40a92004b32bc *man/dim-big.matrix-method.Rd 5839f793116726982274d12f63880a2b *man/dimnames-methods.Rd 5e108218b33557930c69bf29360cb56f *man/extract-methods.Rd 7b8a8e00330d767e79c73a571aab34ab *man/flush-methods.Rd fd763376002487f37d89080ca3e2e154 *man/head-methods.Rd 1485b2179f4b7e0dfc9c58c17a14b6e8 *man/is.float-numeric-method.Rd 358961fb1a2e1a7171cdd645b2e2d173 *man/is.float.Rd 27abcc768e5406d4f8a0b175ba2625ef *man/length-big.matrix-method.Rd d7eb312cf5c121c4e7d5fdc1192df132 *man/morder.Rd ea678aaa248d372b447bec3f7b320728 *man/mwhich-methods.Rd 0244ec464e2281ceaebb1f4f0afbe9e0 *man/mwhich.Rd 6ac6e851e12fd158378a3bb4f6b5d89d *man/ncol-methods.Rd 9bdc6317e3b89666b347411608c8b701 *man/print-big.matrix-method.Rd f237dfc1947b1b420162109e98dc8aab *man/sub.big.matrix.Rd 96f999fb0f7d3ce07e59b3ca4fd57bcf *man/typeof-big.matrix-method.Rd 81de0e433635ec11ea9b8ed20ab70f5d *man/write.big.matrix.Rd 8797f18832c16b65b266a781908675ba *src/BigMatrix.cpp 565db44c468f4659f58e3100d7484e50 *src/RcppExports.cpp 81e6f49c7f623fb97376bd4b7132b176 *src/SharedCounter.cpp 69e2907db6989b1c5467db10f742f160 *src/bigmemory.cpp 22f6c68181a554386131fbf5fb6b6e49 *src/deepcopy.cpp b8c4d52de4096d181b7358e4c7c7698a *src/util.cpp 2b4877ae1449175221f543146cdce8b5 *tests/testthat.R 88784d61595f849333748ce9d7475b2a *tests/testthat/test_assignment.R 42624f362c5c8d64158c3c4d504cf823 *tests/testthat/test_attach_path.R d0e5ce447f9217e84863a896a17f34f9 *tests/testthat/test_create.R 0f42da6d75e92a319fb36b4574492680 *tests/testthat/test_deepcopy.R 2352ed49eb1d3901655fc857db7ab0d6 *tests/testthat/test_float_type.R 77bccefb28aacb9a675fab5325cc541d *tests/testthat/test_matrix_manips.R 54ecbee0d9f3f5299cc5e59cb76061c3 *tests/testthat/test_misc.R 9f32657882754f7dd932a6d5bd48259e *tests/testthat/test_morder.R de1ae509d7b275492703a1353912cb01 *tests/testthat/test_mwhich.R ff82a1f176f4607412dfc61f513feb3f *tests/testthat/test_raw.R e6f02eaea4087db5c169bae65691bb89 *tests/testthat/test_read.R 80714f3b4b3abcbc2e31f0eaad48c111 *tests/testthat/test_readonly.R 2f4a94fccccd1df5f02369fd3e56161a *tests/testthat/test_shared.R bigmemory/inst/0000755000175100001440000000000013577164474013261 5ustar hornikusersbigmemory/inst/include/0000755000175100001440000000000013576750523014677 5ustar hornikusersbigmemory/inst/include/bigmemory/0000755000175100001440000000000013576750523016671 5ustar hornikusersbigmemory/inst/include/bigmemory/BigMatrix.h0000644000175100001440000001621313576750523020733 0ustar hornikusers// proposed new names, InMemorySharedBigMatrix, FileBackedSharedBigMatrix #ifndef BIGMATRIX_H #define BIGMATRIX_H #ifdef INT #undef INT #endif #include #include #include #include #include #include "bigmemoryDefines.h" #include "SharedCounter.h" using namespace std; typedef vector Names; typedef boost::interprocess::mapped_region MappedRegion; typedef boost::shared_ptr MappedRegionPtr; typedef vector MappedRegionPtrs; typedef vector Columns; class BigMatrix : public boost::noncopyable { // Public types public: enum MatrixType {CHAR=1, SHORT=2, INT=3, DOUBLE=4, COMPLEX=5, FLOAT=6}; // Constructor and Destructor public: BigMatrix():_ncol(0),_nrow(0), _totalRows(0), _totalCols(0), _colOffset(0), _rowOffset(0),_matType(0), _pdata(NULL), _sepCols(false), _readOnly(false), _allocationSize(0){} virtual ~BigMatrix(){} // The next function returns the matrix data. It will generally be passed // to an appropriate templated function. void* matrix() {return _pdata;} // Accessors index_type ncol() const {return _ncol;} index_type nrow() const {return _nrow;} // For a submatrix, total_* includes the rows in the supermatrix. index_type total_rows() const {return _totalRows;} index_type total_columns() const {return _totalCols;} index_type col_offset() const {return _colOffset;} index_type row_offset() const {return _rowOffset;} int matrix_type() const {return _matType;} bool shared() const {return _shared;} bool separated_columns() const {return _sepCols;} Names column_names() { Names ret; if (!_colNames.empty()) { std::copy( _colNames.begin()+col_offset(), _colNames.begin()+col_offset()+ncol(), std::back_inserter(ret) ); } return ret; } Names row_names() { Names ret; if (!_rowNames.empty()) { ret.reserve(nrow()); std::copy( _rowNames.begin() + row_offset(), _rowNames.begin() + row_offset() + nrow(), std::back_inserter(ret) ); } return ret; } bool is_submatrix() { return total_rows() != nrow() || total_columns() != ncol(); } // Mutators bool column_names( const Names &newColNames ) { if ( !is_submatrix() && ((newColNames.size() == static_cast(ncol())) || newColNames.size() == 0) ) { _colNames = newColNames; return true; } if ( is_submatrix() && (newColNames.size() == static_cast(ncol())) ) { std::copy( newColNames.begin(), newColNames.end(), _colNames.begin() + col_offset()); return true; } return false; } bool row_names( const Names &newRowNames ) { if ( !is_submatrix() && ((newRowNames.size() == static_cast(nrow())) || newRowNames.size() == 0) ) { _rowNames = newRowNames; return true; } if ( is_submatrix() && (newRowNames.size() == static_cast(nrow())) ) { std::copy( newRowNames.begin(), newRowNames.end(), _rowNames.begin() + row_offset()); return true; } return false; } bool col_offset( const index_type &newOffset ) { _colOffset=newOffset; return true; } bool row_offset( const index_type &newOffset ) { _rowOffset=newOffset; return true; } bool ncol( const index_type &newNumCols ) { _ncol=newNumCols; return true; } bool nrow( const index_type &newNumCols ) { _nrow=newNumCols; return true; } const bool read_only() const { return _readOnly; } void read_only(bool newReadOnly) { _readOnly = newReadOnly; } void* data_ptr() {return _pdata;} const index_type allocation_size() const {return _allocationSize;} // Data Members protected: index_type _ncol; index_type _nrow; index_type _totalRows; index_type _totalCols; index_type _colOffset; index_type _rowOffset; index_type _nebytes; int _matType; void* _pdata; bool _shared; bool _sepCols; Names _colNames; Names _rowNames; bool _readOnly; index_type _allocationSize; }; class LocalBigMatrix : public BigMatrix { public: LocalBigMatrix() : BigMatrix() {_shared=false;} virtual ~LocalBigMatrix() {destroy();}; virtual bool create( const index_type numRow, const index_type numCol, const int matrixType, const bool sepCols); protected: virtual bool destroy(); }; class SharedBigMatrix : public BigMatrix { public: SharedBigMatrix() : BigMatrix() {_shared=true;} virtual ~SharedBigMatrix() {} std::string uuid() const {return _uuid;} std::string shared_name() const {return _sharedName;} protected: virtual bool destroy()=0; protected: // According to the documentation, shared memory has kernel or // filesystem presistence (mechanism exists until the system reboots // or is deleted (kernel) or until the mechanism is explicitly deleted // (filesystem)). As a result, we are going to need a usage counter // so that when the last object is done with the shared resource, it // can delete the resource. The destructor will handle deletion // of the shared usage counter. bool create_uuid(); bool uuid(const std::string &uuid) {_uuid=uuid; return true;} protected: std::string _uuid; std::string _sharedName; MappedRegionPtrs _dataRegionPtrs; }; class SharedMemoryBigMatrix : public SharedBigMatrix { public: SharedMemoryBigMatrix():SharedBigMatrix(){}; virtual ~SharedMemoryBigMatrix(){destroy();}; virtual bool create( const index_type numRow, const index_type numCol, const int matrixType, const bool sepCols); virtual bool connect( const std::string &uuid, const index_type numRow, const index_type numCol, const int matrixType, const bool sepCols, const bool readOnly=false); protected: virtual bool destroy(); protected: SharedCounter _counter; }; class FileBackedBigMatrix : public SharedBigMatrix { // _sharedName is filename_uuid public: FileBackedBigMatrix():SharedBigMatrix(){} virtual ~FileBackedBigMatrix(){destroy();} virtual bool create( const std::string &fileName, const std::string &filePath,const index_type numRow, const index_type numCol, const int matrixType, const bool sepCols); virtual bool connect( const std::string &fileName, const std::string &filePath, const index_type numRow, const index_type numCol, const int matrixType, const bool sepCols, const bool readOnly=false); std::string file_name() const {return _fileName;} std::string file_path() const {return _filePath;} bool flush(); protected: virtual bool destroy(); protected: std::string _fileName, _filePath; }; #endif // BIGMATRIX_H bigmemory/inst/include/bigmemory/isna.hpp0000644000175100001440000000156513576750523020343 0ustar hornikusers#ifndef ISNA_HPP #define ISNA_HPP #ifndef __C99FEATURES__ #define __C99FEATURES__ #endif #include #include "bigmemoryDefines.h" inline bool isna( const char val ) {return NA_CHAR == val;} inline bool isna( const short val ) {return NA_SHORT == val;} inline bool isna( const int val ) {return NA_INTEGER == val;} inline bool isna( const double val ) {return std::isnan(val);} inline bool neginf( const char val ) {return false;} inline bool neginf( const short val ) {return false;} inline bool neginf( const int val ) {return false;} #ifdef _MSC_VER inline bool isinf( const double val ) {return !_finite(val);} #endif inline bool neginf( const double val ) {return std::isinf(val) && val < 0;} inline bool posinf( const char val ); inline bool posinf( const short val ); inline bool posinf( const int val ); inline bool posinf( const double val ); #endif //ISNA_HPP bigmemory/inst/include/bigmemory/MatrixAccessor.hpp0000644000175100001440000000420513576750523022332 0ustar hornikusers#ifndef BIG_MATRIX_ACCESSOR #define BIG_MATRIX_ACCESSOR #include "BigMatrix.h" // The MatrixAccessor class allows the user to access non-separated // big matrix data as matrix[i][j]. template class MatrixAccessor { public: typedef T value_type; public: MatrixAccessor(T* pData, const index_type &nrow) { _pMat = pData; _totalRows = nrow; _rowOffset = 0; _colOffset = 0; _nrow = nrow; } MatrixAccessor(T* pData, const index_type &nrow, const index_type &ncol) { _pMat = pData; _totalRows = nrow; _totalCols = ncol; _rowOffset = 0; _colOffset = 0; _nrow = nrow; _ncol = ncol; } MatrixAccessor( BigMatrix &bm ) { _pMat = reinterpret_cast(bm.matrix()); _totalRows = bm.total_rows(); _totalCols = bm.total_columns(); _rowOffset = bm.row_offset(); _colOffset = bm.col_offset(); _nrow = bm.nrow(); _ncol = bm.ncol(); } inline T* operator[](const index_type &col) { return _pMat + _totalRows * (col + _colOffset) + _rowOffset; } index_type nrow() const { return _nrow; } index_type ncol() const { return _ncol; } protected: T *_pMat; index_type _totalRows; index_type _totalCols; index_type _rowOffset; index_type _colOffset; index_type _nrow; index_type _ncol; }; template class SepMatrixAccessor { public: typedef T value_type; public: SepMatrixAccessor( BigMatrix &bm) { _ppMat = reinterpret_cast(bm.matrix()); _rowOffset = bm.row_offset(); _colOffset = bm.col_offset(); _totalRows = bm.nrow(); _totalCols = bm.ncol(); } inline T* operator[](const index_type col) { return _ppMat[col + _colOffset] + _rowOffset; } index_type nrow() const { return _totalRows; } index_type ncol() const { return _totalCols; } protected: T **_ppMat; index_type _rowOffset; index_type _colOffset; index_type _totalRows; index_type _totalCols; }; #endif //BIG_MATRIX_ACCESSOR bigmemory/inst/include/bigmemory/util.h0000644000175100001440000000332313576750523020020 0ustar hornikusers#ifndef BIGMEMORY_UTIL_HPP #define BIGMEMORY_UTIL_HPP #include "bigmemoryDefines.h" using namespace std; vector RChar2StringVec( SEXP charVec ); vector RChar2StringVec( SEXP charVec, const vector &indices ); SEXP String2RChar(const std::string &str); std::string RChar2String(SEXP str); SEXP StringVec2RChar( const vector &strVec ); // Removed because no longer required with Rcpp /* template SEXP StringVec2RChar( const vector &strVec, T indices, const index_type indicesLength ) { if (strVec.empty()) return NULL_USER_OBJECT; SEXP ret = PROTECT(allocVector(STRSXP, indicesLength)); index_type i; for (i=0; i < indicesLength; ++i) { SET_STRING_ELT(ret, i, mkChar(strVec[static_cast(indices[i])-1].c_str())); } UNPROTECT(1); return ret; } */ template struct NewVec; template<> struct NewVec {SEXP operator()(index_type n) const {return Rcpp::IntegerVector(n);};}; inline SEXP NEW_FLOAT(index_type n) { std::vector out (n, 0); return Rcpp::wrap(out); } template<> struct NewVec {SEXP operator()(index_type n) const {return NEW_FLOAT(n);};}; template<> struct NewVec {SEXP operator()(index_type n) const {return Rcpp::NumericVector(n);};}; template struct VecPtr; template<> struct VecPtr {Rbyte* operator()(SEXP vec) const {return RAW(vec);};}; template<> struct VecPtr {int* operator()(SEXP vec) const {return INTEGER(vec);};}; template<> struct VecPtr {float* operator()(SEXP vec) const {return (float *)(vec);};}; template<> struct VecPtr {double* operator()(SEXP vec) const {return REAL(vec);};}; #endif // BIGMEMORY_UTIL_HPP bigmemory/inst/include/bigmemory/bigmemoryDefines.h0000644000175100001440000000154013576750523022332 0ustar hornikusers #ifndef BIGMEMORY_DEFINES_H #define BIGMEMORY_DEFINES_H #include #include #if __STDC_VERSION__ >= 199901L #define HAVE_COMPLEX #include #undef I #else #undef HAVE_COMPLEX #endif #ifdef __intptr_t_defined typedef intptr_t index_type; #else // We don't have 64-bit indexing. Build with 32. typedef long index_type; #endif #define NA_CHAR CHAR_MIN #define NA_SHORT SHRT_MIN #define R_INT_MIN (1+INT_MIN) #define R_INT_MAX INT_MAX #define R_SHORT_MIN (1+SHRT_MIN) #define R_SHORT_MAX SHRT_MAX #define R_CHAR_MIN (1+CHAR_MIN) #define R_CHAR_MAX CHAR_MAX #define R_DOUBLE_MIN R_NegInf #define R_DOUBLE_MAX R_PosInf #define NA_FLOAT FLT_MIN #define R_FLT_MIN -FLT_MAX #define R_FLT_MAX FLT_MAX #ifdef HAVE_LONG_DOUBLE # define LDOUBLE long double #else # define LDOUBLE double #endif #endif //BIGMEMORY_DEFINES_H bigmemory/inst/include/bigmemory/SharedCounter.h0000644000175100001440000000107113576750523021607 0ustar hornikusers#ifndef _SHARED_COUNTER_H #define _SHARED_COUNTER_H #include #include #include "bigmemoryDefines.h" // Note: Shared Counters are not mutex protected. class SharedCounter { public: SharedCounter(): _pVal(NULL),_pRegion(NULL){}; ~SharedCounter(){reset();}; bool init( const std::string &resourceName); public: index_type get() const; bool reset(); private: index_type *_pVal; boost::interprocess::mapped_region *_pRegion; std::string _resourceName; }; #endif //_SHARED_COUNTER_H bigmemory/inst/CITATION0000644000175100001440000000142413576750523014412 0ustar hornikuserscitHeader("To cite bigmemory in publications use:") citEntry(entry = "Article", title = "Scalable Strategies for Computing with Massive Data", author = personList(as.person("Michael J. Kane"), as.person("John Emerson"), as.person("Stephen Weston")), journal = "Journal of Statistical Software", year = "2013", volume = "55", number = "14", pages = "1--19", url = "http://www.jstatsoft.org/v55/i14/", textVersion = paste("Michael J. Kane, John Emerson, Stephen Weston (2013).", "Scalable Strategies for Computing with Massive Data.", "Journal of Statistical Software, 55(14), 1-19.", "URL http://www.jstatsoft.org/v55/i14/.") ) bigmemory/cleanup0000755000175100001440000000014613600006022013625 0ustar hornikusersrm -f src/Makevars rm -f src/*o rm -f src/*rds rm -f tests/testthat/*.desc rm -f tests/testthat/*.bin bigmemory/configure0000755000175100001440000000202113600006022014151 0ustar hornikusers#################################################################### # configure for package bigmemory # John W. Emerson and Michael Kane # # Sun Studio toolchain not completely BOOST-compatible (the # fault of BOOST, not R-Project). There will be no locking # of the shared counters, but the chance of a problem is very # small. Hopefully BOOST will catch up, soon. FLAGS="PKG_CPPFLAGS=-I../inst/include" LIBS="" echo -n " checking for Sun Studio compiler..." CC=`${R_HOME}/bin/R CMD config CC` cmd=`echo $CC | grep -E 'suncc'` if test -n "$cmd"; then echo "yes" FLAGS="${FLAGS} -DINTERLOCKED_EXCHANGE_HACK" else echo "no" fi echo -n " checking for OS..." if test `uname` = "Linux" ; then echo "Linux" FLAGS="${FLAGS} -DLINUX" LIBS="PKG_LIBS=-lrt -lm" elif test `uname` = "SunOS" ; then echo "Solaris" LIBS="PKG_LIBS=-lrt -lm" elif test `uname` = "Darwin" ; then echo "Darwin" FLAGS="${FLAGS} -DDARWIN -DLENGTH_HACK" else echo "Other:" `uname` fi echo "${FLAGS}" > src/Makevars echo "${LIBS}" >> src/Makevars