forked from jtlap/nt2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nearest.hpp
92 lines (77 loc) · 2.7 KB
/
nearest.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//==============================================================================
// Copyright 2003 - 2012 LASMEA UMR 6602 CNRS/Univ. Clermont II
// Copyright 2009 - 2012 LRI UMR 8623 CNRS/Univ Paris Sud XI
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//==============================================================================
#ifndef NT2_INTERPOL_FUNCTIONS_NEAREST_HPP_INCLUDED
#define NT2_INTERPOL_FUNCTIONS_NEAREST_HPP_INCLUDED
#include <nt2/include/functor.hpp>
#include <nt2/sdk/meta/size_as.hpp>
#include <nt2/sdk/meta/value_as.hpp>
#include <nt2/core/container/dsl/size.hpp>
#include <nt2/core/container/dsl/value_type.hpp>
namespace nt2 { namespace tag
{
/*!
@brief nearest generic tag
Represents the nearest function in generic contexts.
@par Models:
Hierarchy
**/
struct nearest_ : ext::unspecified_<nearest_>
{
/// @brief Parent hierarchy
typedef ext::unspecified_<nearest_> parent;
template<class... Args>
static BOOST_FORCEINLINE BOOST_AUTO_DECLTYPE dispatch(Args&&... args)
BOOST_AUTO_DECLTYPE_BODY( dispatching_nearest_( ext::adl_helper(), static_cast<Args&&>(args)... ) )
};
}
namespace ext
{
template<class Site, class... Ts>
BOOST_FORCEINLINE generic_dispatcher<tag::nearest_, Site> dispatching_nearest_(adl_helper, boost::dispatch::meta::unknown_<Site>, boost::dispatch::meta::unknown_<Ts>...)
{
return generic_dispatcher<tag::nearest_, Site>();
}
template<class... Args>
struct impl_nearest_;
}
/*!
one dimensional nearest interpolation
\par
@par Semantic:
For every parameters expressions
@code
auto r = nearest(x, y, xi{, extrap});
@endcode
search the xi locations i in x using bsearch and returns y(j)
choosing the one that realize the smallest distance of xi to x(j)
if x is in the interval [x(begin_), x(end_)]
and depending on extrap value:
- nan if extrap is missing or false
- extrapolation if extrap is true (so x(begin_) or x(end_) accordingly)
- value of extrap if the type of extrap is a scalar of
the x element type
@param a0
@param a1
@param a2
@param a3
@return a value of the same type as the parameter
**/
NT2_FUNCTION_IMPLEMENTATION(tag::nearest_, nearest, 4)
/// @overload
NT2_FUNCTION_IMPLEMENTATION(tag::nearest_, nearest, 3)
}
namespace nt2 { namespace ext
{
/// INTERNAL ONLY
template<class Domain, class Expr, int N>
struct size_of<tag::nearest_, Domain, N, Expr>
: meta::size_as<Expr,2>
{};
} }
#endif