Learn R Programming

RcppAlgos (version 2.9.3)

divisorsRcpp: Vectorized Factorization (Complete)

Description

Function for generating the complete factorization for a vector of numbers.

Usage

divisorsRcpp(v, namedList = FALSE, nThreads = NULL)

Value

  • Returns an unnamed vector if length(v) == 1 regardless of the value of namedList. If \(v < 2^{31}\), the class of the returned vector will be integer, otherwise the class will be numeric.

  • If length(v) > 1, a named/unnamed list of vectors will be returned. If max(bound1, bound2) \(< 2^{31}\), the class of each vector will be integer, otherwise the class will be numeric.

Arguments

v

Vector of integers or numeric values. Non-integral values will be coerced to whole numbers.

namedList

Logical flag. If TRUE and the length(v) > 1, a named list is returned. The default is FALSE.

nThreads

Specific number of threads to be used. The default is NULL.

Author

Joseph Wood

Details

Efficient algorithm that builds on primeFactorize to generate the complete factorization of many numbers.

References

See Also

primeFactorize

Examples

Run this code
## Get the complete factorization of a single number
divisorsRcpp(10^8)

## Or get the complete factorization of many numbers
set.seed(29)
myVec <- sample(-1000000:1000000, 1000)
system.time(myFacs <- divisorsRcpp(myVec))

## Return named list
myFacsWithNames <- divisorsRcpp(myVec, namedList = TRUE)

## Using nThreads
system.time(divisorsRcpp(myVec, nThreads = 2))

Run the code above in your browser using DataLab