All Questions
56 questions
1
vote
1
answer
81
views
Cython fused dtype memoryview won't complie
I have some code where I (am trying to) do roughly the following:
ctypedef fused Raster_t:
numpy.uint8_t
numpy.uint16_t
cdef class MyClass:
# shape is (rows, cols, channels)
cdef ...
0
votes
1
answer
70
views
Creating a cython memoryview manually
I have a contiguous 1-d numpy array that holds data. However, this array is really a buffer, and I have several numpy views to access that data. These views have different shapes, ndims, offsets etc .....
1
vote
0
answers
109
views
Cython: Memoryviewslice vs C array
I define a C function with memoryview input to work with a NumPy array, but a pure C-defined temporary float array can not work with 'base_func'. Error:
Operation not allowed without gil
How can I ...
2
votes
1
answer
206
views
Cython returned memoryview is always considered uninitialized
Similar to Cython Memoryview as return value, but I didn't see a solution other than hacking the generated C code.
I'm using Cython 3.0, but it looks like the result is the same with <3.
Here's an ...
1
vote
2
answers
120
views
Why does the memoryview assignment from array have python interactions?
When compiled with cython -a my-file.pyx, this simple line of cdef is annotated as yellow in the html file.
# my-file.pyx
from cpython.array cimport array
def f(double[:] xyz):
cdef double[:] ...
2
votes
0
answers
1k
views
Cython vs. Pure Python with Memoryviews
I'm just starting to learn Cython and I'm confused on an issue. If you look at the main tutorial they have examples that show a "Pure Python" mode vs. "Cython" mode. The pure ...
1
vote
1
answer
216
views
Cython memoryview shape incorrect?
Consider the following to create a linear array of size 4:
import numpy as np
cimport numpy as np
cdef np.float64_t [:] a = np.zeros(shape=(4),dtype=np.float64)
a.shape should be (4,). However:
print(...
0
votes
1
answer
91
views
Cython pyx modification for multidimensional numpy input with memory views
My current input of a function wrapped from a c++ class is a one dimensional numpy array, e.g., func(np.array([1,2,3])) for which my cython description in the pyx looks like the following:
def func(...
-3
votes
1
answer
251
views
Cython example for sending array/vector to a c++ script
Say we have a 1 dimensional numpy array or list that we use as an input to a function, i.e., func(np.array[1.5, 2.5, 3.5]), where this function comes from a wrapped c++ class and our goal is to print ...
2
votes
1
answer
149
views
Cython fastest way to pass a float numbers for high frequency control loops
I have a function(func) in a c++ class and want to call it from the python side to invoke the following sequence with the lowest latency possible:
1_on the python side: func(np.array([1,2,3,4,5]) or ...
2
votes
0
answers
65
views
List of memoryviews in Cython
I have an existing Python codebase that looks a bit like this:
class Lexicon
def __init__(self, ...):
self._mv = memoryview(...)
... elsewhere ...
lexicons # list of lexicons
for word ...
2
votes
0
answers
91
views
How to dynamically allocate memory for multidimension memoryview inside a cdef function using CPython array
I am trying to use cython to work on and output (numpy) array. I have read this post which explains how to do it using cpython array. For example:
from cpython.array import array, clone
def int[:] ...
2
votes
0
answers
494
views
Memoryview of numpy array can't handle assigning to the whole axis
I'm trying to convert my code to Cython.
I'm trying to assign new values to an axis by passing an array of values.
Here is an example code:
cdef double[:,:] array_view = array
for t in range(tau):
...
4
votes
1
answer
174
views
Why does Cython expect 0 dimensions?
I have boiled my problem down to a small reproducible test case:
In file 1 (custom_cython.pyx) file I have the following:
import numpy as np
cimport numpy as np
cimport cython
ctypedef np.uint8_t ...
2
votes
1
answer
1k
views
Cython "Cannot take address of memoryview slice"
I am having trouble creating a simple class in Cython. There is little documentation related to handling memoryviews for arrays in C++ wrappers. I want to create a data class with time, x, y, and z ...