次の例が機能するとは思っていませんでしたが、実際には機能します (g++ 4.6.4、--std=c++0x を使用):
#include <boost/multiprecision/float128.hpp>
#include <blitz/array.h>
#include <fftw3.h>
int main(int /*argc*/, char** /*argv*/)
{
//these are the same
std::cout << sizeof(std::complex<boost::multiprecision::float128>) << " " << sizeof(fftwq_complex) << std::endl;
typedef std::vector< std::complex<boost::multiprecision::float128> > boost128cvec;
//typedef std::vector<std::complex<boost::multiprecision::float128> , fftw::allocator< std::complex<boost::multiprecision::float128> > > boost128cvec;
//declare a std::vector consisting of std::complex<boost::multiprecision::float128>
boost128cvec test_vector3(12);
//casting its data storatge to fftwq_complex*
fftwq_complex* test_ptr3 = reinterpret_cast<fftwq_complex*>(test_vector3.data());
//also create a view to the same data as a blitz::Array
blitz::Array<std::complex<boost::multiprecision::float128>, 1> test_array3(test_vector3.data(), blitz::TinyVector<int, 1>(12), blitz::neverDeleteData);
test_vector3[3] = std::complex<boost::multiprecision::float128>(1.23,4.56);
//this line would not work with std::vector
test_array3 = sin(test_array3);
//this line would not work with the built-in type __float128
test_vector3[4] = sin(test_vector3[3]);
//all of those print the same numbers
std::cout << "fftw::vector: " << test_vector3[3].real() << " + i " << test_vector3[3].imag() << std::endl;
std::cout << "fftw_complex: " << (long double)test_ptr3[3][0] << " + i " << (long double)test_ptr3[3][1] << std::endl;
std::cout << "blitz: " << test_array3(3).real() << " + i " << test_array3(3).imag() << std::endl << std::endl;
}
2 つの注意事項:
- 目標は、同じデータに対して
fftw
とblitz::Array
演算の両方をコピーする必要なく使用できるようにすると同時にsin()
、4 倍精度の複素変数のような汎用関数を使用できるようにすることです。 blitz
-part は正常に動作しますが、これは予想どおりです。しかし、(私にとって)驚いたことは、そのfftwq_complex*
部分もうまく機能することでした.- これは、正しい simd アライメントを保証するために使用さ
fftw::allocator
れる単純な置き換えですが、それはこの質問にとって重要ではないため、省略しました (少なくとも、これはこの質問にとって重要ではないと思います)。std::allocator
fftwq_malloc
私の質問は、私が踏んでいる氷はどれくらい薄いですか?