473,461 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Create 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

iD8DBQFClkGTHn4UHCY8rB8RAgZXAJ0XPg9IH0OU329FVX3o14 QjNFXuXgCgm+UR
O0GpXmDpQr7Y7TgMsmVvZ6s=
=zZnm
-----END PGP SIGNATURE-----
Jul 19 '05 #1
4 4244
"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.org> 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

iD8DBQFClkmlHn4UHCY8rB8RAlUqAKCxSEkEKVIcoshTwmL7GQ NK6d/j0wCgoC67
jOhuXQpnDt23SEAM9huKTQA=
=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.org> 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
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...
10
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...
4
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...
1
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...
1
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...
27
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
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
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...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.