Tapkee
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
covertree_point.hpp
Go to the documentation of this file.
1 /* * This program is free software; you can redistribute it and/or modify
2  * it under the terms of the GNU General Public License as published by
3  * the Free Software Foundation; either version 3 of the License, or
4  * (at your option) any later version.
5  *
6  * Written (W) 2012 Fernando José Iglesias García
7  * Written (W) John Langford and Dinoj Surendran, v_array and its templatization
8  * Copyright (C) 2012 Fernando José Iglesias García
9  */
10 
11 #ifndef _JL_COVERTREE_POINT_H_
12 #define _JL_COVERTREE_POINT_H_
13 
14 /* Tapkee includes */
15 #include <tapkee/defines.hpp>
16 /* End of Tapkee includes */
17 
18 #include <iostream>
19 #include <cmath>
20 
21 namespace tapkee
22 {
23 namespace tapkee_internal
24 {
25 
27 template<class T>
28 class v_array{
29 
30  public:
33  T last() { return elements[index-1];}
34 
36  void decr() { index--;}
37 
39  v_array() : index(0), length(0), elements(NULL) {}
40 
44  T& operator[](IndexType i) { return elements[i]; }
45 
46  public:
48  int index;
49 
51  int length;
52 
55 };
56 
63 template<class T>
64 void push(v_array<T>& v, const T &new_ele)
65 {
66  while(v.index >= v.length)
67  {
68  v.length = 2*v.length + 3;
69  v.elements = (T *)realloc(v.elements,sizeof(T) * v.length);
70  }
71  v[v.index++] = new_ele;
72 }
73 
80 template<class T>
81 void alloc(v_array<T>& v, int length)
82 {
83  v.elements = (T *)realloc(v.elements, sizeof(T) * length);
84  v.length = length;
85 }
86 
96 template<class T>
98 {
99  if (stack.index > 0)
100  return stack[--stack.index];
101  else
102  return v_array<T>();
103 }
104 
110 template <class RandomAccessIterator>
112 {
114  {
115  };
116  CoverTreePoint(const RandomAccessIterator& iter, ScalarType norm) :
117  iter_(iter), norm_(norm)
118  {
119  };
120 
121  RandomAccessIterator iter_;
123 }; /* struct JLCoverTreePoint */
124 
125 template <class Type, class RandomAccessIterator, class Callback>
127 
130 template <class RandomAccessIterator, class Callback>
132  const CoverTreePoint<RandomAccessIterator>& r, ScalarType upper_bound)
133 {
134  //assert(upper_bound>=0);
135 
136  if (l.iter_==r.iter_)
137  return 0.0;
138 
140 }
141 
142 struct KernelType;
143 
144 template <class RandomAccessIterator, class Callback>
145 struct distance_impl<KernelType,RandomAccessIterator,Callback>
146 {
148  const CoverTreePoint<RandomAccessIterator>& r, ScalarType /*upper_bound*/)
149  {
150  return std::sqrt(l.norm_ + r.norm_ - 2*cb(r.iter_,l.iter_));
151  }
152 };
153 
154 struct DistanceType;
155 
156 template <class RandomAccessIterator, class Callback>
157 struct distance_impl<DistanceType,RandomAccessIterator,Callback>
158 {
160  const CoverTreePoint<RandomAccessIterator>& r, ScalarType /*upper_bound*/)
161  {
162  return cb(l.iter_,r.iter_);
163  }
164 };
165 
167 template <class RandomAccessIterator>
169 {
170 }
171 
172 }
173 }
174 #endif /* _JL_COVERTREE_POINT_H_*/
ScalarType distance(Callback &cb, const CoverTreePoint< RandomAccessIterator > &l, const CoverTreePoint< RandomAccessIterator > &r, ScalarType upper_bound)
ScalarType operator()(Callback &cb, const CoverTreePoint< RandomAccessIterator > &l, const CoverTreePoint< RandomAccessIterator > &r, ScalarType)
ScalarType operator()(Callback &cb, const CoverTreePoint< RandomAccessIterator > &l, const CoverTreePoint< RandomAccessIterator > &r, ScalarType)
Class v_array taken directly from JL&#39;s implementation.
double ScalarType
default scalar value (can be overrided with TAPKEE_CUSTOM_INTERNAL_NUMTYPE define) ...
Definition: types.hpp:15
void alloc(v_array< T > &v, int length)
int IndexType
indexing type (non-overridable) set to int for compatibility with OpenMP 2.0
Definition: types.hpp:19
void print(int depth, node< P > &top_node)
Definition: covertree.hpp:140
void push(v_array< T > &v, const T &new_ele)
Class Point to use with John Langford&#39;s CoverTree. This class must have some associated functions def...
v_array< T > pop(v_array< v_array< T > > &stack)
CoverTreePoint(const RandomAccessIterator &iter, ScalarType norm)