need an example of Python numarray to C++ and back again, Boost / SWIG?
I want to pass a 2D array from Python to C++, manipulate it in C++ (for example, add 1 to each element) and pass it back to Python. With these building blocks I will be able to figure out all the rest of what I need to do for my project. I am very familiar with Python, but less so with C++ and Boost or SWIG. Does anyone have an example with all steps that I can follow? More specifically I am looking for the C++ code, ".i" file for SWIG and/or the analagous setup files that Boost would need to do this. Thanks in advance for any help you can provide, -- http://mail.python.org/mailman/listinfo/python-list
Re: need an example of Python numarray to C++ and back again, Boost / SWIG?
I looked at Stefan's post - but he remarks that "Unfortunately, Blitz jealously guards its data (restricted pointers), so that it is not so easy to do the conversion in the other direction. If anyone knows an answer to this problem, I'd be glad to hear it" I've previously looked at Phillip Austin's 'num_util' and Paulo J. S. Silva's 'COIN' example, but even from those two, I can't figure out a way to do: Python 2D numarray --> C++ (process array) --> Python 2D numarray. I forgot about "weave" - I had looked there before and will revisit it to see if it will work. But I was intending to do this with a compiled extension. I wish there was a simple example of this in either the SWIG or Boost docs or a faq/howto posted somewhere . . . -Paul Fernando Perez wrote: > PL wrote: > > > I want to pass a 2D array from Python to C++, manipulate it in C++ (for > > example, add 1 to each element) and pass it back to Python. > > > > With these building blocks I will be able to figure out all the rest of > > what I need to do for my project. I am very familiar with Python, but > > less so with C++ and Boost or SWIG. > > > > Does anyone have an example with all steps that I can follow? More > > specifically I am looking for the C++ code, ".i" file for SWIG and/or > > the analagous setup files that Boost would need to do this. > > You may want to look into weave.inline or weave.blitz, from scipy. Typemaps > for > conversion to blitz++ were recently posted on the scipy list: > > http://aspn.activestate.com/ASPN/Mail/Message/numpy-discussion/2883831 > > In particular look at Stefan's post. > > For info on weave, here you can find some old slides and example code: > > http://amath.colorado.edu/faculty/fperez/python/ > > Cheers, > > f -- http://mail.python.org/mailman/listinfo/python-list
Getting current variable name
Hi all, I followed the mails entitled 'How to turn a variable name into a string?' in march 2005 posts as I have a similar problem. I have to get some list variable names at some point in my program. So I ended up looking into globals() to get them with a small function like this: #!/usr/bin/python l1 = ['r', 'r', 't'] l2 = ['r', 't', 't'] l3 = ['t', 't', 't']# Two equivalent lists but... l4 = ['t', 't', 't']# with different names def nameofObj(obj): # print locals() globdict = globals() var = globals().keys() for i in var : if globdict[i] == obj: print i print '-'*20 ,'\n' nameofObj(l1) print '-'*20 ,'\n' map(nameofObj, [l1, l2, l3, l4]) If you try this, with 2 equivalent lists (here l3 and l4 when using map) the function will return both possibilities l3 and l4 which I understand. So this solution is limitated to unique lists, unfortunately I do have equivalent lists in my case... The problem comes from the fact that locals() and globals() have in common their values but not the keys which then can't be tested. The only solution I see would be to link the list and its name (in a dictionary for instance) but that does not sound elegant to me? If you guys can help a newbie... Thank you -- -- | Patrick LADAM | | | Laboratoire CSSB| THE BIG BANG THEORY: | | UFR SMBH| | | 74 rue Marcel Cachin| In the begining there was | | 93017 Bobigny CEDEX |nothing at all.| | >>> NEW e-mail: <<< | | | [EMAIL PROTECTED] | Then, it exploded... | | Tel: 01 48 38 77 26 / 76 85 | | | Fax: 01 48 38 77 77 | | -- -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-ideas] How the heck does async/await work in Python 3.5
Here are some concurrency benchmarks for python vs other languages. https://github.com/atemerev/skynet/pull/53 Is there something wrong with this implementation? "Hope I suck at coroutines, because the results are abysmal. I get around 63s on my i5 MacBook Air Early 2015. For reference, the go version got around 700ms with GOMAXPROCS=4 and 1.7s with GOMAXPROCS=1 on this same machine." On Wednesday, February 24, 2016 at 5:02:16 AM UTC-5, Victor Stinner wrote: > > See also Doug Hellmann article on asyncio, from its serie of "Python 3 > Module of the Week" articles: > https://pymotw.com/3/asyncio/index.html > > Victor > > 2016-02-23 22:25 GMT+01:00 Joao S. O. Bueno >: > > Today I also stumbled on this helpful "essay" from Brett Cannon about > > the same subject > > > > http://www.snarky.ca/how-the-heck-does-async-await-work-in-python-3-5 > > > > On 23 February 2016 at 18:05, Sven R. Kunze > wrote: > >> On 20.02.2016 07:53, Christian Gollwitzer wrote: > >> > >> If you have difficulties wit hthe overall concept, and if you are open > to > >> discussions in another language, take a look at this video: > >> > >> > https://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-39-await-co-routines > > >> > >> MS has added coroutine support with very similar syntax to VC++ > recently, > >> and the developer tries to explain it to the "stackful" programmers. > >> > >> > >> Because of this thread, I finally finished an older post collecting > valuable > >> insights from last year discussions regarding concurrency modules > available > >> in Python: > http://srkunze.blogspot.com/2016/02/concurrency-in-python.html It > >> appears to me that it would fit here well. > >> > >> @python-ideas > >> Back then, the old thread ("Concurrency Modules") was like basically > meant > >> to result in something useful. I hope the post covers the essence of > the > >> discussion. > >> Some even suggested putting the table into the Python docs. I am > unaware of > >> the formal procedure here but I would be glad if somebody could point > be at > >> the right direction if that the survey table is wanted in the docs. > >> > >> Best, > >> Sven > >> > >> ___ > >> Python-ideas mailing list > >> python...@python.org > >> https://mail.python.org/mailman/listinfo/python-ideas > >> Code of Conduct: http://python.org/psf/codeofconduct/ > > ___ > > Python-ideas mailing list > > python...@python.org > > https://mail.python.org/mailman/listinfo/python-ideas > > Code of Conduct: http://python.org/psf/codeofconduct/ > ___ > Python-ideas mailing list > python...@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -- https://mail.python.org/mailman/listinfo/python-list
Find and display gif file/s in web browser, according to the passed string, compared to files names in the folder.
Dear Programmers, I would like to ask you to write a program/script in Python 3.7 working at Windows 10 and Debian 9.x, according to the scenario: 1). The User in the console is writing the command and a text parameter, e.g.: "d Adam" 2). Script/program "d" assigns value "Adam" to variable "x". 3). A search is done in the folder from which command/script "d" was called. We check in all files names that have ".gif" extension. 4). Each file name is built according to the following pattern : Characters 1-7 contain the file prefix+number, Character/s starting from 8 to "*" are called "InitialText". Character/s from the first character after "*" until ".gif" are called "FinalText" 5). Program has to find file/s, for which "Adam" (value of "x") is between "InitialText" and "FinalText" and open it/them in a web browser. 6). Example 1: 6.1). Command "d Adam" was written in console. 6.2). Program found file WWP0001A*Azor.gif 6.3). "Adam" is between "A" and "Azor" 6.4). File "WWP0001A*Azor.gif" has been opened in the web browser. - Program has to open it in the next tab of an already opened browser. - If no web browser was open yet, the script has to open it first. - We want to open each gif file in a new tab of the same web browser. 7). Example 2: 7.1). "d Brzoza" was inserted in the console. 7.2). Program found 2 files that fit to the parameter : 7.2.1). WWP1119Barbara*Bzura.gif "Brzoza" is between "Barbara" and "Bzura". 7.2.2). WWP5324Akwarystyka*Przeprowadzka.gif "Brzoza" is also between "Akwarystyka" and "Przeprowadzka" 7.2.3). Both the files are opened in two new tabs of web browser. Number of files in search folder : 5000-1 (no subfolders) The acceptable execution time : up to 3 seconds. Latin alphabet sorting or UTF-8 but I am not sure how to do it to let it work in both Windows 10 and Linux (e.g.: Debian 9.x) For the moment Polish, English and Italian languages will be used. (Russian, Japanese or Chinese might be added in future but not now). If this is a big problem, we can remove special characters, so "ą" will be treated as "a", "ę" as "e", etc. using the standard Latin sorting : abcdefghijklmnopqrstuvwxyz for the moment. If for performance reason it was a problem to search each time "on the fly" all files names in the directory then I would like to ask to suggest a solution to accelerate the search process. Please provide a detailed specification which would help me to prepare e.g. an index that would help to search, including rules, structure description/definition, exclusions, etc. I'm ready to pay a reasonable amount of money for writing it for me. Please, send your proposal to my e-mail from which I sent this article. Please, be patient if I expressed something not fully professionally :) Please, ask me additional questions using simple language to let me specify the missing or unclear elements "at high level" or in "pseudocode". Thank you in advance and best regards~~Peter~~pe3no. -- https://mail.python.org/mailman/listinfo/python-list