mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-26 05:50:32 +05:00
Merge branch 'array_iterator_python' into 'master'
array iterator to python See merge request !15
This commit is contained in:
commit
d98579fe6b
@ -60,6 +60,7 @@ namespace netgen
|
||||
T operator*() const { return ar[ind]; }
|
||||
T & operator*() { return ar[ind]; }
|
||||
bool operator != (ArrayIterator d2) { return ind != d2.ind; }
|
||||
bool operator == (ArrayIterator d2) { return ind == d2.ind; }
|
||||
};
|
||||
|
||||
|
||||
|
@ -20,6 +20,7 @@ namespace netgen
|
||||
template <typename T, int BASE = 0, typename TIND = int>
|
||||
void ExportArray (py::module &m)
|
||||
{
|
||||
using TA = Array<T,BASE,TIND>;
|
||||
string name = string("Array_") + typeid(T).name();
|
||||
py::class_<Array<T,BASE,TIND>>(m, name.c_str())
|
||||
.def ("__len__", [] ( Array<T,BASE,TIND> &self ) { return self.Size(); } )
|
||||
@ -31,6 +32,9 @@ void ExportArray (py::module &m)
|
||||
return self[i];
|
||||
}),
|
||||
py::return_value_policy::reference)
|
||||
.def("__iter__", [] ( TA & self) {
|
||||
return py::make_iterator (self.begin(),self.end());
|
||||
}, py::keep_alive<0,1>()) // keep array alive while iterator is used
|
||||
|
||||
;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user