Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72919 - sandbox/numpy/libs/numpy/example
From: seefeld_at_[hidden]
Date: 2011-07-05 10:20:59


Author: stefan
Date: 2011-07-05 10:20:57 EDT (Tue, 05 Jul 2011)
New Revision: 72919
URL: http://svn.boost.org/trac/boost/changeset/72919

Log:
Add example(s)
Added:
   sandbox/numpy/libs/numpy/example/
   sandbox/numpy/libs/numpy/example/Jamfile (contents, props changed)
   sandbox/numpy/libs/numpy/example/simple.cpp (contents, props changed)

Added: sandbox/numpy/libs/numpy/example/Jamfile
==============================================================================
--- (empty file)
+++ sandbox/numpy/libs/numpy/example/Jamfile 2011-07-05 10:20:57 EDT (Tue, 05 Jul 2011)
@@ -0,0 +1,23 @@
+# Copyright 2011 Stefan Seefeld.
+# Distributed under the Boost Software License, Version 1.0. (See
+# accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+import python ;
+
+use-project /boost/numpy : ../src ;
+project /boost/numpy/example ;
+
+lib boost_python ;
+
+
+#lib libxml2 : : <name>xml2 <search>/usr/lib/ ;
+
+#project : requirements
+# <include>/usr/include/libxml2
+# <include>../../..
+# <library>libxml2
+# <library>/boost/xml//boost_xml
+# ;
+
+exe simple : simple.cpp ../src//boost_numpy boost_python /python//python ;

Added: sandbox/numpy/libs/numpy/example/simple.cpp
==============================================================================
--- (empty file)
+++ sandbox/numpy/libs/numpy/example/simple.cpp 2011-07-05 10:20:57 EDT (Tue, 05 Jul 2011)
@@ -0,0 +1,30 @@
+// Copyright 2011 Stefan Seefeld.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/numpy.hpp>
+#include <iostream>
+
+namespace p = boost::python;
+namespace np = boost::numpy;
+
+int main(int argc, char **argv)
+{
+ // Initialize the Python runtime.
+ Py_Initialize();
+ // Initialize NumPy
+ np::initialize();
+ // Create a 3x3 shape...
+ p::tuple shape = p::make_tuple(3, 3);
+ // ...as well as a type for C++ float
+ np::dtype dtype = np::dtype::get_builtin<float>();
+ // Construct an array with the above shape and type
+ np::ndarray a = np::zeros(shape, dtype);
+ // Print the array
+ std::cout << "Original array:\n" << p::extract<char const *>(p::str(a)) << std::endl;
+ // Reshape the array into a 1D array
+ a = a.reshape(p::make_tuple(9));
+ // Print it again.
+ std::cout << "Reshaped array:\n" << p::extract<char const *>(p::str(a)) << std::endl;
+}


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