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
5eb439d8
"platforms/brook/vscode:/vscode.git/clone" did not exist on "cfb9c98a0e90f0c2fc3d0e9636066fa8f10b1739"
Commit
5eb439d8
authored
Nov 19, 2019
by
peastman
Browse files
Optimized processing of expressions with tabulated functions
parent
97b972e9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
14 deletions
+53
-14
platforms/reference/include/ReferenceTabulatedFunction.h
platforms/reference/include/ReferenceTabulatedFunction.h
+18
-1
platforms/reference/src/ReferenceTabulatedFunction.cpp
platforms/reference/src/ReferenceTabulatedFunction.cpp
+35
-13
No files found.
platforms/reference/include/ReferenceTabulatedFunction.h
View file @
5eb439d8
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2014-201
6
Stanford University and the Authors. *
* Portions copyright (c) 2014-201
9
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
#include "openmm/TabulatedFunction.h"
#include "openmm/TabulatedFunction.h"
#include "openmm/internal/windowsExport.h"
#include "openmm/internal/windowsExport.h"
#include "lepton/CustomFunction.h"
#include "lepton/CustomFunction.h"
#include <memory>
#include <vector>
#include <vector>
namespace
OpenMM
{
namespace
OpenMM
{
...
@@ -146,6 +147,22 @@ private:
...
@@ -146,6 +147,22 @@ private:
std
::
vector
<
double
>
values
;
std
::
vector
<
double
>
values
;
};
};
/**
* This is a lightweight wrapper around an immutable CustomFunction. It makes
* cloning very inexpensive since nothing needs to be copied except a single
* pointer.
*/
class
OPENMM_EXPORT
SharedFunctionWrapper
:
public
Lepton
::
CustomFunction
{
public:
SharedFunctionWrapper
(
std
::
shared_ptr
<
const
CustomFunction
>
pointer
);
int
getNumArguments
()
const
;
double
evaluate
(
const
double
*
arguments
)
const
;
double
evaluateDerivative
(
const
double
*
arguments
,
const
int
*
derivOrder
)
const
;
CustomFunction
*
clone
()
const
;
private:
std
::
shared_ptr
<
const
CustomFunction
>
pointer
;
};
}
// namespace OpenMM
}
// namespace OpenMM
#endif
/*OPENMM_REFERENCETABULATEDFUNCTION_H_*/
#endif
/*OPENMM_REFERENCETABULATEDFUNCTION_H_*/
platforms/reference/src/ReferenceTabulatedFunction.cpp
View file @
5eb439d8
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2014-201
6
Stanford University and the Authors. *
* Portions copyright (c) 2014-201
9
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -56,19 +56,22 @@ using namespace std;
...
@@ -56,19 +56,22 @@ using namespace std;
using
Lepton
::
CustomFunction
;
using
Lepton
::
CustomFunction
;
extern
"C"
OPENMM_EXPORT
CustomFunction
*
createReferenceTabulatedFunction
(
const
TabulatedFunction
&
function
)
{
extern
"C"
OPENMM_EXPORT
CustomFunction
*
createReferenceTabulatedFunction
(
const
TabulatedFunction
&
function
)
{
CustomFunction
*
fn
;
if
(
dynamic_cast
<
const
Continuous1DFunction
*>
(
&
function
)
!=
NULL
)
if
(
dynamic_cast
<
const
Continuous1DFunction
*>
(
&
function
)
!=
NULL
)
return
new
ReferenceContinuous1DFunction
(
dynamic_cast
<
const
Continuous1DFunction
&>
(
function
));
fn
=
new
ReferenceContinuous1DFunction
(
dynamic_cast
<
const
Continuous1DFunction
&>
(
function
));
if
(
dynamic_cast
<
const
Continuous2DFunction
*>
(
&
function
)
!=
NULL
)
else
if
(
dynamic_cast
<
const
Continuous2DFunction
*>
(
&
function
)
!=
NULL
)
return
new
ReferenceContinuous2DFunction
(
dynamic_cast
<
const
Continuous2DFunction
&>
(
function
));
fn
=
new
ReferenceContinuous2DFunction
(
dynamic_cast
<
const
Continuous2DFunction
&>
(
function
));
if
(
dynamic_cast
<
const
Continuous3DFunction
*>
(
&
function
)
!=
NULL
)
else
if
(
dynamic_cast
<
const
Continuous3DFunction
*>
(
&
function
)
!=
NULL
)
return
new
ReferenceContinuous3DFunction
(
dynamic_cast
<
const
Continuous3DFunction
&>
(
function
));
fn
=
new
ReferenceContinuous3DFunction
(
dynamic_cast
<
const
Continuous3DFunction
&>
(
function
));
if
(
dynamic_cast
<
const
Discrete1DFunction
*>
(
&
function
)
!=
NULL
)
else
if
(
dynamic_cast
<
const
Discrete1DFunction
*>
(
&
function
)
!=
NULL
)
return
new
ReferenceDiscrete1DFunction
(
dynamic_cast
<
const
Discrete1DFunction
&>
(
function
));
fn
=
new
ReferenceDiscrete1DFunction
(
dynamic_cast
<
const
Discrete1DFunction
&>
(
function
));
if
(
dynamic_cast
<
const
Discrete2DFunction
*>
(
&
function
)
!=
NULL
)
else
if
(
dynamic_cast
<
const
Discrete2DFunction
*>
(
&
function
)
!=
NULL
)
return
new
ReferenceDiscrete2DFunction
(
dynamic_cast
<
const
Discrete2DFunction
&>
(
function
));
fn
=
new
ReferenceDiscrete2DFunction
(
dynamic_cast
<
const
Discrete2DFunction
&>
(
function
));
if
(
dynamic_cast
<
const
Discrete3DFunction
*>
(
&
function
)
!=
NULL
)
else
if
(
dynamic_cast
<
const
Discrete3DFunction
*>
(
&
function
)
!=
NULL
)
return
new
ReferenceDiscrete3DFunction
(
dynamic_cast
<
const
Discrete3DFunction
&>
(
function
));
fn
=
new
ReferenceDiscrete3DFunction
(
dynamic_cast
<
const
Discrete3DFunction
&>
(
function
));
else
throw
OpenMMException
(
"createReferenceTabulatedFunction: Unknown function type"
);
throw
OpenMMException
(
"createReferenceTabulatedFunction: Unknown function type"
);
return
new
SharedFunctionWrapper
(
shared_ptr
<
const
CustomFunction
>
(
fn
));
}
}
ReferenceContinuous1DFunction
::
ReferenceContinuous1DFunction
(
const
Continuous1DFunction
&
function
)
:
function
(
function
)
{
ReferenceContinuous1DFunction
::
ReferenceContinuous1DFunction
(
const
Continuous1DFunction
&
function
)
:
function
(
function
)
{
...
@@ -298,3 +301,22 @@ double ReferenceDiscrete3DFunction::evaluateDerivative(const double* arguments,
...
@@ -298,3 +301,22 @@ double ReferenceDiscrete3DFunction::evaluateDerivative(const double* arguments,
CustomFunction
*
ReferenceDiscrete3DFunction
::
clone
()
const
{
CustomFunction
*
ReferenceDiscrete3DFunction
::
clone
()
const
{
return
new
ReferenceDiscrete3DFunction
(
function
);
return
new
ReferenceDiscrete3DFunction
(
function
);
}
}
SharedFunctionWrapper
::
SharedFunctionWrapper
(
shared_ptr
<
const
CustomFunction
>
pointer
)
:
pointer
(
pointer
)
{
}
int
SharedFunctionWrapper
::
getNumArguments
()
const
{
return
pointer
->
getNumArguments
();
}
double
SharedFunctionWrapper
::
evaluate
(
const
double
*
arguments
)
const
{
return
pointer
->
evaluate
(
arguments
);
}
double
SharedFunctionWrapper
::
evaluateDerivative
(
const
double
*
arguments
,
const
int
*
derivOrder
)
const
{
return
pointer
->
evaluateDerivative
(
arguments
,
derivOrder
);
}
CustomFunction
*
SharedFunctionWrapper
::
clone
()
const
{
return
new
SharedFunctionWrapper
(
pointer
);
}
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