18 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION 20 #include <numpy/arrayobject.h> 33 void *memory = PyCapsule_GetPointer(capsule, NULL);
37 scalable_aligned_free(memory);
52 PyObject*
array_from_ptr(
void * ptr,
int dim, npy_intp* shape,
int np_type) {
54 if (PyArray_API == NULL) {
60 PyObject* arr = PyArray_SimpleNewFromData(dim, shape, np_type, ptr);
65 PyArray_SetBaseObject((PyArrayObject *) arr, capsule);
84 shape[0] = (npy_intp) mtx.
rows;
85 shape[1] = (npy_intp) mtx.
cols;
104 shape[0] = (npy_intp) mtx.
rows;
105 shape[1] = (npy_intp) mtx.
cols;
128 if ( mtx.
rows == 1 ) {
132 else if ( mtx.
cols == 1 ) {
138 shape[0] = (npy_intp) mtx.
rows;
139 shape[1] = (npy_intp) mtx.
cols;
160 if ( mtx.
rows == 1 ) {
164 else if ( mtx.
cols == 1 ) {
170 shape[0] = (npy_intp) mtx.
rows;
171 shape[1] = (npy_intp) mtx.
cols;
192 shape[0] = (npy_intp) mtx.
rows;
193 shape[1] = (npy_intp) mtx.
cols;
210 if ( (PyObject*)arr == Py_None ) {
217 assert( PyArray_IS_C_CONTIGUOUS(arr) &&
"array is not memory contiguous" );
224 int dim_num = PyArray_NDIM( arr );
225 npy_intp* dims = PyArray_DIMS(arr);
229 Matrix mtx =
Matrix(data, static_cast<int>(dims[0]), static_cast<int>(dims[1]));
232 else if (dim_num == 1) {
233 Matrix mtx =
Matrix(data, static_cast<int>(dims[0]), 1);
237 std::string err(
"numpy2matrix: Wrong matrix dimension was given");
252 if ( (PyObject*)arr == Py_None ) {
257 assert( PyArray_IS_C_CONTIGUOUS(arr) &&
"array is not memory contiguous" );
262 int dim_num = PyArray_NDIM( arr );
263 npy_intp* dims = PyArray_DIMS(arr);
269 else if (dim_num == 1) {
274 std::string err(
"numpy2matrix_float: Wrong matrix dimension was given");
287 if ( (PyObject*)arr == Py_None ) {
294 assert( PyArray_IS_C_CONTIGUOUS(arr) &&
"array is not memory contiguous" );
298 double *
data = (
double *)PyArray_DATA(arr);
301 int dim_num = PyArray_NDIM( arr );
302 npy_intp* dims = PyArray_DIMS(arr);
309 else if (dim_num == 1) {
314 std::string err(
"numpy2matrix: Wrong matrix dimension was given");
329 if ( (PyObject*)arr == Py_None ) {
334 assert( PyArray_IS_C_CONTIGUOUS(arr) &&
"array is not memory contiguous" );
337 float *
data = (
float *)PyArray_DATA(arr);
339 int dim_num = PyArray_NDIM( arr );
340 npy_intp* dims = PyArray_DIMS(arr);
346 else if (dim_num == 1) {
351 std::string err(
"numpy2matrix_real_float: Wrong matrix dimension was given");
Header file of single-precision complex array storage with automatic and thread safe reference counti...
Class to store single-precision real arrays and properties.
Structure type representing single-precision complex numbers.
data
load the unitary from file
scalar * get_data() const
Call to get the pointer to the stored data.
PyObject * matrix_int8_to_numpy(matrix_base< int8_t > &mtx)
Call to make a numpy array from an instance of matrix_base<int8_t> class.
Matrix_real_float numpy2matrix_real_float(PyArrayObject *arr)
Call to create a PIC matrix_real_float representation of a numpy array.
PyObject * matrix_float_to_numpy(Matrix_float &mtx)
Call to make a numpy array from an instance of matrix_float class.
int rows
The number of rows.
int cols
The number of columns.
PyObject * matrix_to_numpy(Matrix &mtx)
Call to make a numpy array from an instance of matrix class.
Matrix numpy2matrix(PyArrayObject *arr)
Call to create a matrix representation of a numpy array.
Matrix_float numpy2matrix_float(PyArrayObject *arr)
Call to create a matrix_float representation of a numpy array.
Header file of complex array storage array with automatic and thread safe reference counting...
Structure type representing complex numbers in the SQUANDER package.
Double-precision complex matrix (float64).
Single-precision complex matrix (float32).
Matrix_real numpy2matrix_real(PyArrayObject *arr)
Call to create a PIC matrix_real representation of a numpy array.
PyObject * matrix_real_to_numpy(Matrix_real &mtx)
Call to make a numpy array from an instance of matrix class.
void capsule_cleanup(PyObject *capsule)
Method to cleanup the memory when the python object becomes released.
PyObject * array_from_ptr(void *ptr, int dim, npy_intp *shape, int np_type)
Call to make a numpy array from data stored via void pointer.
PyObject * matrix_real_float_to_numpy(Matrix_real_float &mtx)
Call to make a numpy array from an instance of matrix_real_float class.
Class to store data of complex arrays and its properties.