Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
bf2510ee
Commit
bf2510ee
authored
Jul 18, 2016
by
Ivan Smirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make buffer_info::as_pybuffer a memoryview ctor
parent
41c33990
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
27 deletions
+22
-27
include/pybind11/common.h
+0
-24
include/pybind11/pytypes.h
+22
-3
No files found.
include/pybind11/common.h
View file @
bf2510ee
...
...
@@ -232,30 +232,6 @@ struct buffer_info {
if
(
view
)
{
PyBuffer_Release
(
view
);
delete
view
;
}
}
Py_buffer
&
as_pybuffer
()
const
{
static
Py_buffer
buf
{
};
// Py_buffer uses signed sizes, strides and shape!..
static
std
::
vector
<
Py_ssize_t
>
py_strides
{
};
static
std
::
vector
<
Py_ssize_t
>
py_shape
{
};
buf
.
buf
=
ptr
;
buf
.
itemsize
=
(
Py_ssize_t
)
itemsize
;
buf
.
format
=
const_cast
<
char
*>
(
format
.
c_str
());
buf
.
ndim
=
(
int
)
ndim
;
buf
.
len
=
(
Py_ssize_t
)
size
;
py_strides
.
clear
();
py_shape
.
clear
();
for
(
size_t
i
=
0
;
i
<
ndim
;
++
i
)
{
py_strides
.
push_back
((
Py_ssize_t
)
strides
[
i
]);
py_shape
.
push_back
((
Py_ssize_t
)
shape
[
i
]);
}
buf
.
strides
=
py_strides
.
data
();
buf
.
shape
=
py_shape
.
data
();
buf
.
suboffsets
=
nullptr
;
buf
.
readonly
=
false
;
buf
.
internal
=
nullptr
;
return
buf
;
}
private
:
Py_buffer
*
view
=
nullptr
;
};
...
...
include/pybind11/pytypes.h
View file @
bf2510ee
...
...
@@ -572,10 +572,29 @@ public:
class
memoryview
:
public
object
{
public
:
memoryview
(
const
buffer_info
&
info
)
:
memoryview
(
&
info
.
as_pybuffer
())
{
}
memoryview
(
const
buffer_info
&
info
)
{
static
Py_buffer
buf
{
};
// Py_buffer uses signed sizes, strides and shape!..
static
std
::
vector
<
Py_ssize_t
>
py_strides
{
};
static
std
::
vector
<
Py_ssize_t
>
py_shape
{
};
buf
.
buf
=
info
.
ptr
;
buf
.
itemsize
=
(
Py_ssize_t
)
info
.
itemsize
;
buf
.
format
=
const_cast
<
char
*>
(
info
.
format
.
c_str
());
buf
.
ndim
=
(
int
)
info
.
ndim
;
buf
.
len
=
(
Py_ssize_t
)
info
.
size
;
py_strides
.
clear
();
py_shape
.
clear
();
for
(
size_t
i
=
0
;
i
<
info
.
ndim
;
++
i
)
{
py_strides
.
push_back
((
Py_ssize_t
)
info
.
strides
[
i
]);
py_shape
.
push_back
((
Py_ssize_t
)
info
.
shape
[
i
]);
}
buf
.
strides
=
py_strides
.
data
();
buf
.
shape
=
py_shape
.
data
();
buf
.
suboffsets
=
nullptr
;
buf
.
readonly
=
false
;
buf
.
internal
=
nullptr
;
memoryview
(
Py_buffer
*
view
)
:
object
(
PyMemoryView_FromBuffer
(
view
),
false
)
{
m_ptr
=
PyMemoryView_FromBuffer
(
&
buf
);
if
(
!
m_ptr
)
pybind11_fail
(
"Unable to create memoryview from buffer descriptor"
);
}
...
...
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