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
0bf7b063
"csrc/gfx9/decode/vscode:/vscode.git/clone" did not exist on "aec174740c3167b075f18852d012a2bcfdc18878"
Commit
0bf7b063
authored
Jun 01, 2019
by
peastman
Browse files
Algebraic optimizations
parent
e0b3c2bd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
0 deletions
+12
-0
libraries/lepton/src/ParsedExpression.cpp
libraries/lepton/src/ParsedExpression.cpp
+10
-0
tests/TestParser.cpp
tests/TestParser.cpp
+2
-0
No files found.
libraries/lepton/src/ParsedExpression.cpp
View file @
0bf7b063
...
...
@@ -271,6 +271,16 @@ ExpressionTreeNode ParsedExpression::substituteSimplerExpression(const Expressio
return
ExpressionTreeNode
(
new
Operation
::
MultiplyConstant
(
-
dynamic_cast
<
const
Operation
::
MultiplyConstant
*>
(
&
node
.
getOperation
())
->
getValue
()),
children
[
0
].
getChildren
()[
0
]);
break
;
}
case
Operation
::
SQRT
:
{
if
(
children
[
0
].
getOperation
().
getId
()
==
Operation
::
SQUARE
)
// sqrt(square(x)) = abs(x)
return
ExpressionTreeNode
(
new
Operation
::
Abs
(),
children
[
0
].
getChildren
()[
0
]);
}
case
Operation
::
SQUARE
:
{
if
(
children
[
0
].
getOperation
().
getId
()
==
Operation
::
SQRT
)
// square(sqrt(x)) = x
return
children
[
0
].
getChildren
()[
0
];
}
default:
{
// If operation ID is not one of the above,
...
...
tests/TestParser.cpp
View file @
0bf7b063
...
...
@@ -266,6 +266,8 @@ int main() {
verifyEvaluation
(
"select(x, 1.0, y)"
,
0.3
,
2.0
,
1.0
);
verifyEvaluation
(
"select(x, 1.0, y)"
,
0.0
,
2.0
,
2.0
);
verifyEvaluation
(
"atan2(x, y)"
,
3.0
,
1.5
,
std
::
atan
(
2.0
));
verifyEvaluation
(
"sqrt(x^2)"
,
-
2.2
,
0.0
,
2.2
);
verifyEvaluation
(
"sqrt(x)^2"
,
2.2
,
0.0
,
2.2
);
verifyInvalidExpression
(
"1..2"
);
verifyInvalidExpression
(
"1*(2+3"
);
verifyInvalidExpression
(
"5++4"
);
...
...
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