divisorsRcpp: Vectorized Factorization (Complete)

View source: R/NumberTheory.R

divisorsRcppR Documentation

Vectorized Factorization (Complete)

Description

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

Usage

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

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.

Details

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

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.

Note

The maximum value for each element in v is 2^{53} - 1.

Author(s)

Joseph Wood

References

See Also

primeFactorize

Examples

## 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))

RcppAlgos documentation built on Oct. 3, 2023, 1:07 a.m.