Comments (1)
From sympy/simplify/cse_main.py
noting that optimizations=basic includes two things:
basic_optimizations = [(cse_opts.sub_pre, cse_opts.sub_post),
(factor_terms, None)]
Applying both of those individually to the example of (pose.inverse() * point).jacobian(pose)
, jotting down notes:
- SymPy is fewer ops than SymEngine, even without optimizations.
factor_terms
seems to make things slower, both by itself and with the sub optimization.- The sub optimization makes things quite a bit faster. It also doesn't look like it should be slow. This seems like a pretty useful thing to try and implement in C++ and test on more expressions.
Copying what the "sub" optimization does (in sympy/simplify/cse_opts.py
):
def sub_pre(e):
""" Replace y - x with -(x - y) if -1 can be extracted from y - x.
"""
# replacing Add, A, from which -1 can be extracted with -1*-A
adds = [a for a in e.atoms(Add) if a.could_extract_minus_sign()]
reps = {}
ignore = set()
for a in adds:
na = -a
if na.is_Mul: # e.g. MatExpr
ignore.add(a)
continue
reps[a] = Mul._from_args([S.NegativeOne, na])
e = e.xreplace(reps)
# repeat again for persisting Adds but mark these with a leading 1, -1
# e.g. y - x -> 1*-1*(x - y)
if isinstance(e, Basic):
negs = {}
for a in sorted(e.atoms(Add), key=default_sort_key):
if a in ignore:
continue
if a in reps:
negs[a] = reps[a]
elif a.could_extract_minus_sign():
negs[a] = Mul._from_args([S.One, S.NegativeOne, -a])
e = e.xreplace(negs)
return e
def sub_post(e):
""" Replace 1*-1*x with -x.
"""
replacements = []
for node in preorder_traversal(e):
if isinstance(node, Mul) and \
node.args[0] is S.One and node.args[1] is S.NegativeOne:
replacements.append((node, -Mul._from_args(node.args[2:])))
for node, replacement in replacements:
e = e.xreplace({node: replacement})
return e```
from symforce.
Related Issues (20)
- sf.logical_or HOT 3
- Need to call make three times in a row to make with cmake HOT 4
- Values accept Dict HOT 4
- more resources for generating factor graph HOT 3
- Convert gtsam::Rot3 to sym::Rot3 HOT 2
- Failure to build from source on MacOS HOT 3
- Unreasonable high covariances HOT 6
- gmp install with mamba on macOS doesn't work
- Rust codegen support HOT 7
- Symforce solve different than sympy solve HOT 4
- Idea: `PerformanceWarning` HOT 2
- feat: Symbolic integration HOT 4
- Double free when unused but optimized variable appears appears in cpp solver
- Returning a `Values` with fixed-size Matrix types results in `VectorXd` in resulting LCM struct HOT 2
- Using symforce as submodule, fixing rerun_if_needed.py HOT 2
- Epsilon tutorial: Plot of sin(x)/x doesn't show on website dark mode
- Add example for nonlinear MPC from ICRA 2023 workshop HOT 2
- Bundle-adjustment-in-the-large example optimization fails for larger problems HOT 1
- Release version for Python 3.12
- Request for a more detailed tutorial of codegen
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from symforce.