Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73582 - sandbox/numpy/libs/numpy/example
From: ankitdaf_at_[hidden]
Date: 2011-08-06 17:13:14


Author: ankitdaf
Date: 2011-08-06 17:13:13 EDT (Sat, 06 Aug 2011)
New Revision: 73582
URL: http://svn.boost.org/trac/boost/changeset/73582

Log:
Added working custom dtype example
Text files modified:
   sandbox/numpy/libs/numpy/example/dtype.cpp | 12 ++++++++----
   1 files changed, 8 insertions(+), 4 deletions(-)

Modified: sandbox/numpy/libs/numpy/example/dtype.cpp
==============================================================================
--- sandbox/numpy/libs/numpy/example/dtype.cpp (original)
+++ sandbox/numpy/libs/numpy/example/dtype.cpp 2011-08-06 17:13:13 EDT (Sat, 06 Aug 2011)
@@ -29,12 +29,16 @@
   std::cout << "Original array:\n" << p::extract<char const *>(p::str(a)) << std::endl;
   // Print the datatype of the elements
   std::cout << "Datatype is:\n" << p::extract<char const *>(p::str(a.get_dtype())) << std::endl ;
- // Roundabout way of creating a user defined dtype. Fix this if possible
-/*
+ // Using user defined dtypes to create dtype and an array of the custom dtype
+ // First create a tuple with a variable name and its dtype, double, to create a custom dtype
   p::tuple for_custom_dtype = p::make_tuple("ha",dtype) ;
+ // The list needs to be created, because the constructor to create the custom dtype
+ // takes a list of (variable,variable_type) as an argument
   p::list list_for_dtype ;
   list_for_dtype.append(for_custom_dtype) ;
+ // Create the custom dtype
   np::dtype custom_dtype = np::dtype(list_for_dtype) ;
- np::ndarray new_array = np::zeros(shape,z);
-*/
+ // Create an ndarray with the custom dtype
+ np::ndarray new_array = np::zeros(shape,custom_dtype);
+
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk