Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
arbd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tbgl
tools
arbd
Commits
cec942e3
Commit
cec942e3
authored
1 year ago
by
cmaffeo2
Browse files
Options
Downloads
Patches
Plain Diff
Add a few bindings for Vector3_t<T>
parent
d8e07618
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitmodules
+4
-0
4 additions, 0 deletions
.gitmodules
CMakeLists.txt
+10
-1
10 additions, 1 deletion
CMakeLists.txt
extern/pybind11
+1
-0
1 addition, 0 deletions
extern/pybind11
src/pyarbd.cpp
+70
-0
70 additions, 0 deletions
src/pyarbd.cpp
with
85 additions
and
1 deletion
.gitmodules
+
4
−
0
View file @
cec942e3
[submodule "extern/spdlog"]
path = extern/spdlog
url = https://github.com/gabime/spdlog.git
[submodule "extern/pybind11"]
path = extern/pybind11
url = ../pybind11
branch = stable
This diff is collapsed.
Click to expand it.
CMakeLists.txt
+
10
−
1
View file @
cec942e3
## Specify the project
cmake_minimum_required
(
VERSION 3.9 FATAL_ERROR
)
# cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
cmake_minimum_required
(
VERSION 3.12 FATAL_ERROR
)
# FOR PYBIND, should be 3.15+?
# option(USE_CUDA "Use CUDA" ON)
set
(
USE_CUDA ON
)
...
...
@@ -164,6 +165,14 @@ src/SimManager.cu
src/useful.cu
)
if
(
USE_PYBIND
)
## https://pybind11.readthedocs.io/en/latest/compiling.html
add_subdirectory
(
extern/pybind11
)
find_package
(
Python 3.6 COMPONENTS Interpreter Development REQUIRED
)
pybind11_add_module
(
"py
${
PROJECT_NAME
}
"
MODULE src/pyarbd.cpp
)
target_link_libraries
(
"py
${
PROJECT_NAME
}
"
PUBLIC
"lib
${
PROJECT_NAME
}
"
)
endif
()
target_link_libraries
(
"
${
PROJECT_NAME
}
"
PUBLIC
"lib
${
PROJECT_NAME
}
"
)
## Add optional libraries
...
...
This diff is collapsed.
Click to expand it.
pybind11
@
914c06fb
Subproject commit 914c06fb252b6cc3727d0eedab6736e88a3fcb01
This diff is collapsed.
Click to expand it.
src/pyarbd.cpp
0 → 100644
+
70
−
0
View file @
cec942e3
#include
"Types.h"
#include
"ParticlePatch.h"
#include
<pybind11/pybind11.h>
#include
<pybind11/numpy.h>
#include
<pybind11/operators.h>
namespace
py
=
pybind11
;
template
<
typename
T
>
Vector3_t
<
T
>
array_to_vector
(
py
::
array_t
<
T
>
a
)
{
py
::
buffer_info
buf1
=
a
.
request
();
if
(
buf1
.
ndim
!=
1
)
throw
std
::
runtime_error
(
"Number of dimensions must be one"
);
if
(
buf1
.
size
<
3
||
buf1
.
size
>
4
)
throw
std
::
runtime_error
(
"Size of array must be 3 or 4"
);
T
*
ptr
=
static_cast
<
T
*>
(
buf1
.
ptr
);
if
(
buf1
.
size
==
3
)
return
Vector3_t
<
T
>
(
ptr
[
0
],
ptr
[
1
],
ptr
[
2
]);
else
return
Vector3_t
<
T
>
(
ptr
[
0
],
ptr
[
1
],
ptr
[
2
],
ptr
[
3
]);
}
// basic types
template
<
typename
T
>
void
declare_vector
(
py
::
module
&
m
,
const
std
::
string
&
typestr
)
{
using
Class
=
Vector3_t
<
T
>
;
std
::
string
pyclass_name
=
std
::
string
(
"Vector3_t_"
)
+
typestr
;
py
::
class_
<
Class
>
(
m
,
pyclass_name
.
c_str
(),
py
::
buffer_protocol
(),
py
::
dynamic_attr
())
.
def
(
py
::
init
<>
())
.
def
(
py
::
init
<
T
>
())
.
def
(
py
::
init
<
T
,
T
,
T
>
())
.
def
(
py
::
init
([](
py
::
array_t
<
T
>
a
)
{
return
array_to_vector
<
T
>
(
a
);
}))
// .def(py::init<T, T, T, T>(),[] lambda )
// .def(py::init<T*>())
.
def
(
py
::
self
+
py
::
self
)
.
def
(
py
::
self
*
py
::
self
)
// .def(py::self += py::self)
.
def
(
py
::
self
*=
float
())
.
def
(
float
()
*
py
::
self
)
.
def
(
py
::
self
*
float
())
.
def
(
-
py
::
self
)
.
def
(
"__repr__"
,
&
Class
::
to_string
);
}
PYBIND11_MODULE
(
pyarbd
,
m
)
{
declare_vector
<
int
>
(
m
,
"int"
);
declare_vector
<
float
>
(
m
,
"float"
);
declare_vector
<
double
>
(
m
,
"double"
);
m
.
attr
(
"Vector3"
)
=
m
.
attr
(
"Vector3_t_float"
);
/*
py::class_<Vector_t<T>>(m, "Vector3")
.def(py::init<float, float, float>())
.def(py::init<float, float, float>())
py::class_<Patch>(m, "Patch")
.def(py::init<float, float, float>())
.def(py::self + py::self)
.def(py::self * py::self)
// .def(py::self += py::self)
.def(py::self *= float())
.def(float() * py::self)
.def(py::self * float())
.def(-py::self)
.def("__repr__", &Vector3::to_string);
*/
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment