QuantEcon.py icon indicating copy to clipboard operation
QuantEcon.py copied to clipboard

Vectorize lorenz_curve and gini

Open Smit-create opened this issue 2 years ago • 9 comments

  • Replaced the python loops with vectorized code for enhancing the performance in lorenz_curve and gini_coefficient.

Smit-create avatar Apr 19 '23 11:04 Smit-create

Coverage Status

Coverage: 92.988% (+0.01%) from 92.975% when pulling c448868871e753c2133ebe7db0cdd92a043fb6d3 on Smit-create:opt into eeb0865908da0a7f528ad73e99028b225b8f26d4 on QuantEcon:main.

coveralls avatar Apr 19 '23 11:04 coveralls

Hmm, The tests are already present in https://github.com/QuantEcon/QuantEcon.py/blob/main/quantecon/tests/test_inequality.py so I thought to skip adding them.

Smit-create avatar Apr 22 '23 19:04 Smit-create

Is this adding new features or refactoring the code?

oyamad avatar Apr 23 '23 07:04 oyamad

This is just refactoring the code and removing some for loops for performance optimizations.

Smit-create avatar Apr 23 '23 07:04 Smit-create

@Smit-create It is usually advised to use for loops (and avoid creation of intermediate arrays) in njited functions. Do you have a reason to go against that in this case?

oyamad avatar Apr 24 '23 00:04 oyamad

It is usually advised to use for loops (and avoid creation of intermediate arrays) in njited functions.

I found this better in terms of time performance as this is vectorized version while the extra space complexity (creating new arrays) is still the same for both the functions -- O(n)

Smit-create avatar Apr 24 '23 06:04 Smit-create

@Smit-create thanks for opening this PR.

Would you mind to update the top level comment box with a description of the change and document the performance improvements you mention in this thread so it's clear what this change is about.

mmcky avatar Apr 27 '23 04:04 mmcky

Thanks @mmcky. Done

Smit-create avatar May 05 '23 12:05 Smit-create

@Smit-create I haven't merged this as it isn't clear what level of performance improvement is being made. Is it 2% or 20% for example, it would be helpful to have timings between the different versions to make an assessment here. @oyamad makes a good point around njit so we need a clear reason to change to vectorized code.

mmcky avatar Oct 24 '23 23:10 mmcky