Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
34446311
"vscode:/vscode.git/clone" did not exist on "cbee75175da8e4f75ea119894ba6240747ffdbcf"
Unverified
Commit
34446311
authored
Nov 15, 2022
by
Peter Eastman
Committed by
GitHub
Nov 15, 2022
Browse files
Improvement to expression optimizer (#3834)
parent
3a212464
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
1 deletion
+9
-1
libraries/lepton/src/ParsedExpression.cpp
libraries/lepton/src/ParsedExpression.cpp
+9
-1
No files found.
libraries/lepton/src/ParsedExpression.cpp
View file @
34446311
...
@@ -155,7 +155,7 @@ ExpressionTreeNode ParsedExpression::substituteSimplerExpression(const Expressio
...
@@ -155,7 +155,7 @@ ExpressionTreeNode ParsedExpression::substituteSimplerExpression(const Expressio
// Collect some info on constant expressions in children
// Collect some info on constant expressions in children
bool
first_const
=
children
.
size
()
>
0
&&
isConstant
(
children
[
0
]);
// is first child constant?
bool
first_const
=
children
.
size
()
>
0
&&
isConstant
(
children
[
0
]);
// is first child constant?
bool
second_const
=
children
.
size
()
>
1
&&
isConstant
(
children
[
1
]);
;
// is second child constant?
bool
second_const
=
children
.
size
()
>
1
&&
isConstant
(
children
[
1
]);
// is second child constant?
double
first
,
second
;
// if yes, value of first and second child
double
first
,
second
;
// if yes, value of first and second child
if
(
first_const
)
if
(
first_const
)
first
=
getConstantValue
(
children
[
0
]);
first
=
getConstantValue
(
children
[
0
]);
...
@@ -319,11 +319,19 @@ ExpressionTreeNode ParsedExpression::substituteSimplerExpression(const Expressio
...
@@ -319,11 +319,19 @@ ExpressionTreeNode ParsedExpression::substituteSimplerExpression(const Expressio
{
{
if
(
children
[
0
].
getOperation
().
getId
()
==
Operation
::
SQUARE
)
// sqrt(square(x)) = abs(x)
if
(
children
[
0
].
getOperation
().
getId
()
==
Operation
::
SQUARE
)
// sqrt(square(x)) = abs(x)
return
ExpressionTreeNode
(
new
Operation
::
Abs
(),
children
[
0
].
getChildren
()[
0
]);
return
ExpressionTreeNode
(
new
Operation
::
Abs
(),
children
[
0
].
getChildren
()[
0
]);
break
;
}
}
case
Operation
::
SQUARE
:
case
Operation
::
SQUARE
:
{
{
if
(
children
[
0
].
getOperation
().
getId
()
==
Operation
::
SQRT
)
// square(sqrt(x)) = x
if
(
children
[
0
].
getOperation
().
getId
()
==
Operation
::
SQRT
)
// square(sqrt(x)) = x
return
children
[
0
].
getChildren
()[
0
];
return
children
[
0
].
getChildren
()[
0
];
break
;
}
case
Operation
::
SELECT
:
{
if
(
children
[
1
]
==
children
[
2
])
// Select between two identical values
return
children
[
1
];
break
;
}
}
default:
default:
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment