64-bit Python on Macs

Posted in Apple, Python on June 7th, 2008 by stan / No Comments »

There was a question recently on the ROOT mailing list where someone was having a problem using the python executable that comes with Mac OS X 10.5 and 64-bit libraries.  I went digging around, and noticed a strange discrepancy.  The compiled python libraries that ship with Leopard are four architecture universal binaries:

stan@Rover:/usr/lib/python2.5/config$ file libpython2.5.a 
libpython2.5.a: Mach-O universal binary with 4 architectures
libpython2.5.a (for architecture ppc7400):
    Mach-O dynamically linked shared library ppc
libpython2.5.a (for architecture ppc64):
    Mach-O 64-bit dynamically linked shared library ppc64
libpython2.5.a (for architecture i386):
    Mach-O dynamically linked shared library i386
libpython2.5.a (for architecture x86_64):
    Mach-O 64-bit dynamically linked shared library x86_64

(Reformatted to avoid spilling into my sidebar…)

However, the python executable is not compiled for 64-bit architectures:

stan@Rover:/usr/bin$ file python2.5
python2.5: Mach-O universal binary with 2 architectures
python2.5 (for architecture ppc7400):
    Mach-O executable ppc
python2.5 (for architecture i386):
    Mach-O executable i386

I hadn’t noticed this since my MacBook is the early Core Duo model, rather than Core 2 Duo, so the hardware does not support x86_64.  Apple may have good reasons to force all python scripts to run as 32-bit applications even on 64-bit systems, but I don’t know what they are.

If you find yourself wanting 64-bit python, it’s very easy to make your own, since all the Python libraries on Leopard are already 32/64-bit universal.  Just go grab the very short python64.c from the ROOT svn repository, and compile it like this:

gcc -arch ppc64 -arch x86_64 -arch i386 -arch ppc  \
    -o python64 -I/usr/include/Python2.5 -lpython2.5 python64.c

(Note that this has nothing to do with the ROOT libraries. If you have no idea what ROOT is, the above will still work.)

Now you can check the python64 executable:

Rover:tmp stan$ file python64
python64: Mach-O universal binary with 4 architectures
python64 (for architecture ppc64):
    Mach-O 64-bit executable ppc64
python64 (for architecture x86_64):
    Mach-O 64-bit executable x86_64
python64 (for architecture i386):
    Mach-O executable i386
python64 (for architecture ppc7400):
    Mach-O executable ppc

All four architectures are now present. I haven’t got a 64-bit Mac to try this out on, so I don’t know if it actually runs correctly there. Being universal, this binary works just fine on my 32-bit Mac, of course.

Four Languages

Posted in Computers, Physics on May 31st, 2008 by stan / No Comments »

Inspired by the Slashdot story, Programming as Part of a Science Education?, I have to agree with the author, mostly. These days, every scientist and engineer should be fluent in four kinds of languages:

  1. Verbal: English still works, but the way things are going, Mandarin Chinese is becoming a useful #2.
  2. Pictorial: Each field has its own way to visualize information. In physics, the art of the histogram is paramount.
  3. Mathematical: Calculus the most relevant language for most sciences, but the language of graph theory and abstract algebra can be handy in some niches.
  4. Computational: FORTRAN was king for a while, and C++ is the current king, but on a very slow decline. Personally, I think all scientists would benefit from learning Python first, and then supplement with whatever compiled language is used by their colleagues.

Some people might argue that the first two are languages, and the second two are tools, but I disagree. Both math and programming are ways to express ideas, one symbolic and one procedural. (Unless you do your data analysis in PROLOG, in which case you are impressively loony.) On the physics experiment I work on, our 15-year-old simulation program (woo FORTRAN!) is in many respects the most precise, unambiguous description of how our experiment actually functions. Sure there are piles of words, plots, and equations also documenting everything, but sometimes when I want to know something behaves, I go straight for the code and read it.

In effect, we have built a procedural description of our particle detector, and it is worth recognizing the code as a form of communication. It certainly changes the way you think about programming.

G4TessellatedSolid and G4ExtrudedSolid are broken

Posted in Physics on November 7th, 2007 by stan / Comments Off

Update: This bug has been fixed in GEANT 4.9.1, released on December 14, 2007. Go get it!

Apologies to people reading this (all 3 of you) who don’t care about the GEANT4 simulation library.

I’m pitching this out there in the hopes that Google will index it and help some confused physicist:

G4TessellatedSolid, and therefore the subclass G4ExtrudedSolid, are broken in GEANT 4.9, and most likely earlier releases as well. Geometry optimization (which is enabled in G4LogicalVolume by default) requires the voxelizer to divide the detector geometry into rectangular regions in order to speed up tracking. The voxel generator needs to be able to determine which volumes in your detector overlap with each voxel region. To do this, it calls the G4Tessellated::CalculateExtent() (or G4ExtrudedSolid::CalculateExtent()) passing in an affine transformation describing the solid’s current orientation in the global coordinate system.

The implementation of CalculateExtent() first checks for the easy case, which is a transformation that is pure translation, and behaves correctly in that case. However, if the current transformation has any rotation component at all, then the if statement takes the other branch which is empty! The method obviously does not behave correctly in that case, and the voxelizer will give you nutty results, including mysteriously appearing, disappearing, or clipped volumes.

This problem is now being tracked as bug #983 in the GEANT4 bug database. The workaround is to either disable optimization in the parent G4LogicalVolume of your tessellated or extruded solids, or to patch the G4TessellatedSolid::CalculateExtent() method as described in the bug report.

Always remember to visualize your GEANT4 detector volumes with the raytracer, or you might not catch problems like this!pornstar karina
teen camel toe fuck
pussy cream
ass videos
bdsm clips
old amateur
her first pet sex
fucking wife
gay barebacking
athlete cock
ca whole life insurance
penis enlargement for christian men
gay black men fucking
download hentai free
dragon ball sex toon
gays who swallow
cam teen
canadian small business loan
first gay sex
whip cream in ass
gorgeous pantyhose
cheapest term life insurance
monster facial cumshots
fuzzy pussy
perky coed tits
lesbian galleries
strip video
antique double sink bathroom vanities
boy first time sex
is avril lavigne gay
bi sex videos
pantyhose ebony
girl sleep cams
chubby hot
ass licking mistress
trans porn
two girls caught on hidden camera
asian porn sites
fat naked lesbians
hot girls in very small tight cutoffs
young asian nudes
free mature porno
hot club de paris
rubber bdsm
nude beaches greece
filipina nudity
mature nude models
xxx handjob
anal teens
free femdom trailers
indian sex sites
cuckold hot wife
whip cream in ass
korean femdom
bondage oral
college girls getting fucked
amateur deep throat xxx
big ass teen
hardcore lesbians using strapon
hot lesbians fisting
vintage porn clips
wet breasts
miami zoo
voyeur preteen
zoo movies tgp
paris hilton peeing
gay bodybuilders
hustler hollywood online store
animated teen chat rooms
japanese nude in public
videos of girls wearing thongs
cream pie panties
hand job hetero
business hard money loan
up the skirt cheerleader
make her squirt
kream squirting
animal shelters
vaginal pump
guys wear pantyhose
nude celebrity bondage
in the butt
penis human growth hormone
pantyhose femdom
paris pussy
pee desperate stories
the petting zoo
jeans handjob
breast enhancement pennsylvania
dominatrix domina mistress femdom film clips
spanked wives club
asian hotties
foot fetish mistress
girl hand job
gay virgin
free live porn web cams
big fat huge tits big breast
petite girls xxx
sylvias restaurant harlem
wifey creampie
big blow jobs
wife interracial
sm copenhagen til bdsm adgang bondage
hot asian anal
ladies and girls clothes matches
tied up lesbian femdom
topless teens
bukkake keeps falling on her head lyrics
gay girls
free clit pic
amature wife swap sex video free
horny midget women
hentai cheerleaders
european pussy
caught masturbating at work
term life pro insurance quote
blonde pornstar fucked in ass
seduce my wife
dark obsessions bdsm
bdsm illustrated
stacked zoos zoo york tank
close up vaginal penetration
free female squirt movies
oral play group swallow
nigger fucker
naked brunette pics
bondage mature
diarrhea bukkake
two girls making love
pantyhose glamour filipina model
infinity symbol tattoo
full paris hilton having sex
sea doo personal water craft
clit shots
creampie party
celebrity nips
average boy teen penis size
free clit pumping pics
male genital piercing gallery
gay double anal
i gave my first handjob
beach bj
mature big tit thumbs
age of wonders download
anal prolapse
tight black ass fisting
very horny stories
naughty teen
oral play group swallow
massive squirting
vaginal repair
thongs for young teens
husbands eating creampies
amature outdoor sex
diarrhea bukkake
tight asshole
sink pee
tiffany teen galleries
brazil bargirls
bbw free vids
gay beast
amatuer wife pics
please my wife
paris hiltion nude
pee movie
‘golden shower’ femdom
little peeing girls
hustler ebony dp
adult gay personals
femdom nurses
cock pussy
lesbian wives
transvestite creampies
leave feedback ratings transaction buyer’s
femdom toilet
huge squirt
bang midget 3
high school musical toy stuff
ggg spoon bukkake
hardcore sylvia saint
fake bukkake
free handjob thumbs
petite teens sex
pussy photo
i gave my first handjob
amateur wife movies
body piercing genital female
pornstar interview
animals humping girls
insurance life quote term
hot mom first anal sex
free huge clit clips
brunette squirt
sexual fisting
full paris hilton having sex
small flexible tripod
zoo sex male adult
blond strapon anal
mytunes download
midgets sucking dick
free closeup filipina pussy
bukkake keeps falling on her head lyrics
beefcake vintage wrestling video clips
area attraction near lowry park zoo
girl pee pants
carnival cruise ship glory
midgets sucking dick
teen wet pussy
lesbians undressing
celebs nude fake
camel toe jpg
hot asian anal
personal grants to pay off debts
girlfriends wives naked
under the double eagle mp3
ass jiggle
brazil facial
mature porn sites
college teen fuck
hot lesbians fisting

OS X Leopard Roundup

Posted in Apple, Computers, Python on November 6th, 2007 by stan / No Comments »

After spending 4 days with the new 10.5 release of Mac OS X, I’ve been pretty impressed. Visually, things have improved, except for the obvious problems with the dock and the menu bar. I had the same initial negative reaction to the translucent 3D dock that most other people did, but it has grown on me slowly. The translucent menu bar, however, is simply atrocious if you do not have a very color-neutral (black, white or grey) background. The most common way to correct this is to add a white stripe to the top of your background image. OpaqueMenuBar does this for you automatically whenever your background changes.

Looks aside, I think Leopard’s biggest advance is the amount of attention Apple has shown to developers. (Clearly, OS X is stealing the love from the iPhone…)

X11.app 2.0 is generally a huge improvement. Now based on the X.org 7.2 code base, it draws on the XDarwin code base for X/OS X integration, rather than the source of the old Panther/Tiger X11.app, which was based on XFree86. As a result, there have been a number of regressions, but it sounds like the future of X11.app will be much better. In particular, the source is now being hosted in the X.org git repository, and the main developer is committed to engaging with the user community.

There are a number of glitches, though. Using a fullscreen X desktop (which I suspect is not terribly common) is broken, as is dragging an X window to another display if you have two monitors on your computer. Most annoying, the patch to fix the yellow cursor bug was dropped on the floor, and didn’t make it into X11.app 2.0. The author has since fixed this in an alpha release on the XDarwin wiki page. The Xquartz binary he posts there works great for me, so I’m happy for now.

The launchd program, which is like init/rc/cron/at/inetd all rolled together, is used to pull off two neat tricks in Leopard. First, the $DISPLAY variable is set to a socket that launchd monitors, so the X server now starts automatically on demand. This means you can start up Terminal, do some work, and as soon as you start an X application, you’ll see X11.app appear. The second trick is now an ssh-agent is started on demand when you use SSH. Apple’s ssh-agent can fetch passphrases for your keys from the OS X Keychain as well. You don’t need to use SSHKeychain any more (which is good since it had a major memory leak on my system). The only downside to the ssh-agent Keychain support is there is no obvious way to expire the ssh keys in the agent when the Keychain locks. Once those keys are decrypted into the ssh-agent memory, they stay valid even after you lock your Keychain.

Python has been updated to 2.5.1, which is great because it solves a linker problem I had with the Python bindings for ROOT. The Leopard install of Python includes easy_install, numpy, twisted, and some other handy stuff. In addition, there are new Objective-C/Cocoa bindings, and it comes along with py2app, for generating proper-looking Mac applications entirely written in Python!

The Cocoa programmers are probably excited about Objective-C 2.0, which adds garbage collection and some other improvements, like a compact syntax for looping over an iterator. I’ve been reading up on Objective-C, and the message passing style of object-orientation reminds me greatly of Python’s duck-typing. I find the syntax unspeakably ugly looking, but that’s really just a matter of taste. You can get used to anything, really. :)

Shuffling Algorithms

Posted in Computers on October 30th, 2007 by stan / No Comments »

Last week, my Ph.D. advisor needed to implement a randomized shuffle. The standard algorithm to do this is usually credited to Knuth, and is very easy to describe. Given an array x[] of length N

for i in 1..N:
    j = random number in range [i, N], inclusive
    swap x[i] with x[j]

This algorithm has $$N!$$ possible code paths, which conveniently corresponds to the number of unique permutations of x[]. All that remains is to prove that given a particular permutation of x[], you can reach it with N swaps, and you’ve shown that the above algorithm is complete (can generate any permutation) and unbiased (produces all permutations with equal probability.

Amazingly, any trivial change to the above algorithm will ruin it. The two common mistakes are:

  1. j = random number in range [1,N], inclusive: Here, you might imagine that allowing an element to swap with elements both before and after it will increase randomness somehow. It is true that this version has $$N^N$$ code paths, which is greater than $$N!$$, so all permutations are potentially reachable. However, not all permutations are equally likely (as we’ll see below), which results in a biased algorithm.
  2. j = random number in range [i+1,N], inclusive: By removing the possibility for j = i you might think you are also increasing randomness by never allowing an element to swap with itself, but that is not true. This incorrect version of the algorithm only has $$(N-1)!$$ possible code paths, but you know there are $$N!$$ possible permutations. Therefore some permutations must be unreachable, and this algorithm is therefore incomplete.

To explore these variations, I wrote a small Python program to test the correct and two incorrect versions of the algorithm and report some statistics. The variable $$n$$ sets the length of the sequence to shuffle. Since $$n^n$$ grows very quickly and this program stores every generated sequence in memory, you probably don’t want to try anything larger than $$n=7$$. Here are the results for $$n=7$$:

swap_incorrect: orderings, total = 823543 unique = 5040
repetitions = 163 +/- 50
variation = 30.495%
least common seqs = ['GABCDEF']

swap_nearly_correct: orderings, total = 720 unique = 720
repetitions = 1 +/- 0
variation = 0.000%
least common seqs = (all)

swap_correct: orderings, total = 5040 unique = 5040
repetitions = 1 +/- 0
variation = 0.000%
least common seqs = (all)

Note that swap_incorrect corresponds to case 1 above, and swap_nearly_correct corresponds to case 2. The first incorrect algorithm and the correct algorithm both produce the expected number of unique permutations, $$7! = 5040$$. However, the first incorrect algorithm has substantial variation the frequency of each ordering, with a standard deviation of 30%! The second incorrect algorithm (which never allows j = i) has no repetition, but fails to generate all the possible permutations.

A general result you find if you vary $$n$$ in the above program is that the least common sequence in the first incorrect algorithm is always the original sequence shifted to the right by one index, with the last element moved to the front. It’s not immediately obvious to me how one would prove that for all $$n$$, but it is interesting.

If your $$n$$ gets big enough, $$n!$$ might be larger than the periodicity of your psuedo-random number generator, which means that in practice, you might never be able to generate some orderings. You probably won’t care, since with $$n$$ that large, it would be tough to enumerate all possible orderings anyway. Still good to keep in mind, though…

Entries (RSS)