Conversation
Removes the np.isfinite(val) and np.all(np.isfinite(grad)) checks from the objective and gradient functions in scipy_solver.py. These checks ran on every solver iteration (10,000+ times) adding measurable overhead. Users encountering inf/nan values will still see them in solver output or get solver failures, which is sufficient feedback.
…tion (#82) Use np.dot() and np.sum() instead of Python's sum() with generator expressions. This enables SIMD optimization and NumPy's optimized C loops for vector operations. Changes: - DotProduct.evaluate: use np.array() + np.dot() - VectorSum.evaluate: use np.array() + np.sum() - VectorExpressionSum.evaluate: use np.array() + np.sum()
Add _NUMBER_SPLIT_RE module-level compiled regex pattern instead of calling re.split() with a pattern string on every sort comparison. Reduces function call overhead in O(N log N) sorting operations.
…84) Initialize _hash = None in Constant, BinaryOp, and UnaryOp __init__ methods. These are the most frequently created expression types and benefit from having the slot pre-initialized. The base __hash__ method keeps the hasattr() check for compatibility with other Expression subclasses (in vectors.py, matrices.py) that don't initialize _hash explicitly.
np.array() construction overhead exceeded computation gains at ALL vector sizes tested (up to n=5000). Python's sum(generator) wins. Profiling showed: - VectorSum n=1000: 111.9us (python) vs 190.5us (numpy) = 1.7x slower - DotProduct n=1000: 267.1us (python) vs 343.9us (numpy) = 1.3x slower True numpy benefits require data staying in numpy arrays (v1.3.0 scope).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Theme: Performance Quick Wins (Patch Release)
This release implements low-risk, high-confidence performance improvements from the PERFORMANCE_BOTTLENECK_REPORT.md, along with a solver selection bug fix and documentation updates.
Changes
Bug Fixes
_auto_select_methodno longer selectsL-BFGS-Bfor constrained problems — falls back toSLSQPinsteadself._hash = NonetoMatrixSum,QuadraticForm, andFrobeniusNorm__init__methodsPerformance (Roadmap Tasks 1-4)
np.isfinitesafety checks from hot solver loopDotProductandVectorSumevaluation withnp.dot/np.fromiter_natural_sort_keyat module level_hash=Nonein all Expression subclasses (9 classes across 3 files)Documentation
Benchmarks
Version Bump
pyproject.toml: 1.2.3 → 1.2.4