Skip to content

Commit

Permalink
Docstring factorize
Browse files Browse the repository at this point in the history
  • Loading branch information
JorisVincent committed Dec 19, 2022
1 parent 396ad39 commit 95e53df
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion stimuli/utils/utils.py
Expand Up @@ -64,11 +64,29 @@ def to_img(array, save):


def int_factorize(n):
factors = {1}
"""All integer factors of integer n
All integer factors, i.e., all integers that n is integer-divisible by.
Also not a very efficient algorithm (brute force trial division),
so should only be used as a helpter function.
Parameters
----------
n : int
number to factorize
Returns
-------
set
set of all integer factors of n
"""

factors = {1} # set, guarantees unique factors
for i in range(2, int(np.sqrt(n)) + 1):
if n % i == 0:
# N is divisible by i...
factors.add(i)
# ...thus also divisible by n/i
factors.add(n // i)

return factors

0 comments on commit 95e53df

Please sign in to comment.