55 lines
1.5 KiB
C
55 lines
1.5 KiB
C
// ascee_python.h
|
|
//
|
|
// Author: J.A. de Jong - ASCEE
|
|
//
|
|
// Description:
|
|
// Some routines to generate numpy arrays from matrices and vectors.
|
|
//////////////////////////////////////////////////////////////////////
|
|
#pragma once
|
|
#ifndef LASP_PYTHON_H
|
|
#define LASP_PYTHON_H
|
|
#define TRACERPLUS (-10)
|
|
#include "lasp_pyarray.h"
|
|
|
|
/**
|
|
* Create a numpy array from an existing dmat.
|
|
*
|
|
* @param mat dmat struccture containing array data and metadata.
|
|
* @param transfer_ownership If set to true, Numpy array will be responsible
|
|
* for freeing the data.
|
|
*
|
|
* @return Numpy array
|
|
*/
|
|
static inline PyObject* dmat_to_ndarray(dmat* mat,bool transfer_ownership) {
|
|
dbgassert(mat,NULLPTRDEREF);
|
|
dbgassert(mat->_data,NULLPTRDEREF);
|
|
/* fprintf(stderr, "Enter dmat_to_ndarray\n"); */
|
|
|
|
// Dimensions given in wrong order, as mat is
|
|
// Fortran-contiguous. Later on we transpose the result. This is
|
|
// more easy than using the PyArray_New syntax.
|
|
PyObject* arr = data_to_ndarray(mat->_data,
|
|
mat->n_rows,
|
|
mat->n_cols,
|
|
LASP_NUMPY_FLOAT_TYPE,
|
|
transfer_ownership,
|
|
true); // Fortran-contiguous
|
|
|
|
if(transfer_ownership) {
|
|
mat->_foreign_data = true;
|
|
}
|
|
|
|
if(!arr) {
|
|
WARN("Array creation failure");
|
|
feTRACE(15);
|
|
return NULL;
|
|
}
|
|
/* fprintf(stderr, "Exit dmat_to_ndarray\n"); */
|
|
|
|
return arr;
|
|
}
|
|
|
|
|
|
#endif // LASP_PYTHON_H
|
|
//////////////////////////////////////////////////////////////////////
|