include/lshkit/kernel.h

Go to the documentation of this file.
00001 /* 
00002     Copyright (C) 2008 Wei Dong <wdong@princeton.edu>. All Rights Reserved.
00003   
00004     This file is part of LSHKIT.
00005   
00006     LSHKIT is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     LSHKIT is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with LSHKIT.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00025 #ifndef __LSHKIT_KERNEL__
00026 #define __LSHKIT_KERNEL__
00027 
00028 // This file implements some common kernel functions.
00029 
00030 #include <functional>
00031 
00032 namespace lshkit { namespace kernel {
00033 
00035 template <typename T /* real type */>
00036 class dot : public std::binary_function<const T*, const T*, float>
00037 {
00038     unsigned dim_;
00039 public:
00040     dot (unsigned dim) : dim_(dim) {}
00041     float operator () (const T *first1, const T *first2) const
00042     {
00043         float r = 0.0;
00044         for (unsigned i = 0; i < dim_; ++i)
00045         {
00046             r += first1[i] * first2[i];
00047         }
00048         return r;
00049     }
00050 };
00051 
00052 
00053 }}
00054 
00055 #endif
00056 
00057 

Get LSHKIT at SourceForge.net. Fast, secure and Free Open Source software downloads doxygen