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
686e68dc
Unverified
Commit
686e68dc
authored
Jul 05, 2019
by
peastman
Committed by
GitHub
Jul 05, 2019
Browse files
Merge pull request #2340 from peastman/numpy
Optimized conversion of 1D Numpy array to C++ vector<double>
parents
b9a1bee6
71b24fad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
14 deletions
+50
-14
wrappers/python/src/swig_doxygen/swig_lib/python/header.i
wrappers/python/src/swig_doxygen/swig_lib/python/header.i
+10
-0
wrappers/python/src/swig_doxygen/swig_lib/python/typemaps.i
wrappers/python/src/swig_doxygen/swig_lib/python/typemaps.i
+40
-14
No files found.
wrappers/python/src/swig_doxygen/swig_lib/python/header.i
View file @
686e68dc
...
@@ -20,6 +20,16 @@ PyObject *copyVVec3ToList(std::vector<Vec3> vVec3) {
...
@@ -20,6 +20,16 @@ PyObject *copyVVec3ToList(std::vector<Vec3> vVec3) {
return
pyList
;
return
pyList
;
}
}
int
isNumpyAvailable
()
{
static
bool
initialized
=
false
;
static
bool
available
=
false
;
if
(
!
initialized
)
{
initialized
=
true
;
available
=
(
_import_array
()
>=
0
)
;
}
return
available
;
}
}
// namespace OpenMM
}
// namespace OpenMM
%
}
%
}
...
...
wrappers/python/src/swig_doxygen/swig_lib/python/typemaps.i
View file @
686e68dc
...
@@ -156,13 +156,49 @@ OpenMM::Vec3 Py_SequenceToVec3(PyObject* obj, int& status) {
...
@@ -156,13 +156,49 @@ OpenMM::Vec3 Py_SequenceToVec3(PyObject* obj, int& status) {
%
fragment
(
"Py_SequenceToVecDouble"
,
"header"
,
fragment
=
"Py_StripOpenMMUnits"
)
{
%
fragment
(
"Py_SequenceToVecDouble"
,
"header"
,
fragment
=
"Py_StripOpenMMUnits"
)
{
int
Py_SequenceToVecDouble
(
PyObject
*
obj
,
std
::
vector
<
double
>
&
out
)
{
int
Py_SequenceToVecDouble
(
PyObject
*
obj
,
std
::
vector
<
double
>
&
out
)
{
PyObject
*
stripped
=
NULL
;
PyObject
*
stripped
=
Py_StripOpenMMUnits
(
obj
)
;
PyObject
*
item
=
NULL
;
PyObject
*
item
=
NULL
;
PyObject
*
item1
=
NULL
;
PyObject
*
item1
=
NULL
;
PyObject
*
iterator
=
NULL
;
stripped
=
Py_StripOpenMMUnits
(
obj
)
;
iterator
=
PyObject_GetIter
(
stripped
)
;
if
(
isNumpyAvailable
())
{
if
(
PyArray_Check
(
stripped
)
&
&
PyArray_ISCARRAY_RO(stripped)
&
&
PyArray_NDIM(stripped)
==
1
)
{
int
type
=
PyArray_TYPE
(
stripped
)
;
int
length
=
PyArray_SIZE
(
stripped
)
;
void
*
data
=
PyArray_DATA
((
PyArrayObject
*
)
stripped
)
;
if
(
type
==
NPY_DOUBLE
)
{
out
.
resize
(
length
)
;
memcpy
(
&
out[0],
data,
sizeof(double)*length);
Py_DECREF
(
stripped
)
;
return
SWIG_OK
;
}
if
(
type
==
NPY_FLOAT
)
{
out
.
resize
(
length
)
;
float
*
floatData
=
(
float
*
)
data
;
for
(
int
i
=
0
;
i
<
length
;
i
++
)
out
[
i
]
=
floatData
[
i
]
;
Py_DECREF
(
stripped
)
;
return
SWIG_OK
;
}
if
(
type
==
NPY_INT32
)
{
out
.
resize
(
length
)
;
int
*
intData
=
(
int
*
)
data
;
for
(
int
i
=
0
;
i
<
length
;
i
++
)
out
[
i
]
=
intData
[
i
]
;
Py_DECREF
(
stripped
)
;
return
SWIG_OK
;
}
if
(
type
==
NPY_INT64
)
{
out
.
resize
(
length
)
;
long
long
*
longData
=
(
long
long
*
)
data
;
for
(
int
i
=
0
;
i
<
length
;
i
++
)
out
[
i
]
=
longData
[
i
]
;
Py_DECREF
(
stripped
)
;
return
SWIG_OK
;
}
}
}
PyObject
*
iterator
=
PyObject_GetIter
(
stripped
)
;
if
(
iterator
==
NULL
)
{
if
(
iterator
==
NULL
)
{
Py_DECREF
(
stripped
)
;
Py_DECREF
(
stripped
)
;
return
SWIG_ERROR
;
return
SWIG_ERROR
;
...
@@ -194,16 +230,6 @@ int Py_SequenceToVecDouble(PyObject* obj, std::vector<double>& out) {
...
@@ -194,16 +230,6 @@ int Py_SequenceToVecDouble(PyObject* obj, std::vector<double>& out) {
}
}
%
fragment
(
"Py_SequenceToVecVec3"
,
"header"
,
fragment
=
"Py_SequenceToVec3"
)
{
%
fragment
(
"Py_SequenceToVecVec3"
,
"header"
,
fragment
=
"Py_SequenceToVec3"
)
{
int
isNumpyAvailable
()
{
static
bool
initialized
=
false
;
static
bool
available
=
false
;
if
(
!
initialized
)
{
initialized
=
true
;
available
=
(
_import_array
()
>=
0
)
;
}
return
available
;
}
int
Py_SequenceToVecVec3
(
PyObject
*
obj
,
std
::
vector
<
Vec3
>
&
out
)
{
int
Py_SequenceToVecVec3
(
PyObject
*
obj
,
std
::
vector
<
Vec3
>
&
out
)
{
PyObject
*
stripped
=
Py_StripOpenMMUnits
(
obj
)
;
// new reference
PyObject
*
stripped
=
Py_StripOpenMMUnits
(
obj
)
;
// new reference
if
(
isNumpyAvailable
())
{
if
(
isNumpyAvailable
())
{
...
...
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