473,587 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pyrex: step in for loop

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I'm trying to improve speed in a module and substituted the pythonic
'for in range()' for 'for i from min < i < max:'

But, I need to define a step for the i variable. How can I do it?

for example, how do I iterate through 80000 to 140000 with step 10000?

Luis
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFClkGTHn4 UHCY8rB8RAgZXAJ 0XPg9IH0OU329FV X3o14QjNFXuXgCg m+UR
O0GpXmDpQr7Y7Tg MsmVvZ6s=
=zZnm
-----END PGP SIGNATURE-----
Jul 19 '05 #1
4 4251
"Luis P. Mendes" <lu***********@ netvisaoXXX.pt> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I'm trying to improve speed in a module and substituted the pythonic
'for in range()' for 'for i from min < i < max:'

But, I need to define a step for the i variable. How can I do it?

for example, how do I iterate through 80000 to 140000 with step 10000?


guru% pydoc range
Help on built-in function range in module __builtin__:

range(...)
range([start,] stop[, step]) -> list of integers

Return a list containing an arithmetic progression of integers.
range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
When step is given, it specifies the increment (or decrement).
For example, range(4) returns [0, 1, 2, 3]. The end point is omitted!
These are exactly the valid indices for a list of 4 elements.

so it's

for i in range(80000, 140000, 10000): ...

<mike
--
Mike Meyer <mw*@mired.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
| so it's
|
| for i in range(80000, 140000, 10000): ...
|
| <mike

For what I've read, for i in range is slower than the other for
construct used by Pyrex:

for i from iMin <= i < iMax:

My question had to do with this new expression. How can I introduce a
step there.

I am able to circumvent the problem passing a reduced range for i, let's
say iMin = 8, iMax = 14 when calling the pyrex module and then, after
the for statement:
i = i * 10000
and it works as it is intended to.
But, if there is a way to introduce the step in the 'for i from iMin <=
i < iMax:' expression, I would like to know.

Thank you for your reply.

Luis
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFClkmlHn4 UHCY8rB8RAlUqAK CxSEkEKVIcoshTw mL7GQNK6d/j0wCgoC67
jOhuXQpnDt23SEA M9huKTQA=
=8XO0
-----END PGP SIGNATURE-----
Jul 19 '05 #3
"Luis P. Mendes" <lu***********@ netvisaoXXX.pt> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
| so it's
|
| for i in range(80000, 140000, 10000): ...
|
| <mike

For what I've read, for i in range is slower than the other for
construct used by Pyrex:

for i from iMin <= i < iMax:

My question had to do with this new expression. How can I introduce a
step there.


My bad. I missed the "Pyrex" in the subject line.

Sorry,
<mike
--
Mike Meyer <mw*@mired.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #4
Luis P. Mendes wrote:
I'm trying to improve speed in a module and substituted the pythonic
'for in range()' for 'for i from min < i < max:'

But, I need to define a step for the i variable. How can I do it?


If you want maximum clarity, I'd suggest using the for-loop
to iterate over a contiguous range of integers and an expression
that maps the loop variable to whatever you want.

If you want the maximum possible speed, it *may* be faster
to use a while loop instead and do your own index updating.
But profile to make sure.

--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2288
by: Gary Stephenson | last post by:
I'm getting a clean generate, compile and link from my .pyx script, but when I attempt to run the resultant .exe, I get: "The procedure entry point Py_NoneStruct could not be located in the dynamic link library python23.dll" Can anybody provide me with a clue here? I've already cut down my script to remove all references to None,...
10
2029
by: Kyler Laird | last post by:
I need to submit C/C++ code for a class. (It's not a programming class. The choice of language is inertial. I think that it mostly serves to distract students from the course subject.) I'm fairly fluent with C but it hurts to think about writing in C when Python is *so* much more appropriate for these operations. I'd like to keep my...
4
2069
by: Kyler Laird | last post by:
I mentioned earlier that I started using Pyrex because I'm taking a computer vision course that requires all assignments to be submitted as C(++). While I could write C it would hurt me to do so and certainly distract me from the computer vision aspects. I like using Python these days and Pyrex looked like a good solution. (BTW, on the...
1
1624
by: SM | last post by:
Hi, I would like to play with Pyrex for Windows. I have no clue how to install it including a c compiler. Anyone using pyrex on windows who could give a quickstart? Stani http://spe.pycs.net http://www.stani.be
1
3575
by: Martin Bless | last post by:
Now that I've got my extension building machine using the VC++ Toolkit 2003 up and running I'm keen on using Pyrex (Pyrex-0.9.3, Python-2.4.0). But the definition of the swig_sources() method seems to have changed. When I try to build the examples from Pyrex I get a TypeError: c:\Pyrex-0.9.3\Demos> python Setup.py build_ext --inplace
27
3958
by: Julien Fiore | last post by:
Do you wand to install Pyrex on Windows ? Here is a step-by-step guide explaining: A) how to install Pyrex on Windows XP. B) how to compile a Pyrex module. Julien Fiore, U. of Geneva
11
1978
by: Jim Lewis | last post by:
Has anyone found a good link on exactly how to speed up code using pyrex? I found various info but the focus is usually not on code speedup.
7
2038
by: Jim Lewis | last post by:
I'm trying to move a function into pyrex for speed. The python side needs to pass a list to the pyrex function. Do I need to convert to array or something so pyrex can generate tight code? I'm not clear how to do this.
0
988
by: Georg Grabler | last post by:
Hello everybody. I finally decided to use pyrex for my tasks wrapping and creating new python objects. Anyway, i ran into struggles. I want an array to be passed to a function, so basically i started the function as follows: def addToList (self, char *array):
0
7918
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.