PLaSK library
Loading...
Searching...
No Matches
toeplitz_test.cpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#undef _GLIBCXX_DEBUG
15
16#define BOOST_TEST_DYN_LINK
17#define BOOST_TEST_MODULE "Toeplitz test"
18#include <boost/test/unit_test.hpp>
19
20#if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32)
21namespace boost { namespace unit_test { namespace ut_detail {
22std::string normalize_test_case_name(const_string name) {
23 return ( name[0] == '&' ? std::string(name.begin()+1, name.size()-1) : std::string(name.begin(), name.size() ));
24}
25}}}
26#endif
27
28#define CHECK_CLOSE_COLLECTION(aa, bb, tolerance) { \
29 using std::distance; \
30 using std::begin; \
31 using std::end; \
32 auto a = begin(aa), ae = end(aa); \
33 auto b = begin(bb); \
34 BOOST_REQUIRE_EQUAL(distance(a, ae), distance(b, end(bb))); \
35 double total_error = 0.;\
36 for(; a != ae; ++a, ++b) total_error += abs2(*a - *b); \
37 BOOST_CHECK_SMALL(total_error, double(distance(begin(aa), ae)) * tolerance); \
38}
39
40#include "../fourier/toeplitz.hpp"
41using namespace plask;
42using namespace plask::optical::modal;
43
45
47{
48 // Test forward transform
49 DataVector<dcomplex> T = { 6., 3., 2., 1., 1., 2., 4. };
50 cmatrix X(4, 2, { 24., 35., 42., 38., -3., 8., 4., -1. });
51 cmatrix R(4, 2, { 1., 2., 3., 4., -2., 2., 1., -1. });
52
53 ToeplitzLevinson(T, X);
54 CHECK_CLOSE_COLLECTION(X, R, 1e-14)
55}
56