Split dimension into two integers whose product it is, as close to equal (or to factor) as possible.
Parameters
dimensionintThe number to factor.
factorint= -1If 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))