2014-03-28 17:52:51 +00:00
|
|
|
/*!
|
|
|
|
* \file conjugate_test.cc
|
|
|
|
* \brief This file implements tests for conjugation of long arrays.
|
|
|
|
* \author Carles Fernandez-Prades, 2012. cfernandez(at)cttc.es
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2019-07-26 10:38:20 +00:00
|
|
|
* Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)
|
2014-03-28 17:52:51 +00:00
|
|
|
*
|
|
|
|
* GNSS-SDR is a software defined Global Navigation
|
|
|
|
* Satellite Systems receiver
|
|
|
|
*
|
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
|
|
|
* GNSS-SDR is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2015-01-08 18:49:59 +00:00
|
|
|
* (at your option) any later version.
|
2014-03-28 17:52:51 +00:00
|
|
|
*
|
|
|
|
* GNSS-SDR 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-05-13 20:49:11 +00:00
|
|
|
* along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
|
2014-03-28 17:52:51 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <armadillo>
|
|
|
|
#include <volk/volk.h>
|
2016-08-18 12:17:02 +00:00
|
|
|
#include <volk_gnsssdr/volk_gnsssdr.h>
|
2018-12-09 21:00:09 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <chrono>
|
|
|
|
#include <complex>
|
2014-03-28 17:52:51 +00:00
|
|
|
|
|
|
|
DEFINE_int32(size_conjugate_test, 100000, "Size of the arrays used for conjugate testing");
|
|
|
|
|
|
|
|
|
2017-06-25 20:53:11 +00:00
|
|
|
TEST(ConjugateTest, StandardCComplexImplementation)
|
2014-03-28 17:52:51 +00:00
|
|
|
{
|
2019-02-11 14:33:24 +00:00
|
|
|
auto* input = new std::complex<float>[FLAGS_size_conjugate_test];
|
|
|
|
auto* output = new std::complex<float>[FLAGS_size_conjugate_test];
|
2018-02-25 12:27:27 +00:00
|
|
|
std::fill_n(input, FLAGS_size_conjugate_test, std::complex<float>(0.0, 0.0));
|
2014-03-28 17:52:51 +00:00
|
|
|
|
2017-08-11 03:18:38 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> start, end;
|
|
|
|
start = std::chrono::system_clock::now();
|
2014-03-28 17:52:51 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (int i = 0; i < FLAGS_size_conjugate_test; i++)
|
2014-03-28 17:52:51 +00:00
|
|
|
{
|
|
|
|
output[i] = std::conj(input[i]);
|
|
|
|
}
|
|
|
|
|
2017-08-11 03:18:38 +00:00
|
|
|
end = std::chrono::system_clock::now();
|
|
|
|
std::chrono::duration<double> elapsed_seconds = end - start;
|
2014-03-28 17:52:51 +00:00
|
|
|
std::cout << "Conjugate of a " << FLAGS_size_conjugate_test
|
2017-08-11 03:18:38 +00:00
|
|
|
<< "-length complex float vector in standard C finished in " << elapsed_seconds.count() * 1e6
|
2014-03-28 17:52:51 +00:00
|
|
|
<< " microseconds" << std::endl;
|
2015-05-13 14:40:46 +00:00
|
|
|
|
|
|
|
delete[] input;
|
|
|
|
delete[] output;
|
2017-08-11 03:18:38 +00:00
|
|
|
ASSERT_LE(0, elapsed_seconds.count() * 1e6);
|
2014-03-28 17:52:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-25 20:53:11 +00:00
|
|
|
TEST(ConjugateTest, C11ComplexImplementation)
|
2014-03-29 19:11:32 +00:00
|
|
|
{
|
|
|
|
const std::vector<std::complex<float>> input(FLAGS_size_conjugate_test);
|
|
|
|
std::vector<std::complex<float>> output(FLAGS_size_conjugate_test);
|
2017-08-11 03:18:38 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> start, end;
|
|
|
|
start = std::chrono::system_clock::now();
|
2014-03-29 19:11:32 +00:00
|
|
|
int pos = 0;
|
2018-03-03 01:03:39 +00:00
|
|
|
for (const auto& item : input)
|
2014-03-29 19:11:32 +00:00
|
|
|
{
|
|
|
|
output[pos++] = std::conj(item);
|
|
|
|
}
|
2017-08-11 03:18:38 +00:00
|
|
|
end = std::chrono::system_clock::now();
|
|
|
|
std::chrono::duration<double> elapsed_seconds = end - start;
|
2014-03-29 19:11:32 +00:00
|
|
|
std::cout << "Conjugate of a " << FLAGS_size_conjugate_test
|
2017-08-11 03:18:38 +00:00
|
|
|
<< " complex<float> vector (C++11-style) finished in " << elapsed_seconds.count() * 1e6
|
2014-03-29 19:11:32 +00:00
|
|
|
<< " microseconds" << std::endl;
|
2017-08-11 03:18:38 +00:00
|
|
|
ASSERT_LE(0, elapsed_seconds.count() * 1e6);
|
2014-03-29 19:11:32 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
std::complex<float> expected(0, 0);
|
|
|
|
std::complex<float> result(0, 0);
|
|
|
|
for (const auto& item : output)
|
2014-03-29 19:11:32 +00:00
|
|
|
{
|
|
|
|
result += item;
|
|
|
|
}
|
|
|
|
ASSERT_EQ(expected, result);
|
|
|
|
}
|
|
|
|
|
2014-03-28 17:52:51 +00:00
|
|
|
|
2017-06-25 20:53:11 +00:00
|
|
|
TEST(ConjugateTest, ArmadilloComplexImplementation)
|
2014-03-28 17:52:51 +00:00
|
|
|
{
|
|
|
|
arma::cx_fvec input(FLAGS_size_conjugate_test, arma::fill::zeros);
|
|
|
|
arma::cx_fvec output(FLAGS_size_conjugate_test);
|
|
|
|
|
2017-08-11 03:18:38 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> start, end;
|
|
|
|
start = std::chrono::system_clock::now();
|
2014-03-28 17:52:51 +00:00
|
|
|
|
|
|
|
output = arma::conj(input);
|
|
|
|
|
2017-08-11 03:18:38 +00:00
|
|
|
end = std::chrono::system_clock::now();
|
|
|
|
std::chrono::duration<double> elapsed_seconds = end - start;
|
2014-03-28 17:52:51 +00:00
|
|
|
std::cout << "Conjugate of a " << FLAGS_size_conjugate_test
|
2017-08-11 03:18:38 +00:00
|
|
|
<< "-length complex float Armadillo vector finished in " << elapsed_seconds.count() * 1e6
|
2014-03-28 17:52:51 +00:00
|
|
|
<< " microseconds" << std::endl;
|
2017-08-11 03:18:38 +00:00
|
|
|
ASSERT_LE(0, elapsed_seconds.count() * 1e6);
|
2014-03-28 17:52:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-25 20:53:11 +00:00
|
|
|
TEST(ConjugateTest, VolkComplexImplementation)
|
2014-03-28 17:52:51 +00:00
|
|
|
{
|
2019-02-11 14:33:24 +00:00
|
|
|
auto* input = static_cast<std::complex<float>*>(volk_gnsssdr_malloc(FLAGS_size_conjugate_test * sizeof(std::complex<float>), volk_gnsssdr_get_alignment()));
|
|
|
|
auto* output = static_cast<std::complex<float>*>(volk_gnsssdr_malloc(FLAGS_size_conjugate_test * sizeof(std::complex<float>), volk_gnsssdr_get_alignment()));
|
2018-02-25 12:27:27 +00:00
|
|
|
std::fill_n(input, FLAGS_size_conjugate_test, std::complex<float>(0.0, 0.0));
|
2014-03-28 17:52:51 +00:00
|
|
|
|
2017-08-11 03:18:38 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> start, end;
|
|
|
|
start = std::chrono::system_clock::now();
|
2014-03-28 17:52:51 +00:00
|
|
|
|
|
|
|
volk_32fc_conjugate_32fc(output, input, FLAGS_size_conjugate_test);
|
|
|
|
|
2017-08-11 03:18:38 +00:00
|
|
|
end = std::chrono::system_clock::now();
|
|
|
|
std::chrono::duration<double> elapsed_seconds = end - start;
|
2018-03-03 01:03:39 +00:00
|
|
|
std::cout << "Conjugate of a " << FLAGS_size_conjugate_test
|
2017-08-11 03:18:38 +00:00
|
|
|
<< "-length complex float vector using VOLK finished in " << elapsed_seconds.count() * 1e6
|
2014-03-28 17:52:51 +00:00
|
|
|
<< " microseconds" << std::endl;
|
2017-08-11 03:18:38 +00:00
|
|
|
ASSERT_LE(0, elapsed_seconds.count() * 1e6);
|
2016-08-18 12:17:02 +00:00
|
|
|
volk_gnsssdr_free(input);
|
|
|
|
volk_gnsssdr_free(output);
|
2014-03-28 17:52:51 +00:00
|
|
|
}
|