Skip to content

Commit

Permalink
fix fastlen?
Browse files Browse the repository at this point in the history
  • Loading branch information
fzimmermann89 committed May 6, 2021
1 parent 50aac29 commit 38d476d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion idi/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import itertools as _it
from functools import lru_cache


def radial_profile(data, center=None, calcStd=False, os=1):
"""
calculates a ND radial profile of data around center. will ignore nans
Expand Down Expand Up @@ -212,7 +213,9 @@ def atleastnd(array, n):
array = _np.array(array)
return array[tuple((n - array.ndim) * [None] + [...])]

@lru_cache

@args2tuple
@lru_cache(maxsize=None)
def fastlen(x, factors=(2, 3, 5, 7, 11)):
"""
return N>=x conisting only of the prime factors given as factors
Expand Down
15 changes: 15 additions & 0 deletions idi/util/funchelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ def asgen_helper(arg, *args, **kw):
def parallel(fn=None):
from collections import deque
import time

try:
from pathos.multiprocessing import Pool
except ImportError:
import warnings

warnings.warn('no pathos available, be careful with parallel decorator and pickling errors.')
from multiprocessing import Pool

Expand Down Expand Up @@ -78,3 +80,16 @@ def chain(*fns):

def group(iterable, n):
return zip(*([iter(iterable)] * n))


def args2tuple(function):
import numpy

def wrapper(*args, **kwargs):
args = [tuple(x) if type(x) == list else x for x in args]
kwargs = {k: tuple(x) if type(x) == list else x for k, x in kwargs.items()}
args = [tuple(x.ravel()) if type(x) == numpy.ndarray else x for x in args]
kwargs = {k: tuple(x.ravel()) if type(x) == numpy.ndarray else x for k, x in kwargs.items()}
return function(*args, **kwargs)

return wrapper

0 comments on commit 38d476d

Please sign in to comment.