• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

QuantEcon / QuantEcon.py / 18963651100
93%

Build:
DEFAULT BRANCH: main
Ran 31 Oct 2025 05:31AM UTC
Jobs 3
Files 162
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

31 Oct 2025 05:27AM UTC coverage: 92.577% (-0.002%) from 92.579%
18963651100

push

github

web-flow
Optimize draw (#811)

The key optimization replaces a Python loop with vectorized NumPy operations in the `draw` function's multiple sample case.

**What changed:**
- Replaced the explicit Python loop `for i in range(size): out[i] = searchsorted(cdf, rs[i])` with a single vectorized call: `out = np.searchsorted(cdf, rs, side='right')`
- Removed the separate `np.empty` allocation since `np.searchsorted` returns the output array directly

**Why this is faster:**
The original code performs `size` individual calls to the custom `searchsorted` function in Python, each requiring loop overhead and function call overhead. The optimized version leverages NumPy's highly optimized C implementation that processes the entire array in one operation, eliminating Python loop overhead entirely.

**Performance characteristics:**
- Massive speedups for large sample sizes (857% faster for 1000 samples, 934% for 500 samples)  
- Modest improvements for small sample sizes (35-40% faster for 10-100 samples)
- Single draws remain unchanged, preserving the custom implementation's behavior
- Edge cases like `size=0` show slight regression due to NumPy's overhead for empty arrays, but these are uncommon scenarios

The optimization is most effective when `size` is an integer (vectorizable case), while preserving the original behavior for single draws and non-integer sizes.

Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com>

1 of 1 new or added line in 1 file covered. (100.0%)

7708 of 8326 relevant lines covered (92.58%)

2.78 hits per line

Jobs
ID Job ID Ran Files Coverage
1 18963651100.1 31 Oct 2025 05:31AM UTC 162
92.58
GitHub Action Run
2 18963651100.2 31 Oct 2025 05:31AM UTC 162
92.58
GitHub Action Run
3 18963651100.3 31 Oct 2025 05:31AM UTC 162
92.58
GitHub Action Run
Source Files on build 18963651100
  • Tree
  • List 162
  • Changed 1
  • Source Changed 0
  • Coverage Changed 1
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Repo
  • 83d3c6c9 on github
  • Prev Build on main (#18963640808)
  • Next Build on main (#20159736835)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc