Hi all! I have a large collection (~50,000) of integer vectors in low dimension (~20). For each of these vectors, I want to divide all entries by their gcd. In other words if
def prim_v(v): d = abs(gcd(v)) return v.apply_map(lambda vi: vi.divide_knowing_divisible_by(d)) then I want to compute map(prim_v, V) for a long list V. When trying to profile this using %prun, I found it difficult to tell which part of this computation is taking the most time. So I rewrote this as def foo(v,d): return v.divide_knowing_divisible_by(d) def bar(v): return abs(gcd(v)) def prim_v(v): d = bar(v) return v.apply_map(lambda vi: foo(vi,d)) Then, profiling this with %prun yields the following information. ncalls tottime percall cumtime percall filename:lineno(function) 47802 0.119 0.000 13.811 0.000 LDsolver.py:58(prim_v) 47802 0.116 0.000 3.593 0.000 LDsolver.py:54(bar) 859898 0.360 0.000 0.524 0.000 LDsolver.py:51(foo) If I am reading this correctly, this means that most of the time (~10 seconds) is not spent doing the actual computation (using foo and bar) but simply creating vectors and read/writing values to/from vectors (in apply_map). (Do something like return vector((foo(vi,d) for vi in v)) instead of apply_map does not make much a difference.) Now, my questions are: 1) Why is this so slow? Am I missing something here? 2) Is there anything I can do to improve performance? Thank you very much, Felix -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/groups/opt_out.