mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-27 06:10:34 +05:00
array iterator to python
This commit is contained in:
parent
8e97d91912
commit
0a9abc1acc
@ -60,6 +60,7 @@ namespace netgen
|
|||||||
T operator*() const { return ar[ind]; }
|
T operator*() const { return ar[ind]; }
|
||||||
T & operator*() { return ar[ind]; }
|
T & operator*() { return ar[ind]; }
|
||||||
bool operator != (ArrayIterator d2) { return ind != d2.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>
|
template <typename T, int BASE = 0, typename TIND = int>
|
||||||
void ExportArray (py::module &m)
|
void ExportArray (py::module &m)
|
||||||
{
|
{
|
||||||
|
using TA = Array<T,BASE,TIND>;
|
||||||
string name = string("Array_") + typeid(T).name();
|
string name = string("Array_") + typeid(T).name();
|
||||||
py::class_<Array<T,BASE,TIND>>(m, name.c_str())
|
py::class_<Array<T,BASE,TIND>>(m, name.c_str())
|
||||||
.def ("__len__", [] ( Array<T,BASE,TIND> &self ) { return self.Size(); } )
|
.def ("__len__", [] ( Array<T,BASE,TIND> &self ) { return self.Size(); } )
|
||||||
@ -31,6 +32,9 @@ void ExportArray (py::module &m)
|
|||||||
return self[i];
|
return self[i];
|
||||||
}),
|
}),
|
||||||
py::return_value_policy::reference)
|
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