Let us assume that you know what you are doing. And also let us assume that you notices how extremely slow the "correct" way of communication between Python and C++ is. Well the following section is for you...
Questions to [David Rotermund](mailto:davrot@uni-bremen.de)
It is the job of Python (Numpy or PyTorch) to provide the tensors from which we read and in which we write. In the cpp domain, we will use this matrices as the interface to Python. We are not allowed to change the sizes of these tensors. We are only allowed to change the content of the tensors. In addition we need to make sure that the matrices are in C_CONTIGUOUS shape.
# Also I need the shape information for the C++ program.
np_input_dim_0: int = np_input.shape[0]
np_input_dim_1: int = np_input.shape[1]
np_input_dim_2: int = np_input.shape[2]
np_input_dim_3: int = np_input.shape[3]
```
## On the C++ side
Your C++ method needs to accept these arguments
```cpp
int64_t np_input_pointer_addr,
int64_t np_input_dim_0,
int64_t np_input_dim_1,
int64_t np_input_dim_2,
int64_t np_input_dim_3,
```
Inside your C++ method you convert the address into a pointer. **BE WARNED:** Make absolutely sure that the dtype of the np.ndarray is correctly reflected in the pointer type
Don't forget that C Contiguous is just a complicated way of saying Row-major order memory layout [Row- and column-major order](https://en.wikipedia.org/wiki/Row-_and_column-major_order).
$$M[a,b,c,d] = M[\eta_a \cdot a + \eta_b \cdot b + \eta_c \cdot c + d]$$