Skip to content

Commit

Permalink
Merge pull request #602 from Smit-create/issue_97
Browse files Browse the repository at this point in the history
ENH: Vectorize ECDF's `__call__` method
  • Loading branch information
jstac committed Feb 22, 2022
2 parents 680ab74 + 6cc08be commit 417cf38
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion quantecon/ecdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ def __call__(self, x):
Fraction of the sample less than x
"""
return np.mean(self.observations <= x)
def f(a):
return np.mean(self.observations <= a)
vf = np.frompyfunc(f, 1, 1)
return vf(x).astype(float)
11 changes: 11 additions & 0 deletions quantecon/tests/test_ecdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@ def test_ascending(self):
F_1 = self.ecdf(x)
F_2 = self.ecdf(1.1 * x)
self.assertGreaterEqual(F_2, F_1)

def test_vectorized(self):
"ecdf: testing vectorized __call__ method"
t = np.linspace(-1, 1, 100)
e = self.ecdf(t)
self.assertEqual(t.shape, e.shape)
self.assertEqual(e.dtype, float)
t = np.linspace(-1, 1, 100).reshape(2, 2, 25)
e = self.ecdf(t)
self.assertEqual(t.shape, e.shape)
self.assertEqual(e.dtype, float)

0 comments on commit 417cf38

Please sign in to comment.