28 January 2010

We have agreed that if our stockholders fail to adopt the Amendment at the Special Meeting or any postponement or adjournment thereof, we will continue to seek to obtain the requisite approval at least as frequently as every six months until such stockholder adoption has been obtained.

Really. Thankfully, they caught and removed the draft paragraph's final "you stupid asshats".

Admittedly, I have not yet fully reviewed all the particulars. The choice paragraph appears at the bottom of page 6.

20 January 2010

The Wikipedia article on in-place matrix transposition tantalizingly hints that FFTW can compute rectangular in-place matrix transposes efficiently (or as efficiently as one can). FFTW's manual, however, is silent. At least as far as section headings, function names, and the index are concerned.

Frigo and Johnson's paper, on page 6, spells out how to tap into the in-place transpose routines: create a rank-0 transform of vector rank 2 using transposed vector strides. I had to bug Matteo Frigo twice (nice guy!) to figure out how to accomplish this using the guru interface.

You can get a better performing plan if you're willing to use flags = FFTW_MEASURE or its big brothers. I chose to use FFTW_ESTIMATE in the sample above because I didn't want the planning process to destroy the input array.

There are many restrictions around the the New-array execute interface, so be careful if you go that route.
One very cool thing is that you don't need to know a priori that you're computing an in-place transpose. The planner works for out-of-place transposes as well. Another cool thing is that the plans are useful for rectangular transposes and square transposes alike with more efficient algorithms being used for the latter case.

From burning lots of time playing with FFTW's transpose capabilities, it seems that the planner returns NULL (i.e. bombs) whenever you attempt to transpose a non-contiguous matrix. That rules out specifying leading dimensions and/or arbitrary strides
as far as I can tell. Someone please correct me if I'm wrong. I'd love to be wrong so I can use FFTW to emulate Intel MKL's mkl_trans.h functionality for systems where a newer version of MKL is not available.

I sometimes want to fill a Boost.MultiArray
with a particular value. For concrete implementations like boost::multi_array or boost::multi_array_ref,
the task isn't too hard and std::fill works just fine. But getting an arbitrary-dimensional version working
that only uses the MultiArray concept takes a little thought. This is important when working with views.
I additionally want the solution to take advantage of
the contiguous storage guarantees made by multi_array and multi_array_ref.

Because fill looks like for_each with an assignment-like UnaryFunction, I decided to
write a MultiArray-specific for_each implementation. First comes a helper functor
recursively templated on the dimensionality:

The functor uses std::for_each for the one dimensional base case. The BOOST_STATIC_ASSERTs are there just to keep me
from shooting myself in the foot. A smarter version might specialize for the two- and three-dimensional cases, check the underlying strides,
and then be certain to iterate in the faster directions first.

Now that we've got for_each_functor that works on the general MultiArray concept,
it's straightforward to implement for_each:

With for_each complete, we can move on to implementing fill by mapping an assignment-like functor over
over a MultiArray.

In my particular application I have MultiArrays with complex-valued elements from
a couple of different numeric libraries (e.g. std::complex<T>, T[2]) and I'd like to be able
to fill a MultiArray with a value for which a member operator= may not be available. To accommodate
this need, I created a templated assignment functor which can be specialized using schmancy boost::enable_if
techniques based on both the target and source of the assignment:

That very last code snippet is missing details and won't compile. Note that the suzerain::complex::assign_complex invocation may itself be a template and it receives appropriate type information. This turned out to be important when I wanted to fill a complex-valued MultiArray with a real-valued scalar. I needed two versions of assign_complex: one that took as a Source a recognized complex type and one that took a scalar type. boost::enable_if and boost::disable_if made it easy to provide an assign_complex template that did the right thing.

Given the right #includes in the right places,
the other snippets should all compile. Please let me know if they do not.

This post topic came from a question
I asked on boost-users
a couple of days back. Hopefully someone else finds this post and can use this fill routine.
Thank you to Ronald Garcia for his response and for maintaining Boost.MultiArray.