19 #include <numpy/arrayobject.h> 30 void *memory = PyCapsule_GetPointer(capsule, NULL);
34 scalable_aligned_free(memory);
49 PyObject*
array_from_ptr(
void * ptr,
int dim, npy_intp* shape,
int np_type) {
51 if (PyArray_API == NULL) {
57 PyObject* arr = PyArray_SimpleNewFromData(dim, shape, np_type, ptr);
61 PyArray_SetBaseObject((PyArrayObject *) arr, capsule);
79 shape[0] = (npy_intp) mtx.
rows;
80 shape[1] = (npy_intp) mtx.
cols;
103 if ( mtx.
rows == 1 ) {
107 else if ( mtx.
cols == 1 ) {
113 shape[0] = (npy_intp) mtx.
rows;
114 shape[1] = (npy_intp) mtx.
cols;
135 shape[0] = (npy_intp) mtx.
rows;
136 shape[1] = (npy_intp) mtx.
cols;
153 if ( (PyObject*)arr == Py_None ) {
160 assert( PyArray_IS_C_CONTIGUOUS(arr) &&
"array is not memory contiguous" );
167 int dim_num = PyArray_NDIM( arr );
168 npy_intp* dims = PyArray_DIMS(arr);
175 else if (dim_num == 1) {
180 std::string err(
"numpy2matrix: Wrong matrix dimension was given");
196 if ( (PyObject*)arr == Py_None ) {
203 assert( PyArray_IS_C_CONTIGUOUS(arr) &&
"array is not memory contiguous" );
207 double *
data = (
double *)PyArray_DATA(arr);
210 int dim_num = PyArray_NDIM( arr );
211 npy_intp* dims = PyArray_DIMS(arr);
218 else if (dim_num == 1) {
223 std::string err(
"numpy2matrix: Wrong matrix dimension was given");
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.
Base Class to store data of arrays and its properties.
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.
Header file of complex array storage array with automatic and thread safe reference counting...
Structure type representing complex numbers in the SQUANDER package.
Class to store data of complex arrays and its properties.
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.
Class to store data of complex arrays and its properties.