Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93716323
test_fftw_comparison.cc
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, Nov 30, 22:43
Size
2 KB
Mime Type
text/x-c
Expires
Mon, Dec 2, 22:43 (1 d, 20 h)
Engine
blob
Format
Raw Data
Handle
22601108
Attached To
rMSPPROTO µSpectre prototype implementation
test_fftw_comparison.cc
View Options
/**
* file test_fftw_c2c.cc
*
* @author Till Junge <till.junge@epfl.ch>
*
* @date 11 May 2017
*
* @brief test fftw redundant class
*
* @section LICENCE
*
* Copyright (C) 2017 Till Junge
*
* µSpectre 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, or (at
* your option) any later version.
*
* µSpectre 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
* along with GNU Emacs; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <complex>
#include <unsupported/Eigen/CXX11/Tensor>
#include <Eigen/Dense>
#include "system/fftw_engine_c2c.hh"
#include "system/fftw_engine_r2c.hh"
#include "tests.hh"
#include "materials/materials_toolbox.hh"
namespace
muSpectre
{
template
<
Dim_t
DimS
,
Dim_t
DimM
>
struct
fftw_comp_fixture
{
fftw_comp_fixture
()
:
fftwc
(
std_nb_pix
,
FFT_PlanFlags
::
estimate
),
fftwr
(
std_nb_pix
,
FFT_PlanFlags
::
estimate
){}
const
static
typename
FFTW_EngineC2C
<
DimS
,
DimM
>::
Ccoord
std_nb_pix
;
FFTW_EngineC2C
<
DimS
,
DimM
>
fftwc
;
FFTW_EngineR2C
<
DimS
,
DimM
>
fftwr
;
};
template
<>
const
Ccoord_t
<
1
>
fftw_comp_fixture
<
1
,
1
>::
std_nb_pix
{
3
};
template
<>
const
Ccoord_t
<
2
>
fftw_comp_fixture
<
2
,
2
>::
std_nb_pix
{
5
,
3
};
template
<>
const
Ccoord_t
<
2
>
fftw_comp_fixture
<
2
,
1
>::
std_nb_pix
{
5
,
3
};
template
<>
const
Ccoord_t
<
3
>
fftw_comp_fixture
<
3
,
3
>::
std_nb_pix
{
7
,
5
,
3
};
using
fix2
=
fftw_comp_fixture
<
2
,
2
>
;
BOOST_FIXTURE_TEST_CASE
(
fftw_comparison
,
fix2
)
{
const
size_t
dim_m
=
2
;
const
size_t
tot_nb_pixels
=
fftwc
.
get_tot_nb_pixels
();
Real
in_arr
[
tot_nb_pixels
*
dim_m
*
dim_m
];
for
(
size_t
i
=
0
;
i
<
tot_nb_pixels
;
++
i
)
{
for
(
size_t
d
=
0
;
d
<
dim_m
*
dim_m
;
++
d
)
{
in_arr
[
i
*
dim_m
*
dim_m
+
d
]
=
i
;
}
}
Eigen
::
Tensor
<
Real
,
5
>
G
(
dim_m
,
dim_m
,
dim_m
,
dim_m
,
tot_nb_pixels
);
G
.
setZero
();
for
(
size_t
i
=
1
;
i
<
tot_nb_pixels
;
++
i
)
{
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
Real
,
4
>>
Gmap
(
G
.
data
()
+
dim_m
*
dim_m
*
dim_m
*
dim_m
*
i
,
dim_m
,
dim_m
,
dim_m
,
dim_m
);
Gmap
=
Tensors
::
I4
<
dim_m
>
();
}
Eigen
::
Tensor
<
Real
,
3
>
resc
(
dim_m
,
dim_m
,
tot_nb_pixels
);
Eigen
::
Tensor
<
Real
,
3
>
resr
(
dim_m
,
dim_m
,
tot_nb_pixels
);
fftwc
.
convolve
(
G
.
data
(),
in_arr
,
resc
.
data
());
fftwr
.
convolve
(
G
.
data
(),
in_arr
,
resr
.
data
());
Eigen
::
Map
<
Eigen
::
VectorXd
>
cmap
(
resc
.
data
(),
resc
.
size
());
Eigen
::
Map
<
Eigen
::
VectorXd
>
rmap
(
resr
.
data
(),
resr
.
size
());
Real
error
=
(
rmap
-
cmap
).
norm
()
/
rmap
.
norm
();
Real
tol
=
1e-14
;
BOOST_CHECK_LT
(
error
,
tol
);
}
}
// muSpectre
Event Timeline
Log In to Comment