473,387 Members | 1,700 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,387 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 1583
>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 =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.