Boost logo

Boost Users :

From: Chris Weed (chrisweed_at_[hidden])
Date: 2007-01-22 08:22:20


Whoops that should be v[j]

 std::vector<complex<float> >
 fft(const std::vector<float>& v)
 {
   std::vector<complex<float> > result(v.size(),complex<float>(0,0));
   complex<float> c(0,1);
   for(size_t i=0;i<v.size();++i)
     for(size_t j=0;j<v.size();++j)
     {
       result[i] += (v[j]*exp(-2*M_PI*c*i*j/v.size()));
     }
   return result;
 }

but you get the idea.
Chris

On 1/22/07, Chris Weed <chrisweed_at_[hidden]> wrote:
> Hi,
> I wanted to try to write a DFT that can take a compile-time data
> structure such as the following:
>
> #include <boost/mpl/math/double.hpp>
>
> // v = [1.01 2.01 3.01 4.01 5.01 6.01 7.01]
> typedef boost::mpl::math::string_c_to_double<1,'.',0,1>::type D1;
> typedef boost::mpl::math::string_c_to_double<2,'.',0,1>::type D2;
> typedef boost::mpl::math::string_c_to_double<3,'.',0,1>::type D3;
> typedef boost::mpl::math::string_c_to_double<4,'.',0,1>::type D4;
> typedef boost::mpl::math::string_c_to_double<5,'.',0,1>::type D5;
> typedef boost::mpl::math::string_c_to_double<6,'.',0,1>::type D6;
> typedef boost::mpl::math::string_c_to_double<7,'.',0,1>::type D7;
> typedef boost::mpl::math::string_c_to_double<8,'.',0,1>::type D8;
>
> typedef boost::fusion::vector<D1,D2,D3,D4,D5,D6,D7,D8> VectorType;
>
> and perform the fourier transform at compile time.
>
> The DFT is fairly simple as a for-loop it would look like this:
> std::vector<complex<float> >
> fft(const std::vector<float>& v)
> {
> std::vector<complex<float> > result(v.size(),complex<float>(0,0));
> complex<float> c(0,1);
> for(size_t i=0;i<v.size();++i)
> for(size_t j=0;j<v.size();++j)
> {
> result[i] += (v[i]*exp(-2*M_PI*c*i*j/v.size()));
> }
> return result;
> }
>
> To get this algorithm into fusion, I would need a function object for
> times, divide, and exp.
> Thanks,
> Chris
>
> On 1/22/07, Joel de Guzman <joel_at_[hidden]> wrote:
> > Chris Weed wrote:
> > > Hi,
> > > I am interested in combining the fusion and mpl::math libraries, but I
> > > am not sure if they currently support what I want to do.
> > >
> > > I want to use generic math operations that can easily switch between
> > > run-time and compile-time. I think this would require writing the
> > > mpl::math functions as "Polymorphic Function Object" as described in
> > > the fusion documentation. I am not sure if there is any mpl::math
> > > documentation that describes this.
> > >
> > > It looks like the MPL currently has some math operations that are
> > > strictly meta-functions in boost/mpl/aux_/arithmetic_op.hpp. Are the
> > > any plans to expand these to be functions also?
> >
> > It would be good to start with some use cases. With use cases,
> > it's easier to understand what exactly you want to accomplish.
> >
> > Regards,
> > --
> > Joel de Guzman
> > http://www.boost-consulting.com
> > http://spirit.sf.net
> >
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
> >
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net