3
0
mirror of https://github.com/triqs/dft_tools synced 2025-01-12 05:58:18 +01:00

arrays: to_python now raise exception when array is empty

- otherwise it was simply crashing .
- now raise a C++ exception
- adapted cython wrapper to catch it as a python exception
This commit is contained in:
Olivier Parcollet 2014-02-04 15:03:33 +01:00
parent 65ed3a8dc2
commit dd6b996e5d
2 changed files with 10 additions and 7 deletions

View File

@ -8,7 +8,7 @@ cdef extern from "<triqs/python_tools/array_interface.hpp>" namespace "triqs::ar
array operator -( array_view &) array operator -( array_view &)
array operator *( array_view &) array operator *( array_view &)
array operator /( array_view &) array operator /( array_view &)
object to_python() object to_python() except +
cdef cppclass array_view "triqs::arrays::array_c" [T,R] : cdef cppclass array_view "triqs::arrays::array_c" [T,R] :
array_view() array_view()
@ -18,7 +18,7 @@ cdef extern from "<triqs/python_tools/array_interface.hpp>" namespace "triqs::ar
array_view operator *( array_view &) array_view operator *( array_view &)
array_view operator /( array_view &) array_view operator /( array_view &)
void operator << (array_view &) void operator << (array_view &)
object to_python() object to_python() except +
int shape(int) int shape(int)
# bug in cython # bug in cython
#_lazy_expr operator()(_lazy_expr&) #_lazy_expr operator()(_lazy_expr&)
@ -36,7 +36,7 @@ cdef extern from "<triqs/python_tools/array_interface.hpp>" namespace "triqs::ar
matrix_view(matrix) matrix_view(matrix)
matrix_view(object) except + matrix_view(object) except +
void operator << (matrix_view &) void operator << (matrix_view &)
object to_python() object to_python() except +
cdef cppclass matrix "triqs::arrays::matrix" [T] : cdef cppclass matrix "triqs::arrays::matrix" [T] :
matrix() matrix()
@ -44,7 +44,7 @@ cdef extern from "<triqs/python_tools/array_interface.hpp>" namespace "triqs::ar
matrix operator +( matrix_view &) matrix operator +( matrix_view &)
matrix operator -( matrix_view &) matrix operator -( matrix_view &)
matrix operator /( matrix_view &) matrix operator /( matrix_view &)
object to_python() object to_python() except +
cdef matrix_view operator +( matrix_view & , matrix_view &) cdef matrix_view operator +( matrix_view & , matrix_view &)
cdef matrix_view operator -( matrix_view & , matrix_view &) cdef matrix_view operator -( matrix_view & , matrix_view &)
@ -58,7 +58,7 @@ cdef extern from "<triqs/python_tools/array_interface.hpp>" namespace "triqs::ar
tqa_vector operator -( tqa_vector_view &) tqa_vector operator -( tqa_vector_view &)
tqa_vector operator *( tqa_vector_view &) tqa_vector operator *( tqa_vector_view &)
tqa_vector operator /( tqa_vector_view &) tqa_vector operator /( tqa_vector_view &)
object to_python() object to_python() except +
cdef cppclass tqa_vector_view "triqs::arrays::vector_c" [T] : cdef cppclass tqa_vector_view "triqs::arrays::vector_c" [T] :
tqa_vector_view() tqa_vector_view()
@ -68,5 +68,5 @@ cdef extern from "<triqs/python_tools/array_interface.hpp>" namespace "triqs::ar
tqa_vector_view operator *(tqa_vector_view &) tqa_vector_view operator *(tqa_vector_view &)
tqa_vector_view operator /(tqa_vector_view &) tqa_vector_view operator /(tqa_vector_view &)
void operator << (tqa_vector_view &) void operator << (tqa_vector_view &)
object to_python() object to_python() except +

View File

@ -147,7 +147,10 @@ namespace triqs { namespace arrays {
storage_type & storage() {return storage_;} storage_type & storage() {return storage_;}
#ifdef TRIQS_WITH_PYTHON_SUPPORT #ifdef TRIQS_WITH_PYTHON_SUPPORT
PyObject * to_python() const { return numpy_interface::array_view_to_python(*this);} PyObject *to_python() const {
if (is_empty()) TRIQS_RUNTIME_ERROR << "Error : trying to return an empty array/matrix/vector to python";
return numpy_interface::array_view_to_python(*this);
}
#endif #endif
/// data_start is the starting point of the data of the object /// data_start is the starting point of the data of the object