@@ -48,60 +48,46 @@ namespace python
4848// PythonPointTable
4949
5050PythonPointTable::PythonPointTable (point_count_t limit, int prefetch) :
51- StreamPointTable (m_layout, limit), m_limit(limit), m_prefetch(prefetch),
51+ StreamPointTable (m_layout, limit), m_prefetch(prefetch),
5252 m_curArray (nullptr ), m_dtype(nullptr )
5353{}
5454
5555PythonPointTable::~PythonPointTable ()
56- {
57- py_destroy ();
58- }
59-
60- void PythonPointTable::finalize ()
61- {
62- BasePointTable::finalize ();
63- py_createDescriptor ();
64- m_curArray = py_createArray ();
65- }
66-
67- void PythonPointTable::py_destroy ()
6856{
6957 auto gil = PyGILState_Ensure ();
70-
7158 Py_XDECREF (m_dtype);
7259 Py_XDECREF (m_curArray);
73-
7460 PyGILState_Release (gil);
7561}
7662
77- PyArrayObject * PythonPointTable::py_createArray () const
63+ void PythonPointTable::finalize ()
7864{
79- auto gil = PyGILState_Ensure ();
80-
81- npy_intp size = (npy_intp)m_limit;
82- Py_INCREF (m_dtype);
83- PyArrayObject *arr = (PyArrayObject *)PyArray_NewFromDescr (&PyArray_Type, m_dtype,
84- 1 , &size, 0 , nullptr , NPY_ARRAY_CARRAY, nullptr );
85-
86- PyGILState_Release (gil);
87- return arr;
88- }
65+ BasePointTable::finalize ();
8966
90- void PythonPointTable::py_createDescriptor ()
91- {
67+ // create dtype
9268 auto gil = PyGILState_Ensure ();
93-
9469 if (_import_array () < 0 )
9570 std::cerr << " Could not import array!\n " ;
9671 PyObject *dtype_dict = py_buildNumpyDescriptor ();
9772 if (PyArray_DescrConverter (dtype_dict, &m_dtype) == NPY_FAIL)
98- m_dtype = nullptr ;
73+ throw pdal_error ( " Unable to create numpy dtype " ) ;
9974 Py_XDECREF (dtype_dict);
75+ PyGILState_Release (gil);
76+
77+ py_createArray ();
78+ }
10079
80+ void PythonPointTable::py_createArray ()
81+ {
82+ auto gil = PyGILState_Ensure ();
83+ npy_intp size = capacity ();
84+ Py_INCREF (m_dtype);
85+ m_curArray = (PyArrayObject *)PyArray_NewFromDescr (&PyArray_Type, m_dtype,
86+ 1 , &size, 0 , nullptr , NPY_ARRAY_CARRAY, nullptr );
10187 PyGILState_Release (gil);
10288}
10389
104- void PythonPointTable::py_resizeArray (int np)
90+ void PythonPointTable::py_resizeArray (point_count_t np)
10591{
10692 npy_intp sizes[1 ];
10793 sizes[0 ] = np;
@@ -187,7 +173,7 @@ void PythonPointTable::reset()
187173 if (!skip (idx))
188174 np++;
189175
190- if (np && np != m_limit )
176+ if (np && np != capacity () )
191177 py_resizeArray (np);
192178
193179 // This will keep putting arrays on the list until done, whether or not the consumer
@@ -199,7 +185,7 @@ void PythonPointTable::reset()
199185 if (np)
200186 {
201187 m_arrays.push (m_curArray);
202- m_curArray = py_createArray ();
188+ py_createArray ();
203189 m_producedCv.notify_one ();
204190 }
205191 while (m_arrays.size () > m_prefetch)
@@ -236,7 +222,7 @@ PyArrayObject *PythonPointTable::fetchArray()
236222
237223char *PythonPointTable::getPoint (PointId idx)
238224{
239- return (char *)PyArray_GETPTR1 (m_curArray, (npy_intp) idx);
225+ return (char *)PyArray_GETPTR1 (m_curArray, idx);
240226}
241227
242228
0 commit comments