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

QuantEcon / QuantEcon.py / 18963651100 / 3
93%
main: 93%

Build:
DEFAULT BRANCH: main
Ran 31 Oct 2025 05:31AM UTC
Files 162
Run time 5s
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.3

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>

7708 of 8326 relevant lines covered (92.58%)

0.93 hits per line

Source Files on job 18963651100.3
  • Tree
  • List 162
  • Changed 1
  • Source Changed 0
  • Coverage Changed 1
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Build 18963651100
  • 83d3c6c9 on github
  • Prev Job for on main (#18963640808.1)
  • Next Job for on main (#20159736835.2)
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