$include_dir="/home/hyper-archives/ublas/include"; include("$include_dir/msg-header.inc") ?>
From: Andreas Klöckner (lists_at_[hidden])
Date: 2008-08-11 20:10:14
Hi Jeremy,
On Montag 11 August 2008, Jeremy Conlin wrote:
> I have the need to take the square root of a ublas::vector, i.e. take the
> square root of every element of the vector, independently.  I tried simply
> importing <cmath> but that didn't work.  Is there a ublas header somewhere
> that adds this functionality?
Try the attached header together with something like this:
8< ---------------------------------------------------------------
      struct int_ceil_functor
      {
        typedef double value_type;
        typedef const double &argument_type;
        typedef int result_type;
        static result_type apply(argument_type x)
        {
          return int(ceil(x));
        }
      };
Then use
   pyublas::unary_op<int_ceil_functor>::apply(somevec)
8< ---------------------------------------------------------------
This has the advantage that it works together with Ublas's ET machinery, 
giving you the option of not having a temporary. (You'll have to do some 
simple knitting to make it do "sqrt" instead of "int_ceil".)
Andreas