diff --git a/Jamfile b/Jamfile index 35638af3..2d6f5389 100644 --- a/Jamfile +++ b/Jamfile @@ -5,17 +5,19 @@ subinclude libs/numeric/ublas/test3 ; subinclude libs/numeric/ublas/test4 ; subinclude libs/numeric/ublas/test5 ; subinclude libs/numeric/ublas/test6 ; +subinclude libs/numeric/ublas/test7 ; subinclude libs/numeric/ublas/bench1 ; subinclude libs/numeric/ublas/bench2 ; subinclude libs/numeric/ublas/bench3 ; +subinclude libs/numeric/ublas/bench4 ; SOURCES = concepts ; exe concepts - : $(SOURCES).cpp - : $(BOOST_ROOT) - : EXTERNAL - <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" - <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" - ; + : $(SOURCES).cpp + : $(BOOST_ROOT) + : EXTERNAL + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" + ; diff --git a/bench1/bench1.cpp b/bench1/bench1.cpp index 2fcffd73..d83d8d58 100644 --- a/bench1/bench1.cpp +++ b/bench1/bench1.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/bench1/bench1.hpp b/bench1/bench1.hpp index 08d65b63..7a65e526 100644 --- a/bench1/bench1.hpp +++ b/bench1/bench1.hpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifndef BENCH1_H #define BENCH1_H @@ -19,24 +35,24 @@ struct footer { } }; -template +template struct c_vector_traits { typedef T type [N]; }; -template +template struct c_matrix_traits { typedef T type [N] [M]; }; -template +template struct initialize_c_vector { #ifdef BOOST_MSVC BOOST_UBLAS_INLINE void operator () (typename c_vector_traits::type v) { -#else +#else void operator () (typename c_vector_traits::type &v) { -#endif - for (int i = 0; i < N; ++ i) +#endif + for (int i = 0; i < N; ++ i) v [i] = rand () * 1.f; // v [i] = 0.f; } @@ -45,21 +61,21 @@ template BOOST_UBLAS_INLINE void initialize_vector (V &v) { int size = v.size (); - for (int i = 0; i < size; ++ i) + for (int i = 0; i < size; ++ i) v [i] = rand () * 1.f; // v [i] = 0.f; } -template +template struct initialize_c_matrix { #ifdef BOOST_MSVC BOOST_UBLAS_INLINE void operator () (typename c_matrix_traits::type m) { -#else +#else void operator () (typename c_matrix_traits::type &m) { -#endif - for (int i = 0; i < N; ++ i) - for (int j = 0; j < M; ++ j) +#endif + for (int i = 0; i < N; ++ i) + for (int j = 0; j < M; ++ j) m [i] [j] = rand () * 1.f; // m [i] [j] = 0.f; } @@ -69,8 +85,8 @@ BOOST_UBLAS_INLINE void initialize_matrix (M &m) { int size1 = m.size1 (); int size2 = m.size2 (); - for (int i = 0; i < size1; ++ i) - for (int j = 0; j < size2; ++ j) + for (int i = 0; i < size1; ++ i) + for (int j = 0; j < size2; ++ j) m (i, j) = rand () * 1.f; // m (i, j) = 0.f; } @@ -86,9 +102,9 @@ struct sink_c_vector { #ifdef BOOST_MSVC BOOST_UBLAS_INLINE void operator () (const typename c_vector_traits::type v) { -#else +#else void operator () (const typename c_vector_traits::type &v) { -#endif +#endif static typename c_vector_traits::type g_v; for (int i = 0; i < N; ++ i) g_v [i] = v [i]; @@ -105,9 +121,9 @@ struct sink_c_matrix { #ifdef BOOST_MSVC BOOST_UBLAS_INLINE void operator () (const typename c_matrix_traits::type m) { -#else +#else void operator () (const typename c_matrix_traits::type &m) { -#endif +#endif static typename c_matrix_traits::type g_m; for (int i = 0; i < N; ++ i) for (int j = 0; j < M; ++ j) diff --git a/bench1/bench11.cpp b/bench1/bench11.cpp index 59c5b437..b50b462f 100644 --- a/bench1/bench11.cpp +++ b/bench1/bench11.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/bench1/bench12.cpp b/bench1/bench12.cpp index 05297630..361c208e 100644 --- a/bench1/bench12.cpp +++ b/bench1/bench12.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -347,13 +363,13 @@ void bench_2::operator () (int runs) { ublas::vector >, N> () (runs, safe_tag ()); header ("matrix, vector fast"); - bench_my_outer_prod >, + bench_my_outer_prod >, ublas::vector >, N> () (runs, fast_tag ()); #endif #ifdef USE_UNBOUNDED_ARRAY header ("matrix, vector safe"); - bench_my_outer_prod >, + bench_my_outer_prod >, ublas::vector >, N> () (runs, safe_tag ()); header ("matrix, vector fast"); @@ -363,7 +379,7 @@ void bench_2::operator () (int runs) { #ifdef USE_STD_VALARRAY header ("matrix, vector safe"); - bench_my_outer_prod >, + bench_my_outer_prod >, ublas::vector >, N> () (runs, safe_tag ()); header ("matrix, vector fast"); @@ -407,13 +423,13 @@ void bench_2::operator () (int runs) { ublas::vector >, N> () (runs, safe_tag ()); header ("matrix, vector fast"); - bench_my_matrix_vector_prod >, + bench_my_matrix_vector_prod >, ublas::vector >, N> () (runs, fast_tag ()); #endif #ifdef USE_UNBOUNDED_ARRAY header ("matrix, vector safe"); - bench_my_matrix_vector_prod >, + bench_my_matrix_vector_prod >, ublas::vector >, N> () (runs, safe_tag ()); header ("matrix, vector fast"); @@ -423,7 +439,7 @@ void bench_2::operator () (int runs) { #ifdef USE_STD_VALARRAY header ("matrix, vector safe"); - bench_my_matrix_vector_prod >, + bench_my_matrix_vector_prod >, ublas::vector >, N> () (runs, safe_tag ()); header ("matrix, vector fast"); diff --git a/bench1/bench13.cpp b/bench1/bench13.cpp index 8e48a781..5c6ccd5a 100644 --- a/bench1/bench13.cpp +++ b/bench1/bench13.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/bench2/bench2.cpp b/bench2/bench2.cpp index ccb2f6c8..35765d06 100644 --- a/bench2/bench2.cpp +++ b/bench2/bench2.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/bench2/bench2.hpp b/bench2/bench2.hpp index f4bfb702..40c67f59 100644 --- a/bench2/bench2.hpp +++ b/bench2/bench2.hpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifndef BENCH2_H #define BENCH2_H @@ -28,15 +44,15 @@ struct c_matrix_traits { typedef T type [N] [M]; }; -template +template struct initialize_c_vector { #ifdef BOOST_MSVC BOOST_UBLAS_INLINE void operator () (typename c_vector_traits::type v) { -#else +#else void operator () (typename c_vector_traits::type &v) { -#endif - for (int i = 0; i < N; ++ i) +#endif + for (int i = 0; i < N; ++ i) v [i] = rand () * 1.f; // v [i] = 0.f; } @@ -45,21 +61,21 @@ template BOOST_UBLAS_INLINE void initialize_vector (V &v) { int size = v.size (); - for (int i = 0; i < size; ++ i) + for (int i = 0; i < size; ++ i) v [i] = rand () * 1.f; // v [i] = 0.f; } -template +template struct initialize_c_matrix { #ifdef BOOST_MSVC BOOST_UBLAS_INLINE void operator () (typename c_matrix_traits::type m) { -#else +#else void operator () (typename c_matrix_traits::type &m) { -#endif - for (int i = 0; i < N; ++ i) - for (int j = 0; j < M; ++ j) +#endif + for (int i = 0; i < N; ++ i) + for (int j = 0; j < M; ++ j) m [i] [j] = rand () * 1.f; // m [i] [j] = 0.f; } @@ -69,8 +85,8 @@ BOOST_UBLAS_INLINE void initialize_matrix (M &m, ublas::row_major_tag) { int size1 = m.size1 (); int size2 = m.size2 (); - for (int i = 0; i < size1; ++ i) - for (int j = 0; j < size2; ++ j) + for (int i = 0; i < size1; ++ i) + for (int j = 0; j < size2; ++ j) m (i, j) = rand () * 1.f; // m (i, j) = 0.f; } @@ -79,8 +95,8 @@ BOOST_UBLAS_INLINE void initialize_matrix (M &m, ublas::column_major_tag) { int size1 = m.size1 (); int size2 = m.size2 (); - for (int j = 0; j < size2; ++ j) - for (int i = 0; i < size1; ++ i) + for (int j = 0; j < size2; ++ j) + for (int i = 0; i < size1; ++ i) m (i, j) = rand () * 1.f; // m (i, j) = 0.f; } @@ -102,9 +118,9 @@ struct sink_c_vector { #ifdef BOOST_MSVC BOOST_UBLAS_INLINE void operator () (const typename c_vector_traits::type v) { -#else +#else void operator () (const typename c_vector_traits::type &v) { -#endif +#endif static typename c_vector_traits::type g_v; for (int i = 0; i < N; ++ i) g_v [i] = v [i]; @@ -121,9 +137,9 @@ struct sink_c_matrix { #ifdef BOOST_MSVC BOOST_UBLAS_INLINE void operator () (const typename c_matrix_traits::type m) { -#else +#else void operator () (const typename c_matrix_traits::type &m) { -#endif +#endif static typename c_matrix_traits::type g_m; for (int i = 0; i < N; ++ i) for (int j = 0; j < M; ++ j) diff --git a/bench2/bench21.cpp b/bench2/bench21.cpp index 99fe296f..4470c62a 100644 --- a/bench2/bench21.cpp +++ b/bench2/bench21.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/bench2/bench22.cpp b/bench2/bench22.cpp index 6d22d775..7853b5e5 100644 --- a/bench2/bench22.cpp +++ b/bench2/bench22.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/bench2/bench23.cpp b/bench2/bench23.cpp index c1f9d520..96a5d96b 100644 --- a/bench2/bench23.cpp +++ b/bench2/bench23.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/bench3/bench3.cpp b/bench3/bench3.cpp index b5473b20..c17ba2f1 100644 --- a/bench3/bench3.cpp +++ b/bench3/bench3.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/bench3/bench3.hpp b/bench3/bench3.hpp index a0e2eee1..d1da53ec 100644 --- a/bench3/bench3.hpp +++ b/bench3/bench3.hpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifndef BENCH3_H #define BENCH3_H @@ -19,16 +35,16 @@ struct footer { } }; -template +template struct c_vector_traits { typedef T type [N]; }; -template +template struct c_matrix_traits { typedef T type [N] [M]; }; -template +template struct initialize_c_vector { #ifdef BOOST_MSVC BOOST_UBLAS_INLINE @@ -36,7 +52,7 @@ struct initialize_c_vector { #else void operator () (typename c_vector_traits::type &v) { #endif - for (int i = 0; i < N; ++ i) + for (int i = 0; i < N; ++ i) v [i] = rand () * 1.f; // v [i] = 0.f; } @@ -45,21 +61,21 @@ template BOOST_UBLAS_INLINE void initialize_vector (V &v) { int size = v.size (); - for (int i = 0; i < size; ++ i) + for (int i = 0; i < size; ++ i) v [i] = rand () * 1.f; // v [i] = 0.f; } -template +template struct initialize_c_matrix { #ifdef BOOST_MSVC BOOST_UBLAS_INLINE void operator () (typename c_matrix_traits::type m) { #else void operator () (typename c_matrix_traits::type &m) { -#endif - for (int i = 0; i < N; ++ i) - for (int j = 0; j < M; ++ j) +#endif + for (int i = 0; i < N; ++ i) + for (int j = 0; j < M; ++ j) m [i] [j] = rand () * 1.f; // m [i] [j] = 0.f; } @@ -69,8 +85,8 @@ BOOST_UBLAS_INLINE void initialize_matrix (M &m) { int size1 = m.size1 (); int size2 = m.size2 (); - for (int i = 0; i < size1; ++ i) - for (int j = 0; j < size2; ++ j) + for (int i = 0; i < size1; ++ i) + for (int j = 0; j < size2; ++ j) m (i, j) = rand () * 1.f; // m (i, j) = 0.f; } @@ -88,7 +104,7 @@ struct sink_c_vector { void operator () (const typename c_vector_traits::type v) { #else void operator () (const typename c_vector_traits::type &v) { -#endif +#endif static typename c_vector_traits::type g_v; for (int i = 0; i < N; ++ i) g_v [i] = v [i]; @@ -105,9 +121,9 @@ struct sink_c_matrix { #ifdef BOOST_MSVC BOOST_UBLAS_INLINE void operator () (const typename c_matrix_traits::type m) { -#else +#else void operator () (const typename c_matrix_traits::type &m) { -#endif +#endif static typename c_matrix_traits::type g_m; for (int i = 0; i < N; ++ i) for (int j = 0; j < M; ++ j) diff --git a/bench3/bench31.cpp b/bench3/bench31.cpp index 99be327b..47aba28d 100644 --- a/bench3/bench31.cpp +++ b/bench3/bench31.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/bench3/bench32.cpp b/bench3/bench32.cpp index 183e6e62..efbf1072 100644 --- a/bench3/bench32.cpp +++ b/bench3/bench32.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -391,13 +407,13 @@ void bench_2::operator () (int runs) { ublas::vector >, N> () (runs, safe_tag ()); header ("matrix, vector fast"); - bench_my_outer_prod >, + bench_my_outer_prod >, ublas::vector >, N> () (runs, fast_tag ()); #endif #ifdef USE_UNBOUNDED_ARRAY header ("matrix, vector safe"); - bench_my_outer_prod >, + bench_my_outer_prod >, ublas::vector >, N> () (runs, safe_tag ()); header ("matrix, vector fast"); @@ -407,7 +423,7 @@ void bench_2::operator () (int runs) { #ifdef USE_STD_VALARRAY header ("matrix, vector safe"); - bench_my_outer_prod >, + bench_my_outer_prod >, ublas::vector >, N> () (runs, safe_tag ()); header ("matrix, vector fast"); @@ -451,13 +467,13 @@ void bench_2::operator () (int runs) { ublas::vector >, N> () (runs, safe_tag ()); header ("matrix, vector fast"); - bench_my_matrix_vector_prod >, + bench_my_matrix_vector_prod >, ublas::vector >, N> () (runs, fast_tag ()); #endif #ifdef USE_UNBOUNDED_ARRAY header ("matrix, vector safe"); - bench_my_matrix_vector_prod >, + bench_my_matrix_vector_prod >, ublas::vector >, N> () (runs, safe_tag ()); header ("matrix, vector fast"); @@ -467,7 +483,7 @@ void bench_2::operator () (int runs) { #ifdef USE_STD_VALARRAY header ("matrix, vector safe"); - bench_my_matrix_vector_prod >, + bench_my_matrix_vector_prod >, ublas::vector >, N> () (runs, safe_tag ()); header ("matrix, vector fast"); diff --git a/bench3/bench33.cpp b/bench3/bench33.cpp index 814524b4..6395be43 100644 --- a/bench3/bench33.cpp +++ b/bench3/bench33.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/bench4/Jamfile b/bench4/Jamfile new file mode 100644 index 00000000..e720dcb7 --- /dev/null +++ b/bench4/Jamfile @@ -0,0 +1,13 @@ +subproject libs/numeric/ublas/bench4 ; + +SOURCES = bench4 bench41 bench42 bench43 ; + +exe bench4 + : $(SOURCES).cpp + : $(BOOST_ROOT) + BOOST_UBLAS_USE_INTERVAL + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" + ; + + diff --git a/bench4/bench4.cpp b/bench4/bench4.cpp new file mode 100644 index 00000000..ef259867 --- /dev/null +++ b/bench4/bench4.cpp @@ -0,0 +1,257 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#include "bench4.hpp" + +void header (std::string text) { + std::cout << text << std::endl; + std::cerr << text << std::endl; +} + +template +struct peak_c_plus { + typedef T value_type; + + void operator () (int runs) const { + try { + static T s (0); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + s += T (0); +// sink_scalar (s); + } + footer () (0, 1, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; +template +struct peak_c_multiplies { + typedef T value_type; + + void operator () (int runs) const { + try { + static T s (1); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + s *= T (1); +// sink_scalar (s); + } + footer () (0, 1, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; + +template +void peak::operator () (int runs) { + header ("peak"); + + header ("plus"); + peak_c_plus () (runs); + + header ("multiplies"); + peak_c_multiplies () (runs); +} + +template struct peak >; +template struct peak >; + +#ifdef USE_BOOST_COMPLEX + +template struct peak > >; +template struct peak > >; + +#endif + +#ifdef BOOST_MSVC +// Standard new handler is not standard compliant. +#include +int __cdecl std_new_handler (unsigned) { + throw std::bad_alloc (); +} +#endif + +int main (int argc, char *argv []) { +#ifdef BOOST_MSVC + _set_new_handler (std_new_handler); +#endif + +#ifdef USE_FLOAT + header ("boost::numeric::interval"); + peak > () (100000000); +#endif + +#ifdef USE_DOUBLE + header ("boost::numeric::interval"); + peak > () (100000000); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + header ("std:complex >"); + peak > > () (100000000); +#endif + +#ifdef USE_DOUBLE + header ("std:complex >"); + peak > > () (100000000); +#endif +#endif + + int scale = 1; + if (argc > 1) + scale = atoi (argv [1]); + +#ifdef USE_FLOAT + header ("boost::numeric::interval, 3"); + + bench_1, 3> () (1000000 * scale); + bench_2, 3> () (300000 * scale); + bench_3, 3> () (100000 * scale); + + header ("boost::numeric::interval, 10"); + + bench_1, 10> () (300000 * scale); + bench_2, 10> () (30000 * scale); + bench_3, 10> () (3000 * scale); + + header ("boost::numeric::interval, 30"); + + bench_1, 30> () (100000 * scale); + bench_2, 30> () (3000 * scale); + bench_3, 30> () (100 * scale); + + header ("boost::numeric::interval, 100"); + + bench_1, 100> () (30000 * scale); + bench_2, 100> () (300 * scale); + bench_3, 100> () (3 * scale); +#endif + +#ifdef USE_DOUBLE + header ("boost::numeric::interval, 3"); + + bench_1, 3> () (1000000 * scale); + bench_2, 3> () (300000 * scale); + bench_3, 3> () (100000 * scale); + + header ("boost::numeric::interval, 10"); + + bench_1, 10> () (300000 * scale); + bench_2, 10> () (30000 * scale); + bench_3, 10> () (3000 * scale); + + header ("boost::numeric::interval, 30"); + + bench_1, 30> () (100000 * scale); + bench_2, 30> () (3000 * scale); + bench_3, 30> () (100 * scale); + + header ("boost::numeric::interval, 100"); + + bench_1, 100> () (30000 * scale); + bench_2, 100> () (300 * scale); + bench_3, 100> () (3 * scale); +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT + header ("boost::complex >, 3"); + + bench_1 >, 3> () (1000000 * scale); + bench_2 >, 3> () (300000 * scale); + bench_3 >, 3> () (100000 * scale); + + header ("boost::complex >, 10"); + + bench_1 >, 10> () (300000 * scale); + bench_2 >, 10> () (30000 * scale); + bench_3 >, 10> () (3000 * scale); + + header ("boost::complex >, 30"); + + bench_1 >, 30> () (100000 * scale); + bench_2 >, 30> () (3000 * scale); + bench_3 >, 30> () (100 * scale); + + header ("boost::complex >, 100"); + + bench_1 >, 100> () (30000 * scale); + bench_2 >, 100> () (300 * scale); + bench_3 >, 100> () (3 * scale); +#endif + +#ifdef USE_DOUBLE + header ("boost::complex >, 3"); + + bench_1 >, 3> () (1000000 * scale); + bench_2 >, 3> () (300000 * scale); + bench_3 >, 3> () (100000 * scale); + + header ("boost::complex >, 10"); + + bench_1 >, 10> () (300000 * scale); + bench_2 >, 10> () (30000 * scale); + bench_3 >, 10> () (3000 * scale); + + header ("boost::complex >, 30"); + + bench_1 >, 30> () (100000 * scale); + bench_2 >, 30> () (3000 * scale); + bench_3 >, 30> () (100 * scale); + + header ("boost::complex >, 100"); + + bench_1 >, 100> () (30000 * scale); + bench_2 >, 100> () (300 * scale); + bench_3 >, 100> () (3 * scale); +#endif +#endif + + return 0; +} + diff --git a/bench4/bench4.dsp b/bench4/bench4.dsp new file mode 100644 index 00000000..b77e2f52 --- /dev/null +++ b/bench4/bench4.dsp @@ -0,0 +1,214 @@ +# Microsoft Developer Studio Project File - Name="bench3" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=bench3 - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "bench3.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "bench3.mak" CFG="bench3 - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "bench3 - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "bench3 - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName ""$/boost/libs/numeric/ublas/bench3", SDCAAAAA" +# PROP Scc_LocalPath "." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "bench3 - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +dCPP=cl.exe +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /Oy- /I "..\..\..\.." /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /Zm1000 /c +# ADD BASE RSC /l 0x407 /d "NDEBUG" +# ADD RSC /l 0x407 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "bench3 - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +dCPP=cl.exe +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\.." /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /Zm1000 /c +# ADD BASE RSC /l 0x407 /d "_DEBUG" +# ADD RSC /l 0x407 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "bench3 - Win32 Release" +# Name "bench3 - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\bench3.cpp +# End Source File +# Begin Source File + +SOURCE=.\bench31.cpp +# End Source File +# Begin Source File + +SOURCE=.\bench32.cpp +# End Source File +# Begin Source File + +SOURCE=.\bench33.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\banded.hpp +# End Source File +# Begin Source File + +SOURCE=.\bench3.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\blas.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\concepts.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\config.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\duff.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\exception.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\functional.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\hermitian.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\io.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\iterator.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\matrix.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\matrix_assign.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\matrix_expression.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\matrix_proxy.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\matrix_sparse.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\storage.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\storage_sparse.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\symmetric.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\traits.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\triangular.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\vector.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\vector_assign.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\vector_expression.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\vector_proxy.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\vector_sparse.hpp +# End Source File +# End Group +# End Target +# End Project diff --git a/bench4/bench4.hpp b/bench4/bench4.hpp new file mode 100644 index 00000000..f8439212 --- /dev/null +++ b/bench4/bench4.hpp @@ -0,0 +1,174 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifndef BENCH4_H +#define BENCH4_H + +namespace ublas = boost::numeric::ublas; + +void header (std::string text); + +template +struct footer { + void operator () (int multiplies, int plus, int runs, double elapsed) { + std::cout << "elapsed: " << elapsed << " s, " + << (multiplies * ublas::type_traits::multiplies_complexity + + plus * ublas::type_traits::plus_complexity) * runs / + (1024 * 1024 * elapsed) << " Mflops" << std::endl; + std::cerr << "elapsed: " << elapsed << " s, " + << (multiplies * ublas::type_traits::multiplies_complexity + + plus * ublas::type_traits::plus_complexity) * runs / + (1024 * 1024 * elapsed) << " Mflops" << std::endl; + } +}; + +template +struct c_vector_traits { + typedef T type [N]; +}; +template +struct c_matrix_traits { + typedef T type [N] [M]; +}; + +template +struct initialize_c_vector { +#ifdef BOOST_MSVC + BOOST_UBLAS_INLINE + void operator () (typename c_vector_traits::type v) { +#else + void operator () (typename c_vector_traits::type &v) { +#endif + for (int i = 0; i < N; ++ i) + v [i] = rand () * 1.f; +// v [i] = 0.f; + } +}; +template +BOOST_UBLAS_INLINE +void initialize_vector (V &v) { + int size = v.size (); + for (int i = 0; i < size; ++ i) + v [i] = rand () * 1.f; +// v [i] = 0.f; +} + +template +struct initialize_c_matrix { +#ifdef BOOST_MSVC + BOOST_UBLAS_INLINE + void operator () (typename c_matrix_traits::type m) { +#else + void operator () (typename c_matrix_traits::type &m) { +#endif + for (int i = 0; i < N; ++ i) + for (int j = 0; j < M; ++ j) + m [i] [j] = rand () * 1.f; +// m [i] [j] = 0.f; + } +}; +template +BOOST_UBLAS_INLINE +void initialize_matrix (M &m) { + int size1 = m.size1 (); + int size2 = m.size2 (); + for (int i = 0; i < size1; ++ i) + for (int j = 0; j < size2; ++ j) + m (i, j) = rand () * 1.f; +// m (i, j) = 0.f; +} + +template +BOOST_UBLAS_INLINE +void sink_scalar (const T &s) { + static T g_s = s; +} + +template +struct sink_c_vector { +#ifdef BOOST_MSVC + BOOST_UBLAS_INLINE + void operator () (const typename c_vector_traits::type v) { +#else + void operator () (const typename c_vector_traits::type &v) { +#endif + static typename c_vector_traits::type g_v; + for (int i = 0; i < N; ++ i) + g_v [i] = v [i]; + } +}; +template +BOOST_UBLAS_INLINE +void sink_vector (const V &v) { + static V g_v (v); +} + +template +struct sink_c_matrix { +#ifdef BOOST_MSVC + BOOST_UBLAS_INLINE + void operator () (const typename c_matrix_traits::type m) { +#else + void operator () (const typename c_matrix_traits::type &m) { +#endif + static typename c_matrix_traits::type g_m; + for (int i = 0; i < N; ++ i) + for (int j = 0; j < M; ++ j) + g_m [i] [j] = m [i] [j]; + } +}; +template +BOOST_UBLAS_INLINE +void sink_matrix (const M &m) { + static M g_m (m); +} + +template +struct peak { + void operator () (int runs); +}; + +template +struct bench_1 { + void operator () (int runs); +}; + +template +struct bench_2 { + void operator () (int runs); +}; + +template +struct bench_3 { + void operator () (int runs); +}; + +struct safe_tag {}; +struct fast_tag {}; + +// #define USE_FLOAT +#define USE_DOUBLE +// #define USE_STD_COMPLEX + +#define USE_C_ARRAY +// #define USE_BOUNDED_ARRAY +#define USE_UNBOUNDED_ARRAY +// #define USE_STD_VALARRAY +#define USE_STD_VECTOR + +#endif + + diff --git a/bench4/bench41.cpp b/bench4/bench41.cpp new file mode 100644 index 00000000..4084272d --- /dev/null +++ b/bench4/bench41.cpp @@ -0,0 +1,361 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#include "bench4.hpp" + +template +struct bench_c_inner_prod { + typedef T value_type; + + void operator () (int runs) const { + try { + static typename c_vector_traits::type v1, v2; + initialize_c_vector () (v1); + initialize_c_vector () (v2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + static value_type s (0); + for (int j = 0; j < N; ++ j) { + s += v1 [j] * v2 [j]; + } +// sink_scalar (s); + } + footer () (N, N - 1, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; +template +struct bench_my_inner_prod { + typedef typename V::value_type value_type; + + void operator () (int runs) const { + try { +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + static V v1 (N), v2 (N); + ublas::vector_range vr1 (v1, ublas::range<> (0, N)), + vr2 (v2, ublas::range<> (0, N)); +#else + static V v1 (N), v2 (N); + ublas::vector_range vr1 (v1, ublas::range (0, N)), + vr2 (v2, ublas::range (0, N)); +#endif + initialize_vector (vr1); + initialize_vector (vr2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + static value_type s (0); + s = ublas::inner_prod (vr1, vr2); +// sink_scalar (s); + } + footer () (N, N - 1, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; +template +struct bench_cpp_inner_prod { + typedef typename V::value_type value_type; + + void operator () (int runs) const { + try { + static V v1 (N), v2 (N); + initialize_vector (v1); + initialize_vector (v2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + static value_type s (0); + s = (v1 * v2).sum (); +// sink_scalar (s); + } + footer () (N, N - 1, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; + +template +struct bench_c_vector_add { + typedef T value_type; + + void operator () (int runs) const { + try { + static typename c_vector_traits::type v1, v2, v3; + initialize_c_vector () (v1); + initialize_c_vector () (v2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + for (int j = 0; j < N; ++ j) { + v3 [j] = - (v1 [j] + v2 [j]); + } +// sink_c_vector () (v3); + } + footer () (0, 2 * N, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; +template +struct bench_my_vector_add { + typedef typename V::value_type value_type; + + void operator () (int runs, safe_tag) const { + try { +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + static V v1 (N), v2 (N), v3 (N); + ublas::vector_range vr1 (v1, ublas::range<> (0, N)), + vr2 (v2, ublas::range<> (0, N)), + vr3 (v2, ublas::range<> (0, N)); +#else + static V v1 (N), v2 (N), v3 (N); + ublas::vector_range vr1 (v1, ublas::range (0, N)), + vr2 (v2, ublas::range (0, N)), + vr3 (v2, ublas::range (0, N)); +#endif + initialize_vector (vr1); + initialize_vector (vr2); + initialize_vector (vr3); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + vr3 = - (vr1 + vr2); +// sink_vector (vr3); + } + footer () (0, 2 * N, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } + void operator () (int runs, fast_tag) const { + try { +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + static V v1 (N), v2 (N), v3 (N); + ublas::vector_range vr1 (v1, ublas::range<> (0, N)), + vr2 (v2, ublas::range<> (0, N)), + vr3 (v2, ublas::range<> (0, N)); +#else + static V v1 (N), v2 (N), v3 (N); + ublas::vector_range vr1 (v1, ublas::range (0, N)), + vr2 (v2, ublas::range (0, N)), + vr3 (v2, ublas::range (0, N)); +#endif + initialize_vector (vr1); + initialize_vector (vr2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + vr3.assign (- (vr1 + vr2)); +// sink_vector (vr3); + } + footer () (0, 2 * N, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; +template +struct bench_cpp_vector_add { + typedef typename V::value_type value_type; + + void operator () (int runs) const { + try { + static V v1 (N), v2 (N), v3 (N); + initialize_vector (v1); + initialize_vector (v2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + v3 = - (v1 + v2); +// sink_vector (v3); + } + footer () (0, 2 * N, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; + +// Benchmark O (n) +template +void bench_1::operator () (int runs) { + header ("bench_1"); + + header ("inner_prod"); + + header ("C array"); + bench_c_inner_prod () (runs); + +#ifdef USE_C_ARRAY + header ("c_vector"); + bench_my_inner_prod, N> () (runs); +#endif + +#ifdef USE_BOUNDED_ARRAY + header ("vector"); + bench_my_inner_prod >, N> () (runs); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + header ("vector"); + bench_my_inner_prod >, N> () (runs); +#endif + +#ifdef USE_STD_VALARRAY + header ("vector"); + bench_my_inner_prod >, N> () (); +#endif + +#ifdef USE_STD_VECTOR + header ("vector"); + bench_my_inner_prod >, N> () (runs); +#endif + +#ifdef USE_STD_VALARRAY + header ("std::valarray"); + bench_cpp_inner_prod, N> () (runs); +#endif + + header ("vector + vector"); + + header ("C array"); + bench_c_vector_add () (runs); + +#ifdef USE_C_ARRAY + header ("c_vector safe"); + bench_my_vector_add, N> () (runs, safe_tag ()); + + header ("c_vector fast"); + bench_my_vector_add, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_BOUNDED_ARRAY + header ("vector safe"); + bench_my_vector_add >, N> () (runs, safe_tag ()); + + header ("vector fast"); + bench_my_vector_add >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + header ("vector safe"); + bench_my_vector_add >, N> () (runs, safe_tag ()); + + header ("vector fast"); + bench_my_vector_add >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VALARRAY + header ("vector safe"); + bench_my_vector_add >, N> () (runs, safe_tag ()); + + header ("vector fast"); + bench_my_vector_add >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VECTOR + header ("vector safe"); + bench_my_vector_add >, N> () (runs, safe_tag ()); + + header ("vector fast"); + bench_my_vector_add >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VALARRAY + header ("std::valarray"); + bench_cpp_vector_add, N> () (runs); +#endif +} + +#ifdef USE_FLOAT +template struct bench_1, 3>; +template struct bench_1, 10>; +template struct bench_1, 30>; +template struct bench_1, 100>; +#endif + +#ifdef USE_DOUBLE +template struct bench_1, 3>; +template struct bench_1, 10>; +template struct bench_1, 30>; +template struct bench_1, 100>; +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT +template struct bench_1 >, 3>; +template struct bench_1 >, 10>; +template struct bench_1 >, 30>; +template struct bench_1 >, 100>; +#endif + +#ifdef USE_DOUBLE +template struct bench_1 >, 3>; +template struct bench_1 >, 10>; +template struct bench_1 >, 30>; +template struct bench_1 >, 100>; +#endif +#endif + + diff --git a/bench4/bench42.cpp b/bench4/bench42.cpp new file mode 100644 index 00000000..caf398af --- /dev/null +++ b/bench4/bench42.cpp @@ -0,0 +1,593 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#include "bench4.hpp" + +template +struct bench_c_outer_prod { + typedef T value_type; + + void operator () (int runs) const { + try { + static typename c_matrix_traits::type m; + static typename c_vector_traits::type v1, v2; + initialize_c_vector () (v1); + initialize_c_vector () (v2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + for (int j = 0; j < N; ++ j) { + for (int k = 0; k < N; ++ k) { + m [j] [k] = - v1 [j] * v2 [k]; + } + } +// sink_c_matrix () (m); + } + footer () (N * N, N * N, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; +template +struct bench_my_outer_prod { + typedef typename M::value_type value_type; + + void operator () (int runs, safe_tag) const { + try { +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + static M m (N, N); + ublas::matrix_range mr (m, ublas::range<> (0, N), ublas::range<> (0, N)); + static V v1 (N), v2 (N); + ublas::vector_range vr1 (v1, ublas::range<> (0, N)), + vr2 (v2, ublas::range<> (0, N)); +#else + static M m (N, N); + ublas::matrix_range mr (m, ublas::range (0, N), ublas::range (0, N)); + static V v1 (N), v2 (N); + ublas::vector_range vr1 (v1, ublas::range (0, N)), + vr2 (v2, ublas::range (0, N)); +#endif + initialize_vector (vr1); + initialize_vector (vr2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + mr = - ublas::outer_prod (vr1, vr2); +// sink_matrix (mr); + } + footer () (N * N, N * N, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } + void operator () (int runs, fast_tag) const { + try { +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + static M m (N, N); + ublas::matrix_range mr (m, ublas::range<> (0, N), ublas::range<> (0, N)); + static V v1 (N), v2 (N); + ublas::vector_range vr1 (v1, ublas::range<> (0, N)), + vr2 (v2, ublas::range<> (0, N)); +#else + static M m (N, N); + ublas::matrix_range mr (m, ublas::range (0, N), ublas::range (0, N)); + static V v1 (N), v2 (N); + ublas::vector_range vr1 (v1, ublas::range (0, N)), + vr2 (v2, ublas::range (0, N)); +#endif + initialize_vector (vr1); + initialize_vector (vr2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + mr.assign (- ublas::outer_prod (vr1, vr2)); +// sink_matrix (mr); + } + footer () (N * N, N * N, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; +template +struct bench_cpp_outer_prod { + typedef typename M::value_type value_type; + + void operator () (int runs) const { + try { + static M m (N * N); + static V v1 (N), v2 (N); + initialize_vector (v1); + initialize_vector (v2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + for (int j = 0; j < N; ++ j) { + for (int k = 0; k < N; ++ k) { + m [N * j + k] = - v1 [j] * v2 [k]; + } + } +// sink_vector (m); + } + footer () (N * N, N * N, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; + +template +struct bench_c_matrix_vector_prod { + typedef T value_type; + + void operator () (int runs) const { + try { + static typename c_matrix_traits::type m; + static typename c_vector_traits::type v1, v2; + initialize_c_matrix () (m); + initialize_c_vector () (v1); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + for (int j = 0; j < N; ++ j) { + v2 [j] = 0; + for (int k = 0; k < N; ++ k) { + v2 [j] += m [j] [k] * v1 [k]; + } + } +// sink_c_vector () (v2); + } + footer () (N * N, N * (N - 1), runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; +template +struct bench_my_matrix_vector_prod { + typedef typename M::value_type value_type; + + void operator () (int runs, safe_tag) const { + try { +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + static M m (N, N); + ublas::matrix_range mr (m, ublas::range<> (0, N), ublas::range<> (0, N)); + static V v1 (N), v2 (N); + ublas::vector_range vr1 (v1, ublas::range<> (0, N)), + vr2 (v2, ublas::range<> (0, N)); +#else + static M m (N, N); + ublas::matrix_range mr (m, ublas::range (0, N), ublas::range (0, N)); + static V v1 (N), v2 (N); + ublas::vector_range vr1 (v1, ublas::range (0, N)), + vr2 (v2, ublas::range (0, N)); +#endif + initialize_matrix (mr); + initialize_vector (vr1); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + vr2 = ublas::prod (mr, vr1); +// sink_vector (vr2); + } + footer () (N * N, N * (N - 1), runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } + void operator () (int runs, fast_tag) const { + try { +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + static M m (N, N); + ublas::matrix_range mr (m, ublas::range<> (0, N), ublas::range<> (0, N)); + static V v1 (N), v2 (N); + ublas::vector_range vr1 (v1, ublas::range<> (0, N)), + vr2 (v2, ublas::range<> (0, N)); +#else + static M m (N, N); + ublas::matrix_range mr (m, ublas::range (0, N), ublas::range (0, N)); + static V v1 (N), v2 (N); + ublas::vector_range vr1 (v1, ublas::range (0, N)), + vr2 (v2, ublas::range (0, N)); +#endif + initialize_matrix (mr); + initialize_vector (vr1); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + vr2.assign (ublas::prod (mr, vr1)); +// sink_vector (vr2); + } + footer () (N * N, N * (N - 1), runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; +template +struct bench_cpp_matrix_vector_prod { + typedef typename M::value_type value_type; + + void operator () (int runs) const { + try { + static M m (N * N); + static V v1 (N), v2 (N); + initialize_vector (m); + initialize_vector (v1); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + for (int j = 0; j < N; ++ j) { + std::valarray row (m [std::slice (N * j, N, 1)]); + v2 [j] = (row * v1).sum (); + } +// sink_vector (v2); + } + footer () (N * N, N * (N - 1), runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; + +template +struct bench_c_matrix_add { + typedef T value_type; + + void operator () (int runs) const { + try { + static typename c_matrix_traits::type m1, m2, m3; + initialize_c_matrix () (m1); + initialize_c_matrix () (m2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + for (int j = 0; j < N; ++ j) { + for (int k = 0; k < N; ++ k) { + m3 [j] [k] = - (m1 [j] [k] + m2 [j] [k]); + } + } +// sink_c_matrix () (m3); + } + footer () (0, 2 * N * N, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; +template +struct bench_my_matrix_add { + typedef typename M::value_type value_type; + + void operator () (int runs, safe_tag) const { + try { + static M m1 (N, N), m2 (N, N), m3 (N, N); + initialize_matrix (m1); + initialize_matrix (m2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + m3 = - (m1 + m2); +// sink_matrix (m3); + } + footer () (0, 2 * N * N, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } + void operator () (int runs, fast_tag) const { + try { + static M m1 (N, N), m2 (N, N), m3 (N, N); + initialize_matrix (m1); + initialize_matrix (m2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + m3.assign (- (m1 + m2)); +// sink_matrix (m3); + } + footer () (0, 2 * N * N, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; +template +struct bench_cpp_matrix_add { + typedef typename M::value_type value_type; + + void operator () (int runs) const { + try { + static M m1 (N * N), m2 (N * N), m3 (N * N); + initialize_vector (m1); + initialize_vector (m2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + m3 = - (m1 + m2); +// sink_vector (m3); + } + footer () (0, 2 * N * N, runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; + +// Benchmark O (n ^ 2) +template +void bench_2::operator () (int runs) { + header ("bench_2"); + + header ("outer_prod"); + + header ("C array"); + bench_c_outer_prod () (runs); + +#ifdef USE_C_ARRAY + header ("c_matrix, c_vector safe"); + bench_my_outer_prod, + ublas::c_vector, N> () (runs, safe_tag ()); + + header ("c_matrix, c_vector fast"); + bench_my_outer_prod, + ublas::c_vector, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_BOUNDED_ARRAY + header ("matrix, vector safe"); + bench_my_outer_prod >, + ublas::vector >, N> () (runs, safe_tag ()); + + header ("matrix, vector fast"); + bench_my_outer_prod >, + ublas::vector >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + header ("matrix, vector safe"); + bench_my_outer_prod >, + ublas::vector >, N> () (runs, safe_tag ()); + + header ("matrix, vector fast"); + bench_my_outer_prod >, + ublas::vector >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VALARRAY + header ("matrix, vector safe"); + bench_my_outer_prod >, + ublas::vector >, N> () (runs, safe_tag ()); + + header ("matrix, vector fast"); + bench_my_outer_prod >, + ublas::vector >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VECTOR + header ("matrix, vector safe"); + bench_my_outer_prod >, + ublas::vector >, N> () (runs, safe_tag ()); + + header ("matrix, vector fast"); + bench_my_outer_prod >, + ublas::vector >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VALARRAY + header ("std::valarray"); + bench_cpp_outer_prod, std::valarray, N> () (runs); +#endif + + header ("prod (matrix, vector)"); + + header ("C array"); + bench_c_matrix_vector_prod () (runs); + +#ifdef USE_C_ARRAY + header ("c_matrix, c_vector safe"); + bench_my_matrix_vector_prod, + ublas::c_vector, N> () (runs, safe_tag ()); + + header ("c_matrix, c_vector fast"); + bench_my_matrix_vector_prod, + ublas::c_vector, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_BOUNDED_ARRAY + header ("matrix, vector safe"); + bench_my_matrix_vector_prod >, + ublas::vector >, N> () (runs, safe_tag ()); + + header ("matrix, vector fast"); + bench_my_matrix_vector_prod >, + ublas::vector >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + header ("matrix, vector safe"); + bench_my_matrix_vector_prod >, + ublas::vector >, N> () (runs, safe_tag ()); + + header ("matrix, vector fast"); + bench_my_matrix_vector_prod >, + ublas::vector >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VALARRAY + header ("matrix, vector safe"); + bench_my_matrix_vector_prod >, + ublas::vector >, N> () (runs, safe_tag ()); + + header ("matrix, vector fast"); + bench_my_matrix_vector_prod >, + ublas::vector >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VECTOR + header ("matrix, vector safe"); + bench_my_matrix_vector_prod >, + ublas::vector >, N> () (runs, safe_tag ()); + + header ("matrix, vector fast"); + bench_my_matrix_vector_prod >, + ublas::vector >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VALARRAY + header ("std::valarray"); + bench_cpp_matrix_vector_prod, std::valarray, N> () (runs); +#endif + + header ("matrix + matrix"); + + header ("C array"); + bench_c_matrix_add () (runs); + +#ifdef USE_C_ARRAY + header ("c_matrix safe"); + bench_my_matrix_add, N> () (runs, safe_tag ()); + + header ("c_matrix fast"); + bench_my_matrix_add, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_BOUNDED_ARRAY + header ("matrix safe"); + bench_my_matrix_add >, N> () (runs, safe_tag ()); + + header ("matrix fast"); + bench_my_matrix_add >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + header ("matrix safe"); + bench_my_matrix_add >, N> () (runs, safe_tag ()); + + header ("matrix fast"); + bench_my_matrix_add >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VALARRAY + header ("matrix safe"); + bench_my_matrix_add >, N> () (runs, safe_tag ()); + + header ("matrix fast"); + bench_my_matrix_add >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VECTOR + header ("matrix safe"); + bench_my_matrix_add >, N> () (runs, safe_tag ()); + + header ("matrix fast"); + bench_my_matrix_add >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VALARRAY + header ("std::valarray"); + bench_cpp_matrix_add, N> () (runs); +#endif +} + +#ifdef USE_FLOAT +template struct bench_2, 3>; +template struct bench_2, 10>; +template struct bench_2, 30>; +template struct bench_2, 100>; +#endif + +#ifdef USE_DOUBLE +template struct bench_2, 3>; +template struct bench_2, 10>; +template struct bench_2, 30>; +template struct bench_2, 100>; +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT +template struct bench_2 >, 3>; +template struct bench_2 >, 10>; +template struct bench_2 >, 30>; +template struct bench_2 >, 100>; +#endif + +#ifdef USE_DOUBLE +template struct bench_2 >, 3>; +template struct bench_2 >, 10>; +template struct bench_2 >, 30>; +template struct bench_2 >, 100>; +#endif +#endif + + diff --git a/bench4/bench43.cpp b/bench4/bench43.cpp new file mode 100644 index 00000000..20bec0a4 --- /dev/null +++ b/bench4/bench43.cpp @@ -0,0 +1,248 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#include "bench4.hpp" + +template +struct bench_c_matrix_prod { + typedef T value_type; + + void operator () (int runs) const { + try { + static typename c_matrix_traits::type m1, m2, m3; + initialize_c_matrix () (m1); + initialize_c_matrix () (m2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + for (int j = 0; j < N; ++ j) { + for (int k = 0; k < N; ++ k) { + m3 [j] [k] = 0; + for (int l = 0; l < N; ++ l) { + m3 [j] [k] += m1 [j] [l] * m2 [l] [k]; + } + } + } +// sink_c_matrix () (m3); + } + footer () (N * N * N, N * N * (N - 1), runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; +template +struct bench_my_matrix_prod { + typedef typename M::value_type value_type; + + void operator () (int runs, safe_tag) const { + try { + static M m1 (N, N), m2 (N, N), m3 (N, N); +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + ublas::matrix_range mr1 (m1, ublas::range<> (0, N), ublas::range<> (0, N)), + mr2 (m2, ublas::range<> (0, N), ublas::range<> (0, N)), + mr3 (m3, ublas::range<> (0, N), ublas::range<> (0, N)); +#else + ublas::matrix_range mr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mr2 (m2, ublas::range (0, N), ublas::range (0, N)), + mr3 (m3, ublas::range (0, N), ublas::range (0, N)); +#endif + initialize_matrix (mr1); + initialize_matrix (mr2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + mr3 = ublas::prod (mr1, mr2); +// sink_matrix (mr3); + } + footer () (N * N * N, N * N * (N - 1), runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } + void operator () (int runs, fast_tag) const { + try { + static M m1 (N, N), m2 (N, N), m3 (N, N); +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + ublas::matrix_range mr1 (m1, ublas::range<> (0, N), ublas::range<> (0, N)), + mr2 (m2, ublas::range<> (0, N), ublas::range<> (0, N)), + mr3 (m3, ublas::range<> (0, N), ublas::range<> (0, N)); +#else + ublas::matrix_range mr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mr2 (m2, ublas::range (0, N), ublas::range (0, N)), + mr3 (m3, ublas::range (0, N), ublas::range (0, N)); +#endif + initialize_matrix (mr1); + initialize_matrix (mr2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + mr3.assign (ublas::prod (mr1, mr2)); +// sink_matrix (mr3); + } + footer () (N * N * N, N * N * (N - 1), runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; +template +struct bench_cpp_matrix_prod { + typedef typename M::value_type value_type; + + void operator () (int runs) const { + try { + static M m1 (N * N), m2 (N * N), m3 (N * N); + initialize_vector (m1); + initialize_vector (m2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + for (int j = 0; j < N; ++ j) { + std::valarray row (m1 [std::slice (N * j, N, 1)]); + for (int k = 0; k < N; ++ k) { + std::valarray column (m2 [std::slice (k, N, N)]); + m3 [N * j + k] = (row * column).sum (); + } + } +// sink_vector (m3); + } + footer () (N * N * N, N * N * (N - 1), runs, t.elapsed ()); + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; + +// Benchmark O (n ^ 3) +template +void bench_3::operator () (int runs) { + header ("bench_3"); + + header ("prod (matrix, matrix)"); + + header ("C array"); + bench_c_matrix_prod () (runs); + +#ifdef USE_C_ARRAY + header ("c_matrix safe"); + bench_my_matrix_prod, N> () (runs, safe_tag ()); + + header ("c_matrix fast"); + bench_my_matrix_prod, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_BOUNDED_ARRAY + header ("matrix safe"); + bench_my_matrix_prod >, N> () (runs, safe_tag ()); + + header ("matrix fast"); + bench_my_matrix_prod >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + header ("matrix safe"); + bench_my_matrix_prod >, N> () (runs, safe_tag ()); + + header ("matrix fast"); + bench_my_matrix_prod >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VALARRAY + header ("matrix safe"); + bench_my_matrix_prod >, N> () (runs, safe_tag ()); + + header ("matrix fast"); + bench_my_matrix_prod >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VECTOR + header ("matrix safe"); + bench_my_matrix_prod >, N> () (runs, safe_tag ()); + + header ("matrix fast"); + bench_my_matrix_prod >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VALARRAY + header ("std::valarray"); + bench_cpp_matrix_prod, N> () (runs); +#endif +} + +#ifdef USE_FLOAT +template struct bench_3, 3>; +template struct bench_3, 10>; +template struct bench_3, 30>; +template struct bench_3, 100>; +#endif + +#ifdef USE_DOUBLE +template struct bench_3, 3>; +template struct bench_3, 10>; +template struct bench_3, 30>; +template struct bench_3, 100>; +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT +template struct bench_3 >, 3>; +template struct bench_3 >, 10>; +template struct bench_3 >, 30>; +template struct bench_3 >, 100>; +#endif + +#ifdef USE_DOUBLE +template struct bench_3 >, 3>; +template struct bench_3 >, 10>; +template struct bench_3 >, 30>; +template struct bench_3 >, 100>; +#endif +#endif + + diff --git a/concepts.cpp b/concepts.cpp index 6bb1a20d..62e79cca 100644 --- a/concepts.cpp +++ b/concepts.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/doc/banded.htm b/doc/banded.htm index e7b7ffd8..84581ae4 100644 --- a/doc/banded.htm +++ b/doc/banded.htm @@ -29,7 +29,7 @@ matrices is packed.

int main () {
     using namespace boost::numeric::ublas;
     banded_matrix<double> m (3, 3, 1, 1);
-    for (int i = 0; i < m.size1 (); ++ i) 
+    for (int i = 0; i < m.size1 (); ++ i)
         for (int j = std::max (i - 1, 0); j < std::min (i + 2, m.size2 ()); ++ j)
             m (i, j) = 3 * i + j;
     std::cout << m << std::endl;
@@ -330,11 +330,11 @@ and std::vector<T>. 

Interface

-
    // Array based banded matrix class 
+
    // Array based banded matrix class
     template<class T, class F, class A>
-    class banded_matrix: 
+    class banded_matrix:
         public matrix_expression<banded_matrix<T, F, A> > {
-    public:      
+    public:
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
         typedef T value_type;
@@ -466,7 +466,7 @@ and std::vector<T>. 

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator1 &operator = (const const_iterator1 &it); // Comparison @@ -512,7 +512,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator1 &operator = (const iterator1 &it); // Comparison @@ -559,7 +559,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator2 &operator = (const const_iterator2 &it); // Comparison @@ -605,7 +605,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator2 &operator = (const iterator2 &it); // Comparison @@ -644,7 +644,7 @@ banded matrix adaptor for other matrices.

using namespace boost::numeric::ublas; matrix<double> m (3, 3); banded_adaptor<matrix<double> > ba (m, 1, 1); - for (int i = 0; i < ba.size1 (); ++ i) + for (int i = 0; i < ba.size1 (); ++ i) for (int j = std::max (i - 1, 0); j < std::min (i + 2, ba.size2 ()); ++ j) ba (i, j) = 3 * i + j; std::cout << ba << std::endl; @@ -903,11 +903,11 @@ href="expression.htm#matrix_expression">Matrix Expression.

Interface

-
    // Banded matrix adaptor class 
+
    // Banded matrix adaptor class
     template<class M>
-    class banded_adaptor: 
+    class banded_adaptor:
         public matrix_expression<banded_adaptor<M> > {
-    public:      
+    public:
         typedef const M const_matrix_type;
         typedef M matrix_type;
         typedef typename M::size_type size_type;
@@ -1027,7 +1027,7 @@ href="expression.htm#matrix_expression">Matrix Expression.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator1 &operator = (const const_iterator1 &it); // Comparison @@ -1073,7 +1073,7 @@ href="expression.htm#matrix_expression">Matrix Expression.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator1 &operator = (const iterator1 &it); // Comparison @@ -1120,7 +1120,7 @@ href="expression.htm#matrix_expression">Matrix Expression.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator2 &operator = (const const_iterator2 &it); // Comparison @@ -1166,7 +1166,7 @@ href="expression.htm#matrix_expression">Matrix Expression.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator2 &operator = (const iterator2 &it); // Comparison diff --git a/doc/container.htm b/doc/container.htm index 9a0e5602..6c435171 100644 --- a/doc/container.htm +++ b/doc/container.htm @@ -381,10 +381,10 @@ the matrix.


-

Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
-Permission to copy, use, modify, sell and distribute this document is granted -provided this copyright notice appears in all copies. This document is provided -``as is'' without express or implied warranty, and with no claim as to its suitability +

Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
+Permission to copy, use, modify, sell and distribute this document is granted +provided this copyright notice appears in all copies. This document is provided +``as is'' without express or implied warranty, and with no claim as to its suitability for any purpose.

Last revised: 8/3/2002

diff --git a/doc/expression.htm b/doc/expression.htm index 8aaae942..1aa6ecf4 100644 --- a/doc/expression.htm +++ b/doc/expression.htm @@ -1021,10 +1021,10 @@ quadratic in the size of the proxies.


-

Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
-Permission to copy, use, modify, sell and distribute this document is granted -provided this copyright notice appears in all copies. This document is provided -``as is'' without express or implied warranty, and with no claim as to its suitability +

Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
+Permission to copy, use, modify, sell and distribute this document is granted +provided this copyright notice appears in all copies. This document is provided +``as is'' without express or implied warranty, and with no claim as to its suitability for any purpose.

Last revised: 8/3/2002

diff --git a/doc/hermitian.htm b/doc/hermitian.htm index 56eda66c..8a7abc25 100644 --- a/doc/hermitian.htm +++ b/doc/hermitian.htm @@ -28,12 +28,12 @@ The storage of hermitian matrices is packed.

int main () {
     using namespace boost::numeric::ublas;
     hermitian_matrix<std::complex<double>, lower> ml (3, 3);
-    for (int i = 0; i < ml.size1 (); ++ i) 
+    for (int i = 0; i < ml.size1 (); ++ i)
         for (int j = 0; j <= i; ++ j)
             ml (i, j) = std::complex<double> (3 * i + j, 3 * i + j);
     std::cout << ml << std::endl;
     hermitian_matrix<std::complex<double>, upper> mu (3, 3);
-    for (int i = 0; i < m.size1 (); ++ i) 
+    for (int i = 0; i < m.size1 (); ++ i)
         for (int j = i; j < m.size2 (); ++ j)
             mu (i, j) = std::complex<double> (3 * i + j, 3 * i + j);
     std::cout << mu << std::endl;
@@ -332,11 +332,11 @@ and std::vector<T>. 

Interface

-
    // Array based hermitian matrix class 
+
    // Array based hermitian matrix class
     template<class T, class F1, class F2, class A>
-    class hermitian_matrix: 
+    class hermitian_matrix:
         public matrix_expression<hermitian_matrix<T, F1, F2, A> > {
-    public:      
+    public:
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
         typedef T value_type;
@@ -466,7 +466,7 @@ and std::vector<T>. 

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator1 &operator = (const const_iterator1 &it); // Comparison @@ -512,7 +512,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator1 &operator = (const iterator1 &it); // Comparison @@ -559,7 +559,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator2 &operator = (const const_iterator2 &it); // Comparison @@ -605,7 +605,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator2 &operator = (const iterator2 &it); // Comparison @@ -644,12 +644,12 @@ a hermitian matrix adaptor for other matrices.

using namespace boost::numeric::ublas; matrix<std::complex<double> > m (3, 3); hermitian_adaptor<matrix<std::complex<double> >, lower> hal (m); - for (int i = 0; i < hal.size1 (); ++ i) + for (int i = 0; i < hal.size1 (); ++ i) for (int j = 0; j <= i; ++ j) hal (i, j) = std::complex<double> (3 * i + j, 3 * i + j); std::cout << hal << std::endl; hermitian_adaptor<matrix<std::complex<double> >, upper> hau (m); - for (int i = 0; i < hau.size1 (); ++ i) + for (int i = 0; i < hau.size1 (); ++ i) for (int j = i; j < hau.size2 (); ++ j) hau (i, j) = std::complex<double> (3 * i + j, 3 * i + j); std::cout << sau << std::endl; @@ -909,11 +909,11 @@ for the type of the hermitian adaptor are lower and upperInterface -
    // Hermitian matrix adaptor class 
+
    // Hermitian matrix adaptor class
     template<class M, class F>
-    class hermitian_adaptor: 
+    class hermitian_adaptor:
         public matrix_expression<hermitian_adaptor<M, F> > {
-    public:      
+    public:
         typedef const M const_matrix_type;
         typedef M matrix_type;
         typedef F functor_type;
@@ -1029,7 +1029,7 @@ for the type of the hermitian adaptor are lower and upperlower and upperlower and upperlower and upper
 
int main () {
     using namespace boost::numeric::ublas;
     matrix<double> m (3, 3);
-    for (int i = 0; i < m.size1 (); ++ i) 
-        for (int j = 0; j < m.size2 (); ++ j) 
+    for (int i = 0; i < m.size1 (); ++ i)
+        for (int j = 0; j < m.size2 (); ++ j)
             m (i, j) = 3 * i + j;
     std::cout << m << std::endl;
 }
@@ -443,7 +443,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator1 &operator = (const const_iterator1 &it); // Comparison @@ -489,7 +489,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator1 &operator = (const iterator1 &it); // Comparison @@ -536,7 +536,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator2 &operator = (const const_iterator2 &it); // Comparison @@ -582,7 +582,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator2 &operator = (const iterator2 &it); // Comparison @@ -764,9 +764,9 @@ href="expression.htm#matrix_expression">Matrix Expression.

    // Identity matrix class
     template<class T>
-    class identity_matrix: 
+    class identity_matrix:
         public matrix_expression<identity_matrix<T> > {
-    public:      
+    public:
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
         typedef T value_type;
@@ -854,7 +854,7 @@ href="expression.htm#matrix_expression">Matrix Expression.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator1 &operator = (const const_iterator1 &it); // Comparison @@ -902,7 +902,7 @@ href="expression.htm#matrix_expression">Matrix Expression.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator2 &operator = (const const_iterator2 &it); // Comparison @@ -1078,9 +1078,9 @@ href="expression.htm#matrix_expression">Matrix Expression.

    // Zero matrix class
     template<class T>
-    class zero_matrix: 
+    class zero_matrix:
         public matrix_expression<zero_matrix<T> > {
-    public:      
+    public:
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
         typedef T value_type;
@@ -1163,7 +1163,7 @@ href="expression.htm#matrix_expression">Matrix Expression.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator1 &operator = (const const_iterator1 &it); // Comparison @@ -1207,7 +1207,7 @@ href="expression.htm#matrix_expression">Matrix Expression.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator2 &operator = (const const_iterator2 &it); // Comparison diff --git a/doc/matrix_expression.htm b/doc/matrix_expression.htm index b634e409..8a08c5ba 100644 --- a/doc/matrix_expression.htm +++ b/doc/matrix_expression.htm @@ -77,9 +77,9 @@ including class matrix itself.

typedef E expression_type; typedef matrix_tag type_category; - // This class could define an common interface for all + // This class could define an common interface for all // statically derived expression type classes. - // Due to a compiler deficiency - one can not reference class typedefs of E + // Due to a compiler deficiency - one can not reference class typedefs of E // on MSVC 6.0 (error C2027) - we only implement the casts. const expression_type &operator () () const; @@ -2698,7 +2698,7 @@ F> >
.

public container_const_reference<matrix_matrix_binary>, public random_access_iterator_base<const_iterator1, value_type> { public: - typedef typename restrict_traits<typename E1::const_iterator1::iterator_category, + typedef typename restrict_traits<typename E1::const_iterator1::iterator_category, typename E2::const_iterator2::iterator_category>::iterator_category iterator_category; typedef typename matrix_matrix_binary::difference_type difference_type; typedef typename matrix_matrix_binary::value_type value_type; @@ -2739,7 +2739,7 @@ F> >
.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator1 &operator = (const const_iterator1 &it); // Comparison @@ -2754,7 +2754,7 @@ F> >.

public container_const_reference<matrix_matrix_binary>, public random_access_iterator_base<const_iterator2, value_type> { public: - typedef typename restrict_traits<typename E1::const_iterator1::iterator_category, + typedef typename restrict_traits<typename E1::const_iterator1::iterator_category, typename E2::const_iterator2::iterator_category>::iterator_category iterator_category; typedef typename matrix_matrix_binary::difference_type difference_type; typedef typename matrix_matrix_binary::value_type value_type; @@ -2795,7 +2795,7 @@ F> >.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator2 &operator = (const const_iterator2 &it); // Comparison @@ -2823,38 +2823,38 @@ F> >.

struct matrix_matrix_binary_traits { typedef unknown_orientation_tag dispatch_category; typedef typename promote_traits<T1, T2>::promote_type promote_type; - typedef matrix_matrix_binary<typename E1::const_closure_type, - typename E2::const_closure_type, + typedef matrix_matrix_binary<typename E1::const_closure_type, + typename E2::const_closure_type, matrix_matrix_prod<T1, T2, promote_type> > expression_type; - typedef expression_type result_type; + typedef expression_type result_type; }; template<class E1, class E2> - typename matrix_matrix_binary_traits<typename E1::value_type, E1, + typename matrix_matrix_binary_traits<typename E1::value_type, E1, typename E2::value_type, E2>::result_type - prod (const matrix_expression<E1> &e1, + prod (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2, unknown_orientation_tag); // Dispatcher template<class E1, class E2> - typename matrix_matrix_binary_traits<typename E1::value_type, E1, + typename matrix_matrix_binary_traits<typename E1::value_type, E1, typename E2::value_type, E2>::result_type - prod (const matrix_expression<E1> &e1, + prod (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2); template<class E1, class E2> - typename matrix_matrix_binary_traits<typename type_traits<typename E1::value_type>::precision_type, E1, + typename matrix_matrix_binary_traits<typename type_traits<typename E1::value_type>::precision_type, E1, typename type_traits<typename E2::value_type>::precision_type, E2>::result_type - prec_prod (const matrix_expression<E1> &e1, + prec_prod (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2, unknown_orientation_tag); // Dispatcher template<class E1, class E2> - typename matrix_matrix_binary_traits<typename type_traits<typename E1::value_type>::precision_type, E1, + typename matrix_matrix_binary_traits<typename type_traits<typename E1::value_type>::precision_type, E1, typename type_traits<typename E2::value_type>::precision_type, E2>::result_type - prec_prod (const matrix_expression<E1> &e1, + prec_prod (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2); template<class M, class E1, class E2> @@ -2902,8 +2902,8 @@ product of the matrix expressions.

int main () {
     using namespace boost::numeric::ublas;
     matrix<double > m1 (3, 3), m2 (3, 3);
-    for (int i = 0; i < std::min (m1.size1 (), m2.size1 ()); ++ i) 
-        for (int j = 0; j < std::min (m1.size2 (), m2.size2 ()); ++ j) 
+    for (int i = 0; i < std::min (m1.size1 (), m2.size1 ()); ++ i)
+        for (int j = 0; j < std::min (m1.size2 (), m2.size2 ()); ++ j)
             m1 (i, j) = m2 (i, j) = 3 * i + j;
 
     std::cout << prod (m1, m2) << std::endl;
@@ -2920,29 +2920,29 @@ product of the matrix expressions.

}; template<class E1, class E2> - void inplace_solve (const matrix_expression<E1> &e1, + void inplace_solve (const matrix_expression<E1> &e1, E2 &e2, lower_tag, matrix_tag); template<class E1, class E2> - void inplace_solve (const matrix_expression<E1> &e1, + void inplace_solve (const matrix_expression<E1> &e1, E2 &e2, upper_tag, matrix_tag); template<class E1, class E2> - void inplace_solve (const matrix_expression<E1> &e1, + void inplace_solve (const matrix_expression<E1> &e1, E2 &e2, unit_lower_tag, matrix_tag); template<class E1, class E2> - void inplace_solve (const matrix_expression<E1> &e1, + void inplace_solve (const matrix_expression<E1> &e1, E2 &e2, unit_upper_tag, matrix_tag); template<class E1, class E2, class C> typename matrix_matrix_solve_traits<E1, E2>::result_type - solve (const matrix_expression<E1> &e1, + solve (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2, C);
@@ -2981,8 +2981,8 @@ product of the matrix expressions.

int main () {
     using namespace boost::numeric::ublas;
     matrix<double > m1 (3, 3), m2 (3, 3);
-    for (int i = 0; i < std::min (m1.size1 (), m2.size1 ()); ++ i) 
-        for (int j = 0; j <= i; ++ j) 
+    for (int i = 0; i < std::min (m1.size1 (), m2.size1 ()); ++ i)
+        for (int j = 0; j <= i; ++ j)
             m1 (i, j) = m2 (i, j) = 3 * i + j;
 
     std::cout << solve (m1, m2, lower_tag ()) << std::endl;
diff --git a/doc/matrix_proxy.htm b/doc/matrix_proxy.htm
index e1b7cd03..b4c9ce61 100644
--- a/doc/matrix_proxy.htm
+++ b/doc/matrix_proxy.htm
@@ -26,7 +26,7 @@ addressing a row of a matrix.

matrix<double> m (3, 3); for (int i = 0; i < m.size1 (); ++ i) { matrix_row<matrix<double> > mr (m, i); - for (int j = 0; j < mr.size (); ++ j) + for (int j = 0; j < mr.size (); ++ j) mr (j) = 3 * i + j; std::cout << mr << std::endl; } @@ -208,7 +208,7 @@ href="expression.htm#vector_expression">Vector Expression.

template<class M> class matrix_row: public vector_expression<matrix_row<M> > { - public: + public: typedef const M const_matrix_type; typedef M matrix_type; typedef typename M::size_type size_type; @@ -2495,7 +2495,7 @@ href="expression.htm#matrix_expression">Matrix Expression.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator1 &operator = (const const_iterator1 &it); // Comparison @@ -2541,7 +2541,7 @@ href="expression.htm#matrix_expression">Matrix Expression.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator1 &operator = (const iterator1 &it); // Comparison @@ -2588,7 +2588,7 @@ href="expression.htm#matrix_expression">Matrix Expression.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator2 &operator = (const const_iterator2 &it); // Comparison @@ -2634,7 +2634,7 @@ href="expression.htm#matrix_expression">Matrix Expression.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator2 &operator = (const iterator2 &it); // Comparison @@ -2707,8 +2707,8 @@ construction of matrix slices.

int main () {
     using namespace boost::numeric::ublas;
     matrix<double> m (3, 3);
-    for (int i = 0; i < m.size1 (); ++ i) 
-        for (int j = 0; j < m.size2 (); ++ j) 
+    for (int i = 0; i < m.size1 (); ++ i)
+        for (int j = 0; j < m.size2 (); ++ j)
             project (m, slice (0, 1, 3), slice (0, 1, 3)) (i, j) = 3 * i + j;
     std::cout << project (m, slice (0, 1, 3), slice (0, 1, 3)) << std::endl;
 }
diff --git a/doc/matrix_sparse.htm b/doc/matrix_sparse.htm index ca05ce26..95b4df24 100644 --- a/doc/matrix_sparse.htm +++ b/doc/matrix_sparse.htm @@ -39,8 +39,8 @@ with column major orientation.

int main () {
     using namespace boost::numeric::ublas;
     sparse_matrix<double> m (3, 3, 3 * 3);
-    for (int i = 0; i < m.size1 (); ++ i) 
-        for (int j = 0; j < m.size2 (); ++ j) 
+    for (int i = 0; i < m.size1 (); ++ i)
+        for (int j = 0; j < m.size2 (); ++ j)
             m (i, j) = 3 * i + j;
     std::cout << m << std::endl;
 }
@@ -1729,7 +1729,7 @@ and std::vector<>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator1 &operator = (const const_iterator1 &it); // Comparison @@ -1772,7 +1772,7 @@ and std::vector<>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator1 &operator = (const iterator1 &it); // Comparison @@ -1816,7 +1816,7 @@ and std::vector<>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator2 &operator = (const const_iterator2 &it); // Comparison @@ -1859,7 +1859,7 @@ and std::vector<>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator2 &operator = (const iterator2 &it); // Comparison diff --git a/doc/storage.htm b/doc/storage.htm index 3b0fb33a..2367804b 100644 --- a/doc/storage.htm +++ b/doc/storage.htm @@ -182,10 +182,10 @@ Access Container.

Interface

-
    // Unbounded array 
+
    // Unbounded array
     template<class T>
     class unbounded_array {
-    public:      
+    public:
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
         typedef T value_type;
@@ -427,10 +427,10 @@ Access Container. 

Interface

-
    // Bounded array 
+
    // Bounded array
     template<class T, std::size_t N>
     class bounded_array {
-    public:      
+    public:
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
         typedef T value_type;
@@ -645,7 +645,7 @@ Reversible Container. 

// Index size_type index () const; - // Assignment + // Assignment const_iterator &operator = (const const_iterator &it); // Comparison @@ -828,7 +828,7 @@ Reversible Container.

// Index size_type index () const; - // Assignment + // Assignment const_iterator &operator = (const const_iterator &it); // Comparison @@ -848,10 +848,10 @@ Reversible Container.


-

Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
-Permission to copy, use, modify, sell and distribute this document is granted -provided this copyright notice appears in all copies. This document is provided -``as is'' without express or implied warranty, and with no claim as to its suitability +

Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
+Permission to copy, use, modify, sell and distribute this document is granted +provided this copyright notice appears in all copies. This document is provided +``as is'' without express or implied warranty, and with no claim as to its suitability for any purpose.

Last revised: 8/3/2002

diff --git a/doc/storage_sparse.htm b/doc/storage_sparse.htm index 15f80cf1..e4d6e6be 100644 --- a/doc/storage_sparse.htm +++ b/doc/storage_sparse.htm @@ -215,10 +215,10 @@ Reversible Container.

Interface

-
    // Map array 
+
    // Map array
     template<class I, class T>
     class map_array {
-    public:      
+    public:
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
         typedef I index_type;
@@ -298,10 +298,10 @@ Reversible Container.


-

Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
-Permission to copy, use, modify, sell and distribute this document is granted -provided this copyright notice appears in all copies. This document is provided -``as is'' without express or implied warranty, and with no claim as to its suitability +

Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
+Permission to copy, use, modify, sell and distribute this document is granted +provided this copyright notice appears in all copies. This document is provided +``as is'' without express or implied warranty, and with no claim as to its suitability for any purpose.

Last revised: 8/3/2002

diff --git a/doc/symmetric.htm b/doc/symmetric.htm index 8388194e..c78290bf 100644 --- a/doc/symmetric.htm +++ b/doc/symmetric.htm @@ -28,12 +28,12 @@ symmetric matrices is packed.

int main () {
     using namespace boost::numeric::ublas;
     symmetric_matrix<double, lower> ml (3, 3);
-    for (int i = 0; i < ml.size1 (); ++ i) 
+    for (int i = 0; i < ml.size1 (); ++ i)
         for (int j = 0; j <= i; ++ j)
             ml (i, j) = 3 * i + j;
     std::cout << ml << std::endl;
     symmetric_matrix<double, upper> mu (3, 3);
-    for (int i = 0; i < m.size1 (); ++ i) 
+    for (int i = 0; i < m.size1 (); ++ i)
         for (int j = i; j < m.size2 (); ++ j)
             mu (i, j) = 3 * i + j;
     std::cout << mu << std::endl;
@@ -332,11 +332,11 @@ and std::vector<T>. 

Interface

-
    // Array based symmetric matrix class 
+
    // Array based symmetric matrix class
     template<class T, class F1, class F2, class A>
-    class symmetric_matrix: 
+    class symmetric_matrix:
         public matrix_expression<symmetric_matrix<T, F1, F2, A> > {
-    public:      
+    public:
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
         typedef T value_type;
@@ -466,7 +466,7 @@ and std::vector<T>. 

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator1 &operator = (const const_iterator1 &it); // Comparison @@ -512,7 +512,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator1 &operator = (const iterator1 &it); // Comparison @@ -559,7 +559,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator2 &operator = (const const_iterator2 &it); // Comparison @@ -605,7 +605,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator2 &operator = (const iterator2 &it); // Comparison @@ -644,12 +644,12 @@ a symmetric matrix adaptor for other matrices.

using namespace boost::numeric::ublas; matrix<double> m (3, 3); symmetric_adaptor<matrix<double>, lower> sal (m); - for (int i = 0; i < sal.size1 (); ++ i) + for (int i = 0; i < sal.size1 (); ++ i) for (int j = 0; j <= i; ++ j) sal (i, j) = 3 * i + j; std::cout << sal << std::endl; symmetric_adaptor<matrix<double>, upper> sau (m); - for (int i = 0; i < sau.size1 (); ++ i) + for (int i = 0; i < sau.size1 (); ++ i) for (int j = i; j < sau.size2 (); ++ j) sau (i, j) = 3 * i + j; std::cout << sau << std::endl; @@ -909,11 +909,11 @@ for the type of the symmetric adaptor are lower and upperInterface -
    // Symmetric matrix adaptor class 
+
    // Symmetric matrix adaptor class
     template<class M, class F>
-    class symmetric_adaptor: 
+    class symmetric_adaptor:
         public matrix_expression<symmetric_adaptor<M, F> > {
-    public:      
+    public:
         typedef const M const_matrix_type;
         typedef M matrix_type;
         typedef F functor_type;
@@ -1030,7 +1030,7 @@ for the type of the symmetric adaptor are lower and upperlower and upperlower and upperlower and upper
 
int main () {
     using namespace boost::numeric::ublas;
     triangular_matrix<double, lower> ml (3, 3);
-    for (int i = 0; i < ml.size1 (); ++ i) 
+    for (int i = 0; i < ml.size1 (); ++ i)
         for (int j = 0; j <= i; ++ j)
             ml (i, j) = 3 * i + j;
     std::cout << ml << std::endl;
     triangular_matrix<double, upper> mu (3, 3);
-    for (int i = 0; i < m.size1 (); ++ i) 
+    for (int i = 0; i < m.size1 (); ++ i)
         for (int j = i; j < m.size2 (); ++ j)
             mu (i, j) = 3 * i + j;
     std::cout << mu << std::endl;
@@ -342,11 +342,11 @@ and std::vector<T>. 

Interface

-
    // Array based triangular matrix class 
+
    // Array based triangular matrix class
     template<class T, class F1, class F2, class A>
-    class triangular_matrix: 
+    class triangular_matrix:
         public matrix_expression<triangular_matrix<T, F1, F2, A> > {
-    public:      
+    public:
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
         typedef T value_type;
@@ -474,7 +474,7 @@ and std::vector<T>. 

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator1 &operator = (const const_iterator1 &it); // Comparison @@ -520,7 +520,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator1 &operator = (const iterator1 &it); // Comparison @@ -567,7 +567,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment const_iterator2 &operator = (const const_iterator2 &it); // Comparison @@ -613,7 +613,7 @@ and std::vector<T>.

size_type index1 () const; size_type index2 () const; - // Assignment + // Assignment iterator2 &operator = (const iterator2 &it); // Comparison @@ -652,12 +652,12 @@ a triangular matrix adaptor for other matrices.

using namespace boost::numeric::ublas; matrix<double> m (3, 3); triangular_adaptor<matrix<double>, lower> tal (m); - for (int i = 0; i < tal.size1 (); ++ i) + for (int i = 0; i < tal.size1 (); ++ i) for (int j = 0; j <= i; ++ j) tal (i, j) = 3 * i + j; std::cout << tal << std::endl; triangular_adaptor<matrix<double>, upper> tau (m); - for (int i = 0; i < tau.size1 (); ++ i) + for (int i = 0; i < tau.size1 (); ++ i) for (int j = i; j < tau.size2 (); ++ j) tau (i, j) = 3 * i + j; std::cout << tau << std::endl; @@ -918,11 +918,11 @@ for the type of the triangular adaptor are lower, unit_lower<

Interface

-
    // Triangular matrix adaptor class 
+
    // Triangular matrix adaptor class
     template<class M, class F>
-    class triangular_adaptor: 
+    class triangular_adaptor:
         public matrix_expression<triangular_adaptor<M, F> > {
-    public:      
+    public:
         typedef const M const_matrix_type;
         typedef M matrix_type;
         typedef F functor_type;
@@ -1039,7 +1039,7 @@ for the type of the triangular adaptor are lower, unit_lower<
             size_type index1 () const;
             size_type index2 () const;
 
-            // Assignment 
+            // Assignment
             const_iterator1 &operator = (const const_iterator1 &it);
 
             // Comparison
@@ -1085,7 +1085,7 @@ for the type of the triangular adaptor are lower, unit_lower<
             size_type index1 () const;
             size_type index2 () const;
 
-            // Assignment 
+            // Assignment
             iterator1 &operator = (const iterator1 &it);
 
             // Comparison
@@ -1132,7 +1132,7 @@ for the type of the triangular adaptor are lower, unit_lower<
             size_type index1 () const;
             size_type index2 () const;
 
-            // Assignment 
+            // Assignment
             const_iterator2 &operator = (const const_iterator2 &it);
 
             // Comparison
@@ -1178,7 +1178,7 @@ for the type of the triangular adaptor are lower, unit_lower<
             size_type index1 () const;
             size_type index2 () const;
 
-            // Assignment 
+            // Assignment
             iterator2 &operator = (const iterator2 &it);
 
             // Comparison
diff --git a/doc/vector.htm b/doc/vector.htm
index 7b5b1ce6..eab61f10 100644
--- a/doc/vector.htm
+++ b/doc/vector.htm
@@ -254,11 +254,11 @@ and std::vector<T>. 

Interface

-
    // Array based vector class 
+
    // Array based vector class
     template<class T, class A>
-    class vector: 
+    class vector:
         public vector_expression<vector<T, A> > {
-    public:      
+    public:
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
         typedef T value_type;
@@ -371,7 +371,7 @@ and std::vector<T>. 

// Index size_type index () const; - // Assignment + // Assignment const_iterator &operator = (const const_iterator &it); // Comparison @@ -568,11 +568,11 @@ href="expression.htm#vector_expression">Vector Expression.

Interface

-
    // Unit vector class 
+
    // Unit vector class
     template<class T>
-    class unit_vector: 
+    class unit_vector:
         public vector_expression<unit_vector<T> > {
-    public:      
+    public:
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
         typedef T value_type;
@@ -646,7 +646,7 @@ href="expression.htm#vector_expression">Vector Expression.

// Index size_type index () const; - // Assignment + // Assignment const_iterator &operator = (const const_iterator &it); // Comparison @@ -795,11 +795,11 @@ href="expression.htm#vector_expression">Vector Expression.

Interface

-
    // Zero vector class 
+
    // Zero vector class
     template<class T>
-    class zero_vector: 
+    class zero_vector:
         public vector_expression<zero_vector<T> > {
-    public:      
+    public:
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
         typedef T value_type;
@@ -870,7 +870,7 @@ href="expression.htm#vector_expression">Vector Expression.

// Index size_type index () const; - // Assignment + // Assignment const_iterator &operator = (const const_iterator &it); // Comparison diff --git a/doc/vector_expression.htm b/doc/vector_expression.htm index f0ea2571..93c6f14d 100644 --- a/doc/vector_expression.htm +++ b/doc/vector_expression.htm @@ -76,9 +76,9 @@ including class vector itself.

typedef E expression_type; typedef vector_tag type_category; - // This class could define an common interface for all + // This class could define an common interface for all // statically derived expression type classes. - // Due to a compiler deficiency - one can not reference class typedefs of E + // Due to a compiler deficiency - one can not reference class typedefs of E // on MSVC 6.0 (error C2027) - we only implement the casts. const expression_type &operator () () const; @@ -1507,7 +1507,7 @@ vector_expression<vector_binary_scalar2<E1, E2, F> >
resp.

resp.

template<class T1, class E2, class F> struct vector_binary_scalar1_traits { - typedef vector_binary_scalar1<scalar_const_reference<T1>, + typedef vector_binary_scalar1<scalar_const_reference<T1>, typename E2::const_closure_type, F> expression_type; - typedef expression_type result_type; + typedef expression_type result_type; }; // (t * v) [i] = t * v [i] template<class T1, class E2> typename vector_binary_scalar1_traits<T1, E2, scalar_multiplies<T1, typename E2::value_type> >::result_type - operator * (const T1 &e1, + operator * (const T1 &e1, const vector_expression<E2> &e2); template<class E1, class T2, class F> struct vector_binary_scalar2_traits { typedef vector_binary_scalar2<typename E1::const_closure_type, scalar_const_reference<T2>, F> expression_type; - typedef expression_type result_type; + typedef expression_type result_type; }; // (v * t) [i] = v [i] * t template<class E1, class T2> typename vector_binary_scalar2_traits<E1, T2, scalar_multiplies<typename E1::value_type, T2> >::result_type - operator * (const vector_expression<E1> &e1, + operator * (const vector_expression<E1> &e1, const T2 &e2); // (v / t) [i] = v [i] / t template<class E1, class T2> typename vector_binary_scalar2_traits<E1, T2, scalar_divides<typename E1::value_type, T2> >::result_type - operator / (const vector_expression<E1> &e1, + operator / (const vector_expression<E1> &e1, const T2 &e2);

Description

@@ -1594,7 +1594,7 @@ with the reciprocal of the scalar.

int main () {
     using namespace boost::numeric::ublas;
     vector<double> v (3);
-    for (int i = 0; i < v.size (); ++ i) 
+    for (int i = 0; i < v.size (); ++ i)
         v (i) = i;
 
     std::cout << 2.0 * v << std::endl;
@@ -1670,7 +1670,7 @@ first element having maximal absolute value.

int main () {
     using namespace boost::numeric::ublas;
     vector<double> v (3);
-    for (int i = 0; i < v.size (); ++ i) 
+    for (int i = 0; i < v.size (); ++ i)
         v (i) = i;
 
     std::cout << sum (v) << std::endl;
@@ -1691,19 +1691,19 @@ first element having maximal absolute value.

// inner_prod (v1, v2) = sum (v1 [i] * v2 [i] template<class E1, class E2> - typename vector_scalar_binary_traits<E1, E2, vector_inner_prod<typename E1::value_type, + typename vector_scalar_binary_traits<E1, E2, vector_inner_prod<typename E1::value_type, typename E2::value_type, - typename promote_traits<typename E1::value_type, - typename E2::value_type>::promote_type> >::result_type - inner_prod (const vector_expression<E1> &e1, + typename promote_traits<typename E1::value_type, + typename E2::value_type>::promote_type> >::result_type + inner_prod (const vector_expression<E1> &e1, const vector_expression<E2> &e2); template<class E1, class E2> - typename vector_scalar_binary_traits<E1, E2, vector_inner_prod<typename E1::value_type, + typename vector_scalar_binary_traits<E1, E2, vector_inner_prod<typename E1::value_type, typename E2::value_type, - typename type_traits<typename promote_traits<typename E1::value_type, - typename E2::value_type>::promote_type>::precision_type> >::result_type - prec_inner_prod (const vector_expression<E1> &e1, + typename type_traits<typename promote_traits<typename E1::value_type, + typename E2::value_type>::promote_type>::precision_type> >::result_type + prec_inner_prod (const vector_expression<E1> &e1, const vector_expression<E2> &e2);

Description

@@ -1740,7 +1740,7 @@ double precision inner product of the vector expressions.

int main () {
     using namespace boost::numeric::ublas;
     vector<double> v1 (3), v2 (3);
-    for (int i = 0; i < std::min (v1.size (), v2.size ()); ++ i) 
+    for (int i = 0; i < std::min (v1.size (), v2.size ()); ++ i)
         v1 (i) = v2 (i) = i;
 
     std::cout << inner_prod (v1, v2) << std::endl;
@@ -1748,10 +1748,10 @@ double precision inner product of the vector expressions.


-

Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
-Permission to copy, use, modify, sell and distribute this document is granted -provided this copyright notice appears in all copies. This document is provided -``as is'' without express or implied warranty, and with no claim as to its suitability +

Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
+Permission to copy, use, modify, sell and distribute this document is granted +provided this copyright notice appears in all copies. This document is provided +``as is'' without express or implied warranty, and with no claim as to its suitability for any purpose.

Last revised: 8/3/2002

diff --git a/doc/vector_proxy.htm b/doc/vector_proxy.htm index bb146b91..f61fed0a 100644 --- a/doc/vector_proxy.htm +++ b/doc/vector_proxy.htm @@ -220,7 +220,7 @@ href="expression.htm#vector_expression">Vector Expression.

template<class V> class vector_range: public vector_expression<vector_range<V> > { - public: + public: typedef const V const_vector_type; typedef V vector_type; typedef typename V::size_type size_type; @@ -238,12 +238,12 @@ href="expression.htm#vector_expression">Vector Expression.

dense_proxy_tag>::storage_category storage_category; // Construction and destruction - vector_range (); - vector_range (vector_type &data, const range &r); + vector_range (); + vector_range (vector_type &data, const range &r); // Accessors - size_type start () const; - size_type size () const; + size_type start () const; + size_type size () const; const_vector_type &data () const; vector_type &data (); @@ -320,7 +320,7 @@ href="expression.htm#vector_expression">Vector Expression.

// Index size_type index () const; - // Assignment + // Assignment const_iterator &operator = (const const_iterator &it); // Comparison @@ -358,7 +358,7 @@ href="expression.htm#vector_expression">Vector Expression.

// Index size_type index () const; - // Assignment + // Assignment iterator &operator = (const iterator &it); // Comparison @@ -442,7 +442,7 @@ addressing a slice of a vector.

using namespace boost::numeric::ublas; vector<double> v (3); vector_slice<vector<double> > vs (v, slice (0, 1, 3)); - for (int i = 0; i < vs.size (); ++ i) + for (int i = 0; i < vs.size (); ++ i) vs (i) = i; std::cout << vs << std::endl; }
@@ -633,7 +633,7 @@ href="expression.htm#vector_expression">Vector Expression.

template<class V> class vector_slice: public vector_expression<vector_slice<V> > { - public: + public: typedef const V const_vector_type; typedef V vector_type; typedef typename V::size_type size_type; @@ -735,7 +735,7 @@ href="expression.htm#vector_expression">Vector Expression.

// Index size_type index () const; - // Assignment + // Assignment const_iterator &operator = (const const_iterator &it); // Comparison @@ -773,7 +773,7 @@ href="expression.htm#vector_expression">Vector Expression.

// Index size_type index () const; - // Assignment + // Assignment iterator &operator = (const iterator &it); // Comparison diff --git a/doc/vector_sparse.htm b/doc/vector_sparse.htm index ceed0dbb..1537493f 100644 --- a/doc/vector_sparse.htm +++ b/doc/vector_sparse.htm @@ -31,7 +31,7 @@ elements of the associative container, i.e. for elements k
int main () {
     using namespace boost::numeric::ublas;
     sparse_vector<double> v (3, 3);
-    for (int i = 0; i < v.size (); ++ i) 
+    for (int i = 0; i < v.size (); ++ i)
         v (i) = i;
     std::cout << v << std::endl;
 }
@@ -268,11 +268,11 @@ and std::map<std::size_t, T>.

Interface

-
    // Array based sparse vector class 
+
    // Array based sparse vector class
     template<class T, class A>
-    class sparse_vector: 
+    class sparse_vector:
         public vector_expression<sparse_vector<T, A> > {
-    public:      
+    public:
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
         typedef T value_type;
@@ -291,7 +291,7 @@ and std::map<std::size_t, T>. 

typedef sparse_tag storage_category; // Construction and destruction - sparse_vector (); + sparse_vector (); sparse_vector (size_type size, size_type non_zeros = 0); sparse_vector (const sparse_vector &v); template<class AE> @@ -458,7 +458,7 @@ container, i.e. for elements k = viint main () { using namespace boost::numeric::ublas; compressed_vector<double> v (3, 3); - for (int i = 0; i < v.size (); ++ i) + for (int i = 0; i < v.size (); ++ i) v (i) = i; std::cout << v << std::endl; }
@@ -714,11 +714,11 @@ and std::vector<>.

Interface

-
    // Array based sparse vector class 
+
    // Array based sparse vector class
     template<class T, std::size_t IB, class IA, class TA>
-    class compressed_vector: 
+    class compressed_vector:
         public vector_expression<compressed_vector<T, IB, IA, TA> > {
-    public:      
+    public:
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
         typedef T value_type;
@@ -737,7 +737,7 @@ and std::vector<>. 

typedef sparse_tag storage_category; // Construction and destruction - compressed_vector (); + compressed_vector (); compressed_vector (size_type size, size_type non_zeros = 0); compressed_vector (const compressed_vector &v); template<class AE> @@ -907,7 +907,7 @@ container, i.e. for elements k = viint main () { using namespace boost::numeric::ublas; coordinate_vector<double> v (3, 3); - for (int i = 0; i < v.size (); ++ i) + for (int i = 0; i < v.size (); ++ i) v (i) = i; std::cout << v << std::endl; }
@@ -1163,11 +1163,11 @@ and std::vector<>.

Interface

-
    // Array based sparse vector class 
+
    // Array based sparse vector class
     template<class T, std::size_t IB, class IA, class TA>
-    class coordinate_vector: 
+    class coordinate_vector:
         public vector_expression<coordinate_vector<T, IB, IA, TA> > {
-    public:      
+    public:
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
         typedef T value_type;
@@ -1186,7 +1186,7 @@ and std::vector<>. 

typedef sparse_tag storage_category; // Construction and destruction - coordinate_vector (); + coordinate_vector (); coordinate_vector (size_type size, size_type non_zeros = 0); coordinate_vector (const coordinate_vector &v); template<class AE> diff --git a/include/boost/numeric/ublas/banded.hpp b/include/boost/numeric/ublas/banded.hpp index f48c292e..9c2e3219 100644 --- a/include/boost/numeric/ublas/banded.hpp +++ b/include/boost/numeric/ublas/banded.hpp @@ -171,7 +171,7 @@ namespace boost { namespace numeric { namespace ublas { // Assignment BOOST_UBLAS_INLINE - banded_matrix &operator = (const banded_matrix &m) { + banded_matrix &operator = (const banded_matrix &m) { BOOST_UBLAS_CHECK (size1_ == m.size1_, bad_size ()); BOOST_UBLAS_CHECK (size2_ == m.size2_, bad_size ()); BOOST_UBLAS_CHECK (lower_ == m.lower_, bad_size ()); @@ -184,13 +184,13 @@ namespace boost { namespace numeric { namespace ublas { return *this; } BOOST_UBLAS_INLINE - banded_matrix &assign_temporary (banded_matrix &m) { + banded_matrix &assign_temporary (banded_matrix &m) { swap (m); return *this; } template BOOST_UBLAS_INLINE - banded_matrix &operator = (const matrix_expression &ae) { + banded_matrix &operator = (const matrix_expression &ae) { #ifdef BOOST_UBLAS_MUTABLE_TEMPORARY return assign_temporary (self_type (ae, lower_, upper_)); #else @@ -277,7 +277,7 @@ namespace boost { namespace numeric { namespace ublas { data ().swap (m.data ()); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (banded_matrix &m1, banded_matrix &m2) { m1.swap (m2); @@ -531,7 +531,7 @@ namespace boost { namespace numeric { namespace ublas { return it2_; } - // Assignment + // Assignment BOOST_UBLAS_INLINE const_iterator1 &operator = (const const_iterator1 &it) { container_const_reference::assign (&it ()); @@ -654,7 +654,7 @@ namespace boost { namespace numeric { namespace ublas { return it2_; } - // Assignment + // Assignment BOOST_UBLAS_INLINE iterator1 &operator = (const iterator1 &it) { container_reference::assign (&it ()); @@ -1248,7 +1248,7 @@ namespace boost { namespace numeric { namespace ublas { matrix_swap (scalar_swap (), *this, m); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (banded_adaptor &m1, banded_adaptor &m2) { m1.swap (m2); diff --git a/include/boost/numeric/ublas/blas.hpp b/include/boost/numeric/ublas/blas.hpp index 910849a3..65e7195e 100644 --- a/include/boost/numeric/ublas/blas.hpp +++ b/include/boost/numeric/ublas/blas.hpp @@ -22,29 +22,29 @@ namespace boost { namespace numeric { namespace ublas { namespace blas_1 { template - typename type_traits::real_type + typename type_traits::real_type asum (const V &v) { return norm_1 (v); } template - typename type_traits::real_type + typename type_traits::real_type nrm2 (const V &v) { return norm_2 (v); } template - typename type_traits::real_type + typename type_traits::real_type amax (const V &v) { return norm_inf (v); } template - typename promote_traits::promote_type + typename promote_traits::promote_type dot (const V1 &v1, const V2 &v2) { return inner_prod (v1, v2); } template - V1 & + V1 & copy (V1 &v1, const V2 &v2) { return v1.assign (v2); } @@ -67,7 +67,7 @@ namespace boost { namespace numeric { namespace ublas { } template - void + void rot (const T1 &t1, V1 &v1, const T2 &t2, V2 &v2) { typedef typename promote_traits::promote_type promote_type; vector vt (t1 * v1 + t2 * v2); @@ -102,9 +102,9 @@ namespace boost { namespace numeric { namespace ublas { gr (M &m, const T &t, const V1 &v1, const V2 &v2) { #ifdef BOOST_UBLAS_USE_ET return m += t * outer_prod (v1, v2); -#else +#else return m = m + t * outer_prod (v1, v2); -#endif +#endif } template @@ -112,18 +112,18 @@ namespace boost { namespace numeric { namespace ublas { sr (M &m, const T &t, const V &v) { #ifdef BOOST_UBLAS_USE_ET return m += t * outer_prod (v, v); -#else +#else return m = m + t * outer_prod (v, v); -#endif +#endif } template M & hr (M &m, const T &t, const V &v) { #ifdef BOOST_UBLAS_USE_ET return m += t * outer_prod (v, conj (v)); -#else +#else return m = m + t * outer_prod (v, conj (v)); -#endif +#endif } template @@ -131,9 +131,9 @@ namespace boost { namespace numeric { namespace ublas { sr2 (M &m, const T &t, const V1 &v1, const V2 &v2) { #ifdef BOOST_UBLAS_USE_ET return m += t * (outer_prod (v1, v2) + outer_prod (v2, v1)); -#else +#else return m = m + t * (outer_prod (v1, v2) + outer_prod (v2, v1)); -#endif +#endif } template M & @@ -142,7 +142,7 @@ namespace boost { namespace numeric { namespace ublas { return m += t * outer_prod (v1, conj (v2)) + type_traits::conj (t) * outer_prod (v2, conj (v1)); #else return m = m + t * outer_prod (v1, conj (v2)) + type_traits::conj (t) * outer_prod (v2, conj (v1)); -#endif +#endif } } diff --git a/include/boost/numeric/ublas/config.hpp b/include/boost/numeric/ublas/config.hpp index 1940ebd1..51289d04 100644 --- a/include/boost/numeric/ublas/config.hpp +++ b/include/boost/numeric/ublas/config.hpp @@ -27,19 +27,52 @@ #include #include - - // Compiler specific problems -#ifdef BOOST_MSVC +#if defined (BOOST_STRICT_CONFIG) || ! (\ + defined (BOOST_MSVC) || \ + defined (__GNUC__) || \ + defined (__BORLANDC__) || \ + defined (_ICL) || \ + defined (_ICC) || \ + defined (__COMO__)) + +#define BOOST_UBLAS_TYPENAME typename +#define BOOST_UBLAS_USING using +// This could be eliminated. +#define BOOST_UBLAS_EXPLICIT explicit + +#define BOOST_UBLAS_USE_LONG_DOUBLE + +#define BOOST_UBLAS_USE_STREAM + +#endif + + + +// Microsoft Visual C++ +#if defined (BOOST_MSVC) && ! (BOOST_MSVC > 1300 && defined (BOOST_STRICT_CONFIG)) // Disable some MSVC specific warnings. #pragma warning (disable: 4355) #pragma warning (disable: 4503) #pragma warning (disable: 4786) -// Open problems: -// MSVC allows to implement free function as friends. -#define BOOST_UBLAS_FRIEND_FUNCTION +// MSVC doesn't always accept the 'typename' keyword. +#define BOOST_UBLAS_TYPENAME +// MSVC doesn't accept the 'using' keyword (at least for importing base members). +#define BOOST_UBLAS_USING +#define BOOST_UBLAS_EXPLICIT explicit + +// #ifdef BOOST_MSVC +// With MSVC we could perform IO via basic_stream +// #define BOOST_UBLAS_USE_BASIC_STREAM +// #else +// IO via streams +#define BOOST_UBLAS_USE_STREAM +// #endif + +#define BOOST_UBLAS_NO_ELEMENT_PROXIES +#define BOOST_UBLAS_NO_SMART_PROXIES // Using MSVC the following is missing: // namespace std { @@ -70,15 +103,13 @@ -#ifdef __GNUC__ +// GNU Compiler Collection +#if defined (__GNUC__) && ! defined (BOOST_STRICT_CONFIG) + +#define BOOST_UBLAS_TYPENAME typename +#define BOOST_UBLAS_USING using +#define BOOST_UBLAS_EXPLICIT explicit -// Open problems: -// GCC 2.95.3 is known not to accept BOOST_UBLAS_FRIEND_FUNCTION (this seems to be arguable). -// GCC 3.x.x allows to implement free function as friends. -#if !(__GNUC__ <= 2 && __GNUC_MINOR__ <= 95) -#define BOOST_UBLAS_FRIEND_FUNCTION -#endif -// GCC 2.95.3 is known not to accept BOOST_UBLAS_MUTABLE_TEMPORARY (this seems to be correct). // GCC 2.95.3 allows to use iterator_base_traits. #define BOOST_UBLAS_USE_ITERATOR_BASE_TRAITS // GCC 2.95.3 needs BOOST_UBLAS_REVERSE_ITERATOR_OVERLOADS (this seems to be arguable). @@ -86,19 +117,29 @@ #define BOOST_UBLAS_USE_LONG_DOUBLE +#define BOOST_UBLAS_USE_STREAM + #endif -#ifdef __BORLANDC__ +// Borland Compiler +#if defined (__BORLANDC__) && ! defined (BOOST_STRICT_CONFIG) -// Open problems: -// BCC allows to implement free function as friends. -#define BOOST_UBLAS_FRIEND_FUNCTION +#define BOOST_UBLAS_TYPENAME typename +#define BOOST_UBLAS_USING using +#define BOOST_UBLAS_EXPLICIT explicit + +#define BOOST_UBLAS_USE_LONG_DOUBLE + +#define BOOST_UBLAS_USE_STREAM + +#define BOOST_UBLAS_NO_ELEMENT_PROXIES +#define BOOST_UBLAS_NO_SMART_PROXIES // BCC's broken. // Thanks to John Maddock for providing a workaround. -#if defined(_STLPORT_VERSION) && defined(_STLP_USE_OWN_NAMESPACE) && ! defined(std) +#if defined(_STLPORT_VERSION) && defined(_STLP_USE_OWN_NAMESPACE) && !defined(std) #include namespace std { using stlport::abs; @@ -111,68 +152,55 @@ namespace std { // Thanks to Roberto Andres Ruiz Vial for porting to Intel. -#ifdef __ICL +#if defined (__ICL) && ! defined (BOOST_STRICT_CONFIG) -// Maybe BOOST_MSVC is set when using ICL with MSVC? #define BOOST_UBLAS_TYPENAME typename - -// Open problems: +#define BOOST_UBLAS_USING using +#define BOOST_UBLAS_EXPLICIT explicit #define BOOST_UBLAS_USE_LONG_DOUBLE +#define BOOST_UBLAS_USE_STREAM + #endif -#ifdef __ICC +// Intel Compiler under Linux +#if defined (__ICC) && ! defined (BOOST_STRICT_CONFIG) + +#define BOOST_UBLAS_TYPENAME typename +#define BOOST_UBLAS_USING using +#define BOOST_UBLAS_EXPLICIT explicit -// Open problems: -// ICC allows to implement free function as friends. -#define BOOST_UBLAS_FRIEND_FUNCTION // ICC sometimes needs qualified type names. #define BOOST_UBLAS_QUALIFIED_TYPENAME +#define BOOST_UBLAS_USE_LONG_DOUBLE + +#define BOOST_UBLAS_USE_STREAM + #endif // Thanks to Kresimir Fresl for porting to Comeau. -#ifdef __COMO__ +#if defined (__COMO__) && ! defined (BOOST_STRICT_CONFIG) + +#define BOOST_UBLAS_TYPENAME typename +#define BOOST_UBLAS_USING using +#define BOOST_UBLAS_EXPLICIT explicit -// Comeau 4.2.45 seems to have problems with BOOST_UBLAS_FRIEND_FUNCTION (this seems to be arguable). -#if (__COMO_VERSION__ >= 4300) -#define BOOST_UBLAS_FRIEND_FUNCTION -#endif // Comeau allows to use iterator_base_traits. #define BOOST_UBLAS_USE_ITERATOR_BASE_TRAITS #define BOOST_UBLAS_USE_LONG_DOUBLE -#endif - - - -#ifdef BOOST_MSVC -// MSVC doesn't always accept the 'typename' keyword. -#define BOOST_UBLAS_TYPENAME -// MSVC doesn't accept the 'using' keyword (at least for importing base members). -#define BOOST_UBLAS_USING -#else -#define BOOST_UBLAS_TYPENAME typename -#define BOOST_UBLAS_USING using -#endif -// This could be eliminated. -#define BOOST_UBLAS_EXPLICIT explicit - - - -// #ifdef BOOST_MSVC -// With MSVC we could perform IO via basic_stream -// #define BOOST_UBLAS_USE_BASIC_STREAM -// #else -// IO via streams #define BOOST_UBLAS_USE_STREAM -// #endif + +#endif + + // Enable assignment of non conformant proxies // Thanks to Michael Stevens for spotting this. @@ -181,7 +209,7 @@ namespace std { // Enable different sparse element proxies // These fix a [1] = a [0] = 1, but probably won't work on broken compilers. // Thanks to Marc Duflot for spotting this. -#if ! defined (BOOST_MSVC) && ! defined (__BORLANDC__) +#ifndef BOOST_UBLAS_NO_ELEMENT_PROXIES // #define BOOST_UBLAS_STRICT_STORAGE_SPARSE #define BOOST_UBLAS_STRICT_VECTOR_SPARSE #define BOOST_UBLAS_STRICT_MATRIX_SPARSE @@ -189,16 +217,15 @@ namespace std { #endif // Enable compile time typedefs for proxies -#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -// Doesn't work under Borland -#ifndef __BORLANDC__ +#ifndef BOOST_UBLAS_NO_SMART_PROXIES #define BOOST_UBLAS_CT_REFERENCE_BASE_TYPEDEFS // #define BOOST_UBLAS_REFERENCE_CONST_MEMBER #define BOOST_UBLAS_CT_PROXY_BASE_TYPEDEFS // #define BOOST_UBLAS_PROXY_CONST_MEMBER #define BOOST_UBLAS_CT_PROXY_CLOSURE_TYPEDEFS #endif -#endif + + // Enable performance options in release mode #ifdef NDEBUG @@ -243,6 +270,10 @@ namespace std { #endif +#ifdef BOOST_UBLAS_BOUNDS_CHECK +static bool disable_type_check = false; +#endif + // Use invariant hoisting. diff --git a/include/boost/numeric/ublas/hermitian.hpp b/include/boost/numeric/ublas/hermitian.hpp index 81f507dc..1ea21765 100644 --- a/include/boost/numeric/ublas/hermitian.hpp +++ b/include/boost/numeric/ublas/hermitian.hpp @@ -417,7 +417,7 @@ namespace boost { namespace numeric { namespace ublas { data ().swap (m.data ()); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (hermitian_matrix &m1, hermitian_matrix &m2) { m1.swap (m2); @@ -1371,7 +1371,7 @@ namespace boost { namespace numeric { namespace ublas { if (this != &m) matrix_swap (scalar_swap (), *this, m); } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (hermitian_adaptor &m1, hermitian_adaptor &m2) { m1.swap (m2); diff --git a/include/boost/numeric/ublas/io.hpp b/include/boost/numeric/ublas/io.hpp index 2079584d..4fb1ffdf 100644 --- a/include/boost/numeric/ublas/io.hpp +++ b/include/boost/numeric/ublas/io.hpp @@ -39,16 +39,16 @@ namespace boost { namespace numeric { namespace ublas { s << '[' << size << "]("; if (size > 0) s << v () (0); - for (std::size_t i = 1; i < size; ++ i) + for (std::size_t i = 1; i < size; ++ i) s << ',' << v () (i); s << ')'; - return os << s.str ().c_str (); + return os << s.str ().c_str (); } - template + template // This function seems to be big. So we do not let the compiler inline it. // BOOST_UBLAS_INLINE - std::basic_ostream &operator << (std::basic_ostream &os, + std::basic_ostream &operator << (std::basic_ostream &os, const vector &v) { std::size_t size = v.size (); std::basic_ostringstream > s; @@ -58,16 +58,16 @@ namespace boost { namespace numeric { namespace ublas { s << '[' << size << "]("; if (size > 0) s << v (0); - for (std::size_t i = 1; i < size; ++ i) + for (std::size_t i = 1; i < size; ++ i) s << ',' << v (i); s << ')'; - return os << s.str ().c_str (); + return os << s.str ().c_str (); } - template + template // This function seems to be big. So we do not let the compiler inline it. // BOOST_UBLAS_INLINE - std::basic_istream &operator >> (std::basic_istream &is, + std::basic_istream &operator >> (std::basic_istream &is, vector &v) { E ch; std::size_t size; @@ -104,10 +104,10 @@ namespace boost { namespace numeric { namespace ublas { return is; } - template + template // This function seems to be big. So we do not let the compiler inline it. // BOOST_UBLAS_INLINE - std::basic_ostream &operator << (std::basic_ostream &os, + std::basic_ostream &operator << (std::basic_ostream &os, const matrix_expression &m) { std::size_t size1 = m ().size1 (); std::size_t size2 = m ().size2 (); @@ -118,9 +118,9 @@ namespace boost { namespace numeric { namespace ublas { s << '[' << size1 << ',' << size2 << "]("; if (size1 > 0) { s << '(' ; - if (size2 > 0) + if (size2 > 0) s << m () (0, 0); - for (std::size_t j = 1; j < size2; ++ j) + for (std::size_t j = 1; j < size2; ++ j) s << ',' << m () (0, j); s << ')'; } @@ -133,13 +133,13 @@ namespace boost { namespace numeric { namespace ublas { s << ')'; } s << ')'; - return os << s.str ().c_str (); + return os << s.str ().c_str (); } - template + template // This function seems to be big. So we do not let the compiler inline it. // BOOST_UBLAS_INLINE - std::basic_ostream &operator << (std::basic_ostream &os, + std::basic_ostream &operator << (std::basic_ostream &os, const matrix &m) { std::size_t size1 = m.size1 (); std::size_t size2 = m.size2 (); @@ -150,28 +150,28 @@ namespace boost { namespace numeric { namespace ublas { s << '[' << size1 << ',' << size2 << "]("; if (size1 > 0) { s << '(' ; - if (size2 > 0) + if (size2 > 0) s << m (0, 0); - for (std::size_t j = 1; j < size2; ++ j) + for (std::size_t j = 1; j < size2; ++ j) s << ',' << m (0, j); s << ')'; } for (std::size_t i = 1; i < size1; ++ i) { s << ",(" ; - if (size2 > 0) + if (size2 > 0) s << m (i, 0); - for (std::size_t j = 1; j < size2; ++ j) + for (std::size_t j = 1; j < size2; ++ j) s << ',' << m (i, j); s << ')'; } s << ')'; - return os << s.str ().c_str (); + return os << s.str ().c_str (); } - template + template // This function seems to be big. So we do not let the compiler inline it. // BOOST_UBLAS_INLINE - std::basic_istream &operator >> (std::basic_istream &is, + std::basic_istream &operator >> (std::basic_istream &is, matrix &m) { E ch; std::size_t size1, size2; @@ -209,7 +209,7 @@ namespace boost { namespace numeric { namespace ublas { is.putback (ch); is.setstate (std::ios_base::failbit); break; - } + } if (is >> ch && ch != ',') { is.putback (ch); if (i < size1 - 1) { @@ -221,7 +221,7 @@ namespace boost { namespace numeric { namespace ublas { if (is >> ch && ch != ')') { is.putback (ch); is.setstate (std::ios_base::failbit); - } + } } if (! is.fail ()) { m.resize (size1, size2); @@ -238,37 +238,37 @@ namespace boost { namespace numeric { namespace ublas { template // This function seems to be big. So we do not let the compiler inline it. // BOOST_UBLAS_INLINE - std::ostream &operator << (std::ostream &os, + std::ostream &operator << (std::ostream &os, const vector_expression &v) { std::size_t size = v ().size (); os << '[' << size << "]("; if (size > 0) os << v () (0); - for (std::size_t i = 1; i < size; ++ i) + for (std::size_t i = 1; i < size; ++ i) os << ',' << v () (i); os << ')'; - return os; + return os; } - template + template // This function seems to be big. So we do not let the compiler inline it. // BOOST_UBLAS_INLINE - std::ostream &operator << (std::ostream &os, + std::ostream &operator << (std::ostream &os, const vector &v) { std::size_t size = v.size (); os << '[' << size << "]("; if (size > 0) os << v (0); - for (std::size_t i = 1; i < size; ++ i) + for (std::size_t i = 1; i < size; ++ i) os << ',' << v (i); os << ')'; - return os; + return os; } - template + template // This function seems to be big. So we do not let the compiler inline it. // BOOST_UBLAS_INLINE - std::istream &operator >> (std::istream &is, + std::istream &operator >> (std::istream &is, vector &v) { char ch; std::size_t size; @@ -302,38 +302,38 @@ namespace boost { namespace numeric { namespace ublas { v = s; } } - return is; + return is; } - template + template // This function seems to be big. So we do not let the compiler inline it. // BOOST_UBLAS_INLINE - std::ostream &operator << (std::ostream &os, + std::ostream &operator << (std::ostream &os, const matrix_expression &m) { std::size_t size1 = m ().size1 (); std::size_t size2 = m ().size2 (); os << '[' << size1 << ',' << size2 << "]("; if (size1 > 0) { os << '(' ; - if (size2 > 0) + if (size2 > 0) os << m () (0, 0); - for (std::size_t j = 1; j < size2; ++ j) + for (std::size_t j = 1; j < size2; ++ j) os << ',' << m () (0, j); os << ')'; } for (std::size_t i = 1; i < size1; ++ i) { os << ",(" ; - if (size2 > 0) + if (size2 > 0) os << m () (i, 0); - for (std::size_t j = 1; j < size2; ++ j) + for (std::size_t j = 1; j < size2; ++ j) os << ',' << m () (i, j); os << ')'; } os << ')'; - return os; + return os; } - template + template // This function seems to be big. So we do not let the compiler inline it. // BOOST_UBLAS_INLINE std::ostream &operator << (std::ostream &os, @@ -343,9 +343,9 @@ namespace boost { namespace numeric { namespace ublas { os << '[' << size1 << ',' << size2 << "]("; if (size1 > 0) { os << '(' ; - if (size2 > 0) + if (size2 > 0) os << m (0, 0); - for (std::size_t j = 1; j < size2; ++ j) + for (std::size_t j = 1; j < size2; ++ j) os << ',' << m (0, j); os << ')'; } @@ -353,18 +353,18 @@ namespace boost { namespace numeric { namespace ublas { os << ",(" ; if (size2 > 0) os << m (i, 0); - for (std::size_t j = 1; j < size2; ++ j) + for (std::size_t j = 1; j < size2; ++ j) os << ',' << m (i, j); os << ')'; } os << ')'; - return os; + return os; } - template + template // This function seems to be big. So we do not let the compiler inline it. // BOOST_UBLAS_INLINE - std::istream &operator >> (std::istream &is, + std::istream &operator >> (std::istream &is, matrix &m) { char ch; std::size_t size1, size2; @@ -402,7 +402,7 @@ namespace boost { namespace numeric { namespace ublas { is.putback (ch); is.setstate (std::ios::failbit); break; - } + } if (is >> ch && ch != ',') { is.putback (ch); if (i < size1 - 1) { @@ -414,17 +414,17 @@ namespace boost { namespace numeric { namespace ublas { if (is >> ch && ch != ')') { is.putback (ch); is.setstate (std::ios::failbit); - } + } } if (! is.fail ()) { m.resize (size1, size2); m = s; } } - return is; + return is; } -#endif +#endif }}} diff --git a/include/boost/numeric/ublas/iterator.hpp b/include/boost/numeric/ublas/iterator.hpp index e762072c..7268a679 100644 --- a/include/boost/numeric/ublas/iterator.hpp +++ b/include/boost/numeric/ublas/iterator.hpp @@ -131,7 +131,7 @@ namespace boost { namespace numeric { namespace ublas { ++ d; return tmp; } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend derived_iterator_type operator ++ (derived_iterator_type &d, int) { derived_iterator_type tmp (d); @@ -148,7 +148,7 @@ namespace boost { namespace numeric { namespace ublas { } }; -#ifndef BOOST_UBLAS_FRIEND_FUNCTION +#ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS template BOOST_UBLAS_INLINE typename forward_iterator_base::derived_iterator_type operator ++ (forward_iterator_base &it, int) { @@ -174,7 +174,7 @@ namespace boost { namespace numeric { namespace ublas { ++ d; return tmp; } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend derived_iterator_type operator ++ (derived_iterator_type &d, int) { derived_iterator_type tmp (d); @@ -189,7 +189,7 @@ namespace boost { namespace numeric { namespace ublas { -- d; return tmp; } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend derived_iterator_type operator -- (derived_iterator_type &d, int) { derived_iterator_type tmp (d); @@ -206,7 +206,7 @@ namespace boost { namespace numeric { namespace ublas { } }; -#ifndef BOOST_UBLAS_FRIEND_FUNCTION +#ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS template BOOST_UBLAS_INLINE typename bidirectional_iterator_base::derived_iterator_type operator ++ (bidirectional_iterator_base &it, int) { @@ -245,7 +245,7 @@ namespace boost { namespace numeric { namespace ublas { ++ d; return tmp; } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend derived_iterator_type operator ++ (derived_iterator_type &d, int) { derived_iterator_type tmp (d); @@ -260,7 +260,7 @@ namespace boost { namespace numeric { namespace ublas { -- d; return tmp; } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend derived_iterator_type operator -- (derived_iterator_type &d, int) { derived_iterator_type tmp (d); @@ -273,7 +273,7 @@ namespace boost { namespace numeric { namespace ublas { derived_iterator_type tmp (*static_cast (this)); return tmp += n; } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend derived_iterator_type operator + (const derived_iterator_type &d, derived_difference_type n) { derived_iterator_type tmp (d); @@ -285,7 +285,7 @@ namespace boost { namespace numeric { namespace ublas { derived_iterator_type tmp (*static_cast (this)); return tmp -= n; } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend derived_iterator_type operator - (const derived_iterator_type &d, derived_difference_type n) { derived_iterator_type tmp (d); @@ -316,7 +316,7 @@ namespace boost { namespace numeric { namespace ublas { } }; -#ifndef BOOST_UBLAS_FRIEND_FUNCTION +#ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS template BOOST_UBLAS_INLINE typename random_access_iterator_base::derived_iterator_type operator ++ (random_access_iterator_base &it, int) { @@ -723,7 +723,7 @@ namespace boost { namespace numeric { namespace ublas { } #endif -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend reverse_iterator_base operator + (const reverse_iterator_base &it, difference_type n) { reverse_iterator_base tmp (it); @@ -754,7 +754,7 @@ namespace boost { namespace numeric { namespace ublas { } }; -#ifndef BOOST_UBLAS_FRIEND_FUNCTION +#ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS template BOOST_UBLAS_INLINE reverse_iterator_base operator + (const reverse_iterator_base &it, std::ptrdiff_t n) { @@ -834,7 +834,7 @@ namespace boost { namespace numeric { namespace ublas { } #endif -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend reverse_iterator_base1 operator + (const reverse_iterator_base1 &it, difference_type n) { reverse_iterator_base1 tmp (it); @@ -892,7 +892,7 @@ namespace boost { namespace numeric { namespace ublas { } }; -#ifndef BOOST_UBLAS_FRIEND_FUNCTION +#ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS template BOOST_UBLAS_INLINE reverse_iterator_base1 operator + (const reverse_iterator_base1 &it, std::ptrdiff_t n) { @@ -972,7 +972,7 @@ namespace boost { namespace numeric { namespace ublas { } #endif -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend reverse_iterator_base2 operator + (const reverse_iterator_base2 &it, difference_type n) { reverse_iterator_base2 tmp (it); @@ -1030,7 +1030,7 @@ namespace boost { namespace numeric { namespace ublas { } }; -#ifndef BOOST_UBLAS_FRIEND_FUNCTION +#ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS template BOOST_UBLAS_INLINE reverse_iterator_base2 operator + (const reverse_iterator_base2 &it, std::ptrdiff_t n) { @@ -1675,15 +1675,15 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE dual_iterator_type begin () const { - return (*this) ().find_first1 (1, 0, index2 ()); + return (*this) ().find_first1 (1, 0, index2 ()); } BOOST_UBLAS_INLINE dual_iterator_type end () const { - return (*this) ().find_first1 (1, (*this) ().size1 (), index2 ()); + return (*this) ().find_first1 (1, (*this) ().size1 (), index2 ()); } BOOST_UBLAS_INLINE dual_reverse_iterator_type rbegin () const { - return dual_reverse_iterator_type (end ()); + return dual_reverse_iterator_type (end ()); } BOOST_UBLAS_INLINE dual_reverse_iterator_type rend () const { @@ -1743,9 +1743,9 @@ namespace boost { namespace numeric { namespace ublas { template class indexed_const_iterator2: - public container_const_reference, + public container_const_reference, public random_access_iterator_base, + indexed_const_iterator2, typename C::value_type, typename C::const_reference> { public: @@ -1770,7 +1770,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE indexed_const_iterator2 (const container_type &c, size_type it1, size_type it2): container_const_reference (c), it1_ (it1), it2_ (it2) {} - BOOST_UBLAS_INLINE + BOOST_UBLAS_INLINE indexed_const_iterator2 (const iterator_type &it): container_const_reference (it ()), it1_ (it.index1 ()), it2_ (it.index2 ()) {} @@ -1826,15 +1826,15 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE dual_iterator_type begin () const { - return (*this) ().find_first1 (1, 0, index2 ()); + return (*this) ().find_first1 (1, 0, index2 ()); } BOOST_UBLAS_INLINE dual_iterator_type end () const { - return (*this) ().find_first1 (1, (*this) ().size1 (), index2 ()); + return (*this) ().find_first1 (1, (*this) ().size1 (), index2 ()); } BOOST_UBLAS_INLINE dual_reverse_iterator_type rbegin () const { - return dual_reverse_iterator_type (end ()); + return dual_reverse_iterator_type (end ()); } BOOST_UBLAS_INLINE dual_reverse_iterator_type rend () const { diff --git a/include/boost/numeric/ublas/matrix.hpp b/include/boost/numeric/ublas/matrix.hpp index 11cc0174..bdc17ae1 100644 --- a/include/boost/numeric/ublas/matrix.hpp +++ b/include/boost/numeric/ublas/matrix.hpp @@ -71,7 +71,7 @@ namespace boost { namespace numeric { namespace ublas { matrix (size_type size1, size_type size2): size1_ (size1), size2_ (size2), data_ (size1 * size2) {} BOOST_UBLAS_INLINE - matrix (size_type size1, size_type size2, const array_type &data): + matrix (size_type size1, size_type size2, const array_type &data): size1_ (size1), size2_ (size2), data_ (data) {} BOOST_UBLAS_INLINE matrix (const matrix &m): @@ -79,17 +79,17 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE matrix (const matrix_expression &ae): - size1_ (ae ().size1 ()), size2_ (ae ().size2 ()), data_ (ae ().size1 () * ae ().size2 ()) { + size1_ (ae ().size1 ()), size2_ (ae ().size2 ()), data_ (ae ().size1 () * ae ().size2 ()) { matrix_assign (scalar_assign (), *this, ae); } // Accessors BOOST_UBLAS_INLINE - size_type size1 () const { + size_type size1 () const { return size1_; } BOOST_UBLAS_INLINE - size_type size2 () const { + size_type size2 () const { return size2_; } BOOST_UBLAS_INLINE @@ -121,7 +121,7 @@ namespace boost { namespace numeric { namespace ublas { // Assignment BOOST_UBLAS_INLINE - matrix &operator = (const matrix &m) { + matrix &operator = (const matrix &m) { BOOST_UBLAS_CHECK (size1_ == m.size1_, bad_size ()); BOOST_UBLAS_CHECK (size2_ == m.size2_, bad_size ()); size1_ = m.size1_; @@ -130,7 +130,7 @@ namespace boost { namespace numeric { namespace ublas { return *this; } BOOST_UBLAS_INLINE - matrix &assign_temporary (matrix &m) { + matrix &assign_temporary (matrix &m) { swap (m); return *this; } @@ -147,7 +147,7 @@ namespace boost { namespace numeric { namespace ublas { } template BOOST_UBLAS_INLINE - matrix &reset (const matrix_expression &ae) { + matrix &reset (const matrix_expression &ae) { self_type temporary (ae); resize (temporary.size1 (), temporary.size2 ()); return assign_temporary (temporary); @@ -171,8 +171,8 @@ namespace boost { namespace numeric { namespace ublas { } template BOOST_UBLAS_INLINE - matrix &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix &plus_assign (const matrix_expression &ae) { + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -188,8 +188,8 @@ namespace boost { namespace numeric { namespace ublas { } template BOOST_UBLAS_INLINE - matrix &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix &minus_assign (const matrix_expression &ae) { + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template @@ -219,7 +219,7 @@ namespace boost { namespace numeric { namespace ublas { data ().swap (m.data ()); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (matrix &m1, matrix &m2) { m1.swap (m2); @@ -1094,7 +1094,7 @@ namespace boost { namespace numeric { namespace ublas { data ().swap (m.data ()); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (vector_of_vector &m1, vector_of_vector &m2) { m1.swap (m2); @@ -1934,7 +1934,7 @@ namespace boost { namespace numeric { namespace ublas { std::swap (size2_, m.size2_); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (identity_matrix &m1, identity_matrix &m2) { m1.swap (m2); @@ -2377,7 +2377,7 @@ namespace boost { namespace numeric { namespace ublas { std::swap (size2_, m.size2_); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (zero_matrix &m1, zero_matrix &m2) { m1.swap (m2); @@ -2805,7 +2805,7 @@ namespace boost { namespace numeric { namespace ublas { std::swap (value_, m.value_); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (scalar_matrix &m1, scalar_matrix &m2) { m1.swap (m2); @@ -3351,7 +3351,7 @@ namespace boost { namespace numeric { namespace ublas { std::swap_ranges (data_ [i], data_ [i] + size2_, m.data_ [i]); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (c_matrix &m1, c_matrix &m2) { m1.swap (m2); @@ -3793,12 +3793,12 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE const_iterator1 begin () const { const self_type &m = (*this) (); - return m.find_first1 (1, 0, index2 ()); + return m.find_first1 (1, 0, index2 ()); } BOOST_UBLAS_INLINE const_iterator1 end () const { const self_type &m = (*this) (); - return m.find_first1 (1, m.size1 (), index2 ()); + return m.find_first1 (1, m.size1 (), index2 ()); } BOOST_UBLAS_INLINE const_reverse_iterator1 rbegin () const { @@ -3924,7 +3924,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE iterator1 end () const { self_type &m = (*this) (); - return m.find_first1 (1, m.size1 (), index2 ()); + return m.find_first1 (1, m.size1 (), index2 ()); } BOOST_UBLAS_INLINE reverse_iterator1 rbegin () const { diff --git a/include/boost/numeric/ublas/matrix_assign.hpp b/include/boost/numeric/ublas/matrix_assign.hpp index 42084b1e..5e71ca80 100644 --- a/include/boost/numeric/ublas/matrix_assign.hpp +++ b/include/boost/numeric/ublas/matrix_assign.hpp @@ -477,7 +477,7 @@ namespace boost { namespace numeric { namespace ublas { typedef F functor_type; typedef typename M::difference_type difference_type; typedef typename M::value_type value_type; -#ifdef BOOST_UBLAS_TYPE_CHECK +#ifdef BOOST_UBLAS_TYPE_CHECK_TOO_STRONG matrix cm (m.size1 (), m.size2 ()); indexing_matrix_assign (scalar_assign (), cm, m, row_major_tag ()); indexing_matrix_assign (functor_type (), cm, e, row_major_tag ()); @@ -558,8 +558,9 @@ namespace boost { namespace numeric { namespace ublas { functor_type () (*it2, value_type ()), ++ it2; ++ it1; } -#ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (m, cm), external_logic ()); +#ifdef BOOST_UBLAS_TYPE_CHECK_TOO_STRONG + if (! disable_type_check) + BOOST_UBLAS_CHECK (equals (m, cm), external_logic ()); #endif } // Packed (proxy) column major case @@ -572,7 +573,7 @@ namespace boost { namespace numeric { namespace ublas { typedef F functor_type; typedef typename M::difference_type difference_type; typedef typename M::value_type value_type; -#ifdef BOOST_UBLAS_TYPE_CHECK +#ifdef BOOST_UBLAS_TYPE_CHECK_TOO_STRONG matrix cm (m.size1 (), m.size2 ()); indexing_matrix_assign (scalar_assign (), cm, m, column_major_tag ()); indexing_matrix_assign (functor_type (), cm, e, column_major_tag ()); @@ -653,8 +654,9 @@ namespace boost { namespace numeric { namespace ublas { functor_type () (*it1, value_type ()), ++ it1; ++ it2; } -#ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (m, cm), external_logic ()); +#ifdef BOOST_UBLAS_TYPE_CHECK_TOO_STRONG + if (! disable_type_check) + BOOST_UBLAS_CHECK (equals (m, cm), external_logic ()); #endif } // Sparse row major case @@ -686,7 +688,8 @@ namespace boost { namespace numeric { namespace ublas { ++ it1e; } #ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (m, cm), external_logic ()); + if (! disable_type_check) + BOOST_UBLAS_CHECK (equals (m, cm), external_logic ()); #endif } // Sparse column major case @@ -718,7 +721,8 @@ namespace boost { namespace numeric { namespace ublas { ++ it2e; } #ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (m, cm), external_logic ()); + if (! disable_type_check) + BOOST_UBLAS_CHECK (equals (m, cm), external_logic ()); #endif } // Sparse proxy row major case @@ -838,7 +842,8 @@ namespace boost { namespace numeric { namespace ublas { ++ it1; } #ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (m, cm), external_logic ()); + if (! disable_type_check) + BOOST_UBLAS_CHECK (equals (m, cm), external_logic ()); #endif } // Sparse proxy column major case @@ -958,7 +963,8 @@ namespace boost { namespace numeric { namespace ublas { ++ it2; } #ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (m, cm), external_logic ()); + if (! disable_type_check) + BOOST_UBLAS_CHECK (equals (m, cm), external_logic ()); #endif } diff --git a/include/boost/numeric/ublas/matrix_expression.hpp b/include/boost/numeric/ublas/matrix_expression.hpp index 208c25e1..5d9a3d15 100644 --- a/include/boost/numeric/ublas/matrix_expression.hpp +++ b/include/boost/numeric/ublas/matrix_expression.hpp @@ -5009,18 +5009,18 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE operator value_type () const { - return functor_type () (e_); + return functor_type () (e_); } private: expression_closure_type e_; }; - + template struct matrix_scalar_unary_traits { typedef matrix_scalar_unary expression_type; #ifdef BOOST_UBLAS_USE_ET - typedef expression_type result_type; + typedef expression_type result_type; #else typedef typename F::result_type result_type; #endif diff --git a/include/boost/numeric/ublas/matrix_proxy.hpp b/include/boost/numeric/ublas/matrix_proxy.hpp index d911edb8..403743b7 100644 --- a/include/boost/numeric/ublas/matrix_proxy.hpp +++ b/include/boost/numeric/ublas/matrix_proxy.hpp @@ -227,7 +227,7 @@ namespace boost { namespace numeric { namespace ublas { vector_swap (scalar_swap (), *this, mr); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (matrix_row &mr1, matrix_row &mr2) { mr1.swap (mr2); @@ -755,7 +755,7 @@ namespace boost { namespace numeric { namespace ublas { vector_swap (scalar_swap (), *this, mc); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (matrix_column &mc1, matrix_column &mc2) { mc1.swap (mc2); @@ -1299,7 +1299,7 @@ namespace boost { namespace numeric { namespace ublas { vector_swap (scalar_swap (), *this, mvr); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (matrix_vector_range &mvr1, matrix_vector_range &mvr2) { mvr1.swap (mvr2); @@ -1827,7 +1827,7 @@ namespace boost { namespace numeric { namespace ublas { vector_swap (scalar_swap (), *this, mvs); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (matrix_vector_slice &mvs1, matrix_vector_slice &mvs2) { mvs1.swap (mvs2); @@ -2358,7 +2358,7 @@ namespace boost { namespace numeric { namespace ublas { vector_swap (scalar_swap (), *this, mvi); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (matrix_vector_indirect &mvi1, matrix_vector_indirect &mvi2) { mvi1.swap (mvi2); @@ -2900,7 +2900,7 @@ namespace boost { namespace numeric { namespace ublas { matrix_swap (scalar_swap (), *this, mr); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (matrix_range &mr1, matrix_range &mr2) { mr1.swap (mr2); @@ -3889,7 +3889,7 @@ namespace boost { namespace numeric { namespace ublas { matrix_swap (scalar_swap (), *this, ms); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (matrix_slice &ms1, matrix_slice &ms2) { ms1.swap (ms2); @@ -4856,7 +4856,7 @@ namespace boost { namespace numeric { namespace ublas { matrix_swap (scalar_swap (), *this, mi); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (matrix_indirect &mi1, matrix_indirect &mi2) { mi1.swap (mi2); diff --git a/include/boost/numeric/ublas/matrix_sparse.hpp b/include/boost/numeric/ublas/matrix_sparse.hpp index 33942b27..889d553f 100644 --- a/include/boost/numeric/ublas/matrix_sparse.hpp +++ b/include/boost/numeric/ublas/matrix_sparse.hpp @@ -421,7 +421,7 @@ namespace boost { namespace numeric { namespace ublas { data ().swap (m.data ()); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (sparse_matrix &m1, sparse_matrix &m2) { m1.swap (m2); @@ -1500,7 +1500,7 @@ namespace boost { namespace numeric { namespace ublas { data ().swap (m.data ()); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (sparse_vector_of_sparse_vector &m1, sparse_vector_of_sparse_vector &m2) { m1.swap (m2); @@ -2722,7 +2722,7 @@ namespace boost { namespace numeric { namespace ublas { value_data ().swap (m.value_data ()); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (compressed_matrix &m1, compressed_matrix &m2) { m1.swap (m2); @@ -2748,7 +2748,7 @@ namespace boost { namespace numeric { namespace ublas { index1_data () [filled1_ - 1] = k_based (filled2_); index2_data () [filled2_ - 1] = k_based (element2); value_data () [filled2_ - 1] = t; - BOOST_UBLAS_CHECK (index1_data () [filled1_ - 1] == k_based (filled2_), internal_logic ()); + BOOST_UBLAS_CHECK (index1_data () [filled1_ - 1] == k_based (filled2_), internal_logic ()); return; } // Raising exceptions abstracted as requested during review. @@ -3663,11 +3663,11 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE static size_type zero_based (size_type k_based_index) { return k_based_index - index_base_; - } + } BOOST_UBLAS_INLINE static size_type k_based (size_type zero_based_index) { return zero_based_index + index_base_; - } + } friend class iterator1; friend class iterator2; @@ -4012,7 +4012,7 @@ namespace boost { namespace numeric { namespace ublas { value_data ().swap (m.value_data ()); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (coordinate_matrix &m1, coordinate_matrix &m2) { m1.swap (m2); @@ -4938,11 +4938,11 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE static size_type zero_based (size_type k_based_index) { return k_based_index - index_base_; - } + } BOOST_UBLAS_INLINE static size_type k_based (size_type zero_based_index) { return zero_based_index + index_base_; - } + } friend class iterator1; friend class iterator2; diff --git a/include/boost/numeric/ublas/operation.hpp b/include/boost/numeric/ublas/operation.hpp index 9665b45a..49f49fcf 100644 --- a/include/boost/numeric/ublas/operation.hpp +++ b/include/boost/numeric/ublas/operation.hpp @@ -192,60 +192,12 @@ namespace boost { namespace numeric { namespace ublas { return axpy_prod (e1, e2, v, true); } - template + template BOOST_UBLAS_INLINE - M & - axpy_prod (const matrix_expression &e1, - const matrix_expression &e2, - M &m, row_major_tag) { - typedef M matrix_type; - typedef const E1 expression1_type; - typedef const E2 expression2_type; - typedef typename M::size_type size_type; - typedef typename M::value_type value_type; - -#ifdef BOOST_UBLAS_TYPE_CHECK - matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), row_major_tag ()); -#endif - typename expression1_type::const_iterator1 it1 (e1 ().begin1 ()); - typename expression1_type::const_iterator1 it1_end (e1 ().end1 ()); - while (it1 != it1_end) { - typename expression1_type::const_iterator2 it2 (it1.begin ()); - typename expression1_type::const_iterator2 it2_end (it1.end ()); - while (it2 != it2_end) { - // row (m, it1.index1 ()).plus_assign (*it2 * row (e2 (), it2.index2 ())); - matrix_row mr (e2 (), it2.index2 ()); - typename matrix_row::const_iterator itr (mr.begin ()); - typename matrix_row::const_iterator itr_end (mr.end ()); - while (itr != itr_end) { - m (it1.index1 (), itr.index ()) += *it2 * *itr; - ++ itr; - } - ++ it2; - } - ++ it1; - } -#ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (m, cm), internal_logic ()); -#endif - return m; - } - - template - BOOST_UBLAS_INLINE -// GCC 2.95 diagnoses ambiguities. -#if !defined (__GNUC__) || !(__GNUC__ <= 2 && __GNUC_MINOR__ <= 95) M & axpy_prod (const matrix_expression &e1, const matrix_expression &e2, M &m, const F &f, row_major_tag) { -#else - M & - axpy_prod_functor (const matrix_expression &e1, - const matrix_expression &e2, - M &m, const F &f, row_major_tag) { -#endif typedef M matrix_type; typedef const E1 expression1_type; typedef const E2 expression2_type; @@ -281,60 +233,12 @@ namespace boost { namespace numeric { namespace ublas { return m; } - template + template BOOST_UBLAS_INLINE - M & - axpy_prod (const matrix_expression &e1, - const matrix_expression &e2, - M &m, column_major_tag) { - typedef M matrix_type; - typedef const E1 expression1_type; - typedef const E2 expression2_type; - typedef typename M::size_type size_type; - typedef typename M::value_type value_type; - -#ifdef BOOST_UBLAS_TYPE_CHECK - matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), column_major_tag ()); -#endif - typename expression2_type::const_iterator2 it2 (e2 ().begin2 ()); - typename expression2_type::const_iterator2 it2_end (e2 ().end2 ()); - while (it2 != it2_end) { - typename expression2_type::const_iterator1 it1 (it2.begin ()); - typename expression2_type::const_iterator1 it1_end (it2.end ()); - while (it1 != it1_end) { - // column (m, it2.index2 ()).plus_assign (*it1 * column (e1 (), it1.index1 ())); - matrix_column mc (e1 (), it1.index1 ()); - typename matrix_column::const_iterator itc (mc.begin ()); - typename matrix_column::const_iterator itc_end (mc.end ()); - while (itc != itc_end) { - m (itc.index (), it2.index2 ()) += *it1 * *itc; - ++ itc; - } - ++ it1; - } - ++ it2; - } -#ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (m, cm), internal_logic ()); -#endif - return m; - } - - template - BOOST_UBLAS_INLINE -// GCC 2.95 diagnoses ambiguities. -#if !defined (__GNUC__) || !(__GNUC__ <= 2 && __GNUC_MINOR__ <= 95) M & axpy_prod (const matrix_expression &e1, const matrix_expression &e2, M &m, const F &f, column_major_tag) { -#else - M & - axpy_prod_functor (const matrix_expression &e1, - const matrix_expression &e2, - M &m, const F &f, column_major_tag) { -#endif typedef M matrix_type; typedef const E1 expression1_type; typedef const E2 expression2_type; @@ -371,36 +275,8 @@ namespace boost { namespace numeric { namespace ublas { } // Dispatcher - template + template BOOST_UBLAS_INLINE - M & - axpy_prod (const matrix_expression &e1, - const matrix_expression &e2, - M &m, bool init = true) { - typedef typename M::value_type value_type; - typedef typename M::orientation_category orientation_category; - - if (init) - m.assign (zero_matrix (e1 ().size1 (), e2 ().size2 ())); - return axpy_prod (e1, e2, m, orientation_category ()); - } - template - BOOST_UBLAS_INLINE - M - axpy_prod (const matrix_expression &e1, - const matrix_expression &e2) { - typedef M matrix_type; - - matrix_type m (e1 ().size1 (), e2 ().size2 ()); - // FIXME: needed for c_matrix?! - // return axpy_prod (e1, e2, m, false); - return axpy_prod (e1, e2, m, true); - } - - template - BOOST_UBLAS_INLINE -// GCC 2.95 diagnoses ambiguities. -#if !defined (__GNUC__) || !(__GNUC__ <= 2 && __GNUC_MINOR__ <= 95) M & axpy_prod (const matrix_expression &e1, const matrix_expression &e2, @@ -412,23 +288,8 @@ namespace boost { namespace numeric { namespace ublas { m.assign (zero_matrix (e1 ().size1 (), e2 ().size2 ())); return axpy_prod (e1, e2, m, f, orientation_category ()); } -#else - M & - axpy_prod_functor (const matrix_expression &e1, - const matrix_expression &e2, - M &m, const F &f, bool init = true) { - typedef typename M::value_type value_type; - typedef typename M::orientation_category orientation_category; - - if (init) - m.assign (zero_matrix (e1 ().size1 (), e2 ().size2 ())); - return axpy_prod_functor (e1, e2, m, f, orientation_category ()); - } -#endif - template + template BOOST_UBLAS_INLINE -// GCC 2.95 diagnoses ambiguities. -#if !defined (__GNUC__) || !(__GNUC__ <= 2 && __GNUC_MINOR__ <= 95) M axpy_prod (const matrix_expression &e1, const matrix_expression &e2, @@ -440,195 +301,30 @@ namespace boost { namespace numeric { namespace ublas { // return axpy_prod (e1, e2, m, f, false); return axpy_prod (e1, e2, m, f, true); } -#else + template + BOOST_UBLAS_INLINE + M & + axpy_prod (const matrix_expression &e1, + const matrix_expression &e2, + M &m, bool init = true) { + typedef typename M::value_type value_type; + typedef typename M::orientation_category orientation_category; + + if (init) + m.assign (zero_matrix (e1 ().size1 (), e2 ().size2 ())); + return axpy_prod (e1, e2, m, full (), orientation_category ()); + } + template + BOOST_UBLAS_INLINE M - axpy_prod_functor (const matrix_expression &e1, - const matrix_expression &e2, - const F &f) { + axpy_prod (const matrix_expression &e1, + const matrix_expression &e2) { typedef M matrix_type; matrix_type m (e1 ().size1 (), e2 ().size2 ()); // FIXME: needed for c_matrix?! - // return axpy_prod_functor (e1, e2, m, f, false); - return axpy_prod_functor (e1, e2, m, f, true); - } -#endif - - template - BOOST_UBLAS_INLINE - V & - axpy_mult_vec (const T1 &t1, - const matrix_expression &e1, - const vector_expression &e2, - const T2 &t2, - V &v) { - typedef V vector_type; - typedef const E1 expression1_type; - typedef const E2 expression2_type; - typedef typename V::size_type size_type; - typedef typename V::value_type value_type; - -#ifdef BOOST_UBLAS_TYPE_CHECK - vector cv (t2 * v); - indexing_vector_assign (scalar_plus_assign (), cv, t1 * prod (e1, e2)); -#endif - v *= t2; - typename expression1_type::const_iterator1 it1 (e1 ().begin1 ()); - typename expression1_type::const_iterator1 it1_end (e1 ().end1 ()); - while (it1 != it1_end) { - typename expression1_type::const_iterator2 it2 (it1.begin ()); - typename expression1_type::const_iterator2 it2_end (it1.end ()); - while (it2 != it2_end) { - v (it1.index1 ()) += (t1 * *it2) * e2 () (it2.index2 ()); - ++ it2; - } - ++ it1; - } -#ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (v, cv), internal_logic ()); -#endif - return v; - } - - template - BOOST_UBLAS_INLINE - V & - axpy_mult_vec (const T1 &t1, - const vector_expression &e1, - const matrix_expression &e2, - const T2 &t2, - V &v) { - typedef V vector_type; - typedef const E1 expression1_type; - typedef const E2 expression2_type; - typedef typename V::size_type size_type; - typedef typename V::value_type value_type; - -#ifdef BOOST_UBLAS_TYPE_CHECK - vector cv (t2 * v); - indexing_vector_assign (scalar_plus_assign (), cv, t1 * prod (e1, e2)); -#endif - v *= t2; - typename expression2_type::const_iterator2 it2 (e2 ().begin2 ()); - typename expression2_type::const_iterator2 it2_end (e2 ().end2 ()); - while (it2 != it2_end) { - typename expression2_type::const_iterator1 it1 (it2.begin ()); - typename expression2_type::const_iterator1 it1_end (it2.end ()); - while (it1 != it1_end) { - v (it2.index2 ()) += (t1 * *it1) * e1 () (it1.index1 ()); - ++ it1; - } - ++ it2; - } -#ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (v, cv), internal_logic ()); -#endif - return v; - } - - template - BOOST_UBLAS_INLINE - M & - axpy_mult_mat (const T1 &t1, - const matrix_expression &e1, - const matrix_expression &e2, - const T2 &t2, - M &m, - row_major_tag) { - typedef M matrix_type; - typedef const E1 expression1_type; - typedef const E2 expression2_type; - typedef typename M::size_type size_type; - typedef typename M::value_type value_type; - -#ifdef BOOST_UBLAS_TYPE_CHECK - matrix cm (t2 * m); - indexing_matrix_assign (scalar_plus_assign (), cm, t1 * prod (e1, e2), row_major_tag ()); -#endif - m *= t2; - typename expression1_type::const_iterator1 it1 (e1 ().begin1 ()); - typename expression1_type::const_iterator1 it1_end (e1 ().end1 ()); - while (it1 != it1_end) { - // matrix_row mr (m, it1.index1 ()); - typename expression1_type::const_iterator2 it2 (it1.begin ()); - typename expression1_type::const_iterator2 it2_end (it1.end ()); - while (it2 != it2_end) { - // mr.plus_assign ((t1 * *it2) * row (e2 (), it2.index2 ())); - matrix_row mr (e2 (), it2.index2 ()); - typename matrix_row::const_iterator itr (mr.begin ()); - typename matrix_row::const_iterator itr_end (mr.end ()); - value_type t (t1 * *it2); - while (itr != itr_end) { - m (it1.index1 (), itr.index ()) += t * *itr; - ++ itr; - } - ++ it2; - } - ++ it1; - } -#ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (m, cm), internal_logic ()); -#endif - return m; - } - - template - BOOST_UBLAS_INLINE - M & - axpy_mult_mat (const T1 &t1, - const matrix_expression &e1, - const matrix_expression &e2, - const T2 &t2, - M &m, - column_major_tag) { - typedef M matrix_type; - typedef const E1 expression1_type; - typedef const E2 expression2_type; - typedef typename M::size_type size_type; - typedef typename M::value_type value_type; - -#ifdef BOOST_UBLAS_TYPE_CHECK - matrix cm (t2 * m); - indexing_matrix_assign (scalar_plus_assign (), cm, t1 * prod (e1, e2), column_major_tag ()); -#endif - m *= t2; - typename expression2_type::const_iterator2 it2 (e2 ().begin2 ()); - typename expression2_type::const_iterator2 it2_end (e2 ().end2 ()); - while (it2 != it2_end) { - // matrix_column mc (m, it2.index2 ()); - typename expression2_type::const_iterator1 it1 (it2.begin ()); - typename expression2_type::const_iterator1 it1_end (it2.end ()); - while (it1 != it1_end) { - // mc.plus_assign ((t1 * *it1) * column (e1 (), it1.index1 ())); - matrix_column mc (e1 (), it1.index1 ()); - typename matrix_column::const_iterator itc (mc.begin ()); - typename matrix_column::const_iterator itc_end (mc.end ()); - value_type t (t1 * *it1); - while (itc != itc_end) { - m (itc.index (), it2.index2 ()) += t * *itc; - ++ itc; - } - ++ it1; - } - ++ it2; - } -#ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (m, cm), internal_logic ()); -#endif - return m; - } - - // Dispatcher - template - BOOST_UBLAS_INLINE - M & - axpy_mult_mat (const T1 &t1, - const matrix_expression &e1, - const matrix_expression &e2, - const T2 &t2, - M &m) { - typedef typename M::orientation_category orientation_category; - return axpy_mult_mat (t1, e1, e2, t2, m, orientation_category ()); + // return axpy_prod (e1, e2, m, full (), false); + return axpy_prod (e1, e2, m, full (), true); } }}} diff --git a/include/boost/numeric/ublas/operation_blocked.hpp b/include/boost/numeric/ublas/operation_blocked.hpp new file mode 100644 index 00000000..c899bcd6 --- /dev/null +++ b/include/boost/numeric/ublas/operation_blocked.hpp @@ -0,0 +1,448 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifndef BOOST_UBLAS_OPERATION_BLOCKED_H +#define BOOST_UBLAS_OPERATION_BLOCKED_H + +namespace boost { namespace numeric { namespace ublas { + + template + BOOST_UBLAS_INLINE + V + block_prod (const matrix_expression &e1, + const vector_expression &e2, + std::size_t block_size) { + typedef V vector_type; + typedef const E1 expression1_type; + typedef const E2 expression2_type; + typedef typename V::size_type size_type; + typedef typename V::value_type value_type; + + V v (e1 ().size1 ()); +#ifdef BOOST_UBLAS_TYPE_CHECK + vector cv (v.size ()); + indexing_vector_assign (scalar_assign (), cv, prod (e1, e2)); +#endif + size_type i_size = e1 ().size1 (); + size_type j_size = BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size ()); + for (size_type i_begin = 0; i_begin < i_size; i_begin += block_size) { + size_type i_end = i_begin + std::min (i_size - i_begin, block_size); +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + vector_range v_range (v, range<> (i_begin, i_end)); + v_range.assign (zero_vector (i_end - i_begin)); + for (size_type j_begin = 0; j_begin < j_size; j_begin += block_size) { + size_type j_end = j_begin + std::min (j_size - j_begin, block_size); + const matrix_range e1_range (e1 (), range<> (i_begin, i_end), range<> (j_begin, j_end)); + const vector_range e2_range (e2 (), range<> (j_begin, j_end)); + v_range.plus_assign (prod (e1_range, e2_range)); + } +#else + vector_range v_range (v, range (i_begin, i_end)); + v_range.assign (zero_vector (i_end - i_begin)); + for (size_type j_begin = 0; j_begin < j_size; j_begin += block_size) { + size_type j_end = j_begin + std::min (j_size - j_begin, block_size); + const matrix_range e1_range (e1 (), range (i_begin, i_end), range (j_begin, j_end)); + const vector_range e2_range (e2 (), range (j_begin, j_end)); + v_range.plus_assign (prod (e1_range, e2_range)); + } +#endif + } +#ifdef BOOST_UBLAS_TYPE_CHECK + BOOST_UBLAS_CHECK (equals (v, cv), internal_logic ()); +#endif + return v; + } + + template + BOOST_UBLAS_INLINE + V + block_prec_prod (const matrix_expression &e1, + const vector_expression &e2, + std::size_t block_size) { + typedef V vector_type; + typedef const E1 expression1_type; + typedef const E2 expression2_type; + typedef typename V::size_type size_type; + typedef typename V::value_type value_type; + + V v (e1 ().size1 ()); +#ifdef BOOST_UBLAS_TYPE_CHECK + vector cv (v.size ()); + indexing_vector_assign (scalar_assign (), cv, prod (e1, e2)); +#endif + size_type i_size = e1 ().size1 (); + size_type j_size = BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size ()); + for (size_type i_begin = 0; i_begin < i_size; i_begin += block_size) { + size_type i_end = i_begin + std::min (i_size - i_begin, block_size); +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + vector_range v_range (v, range<> (i_begin, i_end)); + v_range.assign (zero_vector (i_end - i_begin)); + for (size_type j_begin = 0; j_begin < j_size; j_begin += block_size) { + size_type j_end = j_begin + std::min (j_size - j_begin, block_size); + const matrix_range e1_range (e1 (), range<> (i_begin, i_end), range<> (j_begin, j_end)); + const vector_range e2_range (e2 (), range<> (j_begin, j_end)); + v_range.plus_assign (prec_prod (e1_range, e2_range)); + } +#else + vector_range v_range (v, range (i_begin, i_end)); + v_range.assign (zero_vector (i_end - i_begin)); + for (size_type j_begin = 0; j_begin < j_size; j_begin += block_size) { + size_type j_end = j_begin + std::min (j_size - j_begin, block_size); + const matrix_range e1_range (e1 (), range (i_begin, i_end), range (j_begin, j_end)); + const vector_range e2_range (e2 (), range (j_begin, j_end)); + v_range.plus_assign (prec_prod (e1_range, e2_range)); + } +#endif + } +#ifdef BOOST_UBLAS_TYPE_CHECK + BOOST_UBLAS_CHECK (equals (v, cv), internal_logic ()); +#endif + return v; + } + + template + BOOST_UBLAS_INLINE + V + block_prod (const vector_expression &e1, + const matrix_expression &e2, + std::size_t block_size) { + typedef V vector_type; + typedef const E1 expression1_type; + typedef const E2 expression2_type; + typedef typename V::size_type size_type; + typedef typename V::value_type value_type; + + V v (e2 ().size2 ()); +#ifdef BOOST_UBLAS_TYPE_CHECK + vector cv (v.size ()); + indexing_vector_assign (scalar_assign (), cv, prod (e1, e2)); +#endif + size_type i_size = BOOST_UBLAS_SAME (e1 ().size (), e2 ().size1 ()); + size_type j_size = e2 ().size2 (); + for (size_type j_begin = 0; j_begin < j_size; j_begin += block_size) { + size_type j_end = j_begin + std::min (j_size - j_begin, block_size); +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + vector_range v_range (v, range<> (j_begin, j_end)); + v_range.assign (zero_vector (j_end - j_begin)); + for (size_type i_begin = 0; i_begin < i_size; i_begin += block_size) { + size_type i_end = i_begin + std::min (i_size - i_begin, block_size); + const vector_range e1_range (e1 (), range<> (i_begin, i_end)); + const matrix_range e2_range (e2 (), range<> (i_begin, i_end), range<> (j_begin, j_end)); + v_range.plus_assign (prod (e1_range, e2_range)); + } +#else + vector_range v_range (v, range (j_begin, j_end)); + v_range.assign (zero_vector (j_end - j_begin)); + for (size_type i_begin = 0; i_begin < i_size; i_begin += block_size) { + size_type i_end = i_begin + std::min (i_size - i_begin, block_size); + const vector_range e1_range (e1 (), range (i_begin, i_end)); + const matrix_range e2_range (e2 (), range (i_begin, i_end), range (j_begin, j_end)); + v_range.plus_assign (prod (e1_range, e2_range)); + } +#endif + } +#ifdef BOOST_UBLAS_TYPE_CHECK + BOOST_UBLAS_CHECK (equals (v, cv), internal_logic ()); +#endif + return v; + } + + template + BOOST_UBLAS_INLINE + V + block_prec_prod (const vector_expression &e1, + const matrix_expression &e2, + std::size_t block_size) { + typedef V vector_type; + typedef const E1 expression1_type; + typedef const E2 expression2_type; + typedef typename V::size_type size_type; + typedef typename V::value_type value_type; + + V v (e2 ().size2 ()); +#ifdef BOOST_UBLAS_TYPE_CHECK + vector cv (v.size ()); + indexing_vector_assign (scalar_assign (), cv, prod (e1, e2)); +#endif + size_type i_size = BOOST_UBLAS_SAME (e1 ().size (), e2 ().size1 ()); + size_type j_size = e2 ().size2 (); + for (size_type j_begin = 0; j_begin < j_size; j_begin += block_size) { + size_type j_end = j_begin + std::min (j_size - j_begin, block_size); +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + vector_range v_range (v, range<> (j_begin, j_end)); + v_range.assign (zero_vector (j_end - j_begin)); + for (size_type i_begin = 0; i_begin < i_size; i_begin += block_size) { + size_type i_end = i_begin + std::min (i_size - i_begin, block_size); + const vector_range e1_range (e1 (), range<> (i_begin, i_end)); + const matrix_range e2_range (e2 (), range<> (i_begin, i_end), range<> (j_begin, j_end)); + v_range.plus_assign (prec_prod (e1_range, e2_range)); + } +#else + vector_range v_range (v, range (j_begin, j_end)); + v_range.assign (zero_vector (j_end - j_begin)); + for (size_type i_begin = 0; i_begin < i_size; i_begin += block_size) { + size_type i_end = i_begin + std::min (i_size - i_begin, block_size); + const vector_range e1_range (e1 (), range (i_begin, i_end)); + const matrix_range e2_range (e2 (), range (i_begin, i_end), range (j_begin, j_end)); + v_range.plus_assign (prec_prod (e1_range, e2_range)); + } +#endif + } +#ifdef BOOST_UBLAS_TYPE_CHECK + BOOST_UBLAS_CHECK (equals (v, cv), internal_logic ()); +#endif + return v; + } + + template + BOOST_UBLAS_INLINE + M + block_prod (const matrix_expression &e1, + const matrix_expression &e2, + std::size_t block_size, + row_major_tag) { + typedef M matrix_type; + typedef const E1 expression1_type; + typedef const E2 expression2_type; + typedef typename M::size_type size_type; + typedef typename M::value_type value_type; + + M m (e1 ().size1 (), e2 ().size2 ()); +#ifdef BOOST_UBLAS_TYPE_CHECK + matrix cm (m.size1 (), m.size2 ()); + indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), row_major_tag ()); + disable_type_check = true; +#endif + size_type i_size = e1 ().size1 (); + size_type j_size = e2 ().size2 (); + size_type k_size = BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size1 ()); + for (size_type i_begin = 0; i_begin < i_size; i_begin += block_size) { + size_type i_end = i_begin + std::min (i_size - i_begin, block_size); + for (size_type j_begin = 0; j_begin < j_size; j_begin += block_size) { + size_type j_end = j_begin + std::min (j_size - j_begin, block_size); +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + matrix_range m_range (m, range<> (i_begin, i_end), range<> (j_begin, j_end)); + m_range.assign (zero_matrix (i_end - i_begin, j_end - j_begin)); + for (size_type k_begin = 0; k_begin < k_size; k_begin += block_size) { + size_type k_end = k_begin + std::min (k_size - k_begin, block_size); + const matrix_range e1_range (e1 (), range<> (i_begin, i_end), range<> (k_begin, k_end)); + const matrix_range e2_range (e2 (), range<> (k_begin, k_end), range<> (j_begin, j_end)); + m_range.plus_assign (prod (e1_range, e2_range)); + } +#else + matrix_range m_range (m, range (i_begin, i_end), range (j_begin, j_end)); + m_range.assign (zero_matrix (i_end - i_begin, j_end - j_begin)); + for (size_type k_begin = 0; k_begin < k_size; k_begin += block_size) { + size_type k_end = k_begin + std::min (k_size - k_begin, block_size); + const matrix_range e1_range (e1 (), range (i_begin, i_end), range (k_begin, k_end)); + const matrix_range e2_range (e2 (), range (k_begin, k_end), range (j_begin, j_end)); + m_range.plus_assign (prod (e1_range, e2_range)); + } +#endif + } + } +#ifdef BOOST_UBLAS_TYPE_CHECK + disable_type_check = false; + BOOST_UBLAS_CHECK (equals (m, cm), internal_logic ()); +#endif + return m; + } + template + BOOST_UBLAS_INLINE + M + block_prec_prod (const matrix_expression &e1, + const matrix_expression &e2, + std::size_t block_size, + row_major_tag) { + typedef M matrix_type; + typedef const E1 expression1_type; + typedef const E2 expression2_type; + typedef typename M::size_type size_type; + typedef typename M::value_type value_type; + + M m (e1 ().size1 (), e2 ().size2 ()); +#ifdef BOOST_UBLAS_TYPE_CHECK + matrix cm (m.size1 (), m.size2 ()); + indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), row_major_tag ()); + disable_type_check = true; +#endif + size_type i_size = e1 ().size1 (); + size_type j_size = e2 ().size2 (); + size_type k_size = BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size1 ()); + for (size_type i_begin = 0; i_begin < i_size; i_begin += block_size) { + size_type i_end = i_begin + std::min (i_size - i_begin, block_size); + for (size_type j_begin = 0; j_begin < j_size; j_begin += block_size) { + size_type j_end = j_begin + std::min (j_size - j_begin, block_size); +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + matrix_range m_range (m, range<> (i_begin, i_end), range<> (j_begin, j_end)); + m_range.assign (zero_matrix (i_end - i_begin, j_end - j_begin)); + for (size_type k_begin = 0; k_begin < k_size; k_begin += block_size) { + size_type k_end = k_begin + std::min (k_size - k_begin, block_size); + const matrix_range e1_range (e1 (), range<> (i_begin, i_end), range<> (k_begin, k_end)); + const matrix_range e2_range (e2 (), range<> (k_begin, k_end), range<> (j_begin, j_end)); + m_range.plus_assign (prec_prod (e1_range, e2_range)); + } +#else + matrix_range m_range (m, range (i_begin, i_end), range (j_begin, j_end)); + m_range.assign (zero_matrix (i_end - i_begin, j_end - j_begin)); + for (size_type k_begin = 0; k_begin < k_size; k_begin += block_size) { + size_type k_end = k_begin + std::min (k_size - k_begin, block_size); + const matrix_range e1_range (e1 (), range (i_begin, i_end), range (k_begin, k_end)); + const matrix_range e2_range (e2 (), range (k_begin, k_end), range (j_begin, j_end)); + m_range.plus_assign (prec_prod (e1_range, e2_range)); + } +#endif + } + } +#ifdef BOOST_UBLAS_TYPE_CHECK + disable_type_check = false; + BOOST_UBLAS_CHECK (equals (m, cm), internal_logic ()); +#endif + return m; + } + + template + BOOST_UBLAS_INLINE + M + block_prod (const matrix_expression &e1, + const matrix_expression &e2, + std::size_t block_size, + column_major_tag) { + typedef M matrix_type; + typedef const E1 expression1_type; + typedef const E2 expression2_type; + typedef typename M::size_type size_type; + typedef typename M::value_type value_type; + + M m (e1 ().size1 (), e2 ().size2 ()); +#ifdef BOOST_UBLAS_TYPE_CHECK + matrix cm (m.size1 (), m.size2 ()); + indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), column_major_tag ()); + disable_type_check = true; +#endif + size_type i_size = e1 ().size1 (); + size_type j_size = e2 ().size2 (); + size_type k_size = BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size1 ()); + for (size_type j_begin = 0; j_begin < j_size; j_begin += block_size) { + size_type j_end = j_begin + std::min (j_size - j_begin, block_size); + for (size_type i_begin = 0; i_begin < i_size; i_begin += block_size) { + size_type i_end = i_begin + std::min (i_size - i_begin, block_size); +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + matrix_range m_range (m, range<> (i_begin, i_end), range<> (j_begin, j_end)); + m_range.assign (zero_matrix (i_end - i_begin, j_end - j_begin)); + for (size_type k_begin = 0; k_begin < k_size; k_begin += block_size) { + size_type k_end = k_begin + std::min (k_size - k_begin, block_size); + const matrix_range e1_range (e1 (), range<> (i_begin, i_end), range<> (k_begin, k_end)); + const matrix_range e2_range (e2 (), range<> (k_begin, k_end), range<> (j_begin, j_end)); + m_range.plus_assign (prod (e1_range, e2_range)); + } +#else + matrix_range m_range (m, range (i_begin, i_end), range (j_begin, j_end)); + m_range.assign (zero_matrix (i_end - i_begin, j_end - j_begin)); + for (size_type k_begin = 0; k_begin < k_size; k_begin += block_size) { + size_type k_end = k_begin + std::min (k_size - k_begin, block_size); + const matrix_range e1_range (e1 (), range (i_begin, i_end), range (k_begin, k_end)); + const matrix_range e2_range (e2 (), range (k_begin, k_end), range (j_begin, j_end)); + m_range.plus_assign (prod (e1_range, e2_range)); + } +#endif + } + } +#ifdef BOOST_UBLAS_TYPE_CHECK + disable_type_check = false; + BOOST_UBLAS_CHECK (equals (m, cm), internal_logic ()); +#endif + return m; + } + template + BOOST_UBLAS_INLINE + M + block_prec_prod (const matrix_expression &e1, + const matrix_expression &e2, + std::size_t block_size, + column_major_tag) { + typedef M matrix_type; + typedef const E1 expression1_type; + typedef const E2 expression2_type; + typedef typename M::size_type size_type; + typedef typename M::value_type value_type; + + M m (e1 ().size1 (), e2 ().size2 ()); +#ifdef BOOST_UBLAS_TYPE_CHECK + matrix cm (m.size1 (), m.size2 ()); + indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), column_major_tag ()); + disable_type_check = true; +#endif + size_type i_size = e1 ().size1 (); + size_type j_size = e2 ().size2 (); + size_type k_size = BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size1 ()); + for (size_type j_begin = 0; j_begin < j_size; j_begin += block_size) { + size_type j_end = j_begin + std::min (j_size - j_begin, block_size); + for (size_type i_begin = 0; i_begin < i_size; i_begin += block_size) { + size_type i_end = i_begin + std::min (i_size - i_begin, block_size); +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL + matrix_range m_range (m, range<> (i_begin, i_end), range<> (j_begin, j_end)); + m_range.assign (zero_matrix (i_end - i_begin, j_end - j_begin)); + for (size_type k_begin = 0; k_begin < k_size; k_begin += block_size) { + size_type k_end = k_begin + std::min (k_size - k_begin, block_size); + const matrix_range e1_range (e1 (), range<> (i_begin, i_end), range<> (k_begin, k_end)); + const matrix_range e2_range (e2 (), range<> (k_begin, k_end), range<> (j_begin, j_end)); + m_range.plus_assign (prec_prod (e1_range, e2_range)); + } +#else + matrix_range m_range (m, range (i_begin, i_end), range (j_begin, j_end)); + m_range.assign (zero_matrix (i_end - i_begin, j_end - j_begin)); + for (size_type k_begin = 0; k_begin < k_size; k_begin += block_size) { + size_type k_end = k_begin + std::min (k_size - k_begin, block_size); + const matrix_range e1_range (e1 (), range (i_begin, i_end), range (k_begin, k_end)); + const matrix_range e2_range (e2 (), range (k_begin, k_end), range (j_begin, j_end)); + m_range.plus_assign (prec_prod (e1_range, e2_range)); + } +#endif + } + } +#ifdef BOOST_UBLAS_TYPE_CHECK + disable_type_check = false; + BOOST_UBLAS_CHECK (equals (m, cm), internal_logic ()); +#endif + return m; + } + + // Dispatcher + template + BOOST_UBLAS_INLINE + M + block_prod (const matrix_expression &e1, + const matrix_expression &e2, + std::size_t block_size) { + typedef typename M::orientation_category orientation_category; + return block_prod (e1, e2, block_size, orientation_category ()); + } + template + BOOST_UBLAS_INLINE + M + block_prec_prod (const matrix_expression &e1, + const matrix_expression &e2, + std::size_t block_size) { + typedef typename M::orientation_category orientation_category; + return block_prec_prod (e1, e2, block_size, orientation_category ()); + } + +}}} + +#endif + + diff --git a/include/boost/numeric/ublas/operation_sparse.hpp b/include/boost/numeric/ublas/operation_sparse.hpp index fdccf035..4977911f 100644 --- a/include/boost/numeric/ublas/operation_sparse.hpp +++ b/include/boost/numeric/ublas/operation_sparse.hpp @@ -22,12 +22,12 @@ namespace boost { namespace numeric { namespace ublas { - template + template BOOST_UBLAS_INLINE M & sparse_prod (const matrix_expression &e1, const matrix_expression &e2, - M &m, bool init, + M &m, const F &f, row_major_tag) { typedef M matrix_type; typedef const E1 expression1_type; @@ -35,8 +35,6 @@ namespace boost { namespace numeric { namespace ublas { typedef typename M::size_type size_type; typedef typename M::value_type value_type; - if (init) - m.assign (zero_matrix (e1 ().size1 (), e2 ().size2 ())); vector temporary (e2 ().size2 ()); #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); @@ -69,7 +67,8 @@ namespace boost { namespace numeric { namespace ublas { // m.push_back (it1.index1 (), j, temporary (j)); // FIXME: What to do with adaptors? // m.insert (it1.index1 (), j, temporary (j)); - m (it1.index1 (), j) = temporary (j); + if (f.other (it1.index1 (), j)) + m (it1.index1 (), j) = temporary (j); temporary (j) = value_type (); } } @@ -81,12 +80,12 @@ namespace boost { namespace numeric { namespace ublas { return m; } - template + template BOOST_UBLAS_INLINE M & sparse_prod (const matrix_expression &e1, const matrix_expression &e2, - M &m, bool init, + M &m, const F &f, column_major_tag) { typedef M matrix_type; typedef const E1 expression1_type; @@ -94,8 +93,6 @@ namespace boost { namespace numeric { namespace ublas { typedef typename M::size_type size_type; typedef typename M::value_type value_type; - if (init) - m.assign (zero_matrix (e1 ().size1 (), e2 ().size2 ())); vector temporary (e1 ().size1 ()); #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); @@ -128,7 +125,8 @@ namespace boost { namespace numeric { namespace ublas { // m.push_back (i, it2.index2 (), temporary (i)); // FIXME: What to do with adaptors? // m.insert (i, it2.index2 (), temporary (i)); - m (i, it2.index2 ()) = temporary (i); + if (f.other (i, it2.index2 ())) + m (i, it2.index2 ()) = temporary (i); temporary (i) = value_type (); } } @@ -141,14 +139,44 @@ namespace boost { namespace numeric { namespace ublas { } // Dispatcher + template + BOOST_UBLAS_INLINE + M & + sparse_prod (const matrix_expression &e1, + const matrix_expression &e2, + M &m, const F &f, bool init = true) { + typedef typename M::value_type value_type; + typedef typename M::orientation_category orientation_category; + + if (init) + m.assign (zero_matrix (e1 ().size1 (), e2 ().size2 ())); + return sparse_prod (e1, e2, m, f, orientation_category ()); + } + template + BOOST_UBLAS_INLINE + M + sparse_prod (const matrix_expression &e1, + const matrix_expression &e2, + const F &f) { + typedef M matrix_type; + + matrix_type m (e1 ().size1 (), e2 ().size2 ()); + // FIXME: needed for c_matrix?! + // return sparse_prod (e1, e2, m, f, false); + return sparse_prod (e1, e2, m, f, true); + } template BOOST_UBLAS_INLINE M & sparse_prod (const matrix_expression &e1, const matrix_expression &e2, M &m, bool init = true) { + typedef typename M::value_type value_type; typedef typename M::orientation_category orientation_category; - return sparse_prod (e1, e2, m, init, orientation_category ()); + + if (init) + m.assign (zero_matrix (e1 ().size1 (), e2 ().size2 ())); + return sparse_prod (e1, e2, m, full (), orientation_category ()); } template BOOST_UBLAS_INLINE @@ -158,163 +186,9 @@ namespace boost { namespace numeric { namespace ublas { typedef M matrix_type; matrix_type m (e1 ().size1 (), e2 ().size2 ()); - return sparse_prod (e1, e2, m, false); - } - - template - BOOST_UBLAS_INLINE - M & - sparse_mult_mat (const T1 &t1, - const matrix_expression &e1, - const matrix_expression &e2, - const T2 &t2, - M &m, - row_major_tag) { - typedef M matrix_type; - typedef const E1 expression1_type; - typedef const E2 expression2_type; - typedef typename M::size_type size_type; - typedef typename M::value_type value_type; - -#ifdef BOOST_UBLAS_TYPE_CHECK - matrix cm (t2 * m); - indexing_matrix_assign (scalar_plus_assign (), cm, t1 * prod (e1, e2), row_major_tag ()); -#endif - m *= t2; - vector temporary (e2 ().size2 ()); - typename expression1_type::const_iterator1 it1 (e1 ().begin1 ()); - typename expression1_type::const_iterator1 it1_end (e1 ().end1 ()); - while (it1 != it1_end) { - size_type jb (temporary.size ()); - size_type je (0); - // temporary.assign (column (m, it1.index1 ())); - matrix_row mr (m, it1.index1 ()); - typename matrix_row::const_iterator itr (mr.begin ()); - typename matrix_row::const_iterator itr_end (mr.end ()); - while (itr != itr_end) { - size_type j (itr.index ()); - temporary (j) = *itr; - jb = std::min (jb, j); - je = std::max (je, j); - ++ itr; - } - typename expression1_type::const_iterator2 it2 (it1.begin ()); - typename expression1_type::const_iterator2 it2_end (it1.end ()); - while (it2 != it2_end) { - // temporary.plus_assign ((t1 * *it2) * row (e2 (), it2.index2 ())); - matrix_row mr (e2 (), it2.index2 ()); - typename matrix_row::const_iterator itr (mr.begin ()); - typename matrix_row::const_iterator itr_end (mr.end ()); - value_type t (t1 * *it2); - while (itr != itr_end) { - size_type j (itr.index ()); - temporary (j) += t * *itr; - jb = std::min (jb, j); - je = std::max (je, j); - ++ itr; - } - ++ it2; - } - if (jb <= je) { - typename vector::iterator it (temporary.begin () + jb); - typename vector::iterator it_end (temporary.begin () + je + 1); - while (it != it_end) { - if (*it != value_type ()) { - m (it1.index1 (), it.index ()) = *it; - *it = value_type (); - } - ++ it; - } - } - ++ it1; - } -#ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (m, cm), internal_logic ()); -#endif - return m; - } - - template - BOOST_UBLAS_INLINE - M & - sparse_mult_mat (const T1 &t1, - const matrix_expression &e1, - const matrix_expression &e2, - const T2 &t2, - M &m, - column_major_tag) { - typedef M matrix_type; - typedef const E1 expression1_type; - typedef const E2 expression2_type; - typedef typename M::size_type size_type; - typedef typename M::value_type value_type; - -#ifdef BOOST_UBLAS_TYPE_CHECK - matrix cm (t2 * m); - indexing_matrix_assign (scalar_plus_assign (), cm, t1 * prod (e1, e2), column_major_tag ()); -#endif - m *= t2; - vector temporary (e1 ().size1 ()); - typename expression2_type::const_iterator2 it2 (e2 ().begin2 ()); - typename expression2_type::const_iterator2 it2_end (e2 ().end2 ()); - while (it2 != it2_end) { - size_type ib (temporary.size ()); - size_type ie (0); - // temporary.assign (column (m, it2.index2 ())); - matrix_column mc (m, it2.index2 ()); - typename matrix_column::const_iterator itc (mc.begin ()); - typename matrix_column::const_iterator itc_end (mc.end ()); - while (itc != itc_end) { - size_type i (itc.index ()); - temporary (i) = *itc; - ib = std::min (ib, i); - ie = std::max (ie, i); - ++ itc; - } - typename expression2_type::const_iterator1 it1 (it2.begin ()); - typename expression2_type::const_iterator1 it1_end (it2.end ()); - while (it1 != it1_end) { - // temporary.plus_assign ((t1 * *it1) * column (e1 (), it1.index1 ())); - matrix_column mc (e1 (), it1.index1 ()); - typename matrix_column::const_iterator itc (mc.begin ()); - typename matrix_column::const_iterator itc_end (mc.end ()); - value_type t (t1 * *it1); - while (itc != itc_end) { - size_type i (itc.index ()); - temporary (i) += t * *itc; - ib = std::min (ib, i); - ie = std::max (ie, i); - ++ itc; - } - ++ it1; - } - if (ib <= ie) { - for (size_type i = ib; i < ie + 1; ++ i) { - if (temporary (i) != value_type ()) { - m (i, it2.index2 ()) = temporary (i); - temporary (i) = value_type (); - } - } - } - ++ it2; - } -#ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (m, cm), internal_logic ()); -#endif - return m; - } - - // Dispatcher - template - BOOST_UBLAS_INLINE - M & - sparse_mult_mat (const T1 &t1, - const matrix_expression &e1, - const matrix_expression &e2, - const T2 &t2, - M &m) { - typedef typename M::orientation_category orientation_category; - return sparse_mult_mat (t1, e1, e2, t2, m, orientation_category ()); + // FIXME: needed for c_matrix?! + // return sparse_prod (e1, e2, m, full (), false); + return sparse_prod (e1, e2, m, full (), true); } }}} diff --git a/include/boost/numeric/ublas/storage.hpp b/include/boost/numeric/ublas/storage.hpp index 982490c6..a9c751e2 100644 --- a/include/boost/numeric/ublas/storage.hpp +++ b/include/boost/numeric/ublas/storage.hpp @@ -192,7 +192,7 @@ namespace boost { namespace numeric { namespace ublas { std::swap (data_, a.data_); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (unbounded_array &a1, unbounded_array &a2) { a1.swap (a2); @@ -413,7 +413,7 @@ namespace boost { namespace numeric { namespace ublas { std::swap_ranges (data_, data_ + std::max (size_, a.size_), a.data_); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (bounded_array &a1, bounded_array &a2) { a1.swap (a2); @@ -681,7 +681,7 @@ namespace boost { namespace numeric { namespace ublas { std::swap (data_, a.data_); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (array_adaptor &a1, array_adaptor &a2) { a1.swap (a2); @@ -939,7 +939,7 @@ namespace boost { namespace numeric { namespace ublas { std::swap (data_, a.data_); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (array_adaptor &a1, array_adaptor &a2) { a1.swap (a2); diff --git a/include/boost/numeric/ublas/storage_sparse.hpp b/include/boost/numeric/ublas/storage_sparse.hpp index cc002e0d..517a4f3e 100644 --- a/include/boost/numeric/ublas/storage_sparse.hpp +++ b/include/boost/numeric/ublas/storage_sparse.hpp @@ -381,7 +381,7 @@ namespace boost { namespace numeric { namespace ublas { std::swap (size_, a.size_); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (map_array &a1, map_array &a2) { a1.swap (a2); @@ -665,8 +665,8 @@ namespace boost { namespace numeric { namespace ublas { // throw std::bad_alloc (); } BOOST_UBLAS_INLINE - set_array (const set_array &a): - capacity_ (a.size_), data_ (new value_type [a.size_]), size_ (a.size_) { + set_array (const set_array &a): + capacity_ (a.size_), data_ (new value_type [a.size_]), size_ (a.size_) { // Assuming std compliant allocator as requested during review. // if (! data_) // throw std::bad_alloc (); @@ -747,7 +747,7 @@ namespace boost { namespace numeric { namespace ublas { return *this; } BOOST_UBLAS_INLINE - set_array &assign_temporary (set_array &a) { + set_array &assign_temporary (set_array &a) { swap (a); return *this; } @@ -763,7 +763,7 @@ namespace boost { namespace numeric { namespace ublas { std::swap (size_, a.size_); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (set_array &a1, set_array &a2) { a1.swap (a2); @@ -809,7 +809,7 @@ namespace boost { namespace numeric { namespace ublas { resize (size () + it2 - it1); it = begin () + n; std::copy (it1, it2, it); - std::sort (begin (), end (), std::less ()); + std::sort (begin (), end (), std::less ()); #endif } // This function seems to be big. So we do not let the compiler inline it. diff --git a/include/boost/numeric/ublas/symmetric.hpp b/include/boost/numeric/ublas/symmetric.hpp index a5f0700c..819f4e58 100644 --- a/include/boost/numeric/ublas/symmetric.hpp +++ b/include/boost/numeric/ublas/symmetric.hpp @@ -76,8 +76,8 @@ namespace boost { namespace numeric { namespace ublas { // Construction and destruction BOOST_UBLAS_INLINE - symmetric_matrix (): - size_ (0), + symmetric_matrix (): + size_ (0), data_ (0) {} BOOST_UBLAS_INLINE symmetric_matrix (size_type size): @@ -88,28 +88,28 @@ namespace boost { namespace numeric { namespace ublas { size_ (BOOST_UBLAS_SAME (size1, size2)), data_ (functor1_type::packed_size (size1, size2)) {} BOOST_UBLAS_INLINE - symmetric_matrix (size_type size, const array_type &data): + symmetric_matrix (size_type size, const array_type &data): size_ (size), data_ (data) {} BOOST_UBLAS_INLINE - symmetric_matrix (const symmetric_matrix &m): + symmetric_matrix (const symmetric_matrix &m): size_ (m.size_), data_ (m.data_) {} template BOOST_UBLAS_INLINE - symmetric_matrix (const matrix_expression &ae): - size_ (BOOST_UBLAS_SAME (ae ().size1 (), ae ().size2 ())), + symmetric_matrix (const matrix_expression &ae): + size_ (BOOST_UBLAS_SAME (ae ().size1 (), ae ().size2 ())), data_ (functor1_type::packed_size (ae ().size1 (), ae ().size2 ())) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); } // Accessors BOOST_UBLAS_INLINE - size_type size1 () const { + size_type size1 () const { return size_; } BOOST_UBLAS_INLINE - size_type size2 () const { + size_type size2 () const { return size_; } BOOST_UBLAS_INLINE @@ -155,7 +155,7 @@ namespace boost { namespace numeric { namespace ublas { // Assignment BOOST_UBLAS_INLINE - symmetric_matrix &operator = (const symmetric_matrix &m) { + symmetric_matrix &operator = (const symmetric_matrix &m) { BOOST_UBLAS_CHECK (size_ == m.size_, bad_size ()); size_ = m.size_; data () = m.data (); @@ -186,8 +186,8 @@ namespace boost { namespace numeric { namespace ublas { } template BOOST_UBLAS_INLINE - symmetric_matrix &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + symmetric_matrix &assign (const matrix_expression &ae) { + matrix_assign (scalar_assign (), *this, ae); return *this; } template @@ -203,8 +203,8 @@ namespace boost { namespace numeric { namespace ublas { } template BOOST_UBLAS_INLINE - symmetric_matrix &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + symmetric_matrix &plus_assign (const matrix_expression &ae) { + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -249,7 +249,7 @@ namespace boost { namespace numeric { namespace ublas { data ().swap (m.data ()); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (symmetric_matrix &m1, symmetric_matrix &m2) { m1.swap (m2); @@ -1125,7 +1125,7 @@ namespace boost { namespace numeric { namespace ublas { if (this != &m) matrix_swap (scalar_swap (), *this, m); } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (symmetric_adaptor &m1, symmetric_adaptor &m2) { m1.swap (m2); diff --git a/include/boost/numeric/ublas/traits.hpp b/include/boost/numeric/ublas/traits.hpp index c222894d..cb22314f 100644 --- a/include/boost/numeric/ublas/traits.hpp +++ b/include/boost/numeric/ublas/traits.hpp @@ -363,7 +363,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE real_type norm_1 (const_reference t) { // Oops, should have known that! - return type_traits::abs (self_type::real (t)) + + return type_traits::abs (self_type::real (t)) + type_traits::abs (self_type::imag (t)); } static @@ -375,7 +375,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE real_type norm_inf (const_reference t) { // Oops, should have known that! - return std::max (type_traits::abs (self_type::real (t)), + return std::max (type_traits::abs (self_type::real (t)), type_traits::abs (self_type::imag (t))); } @@ -440,7 +440,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE real_type norm_1 (const_reference t) { // Oops, should have known that! - return type_traits::abs (self_type::real (t)) + + return type_traits::abs (self_type::real (t)) + type_traits::abs (self_type::imag (t)); } static @@ -452,7 +452,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE real_type norm_inf (const_reference t) { // Oops, should have known that! - return std::max (type_traits::abs (self_type::real (t)), + return std::max (type_traits::abs (self_type::real (t)), type_traits::abs (self_type::imag (t))); } @@ -514,7 +514,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE real_type norm_1 (const_reference t) { // Oops, should have known that! - return type_traits::abs (self_type::real (t)) + + return type_traits::abs (self_type::real (t)) + type_traits::abs (self_type::imag (t)); } static @@ -526,7 +526,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE real_type norm_inf (const_reference t) { // Oops, should have known that! - return std::max (type_traits::abs (self_type::real (t)), + return std::max (type_traits::abs (self_type::real (t)), type_traits::abs (self_type::imag (t))); } @@ -698,6 +698,590 @@ namespace boost { namespace numeric { namespace ublas { }; #endif +#ifdef BOOST_UBLAS_USE_INTERVAL + template<> + struct type_traits > { + typedef type_traits > self_type; + typedef boost::numeric::interval value_type; + typedef const boost::numeric::interval &const_reference; + typedef boost::numeric::interval &reference; + typedef boost::numeric::interval real_type; + typedef boost::numeric::interval precision_type; + + BOOST_STATIC_CONSTANT (std::size_t, plus_complexity = 1); + BOOST_STATIC_CONSTANT (std::size_t, multiplies_complexity = 1); + + static + BOOST_UBLAS_INLINE + real_type real (const_reference t) { + return t; + } + static + BOOST_UBLAS_INLINE + real_type imag (const_reference t) { + return 0; + } + static + BOOST_UBLAS_INLINE + value_type conj (const_reference t) { + return t; + } + + static + BOOST_UBLAS_INLINE + real_type abs (const_reference t) { + return boost::numeric::abs (t); + } + static + BOOST_UBLAS_INLINE + value_type sqrt (const_reference t) { + return boost::numeric::sqrt (t); + } + + static + BOOST_UBLAS_INLINE + real_type norm_1 (const_reference t) { + return self_type::abs (t); + } + static + BOOST_UBLAS_INLINE + real_type norm_2 (const_reference t) { + return self_type::abs (t); + } + static + BOOST_UBLAS_INLINE + real_type norm_inf (const_reference t) { + return self_type::abs (t); + } + + static + BOOST_UBLAS_INLINE + bool equals (const_reference t1, const_reference t2) { + // Check, that the values match at least half. + static real_type sqrt_epsilon (type_traits::sqrt (std::numeric_limits::epsilon ())); + return self_type::norm_inf (t1 - t2) < sqrt_epsilon * + std::max (std::max (self_type::norm_inf (t1), + self_type::norm_inf (t2)), + std::numeric_limits::min ()); + } + }; + template<> + struct type_traits > { + typedef type_traits > self_type; + typedef boost::numeric::interval value_type; + typedef const boost::numeric::interval &const_reference; + typedef boost::numeric::interval &reference; + typedef boost::numeric::interval real_type; +#ifndef BOOST_UBLAS_USE_LONG_DOUBLE + typedef boost::numeric::interval precision_type; +#else + typedef boost::numeric::interval > precision_type; +#endif + + BOOST_STATIC_CONSTANT (std::size_t, plus_complexity = 1); + BOOST_STATIC_CONSTANT (std::size_t, multiplies_complexity = 1); + + static + BOOST_UBLAS_INLINE + real_type real (const_reference t) { + return t; + } + static + BOOST_UBLAS_INLINE + real_type imag (const_reference t) { + return 0; + } + static + BOOST_UBLAS_INLINE + value_type conj (const_reference t) { + return t; + } + + static + BOOST_UBLAS_INLINE + real_type abs (const_reference t) { + return boost::numeric::abs (t); + } + static + BOOST_UBLAS_INLINE + value_type sqrt (const_reference t) { + return boost::numeric::sqrt (t); + } + + static + BOOST_UBLAS_INLINE + real_type norm_1 (const_reference t) { + return self_type::abs (t); + } + static + BOOST_UBLAS_INLINE + real_type norm_2 (const_reference t) { + return self_type::abs (t); + } + static + BOOST_UBLAS_INLINE + real_type norm_inf (const_reference t) { + return self_type::abs (t); + } + + static + BOOST_UBLAS_INLINE + bool equals (const_reference t1, const_reference t2) { + // Check, that the values match at least half. + static real_type sqrt_epsilon (type_traits::sqrt (std::numeric_limits::epsilon ())); + return self_type::norm_inf (t1 - t2) < sqrt_epsilon * + std::max (std::max (self_type::norm_inf (t1), + self_type::norm_inf (t2)), + std::numeric_limits::min ()); + } + }; +#ifdef BOOST_UBLAS_USE_LONG_DOUBLE + template<> + struct type_traits > { + typedef type_traits > self_type; + typedef boost::numeric::interval value_type; + typedef const boost::numeric::interval &const_reference; + typedef boost::numeric::interval &reference; + typedef boost::numeric::interval real_type; + typedef boost::numeric::interval precision_type; + + BOOST_STATIC_CONSTANT (std::size_t, plus_complexity = 1); + BOOST_STATIC_CONSTANT (std::size_t, multiplies_complexity = 1); + + static + BOOST_UBLAS_INLINE + real_type real (const_reference t) { + return t; + } + static + BOOST_UBLAS_INLINE + real_type imag (const_reference t) { + return 0; + } + static + BOOST_UBLAS_INLINE + value_type conj (const_reference t) { + return t; + } + + static + BOOST_UBLAS_INLINE + real_type abs (const_reference t) { + return boost::numeric::abs (t); + } + static + BOOST_UBLAS_INLINE + value_type sqrt (const_reference t) { + return boost::numeric::sqrt (t); + } + + static + BOOST_UBLAS_INLINE + real_type norm_1 (const_reference t) { + return self_type::abs (t); + } + static + BOOST_UBLAS_INLINE + real_type norm_2 (const_reference t) { + return self_type::abs (t); + } + static + BOOST_UBLAS_INLINE + real_type norm_inf (const_reference t) { + return self_type::abs (t); + } + + static + BOOST_UBLAS_INLINE + bool equals (const_reference t1, const_reference t2) { + // Check, that the values match at least half. + static real_type sqrt_epsilon (type_traits::sqrt (std::numeric_limits::epsilon ())); + return self_type::norm_inf (t1 - t2) < sqrt_epsilon * + std::max (std::max (self_type::norm_inf (t1), + self_type::norm_inf (t2)), + std::numeric_limits::min ()); + } + }; +#endif + +#ifdef BOOST_UBLAS_USE_BOOST_COMPLEX + template<> + struct type_traits > > { + typedef type_traits > > self_type; + typedef boost::complex > value_type; + typedef const boost::complex > &const_reference; + typedef boost::complex > &reference; + typedef boost::numeric::interval real_type; + typedef boost::complex precision_type; + + BOOST_STATIC_CONSTANT (std::size_t, plus_complexity = 2); + BOOST_STATIC_CONSTANT (std::size_t, multiplies_complexity = 6); + + static + BOOST_UBLAS_INLINE + real_type real (const_reference t) { + // return t.real (); + return std::real (t); + } + static + BOOST_UBLAS_INLINE + real_type imag (const_reference t) { + // return t.imag (); + return std::imag (t); + } + static + BOOST_UBLAS_INLINE + value_type conj (const_reference t) { + // return t.conj (); + return std::conj (t); + } + + static + BOOST_UBLAS_INLINE + real_type abs (const_reference t) { + return boost::numeric::abs (t); + } + static + BOOST_UBLAS_INLINE + value_type sqrt (const_reference t) { + return boost::numeric::sqrt (t); + } + + static + BOOST_UBLAS_INLINE + real_type norm_1 (const_reference t) { + // Oops, should have known that! + return type_traits::abs (self_type::real (t)) + + type_traits::abs (self_type::imag (t)); + } + static + BOOST_UBLAS_INLINE + real_type norm_2 (const_reference t) { + return self_type::abs (t); + } + static + BOOST_UBLAS_INLINE + real_type norm_inf (const_reference t) { + // Oops, should have known that! + return std::max (type_traits::abs (self_type::real (t)), + type_traits::abs (self_type::imag (t))); + } + + static + BOOST_UBLAS_INLINE + bool equals (const_reference t1, const_reference t2) { + // Check, that the values match at least half. + static real_type sqrt_epsilon (type_traits::sqrt (std::numeric_limits::epsilon ())); + return self_type::norm_inf (t1 - t2) < sqrt_epsilon * + std::max (std::max (self_type::norm_inf (t1), + self_type::norm_inf (t2)), + std::numeric_limits::min ()); + } + }; + template<> + struct type_traits > { + typedef type_traits > self_type; + typedef boost::complex value_type; + typedef const boost::complex &const_reference; + typedef boost::complex &reference; + typedef double real_type; +#ifndef BOOST_UBLAS_USE_LONG_DOUBLE + typedef boost::complex precision_type; +#else + typedef boost::complex > precision_type; +#endif + + BOOST_STATIC_CONSTANT (std::size_t, plus_complexity = 2); + BOOST_STATIC_CONSTANT (std::size_t, multiplies_complexity = 6); + + static + BOOST_UBLAS_INLINE + real_type real (const_reference t) { + // return t.real (); + return std::real (t); + } + static + BOOST_UBLAS_INLINE + real_type imag (const_reference t) { + // return t.imag (); + return std::imag (t); + } + static + BOOST_UBLAS_INLINE + value_type conj (const_reference t) { + // return t.conj (); + return std::conj (t); + } + + static + BOOST_UBLAS_INLINE + real_type abs (const_reference t) { + return boost::numeric::abs (t); + } + static + BOOST_UBLAS_INLINE + value_type sqrt (const_reference t) { + return boost::numeric::sqrt (t); + } + + static + BOOST_UBLAS_INLINE + real_type norm_1 (const_reference t) { + // Oops, should have known that! + return type_traits::abs (self_type::real (t)) + + type_traits::abs (self_type::imag (t)); + } + static + BOOST_UBLAS_INLINE + real_type norm_2 (const_reference t) { + return self_type::abs (t); + } + static + BOOST_UBLAS_INLINE + real_type norm_inf (const_reference t) { + // Oops, should have known that! + return std::max (type_traits::abs (self_type::real (t)), + type_traits::abs (self_type::imag (t))); + } + + static + BOOST_UBLAS_INLINE + bool equals (const_reference t1, const_reference t2) { + // Check, that the values match at least half. + static real_type sqrt_epsilon (type_traits::sqrt (std::numeric_limits::epsilon ())); + return self_type::norm_inf (t1 - t2) < sqrt_epsilon * + std::max (std::max (self_type::norm_inf (t1), + self_type::norm_inf (t2)), + std::numeric_limits::min ()); + } + }; +#ifdef BOOST_UBLAS_USE_LONG_DOUBLE + template<> + struct type_traits > > { + typedef type_traits > > self_type; + typedef boost::complex > value_type; + typedef const boost::complex > &const_reference; + typedef boost::complex > &reference; + typedef boost::numeric::interval real_type; + typedef boost::complex > precision_type; + + BOOST_STATIC_CONSTANT (std::size_t, plus_complexity = 2); + BOOST_STATIC_CONSTANT (std::size_t, multiplies_complexity = 6); + + static + BOOST_UBLAS_INLINE + real_type real (const_reference t) { + // return t.real (); + return std::real (t); + } + static + BOOST_UBLAS_INLINE + real_type imag (const_reference t) { + // return t.imag (); + return std::imag (t); + } + static + BOOST_UBLAS_INLINE + value_type conj (const_reference t) { + // return t.conj (); + return std::conj (t); + } + + static + BOOST_UBLAS_INLINE + real_type abs (const_reference t) { + return boost::numeric::abs (t); + } + static + BOOST_UBLAS_INLINE + value_type sqrt (const_reference t) { + return boost::numeric::sqrt (t); + } + + static + BOOST_UBLAS_INLINE + real_type norm_1 (const_reference t) { + // Oops, should have known that! + return type_traits::abs (self_type::real (t)) + + type_traits::abs (self_type::imag (t)); + } + static + BOOST_UBLAS_INLINE + real_type norm_2 (const_reference t) { + return self_type::abs (t); + } + static + BOOST_UBLAS_INLINE + real_type norm_inf (const_reference t) { + // Oops, should have known that! + return std::max (type_traits::abs (self_type::real (t)), + type_traits::abs (self_type::imag (t))); + } + + static + BOOST_UBLAS_INLINE + bool equals (const_reference t1, const_reference t2) { + // Check, that the values match at least half. + static real_type sqrt_epsilon (type_traits::sqrt (std::numeric_limits::epsilon ())); + return self_type::norm_inf (t1 - t2) < sqrt_epsilon * + std::max (std::max (self_type::norm_inf (t1), + self_type::norm_inf (t2)), + std::numeric_limits::min ()); + } + }; +#endif +#endif + + template<> + struct promote_traits, boost::numeric::interval > { + typedef boost::numeric::interval promote_type; + }; + template<> + struct promote_traits, boost::numeric::interval > { + typedef boost::numeric::interval promote_type; + }; +#ifdef BOOST_UBLAS_USE_LONG_DOUBLE + template<> + struct promote_traits, boost::numeric::interval > { + typedef boost::numeric::interval promote_type; + }; + template<> + struct promote_traits, boost::numeric::interval > { + typedef boost::numeric::interval promote_type; + }; + template<> + struct promote_traits, boost::numeric::interval > { + typedef boost::numeric::interval promote_type; + }; + template<> + struct promote_traits, boost::numeric::interval > { + typedef boost::numeric::interval promote_type; + }; +#endif + +#ifdef BOOST_UBLAS_USE_BOOST_COMPLEX + template<> + struct promote_traits, boost::complex > > { + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits >, boost::numeric::interval > { + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits, boost::complex > > { + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits >, boost::numeric::interval > { + typedef boost::complex > promote_type; + }; +#ifdef BOOST_UBLAS_USE_LONG_DOUBLE + template<> + struct promote_traits, boost::complex > > { + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits >, boost::numeric::interval > { + typedef boost::complex > promote_type; + }; +#endif + + template<> + struct promote_traits, boost::complex > > { + // Here we'd better go the conservative way. + // typedef boost::complex > promote_type; + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits >, boost::numeric::interval > { + // Here we'd better go the conservative way. + // typedef boost::complex > promote_type; + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits, boost::complex > > { + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits >, boost::numeric::interval > { + typedef boost::complex > promote_type; + }; +#ifdef BOOST_UBLAS_USE_LONG_DOUBLE + template<> + struct promote_traits, boost::complex > > { + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits >, boost::numeric::interval > { + typedef boost::complex > promote_type; + }; +#endif + +#ifdef BOOST_UBLAS_USE_LONG_DOUBLE + template<> + struct promote_traits, boost::complex > > { + // Here we'd better go the conservative way. + // typedef boost::complex > promote_type; + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits >, boost::numeric::interval > { + // Here we'd better go the conservative way. + // typedef boost::complex > promote_type; + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits, boost::complex > > { + // Here we'd better go the conservative way. + // typedef boost::complex > promote_type; + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits >, boost::numeric::interval > { + // Here we'd better go the conservative way. + // typedef boost::complex > promote_type; + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits, boost::complex > > { + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits >, boost::numeric::interval > { + typedef boost::complex > promote_type; + }; +#endif + + template<> + struct promote_traits >, boost::complex > > { + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits >, boost::complex > > { + typedef boost::complex > promote_type; + }; +#ifdef BOOST_UBLAS_USE_LONG_DOUBLE + template<> + struct promote_traits >, boost::complex > > { + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits >, boost::complex > > { + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits >, boost::complex > > { + typedef boost::complex > promote_type; + }; + template<> + struct promote_traits >, boost::complex > > { + typedef boost::complex > promote_type; + }; +#endif +#endif +#endif + struct unknown_storage_tag {}; struct sparse_proxy_tag: public unknown_storage_tag {}; struct sparse_tag: public sparse_proxy_tag {}; diff --git a/include/boost/numeric/ublas/triangular.hpp b/include/boost/numeric/ublas/triangular.hpp index 90761a6b..d6c6eb9a 100644 --- a/include/boost/numeric/ublas/triangular.hpp +++ b/include/boost/numeric/ublas/triangular.hpp @@ -63,32 +63,32 @@ namespace boost { namespace numeric { namespace ublas { size1_ (0), size2_ (0), data_ (0) {} BOOST_UBLAS_INLINE - triangular_matrix (size_type size1, size_type size2): + triangular_matrix (size_type size1, size_type size2): size1_ (size1), size2_ (size2), data_ (functor1_type::packed_size (size1, size2)) {} BOOST_UBLAS_INLINE - triangular_matrix (size_type size1, size_type size2, const array_type &data): + triangular_matrix (size_type size1, size_type size2, const array_type &data): size1_ (size1), size2_ (size2), data_ (data) {} BOOST_UBLAS_INLINE - triangular_matrix (const triangular_matrix &m): + triangular_matrix (const triangular_matrix &m): size1_ (m.size1_), size2_ (m.size2_), data_ (m.data_) {} template BOOST_UBLAS_INLINE - triangular_matrix (const matrix_expression &ae): + triangular_matrix (const matrix_expression &ae): size1_ (ae ().size1 ()), size2_ (ae ().size2 ()), data_ (functor1_type::packed_size (ae ().size1 (), ae ().size2 ())) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); } // Accessors BOOST_UBLAS_INLINE - size_type size1 () const { + size_type size1 () const { return size1_; } BOOST_UBLAS_INLINE - size_type size2 () const { + size_type size2 () const { return size2_; } BOOST_UBLAS_INLINE @@ -131,7 +131,7 @@ namespace boost { namespace numeric { namespace ublas { // Raising exceptions abstracted as requested during review. // throw external_logic (); external_logic ().raise (); -#endif +#endif return one_; } else { #ifndef BOOST_UBLAS_REFERENCE_CONST_MEMBER @@ -145,7 +145,7 @@ namespace boost { namespace numeric { namespace ublas { // Assignment BOOST_UBLAS_INLINE - triangular_matrix &operator = (const triangular_matrix &m) { + triangular_matrix &operator = (const triangular_matrix &m) { BOOST_UBLAS_CHECK (size1_ == m.size1_, bad_size ()); BOOST_UBLAS_CHECK (size2_ == m.size2_, bad_size ()); size1_ = m.size1_; @@ -154,13 +154,13 @@ namespace boost { namespace numeric { namespace ublas { return *this; } BOOST_UBLAS_INLINE - triangular_matrix &assign_temporary (triangular_matrix &m) { + triangular_matrix &assign_temporary (triangular_matrix &m) { swap (m); return *this; } template BOOST_UBLAS_INLINE - triangular_matrix &operator = (const matrix_expression &ae) { + triangular_matrix &operator = (const matrix_expression &ae) { #ifdef BOOST_UBLAS_MUTABLE_TEMPORARY return assign_temporary (self_type (ae)); #else @@ -178,8 +178,8 @@ namespace boost { namespace numeric { namespace ublas { } template BOOST_UBLAS_INLINE - triangular_matrix &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + triangular_matrix &assign (const matrix_expression &ae) { + matrix_assign (scalar_assign (), *this, ae); return *this; } template @@ -195,8 +195,8 @@ namespace boost { namespace numeric { namespace ublas { } template BOOST_UBLAS_INLINE - triangular_matrix &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + triangular_matrix &plus_assign (const matrix_expression &ae) { + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -243,7 +243,7 @@ namespace boost { namespace numeric { namespace ublas { data ().swap (m.data ()); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (triangular_matrix &m1, triangular_matrix &m2) { m1.swap (m2); @@ -1149,7 +1149,7 @@ namespace boost { namespace numeric { namespace ublas { if (this != &m) matrix_swap (scalar_swap (), *this, m); } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (triangular_adaptor &m1, triangular_adaptor &m2) { m1.swap (m2); diff --git a/include/boost/numeric/ublas/vector.hpp b/include/boost/numeric/ublas/vector.hpp index 3c573824..a6fbdebd 100644 --- a/include/boost/numeric/ublas/vector.hpp +++ b/include/boost/numeric/ublas/vector.hpp @@ -101,25 +101,25 @@ namespace boost { namespace numeric { namespace ublas { // Element access BOOST_UBLAS_INLINE const_reference operator () (size_type i) const { - return data () [i]; + return data () [i]; } BOOST_UBLAS_INLINE reference operator () (size_type i) { - return data () [i]; + return data () [i]; } BOOST_UBLAS_INLINE - const_reference operator [] (size_type i) const { - return (*this) (i); + const_reference operator [] (size_type i) const { + return (*this) (i); } BOOST_UBLAS_INLINE - reference operator [] (size_type i) { + reference operator [] (size_type i) { return (*this) (i); } // Assignment BOOST_UBLAS_INLINE - vector &operator = (const vector &v) { + vector &operator = (const vector &v) { BOOST_UBLAS_CHECK (size_ == v.size_, bad_size ()); size_ = v.size_; data () = v.data (); @@ -213,7 +213,7 @@ namespace boost { namespace numeric { namespace ublas { data ().swap (v.data ()); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (vector &v1, vector &v2) { v1.swap (v2); @@ -616,7 +616,7 @@ namespace boost { namespace numeric { namespace ublas { std::swap (index_, v.index_); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (unit_vector &v1, unit_vector &v2) { v1.swap (v2); @@ -855,7 +855,7 @@ namespace boost { namespace numeric { namespace ublas { std::swap (size_, v.size_); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (zero_vector &v1, zero_vector &v2) { v1.swap (v2); @@ -1065,7 +1065,7 @@ namespace boost { namespace numeric { namespace ublas { std::swap (value_, v.value_); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (scalar_vector &v1, scalar_vector &v2) { v1.swap (v2); @@ -1410,7 +1410,7 @@ namespace boost { namespace numeric { namespace ublas { std::swap_ranges (data_, data_ + size_, v.data_); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (c_vector &v1, c_vector &v2) { v1.swap (v2); @@ -1550,7 +1550,7 @@ namespace boost { namespace numeric { namespace ublas { return it_ - v.begin ().it_; } - // Assignment + // Assignment BOOST_UBLAS_INLINE const_iterator &operator = (const const_iterator &it) { container_const_reference::assign (&it ()); @@ -1649,7 +1649,7 @@ namespace boost { namespace numeric { namespace ublas { return it_ - v.begin ().it_; } - // Assignment + // Assignment BOOST_UBLAS_INLINE iterator &operator = (const iterator &it) { container_reference::assign (&it ()); diff --git a/include/boost/numeric/ublas/vector_assign.hpp b/include/boost/numeric/ublas/vector_assign.hpp index c4f338ed..15630efc 100644 --- a/include/boost/numeric/ublas/vector_assign.hpp +++ b/include/boost/numeric/ublas/vector_assign.hpp @@ -319,7 +319,8 @@ namespace boost { namespace numeric { namespace ublas { while (-- size >= 0) functor_type () (*it, value_type ()), ++ it; #ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (v, cv), external_logic ()); + if (! disable_type_check) + BOOST_UBLAS_CHECK (equals (v, cv), external_logic ()); #endif } // Sparse case @@ -345,7 +346,8 @@ namespace boost { namespace numeric { namespace ublas { ++ ite; } #ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (v, cv), external_logic ()); + if (! disable_type_check) + BOOST_UBLAS_CHECK (equals (v, cv), external_logic ()); #endif } // Sparse proxy case @@ -403,7 +405,8 @@ namespace boost { namespace numeric { namespace ublas { ++ it; } #ifdef BOOST_UBLAS_TYPE_CHECK - BOOST_UBLAS_CHECK (equals (v, cv), external_logic ()); + if (! disable_type_check) + BOOST_UBLAS_CHECK (equals (v, cv), external_logic ()); #endif } diff --git a/include/boost/numeric/ublas/vector_expression.hpp b/include/boost/numeric/ublas/vector_expression.hpp index a629396b..393d6b87 100644 --- a/include/boost/numeric/ublas/vector_expression.hpp +++ b/include/boost/numeric/ublas/vector_expression.hpp @@ -1554,7 +1554,7 @@ namespace boost { namespace numeric { namespace ublas { return it1_.index (); } - // Assignment + // Assignment BOOST_UBLAS_INLINE const_iterator &operator = (const const_iterator &it) { container_const_reference::assign (&it ()); @@ -1587,7 +1587,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE const_iterator begin () const { - return find_first (0); + return find_first (0); } BOOST_UBLAS_INLINE const_iterator end () const { @@ -1715,7 +1715,7 @@ namespace boost { namespace numeric { namespace ublas { struct vector_scalar_unary_traits { typedef vector_scalar_unary expression_type; #if defined (BOOST_UBLAS_USE_ET) && defined (BOOST_UBLAS_USE_SCALAR_ET) - typedef expression_type result_type; + typedef expression_type result_type; #else typedef typename F::result_type result_type; #endif @@ -1829,11 +1829,11 @@ namespace boost { namespace numeric { namespace ublas { // Sparse bidirectional specialization BOOST_UBLAS_INLINE value_type evaluate (sparse_bidirectional_iterator_tag) const { - return functor_type () (e1_.begin (), e1_.end (), e2_.begin (), e2_.end (), sparse_bidirectional_iterator_tag ()); + return functor_type () (e1_.begin (), e1_.end (), e2_.begin (), e2_.end (), sparse_bidirectional_iterator_tag ()); } BOOST_UBLAS_INLINE - operator value_type () const { + operator value_type () const { return evaluate (iterator_category ()); } @@ -1846,7 +1846,7 @@ namespace boost { namespace numeric { namespace ublas { struct vector_scalar_binary_traits { typedef vector_scalar_binary expression_type; #if defined (BOOST_UBLAS_USE_ET) && defined (BOOST_UBLAS_USE_SCALAR_ET) - typedef expression_type result_type; + typedef expression_type result_type; #else typedef typename F::result_type result_type; #endif @@ -1855,30 +1855,30 @@ namespace boost { namespace numeric { namespace ublas { // inner_prod (v1, v2) = sum (v1 [i] * v2 [i] template BOOST_UBLAS_INLINE - typename vector_scalar_binary_traits::promote_type> >::result_type - inner_prod (const vector_expression &e1, + typename E2::value_type>::promote_type> >::result_type + inner_prod (const vector_expression &e1, const vector_expression &e2) { - typedef BOOST_UBLAS_TYPENAME vector_scalar_binary_traits::promote_type> >::expression_type expression_type; return expression_type (e1 (), e2 ()); } template BOOST_UBLAS_INLINE - typename vector_scalar_binary_traits::promote_type>::precision_type> >::result_type - prec_inner_prod (const vector_expression &e1, + typename type_traits::promote_type>::precision_type> >::result_type + prec_inner_prod (const vector_expression &e1, const vector_expression &e2) { - typedef BOOST_UBLAS_TYPENAME vector_scalar_binary_traits::promote_type>::precision_type> >::expression_type expression_type; return expression_type (e1 (), e2 ()); } diff --git a/include/boost/numeric/ublas/vector_proxy.hpp b/include/boost/numeric/ublas/vector_proxy.hpp index a6bde58b..f87c75b6 100644 --- a/include/boost/numeric/ublas/vector_proxy.hpp +++ b/include/boost/numeric/ublas/vector_proxy.hpp @@ -263,7 +263,7 @@ namespace boost { namespace numeric { namespace ublas { vector_swap (scalar_swap (), *this, vr); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (vector_range &vr1, vector_range &vr2) { vr1.swap (vr2); @@ -882,7 +882,7 @@ namespace boost { namespace numeric { namespace ublas { vector_swap (scalar_swap (), *this, vs); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (vector_slice &vs1, vector_slice &vs2) { vs1.swap (vs2); @@ -1491,7 +1491,7 @@ namespace boost { namespace numeric { namespace ublas { vector_swap (scalar_swap (), *this, vi); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (vector_indirect &vi1, vector_indirect &vi2) { vi1.swap (vi2); diff --git a/include/boost/numeric/ublas/vector_sparse.hpp b/include/boost/numeric/ublas/vector_sparse.hpp index 7cca20d0..da22f684 100644 --- a/include/boost/numeric/ublas/vector_sparse.hpp +++ b/include/boost/numeric/ublas/vector_sparse.hpp @@ -411,7 +411,7 @@ namespace boost { namespace numeric { namespace ublas { data ().swap (v.data ()); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (sparse_vector &v1, sparse_vector &v2) { v1.swap (v2); @@ -942,7 +942,7 @@ namespace boost { namespace numeric { namespace ublas { value_data ().swap (v.value_data ()); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (compressed_vector &v1, compressed_vector &v2) { v1.swap (v2); @@ -1241,11 +1241,11 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE static size_type zero_based (size_type k_based_index) { return k_based_index - index_base_; - } + } BOOST_UBLAS_INLINE static size_type k_based (size_type zero_based_index) { return zero_based_index + index_base_; - } + } friend class iterator; friend class const_iterator; @@ -1524,7 +1524,7 @@ namespace boost { namespace numeric { namespace ublas { value_data ().swap (v.value_data ()); } } -#ifdef BOOST_UBLAS_FRIEND_FUNCTION +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS BOOST_UBLAS_INLINE friend void swap (coordinate_vector &v1, coordinate_vector &v2) { v1.swap (v2); @@ -1840,11 +1840,11 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE static size_type zero_based (size_type k_based_index) { return k_based_index - index_base_; - } + } BOOST_UBLAS_INLINE static size_type k_based (size_type zero_based_index) { return zero_based_index + index_base_; - } + } friend class iterator; friend class const_iterator; diff --git a/test1/test1.cpp b/test1/test1.cpp index 2e2fbb80..3f436de2 100644 --- a/test1/test1.cpp +++ b/test1/test1.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/test1/test1.hpp b/test1/test1.hpp index 2bd4119f..9ccc3e85 100644 --- a/test1/test1.hpp +++ b/test1/test1.hpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifndef TEST1_H #define TEST1_H diff --git a/test1/test11.cpp b/test1/test11.cpp index 4c4d618b..f53bd280 100644 --- a/test1/test11.cpp +++ b/test1/test11.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -15,7 +31,7 @@ #include "test1.hpp" -// Test vector expression templates +// Test vector expression templates template struct test_my_vector { typedef typename V::value_type value_type; @@ -24,7 +40,7 @@ struct test_my_vector { template void operator () (VP &v1, VP &v2, VP &v3) const { - try { + try { value_type t; size_type i; real_type n; @@ -115,7 +131,7 @@ struct test_my_vector { } } void operator () () const { - try { + try { V v1 (N), v2 (N), v3 (N); (*this) (v1, v2, v3); diff --git a/test1/test12.cpp b/test1/test12.cpp index 4a11fe1f..c67704c6 100644 --- a/test1/test12.cpp +++ b/test1/test12.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -15,7 +31,7 @@ #include "test1.hpp" -// Test matrix & vector expression templates +// Test matrix & vector expression templates template struct test_my_matrix_vector { typedef typename V::value_type value_type; @@ -38,7 +54,7 @@ struct test_my_matrix_vector { m1 = ublas::outer_prod (v1, v2); std::cout << "outer_prod (v1, v2) = " << m1 << std::endl; - // Matrix vector product + // Matrix vector product initialize_matrix (m1); initialize_vector (v1); v2 = ublas::prod (m1, v1); diff --git a/test1/test13.cpp b/test1/test13.cpp index c1b9a278..813a1969 100644 --- a/test1/test13.cpp +++ b/test1/test13.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -15,7 +31,7 @@ #include "test1.hpp" -// Test matrix expression templates +// Test matrix expression templates template struct test_my_matrix { typedef typename M::value_type value_type; @@ -149,7 +165,7 @@ struct test_my_matrix { } }; -// Test matrix +// Test matrix void test_matrix () { std::cout << "test_matrix" << std::endl; diff --git a/test2/test2.cpp b/test2/test2.cpp index 7c7a3602..1b54ef66 100644 --- a/test2/test2.cpp +++ b/test2/test2.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/test2/test2.hpp b/test2/test2.hpp index 6a98e39b..6174eb56 100644 --- a/test2/test2.hpp +++ b/test2/test2.hpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifndef TEST2_H #define TEST2_H @@ -6,7 +22,7 @@ namespace ublas = boost::numeric::ublas; template void initialize_vector (V &v) { int size = v.size (); - for (int i = 0; i < size; ++ i) + for (int i = 0; i < size; ++ i) v [i] = i + 1.f; } @@ -16,9 +32,9 @@ void initialize_matrix (M &m, ublas::lower_tag) { int size2 = m.size2 (); for (int i = 0; i < size1; ++ i) { int j = 0; - for (; j <= i; ++ j) + for (; j <= i; ++ j) m (i, j) = i * size1 + j + 1.f; - for (; j < size2; ++ j) + for (; j < size2; ++ j) m (i, j) = 0.f; } } @@ -28,9 +44,9 @@ void initialize_matrix (M &m, ublas::upper_tag) { int size2 = m.size2 (); for (int i = 0; i < size1; ++ i) { int j = 0; - for (; j < i; ++ j) + for (; j < i; ++ j) m (i, j) = 0.f; - for (; j < size2; ++ j) + for (; j < size2; ++ j) m (i, j) = i * size1 + j + 1.f; } } @@ -38,8 +54,8 @@ template void initialize_matrix (M &m) { int size1 = m.size1 (); int size2 = m.size2 (); - for (int i = 0; i < size1; ++ i) - for (int j = 0; j < size2; ++ j) + for (int i = 0; i < size1; ++ i) + for (int j = 0; j < size2; ++ j) m (i, j) = i * size1 + j + 1.f; } diff --git a/test2/test21.cpp b/test2/test21.cpp index a4a74a7b..4da556ab 100644 --- a/test2/test21.cpp +++ b/test2/test21.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -55,7 +71,7 @@ void test_blas_1::operator () () { ublas::blas_1::copy (v1, v2); std::cout << "copy (v1, v2) = " << v1 << std::endl; - // _swap + // _swap initialize_vector (v1); initialize_vector (v2); ublas::blas_1::swap (v1, v2); diff --git a/test2/test22.cpp b/test2/test22.cpp index a65692f0..4d317c35 100644 --- a/test2/test22.cpp +++ b/test2/test22.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/test2/test23.cpp b/test2/test23.cpp index 013288f7..33f0f0da 100644 --- a/test2/test23.cpp +++ b/test2/test23.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -68,25 +84,25 @@ void test_blas_3::operator () () { initialize_matrix (m2, ublas::lower_tag ()); initialize_matrix (m3); ublas::blas_3::tsm (m1, value_type (1), m2, ublas::lower_tag ()); - std::cout << "tsm (m1, 1, m2) = " << m1 << " " << ublas::prod (m2, m1) - value_type (1) * m3 << std::endl; + std::cout << "tsm (m1, 1, m2) = " << m1 << " " << ublas::prod (m2, m1) - value_type (1) * m3 << std::endl; initialize_matrix (m1); initialize_matrix (m2, ublas::upper_tag ()); ublas::blas_3::tsm (m1, value_type (1), ublas::trans (m2), ublas::lower_tag ()); - std::cout << "tsm (m1, 1, trans (m2)) = " << m1 << " " << ublas::prod (ublas::trans (m2), m1) - value_type (1) * m3 << std::endl; + std::cout << "tsm (m1, 1, trans (m2)) = " << m1 << " " << ublas::prod (ublas::trans (m2), m1) - value_type (1) * m3 << std::endl; #ifdef USE_STD_COMPLEX initialize_matrix (m1); initialize_matrix (m2, ublas::upper_tag ()); ublas::blas_3::tsm (m1, value_type (1), ublas::herm (m2), ublas::lower_tag ()); - std::cout << "tsm (m1, 1, herm (m2)) = " << m1 << " " << ublas::prod (ublas::herm (m2), m1) - value_type (1) * m3 << std::endl; + std::cout << "tsm (m1, 1, herm (m2)) = " << m1 << " " << ublas::prod (ublas::herm (m2), m1) - value_type (1) * m3 << std::endl; #endif initialize_matrix (m1); initialize_matrix (m2, ublas::upper_tag ()); ublas::blas_3::tsm (m1, value_type (1), m2, ublas::upper_tag ()); - std::cout << "tsm (m1, 1, m2) = " << m1 << " " << ublas::prod (m2, m1) - value_type (1) * m3 << std::endl; + std::cout << "tsm (m1, 1, m2) = " << m1 << " " << ublas::prod (m2, m1) - value_type (1) * m3 << std::endl; initialize_matrix (m1); initialize_matrix (m2, ublas::lower_tag ()); ublas::blas_3::tsm (m1, value_type (1), ublas::trans (m2), ublas::upper_tag ()); - std::cout << "tsm (m1, 1, trans (m2)) = " << m1 << " " << ublas::prod (ublas::trans (m2), m1) - value_type (1) * m3 << std::endl; + std::cout << "tsm (m1, 1, trans (m2)) = " << m1 << " " << ublas::prod (ublas::trans (m2), m1) - value_type (1) * m3 << std::endl; #ifdef USE_STD_COMPLEX initialize_matrix (m1); initialize_matrix (m2, ublas::lower_tag ()); diff --git a/test3/test3.cpp b/test3/test3.cpp index c7124f44..dc6cd3de 100644 --- a/test3/test3.cpp +++ b/test3/test3.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/test3/test3.hpp b/test3/test3.hpp index 74f82e59..e0c2338b 100644 --- a/test3/test3.hpp +++ b/test3/test3.hpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifndef TEST3_H #define TEST3_H diff --git a/test3/test31.cpp b/test3/test31.cpp index 665a9350..09f96183 100644 --- a/test3/test31.cpp +++ b/test3/test31.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -117,7 +133,7 @@ struct test_my_vector { } } void operator () () const { - try { + try { V v1 (N, N), v2 (N, N), v3 (N, N); (*this) (v1, v2, v3); diff --git a/test3/test32.cpp b/test3/test32.cpp index feab1383..127b9e14 100644 --- a/test3/test32.cpp +++ b/test3/test32.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/test3/test33.cpp b/test3/test33.cpp index 59c682cb..fb52ee89 100644 --- a/test3/test33.cpp +++ b/test3/test33.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/test4/test4.cpp b/test4/test4.cpp index 8d7921c5..ed72c8ee 100644 --- a/test4/test4.cpp +++ b/test4/test4.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/test4/test4.hpp b/test4/test4.hpp index c960c790..f2cc47b6 100644 --- a/test4/test4.hpp +++ b/test4/test4.hpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifndef TEST4_H #define TEST4_H diff --git a/test4/test41.cpp b/test4/test41.cpp index 75a4f7a1..bec6a17b 100644 --- a/test4/test41.cpp +++ b/test4/test41.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -16,7 +32,7 @@ #include "test4.hpp" -// Test vector expression templates +// Test vector expression templates template struct test_my_vector { typedef typename V::value_type value_type; @@ -25,7 +41,7 @@ struct test_my_vector { template void operator () (VP &v1, VP &v2, VP &v3) const { - try { + try { value_type t; size_type i; real_type n; @@ -116,7 +132,7 @@ struct test_my_vector { } } void operator () () const { - try { + try { V v1 (N), v2 (N), v3 (N); (*this) (v1, v2, v3); diff --git a/test4/test42.cpp b/test4/test42.cpp index 99edb9a1..1e617417 100644 --- a/test4/test42.cpp +++ b/test4/test42.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -16,7 +32,7 @@ #include "test4.hpp" -// Test matrix & vector expression templates +// Test matrix & vector expression templates template struct test_my_matrix_vector { typedef typename V::value_type value_type; @@ -41,7 +57,7 @@ struct test_my_matrix_vector { m1 = ublas::outer_prod (v1, v2); std::cout << "outer_prod (v1, v2) = " << m1 << std::endl; - // Matrix vector product + // Matrix vector product initialize_matrix (m1); initialize_vector (v1); v2 = ublas::prod (m1, v1); diff --git a/test4/test43.cpp b/test4/test43.cpp index 6d24637b..8006cbbf 100644 --- a/test4/test43.cpp +++ b/test4/test43.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -16,7 +32,7 @@ #include "test4.hpp" -// Test matrix expression templates +// Test matrix expression templates template struct test_my_matrix { typedef typename M::value_type value_type; diff --git a/test5/test5.cpp b/test5/test5.cpp index ffe2e8c6..a07f8140 100644 --- a/test5/test5.cpp +++ b/test5/test5.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/test5/test5.hpp b/test5/test5.hpp index 3f67faa6..9ab10f15 100644 --- a/test5/test5.hpp +++ b/test5/test5.hpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifndef TEST5_H #define TEST5_H @@ -6,7 +22,7 @@ namespace ublas = boost::numeric::ublas; template void initialize_vector (V &v) { int size = v.size (); - for (int i = 0; i < size; ++ i) + for (int i = 0; i < size; ++ i) v [i] = i + 1.f; } @@ -16,9 +32,9 @@ void initialize_matrix (M &m, ublas::lower_tag) { // int size2 = m.size2 (); for (int i = 0; i < size1; ++ i) { int j = 0; - for (; j <= i; ++ j) + for (; j <= i; ++ j) m (i, j) = i * size1 + j + 1.f; -// for (; j < size2; ++ j) +// for (; j < size2; ++ j) // m (i, j) = 0.f; } } @@ -28,9 +44,9 @@ void initialize_matrix (M &m, ublas::upper_tag) { int size2 = m.size2 (); for (int i = 0; i < size1; ++ i) { int j = 0; -// for (; j < i; ++ j) +// for (; j < i; ++ j) // m (i, j) = 0.f; - for (; j < size2; ++ j) + for (; j < size2; ++ j) m (i, j) = i * size1 + j + 1.f; } } @@ -38,7 +54,7 @@ template void initialize_matrix (M &m) { int size1 = m.size1 (); int size2 = m.size2 (); - for (int i = 0; i < size1; ++ i) + for (int i = 0; i < size1; ++ i) for (int j = 0; j < size2; ++ j) m (i, j) = i * size1 + j + 1; } diff --git a/test5/test51.cpp b/test5/test51.cpp index 85210802..f68737eb 100644 --- a/test5/test51.cpp +++ b/test5/test51.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -25,7 +41,7 @@ struct test_my_vector { template void operator () (VP &v1, VP &v2, VP &v3) const { - try { + try { value_type t; size_type i; real_type n; @@ -116,7 +132,7 @@ struct test_my_vector { } } void operator () () const { - try { + try { V v1 (N), v2 (N), v3 (N); (*this) (v1, v2, v3); diff --git a/test5/test52.cpp b/test5/test52.cpp index e3df19f8..18785474 100644 --- a/test5/test52.cpp +++ b/test5/test52.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -41,7 +57,7 @@ struct test_my_matrix_vector { m1 = ublas::outer_prod (v1, v2); std::cout << "outer_prod (v1, v2) = " << m1 << std::endl; - // Matrix vector product + // Matrix vector product initialize_matrix (m1, ublas::lower_tag ()); initialize_vector (v1); v2 = ublas::prod (m1, v1); diff --git a/test5/test53.cpp b/test5/test53.cpp index 602f282c..f67b8c46 100644 --- a/test5/test53.cpp +++ b/test5/test53.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -16,7 +32,7 @@ #include "test5.hpp" -// Test matrix expression templates +// Test matrix expression templates template struct test_my_matrix { typedef typename M::value_type value_type; @@ -195,7 +211,7 @@ struct test_my_matrix { } }; -// Test matrix +// Test matrix void test_matrix () { std::cout << "test_matrix" << std::endl; diff --git a/test6/test6.cpp b/test6/test6.cpp index 8052a81a..8fa0737d 100644 --- a/test6/test6.cpp +++ b/test6/test6.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) diff --git a/test6/test6.hpp b/test6/test6.hpp index 132a2f4a..e6f0109b 100644 --- a/test6/test6.hpp +++ b/test6/test6.hpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifndef TEST6_H #define TEST6_H @@ -38,8 +54,8 @@ template void initialize_matrix (M &m) { int size1 = m.size1 (); int size2 = m.size2 (); - for (int i = 0; i < size1; ++ i) - for (int j = 0; j < size2; ++ j) + for (int i = 0; i < size1; ++ i) + for (int j = 0; j < size2; ++ j) m (i, j) = i * size1 + j + 1.f; } diff --git a/test6/test61.cpp b/test6/test61.cpp index 738cc8e1..de7d2d83 100644 --- a/test6/test61.cpp +++ b/test6/test61.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -17,7 +33,7 @@ #include "test6.hpp" -// Test vector expression templates +// Test vector expression templates template struct test_my_vector { typedef typename V::value_type value_type; @@ -26,7 +42,7 @@ struct test_my_vector { template void operator () (VP &v1, VP &v2, VP &v3) const { - try { + try { value_type t; size_type i; real_type n; @@ -117,7 +133,7 @@ struct test_my_vector { } } void operator () () const { - try { + try { V v1 (N), v2 (N), v3 (N); (*this) (v1, v2, v3); diff --git a/test6/test62.cpp b/test6/test62.cpp index 36f6fd59..34f7a759 100644 --- a/test6/test62.cpp +++ b/test6/test62.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -17,7 +33,7 @@ #include "test6.hpp" -// Test matrix & vector expression templates +// Test matrix & vector expression templates template struct test_my_matrix_vector { typedef typename V::value_type value_type; @@ -44,7 +60,7 @@ struct test_my_matrix_vector { m1 = ublas::outer_prod (v1, v2); std::cout << "outer_prod (v1, v2) = " << m1 << std::endl; - // Matrix vector product + // Matrix vector product initialize_matrix (m1, ublas::lower_tag ()); initialize_vector (v1); v2 = ublas::prod (m1, v1); diff --git a/test6/test63.cpp b/test6/test63.cpp index 8fe91660..b8d8f97a 100644 --- a/test6/test63.cpp +++ b/test6/test63.cpp @@ -1,3 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + #ifdef BOOST_MSVC #pragma warning (disable: 4355) @@ -17,7 +33,7 @@ #include "test6.hpp" -// Test matrix expression templates +// Test matrix expression templates template struct test_my_matrix { typedef typename M::value_type value_type; diff --git a/test7/Jamfile b/test7/Jamfile new file mode 100644 index 00000000..97ac2b7c --- /dev/null +++ b/test7/Jamfile @@ -0,0 +1,17 @@ +subproject libs/numeric/ublas/test7 ; + +SOURCES = test7 test71 test72 test73 ; + +exe test7 + : $(SOURCES).cpp + : $(BOOST_ROOT) + BOOST_UBLAS_USE_INTERVAL + BOOST_UBLAS_SAFE + USE_RANGE + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" +; + + + + diff --git a/test7/test7.cpp b/test7/test7.cpp new file mode 100644 index 00000000..7f797b83 --- /dev/null +++ b/test7/test7.cpp @@ -0,0 +1,55 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include + +#include +#include +#include +#include + +#include "test7.hpp" + +#ifdef BOOST_MSVC +// Standard new handler is not standard compliant. +#include +int __cdecl std_new_handler (unsigned) { + throw std::bad_alloc (); +} +#endif + +int main () { +#ifdef BOOST_MSVC + _set_new_handler (std_new_handler); +#endif + test_vector (); + test_matrix_vector (); + test_matrix (); + return 0; +} + + diff --git a/test7/test7.dsp b/test7/test7.dsp new file mode 100644 index 00000000..d56610b3 --- /dev/null +++ b/test7/test7.dsp @@ -0,0 +1,221 @@ +# Microsoft Developer Studio Project File - Name="test1" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=test1 - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "test1.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "test1.mak" CFG="test1 - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "test1 - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "test1 - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName ""$/boost/libs/numeric/ublas/test1", TDCAAAAA" +# PROP Scc_LocalPath "." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "test1 - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +dCPP=cl.exe +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\.." /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /Zm1000 /c +# ADD BASE RSC /l 0x407 /d "NDEBUG" +# ADD RSC /l 0x407 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "test1 - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +dCPP=cl.exe +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\.." /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /Zm1000 /c +# ADD BASE RSC /l 0x407 /d "_DEBUG" +# ADD RSC /l 0x407 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# SUBTRACT LINK32 /nodefaultlib + +!ENDIF + +# Begin Target + +# Name "test1 - Win32 Release" +# Name "test1 - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\test1.cpp +# End Source File +# Begin Source File + +SOURCE=.\test11.cpp +# End Source File +# Begin Source File + +SOURCE=.\test12.cpp +# End Source File +# Begin Source File + +SOURCE=.\test13.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\banded.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\blas.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\concepts.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\config.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\duff.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\exception.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\functional.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\hermitian.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\io.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\iterator.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\math.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\matrix.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\matrix_assign.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\matrix_expression.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\matrix_proxy.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\matrix_sparse.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\storage.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\storage_sparse.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\symmetric.hpp +# End Source File +# Begin Source File + +SOURCE=.\test1.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\traits.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\triangular.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\vector.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\vector_assign.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\vector_expression.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\vector_proxy.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\boost\numeric\ublas\vector_sparse.hpp +# End Source File +# End Group +# End Target +# End Project diff --git a/test7/test7.hpp b/test7/test7.hpp new file mode 100644 index 00000000..5a9d3f76 --- /dev/null +++ b/test7/test7.hpp @@ -0,0 +1,60 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifndef TEST7_H +#define TEST7_H + +namespace ublas = boost::numeric::ublas; + +template +void initialize_vector (V &v) { + int size = v.size (); + for (int i = 0; i < size; ++ i) + v [i] = typename V::value_type (i + 1.f); +} + +template +void initialize_matrix (M &m) { + int size1 = m.size1 (); + int size2 = m.size2 (); + for (int i = 0; i < size1; ++ i) + for (int j = 0; j < size2; ++ j) + m (i, j) = typename M::value_type (i * size1 + j + 1.f); +} + +void test_vector (); + +void test_matrix_vector (); + +void test_matrix (); + +// #define USE_FLOAT +#define USE_DOUBLE +// #define USE_STD_COMPLEX + +// #define USE_RANGE +// #define USE_SLICE + +// #define USE_BOUNDED_ARRAY +#define USE_UNBOUNDED_ARRAY +// #define USE_STD_VECTOR + +#define USE_MATRIX +// #define USE_VECTOR_OF_VECTOR + +#endif + + diff --git a/test7/test71.cpp b/test7/test71.cpp new file mode 100644 index 00000000..5689f9ab --- /dev/null +++ b/test7/test71.cpp @@ -0,0 +1,256 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include + +#include +#include +#include +#include + +#include "test7.hpp" + +// Test vector expression templates +template +struct test_my_vector { + typedef typename V::value_type value_type; + typedef typename V::size_type size_type; + typedef typename ublas::type_traits::real_type real_type; + + template + void operator () (VP &v1, VP &v2, VP &v3) const { + try { + value_type t; + size_type i; + real_type n; + + // Copy and swap + initialize_vector (v1); + initialize_vector (v2); + v1 = v2; + std::cout << "v1 = v2 = " << v1 << std::endl; + v1.assign_temporary (v2); + std::cout << "v1.assign_temporary (v2) = " << v1 << std::endl; + v1.swap (v2); + std::cout << "v1.swap (v2) = " << v1 << " " << v2 << std::endl; + + // Unary vector operations resulting in a vector + initialize_vector (v1); + v2 = - v1; + std::cout << "- v1 = " << v2 << std::endl; + v2 = ublas::conj (v1); + std::cout << "conj (v1) = " << v2 << std::endl; + + // Binary vector operations resulting in a vector + initialize_vector (v1); + initialize_vector (v2); + v3 = v1 + v2; + std::cout << "v1 + v2 = " << v3 << std::endl; + + v3 = v1 - v2; + std::cout << "v1 - v2 = " << v3 << std::endl; + + // Scaling a vector + t = value_type (N); + initialize_vector (v1); + v2 = value_type (1.) * v1; + std::cout << "1. * v1 = " << v2 << std::endl; + v2 = t * v1; + std::cout << "N * v1 = " << v2 << std::endl; + initialize_vector (v1); + v2 = v1 * value_type (1.); + std::cout << "v1 * 1. = " << v2 << std::endl; + v2 = v1 * t; + std::cout << "v1 * N = " << v2 << std::endl; + + // Some assignments + initialize_vector (v1); + initialize_vector (v2); +#ifdef BOOST_UBLAS_USE_ET + v2 += v1; + std::cout << "v2 += v1 = " << v2 << std::endl; + v2 -= v1; + std::cout << "v2 -= v1 = " << v2 << std::endl; +#else + v2 = v2 + v1; + std::cout << "v2 += v1 = " << v2 << std::endl; + v2 = v2 - v1; + std::cout << "v2 -= v1 = " << v2 << std::endl; +#endif + v1 *= value_type (1.); + std::cout << "v1 *= 1. = " << v1 << std::endl; + v1 *= t; + std::cout << "v1 *= N = " << v1 << std::endl; + + // Unary vector operations resulting in a scalar + initialize_vector (v1); + t = ublas::sum (v1); + std::cout << "sum (v1) = " << t << std::endl; + n = ublas::norm_1 (v1); + std::cout << "norm_1 (v1) = " << n << std::endl; + n = ublas::norm_2 (v1); + std::cout << "norm_2 (v1) = " << n << std::endl; + n = ublas::norm_inf (v1); + std::cout << "norm_inf (v1) = " << n << std::endl; + + i = ublas::index_norm_inf (v1); + std::cout << "index_norm_inf (v1) = " << i << std::endl; + + // Binary vector operations resulting in a scalar + initialize_vector (v1); + initialize_vector (v2); + t = ublas::inner_prod (v1, v2); + std::cout << "inner_prod (v1, v2) = " << t << std::endl; + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } + void operator () () const { + try { + V v1 (N), v2 (N), v3 (N); + (*this) (v1, v2, v3); + +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL +#ifdef USE_RANGE + ublas::vector_range vr1 (v1, ublas::range<> (0, N)), + vr2 (v2, ublas::range<> (0, N)), + vr3 (v3, ublas::range<> (0, N)); + (*this) (vr1, vr2, vr3); +#endif + +#ifdef USE_SLICE + ublas::vector_slice vs1 (v1, ublas::slice<> (0, 1, N)), + vs2 (v2, ublas::slice<> (0, 1, N)), + vs3 (v3, ublas::slice<> (0, 1, N)); + (*this) (vs1, vs2, vs3); +#endif +#else +#ifdef USE_RANGE + ublas::vector_range vr1 (v1, ublas::range (0, N)), + vr2 (v2, ublas::range (0, N)), + vr3 (v3, ublas::range (0, N)); + (*this) (vr1, vr2, vr3); +#endif + +#ifdef USE_SLICE + ublas::vector_slice vs1 (v1, ublas::slice (0, 1, N)), + vs2 (v2, ublas::slice (0, 1, N)), + vs3 (v3, ublas::slice (0, 1, N)); + (*this) (vs1, vs2, vs3); +#endif +#endif + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; + +// Test vector +void test_vector () { + std::cout << "test_vector" << std::endl; + +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval, bounded_array" << std::endl; + test_my_vector, ublas::bounded_array, 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval, bounded_array" << std::endl; + test_my_vector, ublas::bounded_array, 3> >, 3 > () (); +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT + std::cout << "boost::complex >, bounded_array" << std::endl; + test_my_vector >, ublas::bounded_array >, 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::complex >, bounded_array" << std::endl; + test_my_vector >, ublas::bounded_array >, 3> >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval, unbounded_array" << std::endl; + test_my_vector, ublas::unbounded_array > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval, unbounded_array" << std::endl; + test_my_vector, ublas::unbounded_array > >, 3 > () (); +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT + std::cout << "boost::complex >, unbounded_array" << std::endl; + test_my_vector >, ublas::unbounded_array > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::complex >, unbounded_array" << std::endl; + test_my_vector >, ublas::unbounded_array > > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval, std::vector" << std::endl; + test_my_vector, std::vector > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval, std::vector" << std::endl; + test_my_vector, std::vector > >, 3 > () (); +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT + std::cout << "boost::complex >, std::vector" << std::endl; + test_my_vector >, std::vector > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::complex >, std::vector" << std::endl; + test_my_vector >, std::vector > > >, 3 > () (); +#endif +#endif +#endif +} + diff --git a/test7/test72.cpp b/test7/test72.cpp new file mode 100644 index 00000000..468b06f7 --- /dev/null +++ b/test7/test72.cpp @@ -0,0 +1,295 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include + +#include +#include +#include +#include + +#include "test7.hpp" + +// Test matrix & vector expression templates +template +struct test_my_matrix_vector { + typedef typename V::value_type value_type; + + template + void operator () (VP &v1, VP &v2, MP &m1) const { + try { + // Rows and columns + initialize_matrix (m1); + for (int i = 0; i < N; ++ i) { + v1 = ublas::row (m1, i); + std::cout << "row (m, " << i << ") = " << v1 << std::endl; + v1 = ublas::column (m1, i); + std::cout << "column (m, " << i << ") = " << v1 << std::endl; + } + + // Outer product + initialize_vector (v1); + initialize_vector (v2); + m1 = ublas::outer_prod (v1, v2); + std::cout << "outer_prod (v1, v2) = " << m1 << std::endl; + + // Matrix vector product + initialize_matrix (m1); + initialize_vector (v1); + v2 = ublas::prod (m1, v1); + std::cout << "prod (m1, v1) = " << v2 << std::endl; + v2 = ublas::prod (v1, m1); + std::cout << "prod (v1, m1) = " << v2 << std::endl; + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } + void operator () () const { + try { + V v1 (N), v2 (N); + M m1 (N, N); + (*this) (v1, v2, m1); + + ublas::matrix_row mr1 (m1, 0), mr2 (m1, 1); + (*this) (mr1, mr2, m1); + + ublas::matrix_column mc1 (m1, 0), mc2 (m1, 1); + (*this) (mc1, mc2, m1); + +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL +#ifdef USE_RANGE_AND_SLICE + ublas::matrix_vector_range mvr1 (m1, ublas::range<> (0, N), ublas::range<> (0, N)), + mvr2 (m1, ublas::range<> (0, N), ublas::range<> (0, N)); + (*this) (mvr1, mvr2, m1); + + ublas::matrix_vector_slice mvs1 (m1, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)), + mvs2 (m1, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)); + (*this) (mvs1, mvs2, m1); +#endif +#else +#ifdef USE_RANGE_AND_SLICE + ublas::matrix_vector_range mvr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mvr2 (m1, ublas::range (0, N), ublas::range (0, N)); + (*this) (mvr1, mvr2, m1); + + ublas::matrix_vector_slice mvs1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + mvs2 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + (*this) (mvs1, mvs2, m1); +#endif +#endif + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; + +// Test matrix & vector +void test_matrix_vector () { + std::cout << "test_matrix_vector" << std::endl; + +#ifdef USE_MATRIX +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval, bounded_array" << std::endl; + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::matrix, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval, bounded_array" << std::endl; + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::matrix, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3> () (); +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT + std::cout << "boost::complex >, bounded_array" << std::endl; + test_my_matrix_vector >, ublas::bounded_array >, 3> >, + ublas::matrix >, ublas::row_major, ublas::bounded_array >, 3 * 3> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::complex >, bounded_array" << std::endl; + test_my_matrix_vector >, ublas::bounded_array >, 3> >, + ublas::matrix >, ublas::row_major, ublas::bounded_array >, 3 * 3> >, 3> () (); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval, unbounded_array" << std::endl; + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::matrix, ublas::row_major, ublas::unbounded_array > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval, unbounded_array" << std::endl; + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::matrix, ublas::row_major, ublas::unbounded_array > >, 3> () (); +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT + std::cout << "boost::complex >, unbounded_array" << std::endl; + test_my_matrix_vector >, ublas::unbounded_array > > >, + ublas::matrix >, ublas::row_major, ublas::unbounded_array > > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::complex >, unbounded_array" << std::endl; + test_my_matrix_vector >, ublas::unbounded_array > > >, + ublas::matrix >, ublas::row_major, ublas::unbounded_array > > >, 3> () (); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval, std::vector" << std::endl; + test_my_matrix_vector, std::vector > >, + ublas::matrix, ublas::row_major, std::vector > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval, std::vector" << std::endl; + test_my_matrix_vector, std::vector > >, + ublas::matrix, ublas::row_major, std::vector > >, 3> () (); +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT + std::cout << "boost::complex >, std::vector" << std::endl; + test_my_matrix_vector >, std::vector > > >, + ublas::matrix >, ublas::row_major, std::vector > > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::complex >, std::vector" << std::endl; + test_my_matrix_vector >, std::vector > > >, + ublas::matrix >, ublas::row_major, std::vector > > >, 3> () (); +#endif +#endif +#endif +#endif + +#ifdef USE_VECTOR_OF_VECTOR +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval, bounded_array" << std::endl; + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::vector_of_vector, ublas::row_major, ublas::bounded_array, 3>, 3 + 1> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval, bounded_array" << std::endl; + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::vector_of_vector, ublas::row_major, ublas::bounded_array, 3>, 3 + 1> >, 3> () (); +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT + std::cout << "boost::complex >, bounded_array" << std::endl; + test_my_matrix_vector >, ublas::bounded_array >, 3> >, + ublas::vector_of_vector >, ublas::row_major, ublas::bounded_array >, 3>, 3 + 1> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::complex >, bounded_array" << std::endl; + test_my_matrix_vector >, ublas::bounded_array >, 3> >, + ublas::vector_of_vector >, ublas::row_major, ublas::bounded_array >, 3>, 3 + 1> >, 3> () (); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval, unbounded_array" << std::endl; + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::vector_of_vector, ublas::row_major, ublas::unbounded_array > > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval, unbounded_array" << std::endl; + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::vector_of_vector, ublas::row_major, ublas::unbounded_array > > >, 3> () (); +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT + std::cout << "boost::complex >, unbounded_array" << std::endl; + test_my_matrix_vector >, ublas::unbounded_array > > >, + ublas::vector_of_vector >, ublas::row_major, ublas::unbounded_array > > > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::complex >, unbounded_array" << std::endl; + test_my_matrix_vector >, ublas::unbounded_array > > >, + ublas::vector_of_vector >, ublas::row_major, ublas::unbounded_array > > > >, 3> () (); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval, std::vector" << std::endl; + test_my_matrix_vector, std::vector > >, + ublas::vector_of_vector, ublas::row_major, std::vector > > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval, std::vector" << std::endl; + test_my_matrix_vector, std::vector > >, + ublas::vector_of_vector, ublas::row_major, std::vector > > >, 3> () (); +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT + std::cout << "boost::complex >, std::vector" << std::endl; + test_my_matrix_vector >, std::vector > > >, + ublas::vector_of_vector >, ublas::row_major, std::vector > > > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::complex >, std::vector" << std::endl; + test_my_matrix_vector >, std::vector > > >, + ublas::vector_of_vector >, ublas::row_major, std::vector > > > >, 3> () (); +#endif +#endif +#endif +#endif +} + + diff --git a/test7/test73.cpp b/test7/test73.cpp new file mode 100644 index 00000000..90a88608 --- /dev/null +++ b/test7/test73.cpp @@ -0,0 +1,323 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. The authors make no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include +#include + +#include +#include +#include +#include + +#include "test7.hpp" + +// Test matrix expression templates +template +struct test_my_matrix { + typedef typename M::value_type value_type; + + template + void operator () (MP &m1, MP &m2, MP &m3) const { + try { + value_type t; + + // Copy and swap + initialize_matrix (m1); + initialize_matrix (m2); + m1 = m2; + std::cout << "m1 = m2 = " << m1 << std::endl; + m1.assign_temporary (m2); + std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl; + m1.swap (m2); + std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl; + + // Unary matrix operations resulting in a matrix + initialize_matrix (m1); + m2 = - m1; + std::cout << "- m1 = " << m2 << std::endl; + m2 = ublas::conj (m1); + std::cout << "conj (m1) = " << m2 << std::endl; + + // Binary matrix operations resulting in a matrix + initialize_matrix (m1); + initialize_matrix (m2); + m3 = m1 + m2; + std::cout << "m1 + m2 = " << m3 << std::endl; + m3 = m1 - m2; + std::cout << "m1 - m2 = " << m3 << std::endl; + + // Scaling a matrix + t = N; + initialize_matrix (m1); + m2 = value_type (1.) * m1; + std::cout << "1. * m1 = " << m2 << std::endl; + m2 = t * m1; + std::cout << "N * m1 = " << m2 << std::endl; + initialize_matrix (m1); + m2 = m1 * value_type (1.); + std::cout << "m1 * 1. = " << m2 << std::endl; + m2 = m1 * t; + std::cout << "m1 * N = " << m2 << std::endl; + + // Some assignments + initialize_matrix (m1); + initialize_matrix (m2); +#ifdef BOOST_UBLAS_USE_ET + m2 += m1; + std::cout << "m2 += m1 = " << m2 << std::endl; + m2 -= m1; + std::cout << "m2 -= m1 = " << m2 << std::endl; +#else + m2 = m2 + m1; + std::cout << "m2 += m1 = " << m2 << std::endl; + m2 = m2 - m1; + std::cout << "m2 -= m1 = " << m2 << std::endl; +#endif + m1 *= value_type (1.); + std::cout << "m1 *= 1. = " << m1 << std::endl; + m1 *= t; + std::cout << "m1 *= N = " << m1 << std::endl; + + // Transpose + initialize_matrix (m1); + m2 = ublas::trans (m1); + std::cout << "trans (m1) = " << m2 << std::endl; + + // Hermitean + initialize_matrix (m1); + m2 = ublas::herm (m1); + std::cout << "herm (m1) = " << m2 << std::endl; + + // Matrix multiplication + initialize_matrix (m1); + initialize_matrix (m2); + m3 = ublas::prod (m1, m2); + std::cout << "prod (m1, m2) = " << m3 << std::endl; + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } + void operator () () const { + try { + M m1 (N, N), m2 (N, N), m3 (N, N); + (*this) (m1, m2, m3); + +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL +#ifdef USE_RANGE + ublas::matrix_range mr1 (m1, ublas::range<> (0, N), ublas::range<> (0, N)), + mr2 (m2, ublas::range<> (0, N), ublas::range<> (0, N)), + mr3 (m3, ublas::range<> (0, N), ublas::range<> (0, N)); + (*this) (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice ms1 (m1, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)), + ms2 (m2, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)), + ms3 (m3, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)); + (*this) (ms1, ms2, ms3); +#endif +#else +#ifdef USE_RANGE + ublas::matrix_range mr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mr2 (m2, ublas::range (0, N), ublas::range (0, N)), + mr3 (m3, ublas::range (0, N), ublas::range (0, N)); + (*this) (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice ms1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms2 (m2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms3 (m3, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + (*this) (ms1, ms2, ms3); +#endif +#endif + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } + } +}; + +// Test matrix +void test_matrix () { + std::cout << "test_matrix" << std::endl; + +#ifdef USE_MATRIX +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval, bounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval, bounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (); +#endif + +#ifdef BOOST_UBLAS_NEED_ANOTHER_COMPLEX_CLASS +#ifdef USE_FLOAT + std::cout << "boost::complex >, bounded_array" << std::endl; + test_my_matrix >, ublas::row_major, ublas::bounded_array >, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::complex >, bounded_array" << std::endl; + test_my_matrix >, ublas::row_major, ublas::bounded_array >, 3 * 3> >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval, unbounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::unbounded_array > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval, unbounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::unbounded_array > >, 3 > () (); +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT + std::cout << "boost::complex >, unbounded_array" << std::endl; + test_my_matrix >, ublas::row_major, ublas::unbounded_array > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::complex >, unbounded_array" << std::endl; + test_my_matrix >, ublas::row_major, ublas::unbounded_array > > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval, std::vector" << std::endl; + test_my_matrix, ublas::row_major, std::vector > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval, std::vector" << std::endl; + test_my_matrix, ublas::row_major, std::vector > >, 3 > () (); +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT + std::cout << "boost::complex >, std::vector" << std::endl; + test_my_matrix >, ublas::row_major, std::vector > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::complex >, std::vector" << std::endl; + test_my_matrix >, ublas::row_major, std::vector > > >, 3 > () (); +#endif +#endif +#endif +#endif + +#ifdef USE_VECTOR_OF_VECTOR +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval, bounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::bounded_array, 3>, 3 + 1> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval, bounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::bounded_array, 3>, 3 + 1> >, 3 > () (); +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT + std::cout << "boost::complex >, bounded_array" << std::endl; + test_my_matrix >, ublas::row_major, ublas::bounded_array >, 3>, 3 + 1> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::complex >, bounded_array" << std::endl; + test_my_matrix >, ublas::row_major, ublas::bounded_array >, 3>, 3 + 1> >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval, unbounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::unbounded_array > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval, unbounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::unbounded_array > > >, 3 > () (); +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT + std::cout << "boost::complex >, unbounded_array" << std::endl; + test_my_matrix >, ublas::row_major, ublas::unbounded_array > > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::complex >, unbounded_array" << std::endl; + test_my_matrix >, ublas::row_major, ublas::unbounded_array > > > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval, std::vector" << std::endl; + test_my_matrix, ublas::row_major, std::vector > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval, std::vector" << std::endl; + test_my_matrix, ublas::row_major, std::vector > > >, 3 > () (); +#endif + +#ifdef USE_BOOST_COMPLEX +#ifdef USE_FLOAT + std::cout << "boost::complex >, std::vector" << std::endl; + test_my_matrix >, ublas::row_major, std::vector > > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::complex >, std::vector" << std::endl; + test_my_matrix >, ublas::row_major, std::vector > > > >, 3 > () (); +#endif +#endif +#endif +#endif +} + + +