// Copyright (C) 2007 Fokko Beekhof // Email contact: Fokko.Beekhof@cui.unige.ch // The OMPTL library 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 2.1 of the License, or (at your option) any later version. // This library 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 // Lesser General Public License for more details. // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include namespace omptl { // Extentions template T transform_accumulate(Iterator first, Iterator last, T init, UnaryFunction unary_op, BinaryFunction binary_op, const unsigned P = _Pfunc::Pfunc()); template T transform_accumulate(Iterator first, Iterator last, T init, UnaryFunction unary_op, const unsigned P = _Pfunc::Pfunc()); // "Manhattan" distance template typename ::std::iterator_traits::value_type L1(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, const unsigned P = _Pfunc::Pfunc()); // "Euclidean" distance template typename ::std::iterator_traits::value_type L2(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, const unsigned P = _Pfunc::Pfunc()); // "Euclidean" length template typename ::std::iterator_traits::value_type L2(InputIterator first, InputIterator last, const unsigned P = _Pfunc::Pfunc()); } // namespace #ifdef _OPENMP #include "omptl_numeric_extentions_par.h" #else #include "omptl_numeric_extentions_ser.h" #endif namespace omptl { // "Manhattan" distance template typename ::std::iterator_traits::value_type L1(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, const unsigned P) { typedef typename ::std::iterator_traits::value_type VT; return ::omptl::inner_product(first1, last1, first2, VT(0), std::plus(), std::minus(), P); } template struct _MinusSq { T operator()(const T &lhs, const T &rhs) const { const T d = lhs - rhs; return d*d; } }; // "Euclidean" distance template typename ::std::iterator_traits::value_type L2(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, const unsigned P) { typedef typename ::std::iterator_traits::value_type VT; return ::std::sqrt(::omptl::inner_product(first1, last1, first2, VT(0), std::plus(), _MinusSq(), P)); } template struct _Sq { T operator()(const T &d) const { return d*d; } }; // "Euclidean" length template typename ::std::iterator_traits::value_type L2(InputIterator first, InputIterator last, const unsigned P) { typedef typename ::std::iterator_traits::value_type VT; return ::std::sqrt(::omptl::transform_accumulate(first, last, VT(0), _Sq(), std::plus(), P)); } } /* namespace _OMPTL_EXTENTION_NAMESPACE */