@@ -94,6 +94,7 @@ cdef extern from "pdal/PipelineExecutor.hpp" namespace "pdal":
9494 PipelineExecutor(string) except +
9595 const PipelineManager& getManagerConst() except +
9696 bool executed() except +
97+ void read() except +
9798 int execute() except +
9899 string getPipeline() except +
99100 string getMetadata() except +
@@ -102,63 +103,29 @@ cdef extern from "pdal/PipelineExecutor.hpp" namespace "pdal":
102103 void setLogLevel(int ) except +
103104
104105
106+ cdef extern from " StreamableExecutor.hpp" namespace " pdal::python" :
107+ cdef cppclass StreamableExecutor(PipelineExecutor):
108+ StreamableExecutor(string, int , int ) except +
109+ np.PyArrayObject* executeNext() except +
110+
111+
105112cdef extern from " PyArray.hpp" namespace " pdal::python" :
106113 cdef cppclass Array:
107114 Array(np.PyArrayObject* ) except +
108115
109116
110117cdef extern from " PyPipeline.hpp" namespace " pdal::python" :
111- void readPipeline(PipelineExecutor* , string) except +
112118 void addArrayReaders(PipelineExecutor* , vector[shared_ptr[Array]]) except +
113119 np.PyArrayObject* viewToNumpyArray(PointViewPtr) except +
114120 np.PyArrayObject* meshToNumpyArray(const TriangularMesh* ) except +
115121
116- cdef extern from " StreamableExecutor.hpp" namespace " pdal::python" :
117- cdef cppclass StreamableExecutor:
118- StreamableExecutor(const char * , int , int ) except +
119- np.PyArrayObject * executeNext() except +
120- bool validate() except +
121- string getMetadata() except +
122- string getPipeline() except +
123- string getSchema() except +
124- string getLog() except +
125- int getLogLevel() except +
126- int setLogLevel(int level) except +
127-
128-
129- cdef class PipelineIterator:
130- cdef int _chunk_size
131- cdef StreamableExecutor * _executor;
132-
133- def __cinit__ (self , unicode json , list arrays = None , int chunk_size = 10000 , int prefetch = 0 ):
134- self ._chunk_size
135- self ._executor = new StreamableExecutor(json.encode(" UTF-8" ), chunk_size, prefetch)
136- # self._add_arrays(arrays)
137-
138- property chunk_size :
139- def __get__ (self ):
140- return self ._chunk_size
141-
142- def validate (self ):
143- return self ._executor.validate()
144-
145- def __iter__ (self ):
146- while True :
147- arrPtr = self ._executor.executeNext()
148- if arrPtr is NULL :
149- break
150- arr = < object > arrPtr
151- Py_DECREF(arr)
152- yield arr
153-
154122
155123cdef class Pipeline:
156- cdef unique_ptr[PipelineExecutor ] _executor
124+ cdef unique_ptr[StreamableExecutor ] _executor
157125 cdef vector[shared_ptr[Array]] _inputs
158126 cdef int _loglevel
159-
160- def execute (self ):
161- return self ._get_executor().execute()
127+ cdef int _chunk_size
128+ cdef int _prefetch
162129
163130 # ========= writeable properties to be set before execution ===========================
164131
@@ -182,6 +149,26 @@ cdef class Pipeline:
182149 self ._loglevel = value
183150 self ._del_executor()
184151
152+ @property
153+ def chunk_size (self ):
154+ return self ._chunk_size
155+
156+ @chunk_size.setter
157+ def chunk_size (self , value ):
158+ assert value > 0
159+ self ._chunk_size = value
160+ self ._del_executor()
161+
162+ @property
163+ def prefetch (self ):
164+ return self ._prefetch
165+
166+ @prefetch.setter
167+ def prefetch (self , value ):
168+ assert value >= 0
169+ self ._prefetch = value
170+ self ._del_executor()
171+
185172 # ========= readable properties to be read after execution ============================
186173
187174 @property
@@ -222,6 +209,21 @@ cdef class Pipeline:
222209 Py_DECREF(output[- 1 ])
223210 return output
224211
212+ # ========= execution methods =========================================================
213+
214+ def execute (self ):
215+ return self ._get_executor().execute()
216+
217+ def __iter__ (self ):
218+ cdef StreamableExecutor* executor = self ._get_executor()
219+ while True :
220+ arr_ptr = executor.executeNext()
221+ if arr_ptr is NULL :
222+ break
223+ arr = < object > arr_ptr
224+ Py_DECREF(arr)
225+ yield arr
226+
225227 # ========= non-public properties & methods ===========================================
226228
227229 def _get_json (self ):
@@ -237,12 +239,12 @@ cdef class Pipeline:
237239 def _del_executor (self ):
238240 self ._executor.reset()
239241
240- cdef PipelineExecutor * _get_executor(self ) except NULL :
242+ cdef StreamableExecutor * _get_executor(self ) except NULL :
241243 if not self ._executor:
242- json = self ._get_json()
243- executor = new PipelineExecutor(json )
244+ executor = new StreamableExecutor( self ._get_json(),
245+ self ._chunk_size, self ._prefetch )
244246 executor.setLogLevel(self ._loglevel)
245- readPipeline( executor, json )
247+ executor.read( )
246248 addArrayReaders(executor, self ._inputs)
247249 self ._executor.reset(executor)
248250 return self ._executor.get()
0 commit comments