Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80307209
pybind11_akantu.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 31, 01:51
Size
1 KB
Mime Type
text/x-c
Expires
Mon, Sep 2, 01:51 (2 d)
Engine
blob
Format
Raw Data
Handle
20220744
Attached To
rAKA akantu
pybind11_akantu.cc
View Options
/* -------------------------------------------------------------------------- */
#include "pybind11_akantu.hh"
/* -------------------------------------------------------------------------- */
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
/* -------------------------------------------------------------------------- */
namespace
py
=
pybind11
;
namespace
akantu
{
PYBIND11_MODULE
(
aka_test
,
m
)
{
m
.
doc
()
=
"Module for the tests of akantu"
;
py
::
class_
<
ArrayProxy
<
Real
>>
(
m
,
"ArrayProxy"
,
py
::
buffer_protocol
())
.
def_buffer
([](
ArrayProxy
<
Real
>
&
a
)
{
return
py
::
buffer_info
(
a
.
storage
(),
/* Pointer to buffer */
sizeof
(
Real
),
/* Size of one scalar */
py
::
format_descriptor
<
Real
>::
format
(),
/* Python struct-style
format descriptor */
2
,
/* Number of dimensions */
{
a
.
size
(),
a
.
getNbComponent
()},
/* Buffer dimensions */
{
sizeof
(
Real
)
*
a
.
getNbComponent
(),
/* Strides (in bytes) for each index */
sizeof
(
Real
)});
})
.
def
(
py
::
init
([](
py
::
array
&
n
)
{
/* Request a buffer descriptor from Python */
py
::
buffer_info
info
=
n
.
request
();
/* Some sanity checks ... */
if
(
info
.
format
!=
py
::
format_descriptor
<
Real
>::
format
())
throw
std
::
runtime_error
(
"Incompatible format: expected a double array!"
);
if
(
info
.
ndim
!=
2
)
throw
std
::
runtime_error
(
"Incompatible buffer dimension!"
);
return
std
::
make_unique
<
ArrayProxy
<
Real
>>
(
static_cast
<
Real
*>
(
info
.
ptr
),
info
.
shape
[
0
],
info
.
shape
[
1
]);
}));
}
}
// namespace akantu
Event Timeline
Log In to Comment