-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: Vectorize ECDF's __call__
method
#602
Conversation
Hello @Smit-create! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2022-02-15 10:45:20 UTC |
__call__
function__call__
method
Hi @Smit-create , many thanks for trying to fix this. What we're looking for is for the following code to execute successfully:
The last line should print the value of Your code still fails this test. I'd be glad if you take another try. |
Thanks for the review! I tried to fix that in some other way. |
Thanks @Smit-create , it's a nice try. I didn't know about that numpy function. There's still a slight problem. I wonder if you can help figure it out. If I run
the output looks good, but the dtype of What do you think about using these methods? https://numba.pydata.org/numba-doc/latest/user/vectorize.html We routinely use numba so it's fine to add it as an import here. |
Oh, I think that's easy to fix. We can use the following diff to fix that: diff --git a/quantecon/ecdf.py b/quantecon/ecdf.py
index 12a2014..647ce7a 100644
--- a/quantecon/ecdf.py
+++ b/quantecon/ecdf.py
@@ -51,4 +51,4 @@ class ECDF:
def f(a):
return np.mean(self.observations <= a)
vf = np.frompyfunc(f, 1, 1)
- return vf(x)
+ return vf(x).astype(np.float) With this above diff I get: >>> import numpy as np
>>> from quantecon import ECDF
>>> obs = np.random.randn(100)
>>> e = ECDF(obs)
>>> t = np.linspace(0, 1, 10)
>>> print(e(t))
[0.49 0.56 0.6 0.65 0.69 0.71 0.75 0.77 0.8 0.83]
>>> e(t)
array([0.49, 0.56, 0.6 , 0.65, 0.69, 0.71, 0.75, 0.77, 0.8 , 0.83])
>>> t
array([0. , 0.11111111, 0.22222222, 0.33333333, 0.44444444,
0.55555556, 0.66666667, 0.77777778, 0.88888889, 1. ])
I am not exactly sure that we need to use |
Excellent job @Smit-create . Many thanks for this (and sorry for the slow response)! |
Thanks for the review! |
Closes #97
cc @jstac