473,287 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Bits module -- early working version

I've been working on a module to get at the bits of all numeric types
(no, I haven't thought of how to solve the decimal data type that is
coming). I've finally got the bits module to pass all of my own tests,
so I'm looking for bug reports, design critiques, and general input. I
eventually plan to release this under an MIT-style license. If you are
interested in seeing read access to the bits of python's numbers, and
want to see what I'm up to / critique someone else's work / volunteer to
help extend, check out:

http://members.dsl-only.net/~daniels/bits.html

If you want to know what questions I have, here are my current set:

1) Do you know a case that fails?
2) Should the names be lsb, lsbit, or lsbitno (and similarly for msb*)?
I've gone with lsb, but cases can be made for the others.
3) Is "extract" the right name, or should I us a name more like "bits"?
4) Should bit(v, N) somehow be subsumed in extract(v, l, hi) (or
whatever extract should be called)?
5) Have I adequately explained what these functions do?
6) Do these functions work as-is (from source) for various machines?
I know/believe Intel x86/pentia work; what about alpha, 68K, ....
7) Should bitcount simply raise and exception on negative input?
8) If you supply an unexpected argument type for the number, should I
try to calla corresponding method? (__bit__ for bit, __msb__ for
msb, ....)

So I'd like feedback before actually releasing.

--
-Scott David Daniels
Sc***********@Acm.Org
Jul 18 '05 #1
1 1580
>Subject: Bits module -- early working version
From: Scott David Daniels Sc***********@Acm.Org
Date: 2/12/2004 11:55 PM Central Standard Time
Message-id: <40******@nntp0.pdx.net>

I've been working on a module to get at the bits of all numeric types
(no, I haven't thought of how to solve the decimal data type that is
coming). I've finally got the bits module to pass all of my own tests,
so I'm looking for bug reports, design critiques, and general input. I
eventually plan to release this under an MIT-style license. If you are
interested in seeing read access to the bits of python's numbers, and
want to see what I'm up to / critique someone else's work / volunteer to
help extend, check out:

http://members.dsl-only.net/~daniels/bits.html

If you want to know what questions I have, here are my current set:

1) Do you know a case that fails?
2) Should the names be lsb, lsbit, or lsbitno (and similarly for msb*)?
I've gone with lsb, but cases can be made for the others.
3) Is "extract" the right name, or should I us a name more like "bits"?
4) Should bit(v, N) somehow be subsumed in extract(v, l, hi) (or
whatever extract should be called)?
5) Have I adequately explained what these functions do?
6) Do these functions work as-is (from source) for various machines?
I know/believe Intel x86/pentia work; what about alpha, 68K, ....
7) Should bitcount simply raise and exception on negative input?
8) If you supply an unexpected argument type for the number, should I
try to calla corresponding method? (__bit__ for bit, __msb__ for
msb, ....)

So I'd like feedback before actually releasing.
Testing for the lsb allows me to speed up my Collatz program since I can
extract all the factors of 2 in one fell swoop as opposed to iterating through
each one. For the large numbers I work with (2**100000 - 1 in the following
example), this optimization is signifigant:

c:\python23\user>python collatz_.py 100000

standard Python long ints without optimization
r1 863323 r2 481603 in 632.234999895 seconds

optimized with bits.lsb() bit scanning
r1 863323 r2 481603 in 332.5 seconds

But I had already been using the gmpy module which has the scan1()
function that does the same thing as bits.lsb(). And gmpy long ints are
more efficient than the Python long ints. Together, I get much better
performance:

optimized with gmpy.scan1() bit scanning
r1 863323 r2 481603 in 131.733999968 seconds

For my work, I can't see any advantage in using bits over gmpy.

--
-Scott David Daniels
Sc***********@Acm.Org


--
Mensanator
Ace of Clubs
Jul 18 '05 #2

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

Similar topics

2
by: x-herbert | last post by:
Hi, I have a small test to "compile" al litle script as a WMI-Tester. The script include a wmi-wrapper and "insert" the Win32-modeles. here the code: my "WMI-Tester.py" ----- import wmi
2
by: Sandeep Gupta | last post by:
I've compiled Python 2.3.3 on NetBSD and the thread (and therefore the threading) module is not available. Am I missing the module because of the way I made the binary? I could use the...
3
by: Geoffrey | last post by:
I am working on a file conversion project that reads data from a one file format, reformats in and writes in out to another. The data is records of informations - names address, account...
13
by: bobueland | last post by:
I'm a newbie experimenting with Python. I want to incrementally develop a module called 'circle'. The problem is now that the file name is used for two purposes. To keep track of the version number...
34
by: Cuthbert | last post by:
Hi folks, I am trying to find a more efficient way to count "How many bits are '1' in a integer variable?". I still have no idea to count the bits except using a loop and "if" statements....
13
by: André | last post by:
Hi, i'm developping asp.net applications and therefore i use VB.net. I have some questions about best practises. According what i read about class and module and if i understand it right, a...
2
by: =?Utf-8?B?c2FtMDFt?= | last post by:
I have a remoting application that was developed on a Windows XP SP2 machine with VS2005 SP1. I finally got everything deployed using Wix 3.0, and it works great. Problem is, when I install the msi...
36
by: The Frog | last post by:
Hi Everyone, I am trying to find a solution for handling zipped data without the need to ship / install any DLL files with the database. Does anybody know of code to handle ZIP files that does...
11
by: JoeC | last post by:
I am working on a graphics program but my question has nothing to do with graphics but trying to get an algorithm to work. I set graphics from a 16x16 grid to bits of a graphic with: bitData =...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.