Monday, May 19, 2014

GSL on Windows

Compiling GSL (Gnu Scientific Library) natively with Visual Studio 2013 Express

  1. Install GSL
    1. Download GSL 1.16 and unpack it.
    2. Download VS sln files from Brian Gladmann's page GSL for Windows. Unpack it into the same directory as GSL. It will add a new directory (build.vc11) and replace a couple files.
    3. If compiling for 64-bit Intel, you might need to change build.vc11/fp-win.c because 64-bit Intel does not allow setting the precision of floating point (see Boost Ticket #4964). On line 40, replace
      
      mask |= _MCW_PC;
      
      
      with
      
      #ifndef _WIN64
       mask |= _MCW_PC;
      #endif
      
      
    4. Read build.vc11/gsl.vc11.readme.txt file. It contains detailed instructions. Basically there will be 4 solution files in build.vc11 directory:
      gsl.dll.sln
      gsl.lib.sln
      test.gsl.dll.sln
      test.gsl.lib.sln
      
      Building any of these is similar so I will go through the steps for building gsl.lib.sln.
    5. Double click gsl.lib.sln to bring up MSVS. Select the solution and change the Solution Platform from Win32 to x64. Then for each project, change the Platform toolset to v120 (in Configuration Properties-->General).
    6. Since I choose to use gslhdrs, I add the project as a dependency of the cblaslib project. And in Configuration Manager, I uncheck the gsldefs project so it won't get built.
    7. Select "Build Solution" and it should build hopefully with no errors.
    8. The default code generation flag is Multi-threaded static runtime (ie, /MTd, /MT). If you switch to a Multi-threaded DLL runtime build (ie, /MDd, /MD), you might encounter errors similar to this:

      error C2375: 'gsl_acosh' : redefinition; different linkage in the file math.h

      This is because the build.vc11/config.h (which is normally generated by configure on Unix-type systems) tells the compiler it (ie, the compiler itself) doesn't have an implementation of acosh when it actually does and therefore does not need a GSL implementation.

      To fix this, go into build.vc11/config.h and change

      
      /* Define to 1 if you have the declaration of `acosh', and to 0 if you don't.
       */
      #undef HAVE_DECL_ACOSH
      
      to
      
      /* Define to 1 if you have the declaration of `acosh', and to 0 if you don't.
       */
      #define HAVE_DECL_ACOSH 1
      
      And repeat for similar problems referring to math.h. Then rebuild the Solution.
    9. I recommend building test.gsl.lib.sln as well. After building, choose any of the projects to run.
  2. Using GSL
    1. If you plan to use the DLL version of GSL in your application, you must pass -DGSL_DLL to the compiler (in Configuration Properties-->C/C++-->Preprocessor-->Preprocessor Definitions) when building your application.

Wednesday, November 13, 2013

Birds of Cold Mountain

A large number of birds appear in Cold Mountain's (寒山) poems. Here is a list I've compiled thus far.

The Cantonese romanization is Jyutping but with the following modifications:

  1. I use "y" instead of "j" for the /j/ (English "y" sound).
  2. There used to be a distinction in Cantonese between the series (/ts/, /tsʰ/, /s/) and (/tɕ/, /tɕʰ/, /ɕ/). Now this distinction is mostly lost and speakers use one or the other. My personal experience has been that I hear /tɕ/, /tɕʰ/, and /s/. Therefore I will use "j", "q", and "s".
  3. I use modified Yale tones ā, á, a, xà, xá, xa to represent the tones a1, a2, a3, a4, a5, a6 respectively. I find contour symbols more immediate and more easily comparable to the pinyin tones. I use a prefix "x" to represent low tones because (1) "x" is less visually intrusive than the Yale romanization's usage of "h" and (2) you need this low tone information before you begin to process the contour information.


TraditionalSimplifiedMand.Canton.Definition
niǎoniúBird
fèngfxungPhoenix
āCrow
chīSparrowhawk
鸿 hónghxùngBean goose. It is also used in an idiom to mean "grand".
gūkSwan. Although today it is a word for archery target.
白鶴白鹤 báihèbxaak.hxokWhite crane
鸚鵡鹦鹉 yīngwǔyīng.mxoúParrot
鸂鶒 xīchìkāi.qīk(?) It appears to be a type of waterfowl which resembles a Mandarin duck.
鷦鷯鳥鹪鹩鸟 jiāoliáoniǎojiū.lxiù.niúWren
fxùWild duck
白鷺白鹭 báilùbxaak.lxouEgret
鴛鴦鸳鸯 yuānyāngyūn.yeūngMandarin duck. They are consider symbols of fidelity as the Chinese believed they formed lifelong couples.
quèjeukSparrow

Friday, December 14, 2012

Gustav Leonhardt


I recently found out that Dutch harpsichordist and influential teacher Gustav Leonhardt had passed away January 12th. I first encountered his recordings in college particularly his effort with Nikolaus Harnoncourt to record all of Bach's sacred cantatas using period instruments and all male voices. A massive project that started in 1971 and only completed in 1990. I felt Harnoncourt's choir was too harsh and militant; but Leonhardt's was full of spirituality and earthiness though his soprano soloists had trouble at times. The cantata Gelobet seist du, Jesu Christ (BWV 91) is one of my favorite cantatas and the wonderful soundscape is typical of Leonhardt. I was not a fan of Leonhardt's harpsichord playing when he was younger because I felt it was a little bit stiff; but I think as he got older, he loosened up. A wonderful example is the above clip of the theme to Bach's Goldberg variations which was produced in 1976.

I also want to mention these two in memoriam videos of Gustav Leonhardt: Bach's concerto for 4 harpsichords and this interview in Dutch (a language that I don't understand).

Tuesday, November 27, 2012

Python Notes

  1. Python 2.7 not available for direct download for Cygwin. Follow the directions at Python 2.7.x under Cygwin to install it. It assumes you have installed gcc/g++ and make in Cygwin.
  2. This was the clearest explanation of Unicode on Python I could find: Unicode in Python, Demystified.

Wednesday, November 21, 2012

Name Notes


A rectification of browser technology names.


Firefox 17Chrome 23IE 9Opera 12
Layout Engine Gecko WebKit Trident Presto
JavaScript Engine SpiderMonkey (in C++)
Rhino (in Java, not used within browser)
Compiles into byte-code
V8 (in C++)
Compiles into assembly
Chakra Carakan (in C++)

The official name for what is normally called JavaScript is ECMAScript. JavaScript was a trademark from Sun and Netscape. Microsoft called its version JScript. See the Wikipedia article ECMAScript for a history.

Monday, November 19, 2012

Rectification of Names (正名)

齊景公問政於孔子。 孔子對曰:「君君,臣臣,父父,子子。」

Duke Jǐng of Qí asked Confucius about government. Confucius replied "Let the ruler be a ruler; the minister, a minister; the father, a father; the son, a son."

-- The Analects 「論語」, 12:11.

Javascript Note 3

  • In Mozilla, the order of events for keystrokes are
    1. keydown event. At this point only modification keys are recorded.
    2. keypress event. At this point the main key is recorded.
    3. keyup event. At this point only modification keys are available.
    4. Element updated.
    Notice the different events for pressing Ctrl-Shift G and Ctrl-Alt G. It depends on key timing. The various key codes are not ASCII key codes but DOM key codes (see KeyboardEvent). Also Mozilla warns that the keyCode attribute of printable keys in keydown and keyup event handlers should not be used.


    Examples
    1. Notice the keyCode is G even though the charCode is g.
      keydown :ALT keyCode[ (18)], charCode[(0)]
      keydown :ALT-SHIFT keyCode[ (16)], charCode[(0)]
      keydown :ALT-SHIFT keyCode[G(71)], charCode[(0)]
      keypress:ALT-SHIFT keyCode[(0)], charCode[G(71)]
      keyup   :ALT-SHIFT keyCode[G(71)], charCode[(0)]
      keyup   : keyCode[ (16)], charCode[(0)]
      
      keydown :CTRL keyCode[ (17)], charCode[(0)]
      keydown :CTRL-ALT keyCode[ (18)], charCode[(0)]
      keydown :CTRL-ALT keyCode[G(71)], charCode[(0)]
      keypress:CTRL-ALT keyCode[(0)], charCode[g(103)]
      keyup   :CTRL-ALT keyCode[G(71)], charCode[(0)]
      keyup   :ALT keyCode[ (17)], charCode[(0)]
      
    2. Typing apostophe (') (ASCII code 39) corresponds to DOM keycode 222. Javascript's String.fromCharCode translates numeric codes to UTF-8 characters. In UTF-8, 222 corresponds to capital Thorn (Þ) which is a letter used in Old English and still used in Icelandic.
      keydown : keyCode[Þ(222)], charCode[(0)]
      keypress: keyCode[(0)], charCode['(39)]
      keyup   : keyCode[Þ(222)], charCode[(0)]
      
    3. Typing "one" results in
      keydown : keyCode[O(79)], charCode[(0)] value[]
      keypress: keyCode[(0)], charCode[o(111)] value[]
      keydown : keyCode[N(78)], charCode[(0)] value[o]
      keypress: keyCode[(0)], charCode[n(110)] value[o]
      keyup   : keyCode[O(79)], charCode[(0)] value[on]
      keyup   : keyCode[N(78)], charCode[(0)] value[on]
      keydown : keyCode[E(69)], charCode[(0)] value[on]
      keypress: keyCode[(0)], charCode[e(101)] value[on]
      keyup   : keyCode[E(69)], charCode[(0)] value[one]
      
      Notice, the full value of the input field is available only on keyup.
    Code Snippet:
    <html>
    <head>
    <style>
    b { color: blue; }
    </style>
    <script type="text/javascript">
    function msg(e, txt) {
      var mydiv = document.getElementById("result");
      
      var modifier = [];
      [[e.ctrlKey,"CTRL"], [e.altKey, "ALT"],
       [e.metaKey, "META"], [e.shiftKey, "SHIFT"],
       [e.getModifierState("OS"), "OS"], [e.getModifierState("CapsLock"),"Caps"]].forEach(
         function (x) {
            if (x[0]) {
              modifier.push(x[1]);
            }
         }
      );
      var txt = mydiv.innerHTML + "<br/>"
              + txt + ":<b>" + modifier.join("-") + "</b>"
              + " keyCode[<b>" + String.fromCharCode(e.keyCode) + "</b>(" + e.keyCode +")],"
              + " charCode[<b>" + String.fromCharCode(e.charCode) + "</b>(" + e.charCode+")]";
      
      if (document.getElementById("includeValue").checked) {
          txt = txt + " value[" + document.getElementById("maininput").value + "]";
      }
      
      mydiv.innerHTML = txt;
    }
    
    function clearResult(e) {
      document.getElementById("result").innerHTML = "";
      document.getElementById("maininput").value = "";
    }
    
    </script>
    </head>
    <body>
    
    <form>
    <input id="maininput"
           type="text" size="80"
           onkeyup=   "msg(event, 'keyup &nbsp;&nbsp;')"
           onkeydown= "msg(event, 'keydown ')"
           onkeypress="msg(event, 'keypress')">
    </input>
    <input id="includeValue" type="checkbox">Include Value</input>
    <input type="button" value="Clear" onclick="clearResult(event)"/>
    <br/>
    <div id="result" style="font-family:monospace">
    </div>
    </form>
    
    </body>
    </html>