Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51063 - in sandbox/miscellanea_algorithm: . boost boost/algorithm libs libs/algorithm libs/algorithm/doc libs/algorithm/src libs/algorithm/src/example
From: erwann.rogard_at_[hidden]
Date: 2009-02-06 15:25:38


Author: e_r
Date: 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
New Revision: 51063
URL: http://svn.boost.org/trac/boost/changeset/51063

Log:
Adding library miscellanea_iterator_algorithm
Added:
   sandbox/miscellanea_algorithm/
   sandbox/miscellanea_algorithm/boost/
   sandbox/miscellanea_algorithm/boost/algorithm/
   sandbox/miscellanea_algorithm/boost/algorithm/accumulate_difference.hpp (contents, props changed)
   sandbox/miscellanea_algorithm/boost/algorithm/find_nearest_neighbor.hpp (contents, props changed)
   sandbox/miscellanea_algorithm/boost/algorithm/functor_abs.hpp (contents, props changed)
   sandbox/miscellanea_algorithm/boost/algorithm/functor_max.hpp (contents, props changed)
   sandbox/miscellanea_algorithm/boost/algorithm/functor_square.hpp (contents, props changed)
   sandbox/miscellanea_algorithm/boost/algorithm/inner_product_skip_one_position.hpp (contents, props changed)
   sandbox/miscellanea_algorithm/boost/algorithm/l2_distance_squared.hpp (contents, props changed)
   sandbox/miscellanea_algorithm/boost/algorithm/l2_norm.hpp (contents, props changed)
   sandbox/miscellanea_algorithm/boost/algorithm/linfinity_distance.hpp (contents, props changed)
   sandbox/miscellanea_algorithm/boost/algorithm/linfinity_norm.hpp (contents, props changed)
   sandbox/miscellanea_algorithm/libs/
   sandbox/miscellanea_algorithm/libs/algorithm/
   sandbox/miscellanea_algorithm/libs/algorithm/doc/
   sandbox/miscellanea_algorithm/libs/algorithm/doc/readme.txt (contents, props changed)
   sandbox/miscellanea_algorithm/libs/algorithm/src/
   sandbox/miscellanea_algorithm/libs/algorithm/src/example/
   sandbox/miscellanea_algorithm/libs/algorithm/src/example/inner_product_skip_one_position.cpp (contents, props changed)
   sandbox/miscellanea_algorithm/libs/algorithm/src/example/inner_product_skip_one_position.h (contents, props changed)
   sandbox/miscellanea_algorithm/libs/algorithm/src/example/main.cpp (contents, props changed)
   sandbox/miscellanea_algorithm/libs/algorithm/src/example/nearest_neighbor.cpp (contents, props changed)
   sandbox/miscellanea_algorithm/libs/algorithm/src/example/nearest_neighbor.h (contents, props changed)
   sandbox/miscellanea_algorithm/libs/algorithm/src/example/norm.cpp (contents, props changed)
   sandbox/miscellanea_algorithm/libs/algorithm/src/example/norm.h (contents, props changed)

Added: sandbox/miscellanea_algorithm/boost/algorithm/accumulate_difference.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/boost/algorithm/accumulate_difference.hpp 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,48 @@
+//////////////////////////////////////////////////////////////////////////////
+// accumulate_difference.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#ifndef BOOST_ALGORITHM_ACCUMULATE_DIFFERENCE_HPP_ER_2009
+#define BOOST_ALGORITHM_ACCUMULATE_DIFFERENCE_HPP_ER_2009
+#include <numeric>
+#include <functional>
+#include <boost/range.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/bind.hpp>
+#include <boost/mpl/apply.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/range/value_type.hpp>
+
+namespace boost{
+/// apply<Binary_outer,T>::type f; f(x,y)
+/// apply<Unary_inner,T>::type f; f(x)
+template<class Binary_outer,class Unary_inner>
+class accumulate_difference{
+ public:
+ accumulate_difference(){}
+
+ template<typename R0, typename R1>
+ typename range_value<R0>::type
+ operator()(const R0& r0, const R1& r1)const{
+ typedef typename range_value<R0>::type result_type;
+ typedef typename range_value<R1>::type result1_type;
+ typedef typename mpl::apply<Binary_outer,result_type>::type
+ outer_type;
+ typedef typename mpl::apply<Unary_inner,result_type>::type
+ unary_type;
+ typedef std::minus<result_type> minus_type;
+
+ return std::inner_product(
+ begin(r0), end(r0), begin(r1), (result_type)(0),
+ outer_type(),
+ bind<result_type>(unary_type(),bind(minus_type(),_1,_2))
+ );
+ }
+
+};
+
+
+}
+#endif

Added: sandbox/miscellanea_algorithm/boost/algorithm/find_nearest_neighbor.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/boost/algorithm/find_nearest_neighbor.hpp 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,92 @@
+//////////////////////////////////////////////////////////////////////////////
+// find_nearest_neighbor.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#ifndef BOOST_ALGORITHM_FIND_NEAREST_NEIGHBOR_HPP_ER_2009
+#define BOOST_ALGORITHM_FIND_NEAREST_NEIGHBOR_HPP_ER_2009
+#include <stdexcept>
+#include <algorithm>
+#include <vector>
+#include <functional>
+#include <iterator>
+#include <boost/assert.hpp>
+#include <boost/range.hpp>
+#include <boost/bind.hpp>
+//#include <boost/numeric/conversion/bounds.hpp>
+//#include <boost/limits.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/algorithm/l2_distance_squared.hpp>
+namespace boost{
+
+ /// Distance::type f; f(x,y)
+ template<typename R,typename Distance = l2_distance_squared>
+ class find_nearest_neighbor{
+ // TODO maybe replace const R by add_const<R>::type
+ typedef typename range_iterator<const R>::type iter_type;
+ typedef typename Distance::type distance_type;
+ public:
+ typedef iter_type result_type;
+ find_nearest_neighbor(const R& points):points_(points){
+ BOOST_ASSERT(size(points_)!=0);
+ }
+ find_nearest_neighbor(const find_nearest_neighbor& that)
+ :points_(that.points_){}
+
+ template<typename R1> result_type
+ operator()(const R1& new_point){
+ return std::min_element(
+ make_transform_iterator(
+ begin(points_),
+ op<R1>(new_point)
+ ),
+ make_transform_iterator(
+ end(points_),
+ op<R1>(new_point)
+ )
+ ).base();
+ }
+ const R& points()const{ return points_; }
+ private:
+ find_nearest_neighbor& operator=(const find_nearest_neighbor& that);
+ const R& points_;
+ template<typename R1>
+ class op{
+ public:
+ typedef typename range_value<R1>::type result_type;
+ op(const R1& new_point):new_point_(new_point){}
+ op(const op& that):new_point_(that.new_point_){}
+ op& operator=(const op& that){
+ if(&that!=this){
+ if(new_point_!=that.new_point_){
+ throw std::runtime_error(
+ "find_nearest_cluster::op::operator=");
+ }
+ //throw std::runtime_error("op");
+ }
+ return *this;
+ }
+ template<typename R2>
+ result_type operator()(const R2& point)const{
+ //return squared_distance(point,new_point_);
+ return distance(point,new_point_);
+ }
+ private:
+ distance_type distance;
+ op();
+ const R1& new_point_;
+ };
+ };
+ template<typename R>
+ find_nearest_neighbor<R> make_find_nearest_neighbor(const R& r){
+ return find_nearest_neighbor<R>(r);
+ }
+ struct find_nearest_neighbor_factory{
+ template<typename R>
+ static find_nearest_neighbor<R> make(const R& r){
+ return make_find_nearest_neighbor(r);
+ }
+ };
+}
+#endif

Added: sandbox/miscellanea_algorithm/boost/algorithm/functor_abs.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/boost/algorithm/functor_abs.hpp 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,19 @@
+//////////////////////////////////////////////////////////////////////////////
+// functor_abs.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#ifndef BOOST_FUNCTOR_ABS_HPP_ER_2009
+#define BOOST_FUNCTOR_ABS_HPP_ER_2009
+//#include <cmath>
+namespace boost{
+ // TODO alternatively, specialize on T and use abs, labs, fabs?
+ template<typename T>
+ struct functor_abs{
+ functor_abs(){}
+ T operator()(T x){ return x<((T)(0))? (-x) : x; }
+ };
+
+}
+#endif

Added: sandbox/miscellanea_algorithm/boost/algorithm/functor_max.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/boost/algorithm/functor_max.hpp 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+// functor_max.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#ifndef BOOST_FUNCTOR_MAX_HPP_ER_2009
+#define BOOST_FUNCTOR_MAX_HPP_ER_2009
+namespace boost{
+ // TODO alternatively, specialize on T and use abs, labs, fabs?
+ template<typename T>
+ struct functor_max{
+ functor_max(){}
+ T operator()(T x,T y){ return (x<y)? y : x; }
+ };
+}
+#endif

Added: sandbox/miscellanea_algorithm/boost/algorithm/functor_square.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/boost/algorithm/functor_square.hpp 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+// functor_square.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#ifndef BOOST_FUNCTOR_SQUARE_HPP_ER_2009
+#define BOOST_FUNCTOR_SQUARE_HPP_ER_2009
+namespace boost{
+
+ template<typename T>
+ struct functor_square{
+ functor_square(){}
+ T operator()(T x)const{return x*x; }
+ };
+}
+#endif

Added: sandbox/miscellanea_algorithm/boost/algorithm/inner_product_skip_one_position.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/boost/algorithm/inner_product_skip_one_position.hpp 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,95 @@
+//////////////////////////////////////////////////////////////////////////////
+// inner_product_skip_one_position.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#ifndef BOOST_ALGORITHM_INNER_PRODUCT_SKIP_ONE_POSITION_HPP_ER_2009
+#define BOOST_ALGORITHM_INNER_PRODUCT_SKIP_ONE_POSITION_HPP_ER_2009
+#include <functional>
+#include <numeric>
+#include <stdexcept>
+#include <boost/range/value_type.hpp>
+#include <boost/iterator/skip_one_step_iterator.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/assert.hpp>
+
+namespace boost{
+
+ template<typename R0,typename R1,typename BinaryOp1,typename BinaryOp2>
+ typename range_value<const R0>::type
+ inner_product_skip_one_position(
+ const R0& range0,
+ const R1& range1,
+ std::size_t position,
+ typename range_value<const R0>::type init,
+ const BinaryOp1& binary_op1,
+ const BinaryOp2& binary_op2
+ ){
+ typedef typename range_value<const R0>::type value_type;
+ typedef typename range_value<const R1>::type value1_type;
+
+ BOOST_MPL_ASSERT( (is_same<value_type,value1_type>) );
+ if(size(range0)!=size(range1)){
+ throw std::runtime_error(
+ "inner_product_skip_one_position size(range0)!=size(range1)"
+ );
+ }
+ if(!((std::size_t)(size(range0))>position)){
+ throw std::runtime_error(
+ "inner_product_skip_one_position !(size(range0)>position)");
+ }
+
+ typedef typename range_iterator<const R0>::type iter0_type;
+ typedef typename range_iterator<const R1>::type iter1_type;
+ typedef skip_one_step_iterator<iter0_type> skip_iter0_type;
+ typedef skip_one_step_iterator<iter1_type> skip_iter1_type;
+
+ iter0_type skip0 = begin(range0); std::advance(skip0,position);
+ iter1_type skip1 = begin(range1); std::advance(skip1,position);
+
+ skip_iter0_type b0
+ = make_skip_one_step_begin_iterator(begin(range0),skip0);
+ skip_iter0_type e0
+ = make_skip_one_step_end_iterator(end(range0),skip0);
+ skip_iter1_type b1
+ = make_skip_one_step_begin_iterator(begin(range1),skip1);
+
+ return std::inner_product(
+ b0,
+ e0,
+ b1,
+ init,
+ binary_op1,
+ binary_op2
+ );
+ };
+
+ template<typename R0,typename R1>
+ typename range_value<const R0>::type
+ inner_product_skip_one_position(
+ const R0& range0,
+ const R1& range1,
+ std::size_t position,
+ typename range_value<const R0>::type init
+ ){
+ typedef typename range_value<const R0>::type value_type;
+ typedef std::plus<value_type> plus_type;
+ typedef std::multiplies<value_type> multiplies_type;
+
+ return inner_product_skip_one_position<
+ R0,
+ R1,
+ plus_type,
+ multiplies_type
+ >(
+ range0,
+ range1,
+ position,
+ init,
+ plus_type(),
+ multiplies_type()
+ );
+ };
+}
+#endif

Added: sandbox/miscellanea_algorithm/boost/algorithm/l2_distance_squared.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/boost/algorithm/l2_distance_squared.hpp 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,23 @@
+//////////////////////////////////////////////////////////////////////////////
+// l2_distance_squared.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#ifndef BOOST_ALGORITHM_L2_DISTANCE_SQUARED_HPP_ER_2009
+#define BOOST_ALGORITHM_L2_DISTANCE_SQUARED_HPP_ER_2009
+#include <functional>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/algorithm/functor_square.hpp>
+#include <boost/algorithm/accumulate_difference.hpp>
+namespace boost{
+
+struct l2_distance_squared{
+ typedef std::plus<mpl::_1> plus_type;
+ typedef functor_square<mpl::_1> square_type;
+
+ typedef accumulate_difference<plus_type, square_type> type;
+};
+
+}
+#endif

Added: sandbox/miscellanea_algorithm/boost/algorithm/l2_norm.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/boost/algorithm/l2_norm.hpp 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,40 @@
+//////////////////////////////////////////////////////////////////////////////
+// l2_norm.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#ifndef BOOST_ALGORITHM_L2_NORM_HPP_ER_2009
+#define BOOST_ALGORITHM_L2_NORM_HPP_ER_2009
+#include <numeric>
+#include <cmath>
+#include <boost/range.hpp>
+#include <boost/range/value_type.hpp>
+namespace boost{
+
+class l2_norm{
+ public:
+ l2_norm(){}
+ template<typename R0>
+ typename range_value<R0>::type
+ operator()(const R0& r0){
+ typedef typename range_value<R0>::type result_type;
+ return std::sqrt(std::accumulate(
+ boost::begin(r0),
+ boost::end(r0),
+ (result_type)(0),
+ bin_op<result_type>()
+ ));
+ };
+
+ private:
+
+ template<typename T>
+ struct bin_op{
+ bin_op(){}
+ T operator()(T x,T y)const{ return x + y*y; }
+ };
+};
+
+}
+#endif

Added: sandbox/miscellanea_algorithm/boost/algorithm/linfinity_distance.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/boost/algorithm/linfinity_distance.hpp 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,23 @@
+//////////////////////////////////////////////////////////////////////////////
+// linfinity_distance.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#ifndef BOOST_ALGORITHM_LINFINITY_DISTANCE_HPP_ER_2009
+#define BOOST_ALGORITHM_LINFINITY_DISTANCE_HPP_ER_2009
+#include <functional>
+#include <boost/algorithm/functor_max.hpp>
+#include <boost/algorithm/functor_abs.hpp>
+#include <boost/algorithm/accumulate_difference.hpp>
+namespace boost{
+
+struct linfinity_distance{
+ typedef functor_max<mpl::_1> max_type;
+ typedef functor_abs<mpl::_1> abs_type;
+ typedef accumulate_difference<max_type,abs_type> type;
+};
+
+
+}
+#endif

Added: sandbox/miscellanea_algorithm/boost/algorithm/linfinity_norm.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/boost/algorithm/linfinity_norm.hpp 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,45 @@
+//////////////////////////////////////////////////////////////////////////////
+// linfinity_norm.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#ifndef BOOST_ALGORITHM_LINFINITY_NORM_HPP_ER_2009
+#define BOOST_ALGORITHM_LINFINITY_HPP_ER_2009
+#include <cmath>
+#include <numeric>
+#include <boost/range.hpp>
+namespace boost{
+
+class linfinity_norm{
+ public:
+ linfinity_norm(){}
+
+ template<typename R0>
+ typename
+ iterator_value<typename boost::range_iterator<R0>::type>::type
+ operator()(const R0& r0){
+ typedef typename
+ iterator_value<typename boost::range_iterator<R0>::type>::type
+ result_type;
+ return std::accumulate(
+ boost::begin(r0),
+ boost::end(r0),
+ (result_type)(0),
+ bin_op<result_type>()
+ );
+ };
+
+ private:
+ template<typename T>
+ struct bin_op{
+ bin_op(){}
+ T operator()(T x,T y)const{
+ T a = abs(y);
+ return (x < a)? a : x;
+ }
+ };
+};
+
+}
+#endif

Added: sandbox/miscellanea_algorithm/libs/algorithm/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/libs/algorithm/doc/readme.txt 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,54 @@
+//////////////////////////////////////////////////////////////////////////////
+// miscellanea_algorithm.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+///////////
+/ Contact /
+///////////
+
+Please send questions or suggestions to erwann.rogard_at_[hidden]
+
+/////////////
+/ Overview /
+/////////////
+
+This collection of C++ classes are take one more ranges as input
+and return an iterator (such as the nearest neighbor to the input) or a value
+(such as the norm of the input).
+
+Warning: these were designed for very specific applications and have very few
+safeguards.
+
+//////////////////
+/ Requirements /
+//////////////////
+
+Compiles fine under
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490)
+
+The compiler search path must include
+boost_1_37_0
+boost/sandbox/miscellanea_iterator_facade
+
+////////////////////////
+/ Output from main.cpp /
+////////////////////////
+->example_find_nearest_neighbor
+3 4 5 <-
+->example_squared_l2_norm()
+ l2_norm(vec0) = 1.41421
+ linfinity_norm(vec0) = 1
+ l2_distance_squared (vec0,vec1) = 8
+ linfinity_distance (vec0,vec1) = 2
+<-
+->example_inner_product_skip_one_position
+0
+-2
+0
+exception=inner_product_skip_one_position size(range0)!=size(range1)
+<-
+

Added: sandbox/miscellanea_algorithm/libs/algorithm/src/example/inner_product_skip_one_position.cpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/libs/algorithm/src/example/inner_product_skip_one_position.cpp 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,67 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/inner_product_skip_one_position.cpp
+// (C) Copyright 2009 Erwann Rogard
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)#include <iostream>
+#include <vector>
+#include <iostream>
+#include <boost/assign.hpp>
+#include <boost/algorithm/inner_product_skip_one_position.hpp>
+#include <libs/algorithm/src/example/inner_product_skip_one_position.h>
+
+void example_inner_product_skip_one_position(){
+ std::cout << "->example_inner_product_skip_one_position" << std::endl;
+ using namespace boost;
+
+ typedef double value_type;
+ typedef std::vector<value_type> vec_type;
+ typedef vec_type::size_type size_type;
+ typedef std::plus<value_type> plus_type;
+ typedef std::multiplies<value_type> multiplies_type;
+ vec_type vec0;
+ vec_type vec1;
+ {
+ using namespace boost::assign;
+ vec0+=-1.0; vec0+=1.0; vec0+=1.0;
+ vec1+=1.0; vec1+=1.0; vec1+=-1.0;
+ }
+
+ for(size_type i=0; i<size(vec0); i++){
+ value_type x =
+ inner_product_skip_one_position<
+ vec_type,
+ vec_type,
+ plus_type,
+ multiplies_type
+ >(
+ vec0,
+ vec1,
+ i,
+ 0.0,
+ plus_type(),
+ multiplies_type()
+ );
+ std::cout << x << std::endl;
+ }
+
+ try{
+ vec_type vec2;
+ {
+ using namespace boost::assign;
+ vec2+=-1.0; vec2+=1.0;
+ }
+ inner_product_skip_one_position(
+ vec0,
+ vec2,
+ 0,
+ 0.0
+ );
+ }catch(const std::exception& e){
+
+ std::cout << "exception=" << e.what() << std::endl;
+ }
+
+ std::cout << "<-" << std::endl;
+
+};

Added: sandbox/miscellanea_algorithm/libs/algorithm/src/example/inner_product_skip_one_position.h
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/libs/algorithm/src/example/inner_product_skip_one_position.h 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,10 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/inner_product_skip_one_position.h
+//
+// Copyright 2009 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#ifndef LIBS_ALGORITHM_INNER_PRODUCT_SKIP_ONE_POSITION_H_ER_2009
+#define LIBS_ALGORITHM_INNER_PRODUCT_SKIP_ONE_POSITION_H_ER_2009
+ void example_inner_product_skip_one_position();
+#endif

Added: sandbox/miscellanea_algorithm/libs/algorithm/src/example/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/libs/algorithm/src/example/main.cpp 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,18 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/main.cpp
+// (C) Copyright 2009 Erwann Rogard
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#include <libs/algorithm/src/example/nearest_neighbor.h>
+#include <libs/algorithm/src/example/norm.h>
+#include <libs/algorithm/src/example/nearest_neighbor.h>
+#include <libs/algorithm/src/example/inner_product_skip_one_position.h>
+int main()
+{
+ example_nearest_neighbor();
+ example_norm();
+ example_inner_product_skip_one_position();
+
+ return 0;
+}

Added: sandbox/miscellanea_algorithm/libs/algorithm/src/example/nearest_neighbor.cpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/libs/algorithm/src/example/nearest_neighbor.cpp 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,54 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/nearest_neighbor.cpp
+// (C) Copyright 2009 Erwann Rogard
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#include <vector>
+#include <list>
+#include <algorithm>
+#include <iterator>
+#include <iostream>//TODO remove
+#include <boost/assert.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/algorithm/find_nearest_neighbor.hpp>
+#include <libs/algorithm/src/example/nearest_neighbor.h>
+
+void example_nearest_neighbor()
+{
+ std::cout << "->example_find_nearest_neighbor" << std::endl;
+
+ using namespace boost;
+ typedef std::vector<int> vec_type;
+ typedef std::vector<vec_type> vecs_type;
+ vec_type vec0, vec1, vec2, vec3, vec_a;
+ vecs_type vecs;
+ {
+ using namespace boost::assign;
+ vec0 += 0, 1 ,2 ;
+ vec1 += 3, 4 ,5 ;
+ vec2 += 6, 7 ,8 ;
+ vec3 += 9, 10 ,11;
+ vec_a += 3, 4 ,5 ;
+ vecs_type vecs;
+ }
+ vecs.push_back(vec0);
+ vecs.push_back(vec1);
+ vecs.push_back(vec2);
+ vecs.push_back(vec3);
+
+ BOOST_ASSERT(boost::size(vecs)!=0);
+
+ boost::find_nearest_neighbor<vecs_type>::result_type res =
+ boost::make_find_nearest_neighbor(vecs)(vec_a);
+
+ copy(
+ boost::begin(*res),
+ boost::end(*res),
+ std::ostream_iterator<int>(std::cout," ")
+ );//should return 4,5,6
+
+ std::cout << "<-" << std::endl;
+
+}
+

Added: sandbox/miscellanea_algorithm/libs/algorithm/src/example/nearest_neighbor.h
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/libs/algorithm/src/example/nearest_neighbor.h 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,10 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/nearest_neighbor.h
+//
+// Copyright 2009 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#ifndef LIBS_ALGORITHM_EXAMPLE_NEAREST_NEIGHBOR_H_ER_2009
+#define LIBS_ALGORITHM_EXAMPLE_NEAREST_NEIGHBOR_H_ER_2009
+void example_nearest_neighbor();
+#endif

Added: sandbox/miscellanea_algorithm/libs/algorithm/src/example/norm.cpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/libs/algorithm/src/example/norm.cpp 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,43 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/norm.cpp
+// (C) Copyright 2009 Erwann Rogard
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#include <iostream>
+#include <vector>
+#include <boost/algorithm/l2_norm.hpp>
+#include <boost/algorithm/linfinity_norm.hpp>
+#include <boost/algorithm/l2_distance_squared.hpp>
+#include <boost/algorithm/linfinity_distance.hpp>
+#include <boost/assign.hpp>
+#include <boost/range.hpp>
+#include <libs/algorithm/src/example/norm.h>
+
+void example_norm(){
+ std::cout << "->example_squared_l2_norm()" << std::endl;
+
+ typedef std::vector<double> vector_type;
+ vector_type vec0(2); vec0[0]=-1.0; vec0[1]=1.0;
+ vector_type vec1(2); vec1[0]=1.0; vec1[1]=-1.0;
+
+ std::cout
+ << " l2_norm(vec0) = "
+ << boost::l2_norm()(vec0)
+ << std::endl;
+
+ std::cout
+ << " linfinity_norm(vec0) = "
+ << boost::linfinity_norm()(vec0)
+ << std::endl;
+ std::cout
+ << " l2_distance_squared (vec0,vec1) = "
+ << boost::l2_distance_squared::type()(vec0,vec1)
+ << std::endl;
+ std::cout
+ << " linfinity_distance (vec0,vec1) = "
+ << boost::linfinity_distance::type()(vec0,vec1)
+ << std::endl;
+ std::cout << "<-" << std::endl;
+};
+

Added: sandbox/miscellanea_algorithm/libs/algorithm/src/example/norm.h
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_algorithm/libs/algorithm/src/example/norm.h 2009-02-06 15:25:37 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,11 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/norm.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#ifndef BOOST_ALGORITHM_NORM_H_ER_2009
+#define BOOST_ALGORITHM_NORM_H_ER_2009
+void example_norm();
+
+#endif


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk