[fusion][mpl::math] generic math operations
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? Chris
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
Hi,
I wanted to try to write a DFT that can take a compile-time data
structure such as the following:
#include
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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Whoops that should be v[j]
std::vector
Hi, I wanted to try to write a DFT that can take a compile-time data structure such as the following:
#include
// 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
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
fft(const std::vector<float>& v) { std::vector result(v.size(),complex<float>(0,0)); complex<float> c(0,1); for(size_t i=0;i 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
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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Wow, there's still interest in MPL.Math? Cooool. I'll look into your problem when I get the chance--hopefully within the next couple of days. Fixing the documentation in general will take significantly longer. Cromwell D. Enage ____________________________________________________________________________________ Need a quick answer? Get one in minutes from people who know. Ask your question on www.Answers.yahoo.com
Yea, I might be the only one. :-P
Is there any available documentation? I have mostly used the source
code, and some previous mail-list discussions to try to get this
working.
Chris
On 1/22/07, Cromwell Enage
Wow, there's still interest in MPL.Math? Cooool.
I'll look into your problem when I get the chance--hopefully within the next couple of days. Fixing the documentation in general will take significantly longer.
Cromwell D. Enage
____________________________________________________________________________________ Need a quick answer? Get one in minutes from people who know. Ask your question on www.Answers.yahoo.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
--- Chris Weed wrote:
Yea, I might be the only one. :-P
Is there any available documentation? I have mostly used the source code, and some previous mail-list discussions to try to get this working.
It'll take three or four days to revamp the RST source files. What will take much longer is getting docutils to convert these source files to real documentation; I should try to help solve your actual problem before doing that. Cromwell D. Enage ____________________________________________________________________________________ Do you Yahoo!? Everyone is raving about the all-new Yahoo! Mail beta. http://new.mail.yahoo.com
On 1/22/07, Cromwell Enage
--- Chris Weed wrote:
Yea, I might be the only one. :-P
Is there any available documentation? I have mostly used the source code, and some previous mail-list discussions to try to get this working.
It'll take three or four days to revamp the RST source files. What will take much longer is getting docutils to convert these source files to real documentation; I should try to help solve your actual problem before doing that.
Cromwell D. Enage
Great! Thanks, Chris
Chris Weed wrote:
Yea, I might be the only one. :-P
Is there any available documentation? I have mostly used the source code, and some previous mail-list discussions to try to get this working.
Chris
On 1/22/07, Cromwell Enage
wrote: Wow, there's still interest in MPL.Math? Cooool.
I'll look into your problem when I get the chance--hopefully within the next couple of days. Fixing the documentation in general will take significantly longer.
I hadn't heard of MPL.Math before... I was actually looking for a way the other day of computing a fixed-point sin lookup table at compile-time using Taylor series approximation for a fixed-point class I have templated on magnitude and fractional bit count. I ended up getting lost and wrote a small program to generate a table and copy & pasted the output into a source file for the fixed-point precision I was using at present. It seems that it would be nice to be able to generate a new table for say 8.24 fixed-point without needed to rerun an external tool. Does this seem like the sort of thing MPL.Math could help with? Thanks, Michael Marcin
--- Michael Marcin wrote:
I hadn't heard of MPL.Math before...
I was actually looking for a way the other day of computing a fixed-point sin lookup table at compile-time using Taylor series approximation for a fixed-point class I have templated on magnitude and fractional bit count. I ended up getting lost and wrote a small program to generate a table and copy & pasted the output into a source file for the fixed-point precision I was using at present.
It seems that it would be nice to be able to generate a new table for say 8.24 fixed-point without needed to rerun an external tool.
#include <iostream>
#include
Does this seem like the sort of thing MPL.Math could help with?
You can look at the sine.cpp example program and see for yourself. As for the sine metafunction implementation, the Taylor series is actually built using a combination of Boost.Preprocessor macros and intermediary typedefs instead of template recursion.
Thanks,
No problem.
Michael Marcin
Cromwell D. Enage ____________________________________________________________________________________ Never miss an email again! Yahoo! Toolbar alerts you the instant new Mail arrives. http://tools.search.yahoo.com/toolbar/features/mail/
I don't think this is what he means by 8.24 fixed-point.
I think he is looking for representing a number by 8 bits to the left
of the decimal, and 24 bits after the decimal, thus creating a special
32-bit number format.
I suspect you could use this library to do what you want, but I think
you would need a way to convert the MPL::Math floating-point
representation to your representation. It has been a while since I
looked at the code, but I recall that MPL::Math is essentially an
implementation of IEEE floating-point representation in a templated
class.
Chris
On 1/24/07, Cromwell Enage
--- Michael Marcin wrote:
I hadn't heard of MPL.Math before...
I was actually looking for a way the other day of computing a fixed-point sin lookup table at compile-time using Taylor series approximation for a fixed-point class I have templated on magnitude and fractional bit count. I ended up getting lost and wrote a small program to generate a table and copy & pasted the output into a source file for the fixed-point precision I was using at present.
It seems that it would be nice to be able to generate a new table for say 8.24 fixed-point without needed to rerun an external tool.
#include <iostream> #include
#include #include using namespace boost; using namespace mpl; using namespace math;
int main() { sine
>::type your_answer; // The runtime_cast function template // converts the internal representation // to the template argument type // for readability. std::cout << runtime_cast<double>(your_answer) << std::endl;
return 0; }
Does this seem like the sort of thing MPL.Math could help with?
You can look at the sine.cpp example program and see for yourself. As for the sine metafunction implementation, the Taylor series is actually built using a combination of Boost.Preprocessor macros and intermediary typedefs instead of template recursion.
Thanks,
No problem.
Michael Marcin
Cromwell D. Enage
____________________________________________________________________________________ Never miss an email again! Yahoo! Toolbar alerts you the instant new Mail arrives. http://tools.search.yahoo.com/toolbar/features/mail/ _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
--- Chris Weed wrote:
I don't think this is what he means by 8.24 fixed-point. I think he is looking for representing a number by 8 bits to the left of the decimal, and 24 bits after the decimal, thus creating a special 32-bit number format.
Ah, okay, thanks for the clarification.
I suspect you could use this library to do what you want, but I think you would need a way to convert the MPL::Math floating-point representation to your representation. It has been a while since I looked at the code, but I recall that MPL::Math is essentially an implementation of IEEE floating-point representation in a templated class.
The boost::mpl::math::double_ metatype implements the 64-bit double-precision format specified by IEEE 754. If there is enough interest, a future version of MPL.Math will include a boost::mpl::math::float_ metatype that implements the 32-bit single-precision format. Cromwell D. Enage ____________________________________________________________________________________ Bored stiff? Loosen up... Download and play hundreds of games for free on Yahoo! Games. http://games.yahoo.com/games/front
Chris Weed wrote:
Hi, I wanted to try to write a DFT that can take a compile-time data structure such as the following:
[snip] There doesn't seem to be a runtime component there. What am I missing? Do you intend to mix runtime values (e.g. int, doubles) with mpl math stuff? Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
The first thing I want to try is as follows:
I would like to be able to use this algorithm on compile-time values,
such as a known filter, and re-use it on the input signal I want to
process at run-time.
The usual use case is that you have a pre-computed filter (the DFT of
your filter), and perform an FFT on an input signal at run-time.
Instead of calculating the DFT off-line, I would like to just
calculate this with a compile-time operation. For now, I could just
use the DFT operation for the run-time calculation, but maybe later
rewrite it as an FFT.
After this I would like to try this on signals that mix run-time and
compile-time values, such as a signal padded with zeros. This could
potentially eliminate the usual DFT/FFT instructions on the zeroed
part, using the compiler to optimize these away.
Chris
On 1/22/07, Joel de Guzman
Chris Weed wrote:
Hi, I wanted to try to write a DFT that can take a compile-time data structure such as the following:
[snip]
There doesn't seem to be a runtime component there. What am I missing? Do you intend to mix runtime values (e.g. int, doubles) with mpl math stuff?
Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (4)
-
Chris Weed
-
Cromwell Enage
-
Joel de Guzman
-
Michael Marcin