\doxysection{Py\+Array.\+hpp}
\hypertarget{PyArray_8hpp_source}{}\label{PyArray_8hpp_source}\index{/home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/PyArray.hpp@{/home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/PyArray.hpp}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ }
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#ifndef\ GYM\_PCB\_PYARRAY\_H}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#define\ GYM\_PCB\_PYARRAY\_H}}
\DoxyCodeLine{00004\ }
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#include\ "{}Py.hpp"{}}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#include\ <vector>}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ \textcolor{keyword}{namespace\ }py\ \{}
\DoxyCodeLine{00009\ }
\DoxyCodeLine{00010\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ \textcolor{keyword}{class\ }NPArray}
\DoxyCodeLine{00011\ \{}
\DoxyCodeLine{00012\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00013\ \ \ \ \ \textcolor{keyword}{static}\ NPArray<T>\ *create(PyObject\ *);}
\DoxyCodeLine{00014\ \ \ \ \ NPArray()\ :\ mPy(0)\ \{\ \}}
\DoxyCodeLine{00015\ \ \ \ \ NPArray<T>\&\ operator=(\textcolor{keyword}{const}\ NPArray<T>\ \&avoid)\ \{\ assert(!avoid.mPy);\ mPy\ =\ 0;\ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};\ \}}
\DoxyCodeLine{00016\ \ \ \ \ NPArray<T>\&\ operator=(NPArray<T>\ \&\&move)\ \{\ own(move.mPy);\ move.mPy\ =\ 0;\ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};\ \}}
\DoxyCodeLine{00017\ \ \ \ \ NPArray(\textcolor{keyword}{const}\ NPArray<T>\ \&avoid)\ :\ mPy(0)\ \{\ assert(!avoid.mPy);\ \}}
\DoxyCodeLine{00018\ \ \ \ \ NPArray(NPArray<T>\ \&\&move)\ :\ mPy(move.mPy)\ \{\ move.mPy\ =\ 0;\ \}}
\DoxyCodeLine{00019\ \ \ \ \ NPArray(\textcolor{keyword}{const}\ std::vector<T>\&);}
\DoxyCodeLine{00020\ \ \ \ \ NPArray(\textcolor{keyword}{const}\ std::vector<T>\&,\ npy\_intp\ d1,\ npy\_intp\ d2);}
\DoxyCodeLine{00021\ \ \ \ \ NPArray(T\ *,\ npy\_intp\ \textcolor{keyword}{const}\ *dims,\ uint\ num\_dims);}
\DoxyCodeLine{00022\ \ \ \ \ NPArray(T\ *,\ npy\_intp\ d1);}
\DoxyCodeLine{00023\ \ \ \ \ NPArray(T\ *,\ npy\_intp\ d1,\ npy\_intp\ d2);}
\DoxyCodeLine{00024\ \ \ \ \ NPArray(T\ *,\ npy\_intp\ d1,\ npy\_intp\ d2,\ npy\_intp\ d3);}
\DoxyCodeLine{00025\ \ \ \ \ NPArray(T\ *,\ npy\_intp\ d1,\ npy\_intp\ d2,\ npy\_intp\ d3,\ npy\_intp\ d4);}
\DoxyCodeLine{00026\ \ \ \ \ NPArray(PyObject\ *py)\ :\ mPy(0)\ \{\ own(py);\ Assert();\ \}}
\DoxyCodeLine{00027\ \ \ \ \ \textcolor{keywordtype}{bool}\ own(PyObject\ *);}
\DoxyCodeLine{00028\ \ \ \ \ \textcolor{keywordtype}{bool}\ own(PyArrayObject\ *);}
\DoxyCodeLine{00029\ \ \ \ \ NPArray<T>\&\ ownData();}
\DoxyCodeLine{00030\ \ \ \ \ \string~NPArray()\ \{\ own((PyArrayObject\ *)0);\ \}}
\DoxyCodeLine{00031\ \ \ \ \ \textcolor{keywordtype}{bool}\ valid()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ mPy;\ \}}
\DoxyCodeLine{00032\ \ \ \ \ \textcolor{keywordtype}{bool}\ isPacked()\ \textcolor{keyword}{const};}
\DoxyCodeLine{00033\ \ \ \ \ \textcolor{keywordtype}{void}\ Assert()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{if}\ (!valid())\ \textcolor{keywordflow}{throw}\ std::runtime\_error(\textcolor{stringliteral}{"{}Invalid\ numpy\ array"{}});\ \}}
\DoxyCodeLine{00034\ \ \ \ \ PyObject\ *release()\ \{\ \textcolor{keyword}{auto}\ rv\ =\ py();\ mPy\ =\ 0;\ \textcolor{keywordflow}{return}\ rv;\ \}}
\DoxyCodeLine{00035\ \ \ \ \ PyObject\ *py()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ \textcolor{keyword}{reinterpret\_cast<}PyObject\ *\textcolor{keyword}{>}(mPy);\ \}}
\DoxyCodeLine{00036\ \ \ \ \ PyArrayObject\ *pyArray()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ mPy;\ \}}
\DoxyCodeLine{00037\ \ \ \ \ T\ *data()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ \textcolor{keyword}{static\_cast<}T\ *\textcolor{keyword}{>}(PyArray\_DATA(mPy));\ \}}
\DoxyCodeLine{00038\ \ \ \ \ intptr\_t\ count()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ PyArray\_SIZE(mPy);\ \}}
\DoxyCodeLine{00039\ \ \ \ \ intptr\_t\ stride(uint\ d)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ PyArray\_STRIDE(mPy,\ d);\ \}}
\DoxyCodeLine{00040\ \ \ \ \ intptr\_t\ size()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ PyArray\_NBYTES(mPy);\ \}}
\DoxyCodeLine{00041\ \ \ \ \ uint\ dim(uint\ d)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ PyArray\_DIM(mPy,\ d);\ \}}
\DoxyCodeLine{00042\ \ \ \ \ uint\ degree()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ PyArray\_NDIM(mPy);\ \}}
\DoxyCodeLine{00043\ \ \ \ \ T\ operator()(uint\ x)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ *(T\ *)PyArray\_GETPTR1(mPy,\ x);\ \}}
\DoxyCodeLine{00044\ \ \ \ \ T\ operator()(uint\ x,\ uint\ y)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ *(T\ *)PyArray\_GETPTR2(mPy,\ x,\ y);\ \}}
\DoxyCodeLine{00045\ \ \ \ \ T\ operator()(uint\ x,\ uint\ y,\ uint\ z)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ *(T\ *)PyArray\_GETPTR3(mPy,\ x,\ y,\ z);\ \}}
\DoxyCodeLine{00046\ \ \ \ \ T\ operator()(uint\ x,\ uint\ y,\ uint\ z,\ uint\ i)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ *(T\ *)PyArray\_GETPTR4(mPy,\ x,\ y,\ z,\ i);\ \}}
\DoxyCodeLine{00047\ \ \ \ \ \textcolor{keywordtype}{void}\ copyto(std::vector<T>\&)\ \textcolor{keyword}{const};}
\DoxyCodeLine{00048\ \ \ \ \ std::vector<T>\ vector()\textcolor{keyword}{\ const\ }\{\ std::vector<T>\ v;\ copyto(v);\ \textcolor{keywordflow}{return}\ v;\ \}}
\DoxyCodeLine{00049\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ checkAPI()\ \{\ assert(PY\_ARRAY\_UNIQUE\_SYMBOL);\ \}}
\DoxyCodeLine{00050\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{bool}\ checkType(PyArrayObject\ *);}
\DoxyCodeLine{00051\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}\ classTypenum();}
\DoxyCodeLine{00052\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00053\ \ \ \ \ PyArrayObject\ *mPy;}
\DoxyCodeLine{00054\ \};}
\DoxyCodeLine{00055\ }
\DoxyCodeLine{00056\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ NPArray<T>::NPArray(T\ *data,\ npy\_intp\ \textcolor{keyword}{const}\ *dims,\ uint\ num\_dims)}
\DoxyCodeLine{00057\ \{}
\DoxyCodeLine{00058\ \ \ \ \ checkAPI();}
\DoxyCodeLine{00059\ \ \ \ \ mPy\ =\ \textcolor{keyword}{reinterpret\_cast<}PyArrayObject\ *\textcolor{keyword}{>}(PyArray\_SimpleNewFromData(num\_dims,\ dims,\ classTypenum(),\ data));}
\DoxyCodeLine{00060\ \}}
\DoxyCodeLine{00061\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ NPArray<T>::NPArray(\textcolor{keyword}{const}\ std::vector<T>\ \&v)}
\DoxyCodeLine{00062\ \{}
\DoxyCodeLine{00063\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ size\ =\ v.size()\ *\ \textcolor{keyword}{sizeof}(T);}
\DoxyCodeLine{00064\ \ \ \ \ \textcolor{keyword}{const}\ npy\_intp\ dims[1]\ =\ \{\ (uint)v.size()\ \};}
\DoxyCodeLine{00065\ \ \ \ \ checkAPI();}
\DoxyCodeLine{00066\ \ \ \ \ \textcolor{keyword}{auto}\ data\ =\ (T\ *)malloc(size);}
\DoxyCodeLine{00067\ \ \ \ \ std::memcpy(data,\ v.data(),\ size);}
\DoxyCodeLine{00068\ \ \ \ \ mPy\ =\ \textcolor{keyword}{reinterpret\_cast<}PyArrayObject\ *\textcolor{keyword}{>}(PyArray\_SimpleNewFromData(1,\ dims,\ classTypenum(),\ data));}
\DoxyCodeLine{00069\ \ \ \ \ ownData();}
\DoxyCodeLine{00070\ \}}
\DoxyCodeLine{00071\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ NPArray<T>::NPArray(\textcolor{keyword}{const}\ std::vector<T>\ \&v,\ npy\_intp\ d1,\ npy\_intp\ d2)}
\DoxyCodeLine{00072\ \{}
\DoxyCodeLine{00073\ \ \ \ \ \textcolor{keyword}{auto}\ srcSize\ =\ v.size()\ *\ \textcolor{keyword}{sizeof}(T);}
\DoxyCodeLine{00074\ \ \ \ \ \textcolor{keyword}{auto}\ dstSize\ =\ d1\ *\ d2\ *\ \textcolor{keyword}{sizeof}(T);}
\DoxyCodeLine{00075\ \ \ \ \ assert(srcSize\ ==\ dstSize);}
\DoxyCodeLine{00076\ \ \ \ \ \textcolor{keyword}{auto}\ data\ =\ (T\ *)malloc(dstSize);}
\DoxyCodeLine{00077\ \ \ \ \ std::memcpy(data,\ v.data(),\ std::min(srcSize,\ dstSize));}
\DoxyCodeLine{00078\ \ \ \ \ \textcolor{keyword}{const}\ npy\_intp\ dims[2]\ =\ \{\ d1,\ d2\ \};}
\DoxyCodeLine{00079\ \ \ \ \ checkAPI();}
\DoxyCodeLine{00080\ \ \ \ \ mPy\ =\ \textcolor{keyword}{reinterpret\_cast<}PyArrayObject\ *\textcolor{keyword}{>}(PyArray\_SimpleNewFromData(2,\ dims,\ classTypenum(),\ data));}
\DoxyCodeLine{00081\ \ \ \ \ ownData();}
\DoxyCodeLine{00082\ \}}
\DoxyCodeLine{00083\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ NPArray<T>::NPArray(T\ *data,\ npy\_intp\ d1)}
\DoxyCodeLine{00084\ \{}
\DoxyCodeLine{00085\ \ \ \ \ checkAPI();}
\DoxyCodeLine{00086\ \ \ \ \ mPy\ =\ \textcolor{keyword}{reinterpret\_cast<}PyArrayObject\ *\textcolor{keyword}{>}(PyArray\_SimpleNewFromData(1,\ \&d1,\ classTypenum(),\ data));}
\DoxyCodeLine{00087\ \}}
\DoxyCodeLine{00088\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ NPArray<T>::NPArray(T\ *data,\ npy\_intp\ d1,\ npy\_intp\ d2)}
\DoxyCodeLine{00089\ \{}
\DoxyCodeLine{00090\ \ \ \ \ \textcolor{keyword}{const}\ npy\_intp\ dims[2]\ =\ \{\ d1,\ d2\ \};}
\DoxyCodeLine{00091\ \ \ \ \ checkAPI();}
\DoxyCodeLine{00092\ \ \ \ \ mPy\ =\ \textcolor{keyword}{reinterpret\_cast<}PyArrayObject\ *\textcolor{keyword}{>}(PyArray\_SimpleNewFromData(2,\ dims,\ classTypenum(),\ data));}
\DoxyCodeLine{00093\ \}}
\DoxyCodeLine{00094\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ NPArray<T>::NPArray(T\ *data,\ npy\_intp\ d1,\ npy\_intp\ d2,\ npy\_intp\ d3)}
\DoxyCodeLine{00095\ \{}
\DoxyCodeLine{00096\ \ \ \ \ \textcolor{keyword}{const}\ npy\_intp\ dims[3]\ =\ \{\ d1,\ d2,\ d3\ \};}
\DoxyCodeLine{00097\ \ \ \ \ checkAPI();}
\DoxyCodeLine{00098\ \ \ \ \ mPy\ =\ \textcolor{keyword}{reinterpret\_cast<}PyArrayObject\ *\textcolor{keyword}{>}(PyArray\_SimpleNewFromData(3,\ dims,\ classTypenum(),\ data));}
\DoxyCodeLine{00099\ \}}
\DoxyCodeLine{00100\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ NPArray<T>::NPArray(T\ *data,\ npy\_intp\ d1,\ npy\_intp\ d2,\ npy\_intp\ d3,\ npy\_intp\ d4)}
\DoxyCodeLine{00101\ \{}
\DoxyCodeLine{00102\ \ \ \ \ \textcolor{keyword}{const}\ npy\_intp\ dims[4]\ =\ \{\ d1,\ d2,\ d3,\ d4\ \};}
\DoxyCodeLine{00103\ \ \ \ \ checkAPI();}
\DoxyCodeLine{00104\ \ \ \ \ mPy\ =\ \textcolor{keyword}{reinterpret\_cast<}PyArrayObject\ *\textcolor{keyword}{>}(PyArray\_SimpleNewFromData(4,\ dims,\ classTypenum(),\ data));}
\DoxyCodeLine{00105\ \}}
\DoxyCodeLine{00106\ }
\DoxyCodeLine{00107\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ \_capsuleDtor(PyObject\ *capsule)}
\DoxyCodeLine{00108\ \{}
\DoxyCodeLine{00109\ \ \ \ \ std::free(PyCapsule\_GetPointer(capsule,\ 0));}
\DoxyCodeLine{00110\ \}}
\DoxyCodeLine{00111\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ \mbox{\hyperlink{classpy_1_1NPArray}{NPArray<T>}}\&\ NPArray<T>::ownData()}
\DoxyCodeLine{00112\ \{}
\DoxyCodeLine{00113\ \ \ \ \ \textcolor{keywordflow}{if}\ (!PyArray\_BASE(mPy))}
\DoxyCodeLine{00114\ \ \ \ \ \ \ \ \ PyArray\_SetBaseObject(mPy,\ PyCapsule\_New(data(),\ 0,\ \_capsuleDtor));}
\DoxyCodeLine{00115\ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00116\ \}}
\DoxyCodeLine{00117\ }
\DoxyCodeLine{00118\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ \mbox{\hyperlink{classpy_1_1NPArray}{NPArray<T>}}\ *NPArray<T>::create(PyObject\ *py)}
\DoxyCodeLine{00119\ \{}
\DoxyCodeLine{00120\ \ \ \ \ \textcolor{keywordflow}{if}\ (py\ \&\&\ PyArray\_Check(py)\ \&\&\ checkType(\textcolor{keyword}{reinterpret\_cast<}PyArrayObject\ *\textcolor{keyword}{>}(py)))}
\DoxyCodeLine{00121\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{new}\ \mbox{\hyperlink{classpy_1_1NPArray}{NPArray}}(py);}
\DoxyCodeLine{00122\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00123\ \}}
\DoxyCodeLine{00124\ }
\DoxyCodeLine{00125\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ \textcolor{keywordtype}{bool}\ NPArray<T>::own(PyArrayObject\ *py)}
\DoxyCodeLine{00126\ \{}
\DoxyCodeLine{00127\ \ \ \ \ checkAPI();}
\DoxyCodeLine{00128\ \ \ \ \ \textcolor{keywordflow}{if}\ (mPy)}
\DoxyCodeLine{00129\ \ \ \ \ \ \ \ \ Py\_DECREF(mPy);}
\DoxyCodeLine{00130\ \ \ \ \ mPy\ =\ (py\ \&\&\ checkType(py))\ ?\ py\ :\ 0;}
\DoxyCodeLine{00131\ \ \ \ \ \textcolor{keywordflow}{return}\ mPy;}
\DoxyCodeLine{00132\ \}}
\DoxyCodeLine{00133\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ \textcolor{keywordtype}{bool}\ NPArray<T>::own(PyObject\ *py)}
\DoxyCodeLine{00134\ \{}
\DoxyCodeLine{00135\ \ \ \ \ checkAPI();}
\DoxyCodeLine{00136\ \ \ \ \ \textcolor{keywordflow}{if}\ (mPy)}
\DoxyCodeLine{00137\ \ \ \ \ \ \ \ \ Py\_DECREF(mPy);}
\DoxyCodeLine{00138\ \ \ \ \ mPy\ =\ (py\ \&\&\ PyArray\_Check(py))\ ?\ \textcolor{keyword}{reinterpret\_cast<}PyArrayObject\ *\textcolor{keyword}{>}(py)\ :\ 0;}
\DoxyCodeLine{00139\ \ \ \ \ \textcolor{keywordflow}{if}\ (mPy\ \&\&\ !checkType(mPy))}
\DoxyCodeLine{00140\ \ \ \ \ \ \ \ \ mPy\ =\ 0;}
\DoxyCodeLine{00141\ \ \ \ \ \textcolor{keywordflow}{return}\ mPy;}
\DoxyCodeLine{00142\ \}}
\DoxyCodeLine{00143\ }
\DoxyCodeLine{00144\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ \textcolor{keywordtype}{int}\ NPArray<T>::classTypenum()}
\DoxyCodeLine{00145\ \{}
\DoxyCodeLine{00146\ \ \ \ \ \textcolor{keywordflow}{if}\ \textcolor{keyword}{constexpr}\ (std::is\_same\_v<float,\ T>)}
\DoxyCodeLine{00147\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NPY\_FLOAT32;}
\DoxyCodeLine{00148\ \ \ \ \ \textcolor{keywordflow}{if}\ \textcolor{keyword}{constexpr}\ (std::is\_same\_v<double,\ T>)}
\DoxyCodeLine{00149\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NPY\_FLOAT64;}
\DoxyCodeLine{00150\ \ \ \ \ \textcolor{keywordflow}{if}\ \textcolor{keyword}{constexpr}\ (std::is\_same\_v<int32\_t,\ T>)}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NPY\_INT32;}
\DoxyCodeLine{00152\ \ \ \ \ \textcolor{keywordflow}{if}\ \textcolor{keyword}{constexpr}\ (std::is\_same\_v<uint32\_t,\ T>)}
\DoxyCodeLine{00153\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NPY\_UINT32;}
\DoxyCodeLine{00154\ \ \ \ \ \textcolor{keywordflow}{if}\ \textcolor{keyword}{constexpr}\ (std::is\_same\_v<uint64\_t,\ T>)}
\DoxyCodeLine{00155\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NPY\_UINT64;}
\DoxyCodeLine{00156\ \ \ \ \ \textcolor{keywordflow}{if}\ \textcolor{keyword}{constexpr}\ (std::is\_same\_v<int8\_t,\ T>)}
\DoxyCodeLine{00157\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NPY\_INT8;}
\DoxyCodeLine{00158\ \ \ \ \ \textcolor{keywordflow}{if}\ \textcolor{keyword}{constexpr}\ (std::is\_same\_v<uint8\_t,\ T>)}
\DoxyCodeLine{00159\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NPY\_UBYTE;}
\DoxyCodeLine{00160\ \ \ \ \ \textcolor{keywordflow}{throw}\ std::runtime\_error(\textcolor{stringliteral}{"{}FIXME"{}});}
\DoxyCodeLine{00161\ \ \ \ \ \textcolor{keywordflow}{return}\ NPY\_VOID;}
\DoxyCodeLine{00162\ \}}
\DoxyCodeLine{00163\ }
\DoxyCodeLine{00164\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ \textcolor{keywordtype}{bool}\ NPArray<T>::checkType(PyArrayObject\ *py)}
\DoxyCodeLine{00165\ \{}
\DoxyCodeLine{00166\ \ \ \ \ \textcolor{keywordflow}{if}\ (PyArray\_TYPE(py)\ ==\ classTypenum())}
\DoxyCodeLine{00167\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{true};}
\DoxyCodeLine{00168\ \ \ \ \ \textcolor{keywordflow}{if}\ \textcolor{keyword}{constexpr}\ (std::is\_same\_v<uint8\_t,\ T>)}
\DoxyCodeLine{00169\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ PyArray\_TYPE(py)\ ==\ NPY\_BOOL\ ||}
\DoxyCodeLine{00170\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ PyArray\_TYPE(py)\ ==\ NPY\_BYTE\ ||}
\DoxyCodeLine{00171\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ PyArray\_TYPE(py)\ ==\ NPY\_UINT8;}
\DoxyCodeLine{00172\ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};}
\DoxyCodeLine{00173\ \}}
\DoxyCodeLine{00174\ }
\DoxyCodeLine{00175\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ \textcolor{keywordtype}{bool}\ NPArray<T>::isPacked()\textcolor{keyword}{\ const}}
\DoxyCodeLine{00176\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00177\ \ \ \ \ uint\ sz\ =\ \textcolor{keyword}{sizeof}(T);}
\DoxyCodeLine{00178\ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{int}\ d\ =\ degree()\ -\/\ 1;\ d\ >=\ 0;\ -\/-\/d)\ \{}
\DoxyCodeLine{00179\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (sz\ !=\ stride(d))}
\DoxyCodeLine{00180\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};}
\DoxyCodeLine{00181\ \ \ \ \ \ \ \ \ sz\ *=\ dim(d);}
\DoxyCodeLine{00182\ \ \ \ \ \}}
\DoxyCodeLine{00183\ \ \ \ \ \textcolor{keywordflow}{if}\ (size()\ !=\ sz)}
\DoxyCodeLine{00184\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};}
\DoxyCodeLine{00185\ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{true};}
\DoxyCodeLine{00186\ \}}
\DoxyCodeLine{00187\ }
\DoxyCodeLine{00188\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>\ \textcolor{keywordtype}{void}\ NPArray<T>::copyto(std::vector<T>\ \&v)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00189\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00190\ \ \ \ \ assert(isPacked());}
\DoxyCodeLine{00191\ \ \ \ \ v.resize(count());}
\DoxyCodeLine{00192\ \ \ \ \ std::memcpy(v.data(),\ data(),\ v.size()\ *\ \textcolor{keyword}{sizeof}(T));}
\DoxyCodeLine{00193\ \}}
\DoxyCodeLine{00194\ }
\DoxyCodeLine{00195\ \}\ \textcolor{comment}{//\ namespace\ py}}
\DoxyCodeLine{00196\ }
\DoxyCodeLine{00197\ \textcolor{keyword}{using\ }FloatNPArray\ =\ \mbox{\hyperlink{classpy_1_1NPArray}{py::NPArray<float>}};}
\DoxyCodeLine{00198\ }
\DoxyCodeLine{00199\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//\ GYM\_PCB\_PYARRAY\_H}}

\end{DoxyCode}
