Skip to content

add typedef to get element type of array_t #632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nbecker opened this issue Jan 31, 2017 · 3 comments
Closed

add typedef to get element type of array_t #632

nbecker opened this issue Jan 31, 2017 · 3 comments

Comments

@nbecker
Copy link

nbecker commented Jan 31, 2017

I believe this makes it a lot easier to write generic code using array_t

diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h
index c224bd4..5795347 100644
--- a/include/pybind11/numpy.h
+++ b/include/pybind11/numpy.h
@@ -563,6 +563,7 @@ protected:
 
 template <typename T, int ExtraFlags = array::forcecast> class array_t : public array {
 public:
+    typedef T el_t;
     array_t() : array(0, static_cast<const T *>(nullptr)) {}
     array_t(handle h, borrowed_t) : array(h, borrowed) { }
     array_t(handle h, stolen_t) : array(h, stolen) { }
@jagerman
Copy link
Member

Seems reasonable. Minor nitpick: maybe value_type rather than el_t?

@nbecker
Copy link
Author

nbecker commented Jan 31, 2017 via email

@aldanor
Copy link
Member

aldanor commented Jan 31, 2017

Looks reasonable.

dean0x7d added a commit to dean0x7d/pybind11 that referenced this issue Mar 13, 2017
dean0x7d added a commit that referenced this issue Mar 13, 2017
* Add value_type member alias to py::array_t (resolve #632)

* Use numpy scalar name in py::array_t function signatures (e.g. float32/64 instead of just float)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants