Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F70297203
test_fftfreq.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Jul 6, 04:49
Size
3 KB
Mime Type
text/x-c
Expires
Mon, Jul 8, 04:49 (2 d)
Engine
blob
Format
Raw Data
Handle
18819978
Attached To
rTAMAAS tamaas
test_fftfreq.cpp
View Options
/**
* @file
* @section LICENSE
*
* Copyright (©) 2016-2021 EPFL (École Polytechnique Fédérale de Lausanne),
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "fft_engine.hh"
#include "grid.hh"
#include "grid_hermitian.hh"
#include "grid_view.hh"
#include "mpi_interface.hh"
#include "partitioner.hh"
#include "test.hh"
#include <pybind11/embed.h>
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
using namespace tamaas;
namespace py = pybind11;
/* -------------------------------------------------------------------------- */
TEST(TestFFTEngine, Frequencies1D) {
mpi::sequential_guard guard{};
std::array<UInt, 1> sizes = {{10}};
auto freq = FFTEngine::computeFrequencies<Real, 1, false>(sizes);
py::module fftfreq = py::module::import("fftfreq");
std::vector<Real> reference(freq.dataSize());
py::array py_arg(reference.size(), reference.data(), py::none());
fftfreq.attr("frequencies1D")(py_arg);
EXPECT_TRUE(compare(reference, freq, AreFloatEqual()))
<< "Non hermitian frequencies are wrong";
auto hfreq = FFTEngine::computeFrequencies<Real, 1, true>(sizes);
std::iota(reference.begin(), reference.end(), 0);
EXPECT_TRUE(compare(reference, hfreq, AreFloatEqual()))
<< "Hermitian frequencies are wrong";
}
/* -------------------------------------------------------------------------- */
TEST(TestFFTEngine, Frequencies2D) {
std::array<UInt, 2> sizes = {{10, 10}};
auto global_sizes = Partitioner<2>::global_size(sizes);
auto freq = FFTEngine::computeFrequencies<Real, 2, false>(sizes);
auto hfreq = FFTEngine::computeFrequencies<Real, 2, true>(sizes);
auto gathered = Partitioner<2>::gather(freq);
auto hgathered = Partitioner<2>::gather(hfreq);
if (mpi::rank() != 0)
return;
py::module fftfreq = py::module::import("fftfreq");
std::vector<Real> reference(gathered.dataSize());
py::array py_arg({global_sizes[0], global_sizes[1], 2u}, reference.data(),
py::none());
fftfreq.attr("frequencies2D")(py_arg);
EXPECT_TRUE(compare(reference, gathered, AreFloatEqual()))
<< "Non hermitian frequencies are wrong";
fftfreq.attr("hfrequencies2D")(py_arg);
EXPECT_TRUE(compare(reference, hgathered, AreFloatEqual()))
<< "Hermitian frequencies are wrong";
}
Event Timeline
Log In to Comment