From d4513a260041290ebec1691e8e521aa19e175de5 Mon Sep 17 00:00:00 2001 From: Chichi Lalescu <clalesc1@jhu.edu> Date: Mon, 2 Mar 2015 10:15:34 -0500 Subject: [PATCH] switch endianness manually for p3DFFT_to_iR thank you Stephen for the btle() function. --- src/field_descriptor.cpp | 25 +++++++++++++++++++++++++ src/field_descriptor.hpp | 5 +++++ src/p3DFFT_to_iR.cpp | 2 ++ test3.ipynb | 28 ++++++++++------------------ 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/field_descriptor.cpp b/src/field_descriptor.cpp index 59550a6d..d6cd7c51 100644 --- a/src/field_descriptor.cpp +++ b/src/field_descriptor.cpp @@ -438,6 +438,31 @@ int field_descriptor::interleave( return EXIT_SUCCESS; } +int field_descriptor::switch_endianness( + float *a) +{ + for (int i = 0; i < this->local_size; i++) + { + *a = btle(*a); + a++; + } + return EXIT_SUCCESS; +} + +int field_descriptor::switch_endianness( + fftwf_complex *b) +{ + float *a = (float*)b; + for (int i = 0; i < this->local_size; i++) + { + *a = btle(*a); + a++; + *a = btle(*a); + a++; + } + return EXIT_SUCCESS; +} + field_descriptor* field_descriptor::get_transpose() { int n[this->ndims]; diff --git a/src/field_descriptor.hpp b/src/field_descriptor.hpp index 29b8c292..a2510841 100644 --- a/src/field_descriptor.hpp +++ b/src/field_descriptor.hpp @@ -84,6 +84,11 @@ class field_descriptor int interleave( fftwf_complex *input, int dim); + + int switch_endianness( + float *a); + int switch_endianness( + fftwf_complex *a); }; diff --git a/src/p3DFFT_to_iR.cpp b/src/p3DFFT_to_iR.cpp index fe15f007..fd2960f7 100644 --- a/src/p3DFFT_to_iR.cpp +++ b/src/p3DFFT_to_iR.cpp @@ -130,6 +130,8 @@ int p3DFFT_to_iR::read( this->f0c->read( ifile[i], (void*)(this->c3 + i*this->f3c->local_size)); + this->f0c->switch_endianness( + (this->c3 + i*this->f3c->local_size)); DEBUG_MSG("p3DFFT_to_iR::read " "this->f0c->transpose(...);\n"); this->f0c->transpose( diff --git a/test3.ipynb b/test3.ipynb index 1cacdb0e..a4beedc2 100644 --- a/test3.ipynb +++ b/test3.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:966c6344a3d90cdf5a7423c96eebbfd82f41bd0e6556fcce769383cb4e93116c" + "signature": "sha256:48849ce7df2009ce7253f1b242366c1e998f76ecec705fb62d3af98ecbe8bbc0" }, "nbformat": 3, "nbformat_minor": 0, @@ -57,22 +57,14 @@ "Kdata0 = generate_data_3D(n, p = 2).astype(np.complex64)\n", "Kdata1 = generate_data_3D(n, p = 2).astype(np.complex64)\n", "Kdata2 = generate_data_3D(n, p = 2).astype(np.complex64)\n", - "Kdata0.T.copy().astype('<c8').tofile(\"Kdata0\")\n", - "Kdata1.T.copy().astype('<c8').tofile(\"Kdata1\")\n", - "Kdata2.T.copy().astype('<c8').tofile(\"Kdata2\")" + "Kdata0.T.copy().astype('>c8').tofile(\"Kdata0\")\n", + "Kdata1.T.copy().astype('>c8').tofile(\"Kdata1\")\n", + "Kdata2.T.copy().astype('>c8').tofile(\"Kdata2\")" ], "language": "python", "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stderr", - "text": [ - "-c:15: RuntimeWarning: divide by zero encountered in true_divide\n" - ] - } - ], - "prompt_number": 2 + "outputs": [], + "prompt_number": 7 }, { "cell_type": "code", @@ -155,7 +147,7 @@ "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 3 + "prompt_number": 8 }, { "cell_type": "code", @@ -208,7 +200,7 @@ "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 5 + "prompt_number": 15 }, { "cell_type": "code", @@ -249,11 +241,11 @@ "text": [ "0.0\n", "distance is small\n", - "14.4104\n" + "15.2714\n" ] } ], - "prompt_number": 6 + "prompt_number": 16 }, { "cell_type": "code", -- GitLab