The LAPACK library is distributed along with IDL, but wrappers to most of the routines are not provided. On Linux, CALL_EXTERNAL can be used to easily access any of the routines. On OS X, the Accelerate Framework can be used. I have not found a solution for Windows1 since the needed symbols in the DLL provided by IDL aren’t exported.

In the following code example for Linux, we will call SGEQRF to determine the QR factorization of a given matrix. First, we need to specify the location of the LAPACK library:

ext = !version.os_family eq 'unix' ? '.so' : '.dll'
lapack = filepath('idl_lapack' + ext, $
                  root=expand_path('<IDL_DEFAULT>', /dlm))

m = 20L
n = 10L
x = randomu(seed, m, n)

info = 0L
tau = fltarr(m < n)
lwork = -1L
work = fltarr(1)
status = call_external(lapack, 'sgeqrf_', m, n, x, m, tau, work, lwork, info, $
                       value=[0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L], $
lwork = long(work[0])
work2 = fltarr(lwork)
status = call_external(lapack, 'sgeqrf_', m, n, x, m, tau, work2, lwork, info, $
                       value=[0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L], $

Here is a more generic routine as an example of calling into LAPACK that works on Linux and OS X.

  1. Please let me know if you have a way to do this on Windows! 

Suyeon Son collects some great tips about Googling for answers to programming questions:

I asked Jeremy Bowers, a news applications developer at NPR, who said he follows a specific pattern when Googling to achieve specific outcomes:

<programming language> <verb> <specific keywords>

e.g. “JavaScript remove key from object”

I would also recommend Googling the exact string of an error message (minus any specific variable names that might appear in it). This is particularly useful for C compile errors.

Also, note the great reference to the original 2000 email to Yak shaving!

I have created a LinkedIn group for IDL Users. If you are on LinkedIn, look it up and invite other IDL users.

QR factorization of a matrix A is the process of determining an orthogonal matrix Q and upper triangular matrix R such that $$A = QR$$ Using a QR factorization is faster and much more numerically stable than finding an inverse matrix of A to solve the system of equations Ax = b. QR factorization is used in fundamental linear algebra IDL routines such as LA_EIGENPROBLEM, LA_LEAST_SQUARES, LA_SVD, and others. I was recently using MAGMA‘s [SDCZ]GEQRF within GPULib to retrieve a QR factorization and found excellent performance improvements by using the GPU.

Also, the full decomposition into Q and R matrices is seldom needed, so the results are not returned in a naive manner. I will show how to retrieve Q and R for the GPULib routines (it’s slightly different than the CPU version).

Continue reading “QR factorization in GPULib.”

Jake Vanderplas, writing on AstroBetter, discusses the licensing of scientific code, providing the following suggestions:

  1. Always license your code. Unlicensed code is closed code, so any open license is better than none (but see #2).
  2. Always use a GPL-compatible license. GPL-compatible licenses ensure broad compatibility for your code, and include GPL, new BSD, MIT, and others (but see #3).
  3. Always use a permissive, BSD-style license. A permissive license such as new BSD or MIT is preferable to a copyleft license such as GPL or LGPL.

I agree. IDLdoc, mgunit, rIDL, my library, and all the other open source code I have on GitHub uses a BSD-style license.

As part of the process of getting IDL recognized by GitHub, I had to add IDL support to Pygments, a popular syntax highlighter supporting many languages. This allows generating syntax highlighting of IDL code.

Use pip to install Pygments:

$ pip install Pygments

Then use pygmentize to generate output:

$ pygmentize -O full,style=colorful -f html -o mg_repmat.html

This produces the output below:

Example Pygments output

Here is the full output. This is obviously not perfect (I just wanted GitHub to recognize the language as IDL).

mpiDL is a set of IDL bindings for the Message Passing Interface (MPI). It is used for tasks where communication between processes is required, as opposed to the independent behavior of TaskDL workers. It can make use of the multiple cores of a single computer and/or multiple nodes of a cluster. mpiDL is supported on OS X and Linux for both OpenMPI and MPICH.

As an example of using mpiDL, I will present a simple probability-based computation of pi using many cores of a computer. If you are interesting in evaluating mpiDL or require more information about, please contact me.

Continue reading “mpiDL example.”

There are IDL-specific editing modes for many of the more popular text editors:

This is the oldest and most complete mode for editing IDL code. JD Smith has been maintaining this for years. JD was looking for a new maintainer a while ago and moved IDLwave from its own website to GitHub, but everything seems to be still working.
This mode includes a routine to scan IDL code and generate tags used for autocompletion.
Vim mode
Marshall Perrin has a Vim mode supporting IDL.
TextMate 2
I used TextMate 2 on the Mac and decided to write this simple mode that supports IDL code and IDLdoc comments. Ethan Gutmann had a TextMate bundle which I liked, but hadn’t been updated for TextMate 2 or newer versions of IDL.

Please let me know if you know of IDL modes for other text editors.

UPDATE 3/5: Some I missed that Jeff N. pointed out:

David Higgins maintains the IDL support for Notepad++.
Support for IDL is builtin!

TaskDL is a task farming library for IDL that allows you to farm out tasks using multiple cores of a single computer or even multiple computers. It is available on Linux, OS X, and Windows. Task farming is suitable for tasks which do not need to communicate with each other, i.e. “naturally” or “embarrassingly” parallel tasks, such as processing many files independently. For more complicated programs which required interprocess communication, mpiDL provides an interface to MPI (Message Passing Interface).

As an example of using TaskDL, I will present a program to compute some areas of the Mandelbrot set and create output files representing them. If you are interesting in evaluating TaskDL or require more information about, please contact me.

Continue reading “TaskDL example.”

I’ve been annoyed for a long time that GitHub marks my IDL code as Prolog in the language statistics. After a quick edit to their Linguist package that determines the language, a long wait for the pull request to get accepted, and more waiting for GitHub to rerun the language statistics on my repos, I now see the true statistics for my projects!

For example, if you go to mglib and click on the bright orange bar, you will see that mglib is 86.7% IDL, 12.1% C, and 1.2% other languages (mostly CMake).

I was told that GitHub reruns language statistics on a push, so if you have a repo that contains IDL code in .pro files that is not getting recognized correctly, try that. I was still not seeing that, though, so I had to contact GitHub support.

older posts »