DGtal 1.4.0
Loading...
Searching...
No Matches
testLinearizer.cpp File Reference
#include <cstddef>
#include <cmath>
#include "DGtalCatch.h"
#include <DGtal/kernel/SpaceND.h>
#include <DGtal/kernel/domains/HyperRectDomain.h>
#include <DGtal/kernel/domains/Linearizer.h>
Include dependency graph for testLinearizer.cpp:

Go to the source code of this file.

Macros

#define TEST_LINEARIZER(N, ORDER)
 
#define BENCH_LINEARIZER(N, ORDER)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser 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 General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Roland Denis (rolan.nosp@m.d.de.nosp@m.nis@u.nosp@m.niv-.nosp@m.smb.f.nosp@m.r )
Date
2015/09/10

This file is part of the DGtal library

Definition in file testLinearizer.cpp.

Macro Definition Documentation

◆ BENCH_LINEARIZER

#define BENCH_LINEARIZER ( N,
ORDER )

Definition at line 245 of file testLinearizer.cpp.

245#define BENCH_LINEARIZER( N , ORDER ) \
246TEST_CASE( "Benchmarking Linearizer in dimension " #N " with " #ORDER, "[.bench][dim" #N "][" #ORDER "]" )\
247{\
248\
249 typedef SpaceND<N> Space;\
250 typedef HyperRectDomain<Space> Domain;\
251 typedef Space::Point Point;\
252\
253 typedef linearizer<Domain, N> RefLinearizer;\
254 typedef Linearizer<Domain, ORDER> NewLinearizer;\
255\
256 typedef PointConverter<ORDER> RefConverter;\
257\
258 std::size_t size = 1e8;\
259\
260 Point lowerBound;\
261 for ( std::size_t i = 0 ; i < N ; ++i )\
262 lowerBound[i] = 1 + 7*i;\
263\
264 std::size_t dim_size = std::size_t( std::pow( double(size), 1./N ) + 0.5 );\
265 Point upperBound;\
266 for ( std::size_t i = 0; i < N ; ++i )\
267 upperBound[i] = lowerBound[i] + dim_size + i;\
268\
269 Domain domain( lowerBound, upperBound );\
270 Point extent = upperBound - lowerBound + Point::diagonal(1);\
271\
272 Point refLowerBound = RefConverter::apply(lowerBound);\
273 Point refExtent = RefConverter::apply(extent);\
274\
275 std::size_t sum = 0;\
276\
277 for ( Domain::ConstIterator it = domain.begin(), it_end = domain.end(); it != it_end ; ++it )\
278 sum += RefLinearizer::apply( RefConverter::apply(*it), refLowerBound, refExtent );\
279 REQUIRE( sum > 0 );\
280 sum = 0;\
281\
282 SECTION( "Benchmarking reference linearizer" )\
283 {\
284 for ( Domain::ConstIterator it = domain.begin(), it_end = domain.end(); it != it_end ; ++it )\
285 sum += RefLinearizer::apply( RefConverter::apply(*it), refLowerBound, refExtent );\
286 }\
287\
288 SECTION( "Benchmarking getIndex(Point, Point, Extent) syntax" )\
289 {\
290 for ( Domain::ConstIterator it = domain.begin(), it_end = domain.end(); it != it_end ; ++it )\
291 sum += NewLinearizer::getIndex( *it, lowerBound, extent );\
292 }\
293\
294 SECTION( "Benchmarking getIndex(Point, Extent) syntax" )\
295 {\
296 for ( Domain::ConstIterator it = domain.begin(), it_end = domain.end(); it != it_end ; ++it )\
297 sum += NewLinearizer::getIndex( *it, extent );\
298 }\
299\
300 SECTION( "Benchmarking getIndex(Point, Domain) syntax" )\
301 {\
302 for ( Domain::ConstIterator it = domain.begin(), it_end = domain.end(); it != it_end ; ++it )\
303 sum += NewLinearizer::getIndex( *it, domain );\
304 }\
305\
306 SECTION( "Benchmarking getPoint(Index, Point, Extent) syntax" )\
307 {\
308 for ( std::size_t i = 0; i < domain.size(); ++i )\
309 sum += NewLinearizer::getPoint( i, lowerBound, extent )[N-1];\
310 }\
311\
312 SECTION( "Benchmarking getPoint(Index, Extent) syntax" )\
313 {\
314 for ( std::size_t i = 0; i < domain.size(); ++i )\
315 sum += NewLinearizer::getPoint( i, extent )[N-1];\
316 }\
317\
318 SECTION( "Benchmarking getPoint(Index, Domain) syntax" )\
319 {\
320 for ( std::size_t i = 0; i < domain.size(); ++i )\
321 sum += NewLinearizer::getPoint( i, domain )[N-1];\
322 }\
323\
324 REQUIRE( sum > 0 );\
325}

◆ TEST_LINEARIZER

#define TEST_LINEARIZER ( N,
ORDER )

Definition at line 178 of file testLinearizer.cpp.

178#define TEST_LINEARIZER( N , ORDER ) \
179TEST_CASE( "Testing Linearizer in dimension " #N " with " #ORDER, "[test][dim" #N "][" #ORDER "]" )\
180{\
181\
182 typedef SpaceND<N> Space;\
183 typedef HyperRectDomain<Space> Domain;\
184 typedef Space::Point Point;\
185\
186 typedef linearizer<Domain, N> RefLinearizer;\
187 typedef Linearizer<Domain, ORDER> NewLinearizer;\
188\
189 typedef PointConverter<ORDER> RefConverter;\
190\
191 std::size_t size = 1e3;\
192\
193 Point lowerBound;\
194 for ( std::size_t i = 0 ; i < N ; ++i )\
195 lowerBound[i] = 1 + 7*i;\
196\
197 std::size_t dim_size = std::size_t( std::pow( double(size), 1./N ) + 0.5 );\
198 Point upperBound;\
199 for ( std::size_t i = 0; i < N ; ++i )\
200 upperBound[i] = lowerBound[i] + dim_size + i;\
201\
202 Domain domain( lowerBound, upperBound );\
203 Point extent = upperBound - lowerBound + Point::diagonal(1);\
204\
205 Point refLowerBound = RefConverter::apply(lowerBound);\
206 Point refExtent = RefConverter::apply(extent);\
207\
208 SECTION( "Testing getIndex(Point, Point, Extent) syntax" )\
209 {\
210 for ( Domain::ConstIterator it = domain.begin(), it_end = domain.end(); it != it_end ; ++it )\
211 REQUIRE( RefLinearizer::apply( RefConverter::apply(*it), refLowerBound, refExtent ) == NewLinearizer::getIndex( *it, lowerBound, extent ) );\
212 }\
213\
214 SECTION( "Testing getIndex(Point, Extent) syntax" )\
215 {\
216 for ( Domain::ConstIterator it = domain.begin(), it_end = domain.end(); it != it_end ; ++it )\
217 REQUIRE( RefLinearizer::apply( RefConverter::apply(*it), refLowerBound, refExtent ) == NewLinearizer::getIndex( *it - lowerBound, extent ) );\
218 }\
219\
220 SECTION( "Testing getIndex(Point, Domain) syntax" )\
221 {\
222 for ( Domain::ConstIterator it = domain.begin(), it_end = domain.end(); it != it_end ; ++it )\
223 REQUIRE( RefLinearizer::apply( RefConverter::apply(*it), refLowerBound, refExtent ) == NewLinearizer::getIndex( *it, domain ) );\
224 }\
225\
226 SECTION( "Testing getPoint(Index, Point, Extent) syntax" )\
227 {\
228 for ( std::size_t i = 0; i < domain.size(); ++i )\
229 REQUIRE( RefLinearizer::apply( RefConverter::apply( NewLinearizer::getPoint( i, lowerBound, extent ) ), refLowerBound, refExtent ) == i );\
230 }\
231\
232 SECTION( "Testing getPoint(Index, Extent) syntax" )\
233 {\
234 for ( std::size_t i = 0; i < domain.size(); ++i )\
235 REQUIRE( RefLinearizer::apply( RefConverter::apply( NewLinearizer::getPoint( i, extent ) + lowerBound ), refLowerBound, refExtent ) == i );\
236 }\
237\
238 SECTION( "Testing getPoint(Index, Domain) syntax" )\
239 {\
240 for ( std::size_t i = 0; i < domain.size(); ++i )\
241 REQUIRE( RefLinearizer::apply( RefConverter::apply( NewLinearizer::getPoint( i, domain ) ), refLowerBound, refExtent ) == i );\
242 }\
243}