build scipy-0.6.0 on Solaris with SunStudio 12

I finally got some clues about how to build scipy with SunStudio and Sun Performance library from this discussion thread. And here are the steps I sumerized:

1. Download the source tar file of scipy, SciPy 0.6.0 tarball, and extract it to anywhere. Apply the following changes to /usr/lib/python2.4/vendor-packages/numpy/distutils/fcompiler/sun.py, since f77compat library is not available on x86/x64 platform,

--- sun.py.orig	2008-10-31 18:30:17.519425733 +0800
+++ sun.py	2008-10-31 18:30:23.842495794 +0800
@@ -38,7 +38,7 @@
         return ['-xtarget=generic']
     def get_libraries(self):
         opt = []
-        opt.extend(['fsu','sunmath','mvec','f77compat'])
+        opt.extend(['fsu','sunmath','mvec'])
         return opt
 if __name__ == '__main__':

and apply the following patch,


--- scipy/sparse/sparsetools/sparsetools.h    2007-09-22 15:55:25.000000000 +0800
+++ scipy/sparse/sparsetools/sparsetools.h    2008-10-31 17:54:47.317379521 +0800
@@ -22,6 +22,7 @@

 #include <vector>
 #include <algorithm>
+#include <functional>

 /*

2. Set CBE environment (/opt/jdsbld/bin/env.sh), and the following environment variables,

$ export LDFLAGS="-lCrun -lCstd"
$ export LAPACK=/opt/SUNWspro/lib/libsunmath.so
$ export BLAS=/opt/SUNWspro/lib/libsunperf.so

3. Then build, install, and test

$ python setup.py build
$ pfexec setup.py install
$ cd ~ # don't run the test under the source directory
$ python
>>> import scipy
>>> scipy.test()

Though, you would see several errors, most of the tests passed.

调整 OpenSolaris nVIDIA 显卡外接投影仪的分辨率

我所使用的是Dell的一款笔记本,配备了nVIDIA的显卡。当外接投影仪的时候,用nvidia-settings(1)自动检测(Detect Displays),可以发现有另一个model(因为是VGA输出,所以通常是CRT-0),但是这个screen的分辨率不能调整、且仅为640x480。这对进行演讲来说非常不方便。可以用如下方法来解决:

  • 先点击“Save to X Configuration File”将这个设置保存到X的配置文件中,即/etc/X11/xorg.conf,
  • 然后编辑该配置文件,定位到ModelName为“CRT-0”的那个Monitor Section,调整水平和垂直刷新,例如:

        HorizSync 31.5 - 64.3
        VertRefresh 40.0 - 150.0

  • 然后退出并重启X,再运行nvidia-settings,就可以看到CRT-0有更多的分辨率可以选择了,不过好像只有4:3的分辨率可选。

详细信息可以参考nVIDIA驱动的README

If your app starts earlier than gnome-session

We found a serious problem recently, if your application starts earlier than gnome-session, and has accesses to gconf services, like iiim-panel, you will see two gconfd daemons after you login to gnome. It might due to the introducing of gnome-keyring (with ssh-agent), so that gnome-session does not recognize and reuse the existing gconfd daemon?

Then when iiim-properties(1) is invoked later by user, it actually talks to the
2nd gconfd, but iiim-panel still connects to the 1st gconfd.That's why iiim-panel does not update its language list after adding/removing input-methods with iiim-properties. [OS.o bug #4024]

A workaround is to terminate your gconfd daemon after iiim-panel is started. There would be no explict impacts to existing clients, they will try to connect to the new gconfd. A better solution is to defer the iiim-panel starting after gnome-session.

P.S., it turns out killing gconfd does not work perfectly, iiim-properties(1)
launched from terminal and the one launched by iiim-panel(1) would still start two different gconf daemons.

How to switch to scim on Solaris/OpenSolaris snv_99

At first, install scim and your favorite input-method engines from pkg.opensolaris.org, you could list the available scim packages, by $ pkg list -a SUNWscim*. For nevada users, you need select the scim metacluster in installer.

Then, edit your $HOME/.profile to export the GTK_IM_MODULE to scim, and re-login


$ cat >> ~/.profile << EOF
> GTK_IM_MODULE=scim
> export GTK_IM_MODULE
> EOF

To switch back to iiim, you could simply comment out the above lines in your $HOME/.profile, and re-login.

Changing UID and GID on Mac OS X Leopard


$ id
uid=501(yongsun) gid=501(yongsun) groups=501(yongsun),98(_lpadmin),81(_appserveradm),79(_appserverusr),80(admin)

$ sudo dscl . -change /Users/yongsun UniqueID 501 1000
$ sudo dscl . -change /Users/yongsun PrimaryGroupID 501 1000
$ sudo dscl . -change /Groups/yongsun PrimaryGroupID 501 1000

$ id
uid=1000(yongsun) gid=1000(yongsun) groups=1000(yongsun),98(_lpadmin),81(_appserveradm),79(_appserverusr),80(admin)

$ chown -R yongsun:yongsun /Users/yongsun

Gnome.Asia Input-Method Presentation Slides are online

Schedule:

Sunday, October 19 2008
No. 1 Conference Hall
14:00
Input methods Technologies - Part1
James Su, Peng Huang
15:00Input methods Technologies - Part2
Yong Sun, Peng Wu

And here is the PDF version of presentation slides. Thanks a lot for the co-authors, Peng Wu, Peng Huang, and Feng Zhu, and thanks to James for reviewing. Looking forward to meet you in the forum, and share your thoughts and comments with us!

Spectral Clustering with Python

Spectral Clustering is the last topic of our NLP learning group activity, hosted by Feng. Here is my homework, you may refer to this tutorial for the symbols used in this simple program. While I still have no idea about the underlying principles in the algorithm.

#!/usr/bin/python
# copyright (c) 2008 Feng Zhu, Yong Sun
import heapq
from functools import partial
from numpy import *
from scipy.linalg import *
from scipy.cluster.vq import *
import pylab
def line_samples ():
    vecs = random.rand (120, 2)
    vecs [:,0] *= 3
    vecs [0:40,1] = 1
    vecs [40:80,1] = 2
    vecs [80:120,1] = 3
    return vecs
def gaussian_simfunc (v1, v2, sigma=1):
    tee = (-norm(v1-v2)**2)/(2*(sigma**2))
    return exp (tee)
def construct_W (vecs, simfunc=gaussian_simfunc):
    n = len (vecs)
    W = zeros ((n, n))
    for i in xrange(n):
        for j in xrange(i,n):
            W[i,j] = W[j,i] = simfunc (vecs[i], vecs[j])
    return W
def knn (W, k, mutual=False):
    n = W.shape[0]
    assert (k>0 and k<(n-1))
    for i in xrange(n):
        thr = heapq.nlargest(k+1, W[i])[-1]
        for j in xrange(n):
            if W[i,j] < thr:
                W[i,j] = -W[i,j]
    for i in xrange(n):
        for j in xrange(i, n):
            if W[i,j] + W[j,i] < 0:
                W[i,j] = W[j,i] = 0
            elif W[i,j] + W[j,i] == 0:
                W[i,j] = W[j,i] = 0 if mutual else abs(W[i,j])
vecs = line_samples()
W = construct_W (vecs, simfunc=partial(gaussian_simfunc, sigma=2))
knn (W, 10)
D = diag([reduce(lambda x,y:x+y, Wi) for Wi in W])
L = D - W
evals, evcts = eig(L,D)
vals = dict (zip(evals, evcts.transpose()))
keys = vals.keys()
keys.sort()
Y = array ([vals[k] for k in keys[:3]]).transpose()
res,idx = kmeans2(Y, 3, minit='points')
colors = [(1,2,3)[i] for i in idx]
pylab.scatter(vecs[:,0],vecs[:,1],c=colors)
pylab.show()