Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
a9488226
Commit
a9488226
authored
Jun 17, 2018
by
gabrieldemarmiesse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
As extend doesn't exist for vectors, replaced it by a resize.
parent
5c04c1a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
16 deletions
+18
-16
docs/examples/userguide/buffer/matrix.pyx
docs/examples/userguide/buffer/matrix.pyx
+16
-0
docs/src/userguide/buffer.rst
docs/src/userguide/buffer.rst
+2
-16
No files found.
docs/examples/userguide/buffer/matrix.pyx
0 → 100644
View file @
a9488226
# distutils: language = c++
# matrix.pyx
from
libcpp.vector
cimport
vector
cdef
class
Matrix
:
cdef
unsigned
ncols
cdef
vector
[
float
]
v
def
__cinit__
(
self
,
unsigned
ncols
):
self
.
ncols
=
ncols
def
add_row
(
self
):
"""Adds a row, initially zero-filled."""
self
.
v
.
resize
(
self
.
v
.
size
()
+
self
.
ncols
)
docs/src/userguide/buffer.rst
View file @
a9488226
...
@@ -16,21 +16,7 @@ The following Cython/C++ code implements a matrix of floats,
...
@@ -16,21 +16,7 @@ The following Cython/C++ code implements a matrix of floats,
where the number of columns is fixed at construction time
where the number of columns is fixed at construction time
but rows can be added dynamically.
but rows can be added dynamically.
::
.. literalinclude:: ../../examples/userguide/buffer/matrix.pyx
# matrix.pyx
from libcpp.vector cimport vector
cdef class Matrix:
cdef unsigned ncols
cdef vector[float] v
def __cinit__(self, unsigned ncols):
self.ncols = ncols
def add_row(self):
"""Adds a row, initially zero-filled."""
self.v.extend(self.ncols)
There are no methods to do anything productive with the matrices' contents.
There are no methods to do anything productive with the matrices' contents.
We could implement custom ``__getitem__``, ``__setitem__``, etc. for this,
We could implement custom ``__getitem__``, ``__setitem__``, etc. for this,
...
@@ -57,7 +43,7 @@ which Cython handles specially.
...
@@ -57,7 +43,7 @@ which Cython handles specially.
def add_row(self):
def add_row(self):
"""Adds a row, initially zero-filled."""
"""Adds a row, initially zero-filled."""
self.v.
extend(
self.ncols)
self.v.
resize(self.v.size() +
self.ncols)
def __getbuffer__(self, Py_buffer *buffer, int flags):
def __getbuffer__(self, Py_buffer *buffer, int flags):
cdef Py_ssize_t itemsize = sizeof(self.v[0])
cdef Py_ssize_t itemsize = sizeof(self.v[0])
...
...
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