ReFRACtor
closest_point.h
Go to the documentation of this file.
1 #ifndef CLOSEST_POINT
2 #define CLOSEST_POINT
3 
4 #include <blitz/array.h>
5 
6 namespace FullPhysics {
7 
8 
9 // Does not assume sorted array.
10 // Returns the index of the element in
11 // target that is closest to data.
12 template <class T1, class T2>
14  const blitz::Array<T1, 1>& target,
15  T2 data)
16 {
17  return minIndex(abs(target-data))(0);
18 }
19 
20 
21 // Does not assume sorted array.
22 // Returns the indexes of the element in
23 // target that are closest to the elements
24 // in data.
25 template <class T1, class T2>
26 blitz::Array<int, 1> closest_point(
27  const blitz::Array<T1, 1>& target,
28  const blitz::Array<T2, 1>& data)
29 {
30  blitz::Array<int, 1> a(data.shape());
31  for(int i=a.base(blitz::firstDim); i<a.base(blitz::firstDim)+a.rows(); i++)
32  a(i) = closest_point(target, data(i));
33 
34  return a;
35 }
36 
37 
38 }
39 
40 #endif
int closest_point(const blitz::Array< T1, 1 > &target, T2 data)
Definition: closest_point.h:13
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:11