Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93865236
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
Mon, Dec 2, 02:55
Size
3 KB
Mime Type
text/x-c
Expires
Wed, Dec 4, 02:55 (2 d)
Engine
blob
Format
Raw Data
Handle
22697753
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
]);
}));
py
::
class_
<
MatrixProxy
<
Real
>>
(
m
,
"Matrix"
,
py
::
buffer_protocol
())
.
def_buffer
([](
MatrixProxy
<
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
(
0
),
a
.
size
(
1
)},
/* Buffer dimensions */
{
sizeof
(
Real
),
a
.
size
(
0
)
*
sizeof
(
Real
)}
/* Strides (in bytes) for each index */
);
})
.
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
<
MatrixProxy
<
Real
>>
(
static_cast
<
Real
*>
(
info
.
ptr
),
info
.
shape
[
0
],
info
.
shape
[
1
]);
}));
}
// Module aka test
}
// namespace akantu
Event Timeline
Log In to Comment