1 /******************************************************************************
2  *
3  * MantaFlow fluid solver framework
4  * Copyright 2017 Steffen Wiewel, Moritz Baecher, Rachel Chu
5  *
6  * This program is free software, distributed under the terms of the
7  * Apache License, Version 2.0
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Convert mantaflow grids to/from numpy arrays
11  *
12  ******************************************************************************/
13 
14 #ifdef _PCONVERT_H
15 #  ifndef _NUMPYCONVERT_H
16 #    define _NUMPYCONVERT_H
17 
18 enum NumpyTypes {
19   N_BOOL = 0,
20   N_BYTE,
21   N_UBYTE,
22   N_SHORT,
23   N_USHORT,
24   N_INT,
25   N_UINT,
26   N_LONG,
27   N_ULONG,
28   N_LONGLONG,
29   N_ULONGLONG,
30   N_FLOAT,
31   N_DOUBLE,
32   N_LONGDOUBLE,
33   N_CFLOAT,
34   N_CDOUBLE,
35   N_CLONGDOUBLE,
36   N_OBJECT = 17,
37   N_STRING,
38   N_UNICODE,
39   N_VOID,
40   /*
41    * New 1.6 types appended, may be integrated
42    * into the above in 2.0.
43    */
44   N_DATETIME,
45   N_TIMEDELTA,
46   N_HALF,
47 
48   N_NTYPES,
49   N_NOTYPE,
50   N_CHAR,          /* special flag */
51   N_USERDEF = 256, /* leave room for characters */
52 
53   /* The number of types not including the new 1.6 types */
54   N_NTYPES_ABI_COMPATIBLE = 21
55 };
56 
57 namespace Manta {
58 class PyArrayContainer {
59  public:
60   /// Constructors
61   PyArrayContainer(void *_pParentPyArray);
62   PyArrayContainer(const PyArrayContainer &_Other);
63   ~PyArrayContainer();
64   /// Operators
65   PyArrayContainer &operator=(const PyArrayContainer &_Other);
66 
67  private:
68   void ExtractData(void *_pParentPyArray);
69 
70  public:
71   void *pData;
72   NumpyTypes DataType;
73   unsigned int TotalSize;
74   std::vector<long> Dims;
75 
76  private:
77   void *pParentPyArray;
78 };
79 
80 // template<> PyArrayContainer* fromPyPtr<PyArrayContainer>(PyObject* obj, std::vector<void*>*
81 // tmp);
82 template<> PyArrayContainer fromPy<PyArrayContainer>(PyObject *obj);
83 }  // namespace Manta
84 
85 #  endif
86 #endif
87