31 December 2009

Small gotcha when combining Boost.Array, Assign, and Test

When attempting to use Boost.Assign's list_of in expressions like BOOST_CHECK_EQUAL(somearray, list_of(x)(y)(z)), where somearray has a type like boost::array<T,N>, I kept running into funky errors that there was no operator<< defined with the appropriate types. So I'd define one at global scope, but the errors kept arising from the depths of BOOST_CHECK_EQUAL. It turns out that I needed to define such an operator<< in the boost namespace:

namespace boost {

template< typename charT, typename traits, typename T, ::std::size_t N >
::std::basic_ostream& operator<<(
        ::std::basic_ostream &os, const ::boost::array &array)
{
    os << '[' << N << "]{ ";
    ::std::copy(array.begin(),
                array.end(),
                ::std::ostream_iterator(os, " "));
    os << '}';
    return os;
}

}

24 December 2009

Lit search

I finally got around to doing some lit search towards both my dissertation proposal and a poster that I need to present in February. CiteULike's been a nice way to organize the information, especially combined with SyncUThink.

The following is a snapshot of the author's that I'll be wading through:

Orlu   Abe   Abedin   Adams   Adrian   Adumitroaie   Akbary   Alazard   Aldama   Alfonsi   Alfredsson   Alving   Ammer   Andersson   Andrieu   Antonia   Arnal   Arnette   Ashrafian   Ashworth   Baer   Bailly   Bake   Bakken   Balakrishnan   Basili   Bazilevs   Beckie   Beddini   Behnia   Benay   Berggren   Berland   Bertolotti   Berzins   Betyaev   Bhaganagar   Bhattacharya   Biagioni   Bientinesi   Bijl   Biringen   Blaisdell   Blottner   Bochev   Boehm   Bogey   Boninger   Bonnet   Borodai   Bosques   Botella   Bottaro   Bourassa   Bowersox   Boyce   Boyd   Bradshaw   Brandt   Brasseur   Brassuer   Brethouwer   Browne   Brun   Buckley   Buter   Cabrit   Cal   Calo   Cambon   Candler   Cartwright   Castillo   Ceccio   Ch   Chae   Chan   Chanetz   Chang   Chauhan   Cheban   Chen   Cheskidov   Childs   Chiyaka   Choi   Chong   Chow   Christon   Christophorou   Chung   Clemens   Coleman   Collis   Comte   Constantin   Constantinescu   Cooper   Corbett   Cortissoz   Creighton   Cremonesi   Crouch   Cutbirth   Da Prato   Dai   Das   Davidson   De Chant   De Graaff   Debussche   Delery   Demko   Dexun   Dilipkumar   Dmitruk   Dolling   Donatelli   Dong   Donovan   Donzis   Doom   Dotter   Doucet   Dowling   Duan   Dubos   Dufresne   Dumas   Durbin   Dussauge   Eaton   Ecer   Egolf   Elghobashi   Elliott   Elsinga   Emerson   Enrique   Erturk   Eswaran   Ewing   Fabignon   Favre   Fedorchenko   Feijóo   Feireisl   Fernando   Fernholz   Ferrante   Ferziger   Fiala   Fife   Finleyt   Fisher   Fitzgerald   Flandoli   Floryan   Fox   Foysi   Fransson   Friedlander   Friedrich   Fu   Fueyo   Fujii   Gad El Hak   Gallagher   Ganapathisubramani   Garcia   Garg   Garnier   Gatski   George   Gerolymos   Geurts   Ghosal   Ghuloum   Glimm   Gokcol   Goldstein   Goyne   Grant   Grasso   Gravemeier   Greenside   Grosse   Guarini   Gubinelli   Guermond   Gullbrand   Guocan   Gwilliam   Haak   Haberkorn   Hadjadj   Hale   Hamba   Haminh   Hamman   Haselbacher   Hattori   Hauke   Heinrichs   Heinz   Helton   Hemsch   Henkes   Henningson   Hilburger   Hillier   Hochstein   Holloway   Honein   Hou   Hoyas   Huang   Hudea   Hughes   Hwang   Imad   Ishihara   Ivanov   Iwamoto   Jackson   Jacobs   Jayaram   Jiménez   Jiménez   Johansson   Johnson   Jordan   Kachanov   Kafoussias   Kaneda   Kasagi   Kattelans   Katz   Kawaguchi   Kawai   Kawamura   Kedia   Kenny   Khujadze   Kiehn   Kim   Kimmel   Kirby   Klebanoff   Kleiser   Klewicki   Kline   Knight   Kopriva   Korimilli   Kravchenko   Krimmelbein   Krishnamurty   Krishnan   Kritsuk   Krogstad   Kuerten   Kunstmann   Kwok   Lan   Langford   Lechner   Lee   Lehoucq   Lele   Leonard   Leonardo   Levin   Li   Liepmann   Lin   Linan   Liu   Lo   Luchini   Luckring   Luker   Lumley   Lumsdaine   Lund   Luo   Lyons   Ma   Maeder   Maekawa   Maghami   Mahesh   Malaya   Malik   Mallinson   Manca   Manhart   Mansour   Martin   Mashayek   Maslowe   Matsubara   Matsuo   Matthaeus   Mattingly   Mazzei   McComb   Mellet   Meneguzzi   Metzger   Miao   Miller   Mizuno   Moin   Monkewitz   Montgomery-Smith   Morinishi   Moser   Mossi   Moussaoui   Mukund   Muller   Munz   Murthy   Müller   Na   Nagib   Najjar   Najm   Nakabayashi   Narasimha   Neemann   Newhall   Nickels   Nicoud   Norman   Nosetips   Oberkampf   Oberlack   Oden   Orszag   Orti   Osterlund   Padoan   Padula   Paicu   Pancaldo   Park   Parkman   Parneix   Passoni   Patel   Paull   Pavlovi&#x107;   Pego   Pekurovsky   Periaux   Perlin   Peterson   Petrovan   Piomelli   Piro   Pirozzoli   Plesniak   Pletcher   Poggie   Politano   Pope   Pouquet   Prabhu   Prudhomme   Psihoyios   Purtell   Quadrio   Quincy   R&#xf6;ckner   Radespiel   Reed   Reichert   Reisenthel   Rempfer   Reshotko   Reynolds   Ribert   Ringuette   Ristorcelli   Rizzetta   Roach   Robinson   Rodi   Rogallo   Rogers   Romito   Roshko   Roy   Rubinstein   Ruzmaikina   Sadowski   Sagaut   Samimy   Sandberg   Sandham   Sarkar   Satofuka   Scarano   Schiffner   Schilling   Schlatter   Schmitt   Schneider   Schochet   Schwarz   Scientist   Scovazzi   Seckel   Sesterhenn   Settles   Shadid   Shariff   Sharp   Sheikh   Shen   Shewchuk   Shikazono   Shvydkoy   Shyy   Sidi   Simens   Simos   Sinha   Skote   Slepoy   Smith   Smith?   Smits   So   Soliman   Soltani   Sommer   Spalart   Spina   Spiteri   Squires   Stalker   Steinkamp   Stolz   Stoynov   Stroud   Sumitani   Suzuki   Svehla   Sverak   Swartz   Sénéchal   Tamano   Tamura   Taulbee   Tavoularis   Taylor   Tchuenche   Teitel   Tenaud   Terracol   Thangada   Thomas   Tomkins   Torres-Nieves   Trefethen   Trouvé   Trucano   Tsuji   Tu   Tyhtila   Ulerich   Unalmis   Urbin   Vahala   Vallet   Van Zee   Vandromme   Vasseur   Vedula   Vegesna   Venugopal   Visbal   Viswanath   Vreman   Wagner   Waleffe   Wallace   Wang   Watmuff   Waymire   Webster   Wendroff   Wesseling   Williams   Winkel   Winter   Wolf   Wray   Wu   Xenos   Xinliang   Xu   Ya   Yaglom   Yakhot   Yan   Yanwen   Yao   Yeoh   Yeung   Zabaras   Zampaglione   Zandonade   Zang   Zeman   Zeytounian   Zhang   Zhong   Zhongmin   Zhou   Zimmermann   Zolver   Zumbrun   de Freitas   de Lange   lio Vargas   van Oudheusden   van de Geijn   van der Heul  

22 December 2009

Undergraduate research...

...the gift to yourself that just keeps on giving.

17 December 2009

Blue Diamond Mine

Weird linkage stemming from the shuffle tonight. "Blue Diamond Mine" by the Texas Rubies sounds insanely like "Where Did You Sleep Last Night?" by Nirvana. Including all the lyrical structure. This isn't too crazy considering the former's genre and the known folk origin of the later, but it is odd when from nowhere a song you've never heard before strikes you as this uncannily familiar. I leave finding an MP3 of "Blue Diamond Mine" as an exercise for the consumer. It appears on Down to the Promised Land.

01 November 2009

Getting 32-bit libstdc++.so.5 in {Karmic Koala,Lucid Lynx} on a 64-bit system

The Intel compilers require a 32-bit version of libstdc++.so.5 to function. Getting a copy of that build of that library requires a couple of steps in the latest 64-bit Ubuntu {9.10,10.04}. These have been alluded to in other places.  Just in case someone needs the details, here they are:

  1. Download the i386 libstdc++ package for Jaunty: http://packages.ubuntu.com/jaunty/i386/libstdc++5/download
  2. Unpack the .deb archive using ar vx ~/Desktop/libstdc++5_3.3.6-17ubuntu1_i386.deb
  3. Unpack the resulting data.tar.gz using tar xzvf data.tar.gz
  4. Confirm that you got the 32-bit version using file usr/lib/libstdc++.so.5.0.7
  5. Install the library into /usr/lib32 using sudo install usr/lib/libstdc++.so.5.0.7 /usr/lib32
  6. Change to /usr/lib32 using cd /usr/lib32
  7. Create a symlink to finish the task via sudo ln -s libstdc++.so.5.0.7 libstdc++.so.5
Many thanks to everyone who provided the source material:


Updated 24 April 2010: Appears that this procedure also works on the Lucid Lynx release candidate.

28 October 2009

Sugar Plum Plug

Milady got the Nutcracker casting she's talked about wanting for several years. Go hit up the show on one of December 6, 12, 18, 19 @ 7:30pm, 21, or 23 to see her grinning from ear to ear.

26 October 2009

BOOST_UBLAS_SHALLOW_ARRAY_ADAPTOR

uBLAS has a shallow_array_adaptor that allows you to wrap an existing block of data with a uBLAS vector. This is useful if you want to wrap raw data provided by someone else. Exposing this functionality is questionable in terms of encapsulation and ownership, and so it isn't available by default. Consequently the documentation is pretty scarce. Here's an example of it's use in the context of a Boost.Test test case.

#define BOOST_TEST_MODULE $Id: test_complex.cc 1817 2009-03-18 19:01:25Z rhys $

// Before ublas #include, enable boost::numeric::ublas::shallow_array_adaptor<T>
#define BOOST_UBLAS_SHALLOW_ARRAY_ADAPTOR 1

#include <algorithm>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/test/included/unit_test.hpp>
#include <boost/foreach.hpp>
#include <complex>

namespace ublas = boost::numeric::ublas;

typedef std::complex<double>                            complex;
typedef ublas::shallow_array_adaptor<double>            shallow_adaptor_double;
typedef ublas::vector<double, shallow_adaptor_double>   shallow_vector_double;
typedef ublas::shallow_array_adaptor<complex>           shallow_adaptor_complex;
typedef ublas::vector<complex, shallow_adaptor_complex> shallow_vector_complex;

// Ensure we can use std::complex<double> as two consecutive doubles
BOOST_AUTO_TEST_CASE( shared_c_array )
{
  // Assumption must hold true for any of this scheme to work
  BOOST_REQUIRE_EQUAL( sizeof(complex), 2*sizeof(double) );

  const std::size_t N = 6;
  double carray_double[N] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 };
  complex *carray_complex = reinterpret_cast<complex *>(carray_double);

  for (std::size_t i = 0; i < N/2; ++i)
    {
      BOOST_CHECK_EQUAL(carray_double[2*i],   carray_complex[i].real());
      BOOST_CHECK_EQUAL(carray_double[2*i+1], carray_complex[i].imag());
    }

  for (std::size_t i = 0; i < N/2; ++i)
    {
      carray_complex[i] += carray_complex[0];
    }

  for (std::size_t i = 0; i < N/2; ++i)
    {
      BOOST_CHECK_EQUAL(carray_double[2*i],   carray_complex[i].real());
      BOOST_CHECK_EQUAL(carray_double[2*i+1], carray_complex[i].imag());
    }
}

// Ensure we can use a C-array of doubles as a ublas::vector.
BOOST_AUTO_TEST_CASE( shallow_array_adaptor_double )
{
  const std::size_t N = 3;
  double raw[N];

  shallow_adaptor_double adaptor(N, raw);
  shallow_vector_double  vec(N, adaptor);

  BOOST_CHECK_EQUAL( vec.size(), N );

  std::fill(&raw[0], &raw[N], 1.0);
  BOOST_CHECK_EQUAL_COLLECTIONS(&raw[0], &raw[N], vec.begin(), vec.end());

  std::fill(vec.begin(), vec.end(), 2.0);
  BOOST_CHECK_EQUAL_COLLECTIONS(&raw[0], &raw[N], vec.begin(), vec.end());
}

// Ensure we can use a C-array of std::complex<double> as a ublas::vector.
BOOST_AUTO_TEST_CASE( shallow_array_adaptor_complex )
{
  const std::size_t N = 3;
  complex raw[N];

  shallow_adaptor_complex adaptor(N, raw);
  shallow_vector_complex  vec(N, adaptor);

  BOOST_CHECK_EQUAL( vec.size(), N );

  std::fill(&raw[0], &raw[N], complex(1.0, -1.0));
  BOOST_CHECK_EQUAL_COLLECTIONS(&raw[0], &raw[N], vec.begin(), vec.end());

  std::fill(vec.begin(), vec.end(), complex(2.0, -2.0));
  BOOST_CHECK_EQUAL_COLLECTIONS(&raw[0], &raw[N], vec.begin(), vec.end());
}

// Ensure we can use the same data as either double or complex ublas::vector
BOOST_AUTO_TEST_CASE( shallow_array_adaptor_shared )
{
  const std::size_t N = 6;
  double carray_double[N] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 };
  complex *carray_complex = reinterpret_cast<complex *>(carray_double);

  shallow_adaptor_double adaptor_double(N, carray_double);
  shallow_vector_double  vec_double(N, adaptor_double);

  shallow_adaptor_complex adaptor_complex(N, carray_complex);
  shallow_vector_complex  vec_complex(N, adaptor_complex);

  for (std::size_t i = 0; i < N/2; ++i)
    {
      BOOST_CHECK_EQUAL(vec_double[2*i],   vec_complex[i].real());
      BOOST_CHECK_EQUAL(vec_double[2*i+1], vec_complex[i].imag());
    }

  for (std::size_t i = 0; i < N/2; ++i)
    {
      vec_complex[i] += vec_complex[0];
    }

  for (std::size_t i = 0; i < N/2; ++i)
    {
      BOOST_CHECK_EQUAL(vec_double[2*i],   vec_complex[i].real());
      BOOST_CHECK_EQUAL(vec_double[2*i+1], vec_complex[i].imag());
    }

  for (std::size_t i = 0; i < N; ++i)
    {
      vec_double[i] += vec_double[N-1];
    }

  for (std::size_t i = 0; i < N/2; ++i)
    {
      BOOST_CHECK_EQUAL(vec_double[2*i],   vec_complex[i].real());
      BOOST_CHECK_EQUAL(vec_double[2*i+1], vec_complex[i].imag());
    }
}

Subscribe Subscribe to The Return of Agent Zlerich