From yuriy at centricsoftware.com Tue Dec 8 00:00:53 1998 From: yuriy at centricsoftware.com (Yuriy Gorvitovskiy) Date: Mon, 7 Dec 1998 15:00:53 -0800 Subject: [C++-SIG] Integration Message-ID: <005b01be2235$7122f500$936ef7cc@spock.centricsoftware.com> Hi, I'm planing to integrate Python in my company product as script language, and may be planing to use it to work as client with internal and external COM objects (I hate VBasic). Did anybody already done such kind of things, and what problems did he expected. I want to understand how big are the problems to struggle with. Application is Windows NT base application and ported to SGI with the help of MainWin kind software. Thank You! Yuriy Gorvitovskiy yuriy at centricsoftware.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From MHammond at skippinet.com.au Tue Dec 8 00:38:48 1998 From: MHammond at skippinet.com.au (Mark Hammond) Date: Tue, 8 Dec 1998 10:38:48 +1100 Subject: [C++-SIG] Integration In-Reply-To: <005b01be2235$7122f500$936ef7cc@spock.centricsoftware.com> Message-ID: <001401be223a$bd8acb70$0801a8c0@bobcat.c3.telstra-mm.net.au> [Many readers of this SIG dont have HTML enabled mailers - plain text is better] Embedding Python into a C++ application is (pratically :-) no harder than embedding it into a C application. This is amazingly easy, and quite well documented. Where there are holes in the documentation, Deja News will come to the rescue. Rest assured that it has indeed been done many-a-time. Utilising COM in your embedded application need be no harder than utilising COM from stand-alone Python. Once ported to SGI, your guess is as good as mine about how COM will work there. I can state fairly certainly that noone else has done it yet. You challenges are likely to be domain specific, and Im afraid we cant offer advice here. One big issue is how you structure the embedding of Python - eg, will it just be a string interface, is there an existing object model you will attempt to extend, will there be specially named user-written methods you will be calling etc? You are probably best served by continuing this discussion on the main Python newsgroup - this is not the focus of the C++ sig, and the newgroup is likely to have a much larger audience of people who can answer your questions effectively... Hope this helps... Mark. -----Original Message----- From: c++-sig-admin at python.org [mailto:c++-sig-admin at python.org]On Behalf Of Yuriy Gorvitovskiy Sent: Tuesday, 8 December 1998 10:01 AM To: c++-sig Python Subject: [C++-SIG] Integration Hi, I'm planing to integrate Python in my company product as script language, and may be planing to use it to work as client with internal and external COM objects (I hate VBasic). Did anybody already done such kind of things, and what problems did he expected. I want to understand how big are the problems to struggle with. Application is Windows NT base application and ported to SGI with the help of MainWin kind software. Thank You! Yuriy Gorvitovskiy yuriy at centricsoftware.com From phil at geog.ubc.ca Wed Dec 9 19:24:32 1998 From: phil at geog.ubc.ca (Phil Austin) Date: 09 Dec 1998 10:24:32 -0800 Subject: [C++-SIG] Re: blitz++ vs. NumPy? In-Reply-To: henk13@my-dejanews.com's message of Wed, 09 Dec 1998 15:24:48 GMT References: <74m4ns$6ht$1@nnrp1.dejanews.com> Message-ID: The following message is a courtesy copy of an article that has been posted as well. posting to comp.lang.python, henk13 at my-dejanews.com writes: > > I just wondered what the advantages and disadvantages would be of doing > Python numerical computiation in a Blitz++ (http://seurat.uwaterloo.ca/blitz) > framework rather than NumPy's Lapack/Blas framework (this is _not_ meant to > offend the people at LLNL). The inherint OO-design of Blitz nicely extends > the mental concept in which Python programs are developed. For instance, the > Array class could be straightforwardly mapped to a Python Array extension > type. > > Is this some utopia or does it make sense? > > Comments are welcome! > Yes, the fit you describe is very close to completion thanks to Paul Dubois,Todd Veldhuizen, Geoff Furnish and others. Here's an example of a Python extension I wrote in about 20 minutes last night, which calculates the 2nd order structure function for a 256 x 256 pixel satellite image of cloud liquid water path. It uses Paul's CXX_Array.h (see the source, http://xfiles.llnl.gov/CXX_Objects/cxx.htm and particularly the last pages of http://starship.skyport.net/~da/freebie). I've added a constructor that creates an n-dimensional PyArray from dimensions specified by a Blitz 1-d array. Blitz arrays are reference-counted, and Todd's provided a constructor that takes a raw C pointer (in this case to the PyArray data). I can mirror the PyArrays with Blitz arrays of the same dimensions, denoted by the "tied" prefix below and get the template metaprograms, 2-dimensional subscripts etc., without paying for a copy. I return the structure function and the pixel counts to Python in a dictionary. The program strucfun.cxx below is compiled into strucfun.so and then called from Python like this: from Numeric import * import strucfun test=arange(4,typecode=Float32) test.shape=(2,2) print strucfun.strucout(test) Some comments/questions: 1) From my perspective the combination of Blitz and CXX_Objects pushes NumPy across a threshold: extension writing has become something that Fortran77 and Matlab programming scientists (like me) can do. 2) Two things I wasn't able to figure out in 20 minutes are: a) How to add my Blitz-based Py::Array constructor to Paul's code using inheritence. It looks like: explicit Array (blitz::Array dimens, PyArray_TYPES t = PyArray_DOUBLE) : Sequence(FromAPI(PyArray_FromDims(dimens.size(), dimens.data(), t))) { validate(); } b) Is there a general way to convert between a Blitz TinyVector of length N (where N isn't known at compile time) and a blitz::Array? I'd like to avoid specifying the dimensions to the Py::Array and the blitz::Array separately. 3) This worked the first time I tried it; everyone responsible for that little miracle has my heartfelt thanks. __________strucfun.cxx_____________ #include "Python.h" #include "CXX_Objects.h" #include "CXX_Extensions.h" #include #include "CXX_Array.h" #include USING(namespace Py) USING(namespace std) blitz::Array convertit( blitz::TinyVector tinyDimens) { blitz::Array junk(2); for(int j=0;j < tinyDimens.length();++j){ junk(j)=tinyDimens(j); } return junk; } static PyObject * ex_strucout(PyObject* self, PyObject* args) { Py_Initialize(); import_array(); PyImport_ImportModule("Numeric"); Tuple t(args); Array tau(t[0]); // // change these to exceptions later // assert(tau.rank()==2); assert(tau.dimension(1)==tau.dimension(2)); assert(tau.species()==6); int N=tau.dimension(1); int Nbig=2*N-1; blitz::TinyVector tinyDimens(Nbig,Nbig); Array sf(convertit(tinyDimens),PyArray_FLOAT); Array count(convertit(tinyDimens),PyArray_FLOAT); // make blitz arrays that point to the same data and have the // same shape blitz::Array tiedTau((float*) sf.to_C(),tinyDimens); blitz::Array tiedSf((float*) sf.to_C(),tinyDimens); blitz::Array tiedCount((float*) count.to_C(),tinyDimens); tiedSf=0.; tiedCount=0.; for(int i=0;i 0.){ tiedSf(i,j)=tiedSf(i,j)/tiedCount(i,j); } } } Dict output; output["count"]=count; output["struct"]=sf; return new_reference_to(output); } extern "C" void initstrucfun(); static ExtensionModule* strucfun; void initstrucfun() { // experimental initialization stuff strucfun = new ExtensionModule("strucfun"); strucfun->add("strucout", ex_strucout, "calculate the structure function"); } -- ------------------------------------------------------------ Phil Austin (phil at geog.ubc.ca) Department of Geography, Tel: (604) 822-2663 University of British Columbia, B.C. Fax: (604) 822-6150 From dubois1 at llnl.gov Mon Dec 21 21:26:38 1998 From: dubois1 at llnl.gov (Paul F. Dubois) Date: Mon, 21 Dec 1998 12:26:38 -0800 Subject: [C++-SIG] Re: blitz++ vs. NumPy? Message-ID: <001901be2d20$375e8fa0$f4160218@c1004579-c.plstn1.sfba.home.com> -----Original Message----- From: Phil Austin Newsgroups: comp.lang.python > >2) Two things I wasn't able to figure out in 20 minutes are: > > a) How to add my Blitz-based Py::Array constructor to Paul's code > using inheritence. It looks like: > > explicit Array (blitz::Array dimens, PyArray_TYPES t = PyArray_DOUBLE) > : Sequence(FromAPI(PyArray_FromDims(dimens.size(), dimens.data(), t))) { > validate(); > } > > b) Is there a general way to convert between a Blitz TinyVector of > length N (where N isn't known at compile time) > and a blitz::Array? I'd like to avoid specifying the > dimensions to the Py::Array and the blitz::Array separately. > a. In C++ certain things are not inherited. These include the constructors and copy constructors, and I think the assignment operator. In the CXX documentation it gives you a list in the comments of the ones you have to reimplement in a child. So the answer to your question is that you have to copy my functions and change their names appropriately and put them in your "child". You make a new child BlitzArray and give it appropriate constructors, assignment, and destructors. You might want to just use Array as a sample rather than a parent so that you can carefully manage the "tied" memory without worrying about what I'm doing in Array. Note that since ~Object is virtual, the destructors are called up the inheritance line after yours is executed. So you are ADDING actions rather than replacing them. b. I don't know much about Blitz in detail and can't answer this question. But you might be needing a member function template here to instantiate something for each needed size. Unfortunately, that is the one area that has the most portability problems at the moment. From phil at geog.ubc.ca Tue Dec 29 19:52:14 1998 From: phil at geog.ubc.ca (Phil Austin) Date: Tue, 29 Dec 1998 10:52:14 -0800 Subject: [C++-SIG] Re: blitz++ vs. NumPy? In-Reply-To: <001901be2d20$375e8fa0$f4160218@c1004579-c.plstn1.sfba.home.com> References: <001901be2d20$375e8fa0$f4160218@c1004579-c.plstn1.sfba.home.com> Message-ID: <199812291852.KAA01701@brant.geog.ubc.ca> >>>>> "Paul" == Paul F Dubois writes: Paul> a. In C++ certain things are not inherited. These include Paul> the constructors and copy constructors, and I think the Paul> assignment operator. In the CXX documentation it gives you a Paul> list in the comments of the ones you have to reimplement in Paul> a child. Thanks, I'll play around with this after I get this pile of finals graded. Paul> b. I don't know much about Blitz in detail and can't answer Paul> this question. But you might be needing a member function Paul> template here to instantiate something for each needed Paul> size. Right, I'm not sure what I was doing wrong, but today this Py::Array constructor worked (under KCC) without a hitch: template explicit Array (blitz::TinyVector dimens, PyArray_TYPES t = PyArray_DOUBLE) : Sequence(FromAPI(PyArray_FromDims(dimens.length(), dimens.data(), t))) { validate(); } Regards, Phil From phil at geog.ubc.ca Wed Dec 30 00:49:26 1998 From: phil at geog.ubc.ca (Phil Austin) Date: Tue, 29 Dec 1998 15:49:26 -0800 Subject: [C++-SIG] blitz++ and NumPy, revision 1 In-Reply-To: <001901be2d20$375e8fa0$f4160218@c1004579-c.plstn1.sfba.home.com> References: <001901be2d20$375e8fa0$f4160218@c1004579-c.plstn1.sfba.home.com> Message-ID: <199812292349.PAA03567@brant.geog.ubc.ca> >>>>> "Paul" == Paul F Dubois writes: Paul> a. In C++ certain things are not inherited. These include Paul> the constructors and copy constructors, and I think the Paul> assignment operator. In the CXX documentation it gives you a Paul> list in the comments of the ones you have to reimplement in Paul> a child. PA> Thanks, I'll play around with this after I get this pile of finals graded. Actually, I could live with something like the following, which just pairs the Blitz and Py:Arrays together in a structure. Corrections/suggestions are welcome. Regards, Phil ___________________ #include "Python.h" #include "CXX_Objects.h" #include "CXX_Extensions.h" #include #include "CXX_Array.h" #include template class TiedArray { public: Py::Array Pn; blitz::Array Bz; TiedArray(blitz::TinyVector dimens); }; template<> class TiedArray { public: Py::Array Pn; blitz::Array Bz; TiedArray(blitz::TinyVector dimens):Pn(dimens,PyArray_FLOAT),Bz((float*) Pn.to_C(),dimens) {}; TiedArray(Py::seqref pyob):Pn(pyob),Bz((float*) Pn.to_C(), blitz::shape(Pn.dimension(1),Pn.dimension(2))) { assert(Pn.rank()==2); assert(Pn.species()==PyArray_FLOAT); }; }; static PyObject * ex_strucout(PyObject* self, PyObject* args) { Py_Initialize(); import_array(); PyImport_ImportModule("Numeric"); Py::Tuple t(args); TiedArray tau(t[0]); assert(tau.Pn.dimension(1)==tau.Pn.dimension(2)); int N=tau.Pn.dimension(1); int Nbig=2*N-1; blitz::TinyVector tinyDimens(Nbig,Nbig); TiedArray sf(tinyDimens); TiedArray count(tinyDimens); sf.Bz=0.; count.Bz=0.; for(int i=0;i 0.){ sf.Bz(i,j)=sf.Bz(i,j)/count.Bz(i,j); } } } Py::Dict output; output["count"]=count.Pn; output["struct"]=sf.Pn; return Py::new_reference_to(output); } extern "C" void initstrucfun(); static Py::ExtensionModule* strucfun; void initstrucfun() { // experimental initialization stuff strucfun = new Py::ExtensionModule("strucfun"); strucfun->add("strucout", ex_strucout, "calculate the structure function"); Py::Dict d = strucfun->initialize(); }