├── .gitmodules ├── .travis.yml ├── DESCRIPTION ├── NAMESPACE ├── R ├── FlashR.R ├── FlashR_base.R ├── FlashR_stats.R ├── KMeans.R ├── SVD.R └── graphics.R ├── aclocal.m4 ├── configure ├── configure.ac ├── demo ├── eigen.R ├── hierarical.spec.cluster.R └── test.cc.R ├── find_FlashX_objs.sh ├── inst └── tests │ ├── test_core.R │ └── test_dense.R ├── man ├── Arithmetic.Rd ├── Comparison.Rd ├── Extract.Rd ├── Extremes.Rd ├── Logic.Rd ├── MathFun.Rd ├── NA.Rd ├── all.Rd ├── any.Rd ├── colSums.Rd ├── cor.Rd ├── cov.wt.Rd ├── crossprod.Rd ├── dim.Rd ├── dimnames.Rd ├── drop.Rd ├── fm-class.Rd ├── fm.agg.Rd ├── fm.agg.op-class.Rd ├── fm.apply.Rd ├── fm.apply.op-class.Rd ├── fm.as.factor.Rd ├── fm.basic.op.Rd ├── fm.bind.Rd ├── fm.bo-class.Rd ├── fm.conv.FM2R.Rd ├── fm.conv.R2FM.Rd ├── fm.conv.layout.Rd ├── fm.conv.store.Rd ├── fm.create.agg.op.Rd ├── fm.eigen.Rd ├── fm.get.eles.Rd ├── fm.get.matrix.Rd ├── fm.groupby.Rd ├── fm.info.Rd ├── fm.inner.prod.Rd ├── fm.kmeans.Rd ├── fm.mapply2.Rd ├── fm.multiply.Rd ├── fm.print.mat.info.Rd ├── fm.read.obj.Rd ├── fm.rep.int.Rd ├── fm.rnorm.Rd ├── fm.rsparse.proj.Rd ├── fm.runif.Rd ├── fm.sapply.Rd ├── fm.seq.Rd ├── fm.set.conf.Rd ├── fm.t.Rd ├── fm.table.Rd ├── fm.write.obj.Rd ├── fmV-class.Rd ├── fmVFactor-class.Rd ├── head.Rd ├── ifelse.Rd ├── integer.Rd ├── is.finite.Rd ├── length.Rd ├── levels.Rd ├── log.Rd ├── materialize.Rd ├── matmult.Rd ├── matrix.Rd ├── mean.Rd ├── names.Rd ├── nlevels.Rd ├── nrow.Rd ├── numeric.Rd ├── print.Rd ├── profile.Rd ├── range.Rd ├── round.Rd ├── scale.Rd ├── sd.Rd ├── sum.Rd ├── summary.Rd ├── svd.Rd ├── sweep.Rd ├── transpose.Rd ├── typeof.Rd └── vector.Rd ├── readme.md ├── src ├── Makevars ├── Makevars.in ├── Rconn.c ├── Rconn.h ├── config.h ├── config.h.in ├── fmr_isna.h ├── fmr_utils.cpp ├── fmr_utils.h ├── matrix_interface.cpp ├── matrix_ops.cpp ├── matrix_ops.h ├── rutils.cpp └── rutils.h └── tests └── testthat.R /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/FlashX"] 2 | path = src/FlashX 3 | url = https://github.com/flashxio/FlashX.git 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | dist: trusty 3 | notifications: 4 | email: false 5 | before_install: 6 | - sudo sh -c 'echo "deb http://cran.rstudio.com/bin/linux/ubuntu trusty/" >> /etc/apt/sources.list' 7 | - gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9 8 | - gpg -a --export E084DAB9 | sudo apt-key add - 9 | - sudo apt-get update 10 | - sudo apt-get install -y cmake libboost-dev libboost-system-dev libboost-filesystem-dev libnuma-dev libaio-dev libhwloc-dev libatlas-base-dev zlib1g-dev numactl 11 | - sudo apt-get install -y r-base-core 12 | - sudo R -e "install.packages(c('Rcpp', 'RSpectra', 'testthat'), repos = 'http://cran.rstudio.com/')" 13 | - R CMD build . 14 | - sudo R CMD INSTALL *.tar.gz 15 | compiler: 16 | - g++ 17 | script: 18 | - Rscript tests/testthat.R 19 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: FlashR 2 | Version: 0.1-0 3 | Date: 2014-11-12 4 | Title: Scale R for massive datasets 5 | Author: See AUTHORS file. 6 | Maintainer: Da Zheng 7 | Description: FlashR extends the R programming framework. It executes R code 8 | in parallel automatically and stores and accesses arrays in the R code on 9 | disks automatically to scale R to large datasets that can't fit in memory. 10 | FlashR reimplements many commonly used R functions to execute existing R 11 | code. In addition, FlashR provides a small set of generalized operators to 12 | express data mining and machine learning algorithms that cannot be expressed 13 | with existing R functions efficiently. 14 | LinkingTo: Rcpp 15 | Depends: 16 | R (>= 3.0), 17 | RSpectra, 18 | methods, 19 | Rcpp 20 | License: Apache License 2.0 21 | URL: https://github.com/icoming/FlashGraph 22 | SystemRequirements: 23 | BugReports: https://github.com/icoming/FlashGraph/issues 24 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | useDynLib(FlashR) 2 | 3 | import(Rcpp) 4 | import(RSpectra) 5 | importFrom(methods, new) 6 | importFrom("stats", "runif") 7 | 8 | exportPattern("^[^\\.]") 9 | -------------------------------------------------------------------------------- /R/FlashR_stats.R: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Open Connectome Project (http://openconnecto.me) 2 | # Written by Da Zheng (zhengda1936@gmail.com) 3 | # 4 | # This file is part of FlashR. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | .sd.int <- function(x, na.rm) 19 | { 20 | x <- as.double(x) 21 | n <- length(x) 22 | x2 <- x * x 23 | test.na <- TRUE 24 | num.na <- 0 25 | if (na.rm) { 26 | zero <- .get.zero(typeof(x)) 27 | in.is.na <- is.na(x) 28 | x <- ifelse(in.is.na, zero, x) 29 | x2 <- ifelse(in.is.na, zero, x2) 30 | test.na <- FALSE 31 | } 32 | sum.x <- sum(x) 33 | sum.x2 <- sum(x2) 34 | 35 | if (test.na) { 36 | x.is.na <- any(.is.na.only(x)) 37 | if (.fmV2scalar(x.is.na)) 38 | return(.get.na(typeof(x))) 39 | } 40 | else { 41 | # If we remove NA, we should calculate the number of 42 | # NAs in the vector. 43 | sum.na <- sum(in.is.na) 44 | n <- n - .fmV2scalar(sum.na) 45 | } 46 | sum.x <- .fmV2scalar(sum.x) 47 | sum.x2 <- .fmV2scalar(sum.x2) 48 | avg <- sum.x / n 49 | sqrt((sum.x2 - n * avg * avg) / (n - 1)) 50 | } 51 | 52 | #' Standard Deviation 53 | #' 54 | #' This function computes the standard deviation of the values in \code{x}. 55 | #' If \code{na.rm} is \code{TRUE} then missing values are removed before 56 | #' computation proceeds. 57 | #' 58 | #' @param x a FlashR vector or matrix. 59 | #' @param na.rm logical. Should missing values be removed? 60 | #' @name sd 61 | #' 62 | #' @examples 63 | #' mat <- fm.runif.matrix(100, 10) 64 | #' sd(mat) 65 | NULL 66 | 67 | #' @rdname sd 68 | setMethod("sd", "fm", .sd.int) 69 | #' @rdname sd 70 | setMethod("sd", "fmV", .sd.int) 71 | 72 | .cov.int <- function(x, y=NULL, use="everything", 73 | method=c("pearson", "kendall", "spearman")) 74 | { 75 | x <- as.double(x) 76 | if (!is.null(y)) { 77 | stopifnot(nrow(x) == nrow(y)) 78 | y <- as.double(y) 79 | } 80 | n <- nrow(x) 81 | if (is.null(y)) { 82 | # we need to transpose x and compute rowSum instead of computing 83 | # colSum on the original matrix. The reason is that fm.materialize 84 | # only works on a set of matrices the same the long dimension and 85 | # dimension size. TODO I need to change that. 86 | x.sum <- rowSums(t(x)) 87 | x.prod <- fm.multiply(t(x), x) 88 | x.mu <- x.sum / n 89 | x.mu <- fm.conv.FM2R(x.mu) 90 | ret <- (fm.conv.FM2R(x.prod) - n * x.mu %*% t(x.mu)) / (n - 1) 91 | } 92 | else { 93 | x.sum <- rowSums(t(x)) 94 | y.sum <- rowSums(t(y)) 95 | xy.prod <- fm.multiply(t(x), y) 96 | x.mu <- x.sum / n 97 | y.mu <- y.sum / n 98 | x.mu <- fm.conv.FM2R(x.mu) 99 | y.mu <- fm.conv.FM2R(y.mu) 100 | ret <- (fm.conv.FM2R(xy.prod) - n * x.mu %*% t(y.mu)) / (n - 1) 101 | } 102 | ret 103 | } 104 | 105 | .cor.int <- function(x, y=NULL, use="everything", 106 | method=c("pearson", "kendall", "spearman")) 107 | { 108 | x <- as.double(x) 109 | if (!is.null(y)) { 110 | stopifnot(nrow(x) == nrow(y)) 111 | y <- as.double(y) 112 | } 113 | n <- nrow(x) 114 | if (is.null(y)) { 115 | x.sum <- rowSums(t(x)) 116 | x2.sum <- rowSums(t(x * x)) 117 | x.prod <- fm.multiply(t(x), x) 118 | x.mu <- x.sum / n 119 | x.sd <- sqrt((x2.sum - n * x.mu * x.mu) / (n - 1)) 120 | x.mu <- fm.conv.FM2R(x.mu) 121 | x.sd <- fm.conv.FM2R(x.sd) 122 | ret <- (fm.conv.FM2R(x.prod) - n * x.mu %*% t(x.mu)) / (n - 1) / (x.sd %*% t(x.sd)) 123 | } 124 | else { 125 | x.sum <- rowSums(t(x)) 126 | y.sum <- rowSums(t(y)) 127 | x2.sum <- rowSums(t(x * x)) 128 | y2.sum <- rowSums(t(y * y)) 129 | xy.prod <- fm.multiply(t(x), y) 130 | x.mu <- x.sum / n 131 | x.sd <- sqrt((x2.sum - n * x.mu * x.mu) / (n - 1)) 132 | x.mu <- fm.conv.FM2R(x.mu) 133 | x.sd <- fm.conv.FM2R(x.sd) 134 | y.mu <- y.sum / n 135 | y.sd <- sqrt((y2.sum - n * y.mu * y.mu) / (n - 1)) 136 | y.mu <- fm.conv.FM2R(y.mu) 137 | y.sd <- fm.conv.FM2R(y.sd) 138 | ret <- (fm.conv.FM2R(xy.prod) - n * x.mu %*% t(y.mu)) / (n - 1) / (x.sd %*% t(y.sd)) 139 | } 140 | ret 141 | } 142 | 143 | .cov.wt.int <- function (x, wt = rep(1/nrow(x), nrow(x)), cor = FALSE, center = TRUE, 144 | method = c("unbiased", "ML")) 145 | { 146 | if (is.data.frame(x)) 147 | x <- fm.as.matrix(x) 148 | else if (!fm.is.matrix(x)) 149 | stop("'x' must be a matrix or a data frame") 150 | x <- as.double(x) 151 | n <- nrow(x) 152 | if (with.wt <- !missing(wt)) { 153 | if (length(wt) != n) 154 | stop("length of 'wt' must equal the number of rows in 'x'") 155 | any.neg <- fm.any(wt < 0, TRUE) 156 | s <- sum(wt) 157 | if (any.neg[1] || s[1] == 0) 158 | stop("weights must be non-negative and not all zero") 159 | wt <- wt/s 160 | } 161 | 162 | all.finite <- fm.all(is.finite(t(x)), TRUE) 163 | if (is.logical(center)) { 164 | center <- if (center) 165 | rowSums(t(wt * x)) 166 | else 0 167 | } 168 | else { 169 | if (length(center) != ncol(x)) 170 | stop("length of 'center' must equal the number of columns in 'x'") 171 | } 172 | wx <- wt * x 173 | wx.cs <- rowSums(t(wx)) 174 | x.cp <- crossprod(wx, x) 175 | if (fm.is.sink(center)) { 176 | center <- fm.conv.FM2R(center) 177 | all.finite <- fm.conv.FM2R(all.finite) 178 | wx.cs <- fm.conv.FM2R(wx.cs) 179 | x.cp <- x.cp 180 | } 181 | else { 182 | all.finite <- fm.conv.FM2R(all.finite) 183 | wx.cs <- fm.conv.FM2R(wx.cs) 184 | x.cp <- x.cp 185 | } 186 | if (!all.finite) 187 | stop("'x' must contain finite values only") 188 | 189 | x.cp <- x.cp - wx.cs %*% t(center) - center %*% t(wx.cs) + center %*% t(center) 190 | cov <- switch(match.arg(method), unbiased = x.cp/(1 - sum(wt^2)), ML = x.cp) 191 | y <- list(cov = cov, center = center, n.obs = n) 192 | if (with.wt) 193 | y$wt <- wt 194 | if (cor) { 195 | Is <- 1/sqrt(diag(cov)) 196 | R <- cov 197 | R[] <- Is * cov * rep(Is, each = nrow(cov)) 198 | y$cor <- R 199 | } 200 | y 201 | } 202 | 203 | #' Correlation, Variance and Covariance (Matrices) 204 | #' 205 | #' \code{cov} and \code{cor} compute the covariance or correlation of \code{x} 206 | #' and \code{y} if these are vectors. If \code{x} 207 | #' and \code{y} are matrices then the covariances (or correlations) between 208 | #' the columns of \code{x} and the columns of \code{y} are computed. 209 | #' 210 | #' @param x a numeric vector or matrix 211 | #' @param y \code{NULL} (default) or a vector or matrix with compatible 212 | #' dimensions to \code{x}. The default is equivalent to \code{y=x}. 213 | #' @param use an optional character string giving a method for computing 214 | #' covariances in the presence of missing values. This must be 215 | #' (an abbreviation of) one of the strings \code{"everything"}, 216 | #' \code{"all.obs"}, \code{"complete.obs"}, \code{"na.or.complete"}, or 217 | #' \code{"pairwise.complete.obs"}. 218 | #' @param method a character string indicating which correlation coefficient 219 | #' (or covariance) is to be computed. One of \code{"pearson"} 220 | #' (default), \code{"kendall"}, or \code{"spearman"}: can be abbreviated. 221 | #' Right now this argument isn't used. 222 | #' @name cor 223 | #' 224 | #' @examples 225 | #' mat <- fm.runif.matrix(100, 10) 226 | #' var(mat) 227 | #' cor(mat) 228 | #' cov(mat) 229 | NULL 230 | 231 | #' @rdname cor 232 | setMethod("var", "fm", function(x, y=NULL, na.rm=FALSE, use) { 233 | if (missing(use)) 234 | use <- if (na.rm) "na.or.complete" else "everything" 235 | cor(x, y, use) 236 | }) 237 | #' @rdname cor 238 | setMethod("cor", "fm", .cor.int) 239 | #' @rdname cor 240 | setMethod("cov", "fm", .cov.int) 241 | 242 | #' Weighted Covariance Matrices 243 | #' 244 | #' Returns a list containing estimates of the weighted covariance 245 | #' matrix and the mean of the data, and optionally of the (weighted) 246 | #' correlation matrix. 247 | #' 248 | #' By default, \code{method = "unbiased"}, The covariance matrix is 249 | #' divided by one minus the sum of squares of the weights, so if the 250 | #' weights are the default (1/n) the conventional unbiased estimate 251 | #' of the covariance matrix with divisor (n - 1) is obtained. This 252 | #' differs from the behaviour in S-PLUS which corresponds to \code{method 253 | #' = "ML"} and does not divide. 254 | #' 255 | #' @param x a matrix. As usual, rows are observations and columns are variables. 256 | #' @param wt a non-negative and non-zero vector of weights for each 257 | #' observation. Its length must equal the number of rows of 258 | #' \code{x}. 259 | #' @param cor a logical indicating whether the estimated correlation 260 | #' weighted matrix will be returned as well. 261 | #' @param center either a logical or a numeric vector specifying the centers 262 | #' to be used when computing covariances. If \code{TRUE}, the 263 | #' (weighted) mean of each variable is used, if \code{FALSE}, zero is 264 | #' used. If \code{center} is numeric, its length must equal the 265 | #' number of columns of \code{x}. 266 | #' @param method string specifying how the result is scaled, see \code{Details} 267 | #' below. Can be abbreviated. 268 | #' @return A list containing the following named components: 269 | #' \itemize{ 270 | #' \item{cov}{the estimated (weighted) covariance matrix.} 271 | #' \item{center}{an estimate for the center (mean) of the data.} 272 | #' \item{n.obs}{the number of observations (rows) in \code{x}.} 273 | #' \item{wt}{the weights used in the estimation. Only returned if given 274 | #' as an argument.} 275 | #' \item{cor}{the estimated correlation matrix. Only returned if \code{cor} is 276 | #' \code{TRUE}} 277 | #' } 278 | #' @name cov.wt 279 | #' 280 | #' @examples 281 | #' mat <- fm.runif.matrix(100, 10) 282 | #' cov.wt(mat, fm.runif(nrow(mat))) 283 | setMethod("cov.wt", "fm", .cov.wt.int) 284 | -------------------------------------------------------------------------------- /R/KMeans.R: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Open Connectome Project (http://openconnecto.me) 2 | # Written by Da Zheng (zhengda1936@gmail.com) 3 | # 4 | # This file is part of FlashR. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | #' KMeans clustering 19 | #' 20 | #' Perform k-means clustering on a data matrix. 21 | #' 22 | #' @param data the input data matrix where each row is a data point. 23 | #' @param centers either the number of clusters, say k, or a set of 24 | #' initial (distinct) cluster centers. If a number, a random set 25 | #' of (distinct) rows in `x' is chosen as the initial centers. 26 | #' @param algorithm character. Currently, we only support "Lloyd". 27 | #' @param iter.max the maximal number of iterations. 28 | #' @param debug This indicates whether to print debug info. 29 | #' @param use.blas a logical value indicating whether to use BLAS to 30 | #' compute Euclidean distance. 31 | #' @return a vector that contains cluster Ids for each data point. 32 | #' @author Da Zheng 33 | fm.kmeans <- function(data, centers, iter.max=10, algorithm=c("Lloyd"), 34 | debug=FALSE, use.blas=FALSE) 35 | { 36 | n <- dim(data)[1] 37 | m <- dim(data)[2] 38 | agg.sum <- fm.create.agg.op(fm.bo.add, fm.bo.add, "sum") 39 | agg.which.min <- fm.create.agg.op(fm.bo.which.min, NULL, "which.min") 40 | # We need to convert the layout because argmin over all rows requires 41 | # to convert the matrix layout. Converting layout every iteration 42 | # is expensive. 43 | data <- fm.materialize(fm.conv.layout(data, byrow=TRUE)) 44 | 45 | cal.centers <- function(data, parts) { 46 | centers1 <- fm.groupby(data, 2, parts, agg.sum) 47 | centers1 <- as.matrix(centers1) 48 | cnts <- as.data.frame(fm.table(parts)) 49 | centers.idx <- as.vector(cnts$val) + 1 50 | # Some centers may not have been initialized if no data points 51 | # are assigned to them. I need to reset those data centers. 52 | centers <- matrix(rep.int(0, length(centers1)), dim(centers1)[1], 53 | dim(centers1)[2]) 54 | centers[centers.idx,] <- centers1[centers.idx,] 55 | # Calculate the mean for each cluster, which is the cluster center 56 | # for the next iteration. 57 | sizes <- rep.int(1, dim(centers)[1]) 58 | sizes[centers.idx] <- as.vector(cnts$Freq) 59 | centers <- diag(1/sizes) %*% centers 60 | fm.as.matrix(centers) 61 | } 62 | 63 | # If `centers' is a scalar, we randomly choose some data points from 64 | # the data matrix as initial centers. 65 | if (length(centers) == 1) { 66 | num.centers <- centers 67 | rand.k <- runif(num.centers, 1, nrow(data)) 68 | new.centers <- data[rand.k,] 69 | } 70 | else { 71 | num.centers <- nrow(centers) 72 | new.centers <- fm.conv.R2FM(centers) 73 | } 74 | parts <- NULL 75 | 76 | iter <- 0 77 | start.time <- Sys.time() 78 | num.moves <- nrow(data) 79 | if (use.blas) 80 | rsData2 <- rowSums(data * data) 81 | while (num.moves > 0 && iter < iter.max) { 82 | if (debug) 83 | iter.start <- Sys.time() 84 | centers <- new.centers 85 | old.parts <- parts 86 | gc() 87 | 88 | if (use.blas) { 89 | rsCenters2 <- rowSums(centers * centers) 90 | m <- -2 * data %*% t(centers) 91 | m <- m + rsData2 92 | m <- sweep(m, 2, rsCenters2, "+") 93 | } 94 | else 95 | m <- fm.inner.prod(data, t(centers), fm.bo.euclidean, fm.bo.add) 96 | 97 | parts <- as.integer(fm.agg.mat(m, 1, agg.which.min) - 1) 98 | # Have the vector materialized during the computation. 99 | fm.set.cached(parts, TRUE, TRUE) 100 | 101 | new.centers <- cal.centers(data, fm.as.factor(parts, num.centers)) 102 | if (!is.null(old.parts)) 103 | num.moves <- as.vector(sum(as.numeric(old.parts != parts))) 104 | iter <- iter + 1 105 | if (debug) { 106 | iter.end <- Sys.time() 107 | cat("iteration", iter, "takes", 108 | as.numeric(iter.end) - as.numeric(iter.start), 109 | "seconds and moves", num.moves, "data points\n") 110 | } 111 | old.parts <- NULL 112 | gc() 113 | } 114 | end.time <- Sys.time() 115 | cat("KMeans takes", iter , "iterations and", 116 | as.numeric(end.time) - as.numeric(start.time), "seconds\n") 117 | 118 | # This is what we really need, but we can't write the computation 119 | # in the following form yet. 120 | #ss <- function(x) sum(scale(x, scale = FALSE)^2) 121 | #withinss <- sapply(split(as.data.frame(x), cluster), ss) 122 | cluster <- fm.as.factor(parts, num.centers) 123 | cnts <- fm.table(cluster) 124 | x2.gsum <- fm.groupby(data * data, 2, cluster, "+") 125 | x.gsum <- fm.groupby(data, 2, cluster, "+") 126 | withinss <- as.vector(rowSums(x2.gsum - (x.gsum^2)/cnts@Freq)) 127 | 128 | ss <- function(x) sum(scale(x, scale = FALSE)^2) 129 | betweenss <- as.vector(ss(new.centers[parts + 1,])) 130 | tot.withinss <- sum(withinss) 131 | totss <- tot.withinss + betweenss 132 | 133 | structure(list(cluster=parts+1, centers=new.centers, totss=totss, withinss=withinss, 134 | tot.withinss=tot.withinss, betweenss=betweenss, 135 | size=as.vector(cnts@Freq), iter=iter), class = "kmeans") 136 | } 137 | 138 | BIC.kmeans <- function(object, ...) 139 | { 140 | m <- ncol(object$centers) 141 | n <- length(object$cluster) 142 | k <- nrow(object$centers) 143 | D <- object$tot.withinss 144 | -2 * D + log(n)*m*k 145 | } 146 | 147 | AIC.kmeans <- function(object, ..., k=2) 148 | { 149 | m <- ncol(object$centers) 150 | n <- length(object$cluster) 151 | k <- nrow(object$centers) 152 | D <- object$tot.withinss 153 | -2 * D + 2*m*k 154 | } 155 | -------------------------------------------------------------------------------- /R/SVD.R: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Open Connectome Project (http://openconnecto.me) 2 | # Written by Da Zheng (zhengda1936@gmail.com) 3 | # 4 | # This file is part of FlashR. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | #' Compute the singular-value decomposition on a large matrix. 19 | #' 20 | #' The difference between \code{svd} and \code{fm.svd} is that \code{fm.svd} 21 | #' allows a user-specified tol. \code{svd} computes eigenvalues in machine 22 | #' precision. 23 | #' 24 | #' @param x a FlashR matrix 25 | #' @param nu the number of left singluar vectors to be computed. 26 | #' @param nv the number of right singluar vectors to be computed. 27 | #' @param tol Stopping criterion: the relative accuracy of the Ritz value 28 | #' is considered acceptable if its error is less than 'tol' times its estimated 29 | #' value. If this is set to zero then machine precision is used. 30 | #' @return Returns a list with three entries 31 | #' \item{d}{ max(nu, nv) approximate singular values} 32 | #' \item{u}{ nu approximate left singular vectors (only when right_only=FALSE)} 33 | #' \item{v}{ nv approximate right singular vectors} 34 | #' @author Da Zheng 35 | #' @name svd 36 | #' 37 | #' @examples 38 | #' mat <- fm.runif.matrix(1000, 100) 39 | #' res <- fm.svd(mat, nu=10, nv=0) 40 | #' res <- svd(mat, nu=10, nv=0) 41 | NULL 42 | 43 | #' @rdname svd 44 | fm.svd <- function(x, nu=min(n, p), nv=min(n, p), tol=1e-8) 45 | { 46 | stopifnot(class(x) == "fm") 47 | x <- as.double(x) 48 | n <- dim(x)[1] 49 | p <- dim(x)[2] 50 | tx <- t(x) 51 | comp.right <- FALSE 52 | if (nrow(x) > ncol(x)) 53 | comp.right <- TRUE 54 | 55 | nev <- max(nu, nv) 56 | x.prod <- NULL 57 | if (fm.is.sparse(x) && comp.right) { 58 | size <- ncol(x) 59 | multiply <- function(vec, extra) t(x) %*% (x %*% vec) 60 | } 61 | else if (fm.is.sparse(x)) { 62 | size <- nrow(x) 63 | multiply <- function(vec, extra) x %*% (t(x) %*% vec) 64 | } 65 | else if (comp.right) { 66 | size <- ncol(x) 67 | x.prod <- tx %*% x 68 | multiply <- function(vec, extra) x.prod %*% vec 69 | } 70 | else { 71 | size <- nrow(x) 72 | x.prod <- x %*% tx 73 | multiply <- function(vec, extra) x.prod %*% vec 74 | } 75 | # If it's a very small matrix, we can compute its eigenvalues directly. 76 | # Or if we need to compute many eigenvalues, we probably should also 77 | # compute its eigenvalues directly. 78 | if (!is.null(x.prod) && (size < 100 || nev >= size / 2)) { 79 | if (!is.matrix(x.prod)) 80 | x.prod <- as.matrix(x.prod) 81 | res <- eigen(x.prod, TRUE, FALSE) 82 | res$values <- res$values[1:nev] 83 | nev <- nrow(x.prod) 84 | res$vectors <- fm.as.matrix(res$vectors) 85 | } 86 | else 87 | res <- fm.eigen(multiply, nev, size, which="LM", sym=TRUE, 88 | options=list(tol=tol, ncv=max(nev * 2, 5))) 89 | if (fm.is.vector(res$vectors)) 90 | res$vectors <- fm.as.matrix(res$vectors) 91 | 92 | # After we compute the other singular vectors, we need to rescale 93 | # these singular vectors because they aren't orthonormal. 94 | rescale <- function(x) { 95 | if (fm.is.vector(x)) 96 | x <- fm.as.matrix(x) 97 | fm.set.cached(x, TRUE) 98 | scal <- sqrt(colSums(x * x)) 99 | x <- fm.mapply.row(x, scal, fm.bo.div) 100 | } 101 | if (comp.right) { 102 | right <- NULL 103 | if (nv > 0) { 104 | if (nv < nev) 105 | right <- res$vectors[,1:nv] 106 | else 107 | right <- res$vectors 108 | } 109 | left <- NULL 110 | if (nu > 0) { 111 | left <- x %*% res$vectors[,1:nu] 112 | left <- rescale(left) 113 | } 114 | } 115 | else { 116 | left <- NULL 117 | if (nu > 0) { 118 | if (nu < nev) 119 | left <- res$vectors[,1:nu] 120 | else 121 | left <- res$vectors 122 | } 123 | right <- NULL 124 | if (nv > 0) { 125 | right <- t(x) %*% res$vectors[,1:nv] 126 | right <- rescale(right) 127 | } 128 | } 129 | # If an eigenvalue is very small (close to the machine precision), it's 130 | # possible that the eigenvalue is negative but very close to 0. 131 | vals <- ifelse(res$values > 0, res$values, 0) 132 | list(d=sqrt(vals), u=left, v=right, options=res$options) 133 | } 134 | 135 | #' @rdname svd 136 | setMethod("svd", signature(x = "fm"), function(x, nu=min(n, p), nv=min(n, p), LINPACK) { 137 | x <- fm.as.matrix(x) 138 | if (any(!is.finite(x))) 139 | stop("infinite or missing values in 'x'") 140 | dx <- dim(x) 141 | n <- dx[1L] 142 | p <- dx[2L] 143 | if (!n || !p) 144 | stop("a dimension is zero") 145 | fm.res <- fm.svd(x, nu, nv, tol=.Machine$double.eps) 146 | res <- list(d = fm.res$d) 147 | if (nu) 148 | res$u <- fm.res$u 149 | if (nv) 150 | res$v <- fm.res$v 151 | res 152 | }) 153 | 154 | setMethod("prcomp", signature(x = "fm"), function(x, retx=TRUE, center=TRUE, 155 | scale.=FALSE, tol=NULL) { 156 | scale.x <- scale(x, center, scale.) 157 | res <- fm.svd(scale.x, nu=0, tol=.Machine$double.eps) 158 | if (!is.null(tol)) { 159 | idxs <- which(res$d > tol) 160 | rotation <- res$v[, idxs] 161 | } 162 | else 163 | rotation <- res$v 164 | if (retx) 165 | x <- scale.x %*% rotation 166 | else 167 | x <- NULL 168 | list(sdev=res$d / sqrt(nrow(scale.x) - 1), rotation=rotation, x=x) 169 | }) 170 | -------------------------------------------------------------------------------- /R/graphics.R: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Open Connectome Project (http://openconnecto.me) 2 | # Written by Da Zheng (zhengda1936@gmail.com) 3 | # 4 | # This file is part of FlashR. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | fm.hist <- function(x, breaks=c("even", "exp"), exp.base=2, plot=TRUE, 19 | plot.file="", log="", xlab=NULL, ylab=NULL) 20 | { 21 | breaks <- match.arg(breaks) 22 | if (breaks == "exp") { 23 | x <- ifelse(x > 0, floor(log(x, exp.base)), 0) 24 | r <- range(x) 25 | vals <- seq(r[1], r[2], 1) 26 | } 27 | else { 28 | r <- range(x) 29 | size <- (r[2] - r[1]) / 100 30 | x <- floor(x / size) 31 | } 32 | tbl <- fm.table(x) 33 | 34 | if (breaks == "exp") { 35 | vals <- fm.conv.FM2R(tbl@val) 36 | breaks <- exp.base^vals 37 | x.names <- paste(as.character(exp.base), "^",as.character(vals), sep="") 38 | } 39 | else { 40 | breaks <- fm.conv.FM2R(tbl@val) * size 41 | x.names <- as.character(breaks) 42 | } 43 | 44 | if (plot && plot.file != "") { 45 | pdf(plot.file) 46 | barplot(fm.conv.FM2R(tbl@Freq), space=0, names.arg=x.names, log=log, 47 | xlab=xlab, ylab=ylab) 48 | dev.off() 49 | } 50 | else if (plot) { 51 | barplot(fm.conv.FM2R(tbl@Freq), space=0, names.arg=x.names, log=log, 52 | xlab=xlab, ylab=ylab) 53 | } 54 | else 55 | list(breaks=breaks, counts=fm.conv.FM2R(tbl@Freq)) 56 | } 57 | 58 | fm.heatmap <- function(coo1, num.slots, logval=FALSE, plot=TRUE, plot.file="", 59 | plot.format="pdf") 60 | { 61 | tbl1 <- fm.table(floor(coo1[,1] * num.slots)) 62 | tbl2 <- fm.table(floor(coo1[,2] * num.slots)) 63 | min.val1 <- as.vector(min(tbl1@val)) 64 | min.val2 <- as.vector(min(tbl2@val)) 65 | len1 <- as.vector(tbl1@val[length(tbl1@val)]) - as.vector(tbl1@val[1]) + 1 66 | len2 <- as.vector(tbl2@val[length(tbl2@val)]) - as.vector(tbl2@val[1]) + 1 67 | vec <- rep(0, times=len1 * len2) 68 | tbl <- fm.table(floor(coo1[,1] * num.slots)*len2 + floor(coo1[,2]*num.slots)) 69 | min.val <- min.val1 * len2 + min.val2 70 | vec[as.vector(tbl@val) - min.val + 1] <- as.vector(tbl@Freq) 71 | row.names <- as.character(seq(min.val2, as.vector(max(tbl2@val)), 1)/num.slots) 72 | col.names <- as.character(seq(min.val1, as.vector(max(tbl1@val)), 1)/num.slots) 73 | data <- matrix(vec, len2, len1, dimnames=list(row.names, col.names)) 74 | if (plot) { 75 | if (plot.file != "" && plot.format == "pdf") 76 | pdf(plot.file) 77 | else if (plot.file != "" && plot.format == "jpg") 78 | jpeg(plot.file) 79 | if (logval) 80 | data <- ifelse(log(data) == -Inf, 0, log(data)) 81 | heatmap.2(data, Colv="NA", Rowv="NA", trace="none") 82 | if (plot.file != "") 83 | dev.off() 84 | } 85 | else { 86 | data 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /aclocal.m4: -------------------------------------------------------------------------------- 1 | # generated automatically by aclocal 1.14.1 -*- Autoconf -*- 2 | 3 | # Copyright (C) 1996-2013 Free Software Foundation, Inc. 4 | 5 | # This file is free software; the Free Software Foundation 6 | # gives unlimited permission to copy and/or distribute it, 7 | # with or without modifications, as long as this notice is preserved. 8 | 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without 11 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A 12 | # PARTICULAR PURPOSE. 13 | 14 | m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])]) 15 | # =========================================================================== 16 | # http://www.gnu.org/software/autoconf-archive/ax_check_library.html 17 | # =========================================================================== 18 | # 19 | # SYNOPSIS 20 | # 21 | # AX_CHECK_LIBRARY(VARIABLE-PREFIX, HEADER-FILE, LIBRARY-FILE, 22 | # [ACTION-IF-FOUND], [ACTION-IF-NOT_FOUND]) 23 | # 24 | # DESCRIPTION 25 | # 26 | # Provides a generic test for a given library, similar in concept to the 27 | # PKG_CHECK_MODULES macro used by pkg-config. 28 | # 29 | # Most simplest libraries can be checked against simply through the 30 | # presence of a header file and a library to link to. This macro allows to 31 | # wrap around the test so that it doesn't have to be recreated each time. 32 | # 33 | # Rather than define --with-$LIBRARY arguments, it uses variables in the 34 | # same way that PKG_CHECK_MODULES does. It doesn't, though, use the same 35 | # names, since you shouldn't provide a value for LIBS or CFLAGS but rather 36 | # for LDFLAGS and CPPFLAGS, to tell the linker and compiler where to find 37 | # libraries and headers respectively. 38 | # 39 | # If the library is find, HAVE_PREFIX is defined, and in all cases 40 | # PREFIX_LDFLAGS and PREFIX_CPPFLAGS are substituted. 41 | # 42 | # Example: 43 | # 44 | # AX_CHECK_LIBRARY([LIBEVENT], [event.h], [event], [], 45 | # [AC_MSG_ERROR([Unable to find libevent])]) 46 | # 47 | # LICENSE 48 | # 49 | # Copyright (c) 2010 Diego Elio Petteno` 50 | # 51 | # This program is free software: you can redistribute it and/or modify it 52 | # under the terms of the GNU General Public License as published by the 53 | # Free Software Foundation, either version 3 of the License, or (at your 54 | # option) any later version. 55 | # 56 | # This program is distributed in the hope that it will be useful, but 57 | # WITHOUT ANY WARRANTY; without even the implied warranty of 58 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 59 | # Public License for more details. 60 | # 61 | # You should have received a copy of the GNU General Public License along 62 | # with this program. If not, see . 63 | # 64 | # As a special exception, the respective Autoconf Macro's copyright owner 65 | # gives unlimited permission to copy, distribute and modify the configure 66 | # scripts that are the output of Autoconf when processing the Macro. You 67 | # need not follow the terms of the GNU General Public License when using 68 | # or distributing such scripts, even though portions of the text of the 69 | # Macro appear in them. The GNU General Public License (GPL) does govern 70 | # all other use of the material that constitutes the Autoconf Macro. 71 | # 72 | # This special exception to the GPL applies to versions of the Autoconf 73 | # Macro released by the Autoconf Archive. When you make and distribute a 74 | # modified version of the Autoconf Macro, you may extend this special 75 | # exception to the GPL to apply to your modified version as well. 76 | 77 | #serial 4 78 | 79 | AC_DEFUN([AX_CHECK_LIBRARY], [ 80 | AC_ARG_VAR($1[_CPPFLAGS], [C preprocessor flags for ]$1[ headers]) 81 | AC_ARG_VAR($1[_LDFLAGS], [linker flags for ]$1[ libraries]) 82 | 83 | AC_CACHE_VAL(AS_TR_SH([ax_cv_have_]$1), 84 | [save_CPPFLAGS="$CPPFLAGS" 85 | save_LDFLAGS="$LDFLAGS" 86 | save_LIBS="$LIBS" 87 | 88 | AS_IF([test "x$]$1[_CPPFLAGS" != "x"], 89 | [CPPFLAGS="$CPPFLAGS $]$1[_CPPFLAGS"]) 90 | 91 | AS_IF([test "x$]$1[_LDFLAGS" != "x"], 92 | [LDFLAGS="$LDFLAGS $]$1[_LDFLAGS"]) 93 | 94 | AC_CHECK_HEADER($2, [ 95 | AC_CHECK_LIB($3, [main], 96 | [AS_TR_SH([ax_cv_have_]$1)=yes], 97 | [AS_TR_SH([ax_cv_have_]$1)=no]) 98 | ], [AS_TR_SH([ax_cv_have_]$1)=no]) 99 | 100 | CPPFLAGS="$save_CPPFLAGS" 101 | LDFLAGS="$save_LDFLAGS" 102 | LIBS="$save_LIBS" 103 | ]) 104 | 105 | AS_IF([test "$]AS_TR_SH([ax_cv_have_]$1)[" = "yes"], 106 | AC_DEFINE([HAVE_]$1, [1], [Define to 1 if ]$1[ is found]) 107 | [$4], 108 | [$5]) 109 | ]) 110 | 111 | # ============================================================================ 112 | # http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_0x.html 113 | # ============================================================================ 114 | # 115 | # SYNOPSIS 116 | # 117 | # AX_CXX_COMPILE_STDCXX_0X 118 | # 119 | # DESCRIPTION 120 | # 121 | # Check for baseline language coverage in the compiler for the C++0x 122 | # standard. 123 | # 124 | # LICENSE 125 | # 126 | # Copyright (c) 2008 Benjamin Kosnik 127 | # 128 | # Copying and distribution of this file, with or without modification, are 129 | # permitted in any medium without royalty provided the copyright notice 130 | # and this notice are preserved. This file is offered as-is, without any 131 | # warranty. 132 | 133 | #serial 7 134 | 135 | AU_ALIAS([AC_CXX_COMPILE_STDCXX_0X], [AX_CXX_COMPILE_STDCXX_0X]) 136 | AC_DEFUN([AX_CXX_COMPILE_STDCXX_0X], [ 137 | AC_CACHE_CHECK(if g++ supports C++0x features without additional flags, 138 | ax_cv_cxx_compile_cxx0x_native, 139 | [AC_LANG_SAVE 140 | AC_LANG_CPLUSPLUS 141 | AC_TRY_COMPILE([ 142 | template 143 | struct check 144 | { 145 | static_assert(sizeof(int) <= sizeof(T), "not big enough"); 146 | }; 147 | 148 | typedef check> right_angle_brackets; 149 | 150 | int a; 151 | decltype(a) b; 152 | 153 | typedef check check_type; 154 | check_type c; 155 | check_type&& cr = static_cast(c);],, 156 | ax_cv_cxx_compile_cxx0x_native=yes, ax_cv_cxx_compile_cxx0x_native=no) 157 | AC_LANG_RESTORE 158 | ]) 159 | 160 | AC_CACHE_CHECK(if g++ supports C++0x features with -std=c++0x, 161 | ax_cv_cxx_compile_cxx0x_cxx, 162 | [AC_LANG_SAVE 163 | AC_LANG_CPLUSPLUS 164 | ac_save_CXXFLAGS="$CXXFLAGS" 165 | CXXFLAGS="$CXXFLAGS -std=c++0x" 166 | AC_TRY_COMPILE([ 167 | template 168 | struct check 169 | { 170 | static_assert(sizeof(int) <= sizeof(T), "not big enough"); 171 | }; 172 | 173 | typedef check> right_angle_brackets; 174 | 175 | int a; 176 | decltype(a) b; 177 | 178 | typedef check check_type; 179 | check_type c; 180 | check_type&& cr = static_cast(c);],, 181 | ax_cv_cxx_compile_cxx0x_cxx=yes, ax_cv_cxx_compile_cxx0x_cxx=no) 182 | CXXFLAGS="$ac_save_CXXFLAGS" 183 | AC_LANG_RESTORE 184 | ]) 185 | 186 | AC_CACHE_CHECK(if g++ supports C++0x features with -std=gnu++0x, 187 | ax_cv_cxx_compile_cxx0x_gxx, 188 | [AC_LANG_SAVE 189 | AC_LANG_CPLUSPLUS 190 | ac_save_CXXFLAGS="$CXXFLAGS" 191 | CXXFLAGS="$CXXFLAGS -std=gnu++0x" 192 | AC_TRY_COMPILE([ 193 | template 194 | struct check 195 | { 196 | static_assert(sizeof(int) <= sizeof(T), "not big enough"); 197 | }; 198 | 199 | typedef check> right_angle_brackets; 200 | 201 | int a; 202 | decltype(a) b; 203 | 204 | typedef check check_type; 205 | check_type c; 206 | check_type&& cr = static_cast(c);],, 207 | ax_cv_cxx_compile_cxx0x_gxx=yes, ax_cv_cxx_compile_cxx0x_gxx=no) 208 | CXXFLAGS="$ac_save_CXXFLAGS" 209 | AC_LANG_RESTORE 210 | ]) 211 | 212 | if test "$ax_cv_cxx_compile_cxx0x_native" = yes || 213 | test "$ax_cv_cxx_compile_cxx0x_cxx" = yes || 214 | test "$ax_cv_cxx_compile_cxx0x_gxx" = yes; then 215 | AC_DEFINE(HAVE_STDCXX_0X,,[Define if g++ supports C++0x features. ]) 216 | fi 217 | ]) 218 | 219 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT(FlashR, @VERSION@, zhengda1936@gmail.com) 2 | AC_CONFIG_SRCDIR(src/matrix_interface.cpp) 3 | AC_CONFIG_HEADERS(src/config.h) 4 | AC_CONFIG_MACRO_DIR([/usr/share/aclocal/]) 5 | 6 | : ${R_HOME=`R RHOME`} 7 | if test -z "${R_HOME}"; then 8 | echo "could not determine R_HOME" 9 | exit 1 10 | fi 11 | CC=`"${R_HOME}/bin/R" CMD config CC` 12 | CXX=`"${R_HOME}/bin/R" CMD config CXX` 13 | FC=`"${R_HOME}/bin/R" CMD config FC` 14 | CFLAGS=`"${R_HOME}/bin/R" CMD config CFLAGS` 15 | CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXXFLAGS` 16 | CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS` 17 | FCFLAGS=`"${R_HOME}/bin/R" CMD config FCFLAGS` 18 | FLIBS=`"${R_HOME}/bin/R" CMD config FLIBS` 19 | 20 | AC_LANG(C) 21 | AC_PROG_CC 22 | 23 | AC_LANG(C++) 24 | AC_REQUIRE_CPP 25 | 26 | AX_CXX_COMPILE_STDCXX_0X 27 | 28 | LIBS_SAVE=$LIBS 29 | LIBS="$LIBS -lm" 30 | AC_CHECK_FUNCS([log2 round]) 31 | LIBS=$LIBS_SAVE 32 | 33 | AC_CHECK_HEADER([sys/times.h], 34 | [AC_DEFINE([HAVE_TIMES_H], [1], [Define to 1 if you have the sys/times.h header])]) 35 | 36 | AC_CHECK_HEADER([hwloc.h], [AC_SUBST(HWLOC_DEF, -DUSE_HWLOC)]) 37 | AC_CHECK_LIB([hwloc], [hwloc_topology_load], [AC_SUBST(HWLOC_LIB, -lhwloc)]) 38 | 39 | AC_CHECK_HEADER([pthread.h], [], [AC_MSG_ERROR("can't find pthread")]) 40 | AC_CHECK_LIB([pthread], [pthread_create], [AC_SUBST(PTHREAD_LIB, -lpthread)], [AC_MSG_ERROR("can't find pthread")]) 41 | 42 | AC_CHECK_HEADER([libaio.h], [AC_SUBST(AIO_DEF, -DUSE_LIBAIO)]) 43 | AC_CHECK_LIB([aio], [io_submit], [AC_SUBST(AIO_LIB, -laio)]) 44 | 45 | AC_CHECK_HEADER([numa.h], [AC_SUBST(NUMA_DEF, -DUSE_NUMA)]) 46 | AC_CHECK_LIB([numa], [numa_alloc_local], [AC_SUBST(NUMA_LIB, -lnuma)]) 47 | 48 | #graphml_support=yes 49 | #AC_ARG_ENABLE(graphml, 50 | # AC_HELP_STRING([--disable-graphml], [Disable support for GraphML format]), 51 | # [graphml_support=$enableval], [graphml_support=yes]) 52 | 53 | sh find_FlashX_objs.sh >> src/Makevars.in 54 | 55 | AC_CONFIG_FILES([src/Makevars.tmp:src/Makevars.in], [ 56 | if test -f src/Makevars && cmp -s src/Makevars.tmp src/Makevars; then 57 | AC_MSG_NOTICE([creating src/Makevars]) 58 | AC_MSG_NOTICE([src/Makevars is unchanged]) 59 | rm src/Makevars.tmp 60 | else 61 | AC_MSG_NOTICE([creating src/Makevars]) 62 | mv src/Makevars.tmp src/Makevars 63 | fi 64 | ] 65 | ) 66 | 67 | AC_OUTPUT 68 | -------------------------------------------------------------------------------- /demo/eigen.R: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Open Connectome Project (http://openconnecto.me) 2 | # Written by Da Zheng (zhengda1936@gmail.com) 3 | # 4 | # This file is part of FlashMatrixR. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | # This implements Implicit Restart Lanczos Method. 19 | 20 | safe.min <- 1e-12 21 | 22 | norm2 <- function(x) 23 | { 24 | sqrt(fm.sum(x * x)) 25 | } 26 | 27 | initr <- function(n) 28 | { 29 | # x <- rep.int(1, n) 30 | x <- fm.runif(n, -1, 1) 31 | } 32 | 33 | # In this version of initialization of r, we need to reorthoganize r against 34 | # the current Lanczos basis. 35 | reinitr <- function(n, V) 36 | { 37 | r <- initr(n) 38 | b0 <- norm2(r) 39 | 40 | iter <- 0 41 | while (iter < 5) { 42 | iter <- iter + 1 43 | s <- fm.multiply(fm.t(V), r) 44 | r <- r - fm.multiply(V, s) 45 | b <- norm2(r) 46 | if (b <= 0.717 * b0) 47 | break 48 | b0 <- b 49 | print("reothoganize r in reinitr") 50 | } 51 | stopifnot(iter < 5) 52 | r 53 | } 54 | 55 | lanczos <- function(A.multiply, k, m, r, V, T) 56 | { 57 | n <- fm.length(r) 58 | b <- norm2(r) 59 | for (j in (k+1):m) { 60 | restart <- FALSE 61 | # Step 1: we need to reinitialize r if necessary. 62 | if (b == 0) { 63 | stopifnot(j > 1) 64 | print("reinitialize r") 65 | r <- reinitr(n, V[,1:(j-1)]) 66 | restart <- TRUE 67 | } 68 | 69 | # Step 2 70 | # stopifnot(b >= safmin) 71 | vj <- r / b 72 | fm.set.cols(V, j, vj) 73 | 74 | # Step 3 75 | r <- A.multiply(vj) 76 | 77 | # Step 4 78 | wnorm <- norm2(r) 79 | w <- fm.multiply(fm.t(fm.get.cols(V,1:j)), r) 80 | r <- r - fm.multiply(fm.get.cols(V,1:j), w) 81 | a <- fm.conv.FM2R(w)[j] 82 | T[j,j] <- a 83 | if (j > 1) { 84 | if (restart) { 85 | T[j, j-1] <- 0 86 | T[j-1, j] <- 0 87 | } 88 | else { 89 | T[j, j-1] <- b 90 | T[j-1, j] <- b 91 | } 92 | } 93 | b <- norm2(r) 94 | 95 | # Step 5 96 | orth.iter <- 0 97 | while (b <= 0.717 * wnorm && orth.iter < 2) { 98 | orth.iter <- orth.iter + 1 99 | s <- fm.multiply(fm.t(fm.get.cols(V,1:j)), r) 100 | r <- r - fm.multiply(fm.get.cols(V,1:j), s) 101 | a <- a + fm.conv.FM2R(s)[j] 102 | T[j,j] <- a 103 | new.b <- norm2(r) 104 | if (new.b > 0.717 * b) { 105 | b <- new.b 106 | break 107 | } 108 | # Try to orthoganize r again 109 | else if (orth.iter < 2) { 110 | print("reothoganize r again") 111 | b <- new.b 112 | next 113 | } 114 | # If we still can't orthoganize r, we need to go to the first 115 | # step and reinitialize r. 116 | else { 117 | print("fail to reorthoganize r") 118 | r <- 0 119 | b <- 0 120 | break 121 | } 122 | } 123 | 124 | if (j > 1 && T[j, j-1] < 0) { 125 | print("negative T[j,j-1]") 126 | # TODO 127 | # T[j, j-1] <- -T[j, j-1] 128 | # T[j-1, j] <- -T[j-1, j] 129 | # if (j < m) 130 | # V[,j] <- -V[,j] 131 | # else 132 | # r <- -r 133 | } 134 | } 135 | 136 | list(T, V, r, b) 137 | } 138 | 139 | compute.eigen <- function(T, last.beta) 140 | { 141 | m <- dim(T)[1] 142 | ev <- eigen(T, TRUE) 143 | # print(ev$values) 144 | bounds <- rep.int(0, m) 145 | for (i in 1:m) 146 | bounds[i] <- abs(last.beta * ev$vectors[m, i]) 147 | list(values=ev$values, vectors=ev$vectors, bounds=bounds) 148 | } 149 | 150 | sort.eigen <- function(ev, which, k) 151 | { 152 | if (which == "LA") { 153 | sort.ret <- sort(ev$values, decreasing=TRUE, index.return=TRUE) 154 | } 155 | else if (which == "SA") { 156 | sort.ret <- sort(ev$values, decreasing=FALSE, index.return=TRUE) 157 | } 158 | else if (which == "LM") { 159 | sort.ret <- sort(abs(ev$values), decreasing=TRUE, index.return=TRUE) 160 | } 161 | else if (which == "SM") { 162 | sort.ret <- sort(abs(ev$values), decreasing=FALSE, index.return=TRUE) 163 | } 164 | ret <- list(values=ev$values[sort.ret$ix], vectors=ev$vectors[,sort.ret$ix], 165 | bounds=ev$bounds[sort.ret$ix]) 166 | m <- length(ev$values) 167 | if (m - k > 1) { 168 | sort.ret <- sort(abs(ret$bounds[(k+1):m]), decreasing=TRUE, index.return=TRUE) 169 | ret$values[(k+1):m] <- ret$values[k + sort.ret$ix] 170 | ret$vectors[,(k+1):m] <- ret$vectors[,k + sort.ret$ix] 171 | ret$bounds[(k+1):m] <- ret$bounds[k + sort.ret$ix] 172 | } 173 | ret 174 | } 175 | 176 | test.conv <- function(ev, k, tol) 177 | { 178 | converged <- c() 179 | for (i in 1:k) { 180 | if (ev$bounds[i] < tol * abs(ev$values[i])) { 181 | converged <- append(converged, i) 182 | } 183 | } 184 | 185 | m <- length(ev$values) 186 | # wanted eigen values 187 | list(wval=ev$values[converged], 188 | # wanted eigen vectors 189 | wvec=ev$vectors[, converged], 190 | # unwanted eigen values 191 | uval=ev$values[(k+1):m]) 192 | } 193 | 194 | #' Compute eigenvalues/vectors on a symmetric matrix. 195 | #' 196 | #' This method reimplements implicitly restarted Lanczos method to compute 197 | #' eigenvalues and eigenvectors. The method is implemented completely in R 198 | #' and follows the implementation of ARPACK library. 199 | #' 200 | #' @param A.multiply the function to perform matrix vector multiplication. 201 | #' @param n Numeric scalar. The dimension of the eigenproblem. 202 | #' @param k Numeric scalar. The number of eigenvalues to be computed. 203 | #' @param m Number of Lanczos vectors to be generated. 204 | #' @param which Specify which eigenvalues/vectors to compute, character 205 | #' constant with exactly two characters. 206 | #' Possible values for symmetric input matrices: 207 | #' "LA" Compute "nev" largest (algebraic) eigenvalues. 208 | #' "SA" Compute "nev" smallest (algebraic) eigenvalues. 209 | #' "LM" Compute "nev" largest (in magnitude) eigenvalues. 210 | #' "SM" Compute "nev" smallest (in magnitude) eigenvalues. 211 | #' @param Numeric scalar. Stopping criterion: the relative accuracy of 212 | #' the Ritz value is considered acceptable if its error is less than 'tol' 213 | #' times its estimated value. If this is set to zero then machine precision is used. 214 | #' @author Da Zheng 215 | fm.arpack <- function(A.multiply, n, k, m, which, tol) 216 | { 217 | # n <- dim(A)[1] 218 | V <- fm.matrix(fm.rep.int(0, n*m), nrow=n, ncol=m) 219 | T <- matrix(rep.int(0, m*m), nrow=m, ncol=m) 220 | r <- initr(n) 221 | res <- lanczos(A.multiply, 0, m, r, V, T) 222 | T <- res[[1]] 223 | V <- res[[2]] 224 | rm <- res[[3]] 225 | last.beta <- res[[4]] 226 | iter <- 0 227 | while (TRUE) { 228 | iter <- iter + 1 229 | 230 | ev <- compute.eigen(T, last.beta) 231 | ev <- sort.eigen(ev, which, k) 232 | res <- test.conv(ev, k, tol) 233 | nconv <- length(res$wval) 234 | bounds <- ev$bounds 235 | np <- m - k 236 | nev <- k 237 | for (i in (k+1):m) { 238 | if (bounds[i] == 0) { 239 | np <- np - 1 240 | nev <- nev + 1 241 | } 242 | } 243 | 244 | if (nconv >= k || np == 0) { 245 | vecs <- fm.conv.R2FM(res$wvec[, 1:k]) 246 | return(list(values=res$wval[1:k], vectors=fm.multiply(V, vecs))) 247 | } 248 | 249 | if (nconv < nev) { 250 | nevbef <- nev 251 | nev <- nev + min(nconv, np / 2) 252 | if (nev == 1 && m >= 6) 253 | nev <- m / 2 254 | else if (nev == 1 && m > 2) 255 | nev <- 2 256 | np <- m - nev 257 | if (nevbef < nev) { 258 | ev <- sort.eigen(ev, which, nev) 259 | print("sort eigen again") 260 | } 261 | print(nev) 262 | } 263 | 264 | Q <- diag(m) 265 | for (j in 1:np) { 266 | mu <- res$uval[j] 267 | qr.res <- qr(T - mu * diag(m), tol=tol) 268 | Qj <- qr.Q(qr.res) 269 | T <- t(Qj) %*% T %*% Qj 270 | Q <- Q %*% Qj 271 | } 272 | bk <- T[nev+1, nev] 273 | sigma <- Q[m, nev] 274 | tmp <- fm.as.vector(fm.get.cols(V,nev+1)) 275 | rk <- bk * tmp + rm * sigma 276 | # rk <- rm * sigma 277 | fm.set.cols(V, 1:nev, fm.multiply(V, fm.conv.R2FM(Q[,1:nev]))) 278 | tmp <- matrix(rep.int(0, m * m), nrow=m, ncol=m) 279 | tmp[1:nev,1:nev] <- T[1:nev,1:nev] 280 | T <- tmp 281 | 282 | res <- lanczos(A.multiply, nev, m, rk, V, T) 283 | T <- res[[1]] 284 | V <- res[[2]] 285 | rm <- res[[3]] 286 | last.beta <- res[[4]] 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /demo/hierarical.spec.cluster.R: -------------------------------------------------------------------------------- 1 | num.clusters <- 1000 2 | num.eigens <- 40 3 | library(FlashR) 4 | fg.set.conf("flash-graph/conf/run_ssds.txt") 5 | vecs <- fm.read.obj(file="/mnt/store_raid/zhengda/friendster-lcc.acd.LM40.1e-6.evecs") 6 | col3 <- fm.get.cols(vecs, 1:3) 7 | r.col3 <- fm.conv.FM2R(col3) 8 | vals <- fm.conv.FM2R(fm.read.obj(file="/mnt/store_raid/zhengda/friendster-lcc.acd.LM40.1e-6.evals"))[1:3] 9 | ase <- r.col3 %*% diag(abs(as.vector(vals))) 10 | sXhat <- ase / sqrt(rowSums(ase^2)) 11 | kmeans.res <- fg.kmeans(sXhat, num.clusters, max.iters=100, init="random") 12 | fg <- fg.load.graph("/mnt/store_raid/zhengda/friendster-lcc.adj-v4", 13 | "/mnt/store_raid/zhengda/friendster-lcc.index-v4") 14 | 15 | large.ccs <- c() 16 | clusters <- kmeans.res$clusters 17 | for (cluster.id in 1:num.clusters) { 18 | clusterV <- which(kmeans.res$cluster==cluster.id) 19 | if (length(clusterV) == 0) 20 | next 21 | sub.fg <- fg.fetch.subgraph(fg, vertices=clusterV - 1, compress=FALSE) 22 | cat("subg #V:", fg.vcount(sub.fg), ", #E:", fg.ecount(sub.fg), "\n") 23 | sub.cc <- fg.clusters(sub.fg, mode="weak") 24 | clusters[clusterV] <- sub.cc[clusterV] 25 | 26 | counts <- as.data.frame(table(sub.cc[sub.cc >= 0])) 27 | lcc.id <- as.integer(levels(counts$Var1)[which.max(counts$Freq)]) 28 | if (max(counts$Freq) > 100) 29 | large.ccs <- c(large.ccs, lcc.id) 30 | cat("subg #components:", length(counts$Var1), ", lcc size:", 31 | sum(sub.cc == lcc.id), ", #isolates:", sum(sub.cc == -1), "\n") 32 | # lcc.fg <- fg.fetch.subgraph(sub.fg, vertices=) 33 | cat("There are ", length(unique(clusters)), " clusters\n") 34 | } 35 | 36 | # This can be used to collect the cluster membership from the vertices 37 | # in the components. 38 | tmp.clusters <- rep.int(-1, fg.vcount(fg)) 39 | max.cid <- 0 40 | for (large.cc in large.ccs) { 41 | clusterV <- which(clusters==large.cc) 42 | clusters[clusterV] <- -1 43 | sub.fg <- fg.fetch.subgraph(fg, vertices=clusterV - 1) 44 | # The cluster IDs are only valid in the subgraph. 45 | sub.clusters <- spec.cluster(sub.fg) 46 | # Now the cluster IDs are globally unique. 47 | tmp.clusters[clusterV] <- sub.clusters + max.cid 48 | max.cid <- max.cid + fg.vcount(sub.fg) 49 | } 50 | clusters[clusters != -1] <- clusters[clusters != -1] + max.cid 51 | clusters[tmp.clusters != -1] <- tmp.clusters[tmp.clusters != -1] 52 | 53 | spec.cluster <- function(fg) 54 | { 55 | eigen <- fg.ASE.igraph(fg, num.eigen=num.eigens, which="AcD", which.eigen="LM") 56 | ase <- eigen$vectors %*% diag(abs(as.vector(eigen$values))) 57 | sXhat <- ase / sqrt(rowSums(ase^2)) 58 | kmeans.res <- fg.kmeans(sXhat, num.clusters, max.iters=100, init="random") 59 | 60 | clusters <- kmeans.res$clusters 61 | for (cluster.id in 1:num.clusters) { 62 | clusterV <- which(kmeans.res$cluster==cluster.id) 63 | if (length(clusterV) == 0) 64 | next 65 | sub.fg <- fg.fetch.subgraph(fg, vertices=clusterV - 1, compress=FALSE) 66 | cat("subg #V:", fg.vcount(sub.fg), ", #E:", fg.ecount(sub.fg), "\n") 67 | sub.cc <- fg.clusters(sub.fg, mode="weak") 68 | clusters[clusterV] <- sub.cc[clusterV] 69 | } 70 | clusters 71 | } 72 | -------------------------------------------------------------------------------- /demo/test.cc.R: -------------------------------------------------------------------------------- 1 | library("FlashR") 2 | library("igraph") 3 | 4 | test.fg.cc <- function(fg, cc.type) 5 | { 6 | cc <- fg.clusters(fg, mode=cc.type) 7 | cc.counts <- as.data.frame(table(cc)) 8 | max.cc <- max(cc.counts$Freq) 9 | cat("There are", nrow(cc.counts), cc.type, "connected components\n") 10 | cat("The largest component has", max.cc, "vertices\n") 11 | 12 | fg.fetch.cc <- function(cid) 13 | { 14 | # Vertex ID starts with 0. 15 | vids <- which(cc == cid) - 1 16 | fg.fetch.subgraph(fg, vids) 17 | } 18 | 19 | # fetch each component from the graph but the largest one. 20 | fg.stat.cc <- function(x) 21 | { 22 | cc.id <- x[1] 23 | cc.size <- as.integer(x[2]) 24 | if (cc.id != -1 && cc.size > 1) { 25 | subg <- fg.fetch.cc(cc.id) 26 | ecount(subg) 27 | } 28 | } 29 | apply(cc.counts, 1, fg.stat.cc) 30 | } 31 | 32 | test.ig.cc <- function(ig, cc.type) 33 | { 34 | ig.cc <- clusters(ig, mode=cc.type) 35 | # isolates <- which(ig.cc$csize==1) 36 | # ig.cc$membership[ig.cc$membership %in% isolates]=-1 37 | ig.cc.counts <- as.data.frame(table(ig.cc$membership)) 38 | ig.max.cc <- max(ig.cc.counts$Freq) 39 | cat("There are", nrow(ig.cc.counts), cc.type, "connected components\n") 40 | cat("The largest component has", ig.max.cc, "vertices\n") 41 | 42 | ig.fetch.cc <- function(cid) 43 | { 44 | # Vertex ID starts with 0. 45 | vids <- which(ig.cc$membership == cid) 46 | induced.subgraph(ig, vids) 47 | } 48 | 49 | # fetch each component from the graph but the largest one. 50 | ig.stat.cc <- function(x) 51 | { 52 | cc.id <- x[1] 53 | cc.size <- as.integer(x[2]) 54 | if (cc.id != -1 && cc.size > 1) { 55 | subg <- ig.fetch.cc(cc.id) 56 | ecount(subg) 57 | } 58 | } 59 | apply(ig.cc.counts, 1, ig.stat.cc) 60 | } 61 | 62 | cc.type <- "weak" 63 | graph.name <- "wiki-Vote" 64 | fg <- fg.get.graph(graph.name) 65 | ig <- read.graph("wiki-Vote.txt") 66 | fg.res <- test.fg.cc(fg, cc.type) 67 | ig.res <- test.ig.cc(ig, cc.type) 68 | 69 | unlist(ig.res) == unlist(fg.res) 70 | -------------------------------------------------------------------------------- /find_FlashX_objs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | out="OBJECTS=" 4 | 5 | files=`ls src/*.c | grep -v "test" | sed -e "s/\.c$/\.o/g" | sed -e "s/^src\///g"` 6 | for I in $files 7 | do 8 | out=$out"$I " 9 | done 10 | 11 | files=`ls src/*.cpp | grep -v "test" | sed -e "s/\.cpp$/\.o/g" | sed -e "s/^src\///g"` 12 | for I in $files 13 | do 14 | out=$out"$I " 15 | done 16 | 17 | files=`find src/FlashX/matrix/ -name "*.cpp" | grep -v "test" | sed -e "s/\.cpp$/\.o/g" | sed -e "s/^src\///g"` 18 | for I in $files 19 | do 20 | out=$out"$I " 21 | done 22 | 23 | files=`find src/FlashX/libsafs/ -name "*.cpp" | grep -v "test" | sed -e "s/\.cpp$/\.o/g" | sed -e "s/^src\///g"` 24 | for I in $files 25 | do 26 | out=$out"$I " 27 | done 28 | 29 | echo $out 30 | -------------------------------------------------------------------------------- /man/Arithmetic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{Arithmetic} 5 | \alias{*,ANY,fm-method} 6 | \alias{*,ANY,fmV-method} 7 | \alias{*,fm,ANY-method} 8 | \alias{*,fm,fm-method} 9 | \alias{*,fm,fmV-method} 10 | \alias{*,fm,matrix-method} 11 | \alias{*,fmV,ANY-method} 12 | \alias{*,fmV,fm-method} 13 | \alias{*,fmV,fmV-method} 14 | \alias{*,matrix,fm-method} 15 | \alias{+,ANY,fm-method} 16 | \alias{+,ANY,fmV-method} 17 | \alias{+,fm,ANY-method} 18 | \alias{+,fm,fm-method} 19 | \alias{+,fm,fmV-method} 20 | \alias{+,fm,matrix-method} 21 | \alias{+,fmV,ANY-method} 22 | \alias{+,fmV,fm-method} 23 | \alias{+,fmV,fmV-method} 24 | \alias{+,matrix,fm-method} 25 | \alias{-,ANY,fm-method} 26 | \alias{-,ANY,fmV-method} 27 | \alias{-,fm,ANY-method} 28 | \alias{-,fm,fm-method} 29 | \alias{-,fm,fmV-method} 30 | \alias{-,fm,matrix-method} 31 | \alias{-,fm,missing-method} 32 | \alias{-,fmV,ANY-method} 33 | \alias{-,fmV,fm-method} 34 | \alias{-,fmV,fmV-method} 35 | \alias{-,fmV,missing-method} 36 | \alias{-,matrix,fm-method} 37 | \alias{/,ANY,fm-method} 38 | \alias{/,ANY,fmV-method} 39 | \alias{/,fm,ANY-method} 40 | \alias{/,fm,fm-method} 41 | \alias{/,fm,fmV-method} 42 | \alias{/,fm,matrix-method} 43 | \alias{/,fmV,ANY-method} 44 | \alias{/,fmV,fm-method} 45 | \alias{/,fmV,fmV-method} 46 | \alias{/,matrix,fm-method} 47 | \alias{Arithmetic} 48 | \alias{^,ANY,fmV-method} 49 | \alias{^,fm,ANY-method} 50 | \alias{^,fm,fm-method} 51 | \alias{^,fm,fmV-method} 52 | \alias{^,fm,matrix-method} 53 | \alias{^,fmV,ANY-method} 54 | \alias{^,fmV,fmV-method} 55 | \alias{^,matrix,fm-method} 56 | \title{Arithmetic Operators} 57 | \usage{ 58 | \S4method{-}{fm,missing}(e1, e2) 59 | 60 | \S4method{-}{fmV,missing}(e1, e2) 61 | 62 | \S4method{+}{fm,fm}(e1, e2) 63 | 64 | \S4method{+}{fmV,fmV}(e1, e2) 65 | 66 | \S4method{+}{fm,fmV}(e1, e2) 67 | 68 | \S4method{+}{fmV,fm}(e1, e2) 69 | 70 | \S4method{+}{fm,matrix}(e1, e2) 71 | 72 | \S4method{+}{matrix,fm}(e1, e2) 73 | 74 | \S4method{+}{fm,ANY}(e1, e2) 75 | 76 | \S4method{+}{ANY,fm}(e1, e2) 77 | 78 | \S4method{+}{fmV,ANY}(e1, e2) 79 | 80 | \S4method{+}{ANY,fmV}(e1, e2) 81 | 82 | \S4method{-}{fm,fm}(e1, e2) 83 | 84 | \S4method{-}{fmV,fmV}(e1, e2) 85 | 86 | \S4method{-}{fm,fmV}(e1, e2) 87 | 88 | \S4method{-}{fmV,fm}(e1, e2) 89 | 90 | \S4method{-}{fm,matrix}(e1, e2) 91 | 92 | \S4method{-}{matrix,fm}(e1, e2) 93 | 94 | \S4method{-}{fm,ANY}(e1, e2) 95 | 96 | \S4method{-}{ANY,fm}(e1, e2) 97 | 98 | \S4method{-}{fmV,ANY}(e1, e2) 99 | 100 | \S4method{-}{ANY,fmV}(e1, e2) 101 | 102 | \S4method{*}{fm,fm}(e1, e2) 103 | 104 | \S4method{*}{fmV,fmV}(e1, e2) 105 | 106 | \S4method{*}{fm,fmV}(e1, e2) 107 | 108 | \S4method{*}{fmV,fm}(e1, e2) 109 | 110 | \S4method{*}{fm,matrix}(e1, e2) 111 | 112 | \S4method{*}{matrix,fm}(e1, e2) 113 | 114 | \S4method{*}{fm,ANY}(e1, e2) 115 | 116 | \S4method{*}{ANY,fm}(e1, e2) 117 | 118 | \S4method{*}{fmV,ANY}(e1, e2) 119 | 120 | \S4method{*}{ANY,fmV}(e1, e2) 121 | 122 | \S4method{/}{fm,fm}(e1, e2) 123 | 124 | \S4method{/}{fmV,fmV}(e1, e2) 125 | 126 | \S4method{/}{fm,fmV}(e1, e2) 127 | 128 | \S4method{/}{fmV,fm}(e1, e2) 129 | 130 | \S4method{/}{fm,matrix}(e1, e2) 131 | 132 | \S4method{/}{matrix,fm}(e1, e2) 133 | 134 | \S4method{/}{fm,ANY}(e1, e2) 135 | 136 | \S4method{/}{ANY,fm}(e1, e2) 137 | 138 | \S4method{/}{fmV,ANY}(e1, e2) 139 | 140 | \S4method{/}{ANY,fmV}(e1, e2) 141 | 142 | \S4method{^}{fm,fm}(e1, e2) 143 | 144 | \S4method{^}{fmV,fmV}(e1, e2) 145 | 146 | \S4method{^}{fm,fmV}(e1, e2) 147 | 148 | \S4method{^}{fm,matrix}(e1, e2) 149 | 150 | \S4method{^}{matrix,fm}(e1, e2) 151 | 152 | \S4method{^}{ANY,fmV}(e1, e2) 153 | 154 | \S4method{^}{fm,ANY}(e1, e2) 155 | 156 | \S4method{^}{fmV,ANY}(e1, e2) 157 | } 158 | \arguments{ 159 | \item{e1, e2}{One of the operands need to be a FlashR object. If one operand 160 | is a matrix and the other is a vector, we perform the arithmetic operation 161 | on the vector and every column of the matrix. If one operand is a scalar, 162 | we perform the operation on the scalar with every element in the matrix or 163 | the vector. 164 | 165 | There are a few exceptions. For example, the left operand of "^" has to be 166 | a FlashR object and the right operand has to be a scalar.} 167 | } 168 | \description{ 169 | Perform unary or binary arithmetic operations on FlashR objects. 170 | } 171 | \examples{ 172 | mat1 <- fm.runif.matrix(100, 10) 173 | mat2 <- fm.runif.matrix(100, 10) 174 | mat <- -mat1 175 | mat <- mat1 + mat2 176 | mat <- mat1 - mat2 177 | mat <- mat1 * mat2 178 | mat <- mat1 / mat2 179 | mat <- mat1 ^ 2 180 | } 181 | 182 | -------------------------------------------------------------------------------- /man/Comparison.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{Comparison} 5 | \alias{!=,ANY,fm-method} 6 | \alias{!=,ANY,fmV-method} 7 | \alias{!=,fm,ANY-method} 8 | \alias{!=,fm,fm-method} 9 | \alias{!=,fm,fmV-method} 10 | \alias{!=,fm,matrix-method} 11 | \alias{!=,fmV,ANY-method} 12 | \alias{!=,fmV,fm-method} 13 | \alias{!=,fmV,fmV-method} 14 | \alias{!=,matrix,fm-method} 15 | \alias{<,ANY,fm-method} 16 | \alias{<,ANY,fmV-method} 17 | \alias{<,fm,ANY-method} 18 | \alias{<,fm,fm-method} 19 | \alias{<,fm,fmV-method} 20 | \alias{<,fm,matrix-method} 21 | \alias{<,fmV,ANY-method} 22 | \alias{<,fmV,fm-method} 23 | \alias{<,fmV,fmV-method} 24 | \alias{<,matrix,fm-method} 25 | \alias{<=,ANY,fm-method} 26 | \alias{<=,ANY,fmV-method} 27 | \alias{<=,fm,ANY-method} 28 | \alias{<=,fm,fm-method} 29 | \alias{<=,fm,fmV-method} 30 | \alias{<=,fm,matrix-method} 31 | \alias{<=,fmV,ANY-method} 32 | \alias{<=,fmV,fm-method} 33 | \alias{<=,fmV,fmV-method} 34 | \alias{<=,matrix,fm-method} 35 | \alias{==,ANY,fm-method} 36 | \alias{==,ANY,fmV-method} 37 | \alias{==,fm,ANY-method} 38 | \alias{==,fm,fm-method} 39 | \alias{==,fm,fmV-method} 40 | \alias{==,fm,matrix-method} 41 | \alias{==,fmV,ANY-method} 42 | \alias{==,fmV,fm-method} 43 | \alias{==,fmV,fmV-method} 44 | \alias{==,matrix,fm-method} 45 | \alias{>,ANY,fm-method} 46 | \alias{>,ANY,fmV-method} 47 | \alias{>,fm,ANY-method} 48 | \alias{>,fm,fm-method} 49 | \alias{>,fm,fmV-method} 50 | \alias{>,fm,matrix-method} 51 | \alias{>,fmV,ANY-method} 52 | \alias{>,fmV,fm-method} 53 | \alias{>,fmV,fmV-method} 54 | \alias{>,matrix,fm-method} 55 | \alias{>=,ANY,fm-method} 56 | \alias{>=,ANY,fmV-method} 57 | \alias{>=,fm,ANY-method} 58 | \alias{>=,fm,fm-method} 59 | \alias{>=,fm,fmV-method} 60 | \alias{>=,fm,matrix-method} 61 | \alias{>=,fmV,ANY-method} 62 | \alias{>=,fmV,fm-method} 63 | \alias{>=,fmV,fmV-method} 64 | \alias{>=,matrix,fm-method} 65 | \alias{Comparison} 66 | \title{Relational Operators} 67 | \usage{ 68 | \S4method{==}{fm,fm}(e1, e2) 69 | 70 | \S4method{==}{fmV,fmV}(e1, e2) 71 | 72 | \S4method{==}{fm,fmV}(e1, e2) 73 | 74 | \S4method{==}{fmV,fm}(e1, e2) 75 | 76 | \S4method{==}{fm,matrix}(e1, e2) 77 | 78 | \S4method{==}{matrix,fm}(e1, e2) 79 | 80 | \S4method{==}{fm,ANY}(e1, e2) 81 | 82 | \S4method{==}{ANY,fm}(e1, e2) 83 | 84 | \S4method{==}{fmV,ANY}(e1, e2) 85 | 86 | \S4method{==}{ANY,fmV}(e1, e2) 87 | 88 | \S4method{!=}{fm,fm}(e1, e2) 89 | 90 | \S4method{!=}{fmV,fmV}(e1, e2) 91 | 92 | \S4method{!=}{fm,fmV}(e1, e2) 93 | 94 | \S4method{!=}{fmV,fm}(e1, e2) 95 | 96 | \S4method{!=}{fm,matrix}(e1, e2) 97 | 98 | \S4method{!=}{matrix,fm}(e1, e2) 99 | 100 | \S4method{!=}{fm,ANY}(e1, e2) 101 | 102 | \S4method{!=}{ANY,fm}(e1, e2) 103 | 104 | \S4method{!=}{fmV,ANY}(e1, e2) 105 | 106 | \S4method{!=}{ANY,fmV}(e1, e2) 107 | 108 | \S4method{>}{fm,fm}(e1, e2) 109 | 110 | \S4method{>}{fmV,fmV}(e1, e2) 111 | 112 | \S4method{>}{fm,fmV}(e1, e2) 113 | 114 | \S4method{>}{fmV,fm}(e1, e2) 115 | 116 | \S4method{>}{fm,matrix}(e1, e2) 117 | 118 | \S4method{>}{matrix,fm}(e1, e2) 119 | 120 | \S4method{>}{fm,ANY}(e1, e2) 121 | 122 | \S4method{>}{ANY,fm}(e1, e2) 123 | 124 | \S4method{>}{fmV,ANY}(e1, e2) 125 | 126 | \S4method{>}{ANY,fmV}(e1, e2) 127 | 128 | \S4method{>=}{fm,fm}(e1, e2) 129 | 130 | \S4method{>=}{fmV,fmV}(e1, e2) 131 | 132 | \S4method{>=}{fm,fmV}(e1, e2) 133 | 134 | \S4method{>=}{fmV,fm}(e1, e2) 135 | 136 | \S4method{>=}{fm,matrix}(e1, e2) 137 | 138 | \S4method{>=}{matrix,fm}(e1, e2) 139 | 140 | \S4method{>=}{fm,ANY}(e1, e2) 141 | 142 | \S4method{>=}{ANY,fm}(e1, e2) 143 | 144 | \S4method{>=}{fmV,ANY}(e1, e2) 145 | 146 | \S4method{>=}{ANY,fmV}(e1, e2) 147 | 148 | \S4method{<=}{fm,fm}(e1, e2) 149 | 150 | \S4method{<=}{fmV,fmV}(e1, e2) 151 | 152 | \S4method{<=}{fm,fmV}(e1, e2) 153 | 154 | \S4method{<=}{fmV,fm}(e1, e2) 155 | 156 | \S4method{<=}{fm,matrix}(e1, e2) 157 | 158 | \S4method{<=}{matrix,fm}(e1, e2) 159 | 160 | \S4method{<=}{fm,ANY}(e1, e2) 161 | 162 | \S4method{<=}{ANY,fm}(e1, e2) 163 | 164 | \S4method{<=}{fmV,ANY}(e1, e2) 165 | 166 | \S4method{<=}{ANY,fmV}(e1, e2) 167 | 168 | \S4method{<}{fm,fm}(e1, e2) 169 | 170 | \S4method{<}{fmV,fmV}(e1, e2) 171 | 172 | \S4method{<}{fm,fmV}(e1, e2) 173 | 174 | \S4method{<}{fmV,fm}(e1, e2) 175 | 176 | \S4method{<}{fm,matrix}(e1, e2) 177 | 178 | \S4method{<}{matrix,fm}(e1, e2) 179 | 180 | \S4method{<}{fm,ANY}(e1, e2) 181 | 182 | \S4method{<}{ANY,fm}(e1, e2) 183 | 184 | \S4method{<}{fmV,ANY}(e1, e2) 185 | 186 | \S4method{<}{ANY,fmV}(e1, e2) 187 | } 188 | \arguments{ 189 | \item{e1, e2}{One of the operands need to be a FlashR object. If one operand 190 | is a matrix and the other is a vector, we perform the arithmetic operation 191 | on the vector and every column of the matrix. If one operand is a scalar, 192 | we perform the operation on the scalar with every element in the matrix or 193 | the vector.} 194 | } 195 | \description{ 196 | Binary operators which allow the comparison of values in atomic 197 | vectors. 198 | } 199 | \examples{ 200 | mat1 <- fm.runif.matrix(100, 10) 201 | mat2 <- fm.runif.matrix(100, 10) 202 | mat <- mat1 == mat2 203 | mat <- mat1 != mat2 204 | mat <- mat1 < mat2 205 | mat <- mat1 <= mat2 206 | mat <- mat1 > mat2 207 | mat <- mat1 >= mat2 208 | } 209 | 210 | -------------------------------------------------------------------------------- /man/Extract.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{Extract} 5 | \alias{Extract} 6 | \alias{[,fm,ANY,ANY,ANY-method} 7 | \alias{[,fm,ANY,missing,ANY-method} 8 | \alias{[,fm,missing,ANY,ANY-method} 9 | \alias{[,fmV,ANY,ANY,ANY-method} 10 | \alias{[<-,fm,ANY,missing,ANY-method} 11 | \alias{[<-,fm,missing,ANY,ANY-method} 12 | \title{Extract Parts of an object} 13 | \usage{ 14 | \S4method{[}{fm,ANY,missing,ANY}(x, i, j, drop = TRUE) 15 | 16 | \S4method{[}{fm,missing,ANY,ANY}(x, i, j, drop = TRUE) 17 | 18 | \S4method{[}{fm,ANY,ANY,ANY}(x, i, j, drop = TRUE) 19 | 20 | \S4method{[}{fmV,ANY,ANY,ANY}(x, i) 21 | 22 | \S4method{[}{fm,ANY,missing,ANY}(x, i, j) <- value 23 | 24 | \S4method{[}{fm,missing,ANY,ANY}(x, i, j) <- value 25 | } 26 | \arguments{ 27 | \item{x}{object from which to extract elements.} 28 | 29 | \item{i, j}{indices specifying elements to extract. Indices are integer 30 | or numeric vectors.} 31 | 32 | \item{drop}{for matrices. If \code{TRUE}, the result is coerced to a vector.} 33 | 34 | \item{value}{a FlashR vector or matrix that contains new data for the rows} 35 | } 36 | \description{ 37 | Operators acting on FlashR vectors and matrices to extract parts of 38 | the objects. 39 | } 40 | \details{ 41 | FlashR supports extracting data from an object as well as replacing data 42 | of a matrix. To assign data in a matrix, it only supports setting 43 | the entire rows or columns. 44 | } 45 | \examples{ 46 | mat <- fm.runif.matrix(100, 10) 47 | mat[1:5,] 48 | mat[,1:5] 49 | mat[1:5,1:5] 50 | mat[,1] <- fm.runif(nrow(mat)) 51 | } 52 | 53 | -------------------------------------------------------------------------------- /man/Extremes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{Extremes} 5 | \alias{Extremes} 6 | \alias{max,fm-method} 7 | \alias{max,fmV-method} 8 | \alias{min,fm-method} 9 | \alias{min,fmV-method} 10 | \alias{pmax,fm-method} 11 | \alias{pmax,fmV-method} 12 | \alias{pmax2} 13 | \alias{pmax2,ANY,fm-method} 14 | \alias{pmax2,ANY,fmV-method} 15 | \alias{pmax2,fm,ANY-method} 16 | \alias{pmax2,fm,fm-method} 17 | \alias{pmax2,fm,fmV-method} 18 | \alias{pmax2,fm,matrix-method} 19 | \alias{pmax2,fmV,ANY-method} 20 | \alias{pmax2,fmV,fm-method} 21 | \alias{pmax2,fmV,fmV-method} 22 | \alias{pmax2,matrix,fm-method} 23 | \alias{pmin,fm-method} 24 | \alias{pmin,fmV-method} 25 | \alias{pmin2} 26 | \alias{pmin2,ANY,fm-method} 27 | \alias{pmin2,ANY,fmV-method} 28 | \alias{pmin2,fm,ANY-method} 29 | \alias{pmin2,fm,fm-method} 30 | \alias{pmin2,fm,fmV-method} 31 | \alias{pmin2,fm,matrix-method} 32 | \alias{pmin2,fmV,ANY-method} 33 | \alias{pmin2,fmV,fm-method} 34 | \alias{pmin2,fmV,fmV-method} 35 | \alias{pmin2,matrix,fm-method} 36 | \title{Maxima and Minima} 37 | \usage{ 38 | pmax2(e1, e2) 39 | 40 | pmin2(e1, e2) 41 | 42 | \S4method{pmax2}{fm,fm}(e1, e2) 43 | 44 | \S4method{pmax2}{fmV,fmV}(e1, e2) 45 | 46 | \S4method{pmax2}{fm,fmV}(e1, e2) 47 | 48 | \S4method{pmax2}{fmV,fm}(e1, e2) 49 | 50 | \S4method{pmax2}{fm,matrix}(e1, e2) 51 | 52 | \S4method{pmax2}{matrix,fm}(e1, e2) 53 | 54 | \S4method{pmax2}{fm,ANY}(e1, e2) 55 | 56 | \S4method{pmax2}{ANY,fm}(e1, e2) 57 | 58 | \S4method{pmax2}{fmV,ANY}(e1, e2) 59 | 60 | \S4method{pmax2}{ANY,fmV}(e1, e2) 61 | 62 | \S4method{pmin2}{fm,fm}(e1, e2) 63 | 64 | \S4method{pmin2}{fmV,fmV}(e1, e2) 65 | 66 | \S4method{pmin2}{fm,fmV}(e1, e2) 67 | 68 | \S4method{pmin2}{fmV,fm}(e1, e2) 69 | 70 | \S4method{pmin2}{fm,matrix}(e1, e2) 71 | 72 | \S4method{pmin2}{matrix,fm}(e1, e2) 73 | 74 | \S4method{pmin2}{fm,ANY}(e1, e2) 75 | 76 | \S4method{pmin2}{ANY,fm}(e1, e2) 77 | 78 | \S4method{pmin2}{fmV,ANY}(e1, e2) 79 | 80 | \S4method{pmin2}{ANY,fmV}(e1, e2) 81 | 82 | \S4method{min}{fm}(x, ..., na.rm = FALSE) 83 | 84 | \S4method{min}{fmV}(x, ..., na.rm = FALSE) 85 | 86 | \S4method{max}{fm}(x, ..., na.rm = FALSE) 87 | 88 | \S4method{max}{fmV}(x, ..., na.rm = FALSE) 89 | 90 | \S4method{pmin}{fm}(..., na.rm = FALSE) 91 | 92 | \S4method{pmin}{fmV}(..., na.rm = FALSE) 93 | 94 | \S4method{pmax}{fm}(..., na.rm = FALSE) 95 | 96 | \S4method{pmax}{fmV}(..., na.rm = FALSE) 97 | } 98 | \arguments{ 99 | \item{e1, e2}{One of the operands need to be a FlashR object. If one 100 | operand is a matrix and the other is a vector, we perform the operation 101 | on the vector and every column of the matrix. If one operand is a scalar, 102 | we perform the operation on the scalar with every element in the matrix or 103 | the vector.} 104 | 105 | \item{x}{a FlashR vector or matrix.} 106 | 107 | \item{...}{FlashR vectors or matrices.} 108 | 109 | \item{na.rm}{a logical indicating whether missing values should be removed.} 110 | } 111 | \value{ 112 | \code{pmin2}, \code{pmax2}, \code{pmin} and \code{pmax} return 113 | a FlashR object, and \code{min} and \code{max} return an R scalar. 114 | } 115 | \description{ 116 | Returns the (parallel) maxima and minima of the input values. 117 | } 118 | \details{ 119 | pmax2 returns the maximum of two objects. 120 | pmin2 returns the minimum of two objects. 121 | 122 | If one of the arguments is a matrix and the other is a vector, \code{pmax2} 123 | or \code{pmin2} return a matrix, each of whose column is parallel maxima 124 | and minima of the column of the input matrix and the input vector. 125 | } 126 | \examples{ 127 | mat1 <- fm.runif.matrix(100, 10) 128 | mat2 <- fm.runif.matrix(100, 10) 129 | res <- pmax2(mat1, mat2) 130 | res <- pmin2(mat1, mat2) 131 | res <- pmax(mat1, mat2) 132 | res <- pmin(mat1, mat2) 133 | res <- max(mat1, mat2) 134 | res <- min(mat1, mat2) 135 | } 136 | 137 | -------------------------------------------------------------------------------- /man/Logic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{Logic} 5 | \alias{!.fm} 6 | \alias{!.fmV} 7 | \alias{&,ANY,fm-method} 8 | \alias{&,ANY,fmV-method} 9 | \alias{&,fm,ANY-method} 10 | \alias{&,fm,fm-method} 11 | \alias{&,fm,fmV-method} 12 | \alias{&,fm,matrix-method} 13 | \alias{&,fmV,ANY-method} 14 | \alias{&,fmV,fm-method} 15 | \alias{&,fmV,fmV-method} 16 | \alias{&,matrix,fm-method} 17 | \alias{Logic} 18 | \alias{|,ANY,fm-method} 19 | \alias{|,ANY,fmV-method} 20 | \alias{|,fm,ANY-method} 21 | \alias{|,fm,fm-method} 22 | \alias{|,fm,fmV-method} 23 | \alias{|,fm,matrix-method} 24 | \alias{|,fmV,ANY-method} 25 | \alias{|,fmV,fm-method} 26 | \alias{|,fmV,fmV-method} 27 | \alias{|,matrix,fm-method} 28 | \title{Logical Operators} 29 | \usage{ 30 | \S4method{|}{fm,fm}(e1, e2) 31 | 32 | \S4method{|}{fmV,fmV}(e1, e2) 33 | 34 | \S4method{|}{fm,fmV}(e1, e2) 35 | 36 | \S4method{|}{fmV,fm}(e1, e2) 37 | 38 | \S4method{|}{fm,matrix}(e1, e2) 39 | 40 | \S4method{|}{matrix,fm}(e1, e2) 41 | 42 | \S4method{|}{fm,ANY}(e1, e2) 43 | 44 | \S4method{|}{ANY,fm}(e1, e2) 45 | 46 | \S4method{|}{fmV,ANY}(e1, e2) 47 | 48 | \S4method{|}{ANY,fmV}(e1, e2) 49 | 50 | \S4method{&}{fm,fm}(e1, e2) 51 | 52 | \S4method{&}{fmV,fmV}(e1, e2) 53 | 54 | \S4method{&}{fm,fmV}(e1, e2) 55 | 56 | \S4method{&}{fmV,fm}(e1, e2) 57 | 58 | \S4method{&}{fm,matrix}(e1, e2) 59 | 60 | \S4method{&}{matrix,fm}(e1, e2) 61 | 62 | \S4method{&}{fm,ANY}(e1, e2) 63 | 64 | \S4method{&}{ANY,fm}(e1, e2) 65 | 66 | \S4method{&}{fmV,ANY}(e1, e2) 67 | 68 | \S4method{&}{ANY,fmV}(e1, e2) 69 | 70 | \method{!}{fm}(e1) 71 | 72 | \method{!}{fmV}(e1) 73 | } 74 | \arguments{ 75 | \item{e1, e2}{One of the operands need to be a FlashR object. If one operand 76 | is a matrix and the other is a vector, we perform the arithmetic operation 77 | on the vector and every column of the matrix. If one operand is a scalar, 78 | we perform the operation on the scalar with every element in the matrix or 79 | the vector.} 80 | } 81 | \description{ 82 | These operators act on logical and number-like vectors. 83 | } 84 | \details{ 85 | \code{!} indicates logical negation (NOT). 86 | \code{&} indicates logical AND and \code{|} indicates logical OR. 87 | } 88 | \examples{ 89 | tmp1 <- fm.runif.matrix(100, 10) 90 | tmp2 <- fm.runif.matrix(100, 10) 91 | mat1 <- tmp1 > tmp2 92 | mat2 <- tmp1 < tmp2 93 | mat1 | mat2 94 | mat1 & mat2 95 | !mat1 96 | } 97 | 98 | -------------------------------------------------------------------------------- /man/MathFun.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{MathFun} 5 | \alias{MathFun} 6 | \alias{abs,fm-method} 7 | \alias{abs,fmV-method} 8 | \alias{sqrt,fm-method} 9 | \alias{sqrt,fmV-method} 10 | \title{Miscellaneous Mathematical Functions} 11 | \usage{ 12 | \S4method{abs}{fm}(x) 13 | 14 | \S4method{abs}{fmV}(x) 15 | 16 | \S4method{sqrt}{fm}(x) 17 | 18 | \S4method{sqrt}{fmV}(x) 19 | } 20 | \arguments{ 21 | \item{x}{a numeric vector or array.} 22 | } 23 | \description{ 24 | \code{abs(x)} computes the absolute value of x, \code{sqrt(x)} computes the square 25 | root of x. 26 | } 27 | \examples{ 28 | mat <- abs(fm.runif.matrix(100, 10)) 29 | mat <- sqrt(fm.runif.matrix(100, 10)) 30 | } 31 | 32 | -------------------------------------------------------------------------------- /man/NA.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{methods} 4 | \name{NA} 5 | \alias{NA} 6 | \alias{is.na,fm-method} 7 | \alias{is.na,fmV-method} 8 | \title{'Not Available' / Missing Values} 9 | \usage{ 10 | \S4method{is.na}{fm}(x) 11 | 12 | \S4method{is.na}{fmV}(x) 13 | } 14 | \arguments{ 15 | \item{x}{an FlashR vector or matrix.} 16 | } 17 | \value{ 18 | a logical FlashR vector or matrix. 19 | } 20 | \description{ 21 | This function indicates which elements are missing. 22 | } 23 | \examples{ 24 | mat <- fm.runif.matrix(100, 10) 25 | is.na(mat) 26 | } 27 | 28 | -------------------------------------------------------------------------------- /man/all.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{all} 5 | \alias{all} 6 | \alias{all,fm-method} 7 | \alias{all,fmV-method} 8 | \alias{fm.all} 9 | \title{Are All Values True?} 10 | \usage{ 11 | fm.all(x, lazy = FALSE) 12 | 13 | \S4method{all}{fm}(x, ..., na.rm = FALSE) 14 | 15 | \S4method{all}{fmV}(x, ..., na.rm = FALSE) 16 | } 17 | \arguments{ 18 | \item{x}{a logical FlashR vector.} 19 | 20 | \item{lazy}{indicates whether or not to evaluate it lazily.} 21 | 22 | \item{...}{zero or more logical vectors.} 23 | 24 | \item{na.rm}{a logical indicating whether missing values should be removed.} 25 | } 26 | \value{ 27 | The value is a logical vector of length one. 28 | } 29 | \description{ 30 | \code{all} tests whether all of the values in a set of logical vectors are 31 | true? \code{fm.all} tests whether all values in a single vector are true. 32 | \code{fm.all} can evaluate it lazily. 33 | } 34 | \examples{ 35 | mat <- fm.runif.matrix(100, 10) > 0.5 36 | all(mat) 37 | fm.all(mat) 38 | } 39 | 40 | -------------------------------------------------------------------------------- /man/any.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{any} 5 | \alias{any} 6 | \alias{any,fm-method} 7 | \alias{any,fmV-method} 8 | \alias{fm.any} 9 | \title{Are some Values True?} 10 | \usage{ 11 | fm.any(x, lazy = FALSE) 12 | 13 | \S4method{any}{fm}(x, ..., na.rm = FALSE) 14 | 15 | \S4method{any}{fmV}(x, ..., na.rm = FALSE) 16 | } 17 | \arguments{ 18 | \item{x}{a logical FlashR vector.} 19 | 20 | \item{lazy}{indicates whether or not to evaluate it lazily.} 21 | 22 | \item{...}{zero or more logical vectors.} 23 | 24 | \item{na.rm}{a logical indicating whether missing values should be removed.} 25 | } 26 | \value{ 27 | The value is a logical vector of length one. 28 | } 29 | \description{ 30 | \code{any} tests whether some of the values in a set of logical vectors are 31 | true? \code{fm.any} tests whether some of the values in a single vector are 32 | true. \code{fm.any} can evaluate it lazily. 33 | } 34 | \examples{ 35 | mat <- fm.runif.matrix(100, 10) > 0.5 36 | any(mat) 37 | fm.any(mat) 38 | } 39 | 40 | -------------------------------------------------------------------------------- /man/colSums.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{colSums} 5 | \alias{colMeans,fm-method} 6 | \alias{colSums} 7 | \alias{colSums,fm-method} 8 | \alias{fm.colSums} 9 | \alias{fm.rowSums} 10 | \alias{rowMeans,fm-method} 11 | \alias{rowSums,fm-method} 12 | \title{Form Row and Column Sums and Means} 13 | \usage{ 14 | fm.rowSums(x, lazy = FALSE) 15 | 16 | fm.colSums(x, lazy = FALSE) 17 | 18 | \S4method{rowSums}{fm}(x, na.rm) 19 | 20 | \S4method{colSums}{fm}(x, na.rm) 21 | 22 | \S4method{rowMeans}{fm}(x, na.rm) 23 | 24 | \S4method{colMeans}{fm}(x, na.rm) 25 | } 26 | \arguments{ 27 | \item{x}{a FlashR matrix.} 28 | 29 | \item{lazy}{logical. indicates whether to evaluate the expression lazily.} 30 | 31 | \item{na.rm}{logical. Should missing values (including NaN) be omitted 32 | from the calculations?} 33 | } 34 | \value{ 35 | a FlashR vector. 36 | } 37 | \description{ 38 | Form row and column sums and means for numeric arrays. 39 | } 40 | \examples{ 41 | mat <- fm.runif.matrix(100, 10) 42 | mat <- fm.rowSums(mat) 43 | mat <- fm.colSums(mat) 44 | mat <- rowSums(mat) 45 | mat <- colSums(mat) 46 | mat <- rowMeans(mat) 47 | mat <- colMeans(mat) 48 | } 49 | 50 | -------------------------------------------------------------------------------- /man/cor.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_stats.R 3 | \docType{methods} 4 | \name{cor} 5 | \alias{cor} 6 | \alias{cor,fm-method} 7 | \alias{cov,fm-method} 8 | \alias{var,fm-method} 9 | \title{Correlation, Variance and Covariance (Matrices)} 10 | \usage{ 11 | \S4method{var}{fm}(x, y = NULL, na.rm = FALSE, use) 12 | 13 | \S4method{cor}{fm}(x, y = NULL, use = "everything", method = c("pearson", 14 | "kendall", "spearman")) 15 | 16 | \S4method{cov}{fm}(x, y = NULL, use = "everything", method = c("pearson", 17 | "kendall", "spearman")) 18 | } 19 | \arguments{ 20 | \item{x}{a numeric vector or matrix} 21 | 22 | \item{y}{\code{NULL} (default) or a vector or matrix with compatible 23 | dimensions to \code{x}. The default is equivalent to \code{y=x}.} 24 | 25 | \item{use}{an optional character string giving a method for computing 26 | covariances in the presence of missing values. This must be 27 | (an abbreviation of) one of the strings \code{"everything"}, 28 | \code{"all.obs"}, \code{"complete.obs"}, \code{"na.or.complete"}, or 29 | \code{"pairwise.complete.obs"}.} 30 | 31 | \item{method}{a character string indicating which correlation coefficient 32 | (or covariance) is to be computed. One of \code{"pearson"} 33 | (default), \code{"kendall"}, or \code{"spearman"}: can be abbreviated. 34 | Right now this argument isn't used.} 35 | } 36 | \description{ 37 | \code{cov} and \code{cor} compute the covariance or correlation of \code{x} 38 | and \code{y} if these are vectors. If \code{x} 39 | and \code{y} are matrices then the covariances (or correlations) between 40 | the columns of \code{x} and the columns of \code{y} are computed. 41 | } 42 | \examples{ 43 | mat <- fm.runif.matrix(100, 10) 44 | var(mat) 45 | cor(mat) 46 | cov(mat) 47 | } 48 | 49 | -------------------------------------------------------------------------------- /man/cov.wt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_stats.R 3 | \docType{methods} 4 | \name{cov.wt} 5 | \alias{cov.wt} 6 | \title{Weighted Covariance Matrices} 7 | \usage{ 8 | \S4method{cov.wt}{fm}(x, wt = rep(1/nrow(x), nrow(x)), cor = FALSE, 9 | center = TRUE, method = c("unbiased", "ML")) 10 | } 11 | \arguments{ 12 | \item{x}{a matrix. As usual, rows are observations and columns are variables.} 13 | 14 | \item{wt}{a non-negative and non-zero vector of weights for each 15 | observation. Its length must equal the number of rows of 16 | \code{x}.} 17 | 18 | \item{cor}{a logical indicating whether the estimated correlation 19 | weighted matrix will be returned as well.} 20 | 21 | \item{center}{either a logical or a numeric vector specifying the centers 22 | to be used when computing covariances. If \code{TRUE}, the 23 | (weighted) mean of each variable is used, if \code{FALSE}, zero is 24 | used. If \code{center} is numeric, its length must equal the 25 | number of columns of \code{x}.} 26 | 27 | \item{method}{string specifying how the result is scaled, see \code{Details} 28 | below. Can be abbreviated.} 29 | } 30 | \value{ 31 | A list containing the following named components: 32 | \itemize{ 33 | \item{cov}{the estimated (weighted) covariance matrix.} 34 | \item{center}{an estimate for the center (mean) of the data.} 35 | \item{n.obs}{the number of observations (rows) in \code{x}.} 36 | \item{wt}{the weights used in the estimation. Only returned if given 37 | as an argument.} 38 | \item{cor}{the estimated correlation matrix. Only returned if \code{cor} is 39 | \code{TRUE}} 40 | } 41 | } 42 | \description{ 43 | Returns a list containing estimates of the weighted covariance 44 | matrix and the mean of the data, and optionally of the (weighted) 45 | correlation matrix. 46 | } 47 | \details{ 48 | By default, \code{method = "unbiased"}, The covariance matrix is 49 | divided by one minus the sum of squares of the weights, so if the 50 | weights are the default (1/n) the conventional unbiased estimate 51 | of the covariance matrix with divisor (n - 1) is obtained. This 52 | differs from the behaviour in S-PLUS which corresponds to \code{method 53 | = "ML"} and does not divide. 54 | } 55 | \examples{ 56 | mat <- fm.runif.matrix(100, 10) 57 | cov.wt(mat, fm.runif(nrow(mat))) 58 | } 59 | 60 | -------------------------------------------------------------------------------- /man/crossprod.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{crossprod} 5 | \alias{crossprod} 6 | \alias{crossprod,fm,ANY-method} 7 | \alias{tcrossprod,fm,ANY-method} 8 | \title{Matrix Crossproduct} 9 | \usage{ 10 | \S4method{crossprod}{fm,ANY}(x, y = NULL) 11 | 12 | \S4method{tcrossprod}{fm,ANY}(x, y = NULL) 13 | } 14 | \arguments{ 15 | \item{x, y}{numeric matrices (or vectors): \code{y = NULL} is taken 16 | to be the same matrix as \code{x}. Vectors are promoted to single-column 17 | or single-row matrices, depending on the context.} 18 | 19 | \item{lazy}{a logical value, indicating to perform the computation lazily.} 20 | } 21 | \value{ 22 | a double matrix 23 | } 24 | \description{ 25 | Given matrices \code{x} and \code{y} as arguments, return a matrix 26 | cross-product. This is formally equivalent to (but usually slightly 27 | faster than) the call \code{t(x) \%*\% y} (\code{crossprod}) or 28 | \code{x \%*\% t(y)} (\code{tcrossprod}). 29 | } 30 | \examples{ 31 | mat <- fm.runif.matrix(100, 10) 32 | crossprod(mat) 33 | tcrossprod(mat) 34 | } 35 | 36 | -------------------------------------------------------------------------------- /man/dim.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{dim} 5 | \alias{dim} 6 | \alias{dim,fm-method} 7 | \title{Dimensions of an FlashR Object} 8 | \usage{ 9 | \S4method{dim}{fm}(x) 10 | } 11 | \arguments{ 12 | \item{x}{A FlashR matrix.} 13 | } 14 | \description{ 15 | Retrieve the dimension of an FlashR object. 16 | } 17 | \examples{ 18 | mat <- fm.runif.matrix(100, 10) 19 | dim(mat) 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/dimnames.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{dimnames} 5 | \alias{dimnames} 6 | \alias{dimnames,fm-method} 7 | \alias{dimnames,fmV-method} 8 | \alias{dimnames<-,fm,list-method} 9 | \alias{dimnames<-,fmV,list-method} 10 | \title{Dimnames of an Object} 11 | \usage{ 12 | \S4method{dimnames}{fm}(x) 13 | 14 | \S4method{dimnames}{fmV}(x) 15 | 16 | \S4method{dimnames}{fm,list}(x) <- value 17 | 18 | \S4method{dimnames}{fmV,list}(x) <- value 19 | } 20 | \arguments{ 21 | \item{x}{a FlashR matrix.} 22 | 23 | \item{value}{a list that provides values for dimension names.} 24 | } 25 | \value{ 26 | \code{dimnames} return NULL if there aren't dimension names. 27 | Otherwise, return the dimension names. 28 | } 29 | \description{ 30 | Retrieve or set the dimnames of a matrix. 31 | } 32 | \examples{ 33 | mat <- fm.runif.matrix(100, 10) 34 | dimnames(mat) 35 | dimnames(mat) <- list("dim1", "dim2") 36 | } 37 | 38 | -------------------------------------------------------------------------------- /man/drop.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{drop} 5 | \alias{drop} 6 | \title{Drop Redundant Extent Information} 7 | \usage{ 8 | \S4method{drop}{fm}(x) 9 | } 10 | \arguments{ 11 | \item{x}{a FlashR matrix.} 12 | } 13 | \value{ 14 | a FlashR matrix or vector. 15 | } 16 | \description{ 17 | Delete the dimensions of a FlashR matrix which have only one level. 18 | } 19 | \details{ 20 | If the input matrix has only one row or one column, it works the same as 21 | fm.as.vector. Otherwise, it returns the original matrix. 22 | } 23 | \examples{ 24 | mat <- fm.runif.matrix(100, 1) 25 | vec <- drop(mat) 26 | } 27 | 28 | -------------------------------------------------------------------------------- /man/fm-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{class} 4 | \name{fm-class} 5 | \alias{fm-class} 6 | \title{An S4 class to represent a FlashR matrix.} 7 | \description{ 8 | An S4 class to represent a FlashR matrix. 9 | } 10 | \section{Slots}{ 11 | 12 | \describe{ 13 | \item{\code{pointer}}{points a matrix object in C.} 14 | 15 | \item{\code{name}}{a string indicating the name of the matrix.} 16 | 17 | \item{\code{nrow}}{a numeric value indicating the number of rows.} 18 | 19 | \item{\code{ncol}}{a numeric value indicating the number of columns.} 20 | 21 | \item{\code{type}}{a string indicating the type of the matrix. e.g., sparse or dense.} 22 | 23 | \item{\code{ele_type}}{a string indicating the element type in the matrix.} 24 | 25 | \item{\code{attrs}}{a list that stores the attributes of the matrix.} 26 | }} 27 | 28 | -------------------------------------------------------------------------------- /man/fm.agg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.agg} 4 | \alias{fm.agg} 5 | \alias{fm.agg.lazy} 6 | \alias{fm.agg.mat} 7 | \alias{fm.agg.mat.lazy} 8 | \title{Aggregation on a FlashR object.} 9 | \usage{ 10 | fm.agg(fm, op) 11 | 12 | fm.agg.lazy(fm, op) 13 | 14 | fm.agg.mat(fm, margin, op) 15 | 16 | fm.agg.mat.lazy(fm, margin, op) 17 | } 18 | \arguments{ 19 | \item{fm}{a FlashR object} 20 | 21 | \item{op}{the reference or the name of a predefined basic operator or 22 | the reference to an aggregation operator returned by 23 | \code{fm.create.agg.op}.} 24 | 25 | \item{margin}{the subscript which the function will be applied over.} 26 | } 27 | \value{ 28 | \code{fm.agg} returns a scalar, \code{fm.agg.mat} returns 29 | a FlashR vector, \code{fm.agg.lazy} and \code{fm.agg.mat.lazy} 30 | return a FlashR sink matrix. 31 | } 32 | \description{ 33 | This function accepts a basic operator and perform aggregation on 34 | the FlashR object with the basic operator. 35 | } 36 | \details{ 37 | \code{fm.agg} aggregates over the entire object. 38 | 39 | \code{fm.agg.lazy} aggregates over the entire object, but it performs 40 | aggregation lazily. 41 | 42 | \code{fm.agg.mat} aggregates on the rows or columns of a matrix. It performs 43 | aggregation on the shorter dimension lazily, but on the longer dimension 44 | immediately. 45 | 46 | \code{fm.agg.mat.lazy} aggregates on the rows or columns of a matrix and 47 | performs aggregation lazily regardless the dimension. 48 | } 49 | \examples{ 50 | mat <- fm.runif.matrix(100, 2) 51 | res <- fm.agg(mat, "+") 52 | res <- fm.agg(mat, fm.bo.add) 53 | sum <- fm.create.agg.op(fm.bo.add, fm.bo.add, "sum") 54 | res <- fm.agg(mat, sum) 55 | res <- fm.agg.mat(mat, 1, sum) 56 | } 57 | 58 | -------------------------------------------------------------------------------- /man/fm.agg.op-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{class} 4 | \name{fm.agg.op-class} 5 | \alias{fm.agg.op-class} 6 | \title{An S4 class to represent an aggregation operator used in aggregation 7 | operations in FlashR.} 8 | \description{ 9 | An S4 class to represent an aggregation operator used in aggregation 10 | operations in FlashR. 11 | } 12 | \section{Slots}{ 13 | 14 | \describe{ 15 | \item{\code{agg}}{an integer indicating the operator for computing partial 16 | aggregation results.} 17 | 18 | \item{\code{combine}}{an integer indicating the operator for combining partial 19 | aggregation results and computing the final result.} 20 | 21 | \item{\code{name}}{a string indicating the name of the aggregation operation.} 22 | }} 23 | 24 | -------------------------------------------------------------------------------- /man/fm.apply.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.apply} 4 | \alias{fm.apply} 5 | \title{Apply Functions Over Array Margins} 6 | \usage{ 7 | fm.apply(x, margin, FUN) 8 | } 9 | \arguments{ 10 | \item{x}{a FlashR matrix.} 11 | 12 | \item{margin}{an integer. \code{1} indicates rows and \code{2} indicates columns.} 13 | 14 | \item{FUN}{a string that indicates the name of the predefined function.} 15 | } 16 | \value{ 17 | a FlashR matrix. 18 | } 19 | \description{ 20 | Apply a predefined function on rows/columns of a FlashR matrix. 21 | The predefined function always output a vector of the same length. Thus, 22 | the output of \code{fm.apply} is a matrix. 23 | } 24 | \details{ 25 | Currently, the predefined functions include \code{"rank"} and 26 | } 27 | \examples{ 28 | mat <- fm.runif.matrix(100, 10) 29 | res <- fm.apply(mat, 1, "rank") 30 | } 31 | 32 | -------------------------------------------------------------------------------- /man/fm.apply.op-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{class} 4 | \name{fm.apply.op-class} 5 | \alias{fm.apply.op-class} 6 | \title{An S4 class to represent an apply operator on rows/columns in a matrix. 7 | This operator is used in \code{fm.apply}.} 8 | \description{ 9 | An S4 class to represent an apply operator on rows/columns in a matrix. 10 | This operator is used in \code{fm.apply}. 11 | } 12 | \section{Slots}{ 13 | 14 | \describe{ 15 | \item{\code{info}}{an integer indicating the apply operator registered in the system.} 16 | 17 | \item{\code{name}}{a string indicating the name of the operator.} 18 | }} 19 | 20 | -------------------------------------------------------------------------------- /man/fm.as.factor.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.as.factor} 4 | \alias{fm.as.factor} 5 | \title{FlashR factor vector.} 6 | \usage{ 7 | fm.as.factor(fm, num.levels = -1) 8 | } 9 | \arguments{ 10 | \item{fm}{a FlashR vector.} 11 | 12 | \item{num.levels}{The number of levels in the factor vector.} 13 | } 14 | \value{ 15 | a FlashR factor vector. 16 | } 17 | \description{ 18 | \code{fm.as.factor} converts a FlashR vector to a FlashR factor vector. 19 | } 20 | \details{ 21 | Currently, this function only works for integer input vectors. If 22 | the input vector isn't integers, it converts the vector to an integer 23 | vector. By default, it uses the maximal value as the number of levels 24 | for the factor. 25 | } 26 | \examples{ 27 | vec <- fm.as.factor(as.integer(fm.runif(100, min=0, max=100))) 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/fm.basic.op.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{data} 4 | \name{fm.basic.op} 5 | \alias{fm.basic.op} 6 | \alias{fm.bo.add} 7 | \alias{fm.bo.and} 8 | \alias{fm.bo.count} 9 | \alias{fm.bo.div} 10 | \alias{fm.bo.eq} 11 | \alias{fm.bo.euclidean} 12 | \alias{fm.bo.ge} 13 | \alias{fm.bo.gt} 14 | \alias{fm.bo.le} 15 | \alias{fm.bo.lt} 16 | \alias{fm.bo.max} 17 | \alias{fm.bo.min} 18 | \alias{fm.bo.mul} 19 | \alias{fm.bo.neq} 20 | \alias{fm.bo.or} 21 | \alias{fm.bo.pow} 22 | \alias{fm.bo.sub} 23 | \alias{fm.bo.which.max} 24 | \alias{fm.bo.which.min} 25 | \alias{fm.buo.abs} 26 | \alias{fm.buo.as.int} 27 | \alias{fm.buo.as.numeric} 28 | \alias{fm.buo.ceil} 29 | \alias{fm.buo.floor} 30 | \alias{fm.buo.log} 31 | \alias{fm.buo.log10} 32 | \alias{fm.buo.log2} 33 | \alias{fm.buo.neg} 34 | \alias{fm.buo.not} 35 | \alias{fm.buo.round} 36 | \alias{fm.buo.sqrt} 37 | \alias{fm.get.basic.op} 38 | \alias{fm.get.basic.uop} 39 | \alias{fm.init.basic.op} 40 | \title{The basic operators supported by FlashR.} 41 | \format{An object of class \code{NULL} of length 0.} 42 | \usage{ 43 | fm.get.basic.op(name) 44 | 45 | fm.get.basic.uop(name) 46 | 47 | fm.bo.add 48 | 49 | fm.bo.sub 50 | 51 | fm.bo.mul 52 | 53 | fm.bo.div 54 | 55 | fm.bo.min 56 | 57 | fm.bo.max 58 | 59 | fm.bo.pow 60 | 61 | fm.bo.eq 62 | 63 | fm.bo.neq 64 | 65 | fm.bo.gt 66 | 67 | fm.bo.ge 68 | 69 | fm.bo.lt 70 | 71 | fm.bo.le 72 | 73 | fm.bo.or 74 | 75 | fm.bo.and 76 | 77 | fm.bo.count 78 | 79 | fm.bo.which.max 80 | 81 | fm.bo.which.min 82 | 83 | fm.bo.euclidean 84 | 85 | fm.buo.neg 86 | 87 | fm.buo.sqrt 88 | 89 | fm.buo.abs 90 | 91 | fm.buo.not 92 | 93 | fm.buo.ceil 94 | 95 | fm.buo.floor 96 | 97 | fm.buo.log 98 | 99 | fm.buo.log2 100 | 101 | fm.buo.log10 102 | 103 | fm.buo.round 104 | 105 | fm.buo.as.int 106 | 107 | fm.buo.as.numeric 108 | 109 | fm.init.basic.op() 110 | } 111 | \arguments{ 112 | \item{name}{the name of the basic operator.} 113 | } 114 | \value{ 115 | a reference to the specified basic operator. 116 | } 117 | \description{ 118 | The basic operators are mainly used by the FlashR functions that 119 | accept operators as arguments. Such a function includes \code{fm.mapply}, 120 | \code{fm.inner.prod}, etc. 121 | } 122 | \details{ 123 | \code{fm.get.basic.op} gets the predefined basic binary operator specified by a user. 124 | The supported basic binary operators are: 125 | \itemize{ 126 | \item{"add" or "+"}{compute addition.} 127 | \item{"sub" or "-"}{compute subtraction;} 128 | \item{"mul" or "*"}{compute multiplication;} 129 | \item{"div" or "/"}{compute division;} 130 | \item{"min" and "max"}{compute minimum and maximum, respectively;} 131 | \item{"pow"}{compute exponential;} 132 | \item{"eq" or "=="}{compute equality;} 133 | \item{"gt" or ">"}{compute greater than;} 134 | \item{"ge" or ">="}{compute greater than or equal to;} 135 | \item{"lt" or "<"}{compute less than;} 136 | \item{"le" or "<="}{compute less than or equal to;} 137 | } 138 | 139 | \code{fm.get.basic.uop} gets the predefined basic unary operator specified by a user. 140 | The supported basic unary operators are: 141 | \itemize{ 142 | \item{"neg"}{compute negate;} 143 | \item{"sqrt"}{compute square root;} 144 | \item{"abs"}{compute absolute value;} 145 | \item{"not"}{compute logical NOT;} 146 | \item{"ceil" and "floor"}{compute a ceiling and a floor, respectively;} 147 | \item{"log", "log2" and "log10"}{compute log with different bases;} 148 | \item{"round"}{round a number;} 149 | \item{"as.int" and "as.numeric"}{cast a number to an integer and a numeric 150 | value, respectively.} 151 | } 152 | 153 | \code{fm.init.basic.op} initializes the following basic operators. 154 | \itemize{ 155 | \item{\code{fm.bo.add}}{the predifined basic binary operator for addition.} 156 | \item{\code{fm.bo.sub}}{the predifined basic binary operator for subtraction.} 157 | \item{\code{fm.bo.mul}}{the predifined basic binary operator for multiplication.} 158 | \item{\code{fm.bo.div}}{the predifined basic binary operator for division.} 159 | \item{\code{fm.bo.min}}{the predifined basic binary operator for computing minimum.} 160 | \item{\code{fm.bo.max}}{the predifined basic binary operator for computing maximum.} 161 | \item{\code{fm.bo.pow}}{the predifined basic binary operator for computing exponential.} 162 | \item{\code{fm.bo.eq}, \code{fm.bo.neq}, \code{fm.bo.gt}, \code{fm.bo.ge}, 163 | \code{fm.bo.lt} and \code{fm.bo.le}} 164 | {the predefined basic logical operators to compare two elements: ==, >, >=, <, <=.} 165 | \item{\code{fm.buo.neg}}{the predefined basic unary operator for negate.} 166 | \item{\code{fm.buo.sqrt}}{the predefined basic unary operator for square root.} 167 | \item{\code{fm.buo.abs}}{the predefined basic unary operator for absolute value.} 168 | \item{\code{fm.buo.not}}{the predefined logical NOT operator.} 169 | \item{\code{fm.buo.ceil}}{the predefined basic unary operator of computing 170 | a ceiling of a number.} 171 | \item{\code{fm.buo.floor}}{the predefined basic unary operator of computing 172 | a floor of a number.} 173 | \item{\code{fm.buo.log}, \code{fm.buo.log2} and \code{fm.buo.log10}}{ 174 | the predefined basic unary operators of computing log with different 175 | bases.} 176 | \item{\code{fm.buo.round}}{the predefined basic unary operator of rounding 177 | a value.} 178 | \item{\code{fm.buo.as.int}}{the predefined basic unary operator of casting 179 | a numeric value to an integer.} 180 | \item{\code{fm.buo.as.numeric}}{the predefined basic unary operator of 181 | casting an integer to a numeric value.} 182 | } 183 | } 184 | \author{ 185 | Da Zheng 186 | } 187 | \keyword{datasets} 188 | 189 | -------------------------------------------------------------------------------- /man/fm.bind.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{methods} 4 | \name{fm.bind} 5 | \alias{fm.bind} 6 | \alias{fm.cbind.list} 7 | \alias{fm.rbind.list} 8 | \title{Combine FlashR Vectors/Matrices by Rows or Columns} 9 | \usage{ 10 | fm.rbind.list(objs) 11 | 12 | fm.cbind.list(objs) 13 | 14 | \S4method{rbind}{fm}(..., deparse.level = 1) 15 | 16 | \S4method{rbind}{fmV}(..., deparse.level = 1) 17 | 18 | \S4method{cbind}{fm}(..., deparse.level = 1) 19 | 20 | \S4method{cbind}{fmV}(..., deparse.level = 1) 21 | } 22 | \arguments{ 23 | \item{objs}{A list of FlashR matrices. 24 | 25 | All arguments for \code{rbind} and \code{cbind} have to be either all 26 | vectors or all matrices.} 27 | 28 | \item{...}{A list of FlashR matrices.} 29 | } 30 | \value{ 31 | A FlashR matrix. 32 | } 33 | \description{ 34 | Take a list of FlashR vectors/matrices and combine them by Columns or rows 35 | respectively. 36 | } 37 | \examples{ 38 | mat1 <- fm.runif.matrix(100, 10) 39 | mat2 <- fm.runif.matrix(100, 10) 40 | mat <- rbind(mat1, mat2) 41 | mat <- cbind(mat1, mat2) 42 | mat.list <- list(mat1, mat2) 43 | mat <- fm.rbind.list(mat.list) 44 | mat <- fm.cbind.list(mat.list) 45 | } 46 | \author{ 47 | Da Zheng 48 | } 49 | 50 | -------------------------------------------------------------------------------- /man/fm.bo-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{class} 4 | \name{fm.bo-class} 5 | \alias{fm.bo-class} 6 | \title{An S4 class to represent a binary operator used in generalized matrix 7 | operations.} 8 | \description{ 9 | An S4 class to represent a binary operator used in generalized matrix 10 | operations. 11 | } 12 | \section{Slots}{ 13 | 14 | \describe{ 15 | \item{\code{info}}{an integer indicating the binary operator registered 16 | in the system.} 17 | 18 | \item{\code{name}}{a string indicating the name of the operator.} 19 | }} 20 | 21 | -------------------------------------------------------------------------------- /man/fm.conv.FM2R.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.conv.FM2R} 4 | \alias{fm.conv.FM2R} 5 | \title{Convert a FlashR object to a regular R object} 6 | \usage{ 7 | fm.conv.FM2R(obj) 8 | } 9 | \arguments{ 10 | \item{obj}{a FlashR object} 11 | } 12 | \value{ 13 | a regular R object. 14 | } 15 | \description{ 16 | Convert a FlashR object to a regular R object 17 | } 18 | \examples{ 19 | vec <- fm.conv.FM2R(fm.runif(100)) 20 | mat <- fm.conv.FM2R(fm.runif.matrix(100, 2)) 21 | } 22 | \author{ 23 | Da Zheng 24 | } 25 | 26 | -------------------------------------------------------------------------------- /man/fm.conv.R2FM.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.conv.R2FM} 4 | \alias{fm.conv.R2FM} 5 | \title{Convert a regular R object to a FlashR object.} 6 | \usage{ 7 | fm.conv.R2FM(obj, byrow = FALSE) 8 | } 9 | \arguments{ 10 | \item{obj}{a regular R object} 11 | 12 | \item{byrow}{a logical value to determine the data layout of a FlashR matrix.} 13 | } 14 | \value{ 15 | a FlashR object. If the input R object has 0 element, 16 | \code{fm.conv.R2FM} returns \code{NULL}. 17 | } 18 | \description{ 19 | If the R object is a matrix, \code{byrow} determines how data in the generated 20 | FlashR object is organized in memory. 21 | } 22 | \examples{ 23 | vec <- fm.conv.R2FM(runif(100)) 24 | mat <- fm.conv.R2FM(matrix(runif(100), 100, 2)) 25 | } 26 | \author{ 27 | Da Zheng 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/fm.conv.layout.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.conv.layout} 4 | \alias{fm.conv.layout} 5 | \title{Convert the data layout of a FlashR matrix.} 6 | \usage{ 7 | fm.conv.layout(fm, byrow = FALSE) 8 | } 9 | \arguments{ 10 | \item{fm}{a FlashR matrix} 11 | 12 | \item{byrow}{a logical value to determine the data layout of a FlashR matrix.} 13 | } 14 | \value{ 15 | a FlashR matrix 16 | } 17 | \description{ 18 | A FMR matrix can store elements in a row-major or column-major order. 19 | By changing the data layout, we can improve efficiency of some matrix 20 | operations. 21 | } 22 | \examples{ 23 | mat <- fm.conv.layout(fm.runif.matrix(100, 2), byrow=TRUE) 24 | } 25 | \author{ 26 | Da Zheng 27 | } 28 | 29 | -------------------------------------------------------------------------------- /man/fm.conv.store.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.conv.store} 4 | \alias{fm.conv.store} 5 | \title{Convert the Storage of an Object.} 6 | \usage{ 7 | fm.conv.store(fm, in.mem, name = "") 8 | } 9 | \arguments{ 10 | \item{fm}{a FlashR object.} 11 | 12 | \item{in.mem}{a logical value indicating whether to store the FlashR 13 | object in memory.} 14 | 15 | \item{name}{a string to indicate the name of the new FlashR object.} 16 | } 17 | \value{ 18 | a new FlashR object with data stored in specified storage. 19 | } 20 | \description{ 21 | This function converts the storage of a FlashR vector/matrix. 22 | The storage can be memory or disks. 23 | } 24 | \details{ 25 | If a user provides \code{name} and \code{in.mem} is \code{TRUE}, 26 | the vector/matrix will be kept on disks persistently. That is, even if a user 27 | exits from R, the vector/matrix will still be kept on disks. 28 | } 29 | \examples{ 30 | mat <- fm.runif.matrix(100, 10, in.mem=TRUE) 31 | mat <- fm.conv.store(mat, FALSE) 32 | } 33 | 34 | -------------------------------------------------------------------------------- /man/fm.create.agg.op.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.create.agg.op} 4 | \alias{fm.create.agg.op} 5 | \title{Create an aggregate operator} 6 | \usage{ 7 | fm.create.agg.op(agg, combine, name) 8 | } 9 | \arguments{ 10 | \item{agg}{a \code{fm.basic.op} operator that computes partial aggregation 11 | results.} 12 | 13 | \item{combine}{a \code{fm.basic.op} operator that computes the final result.} 14 | 15 | \item{name}{a string indicating the name of the aggregation operator.} 16 | } 17 | \value{ 18 | a \code{fm.agg.op} operator. 19 | } 20 | \description{ 21 | This function creates an aggregate operator for aggregation operations 22 | on a FlashR object. 23 | } 24 | \details{ 25 | An Aggregate operator has two parts. \code{agg} computes partial 26 | aggregation results and \code{combine} combines the partial aggregation 27 | results to compute the final result. Both \code{agg} and \code{combine} 28 | are the type of \code{fm.basic.op}. 29 | 30 | The main reason of using two operators is for parallelization. Each thread 31 | computes aggregation on part of the object. Eventually, we need an operator 32 | to combine all partial aggregation results. 33 | 34 | For many aggregation operations, \code{agg} and \code{combine} are the same. 35 | For example, in the case of summation, both \code{agg} and \code{combine} 36 | are simply \code{+}. In some cases, these two operators can be different. 37 | For example, when counting the occurences of unique values, \code{agg} 38 | is \code{count} and \code{combine} is \code{+}. 39 | } 40 | \examples{ 41 | agg.op <- fm.create.agg.op(fm.bo.add, fm.bo.add, "sum") 42 | } 43 | 44 | -------------------------------------------------------------------------------- /man/fm.eigen.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \name{fm.eigen} 4 | \alias{fm.cal.residul} 5 | \alias{fm.eigen} 6 | \title{Eigensolver} 7 | \usage{ 8 | fm.eigen(mul, k, n, which = "LM", sym = TRUE, options = NULL, 9 | env = parent.frame()) 10 | 11 | fm.cal.residul(mul, values, vectors) 12 | } 13 | \arguments{ 14 | \item{mul}{The function to perform the matrix-vector multiplication.} 15 | 16 | \item{k}{Integer. The number of eigenvalues to compute.} 17 | 18 | \item{which}{String. Selection criteria.} 19 | 20 | \item{sym}{Logical scalar, whether the input matrix is symmetric.} 21 | 22 | \item{options}{List. Additional options to the eigensolver.} 23 | 24 | \item{env}{The environment in which \code{mul} will bevaluated.} 25 | 26 | \item{values}{The eigenvalues} 27 | 28 | \item{vectors}{The eigenvectors 29 | 30 | The \code{options} argument specifies what kind of computation to perform. 31 | It is a list with the following members, which correspond directly to 32 | Anasazi parameters: 33 | 34 | solver String. The name of the eigensolver to solve the eigenproblems. 35 | Currently, it supports three eigensolvers: KrylovSchur, 36 | Davidson and LOBPCG. KrylovSchur is the default eigensolver. 37 | 38 | tol Numeric scalar. Stopping criterion: the relative accuracy of 39 | the Ritz value is considered acceptable if its error is less 40 | than \code{tol} times its estimated value. 41 | 42 | block_size Numeric scalar. The eigensolvers use a block extension of an 43 | eigensolver algorithm. The block size determines the number 44 | of the vectors that operate together. 45 | 46 | num_blocks Numeric scalar. The number of blocks to compute eigenpairs.} 47 | } 48 | \value{ 49 | \code{fm.eigen} returns a named list with the following members: 50 | values: Numeric vector, the desired eigenvalues. 51 | vectors: Numeric matrix, the desired eigenvectors as columns. 52 | \code{fm.cal.residul} returns the corresponding residuals for 53 | the eigenvalues. 54 | } 55 | \description{ 56 | \code{fm.eigen} computes eigenvalues/vectors of a square matrix. 57 | \code{fm.cal.residul} computes the residual of the eigenvalues. 58 | } 59 | \details{ 60 | \code{fm.eigen} uses Anasazi package of Trilinos, if Anasazi is compiled 61 | into FlashR, or eigs to compute eigenvalues. 62 | 63 | The \code{which} specify which eigenvalues/vectors to compute, character 64 | constant with exactly two characters. Possible values for symmetric input 65 | matrices: 66 | \itemize{ 67 | \item{"LA"}{Compute \code{nev} largest (algebraic) eigenvalues.} 68 | \item{"SA"}{Compute \code{nev} smallest (algebraic) eigenvalues.} 69 | \item{"LM"}{Compute \code{nev} largest (in magnitude) eigenvalues.} 70 | \item{"SM"}{Compute \code{nev} smallest (in magnitude) eigenvalues.} 71 | } 72 | } 73 | \examples{ 74 | mat <- fm.load.sparse.matrix("./spm123.mat", "./spm123.mat_idx") 75 | res <- fm.eigen(mul, 10, nrow(mat)) 76 | fm.cal.residul(mul, res$values, res$vectors) 77 | } 78 | \author{ 79 | Da Zheng 80 | } 81 | 82 | -------------------------------------------------------------------------------- /man/fm.get.eles.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.get.eles} 4 | \alias{fm.get.cols} 5 | \alias{fm.get.eles} 6 | \alias{fm.get.eles.vec} 7 | \alias{fm.get.rows} 8 | \title{Get a submatrix from a FlashR matrix} 9 | \usage{ 10 | fm.get.cols(fm, idxs) 11 | 12 | fm.get.rows(fm, idxs) 13 | 14 | fm.get.eles.vec(fm, idxs) 15 | } 16 | \arguments{ 17 | \item{fm}{A FlashR matrix} 18 | 19 | \item{idxs}{an array of column indices in fm.} 20 | } 21 | \value{ 22 | a FlashR vector if getting one row or column; 23 | a FlashR matrix if getting more than one row or column. 24 | } 25 | \description{ 26 | \code{fm.get.rows} gets specified rows in a FlashR matrix. 27 | \code{fm.get.cols} gets specified columns in a FlashR matrix. 28 | \code{fm.get.eles.vec} gets specified elements from a FlashR vector. 29 | } 30 | \examples{ 31 | mat <- fm.runif.matrix(100, 10) 32 | sub <- fm.get.cols(mat, as.integer(runif(5, min=1, max=10))) 33 | sub <- fm.get.rows(mat, as.integer(runif(5, min=1, max=100))) 34 | vec <- fm.runif(100) 35 | sub <- fm.get.eles.vec(vec, as.integer(runif(5, min=1, max=100))) 36 | } 37 | \author{ 38 | Da Zheng 39 | } 40 | 41 | -------------------------------------------------------------------------------- /man/fm.get.matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.get.matrix} 4 | \alias{fm.get.dense.matrix} 5 | \alias{fm.get.matrix} 6 | \alias{fm.load.dense.matrix} 7 | \alias{fm.load.dense.matrix.bin} 8 | \alias{fm.load.sparse.matrix} 9 | \alias{fm.load.sparse.matrix.bin} 10 | \title{Load a matrix to FlashR.} 11 | \usage{ 12 | fm.get.dense.matrix(name) 13 | 14 | fm.load.dense.matrix(src.file, in.mem, ele.type = "D", delim = ",", 15 | ncol = .Machine$integer.max, name = "") 16 | 17 | fm.load.dense.matrix.bin(src.file, in.mem, nrow, ncol, byrow, ele.type, 18 | name = "") 19 | 20 | fm.load.sparse.matrix(file, in.mem = TRUE, is.sym = FALSE, ele.type = "B", 21 | delim = ",", name = "") 22 | 23 | fm.load.sparse.matrix.bin(spm, spm.idx, t.spm = NULL, t.spm.idx = NULL, 24 | in.mem = TRUE) 25 | } 26 | \arguments{ 27 | \item{name}{a string indicating the name of the dense matrix after being 28 | loaded to FlashR.} 29 | 30 | \item{src.file}{a string that indicates the file in the Linux filesystem 31 | that stores data to be loaded to FlashR.} 32 | 33 | \item{in.mem}{Determine the loaded matrix is stored in memory or on SAFS.} 34 | 35 | \item{ele.type}{A string that represents the element type in a matrix. 36 | "B" means binary, "I" means integer, "L" means long integer, 37 | "F" means single-precision floating point, "D" means double-precision floating point.} 38 | 39 | \item{delim}{The delimiter of separating elements in the text format.} 40 | 41 | \item{ncol}{the number of columns in the binary dense matrix.} 42 | 43 | \item{nrow}{the number of rows in the binary dense matrix.} 44 | 45 | \item{byrow}{a logical value indicating if the data in the binary matrix 46 | is stored by rows.} 47 | 48 | \item{spm}{The file that stores the sparse matrix.} 49 | 50 | \item{spm.idx}{The file that stores the index of the sparse matrix.} 51 | 52 | \item{t.spm}{The file that stores the transpose of the sparse matrix.} 53 | 54 | \item{t.spm.idx}{The file that stores the index of the transpose of the sparse matrix.} 55 | } 56 | \value{ 57 | a FlashR matrix. 58 | } 59 | \description{ 60 | There are many different ways of loading a matrix to FlashR. 61 | \code{fm.load.dense.matrix} loads a dense matrix in the text format from 62 | the Linux filesystem. 63 | \code{fm.load.dense.matrix.bin} loads a dense matrix in the binary format 64 | from the Linux filesystem. 65 | \code{fm.load.sparse.matrix} loads a FlashR sparse matrix from files. 66 | The matrix in the file is in the FlashR format. 67 | \code{fm.get.dense.matrix} returns a named dense matrix that has already 68 | been loaded to FlashR. 69 | } 70 | \details{ 71 | If a user provides \code{name} and \code{in.mem} is \code{TRUE}, the created 72 | vector/matrix will be kept on disks persistently. That is, even if a user 73 | exits from R, the vector/matrix will still be kept on disks. A user can 74 | access to the dense matrix with \code{fm.get.dense.matrix} the next time 75 | when he/she opens FlashR. 76 | } 77 | \examples{ 78 | mat <- fm.get.dense.matrix("mat123") # get a dense matrix named "mat123", stored in SAFS. 79 | mat <- fm.load.dense.matrix("./mat123.cvs", TRUE) # load a dense matrix from a local file "mat123.cvs" to memory. 80 | mat <- fm.load.sparse.matrix("./spm123.mat", "./spm123.mat_idx") # load a symmetric sparse matrix in FlashMatrix format (whose data is stored in "spm123.mat" and the index is stored in "spm123.mat_idx") to memory. 81 | } 82 | \author{ 83 | Da Zheng 84 | } 85 | 86 | -------------------------------------------------------------------------------- /man/fm.groupby.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.groupby} 4 | \alias{fm.groupby} 5 | \alias{fm.sgroupby} 6 | \title{Groupby on a FlashR vector.} 7 | \usage{ 8 | fm.sgroupby(obj, FUN) 9 | 10 | fm.groupby(obj, margin, factor, FUN) 11 | } 12 | \arguments{ 13 | \item{obj}{a FlashR vector or matrix} 14 | 15 | \item{FUN}{an aggregation operator returned by \code{fm.create.agg.op}.} 16 | 17 | \item{margin}{the subscript which the function will be applied over. 18 | E.g., for a matrix, \code{1} indicates rows, \code{2} indicates columns.} 19 | 20 | \item{factor}{a FlashR factor vector that indicates how rows/columns 21 | in a matrix should be grouped.} 22 | } 23 | \value{ 24 | \code{fm.sgroupby} returns a data frame, where the column \code{val} 25 | stores all of the unique values in the original data container, and the column 26 | \code{agg} stores the aggregate result of the corresponding value. 27 | } 28 | \description{ 29 | \code{fm.sgroupby} groups elements in a vector based on corresponding 30 | \code{labels} and applies \code{FUN} to the elements in each group. 31 | \code{FUN} is an aggregation operator. 32 | } 33 | \details{ 34 | \code{fm.groupby} groups rows/columns of a matrix based on corresponding 35 | \code{labels} and applies \code{FUN} to the rows/columns in each group. 36 | \code{FUN} is an aggregation operator. 37 | } 38 | \examples{ 39 | vec <- fm.runif(100) 40 | res <- fm.sgroupby(vec, "+") 41 | mat <- fm.runif.matrix(100, 10) 42 | fact <- fm.as.factor(as.integer(fm.runif(nrow(mat), min=0, max=3))) 43 | res <- fm.groupby(mat, 2, fact, "+") 44 | } 45 | \author{ 46 | Da Zheng 47 | } 48 | 49 | -------------------------------------------------------------------------------- /man/fm.info.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.info} 4 | \alias{fm.in.mem} 5 | \alias{fm.info} 6 | \alias{fm.is.object} 7 | \alias{fm.is.sink} 8 | \alias{fm.is.sparse} 9 | \alias{fm.is.sym} 10 | \alias{fm.matrix.layout} 11 | \title{The information of a FlashR object} 12 | \usage{ 13 | fm.is.sym(fm) 14 | 15 | fm.matrix.layout(fm) 16 | 17 | fm.is.sparse(fm) 18 | 19 | fm.is.sink(fm) 20 | 21 | fm.in.mem(fm) 22 | 23 | fm.is.object(fm) 24 | } 25 | \arguments{ 26 | \item{fm}{The FlashR object} 27 | } 28 | \value{ 29 | \code{fm.is.sym} and \code{fm.is.sparse} returns boolean constants. 30 | } 31 | \description{ 32 | These functions provide the basic information of a FlashR object. 33 | } 34 | \details{ 35 | \code{fm.is.sym} indicates whether a matrix is symmetric. 36 | 37 | \code{fm.matrix.layout} indicates how data in a matrix is organized. 38 | 39 | \code{fm.is.sparse} indicates whether a matrix is sparse. 40 | 41 | \code{fm.is.sink} indicates whether a FlashR object is a sink matrix. 42 | 43 | \code{fm.in.mem} indicates whether a FlashR object is stored in memory. 44 | 45 | \code{fm.is.object} indicates whether this is a FlashR object. 46 | } 47 | \author{ 48 | Da Zheng 49 | } 50 | 51 | -------------------------------------------------------------------------------- /man/fm.inner.prod.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.inner.prod} 4 | \alias{fm.inner.prod} 5 | \title{Matrix inner product} 6 | \usage{ 7 | fm.inner.prod(fm, mat, Fun1, Fun2) 8 | } 9 | \arguments{ 10 | \item{fm}{A FlashR matrix} 11 | 12 | \item{mat}{A FlashR dense matrix.} 13 | 14 | \item{Fun1}{The reference or the name of one of the predefined basic binary 15 | operators.} 16 | 17 | \item{Fun2}{The reference or the name of one of the predefined basic binary 18 | operators.} 19 | } 20 | \value{ 21 | a FlashR vector if the second argument is a vector; 22 | a FlashR matrix if the second argument is a matrix. 23 | } 24 | \description{ 25 | It takes two operators and performs inner product on a dense matrix 26 | } 27 | \examples{ 28 | mat1 <- fm.runif.matrix(1000, 100) 29 | mat2 <- fm.runif.matrix(100, 10) 30 | mat <- fm.inner.prod(mat1, mat2, "*", "+") 31 | mat <- fm.inner.prod(mat1, mat2, fm.bo.mul, fm.bo.add) 32 | } 33 | \author{ 34 | Da Zheng 35 | } 36 | 37 | -------------------------------------------------------------------------------- /man/fm.kmeans.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/KMeans.R 3 | \name{fm.kmeans} 4 | \alias{fm.kmeans} 5 | \title{KMeans clustering} 6 | \usage{ 7 | fm.kmeans(data, centers, max.iters = 10, debug = FALSE, use.blas = FALSE) 8 | } 9 | \arguments{ 10 | \item{data}{the input data matrix where each row is a data point.} 11 | 12 | \item{centers}{either the number of clusters, say k, or a set of 13 | initial (distinct) cluster centers. If a number, a random set 14 | of (distinct) rows in `x' is chosen as the initial centers.} 15 | 16 | \item{max.iters}{the maximal number of iterations.} 17 | 18 | \item{debug}{This indicates whether to print debug info.} 19 | 20 | \item{use.blas}{a logical value indicating whether to use BLAS to 21 | compute Euclidean distance.} 22 | } 23 | \value{ 24 | a vector that contains cluster Ids for each data point. 25 | } 26 | \description{ 27 | Perform k-means clustering on a data matrix. 28 | } 29 | \author{ 30 | Da Zheng 31 | } 32 | 33 | -------------------------------------------------------------------------------- /man/fm.mapply2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{methods} 4 | \name{fm.mapply2} 5 | \alias{fm.mapply.col} 6 | \alias{fm.mapply.row} 7 | \alias{fm.mapply2} 8 | \alias{fm.mapply2,ANY,fm-method} 9 | \alias{fm.mapply2,ANY,fmV-method} 10 | \alias{fm.mapply2,fm,ANY-method} 11 | \alias{fm.mapply2,fm,fm-method} 12 | \alias{fm.mapply2,fm,fmV-method} 13 | \alias{fm.mapply2,fm,matrix-method} 14 | \alias{fm.mapply2,fmV,ANY-method} 15 | \alias{fm.mapply2,fmV,fm-method} 16 | \alias{fm.mapply2,fmV,fmV-method} 17 | \alias{fm.mapply2,matrix,fm-method} 18 | \title{Apply a Function to two FlashR vectors/matrices.} 19 | \usage{ 20 | fm.mapply.row(o1, o2, FUN, set.na = TRUE) 21 | 22 | fm.mapply.col(o1, o2, FUN, set.na = TRUE) 23 | 24 | \S4method{fm.mapply2}{fm,fm}(o1, o2, FUN, set.na = TRUE) 25 | 26 | \S4method{fm.mapply2}{fmV,fmV}(o1, o2, FUN, set.na = TRUE) 27 | 28 | \S4method{fm.mapply2}{fm,fmV}(o1, o2, FUN, set.na = TRUE) 29 | 30 | \S4method{fm.mapply2}{fmV,fm}(o1, o2, FUN, set.na = TRUE) 31 | 32 | \S4method{fm.mapply2}{fm,matrix}(o1, o2, FUN, set.na = TRUE) 33 | 34 | \S4method{fm.mapply2}{matrix,fm}(o1, o2, FUN, set.na = TRUE) 35 | 36 | \S4method{fm.mapply2}{fm,ANY}(o1, o2, FUN, set.na = TRUE) 37 | 38 | \S4method{fm.mapply2}{ANY,fm}(o1, o2, FUN, set.na = TRUE) 39 | 40 | \S4method{fm.mapply2}{fmV,ANY}(o1, o2, FUN, set.na = TRUE) 41 | 42 | \S4method{fm.mapply2}{ANY,fmV}(o1, o2, FUN, set.na = TRUE) 43 | } 44 | \arguments{ 45 | \item{o1, o2}{a FlashR vector/matrix.} 46 | 47 | \item{FUN}{the reference or the name of one of the predefined basic binary 48 | operators.} 49 | 50 | \item{set.na}{a logical value indicating whether to set the value in 51 | the output matrix to NA if the value in the corresponding 52 | location of the input matrix is NA.} 53 | } 54 | \value{ 55 | a FlashR vector/matrix. 56 | } 57 | \description{ 58 | \code{fm.mapply2} applies \code{FUN} to the first elements of each 59 | vector/matrix, the second elements, the third elements, and so on. 60 | Two vectors/matrices should have the same shape. Currently, 61 | \code{fm.mapply2} only accepts predefined basic operators returned 62 | by \code{fm.get.basic.op}. 63 | } 64 | \details{ 65 | \code{fm.mapply.row} and \code{fm.mapply.col} applies to a matrix and 66 | a vector. \code{fm.mapply.row} applies \code{FUN} element-wise to 67 | each row of the matrix in the left argument and the vector in the right 68 | argument. \code{fm.mapply.col} applies \code{FUN} element-wise to 69 | each column of the matrix in the left argument and the vector in the right 70 | argument. 71 | } 72 | \examples{ 73 | mat <- fm.runif.matrix(100, 10) 74 | res <- fm.mapply.row(mat, runif(10), "+") 75 | res <- fm.mapply.col(mat, runif(100), "+") 76 | mat2 <- fm.runif.matrix(100, 10) 77 | res <- fm.mapply2(mat, mat2, "+") 78 | } 79 | \author{ 80 | Da Zheng 81 | } 82 | 83 | -------------------------------------------------------------------------------- /man/fm.multiply.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.multiply} 4 | \alias{fm.multiply} 5 | \title{Matrix multiplication} 6 | \usage{ 7 | fm.multiply(fm, mat) 8 | } 9 | \arguments{ 10 | \item{fm}{A FlashR matrix} 11 | 12 | \item{mat}{A FlashR dense matrix.} 13 | } 14 | \value{ 15 | a FlashR vector if the second argument is a vector; 16 | a FlashR matrix if the second argument is a matrix. 17 | } 18 | \description{ 19 | Multiply a sparse/dense matrix with a dense vector/matrix. 20 | } 21 | \examples{ 22 | mat1 <- fm.runif.matrix(1000, 100) 23 | mat2 <- fm.runif.matrix(100, 10) 24 | mat <- fm.multiply(mat1, mat2) 25 | } 26 | \author{ 27 | Da Zheng 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/fm.print.mat.info.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.print.mat.info} 4 | \alias{fm.print.mat.info} 5 | \title{Print the information of a FlashR object} 6 | \usage{ 7 | fm.print.mat.info(fm) 8 | } 9 | \arguments{ 10 | \item{fm}{a FlashR object 11 | mat <- fm.runif.matrix(100, 10) 12 | fm.print.mat.info(mat) 13 | mat <- fm.runif.matrix(100, 10) + fm.runif.matrix(100, 10) 14 | fm.print.mat.info(mat)} 15 | } 16 | \description{ 17 | Print the information of the internal storage representation of 18 | a FlashR object. For a virtualized computation result, 19 | \code{fm.print.mat.info} prints the internal computation dependancy. 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/fm.read.obj.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.read.obj} 4 | \alias{fm.read.obj} 5 | \title{Read a FlashR object (vector/matrix) from a file.} 6 | \usage{ 7 | fm.read.obj(file) 8 | } 9 | \arguments{ 10 | \item{file}{a file in the local filesystem.} 11 | } 12 | \value{ 13 | a FlashR object (vector/matrix) 14 | } 15 | \description{ 16 | Read a FlashR object (vector/matrix) from a file. 17 | } 18 | \examples{ 19 | mat <- fm.read.obj("/tmp/tmp.mat") 20 | } 21 | \author{ 22 | Da Zheng 23 | } 24 | 25 | -------------------------------------------------------------------------------- /man/fm.rep.int.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.rep.int} 4 | \alias{fm.rep.int} 5 | \title{Create a FlashR vector with replicated elements.} 6 | \usage{ 7 | fm.rep.int(x, times) 8 | } 9 | \arguments{ 10 | \item{x}{A constant initial value} 11 | 12 | \item{times}{The length of the vector to be generated.} 13 | } 14 | \value{ 15 | A FlashR vector 16 | } 17 | \description{ 18 | Create a FlashR vector with replicated elements. 19 | } 20 | \examples{ 21 | vec <- fm.rep.int(0, 10) # create a FlashR vector with 10 elements. 22 | } 23 | \author{ 24 | Da Zheng 25 | } 26 | 27 | -------------------------------------------------------------------------------- /man/fm.rnorm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.rnorm} 4 | \alias{fm.rnorm} 5 | \alias{fm.rnorm.matrix} 6 | \title{The Normal Distribution} 7 | \usage{ 8 | fm.rnorm(n, mean = 0, sd = 1, in.mem = TRUE, name = "") 9 | 10 | fm.rnorm.matrix(nrow, ncol, mean = 0, sd = 1, in.mem = TRUE, name = "") 11 | } 12 | \arguments{ 13 | \item{n}{the number of random numbers to be generated.} 14 | 15 | \item{mean}{the mean of the distribution.} 16 | 17 | \item{sd}{the standard deviation of the distribution.} 18 | 19 | \item{in.mem}{whether the vector is stored in memory.} 20 | 21 | \item{name}{the name of the matrix. It's stored on disks, it's used as 22 | the file name.} 23 | 24 | \item{nrow}{the number of rows in the generated matrix.} 25 | 26 | \item{ncol}{the number of columns in the generated matrix.} 27 | } 28 | \description{ 29 | \code{fm.rnorm} creates a FlashR vector with random numbers from 30 | normal distribution. 31 | \code{fm.rnorm.matrix} creates a FlashR matrix with random numbers from 32 | normal distribution. 33 | } 34 | \details{ 35 | If a user provides \code{name} and \code{in.mem} is \code{TRUE}, the created 36 | vector/matrix will be kept on disks persistently. That is, even if a user 37 | exits from R, the vector/matrix will still be kept on disks. 38 | } 39 | \examples{ 40 | vec <- fm.rnorm(10) # a vector of 10 elements filled with random numbers under normal distribution. 41 | mat <- fm.rnorm.matrix(10, 2) # a 10x2 matrix. 42 | } 43 | \author{ 44 | Da Zheng 45 | } 46 | 47 | -------------------------------------------------------------------------------- /man/fm.rsparse.proj.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.rsparse.proj} 4 | \alias{fm.rsparse.proj} 5 | \title{Create a sparse projection matrix.} 6 | \usage{ 7 | fm.rsparse.proj(nrow, ncol, density, name = "") 8 | } 9 | \arguments{ 10 | \item{nrow}{the number of rows in the generated matrix.} 11 | 12 | \item{ncol}{the number of columns in the generated matrix.} 13 | 14 | \item{density}{the ratio of non-zero entries to the total number of elements.} 15 | 16 | \item{name}{the name of the matrix. It's stored on disks, it's used as 17 | the file name.} 18 | } 19 | \value{ 20 | a FlashR matrix. 21 | } 22 | \description{ 23 | \code{fm.rsparse.proj} creates a sparse projection matrix stored in memory. 24 | } 25 | \details{ 26 | The non-zero values in the sparse projection matrix are either 1 or -1. 27 | Their values are uniformly randomly chosen to be 1 or -1. 28 | } 29 | \examples{ 30 | mat <- fm.rsparse.proj(10000, 100, 0.001) # a sparse projection matrix. 31 | } 32 | 33 | -------------------------------------------------------------------------------- /man/fm.runif.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.runif} 4 | \alias{fm.runif} 5 | \alias{fm.runif.matrix} 6 | \title{The Uniform Distribution} 7 | \usage{ 8 | fm.runif(n, min = 0, max = 1, in.mem = TRUE, name = "") 9 | 10 | fm.runif.matrix(nrow, ncol, min = 0, max = 1, in.mem = TRUE, name = "") 11 | } 12 | \arguments{ 13 | \item{n}{the number of random numbers to be generated.} 14 | 15 | \item{min}{lower limits of the distribution.} 16 | 17 | \item{max}{upper limits of the distribution.} 18 | 19 | \item{in.mem}{whether the vector is stored in memory.} 20 | 21 | \item{name}{the name of the vector. It's stored on disks, it's used as 22 | the file name.} 23 | 24 | \item{nrow}{the number of rows in the generated matrix.} 25 | 26 | \item{ncol}{the number of columns in the generated matrix.} 27 | } 28 | \description{ 29 | \code{fm.runif} creates a FlashR vector with uniformly random numbers. 30 | \code{fm.runif.matrix} creates a FlashR matrix with uniformly random 31 | numbers. 32 | } 33 | \details{ 34 | If a user provides \code{name} and \code{in.mem} is \code{TRUE}, the created 35 | vector/matrix will be kept on disks persistently. That is, even if a user 36 | exits from R, the vector/matrix will still be kept on disks. 37 | } 38 | \examples{ 39 | vec <- fm.runif(10) # a vector of 10 elements filled with uniform random numbers. 40 | mat <- fm.runif.matrix(10, 2) a 10x2 matrix filled with uniform random numbers. 41 | } 42 | \author{ 43 | Da Zheng 44 | } 45 | 46 | -------------------------------------------------------------------------------- /man/fm.sapply.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{methods} 4 | \name{fm.sapply} 5 | \alias{fm.sapply} 6 | \alias{fm.sapply,fm-method} 7 | \alias{fm.sapply,fmV-method} 8 | \title{Apply a Function to a FlashR vector/matrix.} 9 | \usage{ 10 | fm.sapply(o, FUN, set.na = TRUE) 11 | 12 | \S4method{fm.sapply}{fm}(o, FUN, set.na = TRUE) 13 | 14 | \S4method{fm.sapply}{fmV}(o, FUN, set.na = TRUE) 15 | } 16 | \arguments{ 17 | \item{o}{a FlashR vector/matrix.} 18 | 19 | \item{FUN}{the reference or the name of a predefined uniary operator.} 20 | 21 | \item{set.na}{a logical value indicating whether to set the value in 22 | the output vector or matrix to NA if the value in 23 | the corresponding location of the input vector or matrix 24 | is NA.} 25 | } 26 | \value{ 27 | a FlashR vector/matrix. 28 | } 29 | \description{ 30 | \code{sapply} applies \code{FUN} to every element of a vector/matrix. 31 | Currently, \code{sapply} only accepts predefined basic operators 32 | returned by \code{fm.get.basic.uop}. 33 | } 34 | \examples{ 35 | mat <- fm.runif.matrix(100, 10) 36 | res <- fm.sapply(mat, "abs") 37 | } 38 | \author{ 39 | Da Zheng 40 | } 41 | 42 | -------------------------------------------------------------------------------- /man/fm.seq.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.seq} 4 | \alias{fm.seq} 5 | \alias{fm.seq.int} 6 | \alias{fm.seq.matrix} 7 | \title{Sequence Generation} 8 | \usage{ 9 | fm.seq.int(from, to, by) 10 | 11 | fm.seq.matrix(from, to, nrow, ncol, byrow = FALSE) 12 | } 13 | \arguments{ 14 | \item{from}{the starting value of the sequence.} 15 | 16 | \item{to}{the end value of the sequence.} 17 | 18 | \item{by}{number. increment of the sequence.} 19 | 20 | \item{nrow}{the number of rows in the generated matrix.} 21 | 22 | \item{ncol}{the number of columns in the generated matrix.} 23 | 24 | \item{byrow}{logical. If \code{FALSE} (the default) the matrix is filled by 25 | columns, otherwise the matrix is filled by rows.} 26 | } 27 | \value{ 28 | a FlashR vector or matrix filled with a sequence of numbers 29 | that belongs to [from, to] 30 | } 31 | \description{ 32 | \code{fm.seq.int} creates a FlashR vector with a sequence of numbers. 33 | \code{fm.seq.matrix} creates a FlashR matrix with a sequence of numbers. 34 | } 35 | \examples{ 36 | vec <- fm.seq.int(1, 10, 1) # create a FlashR vector of 10 elements whose values are from 1 to 10. 37 | mat <- fm.seq.matrix(1, 20, 10, 2) # create a 10x2 FlashR matrix whose rows are sequence numbers from 1 to 10. 38 | } 39 | \author{ 40 | Da Zheng 41 | } 42 | 43 | -------------------------------------------------------------------------------- /man/fm.set.conf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.set.conf} 4 | \alias{fm.print.conf} 5 | \alias{fm.print.features} 6 | \alias{fm.set.conf} 7 | \alias{fm.set.log.level} 8 | \title{Reconfigure FlashR} 9 | \usage{ 10 | fm.set.conf(conf.file) 11 | 12 | fm.set.log.level(level) 13 | 14 | fm.print.conf() 15 | 16 | fm.print.features() 17 | } 18 | \arguments{ 19 | \item{conf.file}{The configuration file.} 20 | 21 | \item{level}{a string, including "debug", "info", "warning", "error", "fatal".} 22 | } 23 | \description{ 24 | \code{fm.set.conf} reconfigures FlashR with the settings in 25 | the configuration file. \code{fm.print.conf} prints the current configurations. 26 | \code{fm.set.log.level} sets what levels of messages should be logged. 27 | \code{fm.print.features} prints the features compiled into FlashR. 28 | } 29 | \details{ 30 | The configuration file contains a list of key-value pairs. Each line in 31 | the file is a key-value pair in the form of "key_name=value". 32 | } 33 | \examples{ 34 | fm.set.conf("conf/run_test.txt") # configure FlashR with the config file conf/run_test.txt 35 | fm.set.log.level("info") # FlashR prints more information when it runs. 36 | fm.print.conf() 37 | fm.print.features() 38 | } 39 | \author{ 40 | Da Zheng 41 | } 42 | 43 | -------------------------------------------------------------------------------- /man/fm.t.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.t} 4 | \alias{fm.t} 5 | \title{Transpose a FlashR matrix.} 6 | \usage{ 7 | fm.t(m) 8 | } 9 | \arguments{ 10 | \item{m}{a FlashR matrix} 11 | } 12 | \value{ 13 | a FlashR matrix 14 | } 15 | \description{ 16 | Transpose a FlashR matrix. 17 | } 18 | \examples{ 19 | mat <- fm.t(fm.runif.matrix(100, 10)) 20 | } 21 | \author{ 22 | Da Zheng 23 | } 24 | 25 | -------------------------------------------------------------------------------- /man/fm.table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{fm.table} 5 | \alias{as.data.frame,fm.table-method} 6 | \alias{as.vector,fm.table-method} 7 | \alias{fm.table} 8 | \title{Count the number of elements} 9 | \usage{ 10 | fm.table(x) 11 | 12 | \S4method{as.vector}{fm.table}(x) 13 | 14 | \S4method{as.data.frame}{fm.table}(x, row.names = NULL, optional = FALSE, 15 | ...) 16 | } 17 | \arguments{ 18 | \item{x}{a FlashR vector or a "table" object for \code{as.vector} and 19 | \code{as.data.frame}.} 20 | } 21 | \value{ 22 | a table object. 23 | \itemize{ 24 | \item{val}{The unique values in the vector.} 25 | \item{Freq}{The number of occurences of each unique value.} 26 | } 27 | } 28 | \description{ 29 | \code{fm.table} counts the number of occurences of each unique value 30 | in a FlashR vector. 31 | } 32 | \examples{ 33 | vec <- as.integer(fm.runif(1000, min=0, max=10)) 34 | tbl <- fm.table(vec) 35 | cnts <- as.vector(tbl) 36 | df <- as.data.frame(tbl) 37 | } 38 | 39 | -------------------------------------------------------------------------------- /man/fm.write.obj.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{fm.write.obj} 4 | \alias{fm.write.obj} 5 | \title{Write a FlashR object (vector/matrix) to a file} 6 | \usage{ 7 | fm.write.obj(fm, file) 8 | } 9 | \arguments{ 10 | \item{fm}{a FlashR object.} 11 | 12 | \item{file}{a file in the local filesystem.} 13 | } 14 | \value{ 15 | a logical value. True if the object is written to a file 16 | successfully. Otherwise, FALSE. 17 | } 18 | \description{ 19 | Write a FlashR object (vector/matrix) to a file 20 | } 21 | \examples{ 22 | mat <- fm.runif.matrix(100, 10) 23 | fm.write.obj(mat, "/tmp/tmp.mat") 24 | } 25 | \author{ 26 | Da Zheng 27 | } 28 | 29 | -------------------------------------------------------------------------------- /man/fmV-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{class} 4 | \name{fmV-class} 5 | \alias{fmV-class} 6 | \title{An S4 class to represent a FlashR vector.} 7 | \description{ 8 | An S4 class to represent a FlashR vector. 9 | } 10 | \section{Slots}{ 11 | 12 | \describe{ 13 | \item{\code{pointer}}{points a vector object in C.} 14 | 15 | \item{\code{name}}{a string indicating the name of the vector.} 16 | 17 | \item{\code{len}}{a numeric value indicating the number of elements.} 18 | 19 | \item{\code{type}}{a string indicating the type of the vector. This field isn't 20 | used for a vector.} 21 | 22 | \item{\code{ele_type}}{a string indicating the element type in the vector.} 23 | 24 | \item{\code{attrs}}{a list that stores the attributes of the matrix.} 25 | }} 26 | 27 | -------------------------------------------------------------------------------- /man/fmVFactor-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{class} 4 | \name{fmVFactor-class} 5 | \alias{fmVFactor-class} 6 | \title{An S4 class to represent a FlashR factor vector. It inherits from 7 | a FlashR vector.} 8 | \description{ 9 | An S4 class to represent a FlashR factor vector. It inherits from 10 | a FlashR vector. 11 | } 12 | \section{Slots}{ 13 | 14 | \describe{ 15 | \item{\code{pointer}}{points a vector object in C.} 16 | 17 | \item{\code{name}}{a string indicating the name of the vector.} 18 | 19 | \item{\code{len}}{a numeric value indicating the number of elements.} 20 | 21 | \item{\code{type}}{a string indicating the type of the vector. This field isn't 22 | used for a vector.} 23 | 24 | \item{\code{ele_type}}{a string indicating the element type in the vector.} 25 | 26 | \item{\code{num.levels}}{an integer indicating the number of levels.} 27 | }} 28 | 29 | -------------------------------------------------------------------------------- /man/head.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{head} 5 | \alias{head} 6 | \alias{head,fm-method} 7 | \alias{head,fmV-method} 8 | \alias{tail,fm-method} 9 | \alias{tail,fmV-method} 10 | \title{Return the First or Last part of an Object} 11 | \usage{ 12 | \S4method{head}{fm}(x, n = 6L) 13 | 14 | \S4method{tail}{fm}(x, n = 6L) 15 | 16 | \S4method{head}{fmV}(x, n = 6L) 17 | 18 | \S4method{tail}{fmV}(x, n = 6L) 19 | } 20 | \arguments{ 21 | \item{x}{a FlashR vector or matrix.} 22 | 23 | \item{n}{a positive integer.} 24 | } 25 | \value{ 26 | An object (usually) like \code{x} but generally smaller. 27 | } 28 | \description{ 29 | Returns the first or last parts of a FlashR vector or matrix. 30 | } 31 | \examples{ 32 | mat <- fm.runif.matrix(100, 10) 33 | head(mat) 34 | tail(mat) 35 | } 36 | 37 | -------------------------------------------------------------------------------- /man/ifelse.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{methods} 4 | \name{ifelse} 5 | \alias{ifelse} 6 | \alias{ifelse,fm,ANY,fm-method} 7 | \alias{ifelse,fm,fm,ANY-method} 8 | \alias{ifelse,fmV,ANY,fmV-method} 9 | \alias{ifelse,fmV,fmV,ANY-method} 10 | \title{Conditional Element Selection} 11 | \usage{ 12 | \S4method{ifelse}{fm,fm,ANY}(test, yes, no) 13 | 14 | \S4method{ifelse}{fm,ANY,fm}(test, yes, no) 15 | 16 | \S4method{ifelse}{fmV,fmV,ANY}(test, yes, no) 17 | 18 | \S4method{ifelse}{fmV,ANY,fmV}(test, yes, no) 19 | } 20 | \arguments{ 21 | \item{test}{a logical FlashR vector or matrix.} 22 | 23 | \item{yes}{a FlashR vector or matrix or an R scalar.} 24 | 25 | \item{no}{a FlashR vector or matrix or an R scalar.} 26 | } 27 | \value{ 28 | A FlashR vector or matrix of the same size and attributes 29 | (including dimensions) as \code{test} and data values from the values 30 | of \code{yes} or \code{no}. 31 | } 32 | \description{ 33 | \code{ifelse} returns a value with the same shape as \code{test} which is 34 | filled with elements selected from either \code{yes} or \code{no} depending 35 | on whether the element of \code{test} is \code{TRUE} or \code{FALSE}. 36 | } 37 | \details{ 38 | The current implementation requires either \code{yes} or \code{no} to be 39 | a scalar value. 40 | } 41 | \examples{ 42 | mat <- fm.runif.matrix(100, 10) 43 | mat <- ifelse(mat > 0.5, mat, 0) 44 | } 45 | 46 | -------------------------------------------------------------------------------- /man/integer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{integer} 5 | \alias{as.integer,fm-method} 6 | \alias{as.integer,fmV-method} 7 | \alias{integer} 8 | \title{Integer Vectors} 9 | \usage{ 10 | \S4method{as.integer}{fm}(x) 11 | 12 | \S4method{as.integer}{fmV}(x) 13 | } 14 | \arguments{ 15 | \item{x}{a FlashR object to be coerced or tested.} 16 | } 17 | \value{ 18 | \code{as.integer} returns an integer FlashR object, 19 | \code{is.integer} returns a logical value. 20 | } 21 | \description{ 22 | \code{as.integer} coerces objects of type \code{"integer"}. 23 | \code{is.integer} is a more general test of an object being 24 | interpretable as integers. 25 | } 26 | \examples{ 27 | vec <- as.integer(fm.runif(1000, min=0, max=10)) 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/is.finite.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{methods} 4 | \name{is.finite} 5 | \alias{is.finite} 6 | \alias{is.finite,fm-method} 7 | \alias{is.finite,fmV-method} 8 | \alias{is.infinite,fm-method} 9 | \alias{is.infinite,fmV-method} 10 | \alias{is.nan,fm-method} 11 | \alias{is.nan,fmV-method} 12 | \title{Finite, Infinite and NaN Numbers} 13 | \usage{ 14 | \S4method{is.nan}{fm}(x) 15 | 16 | \S4method{is.nan}{fmV}(x) 17 | 18 | \S4method{is.infinite}{fm}(x) 19 | 20 | \S4method{is.infinite}{fmV}(x) 21 | 22 | \S4method{is.finite}{fm}(x) 23 | 24 | \S4method{is.finite}{fmV}(x) 25 | } 26 | \arguments{ 27 | \item{x}{a FlashR object} 28 | } 29 | \value{ 30 | A logical vector of the same length as \code{x} 31 | } 32 | \description{ 33 | \code{is.finite} and \code{is.infinite} return a vector of the same length 34 | as \code{x}, indicating which elements are finite (not infinite and not 35 | missing) or infinite. 36 | } 37 | \examples{ 38 | mat <- fm.runif.matrix(100, 10) 39 | is.finite(mat) 40 | is.infinite(mat) 41 | is.nan(mat) 42 | } 43 | 44 | -------------------------------------------------------------------------------- /man/length.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{length} 5 | \alias{length} 6 | \alias{length,fm-method} 7 | \alias{length,fmV-method} 8 | \title{Length of an Object} 9 | \usage{ 10 | \S4method{length}{fmV}(x) 11 | 12 | \S4method{length}{fm}(x) 13 | } 14 | \arguments{ 15 | \item{x}{an FlashR object.} 16 | } 17 | \value{ 18 | an integer of length 1 or a double if the object has more than 19 | 2^31-1 elements. 20 | } 21 | \description{ 22 | Get the length of a vector or a matrix. 23 | } 24 | \examples{ 25 | mat <- fm.runif.matrix(100, 10) 26 | length(mat) 27 | } 28 | 29 | -------------------------------------------------------------------------------- /man/levels.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{methods} 4 | \name{levels} 5 | \alias{levels} 6 | \title{Levels Attributes} 7 | \usage{ 8 | \S4method{levels}{fmVFactor}(x) 9 | } 10 | \arguments{ 11 | \item{x}{a FlashR factor.} 12 | } 13 | \value{ 14 | a FlashR vector that contains the value of the levels. 15 | } 16 | \description{ 17 | \code{levels} returns the levels attribute of a variable. 18 | } 19 | \details{ 20 | Currently, levels of a factor vector is a sequence number from 1 to 21 | the number of levels. FlashR doesn't support other factor values. 22 | } 23 | \examples{ 24 | vec <- fm.as.factor(as.integer(fm.runif(100, min=0, max=100))) 25 | levels(vec) 26 | } 27 | 28 | -------------------------------------------------------------------------------- /man/log.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{log} 5 | \alias{exp,fm-method} 6 | \alias{exp,fmV-method} 7 | \alias{log} 8 | \alias{log,fm-method} 9 | \alias{log,fmV-method} 10 | \alias{log10,fm-method} 11 | \alias{log10,fmV-method} 12 | \alias{log2,fm-method} 13 | \alias{log2,fmV-method} 14 | \title{Logarithms and Exponentials} 15 | \usage{ 16 | \S4method{log10}{fm}(x) 17 | 18 | \S4method{log10}{fmV}(x) 19 | 20 | \S4method{log2}{fm}(x) 21 | 22 | \S4method{log2}{fmV}(x) 23 | 24 | \S4method{exp}{fm}(x) 25 | 26 | \S4method{exp}{fmV}(x) 27 | 28 | \S4method{log}{fm}(x, base = exp(1)) 29 | 30 | \S4method{log}{fmV}(x, base = exp(1)) 31 | } 32 | \arguments{ 33 | \item{x}{a numeric vector.} 34 | 35 | \item{base}{a positive number.} 36 | } 37 | \value{ 38 | A vector of the same length as \code{x} containing the transformed 39 | values. \code{log(0)} gives \code{-Inf}, and \code{log(x)} for negative 40 | values of \code{x} is \code{NaN}. \code{exp(-Inf)} is 0. 41 | } 42 | \description{ 43 | \code{log} computes logarithms, by default natural logarithms, \code{log10} 44 | computes common (i.e., base 10) logarithms, and \code{log2} computes binary 45 | (i.e., base 2) logarithms. The general form log(x, base) computes logarithms 46 | with \code{base}. 47 | } 48 | \details{ 49 | \code{exp} computes the exponential function. 50 | } 51 | \examples{ 52 | mat <- log(fm.runif.matrix(100, 10)) 53 | mat <- log10(fm.runif.matrix(100, 10)) 54 | mat <- log2(fm.runif.matrix(100, 10)) 55 | mat <- exp(fm.runif.matrix(100, 10)) 56 | } 57 | 58 | -------------------------------------------------------------------------------- /man/materialize.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{materialize} 4 | \alias{fm.materialize} 5 | \alias{fm.materialize.list} 6 | \alias{fm.set.cached} 7 | \alias{materialize} 8 | \title{Materialize virtual FlashR objects.} 9 | \usage{ 10 | fm.materialize.list(args) 11 | 12 | fm.materialize(...) 13 | 14 | fm.set.cached(fm, cached, in.mem = fm.in.mem(fm)) 15 | } 16 | \arguments{ 17 | \item{args}{a list of virtual FlashR objects.} 18 | 19 | \item{...}{a list of virtual FlashR objects.} 20 | 21 | \item{fm}{a FlashR object.} 22 | 23 | \item{in.mem}{a logical value, indicating whether to save the computation 24 | results in memory.} 25 | } 26 | \value{ 27 | a list of materialized compuation results. 28 | } 29 | \description{ 30 | FlashR lazily evaluates many operations and outputs virtual objects 31 | that represent computation results. \code{fm.materialize.list} and 32 | \code{fm.materialize} explicitly materialize the virtualized computation 33 | and save the computation results to memory or disks. Materialization of 34 | these virtualized computations triggers materialization of other virtualized 35 | computation. By default, FlashR only saves the computation results 36 | specified by the arguments of \code{fm.materialize.list} and 37 | \code{fm.materialize}. \code{fm.set.cached} changes the default behavior and 38 | notifies FlashR to save the materialized computation results of a virtual 39 | matrix in memory or on disks. 40 | } 41 | \examples{ 42 | mat <- fm.mapply2(fm.runif.matrix(100, 10), fm.runif.matrix(100, 10), "+") 43 | mat <- fm.materialize(mat) 44 | mat2 <- fm.sapply(fm.runif.matrix(100, 10), "sqrt") 45 | mat.list <- list(mat, mat2) 46 | mat.list <- fm.materialize.list(mat.list) 47 | mat <- fm.mapply2(fm.runif.matrix(100, 10), fm.runif.matrix(100, 10), "+") 48 | fm.set.cached(mat, TRUE) 49 | res <- fm.agg(mat, "+") 50 | } 51 | 52 | -------------------------------------------------------------------------------- /man/matmult.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{matmult} 5 | \alias{\%*\%,ANY,fm-method} 6 | \alias{\%*\%,fm,ANY-method} 7 | \alias{\%*\%,fm,fm-method} 8 | \alias{\%*\%,fm,fmV-method} 9 | \alias{\%*\%,fmV,fm-method} 10 | \alias{matmult} 11 | \title{Matrix multiplication} 12 | \usage{ 13 | \S4method{\%*\%}{fm,fm}(x, y) 14 | 15 | \S4method{\%*\%}{fm,fmV}(x, y) 16 | 17 | \S4method{\%*\%}{fmV,fm}(x, y) 18 | 19 | \S4method{\%*\%}{fm,ANY}(x, y) 20 | 21 | \S4method{\%*\%}{ANY,fm}(x, y) 22 | } 23 | \arguments{ 24 | \item{x}{a FlashR matrix.} 25 | 26 | \item{y}{can be a FlashR vector or matrix, an R vector or matrix.} 27 | } 28 | \value{ 29 | a FlashR matrix. 30 | } 31 | \description{ 32 | Multiplies two matrices, if they are conformable. If one argument is 33 | a vector, it will be promoted to either a row or column matrix to make 34 | the two arguments conformable. 35 | } 36 | \examples{ 37 | mat1 <- fm.runif.matrix(100, 10) 38 | mat2 <- fm.runif.matrix(10, 10) 39 | mat <- mat1 \%*\% mat2 40 | } 41 | 42 | -------------------------------------------------------------------------------- /man/matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{methods} 4 | \name{matrix} 5 | \alias{as.matrix,fm-method} 6 | \alias{as.matrix,fmV-method} 7 | \alias{fm.as.matrix} 8 | \alias{fm.is.matrix} 9 | \alias{fm.matrix} 10 | \alias{matrix} 11 | \title{Matrices} 12 | \usage{ 13 | \S4method{as.matrix}{fm}(x) 14 | 15 | \S4method{as.matrix}{fmV}(x) 16 | 17 | fm.is.matrix(fm) 18 | 19 | fm.as.matrix(x) 20 | 21 | fm.matrix(vec, nrow, ncol, byrow = FALSE) 22 | } 23 | \arguments{ 24 | \item{x}{an R object} 25 | 26 | \item{vec}{an R data vector.} 27 | 28 | \item{nrow}{the desired number of rows.} 29 | 30 | \item{ncol}{the desired number of columns.} 31 | 32 | \item{byrow}{logical. If \code{FALSE} (the default) the matrix is filled by 33 | columns, otherwise the matrix is filled by rows.} 34 | } 35 | \description{ 36 | \code{fm.matrix} creates a matrix from the given set of values. 37 | \code{as.matrix} attempts to turn a FlashR matrix to an R matrix. 38 | \code{fm.as.matrix} attempts to turn its argument into a FlashR matrix. 39 | \code{fm.is.matrix} indicates whether a FlashR object is a matrix. 40 | } 41 | \details{ 42 | Currently, \code{fm.matrix} takes an R vector or a FlashR vector as input 43 | and the length of the vector must be the same as the number of rows if 44 | \code{byrow} is \code{FALSE} or the same as the number of columns if 45 | \code{byrow} is \code{TRUE}. 46 | } 47 | \examples{ 48 | mat <- fm.matrix(runif(100), 100, 2) 49 | mat <- as.matrix(fm.runif.matrix(100, 2)) 50 | mat <- fm.as.matrix(matrix(runif(200), 100, 2)) 51 | res <- fm.is.matrix(mat) 52 | } 53 | 54 | -------------------------------------------------------------------------------- /man/mean.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{mean} 5 | \alias{mean} 6 | \alias{mean,fm-method} 7 | \alias{mean,fmV-method} 8 | \title{Arithmetic Mean} 9 | \usage{ 10 | \S4method{mean}{fm}(x, ...) 11 | 12 | \S4method{mean}{fmV}(x, ...) 13 | } 14 | \arguments{ 15 | \item{x}{A FlashR vector or matrix.} 16 | 17 | \item{...}{further arguments passed to or from other methods.} 18 | } 19 | \description{ 20 | Compute arithmetic mean. 21 | } 22 | \examples{ 23 | mat <- fm.runif.matrix(100, 10) 24 | mean(mat) 25 | } 26 | 27 | -------------------------------------------------------------------------------- /man/names.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{names} 5 | \alias{names} 6 | \alias{names,fm-method} 7 | \alias{names,fmV-method} 8 | \alias{names<-,fm,fm-method} 9 | \alias{names<-,fmV,fmV-method} 10 | \title{The Names of an Object} 11 | \usage{ 12 | \S4method{names}{fm}(x) 13 | 14 | \S4method{names}{fmV}(x) 15 | 16 | \S4method{names}{fm,fm}(x) <- value 17 | 18 | \S4method{names}{fmV,fmV}(x) <- value 19 | } 20 | \arguments{ 21 | \item{x}{a FlashR array} 22 | 23 | \item{value}{a FlashR array.} 24 | } 25 | \value{ 26 | \code{names} returns \code{NULL} or a FlashR array of the same 27 | length as \code{x}. \code{names<-} returns the updated object. 28 | } 29 | \description{ 30 | Functions to get or set the names of an object. 31 | } 32 | \details{ 33 | Currently, \code{value} has to have the same length as \code{x} and has 34 | the same shape. FlashR currently doesn't support character vectors yet. 35 | } 36 | 37 | -------------------------------------------------------------------------------- /man/nlevels.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{methods} 4 | \name{nlevels} 5 | \alias{nlevels} 6 | \title{The Number of Levels of a Factor} 7 | \usage{ 8 | \S4method{nlevels}{fmVFactor}(x) 9 | } 10 | \arguments{ 11 | \item{x}{a FlashR factor} 12 | } 13 | \value{ 14 | The length of \code{levels(x)}, which is zero if \code{x} 15 | has no levels. 16 | } 17 | \description{ 18 | Return the number of levels which its argument has. 19 | } 20 | \details{ 21 | This is applied to a FlashR factor. 22 | } 23 | \examples{ 24 | vec <- fm.as.factor(as.integer(fm.runif(100, min=0, max=100))) 25 | nlevels(vec) 26 | } 27 | 28 | -------------------------------------------------------------------------------- /man/nrow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{nrow} 5 | \alias{ncol,fm-method} 6 | \alias{nrow} 7 | \alias{nrow,fm-method} 8 | \title{The Number of Rows/Columns of a matrix.} 9 | \usage{ 10 | \S4method{nrow}{fm}(x) 11 | 12 | \S4method{ncol}{fm}(x) 13 | } 14 | \arguments{ 15 | \item{x}{a matrix.} 16 | } 17 | \value{ 18 | an integer of length 1 or NULL. 19 | } 20 | \description{ 21 | \code{nrow} and \code{ncol} return the number of rows or columns 22 | present in \code{x}. 23 | } 24 | \examples{ 25 | mat <- fm.runif.matrix(100, 10) 26 | nrow(mat) 27 | ncol(mat) 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/numeric.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{numeric} 5 | \alias{as.numeric,fm-method} 6 | \alias{as.numeric,fmV-method} 7 | \alias{is.numeric,fm-method} 8 | \alias{is.numeric,fmV-method} 9 | \alias{numeric} 10 | \title{Numeric Vectors} 11 | \usage{ 12 | \S4method{as.numeric}{fm}(x) 13 | 14 | \S4method{as.numeric}{fmV}(x) 15 | 16 | \S4method{is.numeric}{fm}(x) 17 | 18 | \S4method{is.numeric}{fmV}(x) 19 | } 20 | \arguments{ 21 | \item{x}{a FlashR object to be coerced or tested.} 22 | } 23 | \value{ 24 | \code{as.numeric} returns a numeric FlashR object, 25 | \code{is.numeric} returns a logical value. 26 | } 27 | \description{ 28 | Coerces or test objects of type \code{"numeric"}. \code{is.numeric} 29 | is a more general test of an object being interpretable as numbers. 30 | } 31 | \examples{ 32 | vec <- as.numeric(fm.runif(1000, min=0, max=10)) 33 | is.numeric(vec) 34 | } 35 | 36 | -------------------------------------------------------------------------------- /man/print.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{print} 5 | \alias{print} 6 | \alias{print,fm-method} 7 | \alias{print,fm.bo-method} 8 | \alias{print,fmV-method} 9 | \alias{print,fmVFactor-method} 10 | \title{Print FlashR objects.} 11 | \usage{ 12 | \S4method{print}{fm}(x) 13 | 14 | \S4method{print}{fmV}(x) 15 | 16 | \S4method{print}{fmVFactor}(x) 17 | 18 | \S4method{print}{fm.bo}(x) 19 | } 20 | \arguments{ 21 | \item{x}{a FlashR object. It can be a vector, a matrix or a FlashR 22 | binary operator.} 23 | } 24 | \description{ 25 | \code{print} prints the information of a FlashR object. 26 | } 27 | 28 | -------------------------------------------------------------------------------- /man/profile.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \name{profile} 4 | \alias{fm.start.profiler} 5 | \alias{fm.stop.profiler} 6 | \alias{profile} 7 | \title{Google profiler} 8 | \usage{ 9 | fm.start.profiler(file) 10 | 11 | fm.stop.profiler() 12 | } 13 | \arguments{ 14 | \item{file}{a string that indicates the file where the profiling result 15 | is saved.} 16 | } 17 | \description{ 18 | This uses the Google profiler to profile the execution of the code. 19 | https://github.com/gperftools/gperftools 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/range.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{range} 5 | \alias{range} 6 | \alias{range,fm-method} 7 | \alias{range,fmV-method} 8 | \title{Range of Values} 9 | \usage{ 10 | \S4method{range}{fm}(x, ..., na.rm = FALSE) 11 | 12 | \S4method{range}{fmV}(x, ..., na.rm = FALSE) 13 | } 14 | \arguments{ 15 | \item{x}{a FlashR vector or matrix.} 16 | 17 | \item{...}{any FlashR vectors or matrices.} 18 | 19 | \item{na.rm}{logical, indicating if \code{NA} should be omitted.} 20 | } 21 | \description{ 22 | \code{range} returns a vector containing the minimum and maximum of all 23 | the given arguments. 24 | } 25 | \examples{ 26 | mat <- fm.runif.matrix(100, 10) 27 | range(mat) 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/round.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{round} 5 | \alias{ceiling,fm-method} 6 | \alias{ceiling,fmV-method} 7 | \alias{floor,fm-method} 8 | \alias{floor,fmV-method} 9 | \alias{round} 10 | \alias{round,fm-method} 11 | \alias{round,fmV-method} 12 | \title{Rounding of Numbers} 13 | \usage{ 14 | \S4method{ceiling}{fm}(x) 15 | 16 | \S4method{ceiling}{fmV}(x) 17 | 18 | \S4method{floor}{fm}(x) 19 | 20 | \S4method{floor}{fmV}(x) 21 | 22 | \S4method{round}{fm}(x) 23 | 24 | \S4method{round}{fmV}(x) 25 | } 26 | \arguments{ 27 | \item{x}{a numeric vector.} 28 | } 29 | \description{ 30 | \code{ceiling} takes a single numeric argument \code{x} and returns 31 | a numeric vector containing the smallest integers not less than 32 | the corresponding elements of \code{x}. 33 | } 34 | \details{ 35 | \code{floor} takes a single numeric argument \code{x} and returns a numeric 36 | vector containing the largest integers not greater than the corresponding 37 | elements of \code{x}. 38 | 39 | \code{round} rounds the values in its first argument to the specified number 40 | of decimal places (default 0). 41 | } 42 | \examples{ 43 | mat <- ceiling(fm.runif.matrix(100, 10)) 44 | mat <- floor(fm.runif.matrix(100, 10)) 45 | mat <- round(fm.runif.matrix(100, 10)) 46 | } 47 | 48 | -------------------------------------------------------------------------------- /man/scale.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{scale} 5 | \alias{scale} 6 | \title{Scaling and Centering of Matrix} 7 | \usage{ 8 | \S4method{scale}{fm}(x, center = TRUE, scale = TRUE) 9 | } 10 | \arguments{ 11 | \item{x}{a FlashR matrix} 12 | 13 | \item{center}{either a logical value or a numeric vector of length equal to 14 | the number of columns of \code{x}.} 15 | 16 | \item{sclae}{either a logical value or a numeric vector of length equal to 17 | the number of columns of \code{x}.} 18 | } 19 | \value{ 20 | a FlashR matrix. 21 | } 22 | \description{ 23 | \code{scale} centers and/or scales the columns of a FlashR matrix. 24 | } 25 | \details{ 26 | The value of \code{center} determines how column centering is 27 | performed. If \code{center} is a numeric vector with length equal to 28 | the number of columns of \code{x}, then each column of \code{x} has the 29 | corresponding value from \code{center} subtracted from it. If \code{center} 30 | is \code{TRUE} then centering is done by subtracting the column means 31 | (omitting \code{NA}s) of \code{x} from their corresponding columns, and if 32 | \code{center} is \code{FALSE}, no centering is done. 33 | 34 | The value of \code{scale} determines how column scaling is performed 35 | (after centering). If \code{scale} is a numeric vector with length 36 | equal to the number of columns of \code{x}, then each column of \code{x} is 37 | divided by the corresponding value from \code{scale}. If \code{scale} is 38 | \code{TRUE} then scaling is done by dividing the (centered) columns of 39 | \code{x} by their standard deviations if \code{center} is \code{TRUE}, 40 | and the root mean square otherwise. If \code{scale} is \code{FALSE}, 41 | no scaling is done. 42 | 43 | The root-mean-square for a (possibly centered) column is defined 44 | as sqrt(sum(x^2)/(n-1)), where x is a vector of the non-missing 45 | values and n is the number of non-missing values. In the case 46 | \code{center = TRUE}, this is the same as the standard deviation, but 47 | in general it is not. 48 | } 49 | \examples{ 50 | mat <- fm.runif.matrix(100, 10) 51 | mat <- scale(mat) 52 | } 53 | \author{ 54 | Da Zheng 55 | } 56 | 57 | -------------------------------------------------------------------------------- /man/sd.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_stats.R 3 | \docType{methods} 4 | \name{sd} 5 | \alias{sd} 6 | \alias{sd,fm-method} 7 | \alias{sd,fmV-method} 8 | \title{Standard Deviation} 9 | \usage{ 10 | \S4method{sd}{fm}(x, na.rm = FALSE) 11 | 12 | \S4method{sd}{fmV}(x, na.rm = FALSE) 13 | } 14 | \arguments{ 15 | \item{x}{a FlashR vector or matrix.} 16 | 17 | \item{na.rm}{logical. Should missing values be removed?} 18 | } 19 | \description{ 20 | This function computes the standard deviation of the values in \code{x}. 21 | If \code{na.rm} is \code{TRUE} then missing values are removed before 22 | computation proceeds. 23 | } 24 | \examples{ 25 | mat <- fm.runif.matrix(100, 10) 26 | sd(mat) 27 | } 28 | 29 | -------------------------------------------------------------------------------- /man/sum.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{sum} 5 | \alias{fm.sum} 6 | \alias{sum} 7 | \alias{sum,fm-method} 8 | \alias{sum,fmV-method} 9 | \title{Sum of Vector Elements} 10 | \usage{ 11 | fm.sum(x, lazy = FALSE) 12 | 13 | \S4method{sum}{fm}(x, ..., na.rm = FALSE) 14 | 15 | \S4method{sum}{fmV}(x, ..., na.rm = FALSE) 16 | } 17 | \arguments{ 18 | \item{x}{a FlashR vector or matrix.} 19 | 20 | \item{lazy}{indicates whether or not to evaluate it lazily.} 21 | 22 | \item{...}{zero or more vectors or matrices.} 23 | 24 | \item{na.rm}{logical. Should missing values (including \code{NaN}) be removed?} 25 | } 26 | \value{ 27 | The sum. 28 | } 29 | \description{ 30 | \code{sum} returns the sum of all the values in its arguments. 31 | \code{fm.sum} returns the sum of all the values in the input object. It can 32 | evaluate the summation lazily. 33 | } 34 | \examples{ 35 | mat <- fm.runif.matrix(100, 10) 36 | sum(mat) 37 | fm.sum(mat) 38 | } 39 | 40 | -------------------------------------------------------------------------------- /man/summary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{summary} 5 | \alias{.summary} 6 | \alias{summary} 7 | \alias{summary,fm-method} 8 | \alias{summary,fmV-method} 9 | \title{FlashR Summaries} 10 | \usage{ 11 | .summary(x) 12 | 13 | \S4method{summary}{fm}(object, ...) 14 | 15 | \S4method{summary}{fmV}(object, ...) 16 | } 17 | \arguments{ 18 | \item{x}{a FlashR vector or matrix.} 19 | } 20 | \value{ 21 | A list containing the following named components: 22 | \itemize{ 23 | \item{min}{The minimum value} 24 | \item{max}{The maximum value} 25 | \item{mean}{The average} 26 | \item{normL1}{The L1 norm} 27 | \item{normL2}{The L2 norm} 28 | \item{numNonzeros}{The number of non-zero values} 29 | } 30 | } 31 | \description{ 32 | \code{summary} produces summaries of a FlashR object. 33 | } 34 | \details{ 35 | It computes the min, max, sum, mean, L1, L2, number of non-zero values if 36 | the argument is a vector, or these statistics for each column if the argument 37 | is a matrix. 38 | } 39 | \examples{ 40 | mat <- fm.runif.matrix(100, 10) 41 | summary(mat) 42 | } 43 | 44 | -------------------------------------------------------------------------------- /man/svd.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/SVD.R 3 | \docType{methods} 4 | \name{svd} 5 | \alias{fm.svd} 6 | \alias{svd} 7 | \alias{svd,fm-method} 8 | \title{Compute the singular-value decomposition on a large matrix.} 9 | \usage{ 10 | fm.svd(x, nu = min(n, p), nv = min(n, p), tol = 1e-08) 11 | 12 | \S4method{svd}{fm}(x, nu = min(n, p), nv = min(n, p), LINPACK = FALSE) 13 | } 14 | \arguments{ 15 | \item{x}{a FlashR matrix} 16 | 17 | \item{nu}{the number of left singluar vectors to be computed.} 18 | 19 | \item{nv}{the number of right singluar vectors to be computed.} 20 | 21 | \item{tol}{Stopping criterion: the relative accuracy of the Ritz value 22 | is considered acceptable if its error is less than 'tol' times its estimated 23 | value. If this is set to zero then machine precision is used.} 24 | } 25 | \value{ 26 | Returns a list with three entries 27 | \item{d}{ max(nu, nv) approximate singular values} 28 | \item{u}{ nu approximate left singular vectors (only when right_only=FALSE)} 29 | \item{v}{ nv approximate right singular vectors} 30 | } 31 | \description{ 32 | The difference between \code{svd} and \code{fm.svd} is that \code{fm.svd} 33 | allows a user-specified tol. \code{svd} computes eigenvalues in machine 34 | precision. 35 | } 36 | \examples{ 37 | mat <- fm.runif.matrix(1000, 100) 38 | res <- fm.svd(mat, nu=10, nv=0) 39 | res <- svd(mat, nu=10, nv=0) 40 | } 41 | \author{ 42 | Da Zheng 43 | } 44 | 45 | -------------------------------------------------------------------------------- /man/sweep.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{sweep} 5 | \alias{sweep} 6 | \title{Sweep out Array Summaries} 7 | \usage{ 8 | \S4method{sweep}{fm}(x, MARGIN, STATS, FUN = "-", check.margin = TRUE, ...) 9 | } 10 | \arguments{ 11 | \item{x}{a FlashR matrix.} 12 | 13 | \item{MARGIN}{an integer giving the extent of \code{x} which 14 | correspond to \code{STATS}.} 15 | 16 | \item{STATS}{the summary statistic which is to be swept out.} 17 | 18 | \item{FUN}{the function to be used to carry out the sweep.} 19 | 20 | \item{check.margin}{logical. It's ignored right now.} 21 | 22 | \item{...}{optional arguments to \code{FUN}.} 23 | } 24 | \value{ 25 | A matrix with the same shape as \code{x}, but with the summary 26 | statistics swept out. 27 | } 28 | \description{ 29 | Return an array obtained from an input array by sweeping out a 30 | summary statistic. 31 | } 32 | \examples{ 33 | mat <- fm.runif.matrix(100, 10) 34 | sweep(mat, 1, runif(100)) 35 | } 36 | 37 | -------------------------------------------------------------------------------- /man/transpose.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{transpose} 5 | \alias{t,fm-method} 6 | \alias{t,fmV-method} 7 | \alias{transpose} 8 | \title{Matrix Transpose} 9 | \usage{ 10 | \S4method{t}{fm}(x) 11 | 12 | \S4method{t}{fmV}(x) 13 | } 14 | \arguments{ 15 | \item{x}{a FlashR matrix.} 16 | } 17 | \value{ 18 | a matrix. 19 | } 20 | \description{ 21 | Given a matrix \code{x}, \code{t} returns the transpose of \code{x}. 22 | } 23 | \examples{ 24 | mat <- fm.runif.matrix(100, 10) 25 | t(mat) 26 | } 27 | 28 | -------------------------------------------------------------------------------- /man/typeof.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR_base.R 3 | \docType{methods} 4 | \name{typeof} 5 | \alias{typeof} 6 | \alias{typeof,fm-method} 7 | \alias{typeof,fmV-method} 8 | \title{The Type of an Object} 9 | \usage{ 10 | \S4method{typeof}{fm}(x) 11 | 12 | \S4method{typeof}{fmV}(x) 13 | } 14 | \arguments{ 15 | \item{x}{a FlashR object.} 16 | } 17 | \value{ 18 | A character string. Current values are "logical", "integer", 19 | "double". 20 | } 21 | \description{ 22 | \code{typeof} determines the R type of an FlashR object. 23 | } 24 | \examples{ 25 | mat <- fm.runif.matrix(100, 10) 26 | typeof(mat) 27 | } 28 | 29 | -------------------------------------------------------------------------------- /man/vector.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FlashR.R 3 | \docType{methods} 4 | \name{vector} 5 | \alias{as.vector,fm-method} 6 | \alias{as.vector,fmV-method} 7 | \alias{fm.as.vector} 8 | \alias{fm.is.vector} 9 | \alias{vector} 10 | \title{Vector} 11 | \usage{ 12 | fm.as.vector(obj) 13 | 14 | \S4method{as.vector}{fmV}(x) 15 | 16 | \S4method{as.vector}{fm}(x) 17 | 18 | fm.is.vector(x) 19 | } 20 | \arguments{ 21 | \item{obj}{an object} 22 | 23 | \item{x}{a FlashR vector} 24 | } 25 | \value{ 26 | a FlashR vector 27 | } 28 | \description{ 29 | \code{fm.as.vector} converts an object to a FlashR vector. 30 | \code{as.vector} converts a FlashR vector to an R vector. 31 | \code{fm.is.vector} test whether the input argument is a FlashR vector. 32 | } 33 | \details{ 34 | Right now, \code{fm.as.vector} can only convert a matrix with only one row 35 | or one column. Otherwise, the function returns NULL. 36 | } 37 | \examples{ 38 | vec <- fm.as.vector(runif(100)) # Convert an R vector to a FlashR vector. 39 | vec <- as.vector(fm.runif(100)) # Convert a FlashR vector to an R vector. 40 | res <- fm.is.vector(vec) # Test if an object is a FlashR vector. 41 | } 42 | 43 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | FlashR is an R package that accelerate the existing R matrix functions to process 2 | tera-scale datasets at the lightning speed. 3 | FlashR overrides many R matrix functions in the R "base" package so that users 4 | can execute many existing R code in FlashR with no or little modification. 5 | FlashR parallelizes all matrix operations automatically and scales to large datasets 6 | by storing matrices on solid-state drives (SSDs). 7 | It executes many matrix operations together to achieve performance comparable 8 | to optimized C implementations. 9 | 10 | ## Installation 11 | 12 | To install from Github directly, 13 | ``` 14 | git clone --recursive https://github.com/flashxio/FlashR.git 15 | cd FlashR 16 | R CMD build . 17 | R CMD INSTALL FlashR_0.1-0.tar.gz 18 | ``` 19 | 20 | To install from the tar file directly, 21 | ``` 22 | R -e "install.packages("https://github.com/flashxio/FlashR/releases/download/FlashR-latest/FlashR.tar.gz", repos=NULL)" 23 | ``` 24 | However, the tar file may contain a less up-to-date version. 25 | 26 | **Note: FlashR relies on some Linux and R packages.** Please follow the instructions 27 | [here](https://flashxio.github.io/FlashX-doc/FlashX-Quick-Start-Guide.html) 28 | for more details of installing FlashR. 29 | 30 | ## Documentation 31 | 32 | The [programming tutorial](https://github.com/icoming/FlashX/wiki/FlashR-programming-tutorial) 33 | shows all of the features in FlashR. 34 | 35 | Please visit http://flashx.io/ for more documentation. 36 | -------------------------------------------------------------------------------- /src/Makevars: -------------------------------------------------------------------------------- 1 | # The absolute path of the directory where Rcpp header files are stored. 2 | ifndef RCPP_INCLUDE 3 | RCPP_INCLUDE = . 4 | endif 5 | # The absolute path of the directory where FlashGraph source code is. 6 | ifndef FG_DIR 7 | FG_DIR = . 8 | endif 9 | # The absolute path of the directory where FlashGraph is built. 10 | ifndef FG_LIB 11 | FG_LIB = $(FG_DIR)/build 12 | endif 13 | 14 | #BOOST_LOG=1 15 | OMP_FLAG = -fopenmp 16 | PKG_LIBS = -L$(FG_LIB)/matrix -lFMatrix 17 | PKG_LIBS += -L$(FG_LIB)/libsafs -lsafs 18 | # TODO how do we make aio and numa optional? 19 | PKG_LIBS += $(OMP_FLAG) -lpthread -rdynamic -lrt -lz -laio 20 | 21 | ifdef ENABLE_TRILINOS 22 | PKG_LIBS += -L$(FG_LIB)/matrix/eigensolver -leigen 23 | PKG_LIBS += -lteuchoscomm -lteuchosnumerics -lteuchosparameterlist -lteuchoscore -lanasazi 24 | endif 25 | 26 | ifdef ENABLE_NUMA 27 | PKG_LIBS += -lhwloc -lnuma 28 | endif 29 | 30 | ifdef BOOST_LOG 31 | PKG_LIBS += -lboost_log 32 | endif 33 | PKG_CXXFLAGS = -g -O3 -I. -Wall -fPIC -std=c++0x -DBOOST_LOG_DYN_LINK 34 | PKG_CXXFLAGS += -I$(FG_DIR)/libsafs -I$(FG_DIR)/flash-graph -I$(FG_DIR)/matrix 35 | PKG_CXXFLAGS += -I. -I$(RCPP_INCLUDE) $(OMP_FLAG) 36 | ifdef ENABLE_TRILINOS 37 | PKG_CXXFLAGS += -DENABLE_TRILINOS 38 | endif 39 | ifdef FG_EIGEN 40 | PKG_CXXFLAGS += -DUSE_EIGEN 41 | endif 42 | ifdef ENABLE_PROFILER 43 | PKG_LIBS += -lprofiler 44 | PKG_CXXFLAGS += -DUSE_PROFILER 45 | endif 46 | PKG_CPPFLAGS = $(CXXFLAGS) 47 | -------------------------------------------------------------------------------- /src/Makevars.in: -------------------------------------------------------------------------------- 1 | PKG_CFLAGS=-DUSING_R -I. -IFlashX/libsafs -IFlashX/matrix \ 2 | @CPPFLAGS@ @CFLAGS@ -DNDEBUG -DBOOST_LOG_DYN_LINK @HWLOC_DEF@ @AIO_DEF@ @NUMA_DEF@ -fopenmp \ 3 | -DPACKAGE_VERSION=\"@PACKAGE_VERSION@\" 4 | PKG_CXXFLAGS= -DUSING_R -I. -IFlashX/libsafs -IFlashX/matrix \ 5 | @CPPFLAGS@ @CFLAGS@ -DNDEBUG -DBOOST_LOG_DYN_LINK @HWLOC_DEF@ @AIO_DEF@ @NUMA_DEF@ -fopenmp \ 6 | -DPACKAGE_VERSION=\"@PACKAGE_VERSION@\" -std=c++0x 7 | PKG_LIBS=$(LAPACK_LIBS) $(BLAS_LIBS) @PTHREAD_LIB@ @AIO_LIB@ @HWLOC_LIB@ @NUMA_LIB@ 8 | 9 | all: $(SHLIB) 10 | -------------------------------------------------------------------------------- /src/Rconn.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Open Connectome Project (http://openconnecto.me) 3 | * Written by Da Zheng (zhengda1936@gmail.com) 4 | * 5 | * This file is part of FlashMatrix. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | const char *R_GetConnName(Rconnection conn) 24 | { 25 | return conn->description; 26 | } 27 | -------------------------------------------------------------------------------- /src/Rconn.h: -------------------------------------------------------------------------------- 1 | #ifndef __FLASHR_RCONN_H__ 2 | #define __FLASHR_RCONN_H__ 3 | 4 | /* 5 | * Copyright 2017 Open Connectome Project (http://openconnecto.me) 6 | * Written by Da Zheng (zhengda1936@gmail.com) 7 | * 8 | * This file is part of FlashMatrix. 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | extern "C" { 24 | 25 | struct Rconn; 26 | typedef struct Rconn *Rconnection; 27 | 28 | Rconnection R_GetConnection(SEXP); 29 | size_t R_ReadConnection(Rconnection conn, void *buf, size_t n); 30 | const char *R_GetConnName(Rconnection conn); 31 | 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | /* src/config.h. Generated from config.h.in by configure. */ 2 | -------------------------------------------------------------------------------- /src/config.h.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flashxio/FlashR/e1ad845f736752b559241bdacd5bcd77fbc36915/src/config.h.in -------------------------------------------------------------------------------- /src/fmr_isna.h: -------------------------------------------------------------------------------- 1 | // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- 2 | /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ 3 | // 4 | // na.h: Rcpp R/C++ interface class library -- optimized na checking 5 | // 6 | // Copyright (C) 2012-2014 Dirk Eddelbuettel, Romain Francois, Kevin Ushey 7 | // and Da Zheng 8 | // 9 | // This file is part of Rcpp. 10 | // 11 | // Rcpp is free software: you can redistribute it and/or modify it 12 | // under the terms of the GNU General Public License as published by 13 | // the Free Software Foundation, either version 2 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // Rcpp is distributed in the hope that it will be useful, but 17 | // WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU General Public License 22 | // along with Rcpp. If not, see . 23 | 24 | #include 25 | #include 26 | 27 | #ifdef RCPP_HAS_LONG_LONG_TYPES 28 | 29 | BOOST_STATIC_ASSERT_MSG(sizeof(rcpp_ulong_long_type) == sizeof(double), 30 | "unsigned long long and double have same size"); 31 | 32 | // motivation: on 32bit architectures, we only see 'LargeNA' 33 | // as defined ahead; on 64bit architectures, R defaults to 34 | // 'SmallNA' for R_NaReal, but this can get promoted to 'LargeNA' 35 | // if a certain operation can create a 'signalling' NA, e.g. NA_real_+1 36 | static const rcpp_ulong_long_type SmallNA = 0x7FF00000000007A2; 37 | static const rcpp_ulong_long_type LargeNA = 0x7FF80000000007A2; 38 | 39 | struct NACanChange { 40 | enum { value = sizeof(void*) == 8 }; 41 | }; 42 | 43 | template 44 | bool FM_IsNA__impl(const rcpp_ulong_long_type *x); 45 | 46 | template <> 47 | inline bool FM_IsNA__impl(const rcpp_ulong_long_type *x) { 48 | return *x == SmallNA || *x == LargeNA; 49 | } 50 | 51 | template <> 52 | inline bool FM_IsNA__impl(const rcpp_ulong_long_type *x) { 53 | return *x == LargeNA; 54 | } 55 | 56 | inline bool FM_IsNA(const rcpp_ulong_long_type *x) { 57 | return FM_IsNA__impl< NACanChange::value >(x); 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/fmr_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Open Connectome Project (http://openconnecto.me) 3 | * Written by Da Zheng (zhengda1936@gmail.com) 4 | * 5 | * This file is part of FlashMatrix. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | #include 21 | 22 | #include "data_frame.h" 23 | #include "mem_matrix_store.h" 24 | #include "sparse_matrix.h" 25 | #include "factor.h" 26 | 27 | #include "fmr_utils.h" 28 | 29 | using namespace fm; 30 | 31 | /* 32 | * Clean up a sparse matrix. 33 | */ 34 | static void fm_clean_SpM(SEXP p) 35 | { 36 | object_ref *ref 37 | = (object_ref *) R_ExternalPtrAddr(p); 38 | delete ref; 39 | } 40 | 41 | /* 42 | * Clean up a dense matrix 43 | */ 44 | static void fm_clean_DM(SEXP p) 45 | { 46 | object_ref *ref 47 | = (object_ref *) R_ExternalPtrAddr(p); 48 | delete ref; 49 | } 50 | 51 | static inline Rcpp::String trans_RType2Str(R_type type) 52 | { 53 | if (type == R_type::R_INT) 54 | return Rcpp::String("integer"); 55 | else if (type == R_type::R_REAL) 56 | return Rcpp::String("double"); 57 | else if (type == R_type::R_LOGICAL) 58 | return Rcpp::String("logical"); 59 | else 60 | return Rcpp::String("unknown"); 61 | } 62 | 63 | SEXP create_FMR_matrix(sparse_matrix::ptr m, R_type type, const std::string &name) 64 | { 65 | if (m == NULL) { 66 | fprintf(stderr, "can't create an empty matrix\n"); 67 | return R_NilValue; 68 | } 69 | 70 | Rcpp::List ret; 71 | ret["name"] = Rcpp::String(name); 72 | ret["type"] = Rcpp::String("sparse"); 73 | ret["ele_type"] = trans_RType2Str(type); 74 | 75 | object_ref *ref = new object_ref(m); 76 | SEXP pointer = R_MakeExternalPtr(ref, R_NilValue, R_NilValue); 77 | R_RegisterCFinalizerEx(pointer, fm_clean_SpM, TRUE); 78 | ret["pointer"] = pointer; 79 | 80 | Rcpp::LogicalVector sym(1); 81 | sym[0] = m->is_symmetric(); 82 | ret["sym"] = sym; 83 | 84 | Rcpp::NumericVector nrow(1); 85 | nrow[0] = m->get_num_rows(); 86 | ret["nrow"] = nrow; 87 | 88 | Rcpp::NumericVector ncol(1); 89 | ncol[0] = m->get_num_cols(); 90 | ret["ncol"] = ncol; 91 | 92 | return ret; 93 | } 94 | 95 | SEXP create_FMR_matrix(dense_matrix::ptr m, R_type type, const std::string &name) 96 | { 97 | if (m == NULL) { 98 | fprintf(stderr, "can't create an empty matrix\n"); 99 | return R_NilValue; 100 | } 101 | 102 | Rcpp::List ret; 103 | ret["name"] = Rcpp::String(name); 104 | ret["type"] = Rcpp::String("dense"); 105 | ret["ele_type"] = trans_RType2Str(type); 106 | 107 | object_ref *ref = new object_ref(m); 108 | SEXP pointer = R_MakeExternalPtr(ref, R_NilValue, R_NilValue); 109 | R_RegisterCFinalizerEx(pointer, fm_clean_DM, TRUE); 110 | ret["pointer"] = pointer; 111 | 112 | Rcpp::NumericVector nrow(1); 113 | nrow[0] = m->get_num_rows(); 114 | ret["nrow"] = nrow; 115 | 116 | Rcpp::NumericVector ncol(1); 117 | ncol[0] = m->get_num_cols(); 118 | ret["ncol"] = ncol; 119 | 120 | return ret; 121 | } 122 | 123 | SEXP create_FMR_vector(detail::vec_store::const_ptr vec, R_type type, 124 | const std::string &name) 125 | { 126 | detail::matrix_store::const_ptr mat = vec->conv2mat(vec->get_length(), 127 | 1, false); 128 | if (mat == NULL) 129 | return R_NilValue; 130 | return create_FMR_vector(dense_matrix::create(mat), type, name); 131 | } 132 | 133 | SEXP create_FMR_vector(dense_matrix::ptr m, R_type type, const std::string &name) 134 | { 135 | if (m == NULL) { 136 | fprintf(stderr, "can't create a vector from an empty matrix\n"); 137 | return R_NilValue; 138 | } 139 | 140 | if (m->get_num_cols() > 1) 141 | m = m->transpose(); 142 | if (m->get_num_cols() > 1) { 143 | fprintf(stderr, 144 | "can't create a vector with a matrix with more than one col\n"); 145 | return R_NilValue; 146 | } 147 | 148 | Rcpp::List ret; 149 | ret["name"] = Rcpp::String(name); 150 | ret["type"] = Rcpp::String("vector"); 151 | ret["ele_type"] = trans_RType2Str(type); 152 | 153 | object_ref *ref = new object_ref(m); 154 | SEXP pointer = R_MakeExternalPtr(ref, R_NilValue, R_NilValue); 155 | R_RegisterCFinalizerEx(pointer, fm_clean_DM, TRUE); 156 | ret["pointer"] = pointer; 157 | 158 | Rcpp::NumericVector len(1); 159 | len[0] = m->get_num_rows(); 160 | ret["len"] = len; 161 | 162 | return ret; 163 | } 164 | 165 | SEXP create_FMR_vector(fm::factor_col_vector::ptr v, R_type type, 166 | const std::string &name) 167 | { 168 | if (v == NULL) { 169 | fprintf(stderr, "can't create a factor vector\n"); 170 | return R_NilValue; 171 | } 172 | 173 | Rcpp::List ret; 174 | ret["name"] = Rcpp::String(name); 175 | ret["type"] = Rcpp::String("vector"); 176 | ret["ele_type"] = Rcpp::String("integer"); 177 | 178 | // The element type of a factor vector is factor_value_t in FlashMatrix. 179 | // FlashR can only handle int or double, so let's cast it into int. 180 | dense_matrix::ptr mat = v->cast_ele_type(get_scalar_type(), true); 181 | object_ref *ref = new object_ref(mat); 182 | SEXP pointer = R_MakeExternalPtr(ref, R_NilValue, R_NilValue); 183 | R_RegisterCFinalizerEx(pointer, fm_clean_DM, TRUE); 184 | ret["pointer"] = pointer; 185 | 186 | Rcpp::NumericVector len(1); 187 | len[0] = v->get_length(); 188 | ret["len"] = len; 189 | 190 | Rcpp::IntegerVector nlevels(1); 191 | nlevels[0] = v->get_num_levels(); 192 | ret["num.levels"] = nlevels; 193 | 194 | auto vals = v->get_uniq_vals(); 195 | if (vals == NULL) 196 | ret["vals"] = R_NilValue; 197 | else 198 | ret["vals"] = create_FMR_vector(vals, type, ""); 199 | auto cnts = v->get_counts(); 200 | if (cnts == NULL) 201 | ret["cnts"] = R_NilValue; 202 | else { 203 | // TODO we might want to use double floating-point to count 204 | // more elements. 205 | auto cnt_vec = vector::create(cnts); 206 | auto cnt_mat = cnt_vec->conv2mat(cnt_vec->get_length(), 1, false); 207 | cnt_mat = cnt_mat->cast_ele_type(get_scalar_type()); 208 | ret["cnts"] = create_FMR_vector(cnt_mat, R_type::R_INT, ""); 209 | } 210 | 211 | return ret; 212 | } 213 | 214 | factor_col_vector::ptr get_factor_vector(const Rcpp::S4 &vec) 215 | { 216 | if (!is_factor_vector(vec)) { 217 | fprintf(stderr, "The S4 object isn't a factor vector\n"); 218 | return factor_col_vector::ptr(); 219 | } 220 | object_ref *ref 221 | = (object_ref *) R_ExternalPtrAddr(vec.slot("pointer")); 222 | dense_matrix::ptr mat = ref->get_object(); 223 | // This should be a column matrix. 224 | assert(mat->get_num_cols() == 1); 225 | size_t num_levels = vec.slot("num.levels"); 226 | return factor_col_vector::create(factor(num_levels), mat); 227 | } 228 | 229 | col_vec::ptr get_vector(const Rcpp::S4 &vec) 230 | { 231 | dense_matrix::ptr mat = get_matrix(vec); 232 | if (mat->get_num_rows() > 1 && mat->get_num_cols() > 1) { 233 | fprintf(stderr, "The input object is a matrix"); 234 | return col_vec::ptr(); 235 | } 236 | return col_vec::create(mat); 237 | } 238 | 239 | SEXP create_FMR_data_frame(data_frame::ptr df, 240 | const std::vector &col_types, const std::string &name) 241 | { 242 | if (col_types.size() != df->get_num_vecs()) { 243 | fprintf(stderr, 244 | "# col types doesn't match with # cols in the data frame\n"); 245 | return R_NilValue; 246 | } 247 | 248 | Rcpp::List ret; 249 | for (size_t i = 0; i < df->get_num_vecs(); i++) { 250 | std::string vec_name = df->get_vec_name(i); 251 | ret[vec_name] = create_FMR_vector(df->get_vec(i), col_types[i], 252 | vec_name); 253 | } 254 | return ret; 255 | } 256 | -------------------------------------------------------------------------------- /src/fmr_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Open Connectome Project (http://openconnecto.me) 3 | * Written by Da Zheng (zhengda1936@gmail.com) 4 | * 5 | * This file is part of FlashMatrix. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | #ifndef __FMR_UTILS_H__ 21 | #define __FMR_UTILS_H__ 22 | 23 | #include 24 | #include 25 | 26 | #include "rutils.h" 27 | 28 | namespace fm 29 | { 30 | class col_vec; 31 | class factor_col_vector; 32 | class dense_matrix; 33 | class sparse_matrix; 34 | 35 | namespace detail 36 | { 37 | class vec_store; 38 | } 39 | } 40 | 41 | template 42 | class object_ref 43 | { 44 | typename ObjectType::ptr o; 45 | public: 46 | object_ref(typename ObjectType::ptr o) { 47 | this->o = o; 48 | } 49 | 50 | typename ObjectType::ptr get_object() const { 51 | return o; 52 | } 53 | 54 | void set_object(typename ObjectType::ptr obj) { 55 | this->o = obj; 56 | } 57 | }; 58 | 59 | template 60 | typename MatrixType::ptr get_matrix(const Rcpp::S4 &matrix) 61 | { 62 | // TODO I should test if the pointer slot does exist. 63 | object_ref *ref 64 | = (object_ref *) R_ExternalPtrAddr(matrix.slot("pointer")); 65 | return ref->get_object(); 66 | } 67 | template 68 | void set_matrix(const Rcpp::S4 &matrix, typename MatrixType::ptr mat) 69 | { 70 | // TODO I should test if the pointer slot does exist. 71 | object_ref *ref 72 | = (object_ref *) R_ExternalPtrAddr(matrix.slot("pointer")); 73 | ref->set_object(mat); 74 | } 75 | 76 | std::shared_ptr get_vector(const Rcpp::S4 &vec); 77 | std::shared_ptr get_factor_vector(const Rcpp::S4 &vec); 78 | 79 | SEXP create_FMR_vector(std::shared_ptr vec, 80 | R_type type, const std::string &name); 81 | SEXP create_FMR_vector(std::shared_ptr m, 82 | R_type type, const std::string &name); 83 | SEXP create_FMR_vector(std::shared_ptr v, 84 | R_type type, const std::string &name); 85 | SEXP create_FMR_matrix(std::shared_ptr m, 86 | R_type type, const std::string &name); 87 | SEXP create_FMR_matrix(std::shared_ptr m, 88 | R_type type, const std::string &name); 89 | SEXP create_FMR_data_frame(std::shared_ptr df, 90 | const std::vector &type, const std::string &name); 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /src/matrix_ops.h: -------------------------------------------------------------------------------- 1 | #ifndef __MATRIX_OPS_H__ 2 | #define __MATRIX_OPS_H__ 3 | 4 | /* 5 | * Copyright 2015 Open Connectome Project (http://openconnecto.me) 6 | * Written by Da Zheng (zhengda1936@gmail.com) 7 | * 8 | * This file is part of FlashMatrix. 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include 23 | 24 | #include 25 | 26 | #include "bulk_operate.h" 27 | #include "bulk_operate_ext.h" 28 | #include "rutils.h" 29 | 30 | namespace fm 31 | { 32 | class dense_matrix; 33 | } 34 | 35 | namespace fmr 36 | { 37 | 38 | /* 39 | * Register a binary UDF. 40 | * A user has to provide UDFs for all different types. 41 | */ 42 | void register_udf(const std::vector &ops, 43 | const std::string &name); 44 | /* 45 | * Register a unary UDF. 46 | * A user has to provide UDFs for all different types. 47 | */ 48 | void register_udf(const std::vector &ops, 49 | const std::string &name); 50 | /* 51 | * This registers more UDFs provided by FlashMatrix, which aren't basic UDFs. 52 | */ 53 | void init_udf_ext(); 54 | 55 | /* 56 | * We get an operator based on the operation and the element type of the input 57 | * operands. These operations will output an operator for the input type and 58 | * the output type. The reason that we need to give an output type is that 59 | * R stores both logical values and integers in C integers and FlashMatrix 60 | * `operate' isn't sufficient to carry the type information. 61 | * 62 | * Get a binary operator. 63 | * Even though a binary operator takes two inputs, FlashR always first casts 64 | * the type of one input to match the other. So we assume that all binary 65 | * operators take inputs of the same type. 66 | */ 67 | std::pair get_op(SEXP pfun, R_type type); 68 | /* Get a unary operator. */ 69 | std::pair get_uop(SEXP pfun, R_type type); 70 | /* This construct an aggregation operator from binary operators. */ 71 | std::pair get_agg_op(SEXP pfun, 72 | R_type type); 73 | std::pair get_apply_op(SEXP pfun, 74 | R_type type); 75 | 76 | /* 77 | * This casts the elements of a dense matrix from `in_type' to `out_type'. 78 | * The main reason that we need this is that we need to handle NA correctly 79 | * when casting element types in R. 80 | */ 81 | std::shared_ptr cast_Rtype(std::shared_ptr mat, 82 | R_type in_type, R_type out_type); 83 | 84 | typedef int op_id_t; 85 | 86 | /* Get the binary operator Id given a name. */ 87 | op_id_t get_op_id(const std::string &name); 88 | /* Get the unary operator Id given a name. */ 89 | op_id_t get_uop_id(const std::string &name); 90 | 91 | void init_apply_ops(); 92 | 93 | } 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /src/rutils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Open Connectome Project (http://openconnecto.me) 3 | * Written by Da Zheng (zhengda1936@gmail.com) 4 | * 5 | * This file is part of FlashR. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | #include 21 | 22 | /* 23 | * We need to implement these two functions here because Rinternals.h masses 24 | * up with other C++ header files. 25 | */ 26 | 27 | bool R_is_real(SEXP v) 28 | { 29 | return isReal(v); 30 | } 31 | 32 | bool R_is_integer(SEXP v) 33 | { 34 | return isInteger(v); 35 | } 36 | 37 | bool R_is_logical(SEXP v) 38 | { 39 | return isLogical(v); 40 | } 41 | 42 | bool R_is_null(SEXP v) 43 | { 44 | return isNull(v); 45 | } 46 | 47 | bool R_is_string(SEXP v) 48 | { 49 | return isString(v); 50 | } 51 | 52 | bool R_is_list(SEXP v) 53 | { 54 | return isList(v); 55 | } 56 | 57 | bool R_is_vector(SEXP v) 58 | { 59 | return isVector(v); 60 | } 61 | 62 | void R_gc() 63 | { 64 | SEXP call = PROTECT(lang1(install("gc"))); 65 | PROTECT(eval(call, R_GlobalEnv)); 66 | UNPROTECT(2); 67 | } 68 | 69 | SEXP R_create_s4fm(SEXP fm) 70 | { 71 | SEXP create_fm = PROTECT(lang2(install("new_fm"), fm)); 72 | return PROTECT(eval(create_fm, R_GlobalEnv)); 73 | } 74 | 75 | size_t get_nrows(SEXP o) 76 | { 77 | return nrows(o); 78 | } 79 | 80 | size_t get_ncols(SEXP o) 81 | { 82 | return ncols(o); 83 | } 84 | 85 | size_t get_length(SEXP o) 86 | { 87 | return length(o); 88 | } 89 | -------------------------------------------------------------------------------- /src/rutils.h: -------------------------------------------------------------------------------- 1 | #ifndef __R_UTILS_H__ 2 | #define __R_UTILS_H__ 3 | 4 | /* 5 | * Copyright 2014 Open Connectome Project (http://openconnecto.me) 6 | * Written by Da Zheng (zhengda1936@gmail.com) 7 | * 8 | * This file is part of FlashR. 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #include 24 | 25 | #include 26 | 27 | bool R_is_real(SEXP v); 28 | bool R_is_integer(SEXP v); 29 | bool R_is_logical(SEXP v); 30 | bool R_is_null(SEXP v); 31 | bool R_is_string(SEXP v); 32 | bool R_is_list(SEXP v); 33 | bool R_is_vector(SEXP v); 34 | 35 | enum R_type 36 | { 37 | R_LOGICAL, 38 | R_INT, 39 | R_REAL, 40 | R_NTYPES, 41 | }; 42 | 43 | static inline R_type get_common_Rtype(R_type left, R_type right) 44 | { 45 | // For the order we list the R types, we should cast types 46 | // to the one with a larger value. 47 | return (R_type) std::max((int) left, (int) right); 48 | } 49 | 50 | static inline R_type R_get_type(SEXP v) 51 | { 52 | if (R_is_real(v)) 53 | return R_type::R_REAL; 54 | else if (R_is_integer(v)) 55 | return R_type::R_INT; 56 | else if (R_is_logical(v)) 57 | return R_type::R_LOGICAL; 58 | else { 59 | fprintf(stderr, "The R object has unknown type\n"); 60 | return R_type::R_NTYPES; 61 | } 62 | } 63 | 64 | size_t get_nrows(SEXP o); 65 | size_t get_ncols(SEXP o); 66 | size_t get_length(SEXP o); 67 | 68 | template 69 | bool R_get_number(SEXP v, T &ret) { 70 | if (R_is_real(v)) { 71 | ret = REAL(v)[0]; 72 | return true; 73 | } 74 | else if (R_is_integer(v)) { 75 | ret = INTEGER(v)[0]; 76 | return true; 77 | } 78 | else if (R_is_logical(v)) { 79 | ret = LOGICAL(v)[0]; 80 | return true; 81 | } 82 | else 83 | return false; 84 | } 85 | 86 | /* 87 | * Test if this is a sparse matrix. 88 | */ 89 | static inline bool is_sparse(const Rcpp::S4 &matrix) 90 | { 91 | std::string type = matrix.slot("type"); 92 | return type == "sparse"; 93 | } 94 | 95 | static inline bool is_vector(const Rcpp::S4 &vec) 96 | { 97 | return vec.is("fmV"); 98 | } 99 | 100 | static inline bool is_factor_vector(const Rcpp::S4 &vec) 101 | { 102 | return vec.is("fmVFactor"); 103 | } 104 | 105 | void R_gc(); 106 | SEXP R_create_s4fm(SEXP fm); 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(FlashR) 3 | 4 | ret <- test_file("inst/tests/test_dense.R") 5 | msgs <- capture.output(ret) 6 | tests <- length(msgs) / 3 7 | fails <- sum(as.integer(sapply(strsplit(msgs[(tests+2):(2*tests)], " +"), 8 | function(x) x[length(x)-1]))) 9 | q(status=fails) 10 | --------------------------------------------------------------------------------