Hi all,
I am wondering if there are any issues (performance, design flaws, etc.) with the following setup I am thinking of.
The extension type class I have wants to take in a 2D array of shape (n_samples, n_features), where each row is a separate sample. The sample is comprised of a vectorized 1D array. However, I want to perform operations on a reshaped version of the vectorized array because it's easier to reason and code.
For example, I have a vectorized array of shape (12,), and I want to then do operations on a reshaped memory view that views that array as (4, 3). In terms of Cython code, I was thinking of something like:
```
cdef class A:
def __cinit__(self, double [:, ::1] X):
self.X = X
cdef inline double compute_something(self):
cdef double[:, :, ::1] reshaped_X = self.X.reshape(-1, 4, 3)
# compute something using the reshaped array - only requires read-access
cdef double result = 0
for idx in range(n_samples):
result += reshaped_X[idx, 2, 2]
return result
```
Now, my understanding of memory views is that this is not a copy of the underlying array (instantiated in Python via numpy). And when you reshape the array, you are only changing the strides, so you are also not making a copy of the underlying data.
1. Does the design I posed work, or do I have to do something special to initialize the `reshaped_X` memory view as a "reshaped view" into X?
2. Does the design with `reshaped_X` make a copy of X? It should only change the strides and make a new "view" into the underlying data of X right?
3. Would the design I posed be fine performance-wise, or is there anything I need to consider?
Thanks!