QuantEcon.py
QuantEcon.py copied to clipboard
Vectorize lorenz_curve and gini
- Replaced the python loops with vectorized code for enhancing the performance in
lorenz_curveandgini_coefficient.
Coverage: 92.988% (+0.01%) from 92.975% when pulling c448868871e753c2133ebe7db0cdd92a043fb6d3 on Smit-create:opt into eeb0865908da0a7f528ad73e99028b225b8f26d4 on QuantEcon:main.
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.
Is this adding new features or refactoring the code?
This is just refactoring the code and removing some for loops for performance optimizations.
@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?
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 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.
Thanks @mmcky. Done
@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.