Skip to content
fn

factorization

→tuple of int
factorization(dimension: int, factor: int = -1)

Split dimension into two integers whose product it is, as close to equal (or to factor) as possible.

Parameters

dimensionint
The number to factor.
factorint= -1
If positive and it divides dimension, the first number is factor. Otherwise the search is for a divisor near the square root (-1) or no larger than factor.

Returns

tuple of int

(m, n) with m * n == dimension and m <= n, unless factor divides dimension (then (factor, dimension // factor) as given).

Examples

>>> from lucid.peft.tuners.lokr import factorization
>>> factorization(256), factorization(128), factorization(127), factorization(128, factor=4)
((16, 16), (8, 16), (1, 127), (4, 32))

Used by 1