In [1]:
from __future__ import print_function
import numpy as np
np.random.seed(1)
import scipy.stats
import sys
import cProfile
%reload_ext memory_profiler
%reload_ext cythonmagic
# dev imports
import anhima.opt.ld
sys.path.insert(0, '../src')
%reload_ext autoreload
%autoreload 1
%aimport anhima.sim
%aimport anhima.gt
%aimport anhima.ld

In [2]:
n_variants = 10000
n_samples = 100
gn = anhima.sim.simulate_genotypes_with_ld(n_variants, n_samples, correlation=.97).astype('u1')

In [3]:
included2 = anhima.ld.ld_prune_pairwise(gn)
np.count_nonzero(included2)


Out[3]:
370

In [4]:
%timeit anhima.ld.ld_prune_pairwise(gn)


10 loops, best of 3: 43.5 ms per loop

In [5]:
%memit anhima.ld.ld_prune_pairwise(gn)


peak memory: 74.63 MiB, increment: 0.20 MiB

In [6]:
cProfile.run('anhima.ld.ld_prune_pairwise(gn)', sort='time')


         34 function calls in 0.054 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.053    0.053    0.054    0.054 {anhima.opt.ld.ld_prune_pairwise_uint8}
        1    0.001    0.001    0.001    0.001 {numpy.core._dotblas.dot}
        1    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.ndarray' objects}
        1    0.000    0.000    0.001    0.001 function_base.py:1649(cov)
        1    0.000    0.000    0.001    0.001 function_base.py:1769(corrcoef)
        1    0.000    0.000    0.000    0.000 {method 'reduce' of 'numpy.ufunc' objects}
        5    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
        1    0.000    0.000    0.000    0.000 _methods.py:49(_mean)
        1    0.000    0.000    0.000    0.000 {method 'outer' of 'numpy.ufunc' objects}
        1    0.000    0.000    0.054    0.054 ld.py:237(ld_prune_pairwise)
        3    0.000    0.000    0.000    0.000 numeric.py:392(asarray)
        1    0.000    0.000    0.000    0.000 {numpy.core.multiarray.copyto}
        1    0.000    0.000    0.000    0.000 twodim_base.py:221(diag)
        1    0.000    0.000    0.000    0.000 numeric.py:136(ones)
        1    0.000    0.000    0.000    0.000 {numpy.core.multiarray.empty}
        1    0.000    0.000    0.000    0.000 {method 'diagonal' of 'numpy.ndarray' objects}
        1    0.000    0.000    0.054    0.054 <string>:1(<module>)
        1    0.000    0.000    0.000    0.000 {method 'mean' of 'numpy.ndarray' objects}
        1    0.000    0.000    0.000    0.000 _methods.py:39(_count_reduce_items)
        2    0.000    0.000    0.000    0.000 {isinstance}
        1    0.000    0.000    0.000    0.000 numeric.py:462(asanyarray)
        1    0.000    0.000    0.000    0.000 {issubclass}
        2    0.000    0.000    0.000    0.000 {len}
        1    0.000    0.000    0.000    0.000 {method 'squeeze' of 'numpy.ndarray' objects}
        1    0.000    0.000    0.000    0.000 {method 'conj' of 'numpy.ndarray' objects}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}



In [10]: