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

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

oecreview from 11518 to present

File size: 13.6 KB
  • proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/TriMesh.cpp.bak

     
     1#include <stdio.h>
     2using namespace std;
     3
     4void meshx(double* index,int n) {
     5        int i;
     6        for(i=0;i<n;i++){
     7                printf("%g\n",index[i]);
     8        }
     9}
     10
     11#include <boost/python.hpp>
     12#include <boost/python/module.hpp>
     13#include <boost/python/def.hpp>
     14using namespace boost::python;
     15
     16void FetchData(double** array,int* N,boost::python::list pythonlist){/*{{{*/
     17
     18        /*Get list size*/
     19        int n = boost::python::extract<int>(pythonlist.attr("__len__")());
     20
     21        /*Assign double array and populate*/
     22        double* clist = new double[n];
     23        for (int i=0;i<n;i++) clist[i] = extract<double>(pythonlist[i]);
     24
     25        /*Assign output pointers*/
     26        *array = clist;
     27        if(N) *N = n;
     28}/*}}}*/
     29
     30boost::python::list void mesh(boost::python::list INDEX){
     31
     32        boost::python::list output;
     33
     34        double *index=NULL;
     35        int     n;
     36
     37        FetchData(&index,&n,INDEX);
     38
     39        /*Call x layer*/
     40        meshx(index,n);
     41
     42        /*Clean up*/
     43        delete index;
     44}
     45
     46
     47#include <boost/python/module.hpp>
     48#include <boost/python/def.hpp>
     49using namespace boost::python;
     50
     51BOOST_PYTHON_MODULE(TriMesh_ext){
     52        def("mesh",mesh);
     53}
  • proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/Code.cpp

     
     1/*Copyright 2006  Phil Austin (http:www.eos.ubc.ca/personal/paustin)
     2  Distributed under the Boost Software License, Version 1.0. (See
     3  accompanying file LICENSE_1_0.txt or copy at
     4http:www.boost.org/LICENSE_1_0.txt)
     5*/
     6
     7#define PY_ARRAY_UNIQUE_SYMBOL PyArrayHandle
     8#include "num_util.h"
     9#include <iostream>
     10
     11namespace { const char* rcsid = "$Id: simpletest.cpp,v 1.4 2006/07/05 22:55:16 phil Exp $"; }
     12
     13//send a dictionary with two arrays back to python
     14boost::python::dict testToPython(void){
     15        double ia[6] = {1,2,3,4,5,6};
     16        int ib[3] = {88,99,100};
     17        //construct two numpy arrays
     18        boost::python::numeric::array pyDoubles=num_util::makeNum(ia,6);
     19        boost::python::numeric::array pyInts=num_util::makeNum(ib,3);
     20        //pack them in a dictionary and return to python
     21        boost::python::dict retvals;
     22        retvals["myDoubles"]=pyDoubles;
     23        retvals["myInts"]=pyInts;
     24        return retvals;
     25}
     26
     27//get an array from python
     28void testFromPython(boost::python::numeric::array inValue){
     29        num_util::check_type(inValue, PyArray_DOUBLE);
     30        num_util::check_rank(inValue, 2);
     31        double* dataPtr = (double*) num_util::data(inValue);
     32        int theSize= num_util::size(inValue);
     33        std::cout << std::endl << "data values on c++ side: " << std::endl;
     34        for(int i=0;i < theSize;++i){
     35                std::cout << *(dataPtr + i) << std::endl;
     36        }
     37
     38
     39BOOST_PYTHON_MODULE(simple_ext)
     40{
     41        import_array();
     42        boost::python::numeric::array::set_module_and_type("numpy", "ArrayType");
     43        //global doc string
     44        boost::python::scope().attr("RCSID") = rcsid;
     45        std::string str1;
     46        str1="docstring for module\n";
     47        boost::python::scope().attr("__doc__") = str1.c_str();
     48        str1 = "Doc string for testToPython\n";
     49        def("testToPython", testToPython,str1.c_str());
     50        str1 = "Doc string for testFromPython\n";
     51        def("testFromPython", testFromPython,str1.c_str());
     52}
     53
  • proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/TriMesh.cpp

     
     1#include <stdio.h>
     2using namespace std;
     3
     4void meshx(double* index,int n) {
     5        int i;
     6        for(i=0;i<n;i++){
     7                printf("%g\n",index[i]);
     8        }
     9}
     10
     11#include <boost/python.hpp>
     12#include <boost/python/module.hpp>
     13#include <boost/python/def.hpp>
     14using namespace boost::python;
     15
     16void FetchData(double** array,int* N,boost::python::list pythonlist){/*{{{*/
     17
     18        /*Get list size*/
     19        int n = boost::python::extract<int>(pythonlist.attr("__len__")());
     20
     21        /*Assign double array and populate*/
     22        double* clist = new double[n];
     23        for (int i=0;i<n;i++) clist[i] = extract<double>(pythonlist[i]);
     24
     25        /*Assign output pointers*/
     26        *array = clist;
     27        if(N) *N = n;
     28}/*}}}*/
     29
     30boost::python::list mesh(boost::python::list INDEX){
     31
     32        int i;
     33
     34        boost::python::list output;
     35
     36        double *index=NULL;
     37        int     n;
     38
     39        FetchData(&index,&n,INDEX);
     40
     41        for(i=0;i<n;i++)output.append(index[i]);
     42
     43        /*Call x layer*/
     44        meshx(index,n);
     45
     46        /*Clean up*/
     47        delete index;
     48        return output;
     49}
     50
     51
     52#include <boost/python/module.hpp>
     53#include <boost/python/def.hpp>
     54using namespace boost::python;
     55
     56BOOST_PYTHON_MODULE(TriMesh){
     57        def("mesh",mesh);
     58}
  • proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/Makefile

     
    1 all: ice
     1all: TriMesh.so
    22
    3 ice:
    4         g++ -bundle  -bind \
    5                 -I$(ISSM_TIER)/externalpackages/boost/install/include \
    6                 -I/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m\
    7                 -L$(ISSM_TIER)/externalpackages/boost/install/lib -lboost_python \
    8                 -L/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/config-3.2m/ -lpython3.2 \
    9                 TriMeshmodule.cpp -o TriMesh.so
    103
     4TriMesh.o: TriMesh.cpp
     5        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
     6
     7TriMesh.so: TriMesh.o
     8        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   
     9
    1110clean:
    12         rm TriMesh.so
     11        rm TriMesh.so TriMesh.o
  • proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/test.py

     
     1from TriMesh import *
     2from numpy import *
     3a=array([1.0,2.0]);
     4
     5mesh(a)
  • proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp.bak

     
     1#include <stdio.h>
     2using namespace std;
     3
     4void meshx(double* index,int n) {
     5        int i;
     6        for(i=0;i<n;i++){
     7                printf("%g\n",index[i]);
     8        }
     9}
     10
     11#include <boost/python.hpp>
     12#include <boost/python/module.hpp>
     13#include <boost/python/def.hpp>
     14using namespace boost::python;
     15
     16void FetchData(double** array,int* N,boost::python::list pythonlist){/*{{{*/
     17
     18        /*Get list size*/
     19        int n = boost::python::extract<int>(pythonlist.attr("__len__")());
     20
     21        /*Assign double array and populate*/
     22        double* clist = new double[n];
     23        for (int i=0;i<n;i++) clist[i] = extract<double>(pythonlist[i]);
     24
     25        /*Assign output pointers*/
     26        *array = clist;
     27        if(N) *N = n;
     28}/*}}}*/
     29
     30boost::python::list void mesh(boost::python::list INDEX){
     31
     32        boost::python::list output;
     33
     34        double *index=NULL;
     35        int     n;
     36
     37        FetchData(&index,&n,INDEX);
     38
     39        /*Call x layer*/
     40        meshx(index,n);
     41
     42        /*Clean up*/
     43        delete index;
     44}
     45
     46
     47#include <boost/python/module.hpp>
     48#include <boost/python/def.hpp>
     49using namespace boost::python;
     50
     51BOOST_PYTHON_MODULE(TriMesh_ext){
     52        def("mesh",mesh);
     53}
  • proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp.bak2

     
     1#include <stdio.h>
     2using namespace std;
     3
     4#include <boost/python.hpp>
     5#include <boost/python/module.hpp>
     6#include <boost/python/def.hpp>
     7//#include "num_util.h"
     8
     9using namespace boost::python;
     10
     11void mesh(boost::python::numeric::array array){
     12
     13        int n;
     14        double a;
     15
     16        n = boost::python::extract<int>(array.attr("__len__")());
     17
     18        for(int i=0;i < n;++i){
     19                a=extract<double>(array[i]);
     20                printf("%g\n",a);
     21        }
     22       
     23}
     24
     25
     26#include <boost/python/module.hpp>
     27#include <boost/python/def.hpp>
     28using namespace boost::python;
     29
     30BOOST_PYTHON_MODULE(TriMesh){
     31        boost::python::numeric::array::set_module_and_type( "numpy", "ndarray");
     32        def("mesh",mesh);
     33}
  • proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Code.cpp

     
     1/*Copyright 2006  Phil Austin (http:www.eos.ubc.ca/personal/paustin)
     2  Distributed under the Boost Software License, Version 1.0. (See
     3  accompanying file LICENSE_1_0.txt or copy at
     4http:www.boost.org/LICENSE_1_0.txt)
     5*/
     6
     7#define PY_ARRAY_UNIQUE_SYMBOL PyArrayHandle
     8#include "num_util.h"
     9#include <iostream>
     10
     11namespace { const char* rcsid = "$Id: simpletest.cpp,v 1.4 2006/07/05 22:55:16 phil Exp $"; }
     12
     13//send a dictionary with two arrays back to python
     14boost::python::dict testToPython(void){
     15        double ia[6] = {1,2,3,4,5,6};
     16        int ib[3] = {88,99,100};
     17        //construct two numpy arrays
     18        boost::python::numeric::array pyDoubles=num_util::makeNum(ia,6);
     19        boost::python::numeric::array pyInts=num_util::makeNum(ib,3);
     20        //pack them in a dictionary and return to python
     21        boost::python::dict retvals;
     22        retvals["myDoubles"]=pyDoubles;
     23        retvals["myInts"]=pyInts;
     24        return retvals;
     25}
     26
     27//get an array from python
     28void testFromPython(boost::python::numeric::array inValue){
     29        num_util::check_type(inValue, PyArray_DOUBLE);
     30        num_util::check_rank(inValue, 2);
     31        double* dataPtr = (double*) num_util::data(inValue);
     32        int theSize= num_util::size(inValue);
     33        std::cout << std::endl << "data values on c++ side: " << std::endl;
     34        for(int i=0;i < theSize;++i){
     35                std::cout << *(dataPtr + i) << std::endl;
     36        }
     37
     38
     39BOOST_PYTHON_MODULE(simple_ext)
     40{
     41        import_array();
     42        boost::python::numeric::array::set_module_and_type("numpy", "ArrayType");
     43        //global doc string
     44        boost::python::scope().attr("RCSID") = rcsid;
     45        std::string str1;
     46        str1="docstring for module\n";
     47        boost::python::scope().attr("__doc__") = str1.c_str();
     48        str1 = "Doc string for testToPython\n";
     49        def("testToPython", testToPython,str1.c_str());
     50        str1 = "Doc string for testFromPython\n";
     51        def("testFromPython", testFromPython,str1.c_str());
     52}
     53
  • proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp

     
     1#include <stdio.h>
     2using namespace std;
     3
     4#include <boost/python.hpp>
     5#include <boost/python/module.hpp>
     6#include <boost/python/def.hpp>
     7#include <numpy/arrayobject.h>
     8
     9using namespace boost::python;
     10
     11void mesh(boost::python::numeric::array array){
     12//void mesh(boost::python::object array){
     13
     14        int i;
     15        double* b=NULL;
     16        int nd,M,N;
     17        int* dims=NULL;
     18        PyArrayObject* a = (PyArrayObject*)array.ptr();
     19        b=(double*)PyArray_DATA(a);
     20        nd=PyArray_NDIM(a);
     21        dims=(int*)PyArray_DIMS(a);
     22        M=dims[0];
     23
     24        printf("nd: %i M: %i\n",nd,M);
     25        for(i=0;i<M;i++){
     26                printf("%g\n",b[i]);
     27        }
     28
     29       
     30}
     31
     32
     33#include <boost/python/module.hpp>
     34#include <boost/python/def.hpp>
     35using namespace boost::python;
     36
     37BOOST_PYTHON_MODULE(TriMesh){
     38        boost::python::numeric::array::set_module_and_type( "numpy", "ndarray");
     39        //boost::python::numeric::array::set_module_and_type( "numpy", "array");
     40        def("mesh",mesh);
     41}
  • proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Makefile

     
     1all: TriMesh.so
     2
     3
     4TriMesh.o: TriMesh.cpp
     5        g++  -DNPY_NO_DEPRECATED_API -c -o TriMesh.o TriMesh.cpp  \
     6        -I$(ISSM_TIER)/externalpackages/boost/install/include     \
     7        -I$(ISSM_TIER)/externalpackages/python/install/include \
     8        -I$(ISSM_TIER)/externalpackages/python/install/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include 
     9       
     10
     11TriMesh.so: TriMesh.o
     12        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   
     13
     14clean:
     15        rm TriMesh.so TriMesh.o
Note: See TracBrowser for help on using the repository browser.