source: issm/oecreview/Archive/11841-11860/ISSM-11849-11850.diff

Last change on this file was 11991, checked in by Eric.Larour, 13 years ago

oecreview from 11518 to present

File size: 13.6 KB
RevLine 
[11991]1Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/TriMesh.cpp.bak
2===================================================================
3--- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/TriMesh.cpp.bak (revision 0)
4+++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/TriMesh.cpp.bak (revision 11850)
5@@ -0,0 +1,53 @@
6+#include <stdio.h>
7+using namespace std;
8+
9+void meshx(double* index,int n) {
10+ int i;
11+ for(i=0;i<n;i++){
12+ printf("%g\n",index[i]);
13+ }
14+}
15+
16+#include <boost/python.hpp>
17+#include <boost/python/module.hpp>
18+#include <boost/python/def.hpp>
19+using namespace boost::python;
20+
21+void FetchData(double** array,int* N,boost::python::list pythonlist){/*{{{*/
22+
23+ /*Get list size*/
24+ int n = boost::python::extract<int>(pythonlist.attr("__len__")());
25+
26+ /*Assign double array and populate*/
27+ double* clist = new double[n];
28+ for (int i=0;i<n;i++) clist[i] = extract<double>(pythonlist[i]);
29+
30+ /*Assign output pointers*/
31+ *array = clist;
32+ if(N) *N = n;
33+}/*}}}*/
34+
35+boost::python::list void mesh(boost::python::list INDEX){
36+
37+ boost::python::list output;
38+
39+ double *index=NULL;
40+ int n;
41+
42+ FetchData(&index,&n,INDEX);
43+
44+ /*Call x layer*/
45+ meshx(index,n);
46+
47+ /*Clean up*/
48+ delete index;
49+}
50+
51+
52+#include <boost/python/module.hpp>
53+#include <boost/python/def.hpp>
54+using namespace boost::python;
55+
56+BOOST_PYTHON_MODULE(TriMesh_ext){
57+ def("mesh",mesh);
58+}
59Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/Code.cpp
60===================================================================
61--- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/Code.cpp (revision 0)
62+++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/Code.cpp (revision 11850)
63@@ -0,0 +1,53 @@
64+/*Copyright 2006 Phil Austin (http:www.eos.ubc.ca/personal/paustin)
65+ Distributed under the Boost Software License, Version 1.0. (See
66+ accompanying file LICENSE_1_0.txt or copy at
67+http:www.boost.org/LICENSE_1_0.txt)
68+*/
69+
70+#define PY_ARRAY_UNIQUE_SYMBOL PyArrayHandle
71+#include "num_util.h"
72+#include <iostream>
73+
74+namespace { const char* rcsid = "$Id: simpletest.cpp,v 1.4 2006/07/05 22:55:16 phil Exp $"; }
75+
76+//send a dictionary with two arrays back to python
77+boost::python::dict testToPython(void){
78+ double ia[6] = {1,2,3,4,5,6};
79+ int ib[3] = {88,99,100};
80+ //construct two numpy arrays
81+ boost::python::numeric::array pyDoubles=num_util::makeNum(ia,6);
82+ boost::python::numeric::array pyInts=num_util::makeNum(ib,3);
83+ //pack them in a dictionary and return to python
84+ boost::python::dict retvals;
85+ retvals["myDoubles"]=pyDoubles;
86+ retvals["myInts"]=pyInts;
87+ return retvals;
88+}
89+
90+//get an array from python
91+void testFromPython(boost::python::numeric::array inValue){
92+ num_util::check_type(inValue, PyArray_DOUBLE);
93+ num_util::check_rank(inValue, 2);
94+ double* dataPtr = (double*) num_util::data(inValue);
95+ int theSize= num_util::size(inValue);
96+ std::cout << std::endl << "data values on c++ side: " << std::endl;
97+ for(int i=0;i < theSize;++i){
98+ std::cout << *(dataPtr + i) << std::endl;
99+ }
100+}
101+
102+BOOST_PYTHON_MODULE(simple_ext)
103+{
104+ import_array();
105+ boost::python::numeric::array::set_module_and_type("numpy", "ArrayType");
106+ //global doc string
107+ boost::python::scope().attr("RCSID") = rcsid;
108+ std::string str1;
109+ str1="docstring for module\n";
110+ boost::python::scope().attr("__doc__") = str1.c_str();
111+ str1 = "Doc string for testToPython\n";
112+ def("testToPython", testToPython,str1.c_str());
113+ str1 = "Doc string for testFromPython\n";
114+ def("testFromPython", testFromPython,str1.c_str());
115+}
116+
117Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/TriMesh.cpp
118===================================================================
119--- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/TriMesh.cpp (revision 0)
120+++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/TriMesh.cpp (revision 11850)
121@@ -0,0 +1,58 @@
122+#include <stdio.h>
123+using namespace std;
124+
125+void meshx(double* index,int n) {
126+ int i;
127+ for(i=0;i<n;i++){
128+ printf("%g\n",index[i]);
129+ }
130+}
131+
132+#include <boost/python.hpp>
133+#include <boost/python/module.hpp>
134+#include <boost/python/def.hpp>
135+using namespace boost::python;
136+
137+void FetchData(double** array,int* N,boost::python::list pythonlist){/*{{{*/
138+
139+ /*Get list size*/
140+ int n = boost::python::extract<int>(pythonlist.attr("__len__")());
141+
142+ /*Assign double array and populate*/
143+ double* clist = new double[n];
144+ for (int i=0;i<n;i++) clist[i] = extract<double>(pythonlist[i]);
145+
146+ /*Assign output pointers*/
147+ *array = clist;
148+ if(N) *N = n;
149+}/*}}}*/
150+
151+boost::python::list mesh(boost::python::list INDEX){
152+
153+ int i;
154+
155+ boost::python::list output;
156+
157+ double *index=NULL;
158+ int n;
159+
160+ FetchData(&index,&n,INDEX);
161+
162+ for(i=0;i<n;i++)output.append(index[i]);
163+
164+ /*Call x layer*/
165+ meshx(index,n);
166+
167+ /*Clean up*/
168+ delete index;
169+ return output;
170+}
171+
172+
173+#include <boost/python/module.hpp>
174+#include <boost/python/def.hpp>
175+using namespace boost::python;
176+
177+BOOST_PYTHON_MODULE(TriMesh){
178+ def("mesh",mesh);
179+}
180Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/Makefile
181===================================================================
182--- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/Makefile (revision 11849)
183+++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/Makefile (revision 11850)
184@@ -1,12 +1,11 @@
185-all: ice
186+all: TriMesh.so
187
188-ice:
189- g++ -bundle -bind \
190- -I$(ISSM_TIER)/externalpackages/boost/install/include \
191- -I/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m\
192- -L$(ISSM_TIER)/externalpackages/boost/install/lib -lboost_python \
193- -L/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/config-3.2m/ -lpython3.2 \
194- TriMeshmodule.cpp -o TriMesh.so
195
196+TriMesh.o: TriMesh.cpp
197+ g++ -I$(ISSM_TIER)/externalpackages/boost/install/include -I$(ISSM_TIER)/externalpackages/python/install/Python.framework/Versions/3.2/include/python3.2 -c -o TriMesh.o TriMesh.cpp
198+
199+TriMesh.so: TriMesh.o
200+ g++ -dynamiclib -o TriMesh.so TriMesh.o -L$(ISSM_TIER)/externalpackages/boost/install/lib -lboost_python -L$(ISSM_TIER)/externalpackages/python/install/Python.framework/Versions/3.2/lib -L$(ISSM_TIER)/externalpackages/python/install/Python.framework/Versions/3.2/lib/python3.2/config -lpython3.2
201+
202 clean:
203- rm TriMesh.so
204+ rm TriMesh.so TriMesh.o
205Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/test.py
206===================================================================
207--- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/test.py (revision 0)
208+++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/test.py (revision 11850)
209@@ -0,0 +1,5 @@
210+from TriMesh import *
211+from numpy import *
212+a=array([1.0,2.0]);
213+
214+mesh(a)
215Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp.bak
216===================================================================
217--- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp.bak (revision 0)
218+++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp.bak (revision 11850)
219@@ -0,0 +1,53 @@
220+#include <stdio.h>
221+using namespace std;
222+
223+void meshx(double* index,int n) {
224+ int i;
225+ for(i=0;i<n;i++){
226+ printf("%g\n",index[i]);
227+ }
228+}
229+
230+#include <boost/python.hpp>
231+#include <boost/python/module.hpp>
232+#include <boost/python/def.hpp>
233+using namespace boost::python;
234+
235+void FetchData(double** array,int* N,boost::python::list pythonlist){/*{{{*/
236+
237+ /*Get list size*/
238+ int n = boost::python::extract<int>(pythonlist.attr("__len__")());
239+
240+ /*Assign double array and populate*/
241+ double* clist = new double[n];
242+ for (int i=0;i<n;i++) clist[i] = extract<double>(pythonlist[i]);
243+
244+ /*Assign output pointers*/
245+ *array = clist;
246+ if(N) *N = n;
247+}/*}}}*/
248+
249+boost::python::list void mesh(boost::python::list INDEX){
250+
251+ boost::python::list output;
252+
253+ double *index=NULL;
254+ int n;
255+
256+ FetchData(&index,&n,INDEX);
257+
258+ /*Call x layer*/
259+ meshx(index,n);
260+
261+ /*Clean up*/
262+ delete index;
263+}
264+
265+
266+#include <boost/python/module.hpp>
267+#include <boost/python/def.hpp>
268+using namespace boost::python;
269+
270+BOOST_PYTHON_MODULE(TriMesh_ext){
271+ def("mesh",mesh);
272+}
273Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp.bak2
274===================================================================
275--- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp.bak2 (revision 0)
276+++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp.bak2 (revision 11850)
277@@ -0,0 +1,33 @@
278+#include <stdio.h>
279+using namespace std;
280+
281+#include <boost/python.hpp>
282+#include <boost/python/module.hpp>
283+#include <boost/python/def.hpp>
284+//#include "num_util.h"
285+
286+using namespace boost::python;
287+
288+void mesh(boost::python::numeric::array array){
289+
290+ int n;
291+ double a;
292+
293+ n = boost::python::extract<int>(array.attr("__len__")());
294+
295+ for(int i=0;i < n;++i){
296+ a=extract<double>(array[i]);
297+ printf("%g\n",a);
298+ }
299+
300+}
301+
302+
303+#include <boost/python/module.hpp>
304+#include <boost/python/def.hpp>
305+using namespace boost::python;
306+
307+BOOST_PYTHON_MODULE(TriMesh){
308+ boost::python::numeric::array::set_module_and_type( "numpy", "ndarray");
309+ def("mesh",mesh);
310+}
311Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Code.cpp
312===================================================================
313--- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Code.cpp (revision 0)
314+++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Code.cpp (revision 11850)
315@@ -0,0 +1,53 @@
316+/*Copyright 2006 Phil Austin (http:www.eos.ubc.ca/personal/paustin)
317+ Distributed under the Boost Software License, Version 1.0. (See
318+ accompanying file LICENSE_1_0.txt or copy at
319+http:www.boost.org/LICENSE_1_0.txt)
320+*/
321+
322+#define PY_ARRAY_UNIQUE_SYMBOL PyArrayHandle
323+#include "num_util.h"
324+#include <iostream>
325+
326+namespace { const char* rcsid = "$Id: simpletest.cpp,v 1.4 2006/07/05 22:55:16 phil Exp $"; }
327+
328+//send a dictionary with two arrays back to python
329+boost::python::dict testToPython(void){
330+ double ia[6] = {1,2,3,4,5,6};
331+ int ib[3] = {88,99,100};
332+ //construct two numpy arrays
333+ boost::python::numeric::array pyDoubles=num_util::makeNum(ia,6);
334+ boost::python::numeric::array pyInts=num_util::makeNum(ib,3);
335+ //pack them in a dictionary and return to python
336+ boost::python::dict retvals;
337+ retvals["myDoubles"]=pyDoubles;
338+ retvals["myInts"]=pyInts;
339+ return retvals;
340+}
341+
342+//get an array from python
343+void testFromPython(boost::python::numeric::array inValue){
344+ num_util::check_type(inValue, PyArray_DOUBLE);
345+ num_util::check_rank(inValue, 2);
346+ double* dataPtr = (double*) num_util::data(inValue);
347+ int theSize= num_util::size(inValue);
348+ std::cout << std::endl << "data values on c++ side: " << std::endl;
349+ for(int i=0;i < theSize;++i){
350+ std::cout << *(dataPtr + i) << std::endl;
351+ }
352+}
353+
354+BOOST_PYTHON_MODULE(simple_ext)
355+{
356+ import_array();
357+ boost::python::numeric::array::set_module_and_type("numpy", "ArrayType");
358+ //global doc string
359+ boost::python::scope().attr("RCSID") = rcsid;
360+ std::string str1;
361+ str1="docstring for module\n";
362+ boost::python::scope().attr("__doc__") = str1.c_str();
363+ str1 = "Doc string for testToPython\n";
364+ def("testToPython", testToPython,str1.c_str());
365+ str1 = "Doc string for testFromPython\n";
366+ def("testFromPython", testFromPython,str1.c_str());
367+}
368+
369Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp
370===================================================================
371--- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp (revision 0)
372+++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp (revision 11850)
373@@ -0,0 +1,41 @@
374+#include <stdio.h>
375+using namespace std;
376+
377+#include <boost/python.hpp>
378+#include <boost/python/module.hpp>
379+#include <boost/python/def.hpp>
380+#include <numpy/arrayobject.h>
381+
382+using namespace boost::python;
383+
384+void mesh(boost::python::numeric::array array){
385+//void mesh(boost::python::object array){
386+
387+ int i;
388+ double* b=NULL;
389+ int nd,M,N;
390+ int* dims=NULL;
391+ PyArrayObject* a = (PyArrayObject*)array.ptr();
392+ b=(double*)PyArray_DATA(a);
393+ nd=PyArray_NDIM(a);
394+ dims=(int*)PyArray_DIMS(a);
395+ M=dims[0];
396+
397+ printf("nd: %i M: %i\n",nd,M);
398+ for(i=0;i<M;i++){
399+ printf("%g\n",b[i]);
400+ }
401+
402+
403+}
404+
405+
406+#include <boost/python/module.hpp>
407+#include <boost/python/def.hpp>
408+using namespace boost::python;
409+
410+BOOST_PYTHON_MODULE(TriMesh){
411+ boost::python::numeric::array::set_module_and_type( "numpy", "ndarray");
412+ //boost::python::numeric::array::set_module_and_type( "numpy", "array");
413+ def("mesh",mesh);
414+}
415Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Makefile
416===================================================================
417--- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Makefile (revision 0)
418+++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Makefile (revision 11850)
419@@ -0,0 +1,15 @@
420+all: TriMesh.so
421+
422+
423+TriMesh.o: TriMesh.cpp
424+ g++ -DNPY_NO_DEPRECATED_API -c -o TriMesh.o TriMesh.cpp \
425+ -I$(ISSM_TIER)/externalpackages/boost/install/include \
426+ -I$(ISSM_TIER)/externalpackages/python/install/include \
427+ -I$(ISSM_TIER)/externalpackages/python/install/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include
428+
429+
430+TriMesh.so: TriMesh.o
431+ g++ -dynamiclib -o TriMesh.so TriMesh.o -L$(ISSM_TIER)/externalpackages/boost/install/lib -lboost_python -L$(ISSM_TIER)/externalpackages/python/install/lib -lpython3.2
432+
433+clean:
434+ rm TriMesh.so TriMesh.o
435
436Property changes on: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Makefile
437___________________________________________________________________
438Added: svn:executable
439 + *
440
Note: See TracBrowser for help on using the repository browser.