Skip to content

Commit 417cf38

Browse files
authored
Merge pull request #602 from Smit-create/issue_97
ENH: Vectorize ECDF's `__call__` method
2 parents 680ab74 + 6cc08be commit 417cf38

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

quantecon/ecdf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,7 @@ def __call__(self, x):
4848
Fraction of the sample less than x
4949
5050
"""
51-
return np.mean(self.observations <= x)
51+
def f(a):
52+
return np.mean(self.observations <= a)
53+
vf = np.frompyfunc(f, 1, 1)
54+
return vf(x).astype(float)

quantecon/tests/test_ecdf.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,14 @@ def test_ascending(self):
3030
F_1 = self.ecdf(x)
3131
F_2 = self.ecdf(1.1 * x)
3232
self.assertGreaterEqual(F_2, F_1)
33+
34+
def test_vectorized(self):
35+
"ecdf: testing vectorized __call__ method"
36+
t = np.linspace(-1, 1, 100)
37+
e = self.ecdf(t)
38+
self.assertEqual(t.shape, e.shape)
39+
self.assertEqual(e.dtype, float)
40+
t = np.linspace(-1, 1, 100).reshape(2, 2, 25)
41+
e = self.ecdf(t)
42+
self.assertEqual(t.shape, e.shape)
43+
self.assertEqual(e.dtype, float)

0 commit comments

Comments
 (0)