From 4cde2a80db7f82bb115967fc1c697f7ea462752b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Walter?= Date: Sat, 14 Sep 2002 09:48:41 +0000 Subject: [PATCH] Merge. [SVN r15321] --- Jamfile | 20 + bench1/Jamfile | 24 + bench1/bench1.cpp | 220 +++ bench1/bench1.dsp | 214 +++ bench1/bench1.hpp | 156 ++ bench1/bench11.cpp | 307 ++++ bench1/bench12.cpp | 524 +++++++ bench1/bench13.cpp | 206 +++ bench2/Jamfile | 10 + bench2/bench2.cpp | 219 +++ bench2/bench2.dsp | 214 +++ bench2/bench2.hpp | 170 +++ bench2/bench21.cpp | 270 ++++ bench2/bench22.cpp | 442 ++++++ bench2/bench23.cpp | 189 +++ bench3/Jamfile | 11 + bench3/bench3.cpp | 217 +++ bench3/bench3.dsp | 214 +++ bench3/bench3.hpp | 156 ++ bench3/bench31.cpp | 336 +++++ bench3/bench32.cpp | 568 +++++++ bench3/bench33.cpp | 223 +++ concepts.cpp | 57 + concepts.dsp | 282 ++++ doc/banded.htm | 1206 +++++++++++++++ doc/c++boost.gif | Bin 0 -> 8819 bytes doc/container.htm | 393 +++++ doc/expression.htm | 1033 +++++++++++++ doc/hermitian.htm | 1208 +++++++++++++++ doc/index.htm | 316 ++++ doc/iterator.htm | 1251 ++++++++++++++++ doc/matrix.htm | 1242 +++++++++++++++ doc/matrix_expression.htm | 3002 +++++++++++++++++++++++++++++++++++++ doc/matrix_proxy.htm | 2727 +++++++++++++++++++++++++++++++++ doc/matrix_sparse.htm | 622 ++++++++ doc/overview.htm | 1534 +++++++++++++++++++ doc/readme.txt | 20 + doc/storage.htm | 860 +++++++++++ doc/storage_sparse.htm | 310 ++++ doc/symmetric.htm | 1209 +++++++++++++++ doc/triangular.htm | 1218 +++++++++++++++ doc/vector.htm | 898 +++++++++++ doc/vector_expression.htm | 1760 ++++++++++++++++++++++ doc/vector_proxy.htm | 861 +++++++++++ doc/vector_sparse.htm | 448 ++++++ test1/Jamfile | 13 + test1/test1.cpp | 36 + test1/test1.dsp | 221 +++ test1/test1.hpp | 40 + test1/test11.cpp | 207 +++ test1/test12.cpp | 216 +++ test1/test13.cpp | 246 +++ test2/Jamfile | 10 + test2/test2.cpp | 81 + test2/test2.dsp | 218 +++ test2/test2.hpp | 72 + test2/test21.cpp | 97 ++ test2/test22.cpp | 150 ++ test2/test23.cpp | 210 +++ test3/Jamfile | 10 + test3/test3.cpp | 37 + test3/test3.dsp | 219 +++ test3/test3.hpp | 48 + test3/test31.cpp | 211 +++ test3/test32.cpp | 200 +++ test3/test33.cpp | 233 +++ test4/Jamfile | 10 + test4/test4.cpp | 36 + test4/test4.dsp | 219 +++ test4/test4.hpp | 40 + test4/test41.cpp | 208 +++ test4/test42.cpp | 226 +++ test4/test43.cpp | 255 ++++ test5/Jamfile | 10 + test5/test5.cpp | 36 + test5/test5.dsp | 219 +++ test5/test5.hpp | 65 + test5/test51.cpp | 208 +++ test5/test52.cpp | 226 +++ test5/test53.cpp | 255 ++++ test6/Jamfile | 10 + test6/test6.cpp | 37 + test6/test6.dsp | 219 +++ test6/test6.hpp | 65 + test6/test61.cpp | 209 +++ test6/test62.cpp | 229 +++ test6/test63.cpp | 256 ++++ ublas.dsw | 181 +++ 88 files changed, 33361 insertions(+) create mode 100644 Jamfile create mode 100644 bench1/Jamfile create mode 100644 bench1/bench1.cpp create mode 100644 bench1/bench1.dsp create mode 100644 bench1/bench1.hpp create mode 100644 bench1/bench11.cpp create mode 100644 bench1/bench12.cpp create mode 100644 bench1/bench13.cpp create mode 100644 bench2/Jamfile create mode 100644 bench2/bench2.cpp create mode 100644 bench2/bench2.dsp create mode 100644 bench2/bench2.hpp create mode 100644 bench2/bench21.cpp create mode 100644 bench2/bench22.cpp create mode 100644 bench2/bench23.cpp create mode 100644 bench3/Jamfile create mode 100644 bench3/bench3.cpp create mode 100644 bench3/bench3.dsp create mode 100644 bench3/bench3.hpp create mode 100644 bench3/bench31.cpp create mode 100644 bench3/bench32.cpp create mode 100644 bench3/bench33.cpp create mode 100644 concepts.cpp create mode 100644 concepts.dsp create mode 100644 doc/banded.htm create mode 100644 doc/c++boost.gif create mode 100644 doc/container.htm create mode 100644 doc/expression.htm create mode 100644 doc/hermitian.htm create mode 100644 doc/index.htm create mode 100644 doc/iterator.htm create mode 100644 doc/matrix.htm create mode 100644 doc/matrix_expression.htm create mode 100644 doc/matrix_proxy.htm create mode 100644 doc/matrix_sparse.htm create mode 100644 doc/overview.htm create mode 100644 doc/readme.txt create mode 100644 doc/storage.htm create mode 100644 doc/storage_sparse.htm create mode 100644 doc/symmetric.htm create mode 100644 doc/triangular.htm create mode 100644 doc/vector.htm create mode 100644 doc/vector_expression.htm create mode 100644 doc/vector_proxy.htm create mode 100644 doc/vector_sparse.htm create mode 100644 test1/Jamfile create mode 100644 test1/test1.cpp create mode 100644 test1/test1.dsp create mode 100644 test1/test1.hpp create mode 100644 test1/test11.cpp create mode 100644 test1/test12.cpp create mode 100644 test1/test13.cpp create mode 100644 test2/Jamfile create mode 100644 test2/test2.cpp create mode 100644 test2/test2.dsp create mode 100644 test2/test2.hpp create mode 100644 test2/test21.cpp create mode 100644 test2/test22.cpp create mode 100644 test2/test23.cpp create mode 100644 test3/Jamfile create mode 100644 test3/test3.cpp create mode 100644 test3/test3.dsp create mode 100644 test3/test3.hpp create mode 100644 test3/test31.cpp create mode 100644 test3/test32.cpp create mode 100644 test3/test33.cpp create mode 100644 test4/Jamfile create mode 100644 test4/test4.cpp create mode 100644 test4/test4.dsp create mode 100644 test4/test4.hpp create mode 100644 test4/test41.cpp create mode 100644 test4/test42.cpp create mode 100644 test4/test43.cpp create mode 100644 test5/Jamfile create mode 100644 test5/test5.cpp create mode 100644 test5/test5.dsp create mode 100644 test5/test5.hpp create mode 100644 test5/test51.cpp create mode 100644 test5/test52.cpp create mode 100644 test5/test53.cpp create mode 100644 test6/Jamfile create mode 100644 test6/test6.cpp create mode 100644 test6/test6.dsp create mode 100644 test6/test6.hpp create mode 100644 test6/test61.cpp create mode 100644 test6/test62.cpp create mode 100644 test6/test63.cpp create mode 100644 ublas.dsw diff --git a/Jamfile b/Jamfile new file mode 100644 index 00000000..13f90636 --- /dev/null +++ b/Jamfile @@ -0,0 +1,20 @@ +subproject libs/numeric/ublas ; +subinclude libs/numeric/ublas/test1 ; +subinclude libs/numeric/ublas/test2 ; +subinclude libs/numeric/ublas/test3 ; +subinclude libs/numeric/ublas/test4 ; +subinclude libs/numeric/ublas/test5 ; +subinclude libs/numeric/ublas/test6 ; +subinclude libs/numeric/ublas/bench1 ; +subinclude libs/numeric/ublas/bench2 ; +subinclude libs/numeric/ublas/bench3 ; + +SOURCES = concepts ; + +exe concepts + : $(SOURCES).cpp + : $(BOOST_ROOT) + : EXTERNAL + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" + ; + diff --git a/bench1/Jamfile b/bench1/Jamfile new file mode 100644 index 00000000..c211a1e1 --- /dev/null +++ b/bench1/Jamfile @@ -0,0 +1,24 @@ +subproject libs/numeric/ublas/bench1 ; + +SOURCES = bench1 bench11 bench12 bench13 ; + +exe bench1 + : $(SOURCES).cpp + : $(BOOST_ROOT) + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" + <*>"-tpp7" + ; + + + + + + + + + + + + + + diff --git a/bench1/bench1.cpp b/bench1/bench1.cpp new file mode 100644 index 00000000..f4afef6b --- /dev/null +++ b/bench1/bench1.cpp @@ -0,0 +1,220 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include +#include + +#include +#include +#include + +#include + +#include "bench1.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; +template struct peak >; +template struct peak >; + +#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 + + header ("float"); + peak () (100000000); + + header ("double"); + peak () (100000000); + +#ifdef USE_COMPLEX + header ("std:complex"); + peak > () (100000000); + + header ("std:complex"); + peak > () (100000000); +#endif + + int scale = 1; + if (argc > 1) + scale = atoi (argv [1]); + + header ("float, 3"); + + bench_1 () (1000000 * scale); + bench_2 () (300000 * scale); + bench_3 () (100000 * scale); + + header ("float, 10"); + + bench_1 () (300000 * scale); + bench_2 () (30000 * scale); + bench_3 () (3000 * scale); + + header ("float, 30"); + + bench_1 () (100000 * scale); + bench_2 () (3000 * scale); + bench_3 () (100 * scale); + + header ("float, 100"); + + bench_1 () (30000 * scale); + bench_2 () (300 * scale); + bench_3 () (3 * scale); + + header ("double, 3"); + + bench_1 () (1000000 * scale); + bench_2 () (300000 * scale); + bench_3 () (100000 * scale); + + header ("double, 10"); + + bench_1 () (300000 * scale); + bench_2 () (30000 * scale); + bench_3 () (3000 * scale); + + header ("double, 30"); + + bench_1 () (100000 * scale); + bench_2 () (3000 * scale); + bench_3 () (100 * scale); + + header ("double, 100"); + + bench_1 () (30000 * scale); + bench_2 () (300 * scale); + bench_3 () (3 * scale); + +#ifdef USE_STD_COMPLEX + header ("std::complex, 3"); + + bench_1, 3> () (1000000 * scale); + bench_2, 3> () (300000 * scale); + bench_3, 3> () (100000 * scale); + + header ("std::complex, 10"); + + bench_1, 10> () (300000 * scale); + bench_2, 10> () (30000 * scale); + bench_3, 10> () (3000 * scale); + + header ("std::complex, 30"); + + bench_1, 30> () (100000 * scale); + bench_2, 30> () (3000 * scale); + bench_3, 30> () (100 * scale); + + header ("std::complex, 100"); + + bench_1, 100> () (30000 * scale); + bench_2, 100> () (300 * scale); + bench_3, 100> () (3 * scale); + + header ("std::complex, 3"); + + bench_1, 3> () (1000000 * scale); + bench_2, 3> () (300000 * scale); + bench_3, 3> () (100000 * scale); + + header ("std::complex, 10"); + + bench_1, 10> () (300000 * scale); + bench_2, 10> () (30000 * scale); + bench_3, 10> () (3000 * scale); + + header ("std::complex, 30"); + + bench_1, 30> () (100000 * scale); + bench_2, 30> () (3000 * scale); + bench_3, 30> () (100 * scale); + + header ("std::complex, 100"); + + bench_1, 100> () (30000 * scale); + bench_2, 100> () (300 * scale); + bench_3, 100> () (3 * scale); +#endif + + return 0; +} + + + + diff --git a/bench1/bench1.dsp b/bench1/bench1.dsp new file mode 100644 index 00000000..f3c2dd46 --- /dev/null +++ b/bench1/bench1.dsp @@ -0,0 +1,214 @@ +# Microsoft Developer Studio Project File - Name="bench1" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=bench1 - 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 "bench1.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 "bench1.mak" CFG="bench1 - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "bench1 - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "bench1 - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName ""$/boost/libs/numeric/bench1", ACCAAAAA" +# PROP Scc_LocalPath "." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "bench1 - 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 /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)" == "bench1 - 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 "bench1 - Win32 Release" +# Name "bench1 - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\bench1.cpp +# End Source File +# Begin Source File + +SOURCE=.\bench11.cpp +# End Source File +# Begin Source File + +SOURCE=.\bench12.cpp +# End Source File +# Begin Source File + +SOURCE=.\bench13.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=.\bench1.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/bench1/bench1.hpp b/bench1/bench1.hpp new file mode 100644 index 00000000..c58a910a --- /dev/null +++ b/bench1/bench1.hpp @@ -0,0 +1,156 @@ +#ifndef BENCH1_H +#define BENCH1_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_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/bench1/bench11.cpp b/bench1/bench11.cpp new file mode 100644 index 00000000..8668ec44 --- /dev/null +++ b/bench1/bench11.cpp @@ -0,0 +1,307 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include +#include + +#include +#include +#include + +#include + +#include "bench1.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 { + 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 = ublas::inner_prod (v1, v2); +// 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 { + 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; + } + } + void operator () (int runs, fast_tag) 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.assign (- (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; + } + } +}; +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 +} + +template struct bench_1; +template struct bench_1; +template struct bench_1; +template struct bench_1; + +template struct bench_1; +template struct bench_1; +template struct bench_1; +template struct bench_1; + +#ifdef USE_STD_COMPLEX + +template struct bench_1, 3>; +template struct bench_1, 10>; +template struct bench_1, 30>; +template struct bench_1, 100>; + +template struct bench_1, 3>; +template struct bench_1, 10>; +template struct bench_1, 30>; +template struct bench_1, 100>; + +#endif + + diff --git a/bench1/bench12.cpp b/bench1/bench12.cpp new file mode 100644 index 00000000..ec269c7f --- /dev/null +++ b/bench1/bench12.cpp @@ -0,0 +1,524 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include +#include + +#include +#include +#include + +#include + +#include "bench1.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 { + 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) { + m = - ublas::outer_prod (v1, v2); +// sink_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; + } + } + void operator () (int runs, fast_tag) 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) { + m.assign (- ublas::outer_prod (v1, v2)); +// sink_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_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 { + static M m (N, N); + static V v1 (N), v2 (N); + initialize_matrix (m); + initialize_vector (v1); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + v2 = ublas::prod (m, v1); +// 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; + } + } + void operator () (int runs, fast_tag) const { + try { + static M m (N, N); + static V v1 (N), v2 (N); + initialize_matrix (m); + initialize_vector (v1); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + v2.assign (ublas::prod (m, v1)); +// 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_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 +} + +template struct bench_2; +template struct bench_2; +template struct bench_2; +template struct bench_2; + +template struct bench_2; +template struct bench_2; +template struct bench_2; +template struct bench_2; + +#ifdef USE_STD_COMPLEX + +template struct bench_2, 3>; +template struct bench_2, 10>; +template struct bench_2, 30>; +template struct bench_2, 100>; + +template struct bench_2, 3>; +template struct bench_2, 10>; +template struct bench_2, 30>; +template struct bench_2, 100>; + +#endif + + diff --git a/bench1/bench13.cpp b/bench1/bench13.cpp new file mode 100644 index 00000000..a7fef89a --- /dev/null +++ b/bench1/bench13.cpp @@ -0,0 +1,206 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include +#include + +#include +#include +#include + +#include + +#include "bench1.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); + initialize_matrix (m1); + initialize_matrix (m2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + m3 = ublas::prod (m1, m2); +// sink_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; + } + } + 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 (ublas::prod (m1, m2)); +// sink_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_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 +} + +template struct bench_3; +template struct bench_3; +template struct bench_3; +template struct bench_3; + +template struct bench_3; +template struct bench_3; +template struct bench_3; +template struct bench_3; + +#ifdef USE_STD_COMPLEX + +template struct bench_3, 3>; +template struct bench_3, 10>; +template struct bench_3, 30>; +template struct bench_3, 100>; + +template struct bench_3, 3>; +template struct bench_3, 10>; +template struct bench_3, 30>; +template struct bench_3, 100>; + +#endif + + + diff --git a/bench2/Jamfile b/bench2/Jamfile new file mode 100644 index 00000000..e9273401 --- /dev/null +++ b/bench2/Jamfile @@ -0,0 +1,10 @@ +subproject libs/numeric/ublas/bench2 ; + +SOURCES = bench2 bench21 bench22 bench23 ; + +exe bench2 + : $(SOURCES).cpp + : $(BOOST_ROOT) + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" + ; + diff --git a/bench2/bench2.cpp b/bench2/bench2.cpp new file mode 100644 index 00000000..98fe7fb8 --- /dev/null +++ b/bench2/bench2.cpp @@ -0,0 +1,219 @@ +#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 "bench2.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; +template struct peak >; +template struct peak >; + +#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 + + header ("float"); + peak () (100000000); + + header ("double"); + peak () (100000000); + +#ifdef USE_STD_COMPLEX + header ("std:complex"); + peak > () (100000000); + + header ("std:complex"); + peak > () (100000000); +#endif + + int scale = 1; + if (argc > 1) + scale = atoi (argv [1]); + + header ("float, 3"); + + bench_1 () (1000000 * scale); + bench_2 () (300000 * scale); + bench_3 () (100000 * scale); + + header ("float, 10"); + + bench_1 () (300000 * scale); + bench_2 () (30000 * scale); + bench_3 () (3000 * scale); + + header ("float, 30"); + + bench_1 () (100000 * scale); + bench_2 () (3000 * scale); + bench_3 () (100 * scale); + + header ("float, 100"); + + bench_1 () (30000 * scale); + bench_2 () (300 * scale); + bench_3 () (3 * scale); + + header ("double, 3"); + + bench_1 () (1000000 * scale); + bench_2 () (300000 * scale); + bench_3 () (100000 * scale); + + header ("double, 10"); + + bench_1 () (300000 * scale); + bench_2 () (30000 * scale); + bench_3 () (3000 * scale); + + header ("double, 30"); + + bench_1 () (100000 * scale); + bench_2 () (3000 * scale); + bench_3 () (100 * scale); + + header ("double, 100"); + + bench_1 () (30000 * scale); + bench_2 () (300 * scale); + bench_3 () (3 * scale); + +#ifdef USE_STD_COMPLEX + header ("std::complex, 3"); + + bench_1, 3> () (1000000 * scale); + bench_2, 3> () (300000 * scale); + bench_3, 3> () (100000 * scale); + + header ("std::complex, 10"); + + bench_1, 10> () (300000 * scale); + bench_2, 10> () (30000 * scale); + bench_3, 10> () (3000 * scale); + + header ("std::complex, 30"); + + bench_1, 30> () (100000 * scale); + bench_2, 30> () (3000 * scale); + bench_3, 30> () (100 * scale); + + header ("std::complex, 100"); + + bench_1, 100> () (30000 * scale); + bench_2, 100> () (300 * scale); + bench_3, 100> () (3 * scale); + + header ("std::complex, 3"); + + bench_1, 3> () (1000000 * scale); + bench_2, 3> () (300000 * scale); + bench_3, 3> () (100000 * scale); + + header ("std::complex, 10"); + + bench_1, 10> () (300000 * scale); + bench_2, 10> () (30000 * scale); + bench_3, 10> () (3000 * scale); + + header ("std::complex, 30"); + + bench_1, 30> () (100000 * scale); + bench_2, 30> () (3000 * scale); + bench_3, 30> () (100 * scale); + + header ("std::complex, 100"); + + bench_1, 100> () (30000 * scale); + bench_2, 100> () (300 * scale); + bench_3, 100> () (3 * scale); +#endif + + return 0; +} + diff --git a/bench2/bench2.dsp b/bench2/bench2.dsp new file mode 100644 index 00000000..84d4b9f5 --- /dev/null +++ b/bench2/bench2.dsp @@ -0,0 +1,214 @@ +# Microsoft Developer Studio Project File - Name="bench2" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=bench2 - 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 "bench2.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 "bench2.mak" CFG="bench2 - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "bench2 - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "bench2 - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName ""$/boost/libs/numeric/ublas/bench2", LDCAAAAA" +# PROP Scc_LocalPath "." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "bench2 - 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 /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)" == "bench2 - 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 "bench2 - Win32 Release" +# Name "bench2 - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\bench2.cpp +# End Source File +# Begin Source File + +SOURCE=.\bench21.cpp +# End Source File +# Begin Source File + +SOURCE=.\bench22.cpp +# End Source File +# Begin Source File + +SOURCE=.\bench23.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=.\bench2.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/bench2/bench2.hpp b/bench2/bench2.hpp new file mode 100644 index 00000000..64b788c7 --- /dev/null +++ b/bench2/bench2.hpp @@ -0,0 +1,170 @@ +#ifndef BENCH2_H +#define BENCH2_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, 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) + m (i, j) = rand () * 1.f; +// m (i, j) = 0.f; +} +template +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) + m (i, j) = rand () * 1.f; +// m (i, j) = 0.f; +} +template +BOOST_UBLAS_INLINE +void initialize_matrix (M &m) { + typedef BOOST_UBLAS_TYPENAME M::orientation_category orientation_category; + initialize_matrix (m, orientation_category ()); +} + +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_STD_COMPLEX + +#define USE_MAP_ARRAY +// #define USE_STD_MAP +// #define USE_STD_VALARRAY + +#endif + + diff --git a/bench2/bench21.cpp b/bench2/bench21.cpp new file mode 100644 index 00000000..08ee6e1e --- /dev/null +++ b/bench2/bench21.cpp @@ -0,0 +1,270 @@ +#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 "bench2.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 { + static V v1 (N, N), v2 (N, N); + initialize_vector (v1); + initialize_vector (v2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + static value_type s (0); + s = ublas::inner_prod (v1, v2); +// 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 { + static V v1 (N, N), v2 (N, N), v3 (N, 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; + } + } + void operator () (int runs, fast_tag) const { + try { + static V v1 (N, N), v2 (N, N), v3 (N, N); + initialize_vector (v1); + initialize_vector (v2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + v3.assign (- (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; + } + } +}; +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_MAP_ARRAY + header ("sparse_vector"); + bench_my_inner_prod >, N> () (runs); +#endif + +#ifdef USE_STD_MAP + header ("sparse_vector"); + bench_my_inner_prod >, N> () (runs); +#endif + +#ifdef USE_STD_VALARRAY + header ("std::valarray"); + bench_cpp_inner_prod, N> () (runs); +#endif + + header ("sparse_vector + sparse_vector"); + + header ("C array"); + bench_c_vector_add () (runs); + +#ifdef USE_MAP_ARRAY + header ("sparse_vector safe"); + bench_my_vector_add >, N> () (runs, safe_tag ()); + + header ("sparse_vector fast"); + bench_my_vector_add >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_MAP + header ("sparse_vector safe"); + bench_my_vector_add >, N> () (runs, safe_tag ()); + + header ("sparse_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 +} + +template struct bench_1; +template struct bench_1; +template struct bench_1; +template struct bench_1; + +template struct bench_1; +template struct bench_1; +template struct bench_1; +template struct bench_1; + +#ifdef USE_STD_COMPLEX + +template struct bench_1, 3>; +template struct bench_1, 10>; +template struct bench_1, 30>; +template struct bench_1, 100>; + +template struct bench_1, 3>; +template struct bench_1, 10>; +template struct bench_1, 30>; +template struct bench_1, 100>; + +#endif + + diff --git a/bench2/bench22.cpp b/bench2/bench22.cpp new file mode 100644 index 00000000..64ab76f8 --- /dev/null +++ b/bench2/bench22.cpp @@ -0,0 +1,442 @@ +#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 "bench2.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 { + static M m (N, N, N * N); + static V v1 (N, N), v2 (N, N); + initialize_vector (v1); + initialize_vector (v2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + m = - ublas::outer_prod (v1, v2); +// sink_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; + } + } + void operator () (int runs, fast_tag) const { + try { + static M m (N, N, N * N); + static V v1 (N, N), v2 (N, N); + initialize_vector (v1); + initialize_vector (v2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + m.assign (- ublas::outer_prod (v1, v2)); +// sink_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_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 { + static M m (N, N, N * N); + static V v1 (N, N), v2 (N, N); + initialize_matrix (m); + initialize_vector (v1); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + v2 = ublas::prod (m, v1); +// 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; + } + } + void operator () (int runs, fast_tag) const { + try { + static M m (N, N, N * N); + static V v1 (N, N), v2 (N, N); + initialize_matrix (m); + initialize_vector (v1); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + v2.assign (ublas::prod (m, v1)); +// 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_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, N * N), m2 (N, N, N * N), m3 (N, N, 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, N * N), m2 (N, N, N * N), m3 (N, N, 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_MAP_ARRAY + header ("sparse_matrix, sparse_vector safe"); + bench_my_outer_prod >, + ublas::sparse_vector >, N> () (runs, safe_tag ()); + + header ("sparse_matrix, sparse_vector fast"); + bench_my_outer_prod >, + ublas::sparse_vector >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_MAP + header ("sparse_matrix, sparse_vector safe"); + bench_my_outer_prod >, + ublas::sparse_vector >, N> () (runs, safe_tag ()); + + header ("sparse_matrix, sparse_vector fast"); + bench_my_outer_prod >, + ublas::sparse_vector >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VALARRAY + header ("std::valarray"); + bench_cpp_outer_prod, std::valarray, N> () (runs); +#endif + + header ("prod (sparse_matrix, sparse_vector)"); + + header ("C array"); + bench_c_matrix_vector_prod () (runs); + +#ifdef USE_MAP_ARRAY + header ("sparse_matrix, sparse_vector safe"); + bench_my_matrix_vector_prod >, + ublas::sparse_vector >, N> () (runs, safe_tag ()); + + header ("sparse_matrix, sparse_vector fast"); + bench_my_matrix_vector_prod >, + ublas::sparse_vector >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_MAP + header ("sparse_matrix, sparse_vector safe"); + bench_my_matrix_vector_prod >, + ublas::sparse_vector >, N> () (runs, safe_tag ()); + + header ("sparse_matrix, sparse_vector fast"); + bench_my_matrix_vector_prod >, + ublas::sparse_vector >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VALARRAY + header ("std::valarray"); + bench_cpp_matrix_vector_prod, std::valarray, N> () (runs); +#endif + + header ("sparse_matrix + sparse_matrix"); + + header ("C array"); + bench_c_matrix_add () (runs); + +#ifdef USE_MAP_ARRAY + header ("sparse_matrix safe"); + bench_my_matrix_add >, N> () (runs, safe_tag ()); + + header ("sparse_matrix fast"); + bench_my_matrix_add >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_MAP + header ("sparse_matrix safe"); + bench_my_matrix_add >, N> () (runs, safe_tag ()); + + header ("sparse_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 +} + +template struct bench_2; +template struct bench_2; +template struct bench_2; +template struct bench_2; + +template struct bench_2; +template struct bench_2; +template struct bench_2; +template struct bench_2; + +#ifdef USE_STD_COMPLEX + +template struct bench_2, 3>; +template struct bench_2, 10>; +template struct bench_2, 30>; +template struct bench_2, 100>; + +template struct bench_2, 3>; +template struct bench_2, 10>; +template struct bench_2, 30>; +template struct bench_2, 100>; + +#endif + + diff --git a/bench2/bench23.cpp b/bench2/bench23.cpp new file mode 100644 index 00000000..2b874019 --- /dev/null +++ b/bench2/bench23.cpp @@ -0,0 +1,189 @@ +#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 "bench2.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 M1::value_type value_type; + + void operator () (int runs, safe_tag) const { + try { + static M1 m1 (N, N, N * N), m3 (N, N, N * N); + static M2 m2 (N, N, N * N); + initialize_matrix (m1); + initialize_matrix (m2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + m3 = ublas::prod (m1, m2); +// sink_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; + } + } + void operator () (int runs, fast_tag) const { + try { + static M1 m1 (N, N, N * N), m3 (N, N, N * N); + static M2 m2 (N, N, N * N); + initialize_matrix (m1); + initialize_matrix (m2); + boost::timer t; + for (int i = 0; i < runs; ++ i) { + m3.assign (ublas::prod (m1, m2)); +// sink_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_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 (sparse_matrix, sparse_matrix)"); + + header ("C array"); + bench_c_matrix_prod () (runs); + +#ifdef USE_MAP_ARRAY + header ("sparse_matrix, sparse_matrix safe"); + bench_my_matrix_prod >, + ublas::sparse_matrix >, N> () (runs, safe_tag ()); + + header ("sparse_matrix, sparse_matrix fast"); + bench_my_matrix_prod >, + ublas::sparse_matrix >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_MAP + header ("sparse_matrix, sparse_matrix safe"); + bench_my_matrix_prod >, + ublas::sparse_matrix >, N> () (runs, safe_tag ()); + + header ("sparse_matrix, sparse_matrix fast"); + bench_my_matrix_prod >, + ublas::sparse_matrix >, N> () (runs, fast_tag ()); +#endif + +#ifdef USE_STD_VALARRAY + header ("std::valarray"); + bench_cpp_matrix_prod, N> () (runs); +#endif +} + +template struct bench_3; +template struct bench_3; +template struct bench_3; +template struct bench_3; + +template struct bench_3; +template struct bench_3; +template struct bench_3; +template struct bench_3; + +#ifdef USE_STD_COMPLEX + +template struct bench_3, 3>; +template struct bench_3, 10>; +template struct bench_3, 30>; +template struct bench_3, 100>; + +template struct bench_3, 3>; +template struct bench_3, 10>; +template struct bench_3, 30>; +template struct bench_3, 100>; + +#endif + + diff --git a/bench3/Jamfile b/bench3/Jamfile new file mode 100644 index 00000000..644bf3b7 --- /dev/null +++ b/bench3/Jamfile @@ -0,0 +1,11 @@ +subproject libs/numeric/ublas/bench3 ; + +SOURCES = bench3 bench31 bench32 bench33 ; + +exe bench3 + : $(SOURCES).cpp + : $(BOOST_ROOT) + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" + ; + + diff --git a/bench3/bench3.cpp b/bench3/bench3.cpp new file mode 100644 index 00000000..2f340e8d --- /dev/null +++ b/bench3/bench3.cpp @@ -0,0 +1,217 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include +#include + +#include +#include +#include + +#include + +#include "bench3.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; +template struct peak >; +template struct peak >; + +#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 + + header ("float"); + peak () (100000000); + + header ("double"); + peak () (100000000); + +#ifdef USE_COMPLEX + header ("std:complex"); + peak > () (100000000); + + header ("std:complex"); + peak > () (100000000); +#endif + + int scale = 1; + if (argc > 1) + scale = atoi (argv [1]); + + header ("float, 3"); + + bench_1 () (1000000 * scale); + bench_2 () (300000 * scale); + bench_3 () (100000 * scale); + + header ("float, 10"); + + bench_1 () (300000 * scale); + bench_2 () (30000 * scale); + bench_3 () (3000 * scale); + + header ("float, 30"); + + bench_1 () (100000 * scale); + bench_2 () (3000 * scale); + bench_3 () (100 * scale); + + header ("float, 100"); + + bench_1 () (30000 * scale); + bench_2 () (300 * scale); + bench_3 () (3 * scale); + + header ("double, 3"); + + bench_1 () (1000000 * scale); + bench_2 () (300000 * scale); + bench_3 () (100000 * scale); + + header ("double, 10"); + + bench_1 () (300000 * scale); + bench_2 () (30000 * scale); + bench_3 () (3000 * scale); + + header ("double, 30"); + + bench_1 () (100000 * scale); + bench_2 () (3000 * scale); + bench_3 () (100 * scale); + + header ("double, 100"); + + bench_1 () (30000 * scale); + bench_2 () (300 * scale); + bench_3 () (3 * scale); + +#ifdef USE_STD_COMPLEX + header ("std::complex, 3"); + + bench_1, 3> () (1000000 * scale); + bench_2, 3> () (300000 * scale); + bench_3, 3> () (100000 * scale); + + header ("std::complex, 10"); + + bench_1, 10> () (300000 * scale); + bench_2, 10> () (30000 * scale); + bench_3, 10> () (3000 * scale); + + header ("std::complex, 30"); + + bench_1, 30> () (100000 * scale); + bench_2, 30> () (3000 * scale); + bench_3, 30> () (100 * scale); + + header ("std::complex, 100"); + + bench_1, 100> () (30000 * scale); + bench_2, 100> () (300 * scale); + bench_3, 100> () (3 * scale); + + header ("std::complex, 3"); + + bench_1, 3> () (1000000 * scale); + bench_2, 3> () (300000 * scale); + bench_3, 3> () (100000 * scale); + + header ("std::complex, 10"); + + bench_1, 10> () (300000 * scale); + bench_2, 10> () (30000 * scale); + bench_3, 10> () (3000 * scale); + + header ("std::complex, 30"); + + bench_1, 30> () (100000 * scale); + bench_2, 30> () (3000 * scale); + bench_3, 30> () (100 * scale); + + header ("std::complex, 100"); + + bench_1, 100> () (30000 * scale); + bench_2, 100> () (300 * scale); + bench_3, 100> () (3 * scale); +#endif + + return 0; +} + diff --git a/bench3/bench3.dsp b/bench3/bench3.dsp new file mode 100644 index 00000000..b77e2f52 --- /dev/null +++ b/bench3/bench3.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/bench3/bench3.hpp b/bench3/bench3.hpp new file mode 100644 index 00000000..e94c62d4 --- /dev/null +++ b/bench3/bench3.hpp @@ -0,0 +1,156 @@ +#ifndef BENCH3_H +#define BENCH3_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_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/bench3/bench31.cpp b/bench3/bench31.cpp new file mode 100644 index 00000000..190cdb67 --- /dev/null +++ b/bench3/bench31.cpp @@ -0,0 +1,336 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include +#include + +#include +#include +#include + +#include + +#include "bench3.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 +} + +template struct bench_1; +template struct bench_1; +template struct bench_1; +template struct bench_1; + +template struct bench_1; +template struct bench_1; +template struct bench_1; +template struct bench_1; + +#ifdef USE_STD_COMPLEX + +template struct bench_1, 3>; +template struct bench_1, 10>; +template struct bench_1, 30>; +template struct bench_1, 100>; + +template struct bench_1, 3>; +template struct bench_1, 10>; +template struct bench_1, 30>; +template struct bench_1, 100>; + +#endif + + diff --git a/bench3/bench32.cpp b/bench3/bench32.cpp new file mode 100644 index 00000000..b7a50d04 --- /dev/null +++ b/bench3/bench32.cpp @@ -0,0 +1,568 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include +#include + +#include +#include +#include + +#include + +#include "bench3.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 +} + +template struct bench_2; +template struct bench_2; +template struct bench_2; +template struct bench_2; + +template struct bench_2; +template struct bench_2; +template struct bench_2; +template struct bench_2; + +#ifdef USE_STD_COMPLEX + +template struct bench_2, 3>; +template struct bench_2, 10>; +template struct bench_2, 30>; +template struct bench_2, 100>; + +template struct bench_2, 3>; +template struct bench_2, 10>; +template struct bench_2, 30>; +template struct bench_2, 100>; + +#endif + + diff --git a/bench3/bench33.cpp b/bench3/bench33.cpp new file mode 100644 index 00000000..584df7ab --- /dev/null +++ b/bench3/bench33.cpp @@ -0,0 +1,223 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include +#include + +#include +#include +#include + +#include + +#include "bench3.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 +} + +template struct bench_3; +template struct bench_3; +template struct bench_3; +template struct bench_3; + +template struct bench_3; +template struct bench_3; +template struct bench_3; +template struct bench_3; + +#ifdef USE_STD_COMPLEX + +template struct bench_3, 3>; +template struct bench_3, 10>; +template struct bench_3, 30>; +template struct bench_3, 100>; + +template struct bench_3, 3>; +template struct bench_3, 10>; +template struct bench_3, 30>; +template struct bench_3, 100>; + +#endif + + diff --git a/concepts.cpp b/concepts.cpp new file mode 100644 index 00000000..6bb1a20d --- /dev/null +++ b/concepts.cpp @@ -0,0 +1,57 @@ +#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 +#include +#include +#include + +#include + +namespace ublas = boost::numeric::ublas; + +int main () { + void (* check) (void) = ublas::concept_checks; + ublas::ignore_unused_variable_warning (check); + return 0; +} + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/concepts.dsp b/concepts.dsp new file mode 100644 index 00000000..bbbe4f7a --- /dev/null +++ b/concepts.dsp @@ -0,0 +1,282 @@ +# Microsoft Developer Studio Project File - Name="concepts" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=concepts - 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 "concepts.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 "concepts.mak" CFG="concepts - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "concepts - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "concepts - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName ""$/boost/libs/numeric/ublas", ECCAAAAA" +# PROP Scc_LocalPath "." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "concepts - 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 dCPP /D _MBCS /D _CONSOLE /D _MBCS +# ADD dCPP /D _MBCS /D _CONSOLE /D _MBCS +# 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)" == "concepts - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "concepts___Win32_Debug" +# PROP BASE Intermediate_Dir "concepts___Win32_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 dCPP /D _MBCS /D _CONSOLE /D _MBCS +# ADD dCPP /D _MBCS /D _CONSOLE /D _MBCS +# 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 "concepts - Win32 Release" +# Name "concepts - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\concepts.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\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 +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# Begin Source File + +SOURCE=.\doc\banded.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\container.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\expression.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\hermitian.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\index.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\iterator.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\matrix.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\matrix_expression.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\matrix_proxy.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\matrix_sparse.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\overview.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\storage.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\storage_sparse.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\symmetric.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\triangular.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\vector.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\vector_expression.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\vector_proxy.htm +# End Source File +# Begin Source File + +SOURCE=.\doc\vector_sparse.htm +# End Source File +# End Target +# End Project diff --git a/doc/banded.htm b/doc/banded.htm new file mode 100644 index 00000000..e7b7ffd8 --- /dev/null +++ b/doc/banded.htm @@ -0,0 +1,1206 @@ + + + + + +Banded Matrix + + + + +

c++boost.gifBanded Matrix

+ +

Banded Matrix

+ +

Description

+ +

The templated class banded_matrix<T, F, A> is +the base container adaptor for banded matrices. For a (m x n)-dimensional +banded matrix with l lower and u upper +diagonals and 0 <= i < m, 0 <= j < n +holds bi, j = 0, if i +> j + l or i < j - u. The storage of banded +matrices is packed.

+ +

Example

+ +
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 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;
+}
+ +

Definition

+ +

Defined in the header banded.hpp.

+ +

Template parameters

+ + + + + + + + + + + + + + + + + + + + + + +
Parameter Description Default
T The type of object stored in the matrix. 
FFunctor describing the storage organization. [1]row_major
AThe type of the adapted array. [2]unbounded_array<T>
+ +

Model of

+ +

Matrix.

+ +

Type requirements

+ +

None, except for those imposed by the requirements of Matrix.

+ +

Public base classes

+ +

matrix_expression<banded_matrix<T, F, A> > +

+ +

Members

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Member Description
banded_matrix () Allocates an uninitialized banded_matrix + that holds zero rows of zero elements.
banded_matrix (size_type size1, size_type + size2, size_type lower = 0, size_type upper = 0)Allocates an uninitialized banded_matrix + that holds (lower + 1 + upper) diagonals + around the main diagonal of a matrix with size1 + rows of size2 elements.
banded_matrix (const banded_matrix &m)The copy constructor.
template<class AE>
+ banded_matrix (const matrix_expression<AE> &ae)
The extended copy constructor.
void resize (size_type size1, size_type size2, + size_type lower = 0, size_type upper = 0)Reallocates a banded_matrix to hold (lower + + 1 + upper) diagonals around the main diagonal of + a matrix with size1 rows of size2 + elements. The content of the banded_matrix + is not preserved.
size_type size1 () constReturns the number of rows.
size_type size2 () constReturns the number of columns.
size_type lower () constReturns the number of diagonals below the main + diagonal.
size_type upper () constReturns the number of diagonals above the main + diagonal.
const_reference operator () (size_type i, + size_type j) constReturns a const reference of the j-th + element in the i-th row.
reference operator () (size_type i, size_type + j)Returns a reference of the j-th element + in the i-th row.
banded_matrix &operator = (const + banded_matrix &m)The assignment operator.
banded_matrix &assign_temporary + (banded_matrix &m)Assigns a temporary. May change the banded matrix m.
template<class AE>
+ banded_matrix &operator = (const + matrix_expression<AE> &ae)
The extended assignment operator.
template<class AE>
+ banded_matrix &assign (const + matrix_expression<AE> &ae)
Assigns a matrix expression to the banded matrix. + Left and right hand side of the assignment should be + independent.
template<class AE>
+ banded_matrix &operator += (const + matrix_expression<AE> &ae)
A computed assignment operator. Adds the matrix + expression to the banded matrix.
template<class AE>
+ banded_matrix &plus_assign (const + matrix_expression<AE> &ae)
Adds a matrix expression to the banded matrix. Left + and right hand side of the assignment should be + independent.
template<class AE>
+ banded_matrix &operator -= (const + matrix_expression<AE> &ae)
A computed assignment operator. Subtracts the matrix + expression from the banded matrix.
template<class AE>
+ banded_matrix &minus_assign (const + matrix_expression<AE> &ae)
Subtracts a matrix expression from the banded matrix. + Left and right hand side of the assignment should be + independent.
template<class AT>
+ banded_matrix &operator *= (const AT &at)
A computed assignment operator. Multiplies the banded + matrix with a scalar.
template<class AT>
+ banded_matrix &operator /= (const AT &at)
A computed assignment operator. Divides the banded + matrix through a scalar.
void swap (banded_matrix &m)Swaps the contents of the banded matrices.
void insert (size_type i, size_type j, + const_reference t)Inserts the value t at the j-th + element of the i-th row.
void erase (size_type i, size_type j)Erases the value at the j-th elemenst of + the i-th row.
void clear ()Clears the matrix.
const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the banded_matrix.
const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the banded_matrix.
iterator1 begin1 () Returns a iterator1 pointing to the + beginning of the banded_matrix.
iterator1 end1 () Returns a iterator1 pointing to the end + of the banded_matrix.
const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the banded_matrix.
const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the banded_matrix.
iterator2 begin2 () Returns a iterator2 pointing to the + beginning of the banded_matrix.
iterator2 end2 () Returns a iterator2 pointing to the end + of the banded_matrix.
const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed banded_matrix. +
const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed banded_matrix. +
reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to + the beginning of the reversed banded_matrix. +
reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to + the end of the reversed banded_matrix.
const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed banded_matrix. +
const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed banded_matrix. +
reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to + the beginning of the reversed banded_matrix. +
reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to + the end of the reversed banded_matrix.
+ +

Notes

+ +

[1] Supported parameters for the +storage organization are row_major and column_major.

+ +

[2] Supported parameters for the +adapted array are unbounded_array<T>, bounded_array<T> +and std::vector<T>.

+ +

Interface

+ +
    // Array based banded matrix class 
+    template<class T, class F, class A>
+    class banded_matrix: 
+        public matrix_expression<banded_matrix<T, F, A> > {
+    public:      
+        typedef std::size_t size_type;
+        typedef std::ptrdiff_t difference_type;
+        typedef T value_type;
+        typedef const T &const_reference;
+        typedef T &reference;
+        typedef const T *const_pointer;
+        typedef T *pointer;
+        typedef F functor_type;
+        typedef A array_type;
+        typedef const A const_array_type;
+        typedef const banded_matrix<T, F, A> const_self_type;
+        typedef banded_matrix<T, F, A> self_type;
+        typedef const matrix_const_reference<const_self_type> const_closure_type;
+        typedef matrix_reference<self_type> closure_type;
+        typedef packed_tag storage_category;
+        typedef typename F::orientation_category orientation_category;
+
+        // Construction and destruction
+        banded_matrix ();
+        banded_matrix (size_type size1, size_type size2, size_type lower = 0, size_type upper = 0);
+        banded_matrix (const banded_matrix &m);
+        template<class AE>
+        banded_matrix (const matrix_expression<AE> &ae, size_type lower = 0, size_type upper = 0);
+
+        // Accessors
+        size_type size1 () const;
+        size_type size2 () const;
+        size_type lower () const;
+        size_type upper () const;
+        const_array_type &data () const;
+        array_type &data ();
+
+        // Resizing
+        void resize (size_type size1, size_type size2, size_type lower = 0, size_type upper = 0);
+
+        // Element access
+        const_reference operator () (size_type i, size_type j) const;
+        reference operator () (size_type i, size_type j);
+
+        // Assignment
+        banded_matrix &operator = (const banded_matrix &m);
+        banded_matrix &assign_temporary (banded_matrix &m);
+        template<class AE>
+        banded_matrix &operator = (const matrix_expression<AE> &ae);
+        template<class AE>
+        banded_matrix &reset (const matrix_expression<AE> &ae);
+        template<class AE>
+        banded_matrix &assign (const matrix_expression<AE> &ae);
+        template<class AE>
+        banded_matrix& operator += (const matrix_expression<AE> &ae);
+        template<class AE>
+        banded_matrix &plus_assign (const matrix_expression<AE> &ae);
+        template<class AE>
+        banded_matrix& operator -= (const matrix_expression<AE> &ae);
+        template<class AE>
+        banded_matrix &minus_assign (const matrix_expression<AE> &ae);
+        template<class AT>
+        banded_matrix& operator *= (const AT &at);
+        template<class AT>
+        banded_matrix& operator /= (const AT &at);
+
+        // Swapping
+        void swap (banded_matrix &m);
+        friend void swap (banded_matrix &m1, banded_matrix &m2);
+
+        // Element insertion and erasure
+        void insert (size_type i, size_type j, const_reference t);
+        void erase (size_type i, size_type j);
+        void clear ();
+
+        class const_iterator1;
+        class iterator1;
+        class const_iterator2;
+        class iterator2;
+        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
+        typedef reverse_iterator_base1<iterator1> reverse_iterator1;
+        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
+        typedef reverse_iterator_base2<iterator2> reverse_iterator2;
+
+        // Element lookup
+        const_iterator1 find1 (int rank, size_type i, size_type j) const;
+        iterator1 find1 (int rank, size_type i, size_type j);
+        const_iterator2 find2 (int rank, size_type i, size_type j) const;
+        iterator2 find2 (int rank, size_type i, size_type j);
+        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
+        iterator1 find_first1 (int rank, size_type i, size_type j);
+        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
+        iterator1 find_last1 (int rank, size_type i, size_type j);
+        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
+        iterator2 find_first2 (int rank, size_type i, size_type j);
+        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
+        iterator2 find_last2 (int rank, size_type i, size_type j);
+
+        // Iterators simply are indices.
+
+        class const_iterator1:
+            public container_const_reference<banded_matrix>,
+            public random_access_iterator_base<const_iterator1, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename banded_matrix::difference_type difference_type;
+            typedef typename banded_matrix::value_type value_type;
+            typedef typename banded_matrix::const_reference reference;
+            typedef typename banded_matrix::const_pointer pointer;
+            typedef const_iterator2 dual_iterator_type;
+            typedef const_reverse_iterator2 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator1 ();
+            const_iterator1 (const banded_matrix &m, size_type it1, size_type it2);
+            const_iterator1 (const iterator1 &it);
+
+            // Arithmetic
+            const_iterator1 &operator ++ ();
+            const_iterator1 &operator -- ();
+            const_iterator1 &operator += (difference_type n);
+            const_iterator1 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator1 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator2 begin () const;
+            const_iterator2 end () const;
+            const_reverse_iterator2 rbegin () const;
+            const_reverse_iterator2 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator1 &operator = (const const_iterator1 &it);
+
+            // Comparison
+            bool operator == (const const_iterator1 &it) const;
+            bool operator < (const const_iterator1 &it) const;
+        };
+
+        const_iterator1 begin1 () const;
+        const_iterator1 end1 () const;
+
+        class iterator1:
+            public container_reference<banded_matrix>,
+            public random_access_iterator_base<iterator1, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename banded_matrix::difference_type difference_type;
+            typedef typename banded_matrix::value_type value_type;
+            typedef typename banded_matrix::reference reference;
+            typedef typename banded_matrix::pointer pointer;
+            typedef iterator2 dual_iterator_type;
+            typedef reverse_iterator2 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            iterator1 ();
+            iterator1 (banded_matrix &m, size_type it1, size_type it2);
+
+            // Arithmetic
+            iterator1 &operator ++ ();
+            iterator1 &operator -- ();
+            iterator1 &operator += (difference_type n);
+            iterator1 &operator -= (difference_type n);
+            difference_type operator - (const iterator1 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            iterator2 begin () const;
+            iterator2 end () const;
+            reverse_iterator2 rbegin () const;
+            reverse_iterator2 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            iterator1 &operator = (const iterator1 &it);
+
+            // Comparison
+            bool operator == (const iterator1 &it) const;
+            bool operator < (const iterator1 &it) const;
+        };
+
+        iterator1 begin1 ();
+        iterator1 end1 ();
+
+        class const_iterator2:
+            public container_const_reference<banded_matrix>,
+            public random_access_iterator_base<const_iterator2, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename banded_matrix::difference_type difference_type;
+            typedef typename banded_matrix::value_type value_type;
+            typedef typename banded_matrix::const_reference reference;
+            typedef typename banded_matrix::const_pointer pointer;
+            typedef const_iterator1 dual_iterator_type;
+            typedef const_reverse_iterator1 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator2 ();
+            const_iterator2 (const banded_matrix &m, size_type it1, size_type it2);
+            const_iterator2 (const iterator2 &it);
+
+            // Arithmetic
+            const_iterator2 &operator ++ ();
+            const_iterator2 &operator -- ();
+            const_iterator2 &operator += (difference_type n);
+            const_iterator2 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator2 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator1 begin () const;
+            const_iterator1 end () const;
+            const_reverse_iterator1 rbegin () const;
+            const_reverse_iterator1 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator2 &operator = (const const_iterator2 &it);
+
+            // Comparison
+            bool operator == (const const_iterator2 &it) const;
+            bool operator < (const const_iterator2 &it) const;
+        };
+
+        const_iterator2 begin2 () const;
+        const_iterator2 end2 () const;
+
+        class iterator2:
+            public container_reference<banded_matrix>,
+            public random_access_iterator_base<iterator2, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename banded_matrix::difference_type difference_type;
+            typedef typename banded_matrix::value_type value_type;
+            typedef typename banded_matrix::reference reference;
+            typedef typename banded_matrix::pointer pointer;
+            typedef iterator1 dual_iterator_type;
+            typedef reverse_iterator1 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            iterator2 ();
+            iterator2 (banded_matrix &m, size_type it1, size_type it2);
+
+            // Arithmetic
+            iterator2 &operator ++ ();
+            iterator2 &operator -- ();
+            iterator2 &operator += (difference_type n);
+            iterator2 &operator -= (difference_type n);
+            difference_type operator - (const iterator2 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            iterator1 begin () const;
+            iterator1 end () const;
+            reverse_iterator1 rbegin () const;
+            reverse_iterator1 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            iterator2 &operator = (const iterator2 &it);
+
+            // Comparison
+            bool operator == (const iterator2 &it) const;
+            bool operator < (const iterator2 &it) const;
+        };
+
+        iterator2 begin2 ();
+        iterator2 end2 ();
+
+        // Reverse iterators
+
+        const_reverse_iterator1 rbegin1 () const;
+        const_reverse_iterator1 rend1 () const;
+
+        reverse_iterator1 rbegin1 ();
+        reverse_iterator1 rend1 ();
+
+        const_reverse_iterator2 rbegin2 () const;
+        const_reverse_iterator2 rend2 () const;
+
+        reverse_iterator2 rbegin2 ();
+        reverse_iterator2 rend2 ();
+    };
+ +

Banded Adaptor

+ +

Description

+ +

The templated class banded_adaptor<M> is a +banded matrix adaptor for other matrices.

+ +

Example

+ +
int main () {
+    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 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;
+}
+ +

Definition

+ +

Defined in the header banded.hpp.

+ +

Template parameters

+ + + + + + + + + + + + +
Parameter Description Default
MThe type of the adapted matrix. 
+ +

Model of

+ +

Matrix Expression. +

+ +

Type requirements

+ +

None, except for those imposed by the requirements of Matrix Expression.

+ +

Public base classes

+ +

matrix_expression<banded_adaptor<M> > +

+ +

Members

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Member Description
banded_adaptor () Constructs a banded_adaptor that holds + zero rows of zero elements.
banded_adaptor (matrix_type &data, + size_type lower = 0, size_type upper = 0)Constructs a banded_adaptor that holds (lower + + 1 + upper) diagonals around the main diagonal of + a matrix.
banded_adaptor (const banded_adaptor &m)The copy constructor.
template<class AE>
+ banded_adaptor (const matrix_expression<AE> + &ae)
The extended copy constructor.
size_type size1 () constReturns the number of rows.
size_type size2 () constReturns the number of columns.
size_type lower () constReturns the number of diagonals below the main + diagonal.
size_type upper () constReturns the number of diagonals above the main + diagonal.
const_reference operator () (size_type i, + size_type j) constReturns a const reference of the j-th + element in the i-th row.
reference operator () (size_type i, size_type + j)Returns a reference of the j-th element + in the i-th row.
banded_adaptor &operator = (const + banded_adaptor &m)The assignment operator.
banded_adaptor &assign_temporary + (banded_adaptor &m)Assigns a temporary. May change the banded adaptor m.
template<class AE>
+ banded_adaptor &operator = (const + matrix_expression<AE> &ae)
The extended assignment operator.
template<class AE>
+ banded_adaptor &assign (const + matrix_expression<AE> &ae)
Assigns a matrix expression to the banded adaptor. + Left and right hand side of the assignment should be + independent.
template<class AE>
+ banded_adaptor &operator += (const + matrix_expression<AE> &ae)
A computed assignment operator. Adds the matrix + expression to the banded adaptor.
template<class AE>
+ banded_adaptor &plus_assign (const + matrix_expression<AE> &ae)
Adds a matrix expression to the banded adaptor. Left + and right hand side of the assignment should be + independent.
template<class AE>
+ banded_adaptor &operator -= (const + matrix_expression<AE> &ae)
A computed assignment operator. Subtracts the matrix + expression from the banded adaptor.
template<class AE>
+ banded_adaptor &minus_assign (const + matrix_expression<AE> &ae)
Subtracts a matrix expression from the banded + adaptor. Left and right hand side of the assignment + should be independent.
template<class AT>
+ banded_adaptor &operator *= (const AT &at)
A computed assignment operator. Multiplies the banded + adaptor with a scalar.
template<class AT>
+ banded_adaptor &operator /= (const AT &at)
A computed assignment operator. Divides the banded + adaptor through a scalar.
void swap (banded_adaptor &m)Swaps the contents of the banded adaptors.
const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the banded_adaptor.
const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the banded_adaptor.
iterator1 begin1 () Returns a iterator1 pointing to the + beginning of the banded_adaptor.
iterator1 end1 () Returns a iterator1 pointing to the end + of the banded_adaptor.
const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the banded_adaptor.
const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the banded_adaptor.
iterator2 begin2 () Returns a iterator2 pointing to the + beginning of the banded_adaptor.
iterator2 end2 () Returns a iterator2 pointing to the end + of the banded_adaptor.
const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed banded_adaptor. +
const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed banded_adaptor. +
reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to + the beginning of the reversed banded_adaptor. +
reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to + the end of the reversed banded_adaptor.
const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed banded_adaptor. +
const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed banded_adaptor. +
reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to + the beginning of the reversed banded_adaptor. +
reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to + the end of the reversed banded_adaptor.
+ +

Interface

+ +
    // Banded matrix adaptor class 
+    template<class M>
+    class banded_adaptor: 
+        public matrix_expression<banded_adaptor<M> > {
+    public:      
+        typedef const M const_matrix_type;
+        typedef M matrix_type;
+        typedef typename M::size_type size_type;
+        typedef typename M::difference_type difference_type;
+        typedef typename M::value_type value_type;
+        typedef typename M::const_reference const_reference;
+        typedef typename M::reference reference;
+        typedef typename M::const_pointer const_pointer;
+        typedef typename M::pointer pointer;
+        typedef const banded_adaptor<M> const_self_type;
+        typedef banded_adaptor<M> self_type;
+        typedef const matrix_const_reference<const_self_type> const_closure_type;
+        typedef matrix_reference<self_type> closure_type;
+        typedef typename storage_restrict_traits<typename M::storage_category,
+                                                 packed_proxy_tag>::storage_category storage_category;
+        typedef typename M::orientation_category orientation_category;
+
+        // Construction and destruction
+        banded_adaptor ();
+        banded_adaptor (matrix_type &data, size_type lower = 0, size_type upper = 0);
+        banded_adaptor (const banded_adaptor &m);
+
+        // Accessors
+        size_type size1 () const;
+        size_type size2 () const;
+        size_type lower () const;
+        size_type upper () const;
+        const_matrix_type &data () const;
+        matrix_type &data ();
+
+        // Element access
+        const_reference operator () (size_type i, size_type j) const;
+        reference operator () (size_type i, size_type j);
+
+        // Assignment
+        banded_adaptor &operator = (const banded_adaptor &m);
+        banded_adaptor &assign_temporary (banded_adaptor &m);
+        template<class AE>
+        banded_adaptor &operator = (const matrix_expression<AE> &ae);
+        template<class AE>
+        banded_adaptor &assign (const matrix_expression<AE> &ae);
+        template<class AE>
+        banded_adaptor& operator += (const matrix_expression<AE> &ae);
+        template<class AE>
+        banded_adaptor &plus_assign (const matrix_expression<AE> &ae);
+        template<class AE>
+        banded_adaptor& operator -= (const matrix_expression<AE> &ae);
+        template<class AE>
+        banded_adaptor &minus_assign (const matrix_expression<AE> &ae);
+        template<class AT>
+        banded_adaptor& operator *= (const AT &at);
+        template<class AT>
+        banded_adaptor& operator /= (const AT &at);
+
+        // Swapping
+        void swap (banded_adaptor &m);
+        friend void swap (banded_adaptor &m1, banded_adaptor &m2);
+
+        class const_iterator1;
+        class iterator1;
+        class const_iterator2;
+        class iterator2;
+        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
+        typedef reverse_iterator_base1<iterator1> reverse_iterator1;
+        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
+        typedef reverse_iterator_base2<iterator2> reverse_iterator2;
+
+        // Element lookup
+        const_iterator1 find1 (int rank, size_type i, size_type j) const;
+        iterator1 find1 (int rank, size_type i, size_type j);
+        const_iterator2 find2 (int rank, size_type i, size_type j) const;
+        iterator2 find2 (int rank, size_type i, size_type j);
+        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
+        iterator1 find_first1 (int rank, size_type i, size_type j);
+        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
+        iterator1 find_last1 (int rank, size_type i, size_type j);
+        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
+        iterator2 find_first2 (int rank, size_type i, size_type j);
+        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
+        iterator2 find_last2 (int rank, size_type i, size_type j);
+
+        // Iterators simply are indices.
+
+        class const_iterator1:
+            public container_const_reference<banded_adaptor>,
+            public random_access_iterator_base<const_iterator1, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename banded_adaptor::difference_type difference_type;
+            typedef typename banded_adaptor::value_type value_type;
+            typedef typename banded_adaptor::const_reference reference;
+            typedef typename banded_adaptor::const_pointer pointer;
+            typedef const_iterator2 dual_iterator_type;
+            typedef const_reverse_iterator2 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator1 ();
+            const_iterator1 (const banded_adaptor &m, size_type it1, size_type it2);
+            const_iterator1 (const iterator1 &it);
+
+            // Arithmetic
+            const_iterator1 &operator ++ ();
+            const_iterator1 &operator -- ();
+            const_iterator1 &operator += (difference_type n);
+            const_iterator1 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator1 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator2 begin () const;
+            const_iterator2 end () const;
+            const_reverse_iterator2 rbegin () const;
+            const_reverse_iterator2 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator1 &operator = (const const_iterator1 &it);
+
+            // Comparison
+            bool operator == (const const_iterator1 &it) const;
+            bool operator < (const const_iterator1 &it) const;
+        };
+
+        const_iterator1 begin1 () const;
+        const_iterator1 end1 () const;
+
+        class iterator1:
+            public container_reference<banded_adaptor>,
+            public random_access_iterator_base<iterator1, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename banded_adaptor::difference_type difference_type;
+            typedef typename banded_adaptor::value_type value_type;
+            typedef typename banded_adaptor::reference reference;
+            typedef typename banded_adaptor::pointer pointer;
+            typedef iterator2 dual_iterator_type;
+            typedef reverse_iterator2 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            iterator1 ();
+            iterator1 (banded_adaptor &m, size_type it1, size_type it2);
+
+            // Arithmetic
+            iterator1 &operator ++ ();
+            iterator1 &operator -- ();
+            iterator1 &operator += (difference_type n);
+            iterator1 &operator -= (difference_type n);
+            difference_type operator - (const iterator1 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            iterator2 begin () const;
+            iterator2 end () const;
+            reverse_iterator2 rbegin () const;
+            reverse_iterator2 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            iterator1 &operator = (const iterator1 &it);
+
+            // Comparison
+            bool operator == (const iterator1 &it) const;
+            bool operator < (const iterator1 &it) const;
+        };
+
+        iterator1 begin1 ();
+        iterator1 end1 ();
+
+        class const_iterator2:
+            public container_const_reference<banded_adaptor>,
+            public random_access_iterator_base<const_iterator2, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename banded_adaptor::difference_type difference_type;
+            typedef typename banded_adaptor::value_type value_type;
+            typedef typename banded_adaptor::const_reference reference;
+            typedef typename banded_adaptor::const_pointer pointer;
+            typedef const_iterator1 dual_iterator_type;
+            typedef const_reverse_iterator1 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator2 ();
+            const_iterator2 (const banded_adaptor &m, size_type it1, size_type it2);
+            const_iterator2 (const iterator2 &it);
+
+            // Arithmetic
+            const_iterator2 &operator ++ ();
+            const_iterator2 &operator -- ();
+            const_iterator2 &operator += (difference_type n);
+            const_iterator2 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator2 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator1 begin () const;
+            const_iterator1 end () const;
+            const_reverse_iterator1 rbegin () const;
+            const_reverse_iterator1 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator2 &operator = (const const_iterator2 &it);
+
+            // Comparison
+            bool operator == (const const_iterator2 &it) const;
+            bool operator < (const const_iterator2 &it) const;
+        };
+
+        const_iterator2 begin2 () const;
+        const_iterator2 end2 () const;
+
+        class iterator2:
+            public container_reference<banded_adaptor>,
+            public random_access_iterator_base<iterator2, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename banded_adaptor::difference_type difference_type;
+            typedef typename banded_adaptor::value_type value_type;
+            typedef typename banded_adaptor::reference reference;
+            typedef typename banded_adaptor::pointer pointer;
+            typedef iterator1 dual_iterator_type;
+            typedef reverse_iterator1 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            iterator2 ();
+            iterator2 (banded_adaptor &m, size_type it1, size_type it2);
+
+            // Arithmetic
+            iterator2 &operator ++ ();
+            iterator2 &operator -- ();
+            iterator2 &operator += (difference_type n);
+            iterator2 &operator -= (difference_type n);
+            difference_type operator - (const iterator2 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            iterator1 begin () const;
+            iterator1 end () const;
+            reverse_iterator1 rbegin () const;
+            reverse_iterator1 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            iterator2 &operator = (const iterator2 &it);
+
+            // Comparison
+            bool operator == (const iterator2 &it) const;
+            bool operator < (const iterator2 &it) const;
+        };
+
+        iterator2 begin2 ();
+        iterator2 end2 ();
+
+        // Reverse iterators
+
+        const_reverse_iterator1 rbegin1 () const;
+        const_reverse_iterator1 rend1 () const;
+
+        reverse_iterator1 rbegin1 ();
+        reverse_iterator1 rend1 ();
+
+        const_reverse_iterator2 rbegin2 () const;
+        const_reverse_iterator2 rend2 () const;
+
+        reverse_iterator2 rbegin2 ();
+        reverse_iterator2 rend2 ();
+    };
+ +
+ +

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/c++boost.gif b/doc/c++boost.gif new file mode 100644 index 0000000000000000000000000000000000000000..58be431a3fafbd5adfa01e829ce8d80a03a83ed0 GIT binary patch literal 8819 zcmZ?wbhEHb6lDx!_|CwzZQFbH(K6ngWKJ ziiVnsJ(`+|nwo~1nogRU#hRMcnwmYDhC!N^Q#37?YC7%JbULQ#bxbqrnr8BQL(ODE zLoY+8V}?P;41=y2MlCgrx@H*l+%Wl?Ve)gs?C+L}mX?N=mWDx=hSipqQ!JgPSURn> z^vbpjT56g6-Lm?-WzTmf!(=DJY9}WzC#NVUr)(#u7ALR0PC?a9L35m__ikjmUwbv`^m{;;Wuj=n!J>P?zs)M|u zg1oYWg0h2x<^%<;4T`!KlsqLUd1+Ac+Mw)XLD|=WvhM|DKM$(D7F7K{sO5W5&-0+3 z??H3EM|mYj1#OK2ftIN3wNcggqSpRT4$4lBTAG}kot#{qoIE8tyC*q&PIC6vOS7xD zW>??KZaJ6Tb1u8*UUtv(>?z-~m%h(F_CNdD|Kj4M#l`1}=X@_-`@MMU_u_NktBZT8 zpp&i(JHp3~FQ z(gOl>dV03@^c?G%^1f%zxt=-KdX`@6S^B(Z>-#A^bEeFhGiA=&DRcHtS^9j+()UxA zexI`S-juEHr|f+`W$$+oI`@ChoO5&5URye6?b11Wmo7cFbm_UJOYbdRyLai)y3n&#m2hZSB_QYmePqd+hz%bMM!l`@Z(t_qETz@7;S2jPC8- z`+V=-_j~t#-+S!X-gEc%o_oLd-1lQ!uN`~-{oJ{G=gz%9ckkZ0d+*QP`+n{H_iNw3 z-@Etx-o5Y7LE!uQ=ilFd2LZ*OEQ|~c{~2^ZSpk$M7&!hh{O6SM*s$PWGl#HN%!v&P z54Q^_d(H9KxaerNgmKoL6B`#F?^kf{lJVTM)Z?TNcv$a| zX8p~bZNB0Df&T~6_*U;Ue!k)Nx4)0STN=lnoy=Uk&wHlPgHtoufA^>{GB7Z*NC+qx zEcpIN;8}uG+nxy)Z*Fk5pN`YwZ+XkW@@A=`LV`o-eI~Cj)^QWQ-oG;S@4wD($Mp*; zKP`6s{@DHBpR&r|f1Y;l*S~LH`{mvB-SzM1@2UKMVR3)O&lAhfXRyDTtWf>OAmU!t zs=u54Gam$&%`7~<@(I8EdENsIoYf18T1uH!F5G5d%-B3PRcBIqc*K(2v|IK+EpEtF zvVWTFZ*Tf*@q*YTCzbu}KZ#iM+uB`wtUT%073U>3|4u$WZ{ub)vwzYj1 zuldQd;&D~NvF-O#<}b8Nu8>@&;-9;Xcf)NZMy&}m=Ir4$;7VZmncQc2tKjgwqRO9N zm2B@69PXQ`ze#LXi_kW+n@esNs@-bIFpJ8}njN-lZftLp)yfr%lw4wFt350_kh}L| z+bR2hhkXvb%G=Y~cylrH%;s)`%pM)00cDHCB8v?zgnNb(GKA z#VV6;>)Rcd&s%@~^7x$1zd6b0?C$^iIo0ykHf4VM&pV8lZu@Lu*+1oT!|Hxpf4|Hp zebJ9zByaeB$KplThPhp@+}w7ws^{-I@aj&~7QP3E9IP%KooDK%P!P@VoTuVR?H94` zCpNd97&Ruj`*iYECj5P=JLyHiW`FayIluYr-`yzgH@o}hbD!0}CB}K?FTZT=v;Hk} z*Wb!~J9CMZ>G{tyuKeBLtiR*imCgMV{z~j#(jUWiC!yMCQ>B4B)0tJb8Fs#D?q0)q z;wM8smqL1^eT~I-iGN!rN2$G9{?}&G>8NXw2Oq>Pd~2*xz3{8?!x??n>n!ZQoBUAi z{}dgt z+CLsYPp}lKr}0kz_UE(Cjeixn=arWW*d5?Mdt3Fq+0Tf_yms$*G@rM4{ATfKgFi9M z=WOo^IQyI4zjJt>-Hn*T{Dw!KeD?kQBBq$%>gJQnz2<*jxcxrVXp+6cL-y^1<5sr{ z`AbdC%KXfjzPTZlzxu=CroTTf_WNC*B_^p;##iY5_F7rj>MP4aUq9$&K4+pK&+5n2 z!p(61TN3}pH%Ikq4zMyjF=2>~Y^(eCN8^~qA4a>{2K|ohC)^DWE#y!Acv#~4jpK$J zCh})UD9aza;A&SA$Xgq+QGWk|V|EKZcGtx$mio(a-29VaPu`tm*#{5Wr7lO9EI*qg z_x*>M{f@2fH8&SWOYE86f26Jd%#L$;3OOAdnOkRvpM0FMR_TBQhXG^Do5zBR5#60P z3bl5BIiCOT1+(6&VC{gj>ONC~C-i-q$Y1rM!|PW<>cn?T7pPrjwogoYI#uL~SMtlp zaz72i*j_HQ;AZM7j}w0CS{L;d zE~=m2vY1ct#=_Edu3C*3-sHVm(ags>fq^Mvq3pkZi{15F7V;NbD9dljIA%L#VNZ?D zV~H;}T(zDsa>iYGEV_O}yH-sgfBYUL`Bfc9ZFVf`kKOQS;hGc2^^z94q+D?pUozvk ze$T@GEC*-#>lH7}HwE_RS2WAr?r^g^wz03K#aZ@e#Bu9)AN$IGtZA#CBQ$x2iWPrW zvErQ=2W3_xMpmB(tM~#K=CTy=7u!5q-M^w)P^e6{jAyY(LaKY+pCi4wHck9VM_a$F zDG1wO*Cc%*fz5u(MV@MfWU1bpDlCu?UGugvkfU^sbp!| zxOzv6ZNkE?@*_%%jzze-_CD;3w@H>;ccIm0Rb%h%u*ci(Z)i6^RM?-tM_K;8hr-oY zM{UCTjyY-SaTHfRKD#%8%}iBUm67MdoiIZO^B$E338V5&x1MTFTCr?uCx;-H%JxUH z3mjamCnU1wGCUG~f1;7^%*8gxEy=u@8SPS66#7l>D9UDfd=vCC=+|Ac@aFuEb=*%9 zIm~Y?=AByMuBv0$e{@&!#tE^l)*+1Cl?xt;e2G};70%6*af4afD0ja3m4*E!OAgE5 z`6Sq&=A-;I!Rqqtvb-Xeq}~{nV=n90@#$AEa?1%Um{(T8W~i0E{Pl+oR>vIJbpBNZ zobUd>K=y9M@!IZReAOL?r4CPUtG%1ZS6F#C^R0us^@4AG_H!T0-2HKF{+)|`WhL+Z zZ%%Trf8MB5S+Ke~X!Z1l=NA(c6<5oCom90~-l(`LsX7Qzz_eLm>(Kl$h$PuI8) zit=SQw(GCB@s7b^!d0#lnQ}Hi99fkXH0=A|X!GNRb(OV21Bb-|^Vbg=IkYA;?BjP} zOgpjFT3{ka%=JgI3K@>(c7c@^42{wjKbowTENIR1P~?44&?L2MBdhL`IPPZ}i~{!< z+Y{eA@V@tOmcDn9&1OfkKwE~pVpBh-&z5GP=@$RAE(CH0Z%GyrOl{S9c91Li%wtKN zSU2-m{{$~rH$0ZEebc_^SL1`3yjeZ_&hE!-krc^Hi0k5 zfc3=%wjhC)tOtBYukkfIaO_D>ou0ti^_A=G0rm+O_>O;wIPih%^Ma^P2|W7^_&-kO zzgl4DdNuUz0vm=;hF=5Z3^ytHx0Z2z=dYb$c3#lD=7MLLBbWLX2BrgiiA?hPpEP5G zEWbE#EiaH(GGO=@e68ro2V>W*eBBi$uP*R1ec`>ff%j-a@Vy4UD+_pUU*LT(f$#PK zW2Ps(4=(V|?cn?WneTQ(*8>5*mkWwtEr?#9!S{;6l#j*KD!hcFh3`cI--#r?oipP9 zhVuVNjTaR0`N1T1ghgyVla}7KHUVM7tmpiy3DVmO)rBwk{X0;0c(ETx0&kfj-%108 z9|!oEGWvc981y%A2^ceQ8}KhI$nJ1xENb9*#K6Aj0-yH<#`_BFodfceGS$i1-_sS zY^S!dEi>nMaDc73fv>{hALm;Kj)@6;(>8FtNZ^{Tz`yzf=Vyn=Pan8DTX|Pc<$ZX- z?e+%#^)L7zFz9_vM z_8@^H^8w!!2aY!h98(MUY7$asU*%iL(7N#e_m>CUt3~-P9B@k#;VW!$xR<2=jmhS@ z#s|b=djli_8U=dYS(jurVFrU0lR}V3OrC3*TQKIBGXIrx@5i+%WI^ zVz&nkyr&I;v z0VMg!CJfaUiT*z>p;lt1tWCotY|UaQU=v)x6(_*H-(kYT3#=KhSe-8LIu$TqH(*gaz{@&;fvuD2 zUIU|s0AHa2>IQysDU<(UdLJJt z2^quLYa;mVo<-}ljZjS%Wn$&^PTy>D40HT z;OY6mp0=Qj=b`T230#{#aNiK%`x?n}@dMA52HyJ&yeAoWuNf@3Zm|7+K-V<~o{I&% z_Y&scci_G9p_Yw{PvVz-lefvPQu`MZ_~v);y;@KlaG9^3Nn_8B1+z3dUoh}LGf4b= zK{fG{Wg3&%xfea@&8wLe8FLiXc@)&c0=VuZ^s*GN**VDW6p(A(()&iRVTbh^rW0jP z7&u-8#JpX=Y}vrq&cJoSfLq`rU)}@O6Aer68?ZPF@H#(WJ*L1C_pgALCxGFC1Czl7 z9Tp>J@FH2$OfJ&0kVI$Zj~v;J(l!^Q`3hK^x}|>^FtIo=1_|wA?%17iQtqjN!s#eJ!6{sy8<;~s z@GTVJ+F!sU_>s@4fF~=8=T#JsvjF=A1s10U-dG04{R|9jA9&jv*lsH@NEECvy}%oI zfa!VxvmXO5ivjcX35=2#cqJDw-8En~e88*C!KZX`X7mSMKLytJ46KkTg##f!d za)BWsTq*JA1Kz0tk$W$2|6^LoPB zpPmbjZs5K0V8NXa_In+8I1CrO{E%SE%~R!v|B0im`Z;U?7n0ZldCCnqCqL!>b%A^T2L8k?_E#S8 zKWtE$V6D2aI8*17$dYV<35|TJA5QKP%;t1pteL=fw_%H}$eQOndS#cgzkR?laRJ|s zKYUgREUzYTF8si^R)Kwg!yfjD{3j>auqU!zSiRo)1J`A3mrq~$*sC}uF)#>z;FfY= zy;8s&yMa6K!>tny@!uTypCxbwC2&bCU^*YbEZM;KX*c&Ob%*|IdUrN(MK9o5tIivB zfMs`sz{&-zo&VNyi9h8&e}MmL0PnlW*QTiHrB%rD2`Sz&l=w4&yZ!;w-o!O(MJ(P2 zcq&VX9M=R3;3EB@aT!N zy>(#8{J^(Jpz-q$?zIg9KN>g!8U&tNv1~SAneXtJO_5(FflESxWxoLH>staF6S(vR zn0E; zD8*U$_%5SYW?)|9z`E&!z`7U>Ej)&uzoT&Iue(4Eo<2{8*p&xln+EBa!p*E-sEjR`CXb%?}vs9C+CS zc>)uTuzlq7ci>=8Thc|+W?27z4P~9K@Lgrrf@$`#({Ab*|TdmIDGqG%b)WqLkGG!L|KXgd_70Q?5T2mRp`*D&_ z@>F)I_nJZone%$HqnzpI921zQ4MoZiUy&->kjyTeJV| zTl#tWxx4!-KmWUW`n$jU{`$WX)^m1*d`dYr$u(`s^!H0nPWcyB_3s;xZv39q4|2Yn zzIRTtt=oO3^XI2^qAMyp9ril6WW+9t+TWzR^|)5woQR@53of5f?mJer=v>B$EM~_)l-R_Xznf6oeWzx^n@>{b0t*hncskrx`GWF}r z-|h43q`F^hI>qN=;Mgm6>y1iBT+#~J;wKZA&pmWUafK}B!N}*b1@|J^Wr_|7w$I7; zt5KV}^pB%DuT#X%Ba`w>PAPHs?y^)Ccrj^$o3iz~1@6k_#~hL;IaoQWPL1ul_;lu{ zd7ka_DnIRXpI@`?j=RHgxvCG2C$tuwa9};IQtaBT_j&o;vmXvFpI;sK>Wy4gRpURF zx#205?9-~>M5gqWe4B7|UVww7`icU(lge|7P6fL1pPHrU!e_baA_te>nnx^adgfI& zUFu2t;4IO%i<70n&+o%San%|HedVl@6;AWKk6m2OZ}%zks6=&KWt)7)yp89V<}rA? z%N=?ZsAE_s(VU@Vc)DeqPn#Fh=Y?f+?)J=|a&OOb@#2z)uJgQ7UK-5HJ1}Fhbfk-? zx?toX&Zoi!4wf!~hH8aNHihh&z`V2P-HKLA*LkNoW{EF3<-zG*_Tq$mkkrS6?RfzK zi)L)yccO7#VcNpweXhSMTc_5Ay!<*n>&MRZ^Y{M=JbvTQzmx0^+S0ev7cnkAYI%$4 ze2dSLdDs87w98g~n;5K6|7u~oT;-0<%jK%?RsMQewIFZ#Y*o`q%h}b9U#az)Y&)jG ztzi=NtjBP{?j)(+u9hXCeLp;pPS0B4c=VC){E6*ywHj~S?z!k$Bxs?Ch6K*n1cHi^2SLRI6N2b>kxI`y4o zyWWeBTnRUvB^xKXGX6{a$XVU+PByH-#VCbwxAUDuqyj`)%|(fb0UMCF;o@~$nC z4L=wc)LnVw{jOQbFz{ZQmDd6De@%cIkli+R?R2an})b{&`e_^_|6 zhFMB#rMr~Q3PC3yrgDjov)uMA?DEKHkxt&w<`xpzn_8nRxoQT>CkrF~*d>SZBo?w+ z?Fu|n7o#a3d8^%N%MyVOlO^eaEKg@}Jz1*eH&N-wg5$s5IPz3^D9ii_U^98v*mIiE zS@N5rtL=>~-sj(J>X{(W>-OiLW1oQ0av7aH9ty{%P0aRKC}b|x_}PG|CH_kT`~C+9 z`P3Ra+|!P*r!d@h-KEH8@F7`r^#gVlzk~em{xU@zUEyzjL2zHmpT(*FBce7jg=|i1 zy)<9)rq6VbLlX>2k11Z*;AXc+u&=u2vBZlV$DWog>^5mSEI0S{QvHvD{jvX;L=WY- z8ya6SNr^fl^rS)7*hR}Pf=5l+@4;2$GmgFaC5t5%XS5_532_J?xS(`-gOmKW<6X6H z4vGEKXfu4~%v&GQyzf&m*TY){h!&qb{Ur2BZ`q(`y zc8OfiiEy_r#m+-sDN^@09JiIawAI;rj^bTUw$0(J=ZP#j)z%h&day9b}a6P@?2ydR3y8pG#d0= zVV2oj5oW$XaLI&*$KpLZIqan_HqDN0>Ak7Tro88b+P@1|ZWs$6JnnKue8F*D?b=?) zjkV6wYB_JG7cyo|*fwR4d8Nn_h0HhaqUXA~?P_}5C;rksq}8)0KIJ=4+JzJPlRk34 z=(@}kzV1Xqec{?8jE8tS4{{_P&J@fPVV2ELnm^%d%*=L=C0k;IUJJfF$p7xk_T8;{ z?5&qR^3`zcxcKNoj_s?1x25)r%G59Av2~epH+{kOBh%FiAJtt<>Yj1<)UmG3mJF|W z3j&;#e=T4$eDYCEM!4@p^|7z+Wnn4pZ=B`+bDIhs zp272;Y;n*2 z{OG1NpCiA|f7$s7FOOf4TN2r3^2Gk%3L)nw3;WMV&Aw5swezu!b8fc&Qdu$ATh=W1 z9_H;>oVn&L+Z^jlyk{;Yue#b^`%opU3=oSpr%~ki<~5JQji;JxWPB4V%(6NB`TUQo#$ArQu`m89 zeQ3(G-2NtTYo5ba*_RpZDk}wZJ=J^VoEE!V?K14W$R8;8a>8Ggw;PMvJUr#@EjVVf zB9ZR_^M2{uAKa|JCcG~{Wm5rX_ww!QeeOTV*8nj z4)0si4<@UW7_dKEJVDoK50hrcAq^$2os;Tr?Rc+z@O$F?qcc0Sx_ah2>Rxu*Io-p) zEuv>r&_T99&dIwc{lCDIa9F6NfT!+&%9=$2-<^5Z-fDko&GE;oLv@Ra&c`)+H`o99 zwWdt_pq5I$u!s(4S++p>L(}xgX;slO(kd%dpQv=KP-;D)!WihRZ0-D~NT9xB{@Dz3 zlb3edTMm~OJKH@LGJJA)O}3$!%7hiW4?C(HaWXmL>~h2<Q%P5$_{Me6AeveR9N4XL17rgEatT*T~8M literal 0 HcmV?d00001 diff --git a/doc/container.htm b/doc/container.htm new file mode 100644 index 00000000..9a0e5602 --- /dev/null +++ b/doc/container.htm @@ -0,0 +1,393 @@ + + + + + +Container Concepts + + + + +

c++boost.gifContainer Concepts

+ +

Vector

+ +

Description

+ +

A Vector describes common aspects of dense, packed and sparse vectors. +

+ +

Refinement of

+ +

Vector Expression.

+ +

Associated types

+ + + + + + + + + + + + + + + + + +
Value type value_type The type of the vector.
Distance type difference_type A signed integral type used to represent the distance + between two of the vector's iterators.
Size type size_type An unsigned integral type that can represent any + nonnegative value of the vector's distance type.
+ +

Notation

+ + + + + + + + + + + + + + + + + + +
V A type that is a model of Vector
vObjects of type V
n, iObjects of a type convertible to size_type +
tObject of a type convertible to value_type +
+ +

Definitions

+ +

Valid expressions

+ +

In addition to the expressions defined in Vector Expression the +following expressions must be valid.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Type requirements Return type
Sizing constructor V v (n)  V
Insert v.insert (i, t) v is mutable.void
Erase v.erase (i) v is mutable.void
Clear v.clear () v is mutable.void
Resize v.resize (n) v is mutable.void
+ +

Expression semantics

+ +

Semantics of an expression is defined only where it differs +from, or is not defined in Vector Expression.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Precondition Semantics Postcondition
Sizing constructor V v (n) n >= 0 Creates a vector of n elements. v.size () == n.
Insert v.insert (i, t) 0 <= i < v.size () and
+ v (i) is a copy of value_type ().
A copy of t is inserted in v. + v (i) is a copy of t.
Erase v.erase (i) 0 <= i < v.size () Destroys the element v (i) and replaces + it with value_type (). v (i) is a copy of value_type (). +
Clear v.clear ()   Equivalent to
+ for (i = 0; i < v.size (); ++ i)
+   v.erase (i);
 
Resize v.resize (n)  Modifies the vector so that it can hold n + elements. v.size () == n.
+ +

Complexity guarantees

+ +

The run-time complexity of the sizing constructor is linear in +the vector's size.

+ +

The run-time complexity of insert and erase is specific for +the vector.

+ +

Invariants

+ +

Models

+ +
    +
  • vector<T, A>
  • +
  • unit_vector<T>
  • +
  • zero_vector<T>
  • +
  • sparse_vector<T, A>
  • +
+ +

Matrix

+ +

Description

+ +

A Matrix describes common aspects of dense, packed and sparse +matrices.

+ +

Refinement of

+ +

Matrix Expression.

+ +

Associated types

+ + + + + + + + + + + + + + + + + +
Value type value_type The type of the matrix.
Distance type difference_type A signed integral type used to represent the distance + between two of the matrix's iterators.
Size type size_type An unsigned integral type that can represent any + nonnegative value of the matrix's distance type.
+ +

Notation

+ + + + + + + + + + + + + + + + + + +
M A type that is a model of Matrix
mObjects of type M
n1, n2, i, jObjects of a type convertible to size_type +
tObject of a type convertible to value_type +
+ +

Definitions

+ +

Valid expressions

+ +

In addition to the expressions defined in Matrix Expression the +following expressions must be valid.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Type requirements Return type
Sizing constructor M m (n1, n2)  M
Insert m.insert (i, j, t) m is mutable.void
Erase m.erase (i, j) m is mutable.void
Clear m.clear () m is mutable.void
Resize m.resize (n1, n2) m is mutable.void
+ +

Expression semantics

+ +

Semantics of an expression is defined only where it differs +from, or is not defined in Matrix Expression.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Precondition Semantics Postcondition
Sizing constructor M m (n1, n2) n1 >= 0 and n2 >= 0Creates a matrix of n1 rows and n2 + columns. m.size1 () == n1 and m.size2 () == + n2.
Insert m.insert (i, j, t) 0 <= i < m.size1 (),
+ 0 <= j < m.size2 ()and
+ m (i, j)
is a copy of value_type ().
A copy of t is inserted in m. + m (i, j) is a copy of t.
Erase m.erase (i, j) 0 <= i < m.size1 ()and
+ 0 <= j < m.size2
Destroys the element m (i, j) and + replaces it with value_type (). m (i, j) is a copy of value_type + ().
Clear m.clear ()   Equivalent to
+ for (i = 0; i < m.size1 (); ++ i)
+   for (j = 0; j < m.size2 (); ++ j)
+     m.erase (i, j);
 
Resize m.resize (n1, n2)  Modifies the vector so that it can hold n1 rows + and n2 columns. m.size1 () == n1 and m.size2 () == + n2.
+ +

Complexity guarantees

+ +

The run-time complexity of the sizing constructor is quadratic +in the matrix's size.

+ +

The run-time complexity of insert and erase is specific for +the matrix.

+ +

Invariants

+ +

Models

+ +
    +
  • matrix<T, F, A>
  • +
  • identity_matrix<T>
  • +
  • zero_matrix<T>
  • +
  • triangular_matrix<T, F1, F2, A>
  • +
  • symmetric_matrix<T, F1, F2, A>
  • +
  • banded_matrix<T, F, A>
  • +
  • sparse_matrix<T, F, A>
  • +
+
+ +

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 new file mode 100644 index 00000000..8aaae942 --- /dev/null +++ b/doc/expression.htm @@ -0,0 +1,1033 @@ + + + + + +Expression Concepts + + + + +

c++boost.gifExpression Concepts

+ +

Scalar Expression

+ +

Description

+ +

A Scalar Expression is an expression convertible to a scalar +type.

+ +

Refinement of

+ +

Default Constructible.

+ +

Associated types

+ + + + + + + +
Value type value_type The type of the scalar expression.
+ +

Notation

+ + + + + + +
S A type that is a model of Scalar Expression
+ +

Definitions

+ +

Valid expressions

+ +

In addition to the expressions defined in Default +Constructible the following expressions must be valid.

+ + + + + + + + + + + + + + +
Name Expression Type requirements Return type
Evaluation operator value_type () const  value_type
+ +

Expression semantics

+ +

Semantics of an expression is defined only where it differs +from, or is not defined in Default Constructible.

+ + + + + + + + + + + + + + + + +
Name Expression Precondition Semantics Postcondition
Evaluation operator value_type () const    Evaluates the scalar expression. 
+ +

Complexity guarantees

+ +

The run-time complexity of the evaluation is specific for the +evaluated scalar expression.

+ +

Invariants

+ +

Models

+ +
    +
  • vector_scalar_unary<E, F>
  • +
  • vector_scalar_binary<E1, E2, F>
  • +
+ +

Vector Expression

+ +

Description

+ +

A Vector Expression is an expression evaluatable to a vector. +Vector Expression provides an Indexed +Bidirectional Iterator or an Indexed Random +Access Iterator.

+ +

Refinement of

+ +

Default Constructible.

+ +

Associated types

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Value type value_type The type of the vector expression.
Const iterator type const_iterator A type of iterator that may be used to examine a + vector expression's elements.
Iterator type iterator A type of iterator that may be used to modify a + vector expression's elements.
Distance type difference_type A signed integral type used to represent the distance + between two of the vector expression's iterators.
Size type size_type An unsigned integral type that can represent any + nonnegative value of the vector expression's distance + type.
Const reverse iterator type const_reverse_iterator A Reverse Iterator adaptor whose base iterator type + is the vector expression's const iterator type.
Reverse iterator type reverse_iterator A Reverse Iterator adaptor whose base iterator type + is the vector expression's iterator type.
+ +

Notation

+ + + + + + + + + + + + + + + + + + +
V A type that is a model of Vector Expression
v, v1, v2Object of type V
iObject of a type convertible to size_type +
tObject of a type convertible to value_type
+ +

Definitions

+ +

Valid expressions

+ +

In addition to the expressions defined in Default +Constructible the following expressions must be valid.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Type requirements Return type
Beginning of range v.begin ()   const_iterator
v.begin ()v is mutable. iterator
End of range v.end ()   const_iterator
v.end () v is mutable.iterator
Size v.size ()   size_type
Swap v1.swap (v2) v1 and v2 are mutable.void
Beginning of reverse range v.rbegin ()   const_reverse_iterator
v.rbegin () v is mutable.reverse_iterator
End of reverse range v.rend ()   const_reverse_iterator
v.rend () v is mutable.reverse_iterator
Element access v (i) i is convertible to size_type. + Convertible to value_type.
Assignmentv2 = v1v2 is mutable and v1 is + convertible to V. V &
v2.assign (v1)v2 is mutable and v1 is + convertible to V.V &
Computed assignmentv2 += v1v2 is mutable and v1 is + convertible to V.V &
v2.plus_assign (v1)v2 is mutable and v1 is + convertible to V.V &
v2 -= v1v2 is mutable and v1 is + convertible to V.V &
v2.minus_assign (v1)v2 is mutable and v1 is + convertible to V.V &
v *= tv is mutable and t is + convertible to value_type.V &
+ +

Expression semantics

+ +

Semantics of an expression is defined only where it differs +from, or is not defined in Default Constructible.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Precondition Semantics Postcondition
Beginning of range v.begin ()   Returns an iterator pointing to the first element in + the vector expression. v.begin () is either dereferenceable or + past-the-end. It is past-the-end if and only if v.size + () == 0.
End of range v.end ()   Returns an iterator pointing one past the last + element in the vector expression. v.end () is past-the-end.
Size v.size ()   Returns the size of the vector expression, that is, + its number of elements. v.size () >= 0
Swap v1.swap (v2)   Equivalent to swap (v1, v2).  
Beginning of reverse range v.rbegin ()   Equivalent to reverse_iterator (v.end ()). + v.rbegin () is either dereferenceable or + past-the-end. It is past-the-end if and only if v.size + () == 0.
End of reverse range v.rend ()   Equivalent to reverse_iterator (v.begin ()). + v.rend () is past-the-end.
Element access v (i) 0 <= i < v.size () Returns the i-th element of the vector + expression.  
Assignmentv2 = v1v1.size () == v2.size ()Assigns every element of the evaluated vector + expression v1 to the corresponding element + of v2. 
v2.assign (v1)v1.size () == v2.size ()Assigns every element of v1 to the + corresponding element of v2. 
Computed assignmentv2 += v1v1.size () == v2.size ()Adds every element of the evaluated vector expression + v1 to the corresponding element of v2. 
v2.plus_assign (v1)v1.size () == v2.size ()Adds every element of v1 to the + corresponding element of v2. 
v2 -= v1v1.size () == v2.size ()Subtracts every element of the evaluated vector + expression v1 from the corresponding element + of v2. 
v2.minus_assign (v1)v1.size () == v2.size ()Subtracts every element of v1 from the + corresponding element of v2. 
v *= t Multiplies every element of v with t. 
+ +

Complexity guarantees

+ +

The run-time complexity of begin () and end +() is specific for the evaluated vector expression, +typically amortized constant time.

+ +

The run-time complexity of size () is constant +time.

+ +

The run-time complexity of swap () is specific +for the evaluated vector expression, typically constant time.

+ +

The run-time complexity of rbegin () and rend +() is specific for the evaluated vector expression, +typically amortized constant time.

+ +

The run-time complexity of the element access is specific for +the evaluated vector expression, typically amortized constant +time for the dense and logarithmic for the sparse case.

+ +

The run-time complexity of the arithmetic operations is +specific for the evaluated vector expressions, typically linear +in the size of the expressions.

+ +

Invariants

+ + + + + + + + + + + + + + + + + + +
Valid range For any vector expression v, [v.begin + (), v.end ()) is a valid range.
Completeness An algorithm that iterates through the range [v.begin + (), v.end ()) will pass through every element of v. +
Valid reverse range [v.rbegin (), v.rend ()) is a valid + range.
Equivalence of ranges The distance from v.begin () to v.end + () is the same as the distance from v.rbegin + () to v.rend ().
+ +

Models

+ +
    +
  • vector_range<V>
  • +
  • vector_slice<V>
  • +
  • matrix_row<M>
  • +
  • matrix_column<M>
  • +
  • matrix_vector_range<M>
  • +
  • matrix_vector_slice<M>
  • +
  • vector_unary<E, F>
  • +
  • vector_binary<E1, E2, F>
  • +
  • vector_binary_scalar1<E1, E2, F>
  • +
  • vector_binary_scalar2<E1, E2, F>
  • +
  • matrix_vector_unary1<E>
  • +
  • matrix_vector_unary2<E>
  • +
  • matrix_vector_binary1<E1, E2, F>
  • +
  • matrix_vector_binary2<E1, E2, F>
  • +
+ +

Matrix Expression

+ +

Description

+ +

A Matrix Expression is an expression evaluatable to a matrix. +Matrix Expression provides an Indexed +Bidirectional Column/Row Iterator or an Indexed +Random Access Column/Row Iterator.

+ +

Refinement of

+ +

Default Constructible.

+ +

Associated types

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Value type value_type The type of the matrix expression.
Const iterator types const_iterator1 A type of column iterator that may be used to examine + a matrix expression's elements.
const_iterator2A type of row iterator that may be used to examine a + matrix expression's elements.
Iterator types iterator1 A type of column iterator that may be used to modify + a matrix expression's elements.
iterator2A type of row iterator that may be used to modify a + matrix expression's elements.
Distance type difference_type A signed integral type used to represent the distance + between two of the matrix expression's iterators.
Size type size_type An unsigned integral type that can represent any + nonnegative value of the matrix expression's distance + type.
Const reverse iterator types const_reverse_iterator1 A Reverse Iterator adaptor whose base iterator type + is the matrix expression's const column iterator type.
const_reverse_iterator2 A Reverse Iterator adaptor whose base iterator type + is the matrix expression's const row iterator type.
Reverse iterator types reverse_iterator1 A Reverse Iterator adaptor whose base iterator type + is the matrix expression's column iterator type.
reverse_iterator2 A Reverse Iterator adaptor whose base iterator type + is the matrix expression's row iterator type.
+ +

Notation

+ + + + + + + + + + + + + + + + + + +
M A type that is a model of Matrix Expression
m, m1, m2Object of type M
i, jObjects of a type convertible to size_type +
tObject of a type convertible to value_type
+ +

Definitions

+ +

Valid expressions

+ +

In addition to the expressions defined in Default +Constructible the following expressions must be valid.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Type requirements Return type
Beginning of range m.begin1 ()   const_iterator1
m.begin2 ()  const_iterator2
m.begin1 () m is mutable.  iterator1
m.begin2 () m is mutable.iterator2
End of range m.end1 ()   const_iterator1
m.end2 ()  const_iterator2
m.end1 () m is mutable.  iterator1
m.end2 () m is mutable.iterator2
Size m.size1 ()   size_type
m.size2 ()  size_type
Swap m1.swap (m2)m1 and m2 are + mutable.  void
Beginning of reverse range m.rbegin1 ()   const_reverse_iterator1
m.rbegin2 ()  const_reverse_iterator2
m.rbegin1 () m is mutable.  reverse_iterator1
m.rbegin2 () m is mutable.reverse_iterator2
End of reverse range m.rend1 ()   const_reverse_iterator1
m.rend2 ()  const_reverse_iterator2
m.rend1 () m is mutable.reverse_iterator1
m.rend2 ()m is mutable.reverse_iterator2
Element access m (i, j) i and j are convertible to size_type. + Convertible to value_type.
Assignmentm2 = m1m2 is mutable and m1 is + convertible to M.M &
m2.assign (m1)m2 is mutable and m1 is + convertible to M.M &
Computed assignmentm2 += m1m2 is mutable and m1 is + convertible to M.M &
m2.plus_assign (m1)m2 is mutable and m1 is + convertible to M.M &
m2 -= m1m2 is mutable and m1 is + convertible to M.M &
m2.minus_assign (m1)m2 is mutable and m1 is + convertible to M.M &
m *= tm is mutable and t is + convertible to value_type.M &
+ +

Expression semantics

+ +

Semantics of an expression is defined only where it differs +from, or is not defined in Default Constructible.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Precondition Semantics Postcondition
Beginning of range m.begin1 ()   Returns an iterator pointing to the first element in + the first column of a matrix expression. m.begin1 () is either dereferenceable or + past-the-end. It is past-the-end if and only if m.size1 + () == 0.
m.begin2 ()   Returns an iterator pointing to the first element in + the first row of a matrix expression. m.begin2 () is either dereferenceable or + past-the-end. It is past-the-end if and only if m.size2 + () == 0.
End of range m.end1 ()   Returns an iterator pointing one past the last + element in the matrix expression. m.end1 () is past-the-end.
m.end2 ()   Returns an iterator pointing one past the last + element in the matrix expression. m.end2 () is past-the-end.
Size m.size1 ()   Returns the number of rows of the matrix expression. m.size1 () >= 0
m.size2 ()   Returns the number of columns of the matrix + expression. m.size2 () >= 0
Swap m1.swap (m2)   Equivalent to swap (m1, m2).  
Beginning of reverse range m.rbegin1 ()   Equivalent to reverse_iterator1 (m.end1 ()). + m.rbegin1 () is either dereferenceable + or past-the-end. It is past-the-end if and only if m.size1 + () == 0.
m.rbegin2 ()   Equivalent to reverse_iterator2 (m.end2 ()). + m.rbegin2 () is either dereferenceable + or past-the-end. It is past-the-end if and only if m.size2 + () == 0.
End of reverse range m.rend1 ()   Equivalent to reverse_iterator1 (m.begin1 ()). + m.rend1 () is past-the-end.
m.rend2 ()   Equivalent to reverse_iterator2 (m.begin2 ()). + m.rend2 () is past-the-end.
Element access m (i, j) 0 <= i < m.size1 () and 0 + <= j < m.size2 () Returns the j-th element of the i-th + row of the matrix expression.  
Assignmentm2 = m1m1.size1 () == m2.size1 () and
+ m1.size2 () == m2.size2 ()
Assigns every element of the evaluated matrix + expression m1 to the corresponding element + of m2. 
m2.assign (m1)m1.size1 () == m2.size1 () and
+ m1.size2 () == m2.size2 ()
Assigns every element of m1 to the + corresponding element of m2. 
Computed assignmentm2 += m1m1.size1 () == m2.size1 () and
+ m1.size2 () == m2.size2 ()
Adds every element of the evaluated matrix expression + m1 to the corresponding element of m2. 
m2.plus_assign (m1)m1.size1 () == m2.size1 () and
+ m1.size2 () == m2.size2 ()
Adds every element of m1 to the + corresponding element of m2. 
m2 -= m1m1.size1 () == m2.size1 () and
+ m1.size2 () == m2.size2 ()
Subtracts every element of the evaluated matrix + expression m1 from the corresponding element + of m2. 
m2.minus_assign (m1)m1.size1 () == m2.size1 () and
+ m1.size2 () == m2.size2 ()
Subtracts every element of m1 from the + corresponding element of m2. 
m *= t Multiplies every element of m with t. 
+ +

Complexity guarantees

+ +

The run-time complexity of begin1 (), +begin2 (), end1 () and end2 () is +specific for the evaluated matrix expression.

+ +

The run-time complexity of size1 () and size2 +() is constant time.

+ +

The run-time complexity of swap () is specific +for the evaluated matrix expression, typically constant time.

+ +

The run-time complexity of rbegin1 (), +rbegin2 (), rend1 () and rend2 () is +specific for the evaluated matrix expression.

+ +

The run-time complexity of the element access is specific for +the evaluated matrix expression, typically amortized constant +time for the dense and logarithmic for the sparse case.

+ +

The run-time complexity of the arithmetic operations is +specific for the evaluated matrix expressions, typically +quadratic in the size of the proxies.

+ +

Invariants

+ + + + + + + + + + + + + + + + + + +
Valid range For any matrix expression m, [m.begin1 + (), m.end1 ()) and [m.begin2 (), m.end2 ()) + are valid ranges.
Completeness An algorithm that iterates through the range [m.begin1 + (), m.end1 ()) will pass through every row of m, + an algorithm that iterates through the range [m.begin2 + (), m.end2 ()) will pass through every column of m.
Valid reverse range [m.rbegin1 (), m.rend1 ()) and [m.rbegin2 + (), m.rend2 ()) are valid ranges.
Equivalence of ranges The distance from m.begin1 () to m.end1 + () is the same as the distance from m.rbegin1 + () to m.rend1 () and the distance + from m.begin2 () to m.end2 () + is the same as the distance from m.rbegin2 () + to m.rend2 ().
+ +

Models

+ +
    +
  • matrix_range<M>
  • +
  • matrix_slice<M>
  • +
  • triangular_adaptor<M, F>
  • +
  • symmetric_adaptor<M, F>
  • +
  • banded_adaptor<M>
  • +
  • vector_matrix_binary<E1, E2, F>
  • +
  • matrix_unary1<E, F>
  • +
  • matrix_unary2<E, F>
  • +
  • matrix_binary<E1, E2, F>
  • +
  • matrix_binary_scalar1<E1, E2, F>
  • +
  • matrix_binary_scalar2<E1, E2, F>
  • +
  • matrix_matrix_binary<E1, E2, F>
  • +
+ +
+ +

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 new file mode 100644 index 00000000..56eda66c --- /dev/null +++ b/doc/hermitian.htm @@ -0,0 +1,1208 @@ + + + + + +Hermitian Matrix + + + + +

c++boost.gifHermitian Matrix

+ +

Hermitian Matrix

+ +

Description

+ +

The templated class hermitian_matrix<T, F1, F2, A> +is the base container adaptor for hermitian matrices. For +a (n x n)-dimensional hermitian matrix and 0 <= i +< n, 0 <= j < n holds hi, +j = hj, i-. +The storage of hermitian matrices is packed.

+ +

Example

+ +
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 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 j = i; j < m.size2 (); ++ j)
+            mu (i, j) = std::complex<double> (3 * i + j, 3 * i + j);
+    std::cout << mu << std::endl;
+}
+ +

Definition

+ +

Defined in the header hermitian.hpp.

+ +

Template parameters

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Parameter Description Default
T The type of object stored in the matrix.  
F1Functor describing the type of the hermitian matrix. [1]lower
F2Functor describing the storage organization. [2]row_major
AThe type of the adapted array. [3]unbounded_array<T>
+ +

Model of

+ +

Matrix.

+ +

Type requirements

+ +

None, except for those imposed by the requirements of Matrix.

+ +

Public base classes

+ +

matrix_expression<hermitian_matrix<T, F1, F2, +A> >

+ +

Members

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Member Description
hermitian_matrix () Allocates an uninitialized hermitian_matrix + that holds zero rows of zero elements.
hermitian_matrix (size_type size)Allocates an uninitialized hermitian_matrix + that holds size rows of size + elements.
hermitian_matrix (const hermitian_matrix + &m)The copy constructor.
template<class AE>
+ hermitian_matrix (const matrix_expression<AE> + &ae)
The extended copy constructor.
void resize (size_type size)Reallocates a hermitian_matrix to hold size + rows of size elements. The content of the hermitian_matrix + is not preserved.
size_type size1 () constReturns the number of rows.
size_type size2 () constReturns the number of columns.
const_reference operator () (size_type i, + size_type j) constReturns a const reference of the j-th + element in the i-th row.
reference operator () (size_type i, size_type + j)Returns a reference of the j-th element + in the i-th row.
hermitian_matrix &operator = (const + hermitian_matrix &m)The assignment operator.
hermitian_matrix &assign_temporary + (hermitian_matrix &m)Assigns a temporary. May change the hermitian matrix m.
template<class AE>
+ hermitian_matrix &operator = (const + matrix_expression<AE> &ae)
The extended assignment operator.
template<class AE>
+ hermitian_matrix &assign (const + matrix_expression<AE> &ae)
Assigns a matrix expression to the hermitian matrix. + Left and right hand side of the assignment should be + independent.
template<class AE>
+ hermitian_matrix &operator += (const + matrix_expression<AE> &ae)
A computed assignment operator. Adds the matrix + expression to the hermitian matrix.
template<class AE>
+ hermitian_matrix &plus_assign (const + matrix_expression<AE> &ae)
Adds a matrix expression to the hermitian matrix. + Left and right hand side of the assignment should be + independent.
template<class AE>
+ hermitian_matrix &operator -= (const + matrix_expression<AE> &ae)
A computed assignment operator. Subtracts the matrix + expression from the hermitian matrix.
template<class AE>
+ hermitian_matrix &minus_assign (const + matrix_expression<AE> &ae)
Subtracts a matrix expression from the hermitian + matrix. Left and right hand side of the assignment should + be independent.
template<class AT>
+ hermitian_matrix &operator *= (const AT &at)
A computed assignment operator. Multiplies the + hermitian matrix with a scalar.
template<class AT>
+ hermitian_matrix &operator /= (const AT &at)
A computed assignment operator. Divides the hermitian + matrix through a scalar.
void swap (hermitian_matrix &m)Swaps the contents of the hermitian matrices.
void insert (size_type i, size_type j, + const_reference t)Inserts the value t at the j-th + element of the i-th row.
void erase (size_type i, size_type j)Erases the value at the j-th elemenst of + the i-th row.
void clear ()Clears the matrix.
const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the hermitian_matrix.
const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the hermitian_matrix.
iterator1 begin1 () Returns a iterator1 pointing to the + beginning of the hermitian_matrix.
iterator1 end1 () Returns a iterator1 pointing to the end + of the hermitian_matrix.
const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the hermitian_matrix.
const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the hermitian_matrix.
iterator2 begin2 () Returns a iterator2 pointing to the + beginning of the hermitian_matrix.
iterator2 end2 () Returns a iterator2 pointing to the end + of the hermitian_matrix.
const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed hermitian_matrix. +
const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed hermitian_matrix. +
reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to + the beginning of the reversed hermitian_matrix. +
reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to + the end of the reversed hermitian_matrix.
const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed hermitian_matrix. +
const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed hermitian_matrix. +
reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to + the beginning of the reversed hermitian_matrix. +
reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to + the end of the reversed hermitian_matrix.
+ +

Notes

+ +

[1] Supported parameters for +the type of the hermitian matrix are lower and upper.

+ +

[2] Supported parameters for +the storage organization are row_major and column_major.

+ +

[3] Supported parameters for +the adapted array are unbounded_array<T>, bounded_array<T> +and std::vector<T>.

+ +

Interface

+ +
    // Array based hermitian matrix class 
+    template<class T, class F1, class F2, class A>
+    class hermitian_matrix: 
+        public matrix_expression<hermitian_matrix<T, F1, F2, A> > {
+    public:      
+        typedef std::size_t size_type;
+        typedef std::ptrdiff_t difference_type;
+        typedef T value_type;
+        typedef const T const_reference;
+        typedef T &reference;
+        typedef const T *const_pointer;
+        typedef T *pointer;
+        typedef F1 functor1_type;
+        typedef F2 functor2_type;
+        typedef A array_type;
+        typedef const A const_array_type;
+        typedef const hermitian_matrix<T, F1, F2, A> const_self_type;
+        typedef hermitian_matrix<T, F1, F2, A> self_type;
+        typedef const matrix_const_reference<const_self_type> const_closure_type;
+        typedef matrix_reference<self_type> closure_type;
+        typedef packed_tag storage_category;
+        typedef typename F1::packed_category packed_category;
+        typedef typename F2::orientation_category orientation_category;
+
+        // Construction and destruction
+        hermitian_matrix ();
+        hermitian_matrix (size_type size);
+        hermitian_matrix (size_type size1, size_type size2);
+        hermitian_matrix (const hermitian_matrix &m);
+        template<class AE>
+        hermitian_matrix (const matrix_expression<AE> &ae);
+
+        // Accessors
+        size_type size1 () const;
+        size_type size2 () const;
+        const_array_type &data () const;
+        array_type &data ();
+
+        // Resizing
+        void resize (size_type size);
+        void resize (size_type size1, size_type size2);
+
+        // Element access
+        const_reference operator () (size_type i, size_type j) const;
+        reference operator () (size_type i, size_type j);
+
+        // Assignment
+        hermitian_matrix &operator = (const hermitian_matrix &m);
+        hermitian_matrix &assign_temporary (hermitian_matrix &m);
+        template<class AE>
+        hermitian_matrix &operator = (const matrix_expression<AE> &ae);
+        template<class AE>
+        hermitian_matrix &reset (const matrix_expression<AE> &ae);
+        template<class AE>
+        hermitian_matrix &assign (const matrix_expression<AE> &ae);
+        template<class AE>
+        hermitian_matrix& operator += (const matrix_expression<AE> &ae);
+        template<class AE>
+        hermitian_matrix &plus_assign (const matrix_expression<AE> &ae);
+        template<class AE>
+        hermitian_matrix& operator -= (const matrix_expression<AE> &ae);
+        template<class AE>
+        hermitian_matrix &minus_assign (const matrix_expression<AE> &ae);
+        template<class AT>
+        hermitian_matrix& operator *= (const AT &at);
+        template<class AT>
+        hermitian_matrix& operator /= (const AT &at);
+
+        // Swapping
+        void swap (hermitian_matrix &m);
+        friend void swap (hermitian_matrix &m1, hermitian_matrix &m2);
+
+        // Element insertion and erasure
+        void insert (size_type i, size_type j, const_reference t);
+        void erase (size_type i, size_type j);
+        void clear ();
+
+        class const_iterator1;
+        class iterator1;
+        class const_iterator2;
+        class iterator2;
+        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
+        typedef reverse_iterator_base1<iterator1> reverse_iterator1;
+        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
+        typedef reverse_iterator_base2<iterator2> reverse_iterator2;
+
+        // Element lookup
+        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
+        iterator1 find_first1 (int rank, size_type i, size_type j);
+        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
+        iterator1 find_last1 (int rank, size_type i, size_type j);
+        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
+        iterator2 find_first2 (int rank, size_type i, size_type j);
+        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
+        iterator2 find_last2 (int rank, size_type i, size_type j);
+
+        // Iterators simply are indices.
+
+        class const_iterator1:
+            public container_const_reference<hermitian_matrix>,
+            public random_access_iterator_base<const_iterator1, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename hermitian_matrix::difference_type difference_type;
+            typedef typename hermitian_matrix::value_type value_type;
+            typedef typename hermitian_matrix::const_reference reference;
+            typedef typename hermitian_matrix::const_pointer pointer;
+            typedef const_iterator2 dual_iterator_type;
+            typedef const_reverse_iterator2 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator1 ();
+            const_iterator1 (const hermitian_matrix &m, size_type it1, size_type it2);
+            const_iterator1 (const iterator1 &it);
+
+            // Arithmetic
+            const_iterator1 &operator ++ ();
+            const_iterator1 &operator -- ();
+            const_iterator1 &operator += (difference_type n);
+            const_iterator1 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator1 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator2 begin () const;
+            const_iterator2 end () const;
+            const_reverse_iterator2 rbegin () const;
+            const_reverse_iterator2 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator1 &operator = (const const_iterator1 &it);
+
+            // Comparison
+            bool operator == (const const_iterator1 &it) const;
+            bool operator < (const const_iterator1 &it) const;
+        };
+
+        const_iterator1 begin1 () const;
+        const_iterator1 end1 () const;
+
+        class iterator1:
+            public container_reference<hermitian_matrix>,
+            public random_access_iterator_base<iterator1, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename hermitian_matrix::difference_type difference_type;
+            typedef typename hermitian_matrix::value_type value_type;
+            typedef typename hermitian_matrix::reference reference;
+            typedef typename hermitian_matrix::pointer pointer;
+            typedef iterator2 dual_iterator_type;
+            typedef reverse_iterator2 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            iterator1 ();
+            iterator1 (hermitian_matrix &m, size_type it1, size_type it2);
+
+            // Arithmetic
+            iterator1 &operator ++ ();
+            iterator1 &operator -- ();
+            iterator1 &operator += (difference_type n);
+            iterator1 &operator -= (difference_type n);
+            difference_type operator - (const iterator1 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            iterator2 begin () const;
+            iterator2 end () const;
+            reverse_iterator2 rbegin () const;
+            reverse_iterator2 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            iterator1 &operator = (const iterator1 &it);
+
+            // Comparison
+            bool operator == (const iterator1 &it) const;
+            bool operator < (const iterator1 &it) const;
+        };
+
+        iterator1 begin1 ();
+        iterator1 end1 ();
+
+        class const_iterator2:
+            public container_const_reference<hermitian_matrix>,
+            public random_access_iterator_base<const_iterator2, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename hermitian_matrix::difference_type difference_type;
+            typedef typename hermitian_matrix::value_type value_type;
+            typedef typename hermitian_matrix::const_reference reference;
+            typedef typename hermitian_matrix::const_pointer pointer;
+            typedef const_iterator1 dual_iterator_type;
+            typedef const_reverse_iterator1 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator2 ();
+            const_iterator2 (const hermitian_matrix &m, size_type it1, size_type it2);
+            const_iterator2 (const iterator2 &it);
+
+            // Arithmetic
+            const_iterator2 &operator ++ ();
+            const_iterator2 &operator -- ();
+            const_iterator2 &operator += (difference_type n);
+            const_iterator2 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator2 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator1 begin () const;
+            const_iterator1 end () const;
+            const_reverse_iterator1 rbegin () const;
+            const_reverse_iterator1 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator2 &operator = (const const_iterator2 &it);
+
+            // Comparison
+            bool operator == (const const_iterator2 &it) const;
+            bool operator < (const const_iterator2 &it) const;
+        };
+
+        const_iterator2 begin2 () const;
+        const_iterator2 end2 () const;
+
+        class iterator2:
+            public container_reference<hermitian_matrix>,
+            public random_access_iterator_base<iterator2, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename hermitian_matrix::difference_type difference_type;
+            typedef typename hermitian_matrix::value_type value_type;
+            typedef typename hermitian_matrix::reference reference;
+            typedef typename hermitian_matrix::pointer pointer;
+            typedef iterator1 dual_iterator_type;
+            typedef reverse_iterator1 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            iterator2 ();
+            iterator2 (hermitian_matrix &m, size_type it1, size_type it2);
+
+            // Arithmetic
+            iterator2 &operator ++ ();
+            iterator2 &operator -- ();
+            iterator2 &operator += (difference_type n);
+            iterator2 &operator -= (difference_type n);
+            difference_type operator - (const iterator2 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            iterator1 begin () const;
+            iterator1 end () const;
+            reverse_iterator1 rbegin () const;
+            reverse_iterator1 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            iterator2 &operator = (const iterator2 &it);
+
+            // Comparison
+            bool operator == (const iterator2 &it) const;
+            bool operator < (const iterator2 &it) const;
+        };
+
+        iterator2 begin2 ();
+        iterator2 end2 ();
+
+        // Reverse iterators
+
+        const_reverse_iterator1 rbegin1 () const;
+        const_reverse_iterator1 rend1 () const;
+
+        reverse_iterator1 rbegin1 ();
+        reverse_iterator1 rend1 ();
+
+        const_reverse_iterator2 rbegin2 () const;
+        const_reverse_iterator2 rend2 () const;
+
+        reverse_iterator2 rbegin2 ();
+        reverse_iterator2 rend2 ();
+    };
+ +

Hermitian Adaptor

+ +

Description

+ +

The templated class hermitian_adaptor<M, F> is +a hermitian matrix adaptor for other matrices.

+ +

Example

+ +
int main () {
+    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 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 j = i; j < hau.size2 (); ++ j)
+            hau (i, j) = std::complex<double> (3 * i + j, 3 * i + j);
+    std::cout << sau << std::endl;
+}
+ +

Definition

+ +

Defined in the header hermitian.hpp.

+ +

Template parameters

+ + + + + + + + + + + + + + + + + +
Parameter Description Default
MThe type of the adapted matrix. 
FFunctor describing the type of the hermitian adaptor. + [1]lower
+ +

Model of

+ +

Matrix Expression. +

+ +

Type requirements

+ +

None, except for those imposed by the requirements of Matrix Expression.

+ +

Public base classes

+ +

matrix_expression<hermitian_adaptor<M, F> > +

+ +

Members

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Member Description
hermitian_adaptor () Constructs a hermitian_adaptor that + holds zero rows of zero elements.
hermitian_adaptor (matrix_type &data)Constructs a hermitian_adaptor of a + matrix.
hermitian_adaptor (const hermitian_adaptor + &m)The copy constructor.
template<class AE>
+ hermitian_adaptor (const matrix_expression<AE> + &ae)
The extended copy constructor.
size_type size1 () constReturns the number of rows.
size_type size2 () constReturns the number of columns.
const_reference operator () (size_type i, + size_type j) constReturns a const reference of the j-th + element in the i-th row.
reference operator () (size_type i, size_type + j)Returns a reference of the j-th element + in the i-th row.
hermitian_adaptor &operator = (const + hermitian_adaptor &m)The assignment operator.
hermitian_adaptor &assign_temporary + (hermitian_adaptor &m)Assigns a temporary. May change the hermitian adaptor + m.
template<class AE>
+ hermitian_adaptor &operator = (const + matrix_expression<AE> &ae)
The extended assignment operator.
template<class AE>
+ hermitian_adaptor &assign (const + matrix_expression<AE> &ae)
Assigns a matrix expression to the hermitian adaptor. + Left and right hand side of the assignment should be + independent.
template<class AE>
+ hermitian_adaptor &operator += (const + matrix_expression<AE> &ae)
A computed assignment operator. Adds the matrix + expression to the hermitian adaptor.
template<class AE>
+ hermitian_adaptor &plus_assign (const + matrix_expression<AE> &ae)
Adds a matrix expression to the hermitian adaptor. + Left and right hand side of the assignment should be + independent.
template<class AE>
+ hermitian_adaptor &operator -= (const + matrix_expression<AE> &ae)
A computed assignment operator. Subtracts the matrix + expression from the hermitian adaptor.
template<class AE>
+ hermitian_adaptor &minus_assign (const + matrix_expression<AE> &ae)
Subtracts a matrix expression from the hermitian + adaptor. Left and right hand side of the assignment + should be independent.
template<class AT>
+ hermitian_adaptor &operator *= (const AT &at)
A computed assignment operator. Multiplies the + hermitian adaptor with a scalar.
template<class AT>
+ hermitian_adaptor &operator /= (const AT &at)
A computed assignment operator. Divides the hermitian + adaptor through a scalar.
void swap (hermitian_adaptor &m)Swaps the contents of the hermitian adaptors.
const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the hermitian_adaptor.
const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the hermitian_adaptor.
iterator1 begin1 () Returns a iterator1 pointing to the + beginning of the hermitian_adaptor.
iterator1 end1 () Returns a iterator1 pointing to the end + of the hermitian_adaptor.
const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the hermitian_adaptor.
const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the hermitian_adaptor.
iterator2 begin2 () Returns a iterator2 pointing to the + beginning of the hermitian_adaptor.
iterator2 end2 () Returns a iterator2 pointing to the end + of the hermitian_adaptor.
const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed hermitian_adaptor. +
const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed hermitian_adaptor. +
reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to + the beginning of the reversed hermitian_adaptor. +
reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to + the end of the reversed hermitian_adaptor.
const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed hermitian_adaptor. +
const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed hermitian_adaptor. +
reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to + the beginning of the reversed hermitian_adaptor. +
reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to + the end of the reversed hermitian_adaptor.
+ +

Notes

+ +

[1] Supported parameters +for the type of the hermitian adaptor are lower and upper.

+ +

Interface

+ +
    // Hermitian matrix adaptor class 
+    template<class M, class F>
+    class hermitian_adaptor: 
+        public matrix_expression<hermitian_adaptor<M, F> > {
+    public:      
+        typedef const M const_matrix_type;
+        typedef M matrix_type;
+        typedef F functor_type;
+        typedef typename M::size_type size_type;
+        typedef typename M::difference_type difference_type;
+        typedef typename M::value_type value_type;
+        typedef typename M::value_type const_reference;
+        typedef typename M::reference reference;
+        typedef typename M::const_pointer const_pointer;
+        typedef typename M::pointer pointer;
+        typedef const hermitian_adaptor<M, F> const_self_type;
+        typedef hermitian_adaptor<M, F> self_type;
+        typedef const matrix_const_reference<const_self_type> const_closure_type;
+        typedef matrix_reference<self_type> closure_type;
+        typedef typename storage_restrict_traits<typename M::storage_category,
+                                                 packed_proxy_tag>::storage_category storage_category;
+        typedef typename F::packed_category packed_category;
+        typedef typename M::orientation_category orientation_category;
+
+        // Construction and destruction
+        hermitian_adaptor ();
+        hermitian_adaptor (matrix_type &data);
+        hermitian_adaptor (const hermitian_adaptor &m);
+
+        // Accessors
+        size_type size1 () const;
+        size_type size2 () const;
+        const_matrix_type &data () const;
+        matrix_type &data ();
+
+        // Element access
+        const_reference operator () (size_type i, size_type j) const;
+        reference operator () (size_type i, size_type j);
+
+        // Assignment
+        hermitian_adaptor &operator = (const hermitian_adaptor &m);
+        hermitian_adaptor &assign_temporary (hermitian_adaptor &m);
+        template<class AE>
+        hermitian_adaptor &operator = (const matrix_expression<AE> &ae);
+        template<class AE>
+        hermitian_adaptor &assign (const matrix_expression<AE> &ae);
+        template<class AE>
+        hermitian_adaptor& operator += (const matrix_expression<AE> &ae);
+        template<class AE>
+        hermitian_adaptor &plus_assign (const matrix_expression<AE> &ae);
+        template<class AE>
+        hermitian_adaptor& operator -= (const matrix_expression<AE> &ae);
+        template<class AE>
+        hermitian_adaptor &minus_assign (const matrix_expression<AE> &ae);
+        template<class AT>
+        hermitian_adaptor& operator *= (const AT &at);
+        template<class AT>
+        hermitian_adaptor& operator /= (const AT &at);
+
+        // Swapping
+        void swap (hermitian_adaptor &m);
+        friend void swap (hermitian_adaptor &m1, hermitian_adaptor &m2);
+
+        class const_iterator1;
+        class iterator1;
+        class const_iterator2;
+        class iterator2;
+        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
+        typedef reverse_iterator_base1<iterator1> reverse_iterator1;
+        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
+        typedef reverse_iterator_base2<iterator2> reverse_iterator2;
+
+        // Element lookup
+        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
+        iterator1 find_first1 (int rank, size_type i, size_type j);
+        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
+        iterator1 find_last1 (int rank, size_type i, size_type j);
+        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
+        iterator2 find_first2 (int rank, size_type i, size_type j);
+        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
+        iterator2 find_last2 (int rank, size_type i, size_type j);
+
+        // Iterators simply are indices.
+
+        class const_iterator1:
+            public container_const_reference<hermitian_adaptor>,
+            public random_access_iterator_base<const_iterator1, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename hermitian_adaptor::difference_type difference_type;
+            typedef typename hermitian_adaptor::value_type value_type;
+            typedef typename hermitian_adaptor::const_reference reference;
+            typedef typename hermitian_adaptor::const_pointer pointer;
+            typedef const_iterator2 dual_iterator_type;
+            typedef const_reverse_iterator2 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator1 ();
+            const_iterator1 (const hermitian_adaptor &m, size_type it1, size_type it2);
+            const_iterator1 (const iterator1 &it);
+
+            // Arithmetic
+            const_iterator1 &operator ++ ();
+            const_iterator1 &operator -- ();
+            const_iterator1 &operator += (difference_type n);
+            const_iterator1 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator1 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator2 begin () const;
+            const_iterator2 end () const;
+            const_reverse_iterator2 rbegin () const;
+            const_reverse_iterator2 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator1 &operator = (const const_iterator1 &it);
+
+            // Comparison
+            bool operator == (const const_iterator1 &it) const;
+            bool operator < (const const_iterator1 &it) const;
+        };
+
+        const_iterator1 begin1 () const;
+        const_iterator1 end1 () const;
+
+        class iterator1:
+            public container_reference<hermitian_adaptor>,
+            public random_access_iterator_base<iterator1, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename hermitian_adaptor::difference_type difference_type;
+            typedef typename hermitian_adaptor::value_type value_type;
+            typedef typename hermitian_adaptor::reference reference;
+            typedef typename hermitian_adaptor::pointer pointer;
+            typedef iterator2 dual_iterator_type;
+            typedef reverse_iterator2 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            iterator1 ();
+            iterator1 (hermitian_adaptor &m, size_type it1, size_type it2);
+
+            // Arithmetic
+            iterator1 &operator ++ ();
+            iterator1 &operator -- ();
+            iterator1 &operator += (difference_type n);
+            iterator1 &operator -= (difference_type n);
+            difference_type operator - (const iterator1 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            iterator2 begin () const;
+            iterator2 end () const;
+            reverse_iterator2 rbegin () const;
+            reverse_iterator2 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            iterator1 &operator = (const iterator1 &it);
+
+            // Comparison
+            bool operator == (const iterator1 &it) const;
+            bool operator < (const iterator1 &it) const;
+        };
+
+        iterator1 begin1 ();
+        iterator1 end1 ();
+
+        class const_iterator2:
+            public container_const_reference<hermitian_adaptor>,
+            public random_access_iterator_base<const_iterator2, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename hermitian_adaptor::difference_type difference_type;
+            typedef typename hermitian_adaptor::value_type value_type;
+            typedef typename hermitian_adaptor::const_reference reference;
+            typedef typename hermitian_adaptor::const_pointer pointer;
+            typedef const_iterator1 dual_iterator_type;
+            typedef const_reverse_iterator1 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator2 ();
+            const_iterator2 (const hermitian_adaptor &m, size_type it1, size_type it2);
+            const_iterator2 (const iterator2 &it);
+
+            // Arithmetic
+            const_iterator2 &operator ++ ();
+            const_iterator2 &operator -- ();
+            const_iterator2 &operator += (difference_type n);
+            const_iterator2 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator2 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator1 begin () const;
+            const_iterator1 end () const;
+            const_reverse_iterator1 rbegin () const;
+            const_reverse_iterator1 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator2 &operator = (const const_iterator2 &it);
+
+            // Comparison
+            bool operator == (const const_iterator2 &it) const;
+            bool operator < (const const_iterator2 &it) const;
+        };
+
+        const_iterator2 begin2 () const;
+        const_iterator2 end2 () const;
+
+        class iterator2:
+            public container_reference<hermitian_adaptor>,
+            public random_access_iterator_base<iterator2, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename hermitian_adaptor::difference_type difference_type;
+            typedef typename hermitian_adaptor::value_type value_type;
+            typedef typename hermitian_adaptor::reference reference;
+            typedef typename hermitian_adaptor::pointer pointer;
+            typedef iterator1 dual_iterator_type;
+            typedef reverse_iterator1 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            iterator2 ();
+            iterator2 (hermitian_adaptor &m, size_type it1, size_type it2);
+
+            // Arithmetic
+            iterator2 &operator ++ ();
+            iterator2 &operator -- ();
+            iterator2 &operator += (difference_type n);
+            iterator2 &operator -= (difference_type n);
+            difference_type operator - (const iterator2 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            iterator1 begin () const;
+            iterator1 end () const;
+            reverse_iterator1 rbegin () const;
+            reverse_iterator1 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            iterator2 &operator = (const iterator2 &it);
+
+            // Comparison
+            bool operator == (const iterator2 &it) const;
+            bool operator <(const iterator2 &it) const;
+        };
+
+        iterator2 begin2 ();
+        iterator2 end2 ();
+
+        // Reverse iterators
+
+        const_reverse_iterator1 rbegin1 () const;
+        const_reverse_iterator1 rend1 () const;
+
+        reverse_iterator1 rbegin1 ();
+        reverse_iterator1 rend1 ();
+
+        const_reverse_iterator2 rbegin2 () const;
+        const_reverse_iterator2 rend2 () const;
+
+        reverse_iterator2 rbegin2 ();
+        reverse_iterator2 rend2 ();
+    };
+ +
+ +

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/index.htm b/doc/index.htm new file mode 100644 index 00000000..588fe1f9 --- /dev/null +++ b/doc/index.htm @@ -0,0 +1,316 @@ + + + + + +Boost Basic Linear Algebra + + + + +

c++boost.gif Basic Linear Algebra

+ +

uBLAS is a C++ template class library that provides BLAS level 1, 2, 3 +functionality for dense, packed and sparse matrices. The design +and implementation unify mathematical notation via operator +overloading and efficient code generation via expression +templates.

+ +

Functionality

+ +

uBLAS provides templated C++ classes for dense, unit and +sparse vectors, dense, identity, triangular, banded, symmetric, +hermitian and sparse matrices. Views into vectors and matrices +can be constructed via ranges or slices and adaptor classes. The +library covers the usual basic linear algebra operations on +vectors and matrices: reductions like different norms, addition +and subtraction of vectors and matrices and multiplication with a +scalar, inner and outer products of vectors, matrix vector and +matrix matrix products and triangular solver. The glue between +containers, views and expression templated operations is a mostly +STL conforming iterator +interface.

+ +

Dense, packed and sparse matrix classes are being tested with the CLAPACK test suite.

+ +

Known limitations:

+ +
    +
  • The implementation assumes a linear memory address model.
  • +
  • Tuning was focussed on dense matrices.
  • +
+ +

Documentation

+ + + +

Supported Platforms

+ +

As main development platform for uBLAS we used MSVC 6.0 with +Dinkumware STL. Other compilers known to accept the library are

+ +
    +
  • MSVC 6.0 with STLPort-4.5.3
  • +
  • BCC 5.5
  • +
  • GCC 2.95.x, 3.0.x, 3.1
  • +
  • ICC 5.0, 6.0
  • +
  • Comeau 4.2.x
  • +
  • MWCW
  • +
+ +

Download

+ +

You can download the current stable release of the source code +from here. +Prerequisite is the latest stable release of the Boost libraries Configuration, +Timer and optionally SmartPointer.

+ +

CVS Access

+ +

You can also check out the latest version via anonymous CVS. +Here's how:

+ +
 cvs -d:pserver:anonymous@cvs.boost.sourceforge.net:/cvsroot/boost login
+     (password is empty)
+ cvs -d:pserver:anonymous@cvs.boost.sourceforge.net:/cvsroot/boost checkout -r matrix_development boost/boost/numeric/ublas
+ cvs -d:pserver:anonymous@cvs.boost.sourceforge.net:/cvsroot/boost checkout -r matrix_development boost/libs/numeric/ublas
+ +

If you have gzip installed on your system, you can speed up +the transfer using

+ +
 cvs -d:pserver:anonymous@cvs.boost.sourceforge.net:/cvsroot/boost -z9 checkout -r matrix_development boost/boost/numeric/ublas
+ cvs -d:pserver:anonymous@cvs.boost.sourceforge.net:/cvsroot/boost -z9 checkout -r matrix_development boost/libs/numeric/ublas
+ +

You can also view +the CVS archive. You may find the library here. +Documentation and test programs reside here.

+ +

Mailing lists

+ +

uBLAS has no dedicated mailing list. Feel free to use the +mailing lists of Boost.

+ +

Authors and Credits

+ +

uBLAS initially was written by Joerg Walter and Mathias Koch. +We would like to thank all, which supported the development of +this library: David Abrahams, Ed Brey, Fernando Cacciola, Beman Dawes, +Bob Fletcher, Kresimir Fresl, Joachim Kessel, Toon Knapen, +Jens Maurer, Gary Powell, Joachim Pyras, Peter Schmitteckert, Jeremy +Siek, Markus Steffl, Michael Stevens, Benedikt Weber, Martin Weiser, +Marc Zimmermann and the members of Boost

+ +

Frequently Asked Questions

+ +

Q: I'm running the uBLAS dense vector and matrix benchmarks. +Why do I see a significant performance difference between the +native C and library implementations?
+A: uBLAS distinguishes debug mode (size and type conformance +checks enabled, expression templates disabled) and release mode +(size and type conformance checks disabled, expression templates +enabled). Please check, if the preprocessor symbol NDEBUG +of cassert is defined. NDEBUG enables +release mode, which in turn uses expression templates.

+ +

Q: I've written some uBLAS tests, which try to incorrectly +assign different matrix types or overrun vector and matrix +dimensions. Why don't I get a compile time or runtime diagnostic?
+A: uBLAS distinguishes debug mode (size and type conformance +checks enabled, expression templates disabled) and release mode +(size and type conformance checks disabled, expression templates +enabled). Please check, if the preprocessor symbol NDEBUG +of cassert is defined. NDEBUG disables +debug mode, which is needed to get size and type conformance +checks.

+ +

Q: I've written some uBLAS benchmarks to measure the +performance of matrix chain multiplications like prod (A, +prod (B, C)) and see a significant performance penalty due +to the use of expression templates. How can I disable expression +templates?
+A: You do not need to disable expression templates. Please try +reintroducing temporaries using either prod (A, matrix_type +(prod (B, C))) or prod (A, prod<matrix_type> +(B, C)).

+ +

Contact Information

+ +

If you have a problem, or have found a bug, please send us a note.

+ +
+ +

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/iterator.htm b/doc/iterator.htm new file mode 100644 index 00000000..0a476816 --- /dev/null +++ b/doc/iterator.htm @@ -0,0 +1,1251 @@ + + + + + +Iterator Concepts + + + + +

c++boost.gifIterator Concepts

+ +

An Iterator is a restricted pointer-like object pointing into +a vector or matrix container.

+ +

Indexed +Bidirectional Iterator

+ +

Description

+ +

An Indexed Bidirectional Iterator is an iterator of a +container that can be dereferenced, incremented, decremented and +carries index information.

+ +

Refinement of

+ +

Assignable, Equality Comparable, Default Constructible.

+ +

Associated types

+ + + + + + + + + + +
Value type The type of the value obtained by dereferencing a + Indexed Bidirectional Iterator
Container typeThe type of the container a Indexed Bidirectional + Iterator points into.
+ +

Notation

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
I A type that is a model of Indexed Bidirectional + Iterator
T The value type of I
CThe container type of I
it, itt, it1, it2 Objects of type I
t Object of type T
cObject of type C
+ +

Definitions

+ +

A Indexed Bidirectional Iterator may be mutable, +meaning that the values referred to by objects of that type may +be modified, or constant, meaning that they may not. If an +iterator type is mutable, this implies that its value type is a +model of Assignable; the converse, though, is not necessarily +true.

+ +

A Indexed Bidirectional Iterator may have a singular +value, meaning that the results of most operations, including +comparison for equality, are undefined. The only operation that +is guaranteed to be supported is assigning a nonsingular iterator +to a singular iterator.

+ +

A Indexed Bidirectional Iterator may have a dereferenceable +value, meaning that dereferencing it yields a well-defined value. +Dereferenceable iterators are always nonsingular, but the +converse is not true.

+ +

An Indexed Bidirectional Iterator is past-the-end if it +points beyond the last element of a container. Past-the-end +values are nonsingular and nondereferenceable.

+ +

Valid expressions

+ +

In addition to the expressions defined for Assignable, +Equality Comparable and Default Constructible, the following +expressions must be valid.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Type requirements Return type
Default constructor I it   
Dereference *it   Convertible to T.
Dereference assignment *it = t I is mutable.  
Member access it->m T is a type for which t.m + is defined.  
Preincrement++ it  I &
Postincrement it ++  I
Predecrement -- it I &
Postdecrement it --   I
Function callit () Convertible to C &.
Indexit.index () C::size_type
+ +

Expression Semantics

+ +

Semantics of an expression is defined only where it differs +from, or is not defined in, Assignable, Equality Comparable and +Default Constructible.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Precondition Semantics Postcondition
Default constructor I it   it is singular.
Dereference *it it is dereferenceable.   
Dereference assignment *it = tSame as for *it. *it is a copy of t.
Member access it->mit is dereferenceable. Equivalent to (*it).m 
Preincrement ++ it it is dereferenceable. it is modified to point to the next + element. it is dereferenceable or past-the-end.
+ &it == &++ it
.
+ If it1 == it2,
+ then ++ it1 == ++ it2.
Postincrement it ++ Same as for ++ it.Equivalent to
+ {
+  I itt = it;
+  ++ it;
+  return itt;
+ }
it is dereferenceable or past-the-end.
Predecrement -- it it is dereferenceable or past-the-end.
+ There exists a dereferenceable iterator itt + such that it == ++ itt.
it is modified to point to the previous + element. it is dereferenceable.
+ &it = &-- it.
+ If it1 == it2,
+ then -- it1 == -- it2.
Postdecrement it -- Same as for -- it.Equivalent to
+ {
+  I itt = it;
+  -- it;
+  return itt;
+ }
it is dereferenceable. 
Function callit ()it is dereferenceable or past-the-end. If it points into container c + then it () = c. 
Indexit.index ()it is dereferenceable or past-the-end. it.index () >= 0
+ and
+ it.index () <= it ().size ()
If it1 == it2,
+ then it1.index () == it2.index ().
+ If it1 == it2,
+ then it1.index () < (++ it2).index + ().
+ If it1 == it2,
+ then it1.index () > (-- it2).index + ().
+ +

Complexity guarantees

+ +

The complexity of operations on indexed bidirectional +iterators is guaranteed to be amortized constant time.

+ +

Invariants

+ + + + + + + + + + + + + + +
Identity it1 == it2 if and only if &*it1 + == &*it2.
Symmetry of increment and decrement If it is dereferenceable, then ++ + it; --it; is a null operation. Similarly, -- + it; ++ it; is a null operation.
Relation between iterator index and container element + operator If it is dereferenceable, *it == + it () (it.index ()).
+ +

Models

+ +
    +
  • sparse_vector<T>::iterator
  • +
+ +

Indexed Random +Access Iterator

+ +

Description

+ +

An Indexed Random Access Iterator is an iterator of a +container that can be dereferenced, moved forward, moved backward +and carries index information.

+ +

Refinement of

+ +

LessThanComparable, Indexed +Bidirectional Iterator.

+ +

Associated types

+ + + + + + + + + + +
Value type The type of the value obtained by dereferencing a + Indexed Random Access Iterator
Container typeThe type of the container a Indexed Random Access + Iterator points into.
+ +

Notation

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
I A type that is a model of Indexed Random Access + Iterator
T The value type of I
CThe container type of I
it, itt, it1, it2 Objects of type I
t Object of type T
nObject of type C::difference_type
+ +

Definitions

+ +

An Indexed Random Access Iterator it1 is reachable +from an Indexed Random Access Iterator it2 if, after +applying operator ++ to it2 a finite +number of times, it1 == it2.

+ +

Valid expressions

+ +

In addition to the expressions defined for Indexed Bidirectional +Iterator, the following expressions must be valid.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Type requirements Return type
Forward motion it += n I &
Iterator addition it + n   I
Backward motioni -= n  I &
Iterator subtraction it - n  I 
Difference it1 - it2 C::difference_type
Element operator it [n] Convertible to T.
Element assignment it [n] = tI is mutable Convertible to T.
+ +

Expression Semantics

+ +

Semantics of an expression is defined only where it differs +from, or is not defined in, Indexed Bidirectional +Iterator.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Precondition Semantics Postcondition
Forward motion it += n Including it itself, there must be n + dereferenceable or past-the-end iterators following or + preceding it, depending on whether n + is positive or negative. If n > 0, equivalent to executing ++ + it n times. If n < 0, + equivalent to executing -- it n + times. If n == 0, this is a null operation. it is dereferenceable or past-the-end.
Iterator addition it + nSame as for i += n.Equivalent to
+ {
+  I itt = it;
+  return itt += n;
+ }
Result is dereferenceable or past-the-end.
Backward motionit -= nIncluding it itself, there must be n + dereferenceable or past-the-end iterators preceding or + following it, depending on whether n + is positive or negative. Equivalent to it += (-n). it is dereferenceable or past-the-end.
Iterator subtraction it - nSame as for i -= n.Equivalent to
+ {
+  I itt = it;
+  return itt -= n;
+ }
Result is dereferenceable or past-the-end.
Difference it1 - it2 Either it1 is reachable from it2 + or it2 is reachable from it1, + or both. Returns a number n such that it1 + == it2 + n  
Element operatorit [n] it + n exists and is dereferenceable. Equivalent to *(it + n) 
Element assignment i[n] = t Same as for it [n].Equivalent to *(it + n) = t 
+ +

Complexity guarantees

+ +

The complexity of operations on indexed random access +iterators is guaranteed to be amortized constant time.

+ +

Invariants

+ + + + + + + + + + + + + + +
Symmetry of addition and subtraction If it + n is well-defined, then it + += n; it -= n; and (it + n) - n are + null operations. Similarly, if it - n is + well-defined, then it -= n; it += n; and (it + - n) + n are null operations.
Relation between distance and addition If it1 - it2 is well-defined, then it1 + == it2 + (it1 - it2).
Reachability and distanceIf it1 is reachable from it2, + then it1 - it2 >= 0.
+ +

Models

+ +
    +
  • vector<T>::iterator
  • +
+ +

Indexed +Bidirectional Column/Row Iterator

+ +

Description

+ +

An Indexed Bidirectional Column/Row Iterator is an iterator of +a container that can be dereferenced, incremented, decremented +and carries index information.

+ +

Refinement of

+ +

Assignable, Equality Comparable, Default Constructible.

+ +

Associated types

+ + + + + + + + + + +
Value type The type of the value obtained by dereferencing a + Indexed Bidirectional Column/Row Iterator
Container typeThe type of the container a Indexed Bidirectional + Column/Row Iterator points into.
+ +

Notation

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
I1 A type that is a model of Indexed Bidirectional + Column/Row Iterator
I2A type that is a model of Indexed Bidirectional + Row/Column Iterator
T The value type of I1 and I2
CThe container type of I1 and I2
it1, it1t, it11, it12 + Objects of type I1
it2, it2tObjects of type I2
t Object of type T
cObject of type C
+ +

Definitions

+ +

Valid expressions

+ +

In addition to the expressions defined for Assignable, +Equality Comparable and Default Constructible, the following +expressions must be valid.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Type requirements Return type
Default constructor I1 it1   
Dereference *it1   Convertible to T.
Dereference assignment *it1 = t I1 is mutable.  
Member access it1->m T is a type for which t.m + is defined.  
Preincrement++ it1  I1 &
Postincrement it1 ++  I1
Predecrement -- it1 I1 &
Postdecrement it1 --   I1
Function callit1 () Convertible to C &.
Row Indexit1.index1 () C::size_type
Column Indexit1.index2 () C::size_type
Row/Column Beginit1.begin () I2
Row/Column Endit1.end () I2
Reverse Row/Column Beginit1.rbegin () reverse_iterator<I2>
Reverse Row/Column Endit1.rend () reverse_iterator<I2>
+ +

Expression Semantics

+ +

Semantics of an expression is defined only where it differs +from, or is not defined in, Assignable, Equality Comparable and +Default Constructible.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Precondition Semantics Postcondition
Default constructor I1 it1   it1 is singular.
Dereference *it1 it1 is dereferenceable.   
Dereference assignment *it1 = tSame as for *it1. *it1 is a copy of t.
Member access it1->mit1 is dereferenceable. Equivalent to (*it1).m 
Preincrement ++ it1 it1 is dereferenceable. it1 is modified to point to the next + element. it1 is dereferenceable or past-the-end.
+ &it1 == &++ it1
.
+ If it11 == it12,
+ then ++ it11 == ++ it12.
Postincrement it1 ++ Same as for ++ it1.Equivalent to
+ {
+  I1 it1t = it1;
+  ++ it1;
+  return it1t;
+ }
it1 is dereferenceable or past-the-end.
Predecrement -- it1 it1 is dereferenceable or past-the-end.
+ There exists a dereferenceable iterator it1t + such that it1 == ++ it1t.
it1 is modified to point to the previous + element. it1 is dereferenceable.
+ &it1 = &-- it1.
+ If it11 == it12,
+ then -- it11 == -- it12.
Postdecrement it1 -- Same as for -- it1.Equivalent to
+ {
+  I1 it1t = it1;
+  -- it1;
+  return it1t;
+ }
it1 is dereferenceable. 
Function callit1 ()it1 is dereferenceable or past-the-end. If it1 points into container c + then it1 () = c. 
Row Indexit1.index1 ()it1 is dereferenceable or past-the-end. it1.index1 () >= 0 and
+ it1.index1 () <= it () .size1 ()
If it11 == it12,
+ then it11.index1 () == it12.index1 ().
+ If it11, it12 are Indexed + Bidirectional Row Iterators with it11 == it12, +
+ then it11.index1 () < (++ it12).index1 + ().
+ If it11, it12 are Indexed + Bidirectional Row Iterators with it11 == it12, +
+ then it11.index1 () > (-- it12).index1 + ().
Column Indexit1.index2 ()it1 is dereferenceable or past-the-end.it1.index2 () >= 0 and
+ it1.index2 () <= it () .size2 ()
If it11 == it12,
+ then it11.index2 () == it12.index2 ().
+ If it11, it12 are Indexed + Bidirectional Column Iterators with it11 == it12, +
+ then it11.index2 () < (++ it12).index2 + ().
+ If it11, it12 are Indexed + Bidirectional Column Iterators with it11 == it12, +
+ then it11.index2 () > (-- it12).index2 + ().
Row/Column Beginit1.begin ()it1 is dereferenceable.If it1 is a Indexed Bidirectional Column + Iterator,
+ then it2 = it1.begin () is a Indexed + Bidirectional Row Iterator
+ with it2.index1 () == it1.index1 ().

If it1 + is a Indexed Bidirectional Row Iterator,
+ then it2 = it1.begin () is a Indexed + Bidirectional Column Iterator
+ with it2.index2 () == it1.index2 ().

+
 
Row/Column Endit1.end ()it1 is dereferenceable.If it1 is a Indexed Bidirectional Column + Iterator,
+ then it2 = it1.end () is a Indexed + Bidirectional Row Iterator
+ with it2.index1 () == it1.index1 ().

If it1 + is a Indexed Bidirectional Row Iterator,
+ then it2 = it1.end () is a Indexed + Bidirectional Column Iterator
+ with it2.index2 () == it1.index2 ().

+
 
Reverse Row/Column Beginit1.rbegin ()it1 is dereferenceable.Equivalent to reverse_iterator<I2> + (it1.end ()). 
Reverse Row/Column Endit1.rend ()it1 is dereferenceable.Equivalent to reverse_iterator<I2> + (it1.begin ()). 
+ +

Complexity guarantees

+ +

The complexity of operations on indexed bidirectional +column/row iterators is guaranteed to be logarithmic depending on +the size of the container. The complexity of one iterator +(depending on the storage layout) can be lifted to be amortized +constant time. The complexity of the other iterator (depending on +the storage layout and the container) can be lifted to be +amortized constant time for the first row/first column +respectively.

+ +

Invariants

+ + + + + + + + + + + + + + + + + + + + + + +
Identity it11 == it12 if and only if &*it11 + == &*it12.
Symmetry of increment and decrement If it1 is dereferenceable, then ++ + it1; --it1; is a null operation. Similarly, -- + it1; ++ it1; is a null operation.
Relation between iterator index and container element + operator If it1 is dereferenceable, *it1 == + it1 () (it1.index1 (), it2.index2 ())
Relation between iterator column/row begin and + iterator indexIf it1 is a Indexed Bidirectional Column + Iterator and it2 = it1.begin () then + it2.index2 () < it2t.index2 () for all it2t + with it2t () == it2 () and it2t + ().index1 () == it2 ().index1 ().

If it1 + is a Indexed Bidirectional Row Iterator and it2 = + it1.begin () then it2.index1 () < + it2t.index1 () for all it2t with it2t + () == it2 () and it2t ().index2 () == it2 + ().index2 ().

+
Relation between iterator column/row end and iterator + indexIf it1 is a Indexed Bidirectional Column + Iterator and it2 = it1.end () then + it2.index2 () > it2t.index2 () for all it2t + with it2t () == it2 () and it2t + ().index1 () == it2 ().index1 ().

If it1 + is a Indexed Bidirectional Row Iterator and it2 = + it1.end () then it2.index1 () > + it2t.index1 () for all it2t with it2t + () == it2 () and it2t ().index2 () == it2 + ().index2 ().

+
+ +

Models

+ +
    +
  • sparse_matrix<T>::iterator1
  • +
  • sparse_matrix<T>::iterator2
  • +
+ +

Indexed +Random Access Column/Row Iterator

+ +

Description

+ +

An Indexed Random Access Column/Row Iterator is an iterator of +a container that can be dereferenced, incremented, decremented +and carries index information.

+ +

Refinement of

+ +

Indexed +Bidirectional Column/Row Iterator.

+ +

Associated types

+ + + + + + + + + + +
Value type The type of the value obtained by dereferencing a + Indexed Random Access Column/Row Iterator
Container typeThe type of the container a Indexed Random Access + Column/Row Iterator points into.
+ +

Notation

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
I A type that is a model of Indexed Random Access + Column/Row Iterator
T The value type of I
CThe container type of I
it, itt, it1, it2 Objects of type I
t Object of type T
cObject of type C
+ +

Definitions

+ +

Valid expressions

+ +

In addition to the expressions defined for Indexed Bidirectional +Column/Row Iterator, the following expressions must be valid. +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Type requirements Return type
Forward motion it += n I &
Iterator addition it + n   I
Backward motioni -= n  I &
Iterator subtraction it - n  I 
Difference it1 - it2 C::difference_type
Element operator it [n] Convertible to T.
Element assignment it [n] = tI is mutable Convertible to T.
+ +

Expression Semantics

+ +

Semantics of an expression is defined only where it differs +from, or is not defined in, Indexed Bidirectional +Column/Row Iterator.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Expression Precondition Semantics Postcondition
Forward motion it += n Including it itself, there must be n + dereferenceable or past-the-end iterators following or + preceding it, depending on whether n + is positive or negative. If n > 0, equivalent to executing ++ + it n times. If n < 0, + equivalent to executing -- it n + times. If n == 0, this is a null operation. it is dereferenceable or past-the-end.
Iterator addition it + nSame as for i += n.Equivalent to
+ {
+  I itt = it;
+  return itt += n;
+ }
Result is dereferenceable or past-the-end.
Backward motionit -= nIncluding it itself, there must be n + dereferenceable or past-the-end iterators preceding or + following it, depending on whether n + is positive or negative. Equivalent to it += (-n). it is dereferenceable or past-the-end.
Iterator subtraction it - nSame as for i -= n.Equivalent to
+ {
+  I itt = it;
+  return itt -= n;
+ }
Result is dereferenceable or past-the-end.
Difference it1 - it2 Either it1 is reachable from it2 + or it2 is reachable from it1, + or both. Returns a number n such that it1 + == it2 + n  
Element operatorit [n] it + n exists and is dereferenceable. Equivalent to *(it + n) 
Element assignment i[n] = t Same as for it [n].Equivalent to *(it + n) = t 
+ +

Complexity guarantees

+ +

The complexity of operations on indexed random access +Column/Row iterators is guaranteed to be amortized constant time.

+ +

Invariants

+ + + + + + + + + + + + + + +
Symmetry of addition and subtraction If it + n is well-defined, then it + += n; it -= n; and (it + n) - n are + null operations. Similarly, if it - n is + well-defined, then it -= n; it += n; and (it + - n) + n are null operations.
Relation between distance and addition If it1 - it2 is well-defined, then it1 + == it2 + (it1 - it2).
Reachability and distanceIf it1 is reachable from it2, + then it1 - it2 >= 0.
+ +

Models

+ +
    +
  • matrix<T>::iterator1
  • +
  • matrix<T>::iterator2
  • +
+ +
+ +

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/matrix.htm b/doc/matrix.htm new file mode 100644 index 00000000..112662e0 --- /dev/null +++ b/doc/matrix.htm @@ -0,0 +1,1242 @@ + + + + + +Matrix + + + + +

c++boost.gifMatrix

+ +

Matrix

+ +

Description

+ +

The templated class matrix<T, F, A> is the +base container adaptor for dense matrices. For a (m x n)-dimensional +matrix and 0 <= i < m, 0 <= j < n +every element mi, j is mapped to the +(i x n + j)-th element of the container for row major +orientation or the (i + j x m)-th element of the +container for column major orientation.

+ +

Example

+ +
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) 
+            m (i, j) = 3 * i + j;
+    std::cout << m << std::endl;
+}
+ +

Definition

+ +

Defined in the header matrix.hpp.

+ +

Template parameters

+ + + + + + + + + + + + + + + + + + + + + + +
Parameter Description Default
T The type of object stored in the matrix.  
FFunctor describing the storage organization. [1]row_major
AThe type of the adapted array. [2]unbounded_array<T>
+ +

Model of

+ +

Matrix.

+ +

Type requirements

+ +

None, except for those imposed by the requirements of Matrix.

+ +

Public base classes

+ +

matrix_expression<matrix<T, F, A> >

+ +

Members

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Member Description
matrix () Allocates an uninitialized matrix that + holds zero rows of zero elements.
matrix (size_type size1, size_type size2)Allocates an uninitialized matrix that + holds size1 rows of size2 + elements.
matrix (const matrix &m)The copy constructor.
template<class AE>
+ matrix (const matrix_expression<AE> &ae)
The extended copy constructor.
void resize (size_type size1, size_type size2)Reallocates a matrix to hold size1 + rows of size2 elements. The content of the matrix + is not preserved.
size_type size1 () constReturns the number of rows.
size_type size2 () constReturns the number of columns.
const_reference operator () (size_type i, + size_type j) constReturns a const reference of the j-th + element in the i-th row.
reference operator () (size_type i, size_type + j)Returns a reference of the j-th element + in the i-th row.
matrix &operator = (const matrix &m)The assignment operator.
matrix &assign_temporary (matrix &m)Assigns a temporary. May change the matrix m.
template<class AE>
+ matrix &operator = (const matrix_expression<AE> + &ae)
The extended assignment operator.
template<class AE>
+ matrix &assign (const matrix_expression<AE> + &ae)
Assigns a matrix expression to the matrix. Left and + right hand side of the assignment should be independent.
template<class AE>
+ matrix &operator += (const + matrix_expression<AE> &ae)
A computed assignment operator. Adds the matrix + expression to the matrix.
template<class AE>
+ matrix &plus_assign (const + matrix_expression<AE> &ae)
Adds a matrix expression to the matrix. Left and + right hand side of the assignment should be independent.
template<class AE>
+ matrix &operator -= (const + matrix_expression<AE> &ae)
A computed assignment operator. Subtracts the matrix + expression from the matrix.
template<class AE>
+ matrix &minus_assign (const + matrix_expression<AE> &ae)
Subtracts a matrix expression from the matrix. Left + and right hand side of the assignment should be + independent.
template<class AT>
+ matrix &operator *= (const AT &at)
A computed assignment operator. Multiplies the matrix + with a scalar.
template<class AT>
+ matrix &operator /= (const AT &at)
A computed assignment operator. Divides the matrix + through a scalar.
void swap (matrix &m)Swaps the contents of the matrices.
void insert (size_type i, size_type j, + const_reference t)Inserts the value t at the j-th + element of the i-th row.
void erase (size_type i, size_type j)Erases the value at the j-th element of + the i-th row.
void clear ()Clears the matrix.
const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the matrix.
const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the matrix.
iterator1 begin1 () Returns a iterator1 pointing to the + beginning of the matrix.
iterator1 end1 () Returns a iterator1 pointing to the end + of the matrix.
const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the matrix.
const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the matrix.
iterator2 begin2 () Returns a iterator2 pointing to the + beginning of the matrix.
iterator2 end2 () Returns a iterator2 pointing to the end + of the matrix.
const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed matrix. +
const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed matrix.
reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to + the beginning of the reversed matrix.
reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to + the end of the reversed matrix.
const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed matrix. +
const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed matrix.
reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to + the beginning of the reversed matrix.
reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to + the end of the reversed matrix.
+ +

Notes

+ +

[1] Supported parameters for the +storage organization are row_major and column_major.

+ +

[2] Supported parameters for the +adapted array are unbounded_array<T>, bounded_array<T> +and std::vector<T>.

+ +

Interface

+ +
    // Array based matrix class
+    template<class T, class F, class A>
+    class matrix:
+        public matrix_expression<matrix<T, F, A> > {
+    public:
+        typedef std::size_t size_type;
+        typedef std::ptrdiff_t difference_type;
+        typedef T value_type;
+        typedef const T &const_reference;
+        typedef T &reference;
+        typedef const T *const_pointer;
+        typedef T *pointer;
+        typedef F functor_type;
+        typedef A array_type;
+        typedef const A const_array_type;
+        typedef const matrix<T, F, A> const_self_type;
+        typedef matrix<T, F, A> self_type;
+        typedef const matrix_const_reference<const_self_type> const_closure_type;
+        typedef matrix_reference<self_type> closure_type;
+        typedef typename A::const_iterator const_iterator_type;
+        typedef typename A::iterator iterator_type;
+        typedef dense_tag storage_category;
+        typedef typename F::orientation_category orientation_category;
+
+        // Construction and destruction
+        matrix ();
+        matrix (size_type size1, size_type size2);
+        matrix (const matrix &m);
+        template<class AE>
+        matrix (const matrix_expression<AE> &ae);
+
+        // Accessors
+        size_type size1 () const;
+        size_type size2 () const;
+        const_array_type &data () const;
+        array_type &data ();
+
+        // Resizing
+        void resize (size_type size1, size_type size2);
+
+        // Element access
+        const_reference operator () (size_type i, size_type j) const;
+        reference operator () (size_type i, size_type j);
+
+        // Assignment
+        matrix &operator = (const matrix &m);
+        matrix &assign_temporary (matrix &m);
+        template<class AE>
+        matrix &operator = (const matrix_expression<AE> &ae);
+        template<class AE>
+        matrix &reset (const matrix_expression<AE> &ae);
+        template<class AE>
+        matrix &assign (const matrix_expression<AE> &ae);
+        template<class AE>
+        matrix& operator += (const matrix_expression<AE> &ae);
+        template<class AE>
+        matrix &plus_assign (const matrix_expression<AE> &ae);
+        template<class AE>
+        matrix& operator -= (const matrix_expression<AE> &ae);
+        template<class AE>
+        matrix &minus_assign (const matrix_expression<AE> &ae);
+        template<class AT>
+        matrix& operator *= (const AT &at);
+        template<class AT>
+        matrix& operator /= (const AT &at);
+
+        // Swapping
+        void swap (matrix &m);
+        friend void swap (matrix &m1, matrix &m2);
+
+        // Element insertion and erasure
+        void insert (size_type i, size_type j, const_reference t);
+        void erase (size_type i, size_type j);
+        void clear ();
+
+        class const_iterator1;
+        class iterator1;
+        class const_iterator2;
+        class iterator2;
+        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
+        typedef reverse_iterator_base1<iterator1> reverse_iterator1;
+        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
+        typedef reverse_iterator_base2<iterator2> reverse_iterator2;
+
+        // Element lookup
+        const_iterator1 find1 (int rank, size_type i, size_type j) const;
+        iterator1 find1 (int rank, size_type i, size_type j);
+        const_iterator2 find2 (int rank, size_type i, size_type j) const;
+        iterator2 find2 (int rank, size_type i, size_type j);
+        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
+        iterator1 find_first1 (int rank, size_type i, size_type j);
+        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
+        iterator1 find_last1 (int rank, size_type i, size_type j);
+        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
+        iterator2 find_first2 (int rank, size_type i, size_type j);
+        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
+        iterator2 find_last2 (int rank, size_type i, size_type j);
+
+        // Iterators simply are pointers.
+
+        class const_iterator1:
+            public container_const_reference<matrix>,
+            public random_access_iterator_base<const_iterator1, value_type> {
+        public:
+            typedef dense_random_access_iterator_tag iterator_category;
+            typedef typename matrix::difference_type difference_type;
+            typedef typename matrix::value_type value_type;
+            typedef typename matrix::const_reference reference;
+            typedef typename matrix::const_pointer pointer;
+            typedef const_iterator2 dual_iterator_type;
+            typedef const_reverse_iterator2 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator1 ();
+            const_iterator1 (const matrix &m, const const_iterator_type &it);
+            const_iterator1 (const iterator1 &it);
+
+            // Arithmetic
+            const_iterator1 &operator ++ ();
+            const_iterator1 &operator -- ();
+            const_iterator1 &operator += (difference_type n);
+            const_iterator1 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator1 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator2 begin () const;
+            const_iterator2 end () const;
+            const_reverse_iterator2 rbegin () const;
+            const_reverse_iterator2 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator1 &operator = (const const_iterator1 &it);
+
+            // Comparison
+            bool operator == (const const_iterator1 &it) const;
+            bool operator <(const const_iterator1 &it) const;
+        };
+
+        const_iterator1 begin1 () const;
+        const_iterator1 end1 () const;
+
+        class iterator1:
+            public container_reference<matrix>,
+            public random_access_iterator_base<iterator1, value_type> {
+        public:
+            typedef dense_random_access_iterator_tag iterator_category;
+            typedef typename matrix::difference_type difference_type;
+            typedef typename matrix::value_type value_type;
+            typedef typename matrix::reference reference;
+            typedef typename matrix::pointer pointer;
+            typedef iterator2 dual_iterator_type;
+            typedef reverse_iterator2 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            iterator1 ();
+            iterator1 (matrix &m, const iterator_type &it);
+
+            // Arithmetic
+            iterator1 &operator ++ ();
+            iterator1 &operator -- ();
+            iterator1 &operator += (difference_type n);
+            iterator1 &operator -= (difference_type n);
+            difference_type operator - (const iterator1 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            iterator2 begin () const;
+            iterator2 end () const;
+            reverse_iterator2 rbegin () const;
+            reverse_iterator2 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            iterator1 &operator = (const iterator1 &it);
+
+            // Comparison
+            bool operator == (const iterator1 &it) const;
+            bool operator <(const iterator1 &it) const;
+        };
+
+        iterator1 begin1 ();
+        iterator1 end1 ();
+
+        class const_iterator2:
+            public container_const_reference<matrix>,
+            public random_access_iterator_base<const_iterator2, value_type> {
+        public:
+            typedef dense_random_access_iterator_tag iterator_category;
+            typedef typename matrix::difference_type difference_type;
+            typedef typename matrix::value_type value_type;
+            typedef typename matrix::const_reference reference;
+            typedef typename matrix::const_pointer pointer;
+            typedef const_iterator1 dual_iterator_type;
+            typedef const_reverse_iterator1 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator2 ();
+            const_iterator2 (const matrix &m, const const_iterator_type &it);
+            const_iterator2 (const iterator2 &it);
+
+            // Arithmetic
+            const_iterator2 &operator ++ ();
+            const_iterator2 &operator -- ();
+            const_iterator2 &operator += (difference_type n);
+            const_iterator2 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator2 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator1 begin () const;
+            const_iterator1 end () const;
+            const_reverse_iterator1 rbegin () const;
+            const_reverse_iterator1 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator2 &operator = (const const_iterator2 &it);
+
+            // Comparison
+            bool operator == (const const_iterator2 &it) const;
+            bool operator <(const const_iterator2 &it) const;
+        };
+
+        const_iterator2 begin2 () const;
+        const_iterator2 end2 () const;
+
+        class iterator2:
+            public container_reference<matrix>,
+            public random_access_iterator_base<iterator2, value_type> {
+        public:
+            typedef dense_random_access_iterator_tag iterator_category;
+            typedef typename matrix::difference_type difference_type;
+            typedef typename matrix::value_type value_type;
+            typedef typename matrix::reference reference;
+            typedef typename matrix::pointer pointer;
+            typedef iterator1 dual_iterator_type;
+            typedef reverse_iterator1 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            iterator2 ();
+            iterator2 (matrix &m, const iterator_type &it);
+
+            // Arithmetic
+            iterator2 &operator ++ ();
+            iterator2 &operator -- ();
+            iterator2 &operator += (difference_type n);
+            iterator2 &operator -= (difference_type n);
+            difference_type operator - (const iterator2 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            iterator1 begin () const;
+            iterator1 end () const;
+            reverse_iterator1 rbegin () const;
+            reverse_iterator1 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            iterator2 &operator = (const iterator2 &it);
+
+            // Comparison
+            bool operator == (const iterator2 &it) const;
+            bool operator <(const iterator2 &it) const;
+        };
+
+        iterator2 begin2 ();
+        iterator2 end2 ();
+
+        // Reverse iterators
+
+        const_reverse_iterator1 rbegin1 () const;
+        const_reverse_iterator1 rend1 () const;
+
+        reverse_iterator1 rbegin1 ();
+        reverse_iterator1 rend1 ();
+
+        const_reverse_iterator2 rbegin2 () const;
+        const_reverse_iterator2 rend2 () const;
+
+        reverse_iterator2 rbegin2 ();
+        reverse_iterator2 rend2 ();
+    };
+ +

Identity Matrix

+ +

Description

+ +

The templated class identity_matrix<T> represents +identity matrices. For a (m x n)-dimensional identity +matrix and 0 <= i < m, 0 <= j < n +holds idi, j = 0, if i +<> j, and idi, i= 1.

+ +

Example

+ +
int main () {
+    using namespace boost::numeric::ublas;
+    identity_matrix<double> m (3);
+    std::cout << m << std::endl;
+}
+ +

Definition

+ +

Defined in the header matrix.hpp.

+ +

Template parameters

+ + + + + + + + + + + + +
Parameter Description Default
T The type of object stored in the matrix.  
+ +

Model of

+ +

Matrix Expression. +

+ +

Type requirements

+ +

None, except for those imposed by the requirements of Matrix Expression.

+ +

Public base classes

+ +

matrix_expression<identity_matrix<T> > +

+ +

Members

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Member Description
identity_matrix () Constructs an identity_matrix that holds + zero rows of zero elements.
identity_matrix (size_type size)Constructs an identity_matrix that holds + size rows of size elements.
identity_matrix (const identity_matrix &m)The copy constructor.
void resize (size_type size)Resizes a identity_matrix to hold size + rows of size elements.
size_type size1 () constReturns the number of rows.
size_type size2 () constReturns the number of columns.
const_reference operator () (size_type i, + size_type j) constReturns the value of the j-th element in + the i-th row.
identity_matrix &operator = (const + identity_matrix &m)The assignment operator.
identity_matrix &assign_temporary + (identity_matrix &m)Assigns a temporary. May change the identity matrix m.
void swap (identity_matrix &m)Swaps the contents of the identity matrices.
const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the identity_matrix.
const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the identity_matrix.
const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the identity_matrix.
const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the identity_matrix.
const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed identity_matrix. +
const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed identity_matrix. +
const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed identity_matrix. +
const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed identity_matrix. +
+ +

Interface

+ +
    // Identity matrix class
+    template<class T>
+    class identity_matrix: 
+        public matrix_expression<identity_matrix<T> > {
+    public:      
+        typedef std::size_t size_type;
+        typedef std::ptrdiff_t difference_type;
+        typedef T value_type;
+        typedef const T &const_reference;
+        typedef T &reference;
+        typedef const T *const_pointer;
+        typedef T *pointer;
+        typedef const identity_matrix<T> const_self_type;
+        typedef identity_matrix<T> self_type;
+        typedef const matrix_const_reference<const_self_type> const_closure_type;
+        typedef size_type const_iterator_type;
+        typedef packed_tag storage_category;
+        typedef unknown_orientation_tag orientation_category;
+
+        // Construction and destruction
+        identity_matrix ();
+        identity_matrix (size_type size);
+        identity_matrix (size_type size1, size_type size2);
+        identity_matrix (const identity_matrix &m);
+
+        // Accessors
+        size_type size1 () const;
+        size_type size2 () const;
+
+        // Resizing
+        void resize (size_type size);
+        void resize (size_type size1, size_type size2);
+
+        // Element access
+        const_reference operator () (size_type i, size_type j) const;
+
+        // Assignment
+        identity_matrix &operator = (const identity_matrix &m);
+        identity_matrix &assign_temporary (identity_matrix &m);
+
+        // Swapping
+        void swap (identity_matrix &m);
+        friend void swap (identity_matrix &m1, identity_matrix &m2);
+
+        class const_iterator1;
+        class const_iterator2;
+        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
+        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
+
+        // Element lookup
+        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
+        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
+        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
+        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
+
+        // Iterators simply are indices.
+
+        class const_iterator1:
+            public container_const_reference<identity_matrix>,
+            public random_access_iterator_base<const_iterator1, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename identity_matrix::difference_type difference_type;
+            typedef typename identity_matrix::value_type value_type;
+            typedef typename identity_matrix::const_reference reference;
+            typedef typename identity_matrix::const_pointer pointer;
+            typedef const_iterator2 dual_iterator_type;
+            typedef const_reverse_iterator2 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator1 ();
+            const_iterator1 (const identity_matrix &m, const const_iterator_type &it1, const const_iterator_type &it2);
+
+            // Arithmetic
+            const_iterator1 &operator ++ ();
+            const_iterator1 &operator -- ();
+            const_iterator1 &operator += (difference_type n);
+            const_iterator1 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator1 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator2 begin () const;
+            const_iterator2 end () const;
+            const_reverse_iterator2 rbegin () const;
+            const_reverse_iterator2 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator1 &operator = (const const_iterator1 &it);
+
+            // Comparison
+            bool operator == (const const_iterator1 &it) const;
+            bool operator <(const const_iterator1 &it) const;
+        };
+
+        typedef const_iterator1 iterator1;
+
+        const_iterator1 begin1 () const;
+        const_iterator1 end1 () const;
+
+        class const_iterator2:
+            public container_const_reference<identity_matrix>,
+            public random_access_iterator_base<const_iterator2, value_type> {
+        public:
+            typedef packed_random_access_iterator_tag iterator_category;
+            typedef typename identity_matrix::difference_type difference_type;
+            typedef typename identity_matrix::value_type value_type;
+            typedef typename identity_matrix::const_reference reference;
+            typedef typename identity_matrix::const_pointer pointer;
+            typedef const_iterator1 dual_iterator_type;
+            typedef const_reverse_iterator1 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator2 ();
+            const_iterator2 (const identity_matrix &m, const const_iterator_type &it1, const const_iterator_type &it2);
+
+            // Arithmetic
+            const_iterator2 &operator ++ ();
+            const_iterator2 &operator -- ();
+            const_iterator2 &operator += (difference_type n);
+            const_iterator2 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator2 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator1 begin () const;
+            const_iterator1 end () const;
+            const_reverse_iterator1 rbegin () const;
+            const_reverse_iterator1 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator2 &operator = (const const_iterator2 &it);
+
+            // Comparison
+            bool operator == (const const_iterator2 &it) const;
+            bool operator <(const const_iterator2 &it) const;
+        };
+
+        typedef const_iterator2 iterator2;
+
+        const_iterator2 begin2 () const;
+        const_iterator2 end2 () const;
+
+        // Reverse iterators
+
+        const_reverse_iterator1 rbegin1 () const;
+        const_reverse_iterator1 rend1 () const;
+
+        const_reverse_iterator2 rbegin2 () const;
+        const_reverse_iterator2 rend2 () const;
+    };
+ +

Zero Matrix

+ +

Description

+ +

The templated class zero_matrix<T> represents +zero matrices. For a (m x n)-dimensional zero matrix and +0 <= i < m, 0 <= j < n holds zi, +j = 0.

+ +

Example

+ +
int main () {
+    using namespace boost::numeric::ublas;
+    zero_matrix<double> m (3, 3);
+    std::cout << m << std::endl;
+}
+ +

Definition

+ +

Defined in the header matrix.hpp.

+ +

Template parameters

+ + + + + + + + + + + + +
Parameter Description Default
T The type of object stored in the matrix.  
+ +

Model of

+ +

Matrix Expression. +

+ +

Type requirements

+ +

None, except for those imposed by the requirements of Matrix Expression.

+ +

Public base classes

+ +

matrix_expression<zero_matrix<T> >

+ +

Members

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Member Description
zero_matrix () Constructs a zero_matrix that holds zero + rows of zero elements.
zero_matrix (size_type size1, size_type size2)Constructs a zero_matrix that holds size1 + rows of size2 elements.
zero_matrix (const zero_matrix &m)The copy constructor.
void resize (size_type size1, size_type size2)Resizes a zero_matrix to hold size1 + rows of size2 elements.
size_type size1 () constReturns the number of rows.
size_type size2 () constReturns the number of columns.
const_reference operator () (size_type i, + size_type j) constReturns the value of the j-th element in + the i-th row.
zero_matrix &operator = (const zero_matrix + &m)The assignment operator.
zero_matrix &assign_temporary (zero_matrix + &m)Assigns a temporary. May change the zero matrix m.
void swap (zero_matrix &m)Swaps the contents of the zero matrices.
const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the zero_matrix.
const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the zero_matrix.
const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the zero_matrix.
const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the zero_matrix.
const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed zero_matrix. +
const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed zero_matrix. +
const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed zero_matrix. +
const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed zero_matrix. +
+ +

Interface

+ +
    // Zero matrix class
+    template<class T>
+    class zero_matrix: 
+        public matrix_expression<zero_matrix<T> > {
+    public:      
+        typedef std::size_t size_type;
+        typedef std::ptrdiff_t difference_type;
+        typedef T value_type;
+        typedef const T &const_reference;
+        typedef T &reference;
+        typedef const T *const_pointer;
+        typedef T *pointer;
+        typedef const zero_matrix<T> const_self_type;
+        typedef zero_matrix<T> self_type;
+        typedef const matrix_const_reference<const_self_type> const_closure_type;
+        typedef size_type const_iterator_type;
+        typedef sparse_tag storage_category;
+        typedef unknown_orientation_tag orientation_category;
+
+        // Construction and destruction
+        zero_matrix ();
+        zero_matrix (size_type size1, size_type size2);
+        zero_matrix (const zero_matrix &m);
+
+        // Accessors
+        size_type size1 () const;
+        size_type size2 () const;
+
+        // Resizing
+        void resize (size_type size1, size_type size2);
+
+        // Element access
+        const_reference operator () (size_type i, size_type j) const;
+
+        // Assignment
+        zero_matrix &operator = (const zero_matrix &m);
+        zero_matrix &assign_temporary (zero_matrix &m);
+
+        // Swapping
+        void swap (zero_matrix &m);
+        friend void swap (zero_matrix &m1, zero_matrix &m2);
+
+        class const_iterator1;
+        class const_iterator2;
+        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
+        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
+
+        // Element lookup
+        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
+        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
+        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
+        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
+
+        // Iterators simply are indices.
+
+        class const_iterator1:
+            public container_const_reference<zero_matrix>,
+            public bidirectional_iterator_base<const_iterator1, value_type> {
+        public:
+            typedef sparse_bidirectional_iterator_tag iterator_category;
+            typedef typename zero_matrix::difference_type difference_type;
+            typedef typename zero_matrix::value_type value_type;
+            typedef typename zero_matrix::const_reference reference;
+            typedef typename zero_matrix::const_pointer pointer;
+            typedef const_iterator2 dual_iterator_type;
+            typedef const_reverse_iterator2 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator1 ();
+            const_iterator1 (const zero_matrix &m, const const_iterator_type &it1, const const_iterator_type &it2);
+
+            // Arithmetic
+            const_iterator1 &operator ++ ();
+            const_iterator1 &operator -- ();
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator2 begin () const;
+            const_iterator2 end () const;
+            const_reverse_iterator2 rbegin () const;
+            const_reverse_iterator2 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator1 &operator = (const const_iterator1 &it);
+
+            // Comparison
+            bool operator == (const const_iterator1 &it) const;
+        };
+
+        typedef const_iterator1 iterator1;
+
+        const_iterator1 begin1 () const;
+        const_iterator1 end1 () const;
+
+        class const_iterator2:
+            public container_const_reference<zero_matrix>,
+            public bidirectional_iterator_base<const_iterator2, value_type> {
+        public:
+            typedef sparse_bidirectional_iterator_tag iterator_category;
+            typedef typename zero_matrix::difference_type difference_type;
+            typedef typename zero_matrix::value_type value_type;
+            typedef typename zero_matrix::const_reference reference;
+            typedef typename zero_matrix::const_pointer pointer;
+            typedef const_iterator1 dual_iterator_type;
+            typedef const_reverse_iterator1 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator2 ();
+            const_iterator2 (const zero_matrix &m, const const_iterator_type &it1, const const_iterator_type &it2);
+
+            // Arithmetic
+            const_iterator2 &operator ++ ();
+            const_iterator2 &operator -- ();
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator1 begin () const;
+            const_iterator1 end () const;
+            const_reverse_iterator1 rbegin () const;
+            const_reverse_iterator1 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator2 &operator = (const const_iterator2 &it);
+
+            // Comparison
+            bool operator == (const const_iterator2 &it) const;
+        };
+
+        typedef const_iterator2 iterator2;
+
+        const_iterator2 begin2 () const;
+        const_iterator2 end2 () const;
+
+        // Reverse iterators
+
+        const_reverse_iterator1 rbegin1 () const;
+        const_reverse_iterator1 rend1 () const;
+
+        const_reverse_iterator2 rbegin2 () const;
+        const_reverse_iterator2 rend2 () const;
+    };
+ +
+ +

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/matrix_expression.htm b/doc/matrix_expression.htm new file mode 100644 index 00000000..b634e409 --- /dev/null +++ b/doc/matrix_expression.htm @@ -0,0 +1,3002 @@ + + + + + +Matrix Expressions + + + + +

c++boost.gifMatrix Expressions

+ +

Matrix Expression

+ +

Description

+ +

The templated class matrix_expression<E> forms +the base for all static derived matrix expression classes +including class matrix itself.

+ +

Definition

+ +

Defined in the header matrix_expression.hpp.

+ +

Template parameters

+ + + + + + + + + + + + +
Parameter Description Default
E The type of the matrix expression.  
+ +

Model of

+ +

None.

+ +

Type requirements

+ +

None.

+ +

Public base classes

+ +

None.

+ +

Members

+ + + + + + + + + + + + + + +
Member Description
const expression_type &operator () () constReturns a const reference of the + expression.
expression_type &operator () ()Returns a reference of the expression.
+ +

Interface

+ +
    // Base class for the Barton Nackman trick
+    template<class E>
+    struct matrix_expression {
+        typedef E expression_type;
+        typedef matrix_tag type_category;
+
+        // 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 
+        // on MSVC 6.0 (error C2027) - we only implement the casts.
+
+        const expression_type &operator () () const;
+        expression_type &operator () ();
+    };
+ +

Matrix References

+ +

Constant Reference

+ +

Description

+ +

The templated class matrix_const_reference<E> contains +a constant reference to a matrix expression.

+ +

Definition

+ +

Defined in the header matrix_expression.hpp.

+ +

Template parameters

+ + + + + + + + + + + + +
Parameter Description Default
E The type of the matrix expression.  
+ +

Model of

+ +

Matrix Expression. +

+ +

Type requirements

+ +

None, except for those imposed by the requirements of Matrix Expression.

+ +

Public base classes

+ +

matrix_expression<matrix_const_reference<E> +>

+ +

Members

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Member Description
matrix_const_reference (const expression_type + &e) Constructs a constant reference of the expression.
size_type size1 () constReturns the number of rows.
size_type size2 () constReturns the number of columns.
const_reference operator () (size_type i, + size_type j) constReturns the value of the j-th element in + the i-th row.
const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the expression.
const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the expression.
const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the expression.
const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the expression.
const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed expression.
const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed expression.
const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed expression.
const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed expression.
+ +

Interface

+ +
    template<class E>
+    class matrix_const_reference:
+        public matrix_expression<matrix_const_reference<E> > {
+    public:
+        typedef E expression_type;
+        typedef typename E::size_type size_type;
+        typedef typename E::difference_type difference_type;
+        typedef typename E::value_type value_type;
+        typedef typename E::const_reference const_reference;
+        typedef const_reference reference;
+        typedef typename E::const_pointer const_pointer;
+        typedef const_pointer pointer;
+        typedef typename E::orientation_category orientation_category;
+        typedef typename E::const_iterator1 const_iterator1_type;
+        typedef typename E::const_iterator2 const_iterator2_type;
+        typedef unknown_storage_tag storage_category;
+
+        // Construction and destruction
+        matrix_const_reference ();
+        matrix_const_reference (const expression_type &e);
+
+        // Accessors
+        size_type size1 () const;
+        size_type size2 () const;
+        const expression_type &expression () const;
+
+        // Element access
+        const_reference operator () (size_type i, size_type j) const;
+
+        typedef const_iterator1_type const_iterator1;
+        typedef const_iterator1 iterator1;
+        typedef const_iterator2_type const_iterator2;
+        typedef const_iterator2 iterator2;
+
+        // Element lookup
+        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
+        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
+        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
+        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
+
+        // Iterators are the iterators of the referenced expression.
+
+        const_iterator1 begin1 () const;
+        const_iterator1 end1 () const;
+
+        const_iterator2 begin2 () const;
+        const_iterator2 end2 () const;
+
+        // Reverse iterators
+
+        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
+
+        const_reverse_iterator1 rbegin1 () const;
+        const_reverse_iterator1 rend1 () const;
+
+        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
+
+        const_reverse_iterator2 rbegin2 () const;
+        const_reverse_iterator2 rend2 () const;
+    };
+ +

Reference

+ +

Description

+ +

The templated class matrix_reference<E> contains +a reference to a matrix expression.

+ +

Definition

+ +

Defined in the header matrix_expression.hpp.

+ +

Template parameters

+ + + + + + + + + + + + +
Parameter Description Default
E The type of the matrix expression.  
+ +

Model of

+ +

Matrix Expression. +

+ +

Type requirements

+ +

None, except for those imposed by the requirements of Matrix Expression.

+ +

Public base classes

+ +

matrix_expression<matrix_reference<E> >

+ +

Members

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Member Description
matrix_reference (expression_type &e) + Constructs a constant reference of the expression.
void resize (size_type size1, size2)Resizes the expression to hold at most size1 rows + of size2 elements.
size_type size1 () constReturns the number of rows.
size_type size2 () constReturns the number of columns.
const_reference operator () (size_type i, + size_type j) constReturns the value of the j-th element in + the i-th row.
reference operator () (size_type i, size_type + j)Returns a reference of the j-th element + in the i-th row.
const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the expression.
const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the expression.
iterator1 begin1 () Returns a iterator1 pointing to the + beginning of the expression.
iterator1 end1 () Returns a iterator1 pointing to the end + of the expression.
const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the expression.
const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the expression.
iterator2 begin2 () Returns a iterator2 pointing to the + beginning of the expression.
iterator2 end2 () Returns a iterator2 pointing to the end + of the expression.
const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed expression.
const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed expression.
reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to + the beginning of the reversed expression.
reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to + the end of the reversed expression.
const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed expression.
const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed expression.
reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to + the beginning of the reversed expression.
reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to + the end of the reversed expression.
+ +

Interface

+ +
    template<class E>
+    class matrix_reference:
+        public matrix_expression<matrix_reference<E> > {
+    public:
+        typedef E expression_type;
+        typedef typename E::size_type size_type;
+        typedef typename E::difference_type difference_type;
+        typedef typename E::value_type value_type;
+        typedef typename E::const_reference const_reference;
+        typedef typename E::reference reference;
+        typedef typename E::const_pointer const_pointer;
+        typedef typename E::pointer pointer;
+        typedef typename E::orientation_category orientation_category;
+        typedef typename E::const_iterator1 const_iterator1_type;
+        typedef typename E::iterator1 iterator1_type;
+        typedef typename E::const_iterator2 const_iterator2_type;
+        typedef typename E::iterator2 iterator2_type;
+        typedef unknown_storage_tag storage_category;
+
+        // Construction and destruction
+        matrix_reference ();
+        matrix_reference (expression_type &e);
+
+        // Accessors
+        size_type size1 () const;
+        size_type size2 () const;
+        const expression_type &expression () const;
+        expression_type &expression ();
+
+        // Resizing
+        void resize (size_type size1, size_type size2);
+
+        // Element access
+        const_reference operator () (size_type i, size_type j) const;
+        reference operator () (size_type i, size_type j);
+
+        typedef const_iterator1_type const_iterator1;
+        typedef iterator1_type iterator1;
+        typedef const_iterator2_type const_iterator2;
+        typedef iterator2_type iterator2;
+
+        // Element lookup
+        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
+        iterator1 find_first1 (int rank, size_type i, size_type j);
+        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
+        iterator1 find_last1 (int rank, size_type i, size_type j);
+        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
+        iterator2 find_first2 (int rank, size_type i, size_type j);
+        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
+        iterator2 find_last2 (int rank, size_type i, size_type j);
+
+        // Iterators are the iterators of the referenced expression.
+
+        const_iterator1 begin1 () const;
+        const_iterator1 end1 () const;
+
+        iterator1 begin1 ();
+        iterator1 end1 ();
+
+        const_iterator2 begin2 () const;
+        const_iterator2 end2 () const;
+
+        iterator2 begin2 ();
+        iterator2 end2 ();
+
+        // Reverse iterators
+
+        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
+
+        const_reverse_iterator1 rbegin1 () const;
+        const_reverse_iterator1 rend1 () const;
+
+        typedef reverse_iterator_base1<iterator1> reverse_iterator1;
+
+        reverse_iterator1 rbegin1 ();
+        reverse_iterator1 rend1 ();
+
+        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
+
+        const_reverse_iterator2 rbegin2 () const;
+        const_reverse_iterator2 rend2 () const;
+
+        typedef reverse_iterator_base2<iterator2> reverse_iterator2;
+
+        reverse_iterator2 rbegin2 ();
+        reverse_iterator2 rend2 ();
+    };
+ +

Matrix Operations

+ +

Unary Operation Description

+ +

Description

+ +

The templated classes matrix_unary1<E, F> and +matrix_unary2<E, F> describe unary matrix +operations.

+ +

Definition

+ +

Defined in the header matrix_expression.hpp.

+ +

Template parameters

+ + + + + + + + + + + + + + + + + +
Parameter Description Default
E The type of the matrix expression.  
FThe type of the operation. 
+ +

Model of

+ +

Matrix Expression. +

+ +

Type requirements

+ +

None, except for those imposed by the requirements of Matrix Expression.

+ +

Public base classes

+ +

matrix_expression<matrix_unary1<E, F> > and +matrix_expression<matrix_unary2<E, F> > resp.

+ +

Members

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Member Description
matrix_unary1 (const expression_type &e) + Constructs a description of the expression.
matrix_unary2 (const expression_type &e)Constructs a description of the expression.
size_type size1 () constReturns the number of rows.
size_type size2 () constReturns the number of columns.
const_reference operator () (size_type i, + size_type j) constReturns the value of the j-th element in + the i-th row.
const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the expression.
const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the expression.
const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the expression.
const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the expression.
const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed expression.
const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed expression.
const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed expression.
const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed expression.
+ +

Interface

+ +
    template<class E, class F>
+    class matrix_unary1:
+        public matrix_expression<matrix_unary1<E, F> > {
+    public:
+        typedef E expression_type;
+        typedef F functor_type;
+        typedef typename E::size_type size_type;
+        typedef typename E::difference_type difference_type;
+        typedef typename F::result_type value_type;
+        typedef value_type const_reference;
+        typedef const_reference reference;
+        typedef const value_type *const_pointer;
+        typedef const_pointer pointer;
+        typedef const matrix_unary1<E, F> const_closure_type;
+        typedef typename E::orientation_category orientation_category;
+        typedef typename E::const_iterator1 const_iterator1_type;
+        typedef typename E::const_iterator2 const_iterator2_type;
+        typedef unknown_storage_tag storage_category;
+
+        // Construction and destruction
+        matrix_unary1 ();
+        matrix_unary1 (const expression_type &e);
+
+        // Accessors
+        size_type size1 () const;
+        size_type size2 () const;
+        const expression_type &expression () const;
+
+        // Element access
+        const_reference operator () (size_type i, size_type j) const;
+
+        class const_iterator1;
+        typedef const_iterator1 iterator1;
+        class const_iterator2;
+        typedef const_iterator2 iterator2;
+        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
+        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
+
+        // Element lookup
+        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
+        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
+        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
+        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
+
+        // Iterators enhance the iterators of the referenced expression
+        // with the unary functor.
+
+        class const_iterator1:
+            public container_const_reference<matrix_unary1>,
+            public random_access_iterator_base<const_iterator1, value_type> {
+        public:
+            typedef typename E::const_iterator1::iterator_category iterator_category;
+            typedef typename matrix_unary1::difference_type difference_type;
+            typedef typename matrix_unary1::value_type value_type;
+            typedef typename matrix_unary1::const_reference reference;
+            typedef typename matrix_unary1::const_pointer pointer;
+            typedef const_iterator2 dual_iterator_type;
+            typedef const_reverse_iterator2 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator1 ();
+            const_iterator1 (const matrix_unary1 &mu, const const_iterator1_type &it);
+
+            // Arithmetic
+            const_iterator1 &operator ++ ();
+            const_iterator1 &operator -- ();
+            const_iterator1 &operator += (difference_type n);
+            const_iterator1 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator1 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator2 begin () const;
+            const_iterator2 end () const;
+            const_reverse_iterator2 rbegin () const;
+            const_reverse_iterator2 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator1 &operator = (const const_iterator1 &it);
+
+            // Comparison
+            bool operator == (const const_iterator1 &it) const;
+            bool operator <(const const_iterator1 &it) const;
+        };
+
+        const_iterator1 begin1 () const;
+        const_iterator1 end1 () const;
+
+        class const_iterator2:
+            public container_const_reference<matrix_unary1>,
+            public random_access_iterator_base<const_iterator2, value_type> {
+        public:
+            typedef typename E::const_iterator2::iterator_category iterator_category;
+            typedef typename matrix_unary1::difference_type difference_type;
+            typedef typename matrix_unary1::value_type value_type;
+            typedef typename matrix_unary1::const_reference reference;
+            typedef typename matrix_unary1::const_pointer pointer;
+            typedef const_iterator1 dual_iterator_type;
+            typedef const_reverse_iterator1 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator2 ();
+            const_iterator2 (const matrix_unary1 &mu, const const_iterator2_type &it);
+
+            // Arithmetic
+            const_iterator2 &operator ++ ();
+            const_iterator2 &operator -- ();
+            const_iterator2 &operator += (difference_type n);
+            const_iterator2 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator2 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator1 begin () const;
+            const_iterator1 end () const;
+            const_reverse_iterator1 rbegin () const;
+            const_reverse_iterator1 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator2 &operator = (const const_iterator2 &it);
+
+            // Comparison
+            bool operator == (const const_iterator2 &it) const;
+            bool operator <(const const_iterator2 &it) const;
+        };
+
+        const_iterator2 begin2 () const;
+        const_iterator2 end2 () const;
+
+        // Reverse iterators
+
+        const_reverse_iterator1 rbegin1 () const;
+        const_reverse_iterator1 rend1 () const;
+
+        const_reverse_iterator2 rbegin2 () const;
+        const_reverse_iterator2 rend2 () const;
+    };
+
+    template<class E, class F>
+    class matrix_unary2:
+        public matrix_expression<matrix_unary2<E, F> > {
+    public:
+        typedef E expression_type;
+        typedef F functor_type;
+        typedef typename E::size_type size_type;
+        typedef typename E::difference_type difference_type;
+        typedef typename F::result_type value_type;
+        typedef value_type const_reference;
+        typedef const_reference reference;
+        typedef const value_type *const_pointer;
+        typedef const_pointer pointer;
+        typedef const matrix_unary2<E, F> const_closure_type;
+        typedef typename E::orientation_category orientation_category;
+        typedef typename E::const_iterator1 const_iterator2_type;
+        typedef typename E::const_iterator2 const_iterator1_type;
+        typedef unknown_storage_tag storage_category;
+
+        // Construction and destruction
+        matrix_unary2 ();
+        matrix_unary2 (const expression_type &e);
+
+        // Accessors
+        size_type size1 () const;
+        size_type size2 () const;
+        const expression_type &expression () const;
+
+        // Element access
+        const_reference operator () (size_type i, size_type j) const;
+
+        class const_iterator1;
+        typedef const_iterator1 iterator1;
+        class const_iterator2;
+        typedef const_iterator2 iterator2;
+        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
+        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
+
+        // Element lookup
+        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
+        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
+        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
+        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
+
+        // Iterators enhance the iterators of the referenced expression
+        // with the unary functor.
+
+        class const_iterator1:
+            public container_const_reference<matrix_unary2>,
+            public random_access_iterator_base<const_iterator1, value_type> {
+        public:
+            typedef typename E::const_iterator2::iterator_category iterator_category;
+            typedef typename matrix_unary2::difference_type difference_type;
+            typedef typename matrix_unary2::value_type value_type;
+            typedef typename matrix_unary2::const_reference reference;
+            typedef typename matrix_unary2::const_pointer pointer;
+            typedef const_iterator2 dual_iterator_type;
+            typedef const_reverse_iterator2 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator1 ();
+            const_iterator1 (const matrix_unary2 &mu, const const_iterator1_type &it);
+
+            // Arithmetic
+            const_iterator1 &operator ++ ();
+            const_iterator1 &operator -- ();
+            const_iterator1 &operator += (difference_type n);
+            const_iterator1 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator1 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator2 begin () const;
+            const_iterator2 end () const;
+            const_reverse_iterator2 rbegin () const;
+            const_reverse_iterator2 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator1 &operator = (const const_iterator1 &it);
+
+            // Comparison
+            bool operator == (const const_iterator1 &it) const;
+            bool operator <(const const_iterator1 &it) const;
+        };
+
+        const_iterator1 begin1 () const;
+        const_iterator1 end1 () const;
+
+        class const_iterator2:
+            public container_const_reference<matrix_unary2>,
+            public random_access_iterator_base<const_iterator2, value_type> {
+        public:
+            typedef typename E::const_iterator1::iterator_category iterator_category;
+            typedef typename matrix_unary2::difference_type difference_type;
+            typedef typename matrix_unary2::value_type value_type;
+            typedef typename matrix_unary2::const_reference reference;
+            typedef typename matrix_unary2::const_pointer pointer;
+            typedef const_iterator1 dual_iterator_type;
+            typedef const_reverse_iterator1 dual_reverse_iterator_type;
+
+            // Construction and destruction
+            const_iterator2 ();
+            const_iterator2 (const matrix_unary2 &mu, const const_iterator2_type &it);
+
+            // Arithmetic
+            const_iterator2 &operator ++ ();
+            const_iterator2 &operator -- ();
+            const_iterator2 &operator += (difference_type n);
+            const_iterator2 &operator -= (difference_type n);
+            difference_type operator - (const const_iterator2 &it) const;
+
+            // Dereference
+            reference operator * () const;
+
+            const_iterator1 begin () const;
+            const_iterator1 end () const;
+            const_reverse_iterator1 rbegin () const;
+            const_reverse_iterator1 rend () const;
+
+            // Indices
+            size_type index1 () const;
+            size_type index2 () const;
+
+            // Assignment 
+            const_iterator2 &operator = (const const_iterator2 &it);
+
+            // Comparison
+            bool operator == (const const_iterator2 &it) const;
+            bool operator <(const const_iterator2 &it) const;
+        };
+
+        const_iterator2 begin2 () const;
+        const_iterator2 end2 () const;
+
+        // Reverse iterators
+
+        const_reverse_iterator1 rbegin1 () const;
+        const_reverse_iterator1 rend1 () const;
+
+        const_reverse_iterator2 rbegin2 () const;
+        const_reverse_iterator2 rend2 () const;
+    };
+ +

Unary Operations

+ +

Prototypes

+ +
    template<class E, class F>
+    struct matrix_unary1_traits {
+        typedef matrix_unary1<typename E::const_closure_type, F> expression_type;
+        typedef expression_type result_type; 
+    };
+
+    // (- m) [i] [j] = - m [i] [j]
+    template<class E> 
+    typename matrix_unary1_traits<E, scalar_negate<typename E::value_type> >::result_type
+    operator - (const matrix_expression<E> &e);
+
+    // (conj m) [i] [j] = conj (m [i] [j])
+    template<class E> 
+    typename matrix_unary1_traits<E, scalar_conj<typename E::value_type> >::result_type
+    conj (const matrix_expression<E> &e);
+
+    // (real m) [i] [j] = real (m [i] [j])
+    template<class E> 
+    typename matrix_unary1_traits<E, scalar_real<typename E::value_type> >::result_type
+    real (const matrix_expression<E> &e);
+
+    // (imag m) [i] [j] = imag (m [i] [j])
+    template<class E> 
+    typename matrix_unary1_traits<E, scalar_imag<typename E::value_type> >::result_type
+    imag (const matrix_expression<E> &e);
+
+    template<class E, class F>
+    struct matrix_unary2_traits {
+        typedef matrix_unary2<typename E::const_closure_type, F> expression_type;
+        typedef expression_type result_type; 
+    };
+
+    // (trans m) [i] [j] = m [j] [i]
+    template<class E> 
+    typename matrix_unary2_traits<E, scalar_identity<typename E::value_type> >::result_type
+    trans (const matrix_expression<E> &e);
+
+    // (herm m) [i] [j] = conj (m [j] [i])
+    template<class E> 
+    typename matrix_unary2_traits<E, scalar_conj<typename E::value_type> >::result_type
+    herm (const matrix_expression<E> &e);
+ +

Description

+ +

operator - computes the additive inverse of a +matrix expression. conj computes the complex +conjugate of a matrix expression. real and imag +compute the real and imaginary parts of a matrix expression. trans +computes the transpose of a matrix expression. herm computes +the hermitian, i.e. the complex conjugate of the transpose of a +matrix expression.

+ +

Definition

+ +

Defined in the header matrix_expression.hpp.

+ +

Type requirements

+ + +
  • E is a model of Matrix Expression.
  • +
    + +

    Preconditions

    + +

    None.

    + +

    Complexity

    + +

    Quadratic depending from the size of the matrix expression.

    + +

    Examples

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    matrix<std::complex<double> > m (3, 3);
    +    for (int i = 0; i < m.size1 (); ++ i) 
    +        for (int j = 0; j < m.size2 (); ++ j) 
    +            m (i, j) = std::complex (3 * i + j, 3 * i + j);
    +
    +    std::cout << - m << std::endl;
    +    std::cout << conj (m) << std::endl;
    +    std::cout << real (m) << std::endl;
    +    std::cout << imag (m) << std::endl;
    +    std::cout << trans (m) << std::endl;
    +    std::cout << herm (m) << std::endl;
    +}
    + +

    Binary Operation Description

    + +

    Description

    + +

    The templated class matrix_binary<E1, E2, F> describes +a binary matrix operation.

    + +

    Definition

    + +

    Defined in the header matrix_expression.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    E1 The type of the first matrix expression.  
    E2The type of the second matrix expression.  
    FThe type of the operation. 
    + +

    Model of

    + +

    Matrix Expression. +

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Matrix Expression.

    + +

    Public base classes

    + +

    matrix_expression<matrix_binary<E1, E2, F> >.

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    matrix_binary (const expression1_type &e1, + const expression2_type &e2) Constructs a description of the expression.
    size_type size1 () constReturns the number of rows.
    size_type size2 () constReturns the number of columns.
    const_reference operator () (size_type i, + size_type j) constReturns the value of the j-th element in + the i-th row.
    const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the expression.
    const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the expression.
    const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the expression.
    const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the expression.
    const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed expression.
    const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed expression.
    const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed expression.
    const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed expression.
    + +

    Interface

    + +
        template<class E1, class E2, class F>
    +    class matrix_binary:
    +        public matrix_expression<matrix_binary<E1, E2, F> > {
    +    public:
    +        typedef E1 expression1_type;
    +        typedef E2 expression2_type;
    +        typedef F functor_type;
    +        typedef typename promote_traits<typename E1::size_type, typename E2::size_type>::promote_type size_type;
    +        typedef typename promote_traits<typename E1::difference_type, typename E2::difference_type>::promote_type difference_type;
    +        typedef typename F::result_type value_type;
    +        typedef value_type const_reference;
    +        typedef const_reference reference;
    +        typedef const value_type *const_pointer;
    +        typedef const_pointer pointer;
    +        typedef const matrix_binary<E1, E2, F> const_closure_type;
    +        typedef unknown_orientation_tag orientation_category;
    +        typedef typename E1::const_iterator1 const_iterator11_type;
    +        typedef typename E1::const_iterator2 const_iterator12_type;
    +        typedef typename E2::const_iterator1 const_iterator21_type;
    +        typedef typename E2::const_iterator2 const_iterator22_type;
    +        typedef unknown_storage_tag storage_category;
    +
    +        // Construction and destruction
    +        matrix_binary ();
    +        matrix_binary (const E1 &e1, const E2 &e2);
    +
    +        // Accessors
    +        size_type size1 () const;
    +        size_type size2 () const;
    +        const expression1_type &expression1 () const;
    +        const expression2_type &expression2 () const;
    +
    +        // Element access
    +        const_reference operator () (size_type i, size_type j) const;
    +
    +        class const_iterator1;
    +        typedef const_iterator1 iterator1;
    +        class const_iterator2;
    +        typedef const_iterator2 iterator2;
    +        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
    +        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
    +
    +        // Element lookup
    +        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
    +        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
    +        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
    +        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
    +
    +        // Iterators enhance the iterators of the referenced expression
    +        // with the binary functor.
    +
    +        class const_iterator1:
    +            public container_const_reference<matrix_binary>,
    +            public random_access_iterator_base<const_iterator1, value_type> {
    +        public:
    +            typedef typename restrict_traits<typename E1::const_iterator1::iterator_category,
    +                                             typename E2::const_iterator1::iterator_category>::iterator_category iterator_category;
    +            typedef typename matrix_binary::difference_type difference_type;
    +            typedef typename matrix_binary::value_type value_type;
    +            typedef typename matrix_binary::const_reference reference;
    +            typedef typename matrix_binary::const_pointer pointer;
    +            typedef const_iterator2 dual_iterator_type;
    +            typedef const_reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator1 ();
    +            const_iterator1 (const matrix_binary &mb, size_type i, size_type j,
    +                             const const_iterator11_type &it1, const const_iterator11_type &it1_end,
    +                             const const_iterator21_type &it2, const const_iterator21_type &it2_end);
    +
    +            // Dense specializations
    +            void increment (dense_random_access_iterator_tag);
    +            void decrement (dense_random_access_iterator_tag);
    +            value_type dereference (dense_random_access_iterator_tag) const;
    +
    +            // Packed specializations
    +            void increment (packed_random_access_iterator_tag);
    +            void decrement (packed_random_access_iterator_tag);
    +            value_type dereference (packed_random_access_iterator_tag) const;
    +
    +            // Sparse specializations
    +            void increment (sparse_bidirectional_iterator_tag);
    +            void decrement (sparse_bidirectional_iterator_tag);
    +            value_type dereference (sparse_bidirectional_iterator_tag) const;
    +
    +            // Arithmetic
    +            const_iterator1 &operator ++ ();
    +            const_iterator1 &operator -- ();
    +            const_iterator1 &operator += (difference_type n);
    +            const_iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator2 begin () const;
    +            const_iterator2 end () const;
    +            const_reverse_iterator2 rbegin () const;
    +            const_reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator1 &operator = (const const_iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator1 &it) const;
    +            bool operator <(const const_iterator1 &it) const;
    +        };
    +
    +        const_iterator1 begin1 () const;
    +        const_iterator1 end1 () const;
    +
    +        class const_iterator2:
    +            public container_const_reference<matrix_binary>,
    +            public random_access_iterator_base<const_iterator2, value_type> {
    +        public:
    +            typedef typename restrict_traits<typename E1::const_iterator2::iterator_category, 
    +                                             typename E2::const_iterator2::iterator_category>::iterator_category iterator_category;
    +            typedef typename matrix_binary::difference_type difference_type;
    +            typedef typename matrix_binary::value_type value_type;
    +            typedef typename matrix_binary::const_reference reference;
    +            typedef typename matrix_binary::const_pointer pointer;
    +            typedef const_iterator1 dual_iterator_type;
    +            typedef const_reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator2 ();
    +            const_iterator2 (const matrix_binary &mb, size_type i, size_type j,
    +                             const const_iterator12_type &it1, const const_iterator12_type &it1_end,
    +                             const const_iterator22_type &it2, const const_iterator22_type &it2_end);
    +
    +            // Dense specializations
    +            void increment (dense_random_access_iterator_tag);
    +            void decrement (dense_random_access_iterator_tag);
    +            value_type dereference (dense_random_access_iterator_tag) const;
    +
    +            // Packed specializations
    +            void increment (packed_random_access_iterator_tag);
    +            void decrement (packed_random_access_iterator_tag);
    +            value_type dereference (packed_random_access_iterator_tag) const;
    +
    +            // Sparse specializations
    +            void increment (sparse_bidirectional_iterator_tag);
    +            void decrement (sparse_bidirectional_iterator_tag);
    +            value_type dereference (sparse_bidirectional_iterator_tag) const;
    +
    +            // Arithmetic
    +            const_iterator2 &operator ++ ();
    +            const_iterator2 &operator -- ();
    +            const_iterator2 &operator += (difference_type n);
    +            const_iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator1 begin () const;
    +            const_iterator1 end () const;
    +            const_reverse_iterator1 rbegin () const;
    +            const_reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator2 &operator = (const const_iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator2 &it) const;
    +            bool operator <(const const_iterator2 &it) const;
    +        };
    +
    +        const_iterator2 begin2 () const;
    +        const_iterator2 end2 () const;
    +
    +        // Reverse iterators
    +
    +        const_reverse_iterator1 rbegin1 () const;
    +        const_reverse_iterator1 rend1 () const;
    +
    +        const_reverse_iterator2 rbegin2 () const;
    +        const_reverse_iterator2 rend2 () const;
    +    };
    + +

    Binary Operations

    + +

    Prototypes

    + +
        template<class E1, class E2, class F>
    +    struct matrix_binary_traits {
    +        typedef matrix_binary<typename E1::const_closure_type, 
    +                              typename E2::const_closure_type, F> expression_type;
    +        typedef expression_type result_type; 
    +    };
    +
    +    // (m1 + m2) [i] [j] = m1 [i] [j] + m2 [i] [j]
    +    template<class E1, class E2>
    +    typename matrix_binary_traits<E1, E2, scalar_plus<typename E1::value_type, 
    +                                                      typename E2::value_type> >::result_type
    +    operator + (const matrix_expression<E1> &e1, 
    +                const matrix_expression<E2> &e2);
    +
    +    // (m1 - m2) [i] [j] = m1 [i] [j] - m2 [i] [j]
    +    template<class E1, class E2>
    +    typename matrix_binary_traits<E1, E2, scalar_minus<typename E1::value_type, 
    +                                                       typename E2::value_type> >::result_type
    +    operator - (const matrix_expression<E1> &e1, 
    +                const matrix_expression<E2> &e2);
    + +

    Description

    + +

    operator + computes the sum of two matrix +expressions. operator - computes the difference of +two matrix expressions.

    + +

    Definition

    + +

    Defined in the header matrix_expression.hpp.

    + +

    Type requirements

    + + +
  • E1 is a model of Matrix Expression. +
  • +
  • E2 is a model of Matrix Expression. +
  • +
    + +

    Preconditions

    + + +
  • e1 ().size1 () == e2 ().size1 ()
  • +
  • e1 ().size2 () == e2 ().size2 ()
  • +
    + +

    Complexity

    + +

    Quadratic depending from the size of the matrix expressions.

    + +

    Examples

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    matrix<double > m1 (3, 3), m (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) 
    +            m1 (i, j) = m2 (i, j) = 3 * i + j;
    +
    +    std::cout << m1 + m2 << std::endl;
    +    std::cout << m1 - m2 << std::endl;
    +}
    + +

    Scalar Matrix Operation Description

    + +

    Description

    + +

    The templated classes matrix_binary_scalar1<E1, E2, +F> and matrix_binary_scalar2<E1, E2, F> +describe binary operations between a scalar and a matrix.

    + +

    Definition

    + +

    Defined in the header matrix_expression.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    E1/E2 The type of the scalar expression.  
    E2/E1The type of the matrix expression.  
    FThe type of the operation. 
    + +

    Model of

    + +

    Matrix Expression. +

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Matrix Expression.

    + +

    Public base classes

    + +

    matrix_expression<matrix_binary_scalar1<E1, E2, +F> > and +matrix_expression<matrix_binary_scalar2<E1, E2, F> > resp.

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    matrix_binary_scalar1 (const expression1_type + &e1, const expression2_type &e2) Constructs a description of the expression.
    matrix_binary_scalar1 (const expression1_type + &e1, const expression2_type &e2) Constructs a description of the expression.
    size_type size1 () constReturns the number of rows.
    size_type size2 () constReturns the number of columns.
    const_reference operator () (size_type i, + size_type j) constReturns the value of the j-th element in + the i-th row.
    const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the expression.
    const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the expression.
    const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the expression.
    const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the expression.
    const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed expression.
    const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed expression.
    const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed expression.
    const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed expression.
    + +

    Interface

    + +
        template<class E1, class E2, class F>
    +    class matrix_binary_scalar1:
    +        public matrix_expression<matrix_binary_scalar1<E1, E2, F> > {
    +    public:
    +        typedef E1 expression1_type;
    +        typedef E2 expression2_type;
    +        typedef F functor_type;
    +        typedef typename E2::size_type size_type;
    +        typedef typename E2::difference_type difference_type;
    +        typedef typename F::result_type value_type;
    +        typedef value_type const_reference;
    +        typedef const_reference reference;
    +        typedef const value_type *const_pointer;
    +        typedef const_pointer pointer;
    +        typedef const matrix_binary_scalar1<E1, E2, F> const_closure_type;
    +        typedef typename E2::orientation_category orientation_category;
    +        typedef typename E1::value_type const_iterator1_type;
    +        typedef typename E2::const_iterator1 const_iterator21_type;
    +        typedef typename E2::const_iterator2 const_iterator22_type;
    +        typedef unknown_storage_tag storage_category;
    +
    +        // Construction and destruction
    +        matrix_binary_scalar1 ();
    +        matrix_binary_scalar1 (const expression1_type &e1, const expression2_type &e2);
    +
    +        // Accessors
    +        size_type size1 () const;
    +        size_type size2 () const;
    +        const expression1_type &expression1 () const;
    +        const expression2_type &expression2 () const;
    +
    +        // Element access
    +        const_reference operator () (size_type i, size_type j) const;
    +
    +        class const_iterator1;
    +        typedef const_iterator1 iterator1;
    +        class const_iterator2;
    +        typedef const_iterator2 iterator2;
    +        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
    +        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
    +
    +        // Element lookup
    +        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
    +        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
    +        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
    +        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
    +
    +        // Iterators enhance the iterators of the referenced expression
    +        // with the binary functor.
    +
    +        class const_iterator1:
    +            public container_const_reference<matrix_binary_scalar1>,
    +            public random_access_iterator_base<const_iterator1, value_type> {
    +        public:
    +            typedef typename E2::const_iterator1::iterator_category iterator_category;
    +            typedef typename matrix_binary_scalar1::difference_type difference_type;
    +            typedef typename matrix_binary_scalar1::value_type value_type;
    +            typedef typename matrix_binary_scalar1::const_reference reference;
    +            typedef typename matrix_binary_scalar1::const_pointer pointer;
    +            typedef const_iterator2 dual_iterator_type;
    +            typedef const_reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator1 ();
    +            const_iterator1 (const matrix_binary_scalar1 &mbs, const const_iterator1_type &it1, const const_iterator21_type &it2);
    +
    +            // Arithmetic
    +            const_iterator1 &operator ++ ();
    +            const_iterator1 &operator -- ();
    +            const_iterator1 &operator += (difference_type n);
    +            const_iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator2 begin () const;
    +            const_iterator2 end () const;
    +            const_reverse_iterator2 rbegin () const;
    +            const_reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator1 &operator = (const const_iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator1 &it) const;
    +            bool operator <(const const_iterator1 &it) const;
    +        };
    +
    +        const_iterator1 begin1 () const;
    +        const_iterator1 end1 () const;
    +
    +        class const_iterator2:
    +            public container_const_reference<matrix_binary_scalar1>,
    +            public random_access_iterator_base<const_iterator2, value_type> {
    +        public:
    +            typedef typename E2::const_iterator2::iterator_category iterator_category;
    +            typedef typename matrix_binary_scalar1::difference_type difference_type;
    +            typedef typename matrix_binary_scalar1::value_type value_type;
    +            typedef typename matrix_binary_scalar1::const_reference reference;
    +            typedef typename matrix_binary_scalar1::const_pointer pointer;
    +            typedef const_iterator1 dual_iterator_type;
    +            typedef const_reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator2 ();
    +            const_iterator2 (const matrix_binary_scalar1 &mbs, const const_iterator1_type &it1, const const_iterator22_type &it2);
    +
    +            // Arithmetic
    +            const_iterator2 &operator ++ ();
    +            const_iterator2 &operator -- ();
    +            const_iterator2 &operator += (difference_type n);
    +            const_iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator1 begin () const;
    +            const_iterator1 end () const;
    +            const_reverse_iterator1 rbegin () const;
    +            const_reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator2 &operator = (const const_iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator2 &it) const;
    +            bool operator <(const const_iterator2 &it) const;
    +        };
    +
    +        const_iterator2 begin2 () const;
    +        const_iterator2 end2 () const;
    +
    +        // Reverse iterators
    +
    +        const_reverse_iterator1 rbegin1 () const;
    +        const_reverse_iterator1 rend1 () const;
    +
    +        const_reverse_iterator2 rbegin2 () const;
    +        const_reverse_iterator2 rend2 () const;
    +    };
    +
    +    template<class E1, class E2, class F>
    +    class matrix_binary_scalar2:
    +        public matrix_expression<matrix_binary_scalar2<E1, E2, F> > {
    +    public:
    +        typedef E1 expression1_type;
    +        typedef E2 expression2_type;
    +        typedef F functor_type;
    +        typedef typename E1::size_type size_type;
    +        typedef typename E1::difference_type difference_type;
    +        typedef typename F::result_type value_type;
    +        typedef value_type const_reference;
    +        typedef const_reference reference;
    +        typedef const value_type *const_pointer;
    +        typedef const_pointer pointer;
    +        typedef const matrix_binary_scalar2<E1, E2, F> const_closure_type;
    +        typedef typename E1::orientation_category orientation_category;
    +        typedef typename E1::const_iterator1 const_iterator11_type;
    +        typedef typename E1::const_iterator2 const_iterator12_type;
    +        typedef typename E2::value_type const_iterator2_type;
    +        typedef unknown_storage_tag storage_category;
    +
    +        // Construction and destruction
    +        matrix_binary_scalar2 ();
    +        matrix_binary_scalar2 (const expression1_type &e1, const expression2_type &e2);
    +
    +        // Accessors
    +        size_type size1 () const;
    +        size_type size2 () const;
    +        const expression1_type &expression1 () const;
    +        const expression2_type &expression2 () const;
    +
    +        // Element access
    +        const_reference operator () (size_type i, size_type j) const;
    +
    +        class const_iterator1;
    +        typedef const_iterator1 iterator1;
    +        class const_iterator2;
    +        typedef const_iterator2 iterator2;
    +        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
    +        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
    +
    +        // Element lookup
    +        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
    +        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
    +        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
    +        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
    +
    +        // Iterators enhance the iterators of the referenced expression
    +        // with the binary functor.
    +
    +        class const_iterator1:
    +            public container_const_reference<matrix_binary_scalar2>,
    +            public random_access_iterator_base<const_iterator1, value_type> {
    +        public:
    +            typedef typename E1::const_iterator1::iterator_category iterator_category;
    +            typedef typename matrix_binary_scalar2::difference_type difference_type;
    +            typedef typename matrix_binary_scalar2::value_type value_type;
    +            typedef typename matrix_binary_scalar2::const_reference reference;
    +            typedef typename matrix_binary_scalar2::const_pointer pointer;
    +            typedef const_iterator2 dual_iterator_type;
    +            typedef const_reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator1 ();
    +            const_iterator1 (const matrix_binary_scalar2 &mbs, const const_iterator11_type &it1, const const_iterator2_type &it2);
    +
    +            // Arithmetic
    +            const_iterator1 &operator ++ ();
    +            const_iterator1 &operator -- ();
    +            const_iterator1 &operator += (difference_type n);
    +            const_iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator2 begin () const;
    +            const_iterator2 end () const;
    +            const_reverse_iterator2 rbegin () const;
    +            const_reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator1 &operator = (const const_iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator1 &it) const;
    +            bool operator <(const const_iterator1 &it) const;
    +        };
    +
    +        const_iterator1 begin1 () const;
    +        const_iterator1 end1 () const;
    +
    +        class const_iterator2:
    +            public container_const_reference<matrix_binary_scalar2>,
    +            public random_access_iterator_base<const_iterator2, value_type> {
    +        public:
    +            typedef typename E1::const_iterator2::iterator_category iterator_category;
    +            typedef typename matrix_binary_scalar2::difference_type difference_type;
    +            typedef typename matrix_binary_scalar2::value_type value_type;
    +            typedef typename matrix_binary_scalar2::const_reference reference;
    +            typedef typename matrix_binary_scalar2::const_pointer pointer;
    +            typedef const_iterator1 dual_iterator_type;
    +            typedef const_reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator2 ();
    +            const_iterator2 (const matrix_binary_scalar2 &mbs, const const_iterator12_type &it1, const const_iterator2_type &it2);
    +
    +            // Arithmetic
    +            const_iterator2 &operator ++ ();
    +            const_iterator2 &operator -- ();
    +            const_iterator2 &operator += (difference_type n);
    +            const_iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator1 begin () const;
    +            const_iterator1 end () const;
    +            const_reverse_iterator1 rbegin () const;
    +            const_reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator2 &operator = (const const_iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator2 &it) const;
    +            bool operator <(const const_iterator2 &it) const;
    +        };
    +
    +        const_iterator2 begin2 () const;
    +        const_iterator2 end2 () const;
    +
    +        // Reverse iterators
    +
    +        const_reverse_iterator1 rbegin1 () const;
    +        const_reverse_iterator1 rend1 () const;
    +
    +        const_reverse_iterator2 rbegin2 () const;
    +        const_reverse_iterator2 rend2 () const;
    +    };
    + +

    Scalar Matrix Operations

    + +

    Prototypes

    + +
        template<class T1, class E2, class F>
    +    struct matrix_binary_scalar1_traits {
    +        typedef matrix_binary_scalar1<scalar_const_reference<T1>, 
    +                                     typename E2::const_closure_type, F> expression_type;
    +        typedef expression_type result_type; 
    +    };
    +
    +    // (t * m) [i] [j] = t * m [i] [j]
    +    template<class T1, class E2>
    +    typename matrix_binary_scalar1_traits<T1, E2, scalar_multiplies<T1, typename E2::value_type> >::result_type
    +    operator * (const T1 &e1, 
    +                const matrix_expression<E2> &e2);
    +
    +    template<class E1, class T2, class F>
    +    struct matrix_binary_scalar2_traits {
    +        typedef matrix_binary_scalar2<typename E1::const_closure_type,
    +                                      scalar_const_reference<T2>, F> expression_type;
    +        typedef expression_type result_type; 
    +    };
    +
    +    // (m * t) [i] [j] = m [i] [j] * t
    +    template<class E1, class T2>
    +    typename matrix_binary_scalar2_traits<E1, T2, scalar_multiplies<typename E1::value_type, T2> >::result_type
    +    operator * (const matrix_expression<E1> &e1, 
    +                const T2 &e2);
    +
    +    // (m / t) [i] [j] = m [i] [j] / t
    +    template<class E1, class T2>
    +    typename matrix_binary_scalar2_traits<E1, T2, scalar_divides<typename E1::value_type, T2> >::result_type
    +    operator / (const matrix_expression<E1> &e1, 
    +                const T2 &e2);
    + +

    Description

    + +

    operator * computes the product of a scalar and a +matrix expression. operator / multiplies the matrix +with the reciprocal of the scalar.

    + +

    Definition

    + +

    Defined in the header matrix_expression.hpp.

    + +

    Type requirements

    + + +
  • T1/T2 is a model of Scalar Expression. +
  • +
  • E2/E1 is a model of Matrix Expression.
  • +
    + +

    Preconditions

    + +

    None.

    + +

    Complexity

    + +

    Quadratic depending from the size of the matrix expression.

    + +

    Examples

    + +
    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) 
    +            m (i, j) = 3 * i + j;
    +
    +    std::cout << 2.0 * m << std::endl;
    +    std::cout << m * 2.0 << std::endl;
    +}
    + +

    Matrix Reductions

    + +

    Operations

    + +

    Prototypes

    + +
        template<class M>
    +    matrix_row<M> row (M &data, std::size_t i);
    +
    +    template<class M>
    +    matrix_column<M> column (M &data, std::size_t j);
    + +

    Description

    + +

    row returns the the i-th row of a +matrix expression. column returns the the j-th row +of a matrix expression.

    + +

    Definition

    + +

    Defined in the header matrix_proxy.hpp.

    + +

    Type requirements

    + + +
  • E is a model of Matrix Expression.
  • +
    + +

    Preconditions

    + + +
  • i < e ().size1 ()
  • +
  • j < e ().size2 ()
  • +
    + +

    Complexity

    + +

    Linear depending from the size of the matrix expression.

    + +

    Examples

    + +
    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) 
    +            m (i, j) = 3 * i + j;
    +
    +    for (int i = 0; i < m.size1 (); ++ i) 
    +        std::cout << row (m, i) << std::endl;
    +    for (int j = 0; j < m.size2 (); ++ j) 
    +        std::cout << column (m, j) << std::endl;
    +}
    + +

    Matrix Vector +Operations

    + +

    Binary Operation Description

    + +

    Description

    + +

    The templated classes matrix_vector_binary1<E1, E2, +F> and matrix_vector_binary2<E1, E2, F> describe +binary matrix vector operations.

    + +

    Definition

    + +

    Defined in the header matrix_expression.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    E1 The type of the matrix or vector expression.  
    E2 The type of the vector or matrix expression.  
    F The type of the operation. 
    + +

    Model of

    + +

    Vector Expression. +

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector Expression.

    + +

    Public base classes

    + +

    vector_expression<matrix_vector_binary1<E1, E2, +F> > and vector_expression<matrix_vector_binary2<E1, +E2, F> > resp.

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    matrix_vector_binary1 (const expression1_type + &e1, const expression2_type &e2)Constructs a description of the expression.
    matrix_vector_binary2 (const expression1_type + &e1, const expression2_type &e2)Constructs a description of the expression.
    size_type size () constReturns the size of the expression.
    const_reference operator () (size_type i) constReturns the value of the i-th element.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the expression.
    const_iterator end () constReturns a const_iterator pointing to the + end of the expression.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed expression.
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed expression.
    + +

    Interface

    + +
        template<class E1, class E2, class F>
    +    class matrix_vector_binary1:
    +        public vector_expression<matrix_vector_binary1<E1, E2, F> > {
    +    public:
    +        typedef E1 expression1_type;
    +        typedef E2 expression2_type;
    +        typedef F functor_type;
    +        typedef typename promote_traits<typename E1::size_type, typename E2::size_type>::promote_type size_type;
    +        typedef typename promote_traits<typename E1::difference_type, typename E2::difference_type>::promote_type difference_type;
    +        typedef typename F::result_type value_type;
    +        typedef value_type const_reference;
    +        typedef const_reference reference;
    +        typedef const value_type *const_pointer;
    +        typedef const_pointer pointer;
    +        typedef const matrix_vector_binary1<E1, E2, F> const_closure_type;
    +        typedef typename E1::const_iterator1 const_iterator1_type;
    +        typedef typename E2::const_iterator const_iterator2_type;
    +        typedef unknown_storage_tag storage_category;
    +
    +        // Construction and destruction
    +        matrix_vector_binary1 ();
    +        matrix_vector_binary1 (const expression1_type &e1, const expression2_type &e2);
    +
    +        // Accessors
    +        size_type size () const;
    +        const expression1_type &expression1 () const;
    +        const expression2_type &expression2 () const;
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +
    +        class const_iterator;
    +        typedef const_iterator iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type i) const;
    +        const_iterator find_last (size_type i) const;
    +
    +        // Iterator simply is a pointer.
    +
    +        class const_iterator:
    +            public container_const_reference<matrix_vector_binary1>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef typename restrict_traits<typename E1::const_iterator1::iterator_category, 
    +                                             typename E2::const_iterator::iterator_category>::iterator_category iterator_category;
    +            typedef typename matrix_vector_binary1::difference_type difference_type;
    +            typedef typename matrix_vector_binary1::value_type value_type;
    +            typedef typename matrix_vector_binary1::const_reference reference;
    +            typedef typename matrix_vector_binary1::const_pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const matrix_vector_binary1 &mvb, const const_iterator1_type &it1);
    +
    +            // Dense random access specialization
    +            value_type dereference (dense_random_access_iterator_tag) const;
    +
    +            // Packed bidirectional specialization
    +            value_type dereference (packed_bidirectional_iterator_tag) const;
    +
    +            // Sparse bidirectional specialization
    +            value_type dereference (sparse_bidirectional_iterator_tag) const;
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +            bool operator <(const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +    };
    +
    +    template<class E1, class E2, class F>
    +    class matrix_vector_binary2:
    +        public vector_expression<matrix_vector_binary2<E1, E2, F> > {
    +    public:
    +        typedef E1 expression1_type;
    +        typedef E2 expression2_type;
    +        typedef F functor_type;
    +        typedef typename promote_traits<typename E1::size_type, typename E2::size_type>::promote_type size_type;
    +        typedef typename promote_traits<typename E1::difference_type, typename E2::difference_type>::promote_type difference_type;
    +        typedef typename F::result_type value_type;
    +        typedef value_type const_reference;
    +        typedef const_reference reference;
    +        typedef const value_type *const_pointer;
    +        typedef const_pointer pointer;
    +        typedef const matrix_vector_binary2<E1, E2, F> const_closure_type;
    +        typedef typename E1::const_iterator const_iterator1_type;
    +        typedef typename E2::const_iterator2 const_iterator2_type;
    +        typedef unknown_storage_tag storage_category;
    +
    +        // Construction and destruction
    +        matrix_vector_binary2 ();
    +        matrix_vector_binary2 (const expression1_type &e1, const expression2_type &e2);
    +
    +        // Accessors
    +        size_type size () const;
    +        const expression1_type &expression1 () const;
    +        const expression2_type &expression2 () const;
    +
    +        // Element access
    +        const_reference operator () (size_type j) const;
    +
    +        class const_iterator;
    +        typedef const_iterator iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type j) const;
    +        const_iterator find_last (size_type j) const;
    +
    +        // Iterator simply is a pointer.
    +
    +        class const_iterator:
    +            public container_const_reference<matrix_vector_binary2>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef typename restrict_traits<typename E1::const_iterator::iterator_category, 
    +                                             typename E2::const_iterator2::iterator_category>::iterator_category iterator_category;
    +            typedef typename matrix_vector_binary2::difference_type difference_type;
    +            typedef typename matrix_vector_binary2::value_type value_type;
    +            typedef typename matrix_vector_binary2::const_reference reference;
    +            typedef typename matrix_vector_binary2::const_pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const matrix_vector_binary2 &mvb, const const_iterator2_type &it2);
    +
    +            // Dense random access specialization
    +            value_type dereference (dense_random_access_iterator_tag) const;
    +
    +            // Packed bidirectional specialization
    +            value_type dereference (packed_bidirectional_iterator_tag) const;
    +
    +            // Sparse bidirectional specialization
    +            value_type dereference (sparse_bidirectional_iterator_tag) const;
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +            bool operator <(const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +    };
    + +

    Binary Operations

    + +

    Prototypes

    + +
        template<class T1, class E1, class T2, class E2>
    +    struct matrix_vector_binary1_traits {
    +        typedef row_major_tag dispatch_category;
    +        typedef typename promote_traits<T1, T2>::promote_type promote_type;
    +        typedef matrix_vector_binary1<typename E1::const_closure_type, 
    +                                      typename E2::const_closure_type, 
    +                                      matrix_vector_prod1<T1, T2, promote_type> > expression_type;
    +        typedef expression_type result_type; 
    +    };
    +
    +    template<class E1, class E2>
    +    typename matrix_vector_binary1_traits<typename E1::value_type, E1, 
    +                                          typename E2::value_type, E2>::result_type
    +    prod (const matrix_expression<E1> &e1, 
    +          const vector_expression<E2> &e2,
    +          row_major_tag);
    +
    +    // Dispatcher
    +    template<class E1, class E2>
    +    typename matrix_vector_binary1_traits<typename E1::value_type, E1, 
    +                                          typename E2::value_type, E2>::result_type
    +    prod (const matrix_expression<E1> &e1, 
    +          const vector_expression<E2> &e2);
    +
    +    template<class E1, class E2>
    +    typename matrix_vector_binary1_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, 
    +               const vector_expression<E2> &e2,
    +               row_major_tag);
    +
    +    // Dispatcher
    +    template<class E1, class E2>
    +    typename matrix_vector_binary1_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, 
    +               const vector_expression<E2> &e2);
    +
    +    template<class V, class E1, class E2>
    +    V
    +    prod (const matrix_expression<E1> &e1,
    +          const vector_expression<E2> &e2);
    +
    +    template<class V, class E1, class E2>
    +    V
    +    prec_prod (const matrix_expression<E1> &e1,
    +               const vector_expression<E2> &e2);
    +
    +    template<class T1, class E1, class T2, class E2>
    +    struct matrix_vector_binary2_traits {
    +        typedef column_major_tag dispatch_category;
    +        typedef typename promote_traits<T1, T2>::promote_type promote_type;
    +        typedef matrix_vector_binary2<typename E1::const_closure_type, 
    +                                      typename E2::const_closure_type, 
    +                                      matrix_vector_prod2<T1, T2, promote_type> > expression_type;
    +        typedef expression_type result_type; 
    +    };
    +
    +    template<class E1, class E2>
    +    typename matrix_vector_binary2_traits<typename E1::value_type, E1, 
    +                                          typename E2::value_type, E2>::result_type
    +    prod (const vector_expression<E1> &e1, 
    +          const matrix_expression<E2> &e2,
    +          column_major_tag);
    +
    +    // Dispatcher
    +    template<class E1, class E2>
    +    typename matrix_vector_binary2_traits<typename E1::value_type, E1, 
    +                                          typename E2::value_type, E2>::result_type
    +    prod (const vector_expression<E1> &e1, 
    +          const matrix_expression<E2> &e2);
    +
    +    template<class E1, class E2>
    +    typename matrix_vector_binary2_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 vector_expression<E1> &e1, 
    +               const matrix_expression<E2> &e2,
    +               column_major_tag);
    +
    +    // Dispatcher
    +    template<class E1, class E2>
    +    typename matrix_vector_binary2_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 vector_expression<E1> &e1, 
    +               const matrix_expression<E2> &e2);
    +
    +    template<class V, class E1, class E2>
    +    V
    +    prod (const vector_expression<E1> &e1,
    +          const matrix_expression<E2> &e2);
    +
    +    template<class V, class E1, class E2>
    +    V
    +    prec_prod (const vector_expression<E1> &e1,
    +               const matrix_expression<E2> &e2);
    + +

    Description

    + +

    prod computes the product of the matrix and the +vector expression. prec_prod computes the double +precision product of the matrix and the vector expression.

    + +

    Definition

    + +

    Defined in the header matrix_expression.hpp.

    + +

    Type requirements

    + + +
  • E1 is a model of Matrix Expression or + Vector + Expression.
  • +
  • E2 is a model of Vector Expression + or Matrix + Expression.
  • +
    + +

    Preconditions

    + + +
  • e1 ().size2 () == e2 ().size ()
  • +
  • e1 ().size () == e2 ().size1 ()
  • +
    + +

    Complexity

    + +

    Quadratic depending from the size of the matrix expression.

    + +

    Examples

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    matrix<double > m (3, 3), v (3);
    +    for (int i = 0; i < std::min (m.size1 (), v.size ()); ++ i) {
    +        for (int j = 0; j < m.size2 (); ++ j) 
    +            m (i, j) = 3 * i + j;
    +        v (i) = i
    +    }
    +
    +    std::cout << prod (m, v) << std::endl;
    +    std::cout << prod (v, m) << std::endl;
    +}
    + +

    Triangular Solver

    + +

    Prototypes

    + +
        template<class E1, class E2>
    +    struct matrix_vector_solve_traits {
    +        typedef typename promote_traits<typename E1::value_type, typename E2::value_type>::promote_type promote_type;
    +        typedef vector<promote_type> result_type;
    +    };
    +
    +    template<class E1, class E2>
    +    void inplace_solve (const matrix_expression<E1> &e1, 
    +                        E2 &e2,
    +                        lower_tag,
    +                        vector_tag);
    +    template<class E1, class E2>
    +    void inplace_solve (const matrix_expression<E1> &e1, 
    +                        E2 &e2,
    +                        upper_tag,
    +                        vector_tag);
    +    template<class E1, class E2>
    +    void inplace_solve (const matrix_expression<E1> &e1, 
    +                        E2 &e2,
    +                        unit_lower_tag,
    +                        vector_tag);
    +    template<class E1, class E2>
    +    void inplace_solve (const matrix_expression<E1> &e1, 
    +                        E2 &e2,
    +                        unit_upper_tag,
    +                        vector_tag);
    +
    +    template<class E1, class E2, class C>
    +    typename matrix_vector_solve_traits<E1, E2>::result_type
    +    solve (const matrix_expression<E1> &e1, 
    +           const vector_expression<E2> &e2,
    +           C);
    +
    +    template<class E1, class E2>
    +    void inplace_solve (E1 &e1,
    +                        const matrix_expression<E2> &e2, 
    +                        vector_tag, 
    +                        lower_tag);
    +    template<class E1, class E2>
    +    void inplace_solve (E1 &e1,
    +                        const matrix_expression<E2> &e2, 
    +                        vector_tag, 
    +                        upper_tag);
    +    template<class E1, class E2>
    +    void inplace_solve (E1 &e1,
    +                        const matrix_expression<E2> &e2, 
    +                        vector_tag, 
    +                        unit_lower_tag);
    +    template<class E1, class E2>
    +    void inplace_solve (E1 &e1,
    +                        const matrix_expression<E2> &e2, 
    +                        vector_tag, 
    +                        unit_upper_tag);
    +
    +    template<class E1, class E2, class C>
    +    typename matrix_vector_solve_traits<E1, E2>::result_type
    +    solve (const vector_expression<E1> &e1, 
    +           const matrix_expression<E2> &e2,
    +           C);
    + +

    Description

    + +

    solve solves a linear equation for lower or upper +(unit) triangular matrices.

    + +

    Definition

    + +

    Defined in the header triangular.hpp.

    + +

    Type requirements

    + + +
  • E1 is a model of Matrix Expression + or Vector + Expression.
  • +
  • E2 is a model of Vector Expression + or Matrix + Expression.
  • +
    + +

    Preconditions

    + + +
  • e1 ().size1 () == e1 ().size2 ()
  • +
  • e1 ().size2 () == e2 ().size ()
  • +
  • e1 ().size () == e2 ().size1 ()
  • +
  • e2 ().size1 () == e2 ().size2 ()
  • +
    + +

    Complexity

    + +

    Quadratic depending from the size of the matrix expression.

    + +

    Examples

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    matrix<double > m (3, 3), v (3);
    +    for (int i = 0; i < std::min (m.size1 (), v.size ()); ++ i) {
    +        for (int j = 0; j <= i; ++ j) 
    +            m (i, j) = 3 * i + j;
    +        v (i) = i
    +    }
    +
    +    std::cout << solve (m, v, lower_tag ()) << std::endl;
    +    std::cout << solve (v, m, lower_tag ()) << std::endl;
    +}
    + +

    Matrix Matrix +Operations

    + +

    Binary Operation Description

    + +

    Description

    + +

    The templated class matrix_matrix_binary<E1, E2, +F> describes a binary matrix operation.

    + +

    Definition

    + +

    Defined in the header matrix_expression.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    E1 The type of the first matrix expression.  
    E2The type of the second matrix expression.  
    FThe type of the operation. 
    + +

    Model of

    + +

    Matrix Expression. +

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Matrix Expression.

    + +

    Public base classes

    + +

    matrix_expression<matrix_matrix_binary<E1, E2, +F> >.

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    matrix_matrix_binary (const expression1_type + &e1, const expression2_type &e2) Constructs a description of the expression.
    size_type size1 () constReturns the number of rows.
    size_type size2 () constReturns the number of columns.
    const_reference operator () (size_type i, + size_type j) constReturns the value of the j-th element in + the i-th row.
    const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the expression.
    const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the expression.
    const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the expression.
    const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the expression.
    const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed expression.
    const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed expression.
    const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed expression.
    const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed expression.
    + +

    Interface

    + +
        template<class E1, class E2, class F>
    +    class matrix_matrix_binary:
    +        public matrix_expression<matrix_matrix_binary<E1, E2, F> > {
    +    public:
    +        typedef E1 expression1_type;
    +        typedef E2 expression2_type;
    +        typedef F functor_type;
    +        typedef typename promote_traits<typename E1::size_type, typename E2::size_type>::promote_type size_type;
    +        typedef typename promote_traits<typename E1::difference_type, typename E2::difference_type>::promote_type difference_type;
    +        typedef typename F::result_type value_type;
    +        typedef value_type const_reference;
    +        typedef const_reference reference;
    +        typedef const value_type *const_pointer;
    +        typedef const_pointer pointer;
    +        typedef const matrix_matrix_binary<E1, E2, F> const_closure_type;
    +        typedef unknown_orientation_tag orientation_category;
    +        typedef typename E1::const_iterator1 const_iterator11_type;
    +        typedef typename E1::const_iterator2 const_iterator12_type;
    +        typedef typename E2::const_iterator1 const_iterator21_type;
    +        typedef typename E2::const_iterator2 const_iterator22_type;
    +        typedef unknown_storage_tag storage_category;
    +
    +        // Construction and destruction
    +        matrix_matrix_binary ();
    +        matrix_matrix_binary (const expression1_type &e1, const expression2_type &e2);
    +
    +        // Accessors
    +        size_type size1 () const;
    +        size_type size2 () const;
    +        const expression1_type &expression1 () const;
    +        const expression2_type &expression2 () const;
    +
    +        // Element access
    +        const_reference operator () (size_type i, size_type j) const;
    +
    +        class const_iterator1;
    +        typedef const_iterator1 iterator1;
    +        class const_iterator2;
    +        typedef const_iterator2 iterator2;
    +        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
    +        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
    +
    +        // Element lookup
    +        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
    +        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
    +        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
    +        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
    +
    +        // Iterators simply are pointers.
    +
    +        class const_iterator1:
    +            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, 
    +                                             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;
    +            typedef typename matrix_matrix_binary::const_reference reference;
    +            typedef typename matrix_matrix_binary::const_pointer pointer;
    +            typedef const_iterator2 dual_iterator_type;
    +            typedef const_reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator1 ();
    +            const_iterator1 (const matrix_matrix_binary &mmb, const const_iterator11_type &it1, const const_iterator22_type &it2);
    +
    +            // Random access specialization
    +            value_type dereference (dense_random_access_iterator_tag) const;
    +
    +            // Packed bidirectional specialization
    +            value_type dereference (packed_bidirectional_iterator_tag) const;
    +
    +            // Sparse bidirectional specialization
    +            value_type dereference (sparse_bidirectional_iterator_tag) const;
    +
    +            // Arithmetic
    +            const_iterator1 &operator ++ ();
    +            const_iterator1 &operator -- ();
    +            const_iterator1 &operator += (difference_type n);
    +            const_iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator2 begin () const;
    +            const_iterator2 end () const;
    +            const_reverse_iterator2 rbegin () const;
    +            const_reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator1 &operator = (const const_iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator1 &it) const;
    +            bool operator <(const const_iterator1 &it) const;
    +        };
    +
    +        const_iterator1 begin1 () const;
    +        const_iterator1 end1 () const;
    +
    +        class const_iterator2:
    +            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, 
    +                                             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;
    +            typedef typename matrix_matrix_binary::const_reference reference;
    +            typedef typename matrix_matrix_binary::const_pointer pointer;
    +            typedef const_iterator1 dual_iterator_type;
    +            typedef const_reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator2 ();
    +            const_iterator2 (const matrix_matrix_binary &mmb, const const_iterator11_type &it1, const const_iterator22_type &it2);
    +
    +            // Random access specialization
    +            value_type dereference (dense_random_access_iterator_tag) const;
    +
    +            // Packed bidirectional specialization
    +            value_type dereference (packed_bidirectional_iterator_tag) const;
    +
    +            // Sparse bidirectional specialization
    +            value_type dereference (sparse_bidirectional_iterator_tag) const;
    +
    +            // Arithmetic
    +            const_iterator2 &operator ++ ();
    +            const_iterator2 &operator -- ();
    +            const_iterator2 &operator += (difference_type n);
    +            const_iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator1 begin () const;
    +            const_iterator1 end () const;
    +            const_reverse_iterator1 rbegin () const;
    +            const_reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator2 &operator = (const const_iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator2 &it) const;
    +            bool operator <(const const_iterator2 &it) const;
    +        };
    +
    +        const_iterator2 begin2 () const;
    +        const_iterator2 end2 () const;
    +
    +        // Reverse iterators
    +
    +        const_reverse_iterator1 rbegin1 () const;
    +        const_reverse_iterator1 rend1 () const;
    +
    +        const_reverse_iterator2 rbegin2 () const;
    +        const_reverse_iterator2 rend2 () const;
    +    };
    + +

    Binary Operations

    + +

    Prototypes

    + +
        template<class T1, class E1, class T2, class E2>
    +    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, 
    +                                     matrix_matrix_prod<T1, T2, promote_type> > expression_type;
    +        typedef expression_type result_type; 
    +    };
    +
    +    template<class E1, class E2>
    +    typename matrix_matrix_binary_traits<typename E1::value_type, E1, 
    +                                         typename E2::value_type, E2>::result_type
    +    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 E2::value_type, E2>::result_type
    +    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 type_traits<typename E2::value_type>::precision_type, E2>::result_type
    +    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 type_traits<typename E2::value_type>::precision_type, E2>::result_type
    +    prec_prod (const matrix_expression<E1> &e1, 
    +               const matrix_expression<E2> &e2);
    +
    +    template<class M, class E1, class E2>
    +    M
    +    prod (const matrix_expression<E1> &e1,
    +          const matrix_expression<E2> &e2);
    +
    +    template<class M, class E1, class E2>
    +    M
    +    prec_prod (const matrix_expression<E1> &e1,
    +               const matrix_expression<E2> &e2);
    + +

    Description

    + +

    prod computes the product of the matrix +expressions. prec_prod computes the double precision +product of the matrix expressions.

    + +

    Definition

    + +

    Defined in the header matrix_expression.hpp.

    + +

    Type requirements

    + + +
  • E1 is a model of Matrix Expression. +
  • +
  • E2 is a model of Matrix Expression.
  • +
    + +

    Preconditions

    + + +
  • e1 ().size2 () == e2 ().size1 ()
  • +
    + +

    Complexity

    + +

    Cubic depending from the size of the matrix expression.

    + +

    Examples

    + +
    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) 
    +            m1 (i, j) = m2 (i, j) = 3 * i + j;
    +
    +    std::cout << prod (m1, m2) << std::endl;
    +}
    + +

    Triangular Solvers

    + +

    Prototypes

    + +
        template<class E1, class E2>
    +    struct matrix_matrix_solve_traits {
    +        typedef typename promote_traits<typename E1::value_type, typename E2::value_type>::promote_type promote_type;
    +        typedef matrix<promote_type> result_type;
    +    };
    +
    +    template<class E1, class E2>
    +    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, 
    +                        E2 &e2,
    +                        upper_tag,
    +                        matrix_tag);
    +    template<class E1, class E2>
    +    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, 
    +                        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, 
    +           const matrix_expression<E2> &e2,
    +           C);
    + +

    Description

    + +

    solve solves a linear equation for lower or upper +(unit) triangular matrices.

    + +

    Definition

    + +

    Defined in the header triangular.hpp.

    + +

    Type requirements

    + + +
  • E1 is a model of Matrix Expression. +
  • +
  • E2 is a model of Matrix Expression.
  • +
    + +

    Preconditions

    + + +
  • e1 ().size1 () == e1 ().size2 ()
  • +
  • e1 ().size2 () == e2 ().size1 ()
  • +
    + +

    Complexity

    + +

    Cubic depending from the size of the matrix expressions.

    + +

    Examples

    + +
    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) 
    +            m1 (i, j) = m2 (i, j) = 3 * i + j;
    +
    +    std::cout << solve (m1, m2, lower_tag ()) << std::endl;
    +}
    + +
    + +

    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/matrix_proxy.htm b/doc/matrix_proxy.htm new file mode 100644 index 00000000..db5a5590 --- /dev/null +++ b/doc/matrix_proxy.htm @@ -0,0 +1,2727 @@ + + + + + +Matrix Proxies + + + + +

    c++boost.gifMatrix Proxies

    + +

    Matrix Row

    + +

    Description

    + +

    The templated class matrix_row<M> allows +addressing a row of a matrix.

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    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) 
    +            mr (j) = 3 * i + j;
    +        std::cout << mr << std::endl;
    +    }
    +}
    + +

    Definition

    + +

    Defined in the header matrix_proxy.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + +
    Parameter Description Default
    M The type of matrix referenced.  
    + +

    Model of

    + +

    Vector Expression. +

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector Expression.

    + +

    Public base classes

    + +

    vector_expression<matrix_row<M> >

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    matrix_row (matrix_type &data, size_type i)Constructs a sub vector.
    size_type size () constReturns the size of the sub vector.
    const_reference operator () (size_type i) constReturns the value of the i-th element.
    reference operator () (size_type i)Returns a reference of the i-th element. +
    matrix_row &operator = (const matrix_row + &mr)The assignment operator.
    matrix_row &assign_temporary (matrix_row + &mr)Assigns a temporary. May change the matrix row mr.
    template<class AE>
    + matrix_row &operator = (const + vector_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    + matrix_row &assign (const vector_expression<AE> + &ae)
    Assigns a vector expression to the sub vector. Left + and right hand side of the assignment should be + independent.
    template<class AE>
    + matrix_row &operator += (const + vector_expression<AE> &ae)
    A computed assignment operator. Adds the vector + expression to the sub vector.
    template<class AE>
    + matrix_row &plus_assign (const + vector_expression<AE> &ae)
    Adds a vector expression to the sub vector. Left and + right hand side of the assignment should be independent.
    template<class AE>
    + matrix_row &operator -= (const + vector_expression<AE> &ae)
    A computed assignment operator. Subtracts the vector + expression from the sub vector.
    template<class AE>
    + matrix_row &minus_assign (const + vector_expression<AE> &ae)
    Subtracts a vector expression from the sub vector. + Left and right hand side of the assignment should be + independent.
    template<class AT>
    + matrix_row &operator *= (const AT &at)
    A computed assignment operator. Multiplies the sub + vector with a scalar.
    template<class AT>
    + matrix_row &operator /= (const AT &at)
    A computed assignment operator. Divides the sub + vector through a scalar.
    void swap (matrix_row &mr)Swaps the contents of the sub vectors.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the matrix_row.
    const_iterator end () constReturns a const_iterator pointing to the + end of the matrix_row.
    iterator begin () Returns a iterator pointing to the + beginning of the matrix_row.
    iterator end () Returns a iterator pointing to the end + of the matrix_row.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed matrix_row. +
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed matrix_row. +
    reverse_iterator rbegin () Returns a reverse_iterator pointing to + the beginning of the reversed matrix_row.
    reverse_iterator rend () Returns a reverse_iterator pointing to + the end of the reversed matrix_row.
    + +

    Interface

    + +
        // Matrix based row vector class
    +    template<class M>
    +    class matrix_row:
    +        public vector_expression<matrix_row<M> > {
    +    public:      
    +        typedef const M const_matrix_type;
    +        typedef M matrix_type;
    +        typedef typename M::size_type size_type;
    +        typedef typename M::difference_type difference_type;
    +        typedef typename M::value_type value_type;
    +        typedef typename M::const_reference const_reference;
    +        typedef typename M::reference reference;
    +        typedef typename M::const_pointer const_pointer;
    +        typedef typename M::pointer pointer;
    +        typedef const vector_const_reference<const matrix_row<matrix_type> > const_closure_type;
    +        typedef vector_reference<matrix_row<matrix_type> > closure_type;
    +        typedef typename M::const_iterator2 const_iterator_type;
    +        typedef typename M::iterator2 iterator_type;
    +        typedef typename storage_restrict_traits<typename M::storage_category,
    +                                                 dense_proxy_tag>::storage_category storage_category;
    +
    +        // Construction and destruction
    +        matrix_row ();
    +        matrix_row (matrix_type &data, size_type i);
    +
    +        // Accessors
    +        size_type size () const;
    +        const_matrix_type &data () const;
    +        matrix_type &data ();
    +
    +
    +        // Element access
    +        const_reference operator () (size_type j) const;
    +        reference operator () (size_type j);
    +
    +        const_reference operator [] (size_type j) const;
    +        reference operator [] (size_type j);
    +
    +        // Assignment
    +        matrix_row &operator = (const matrix_row &mr);
    +        matrix_row &assign_temporary (matrix_row &mr);
    +        template<class AE>
    +        matrix_row &operator = (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_row &assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_row &operator += (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_row &plus_assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_row &operator -= (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_row &minus_assign (const vector_expression<AE> &ae);
    +        template<class AT>
    +        matrix_row &operator *= (const AT &at);
    +        template<class AT>
    +        matrix_row &operator /= (const AT &at);
    +
    +        // Swapping
    +        void swap (matrix_row &mr);
    +        friend void swap (matrix_row &mr1, matrix_row &mr2);
    +
    +        class const_iterator;
    +        class iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type j) const;
    +        iterator find_first (size_type j);
    +        const_iterator find_last (size_type j) const;
    +        iterator find_last (size_type j);
    +
    +        // Iterators simply are pointers.
    +
    +        class const_iterator:
    +            public container_const_reference<matrix_row>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef typename M::const_iterator2::iterator_category iterator_category;
    +            typedef typename M::const_iterator2::difference_type difference_type;
    +            typedef typename M::const_iterator2::value_type value_type;
    +            typedef typename M::const_iterator2::reference reference;
    +            typedef typename M::const_iterator2::pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const matrix_row &mr, const const_iterator_type &it);
    +            const_iterator (const iterator &it);
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +            bool operator <(const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        class iterator:
    +            public container_reference<matrix_row>,
    +            public random_access_iterator_base<iterator, value_type> {
    +        public:
    +            typedef typename M::iterator2::iterator_category iterator_category;
    +            typedef typename M::iterator2::difference_type difference_type;
    +            typedef typename M::iterator2::value_type value_type;
    +            typedef typename M::iterator2::reference reference;
    +            typedef typename M::iterator2::pointer pointer;
    +
    +            // Construction and destruction
    +            iterator ();
    +            iterator (matrix_row &mr, const iterator_type &it);
    +
    +            // Arithmetic
    +            iterator &operator ++ ();
    +            iterator &operator -- ();
    +            iterator &operator += (difference_type n);
    +            iterator &operator -= (difference_type n);
    +            difference_type operator - (const iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            iterator &operator = (const iterator &it);
    +
    +            // Comparison
    +            bool operator == (const iterator &it) const;
    +            bool operator <(const iterator &it) const;
    +        };
    +
    +        iterator begin ();
    +        iterator end ();
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +
    +        typedef reverse_iterator_base<iterator> reverse_iterator;
    +
    +        reverse_iterator rbegin ();
    +        reverse_iterator rend ();
    +    };
    + +

    Projections

    + +

    Prototypes

    + +
        template<class M>
    +    matrix_row<M> row (M &data, std::size_t i);
    +    template<class M>
    +    const matrix_row<const M> row (const M &data, std::size_t i);
    + +

    Description

    + +

    The free row functions support the construction +of matrix rows.

    + +

    Definition

    + +

    Defined in the header matrix_proxy.hpp.

    + +

    Type requirements

    + + +
  • M is a model of Matrix Expression.
  • +
    + +

    Preconditions

    + +
      +
    • i < data.size1 ()
    • +
    + +

    Complexity

    + +

    Linear depending from the size of the row.

    + +

    Examples

    + +
    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) 
    +            row (m, i) (j) = 3 * i + j;
    +        std::cout << row (m, i) << std::endl;
    +    }
    +}
    + +

    Matrix Column

    + +

    Description

    + +

    The templated class matrix_column<M> allows +addressing a column of a matrix.

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    matrix<double> m (3, 3);
    +    for (int j = 0; j < m.size2 (); ++ j) {
    +        matrix_column<matrix<double> > mc (m, j);
    +        for (int i = 0; i < mc.size (); ++ i)
    +            mc (i) = 3 * i + j;
    +        std::cout << mc << std::endl;
    +    }
    +}
    + +

    Definition

    + +

    Defined in the header matrix_proxy.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + +
    Parameter Description Default
    M The type of matrix referenced.  
    + +

    Model of

    + +

    Vector Expression. +

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector Expression.

    + +

    Public base classes

    + +

    vector_expression<matrix_column<M> >

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    matrix_column (matrix_type &data, size_type + j)Constructs a sub vector.
    size_type size () constReturns the size of the sub vector.
    const_reference operator () (size_type i) constReturns the value of the i-th element.
    reference operator () (size_type i)Returns a reference of the i-th element. +
    matrix_column &operator = (const + matrix_column &mc)The assignment operator.
    matrix_column &assign_temporary + (matrix_column &mc)Assigns a temporary. May change the matrix column mc.
    template<class AE>
    + matrix_column &operator = (const + vector_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    + matrix_column &assign (const + vector_expression<AE> &ae)
    Assigns a vector expression to the sub vector. Left + and right hand side of the assignment should be + independent.
    template<class AE>
    + matrix_column &operator += (const + vector_expression<AE> &ae)
    A computed assignment operator. Adds the vector + expression to the sub vector.
    template<class AE>
    + matrix_column &plus_assign (const + vector_expression<AE> &ae)
    Adds a vector expression to the sub vector. Left and + right hand side of the assignment should be independent.
    template<class AE>
    + matrix_column &operator -= (const + vector_expression<AE> &ae)
    A computed assignment operator. Subtracts the vector + expression from the sub vector.
    template<class AE>
    + matrix_column &minus_assign (const + vector_expression<AE> &ae)
    Subtracts a vector expression from the sub vector. + Left and right hand side of the assignment should be + independent.
    template<class AT>
    + matrix_column &operator *= (const AT &at)
    A computed assignment operator. Multiplies the sub + vector with a scalar.
    template<class AT>
    + matrix_column &operator /= (const AT &at)
    A computed assignment operator. Divides the sub + vector through a scalar.
    void swap (matrix_column &mc)Swaps the contents of the sub vectors.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the matrix_column.
    const_iterator end () constReturns a const_iterator pointing to the + end of the matrix_column.
    iterator begin () Returns a iterator pointing to the + beginning of the matrix_column.
    iterator end () Returns a iterator pointing to the end + of the matrix_column.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed matrix_column. +
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed matrix_column. +
    reverse_iterator rbegin () Returns a reverse_iterator pointing to + the beginning of the reversed matrix_column. +
    reverse_iterator rend () Returns a reverse_iterator pointing to + the end of the reversed matrix_column.
    + +

    Interface

    + +
        // Matrix based column vector class
    +    template<class M>
    +    class matrix_column:
    +        public vector_expression<matrix_column<M> > {
    +    public:      
    +        typedef const M const_matrix_type;
    +        typedef M matrix_type;
    +        typedef typename M::size_type size_type;
    +        typedef typename M::difference_type difference_type;
    +        typedef typename M::value_type value_type;
    +        typedef typename M::const_reference const_reference;
    +        typedef typename M::reference reference;
    +        typedef typename M::const_pointer const_pointer;
    +        typedef typename M::pointer pointer;
    +        typedef const vector_const_reference<const matrix_column<matrix_type> > const_closure_type;
    +        typedef vector_reference<matrix_column<matrix_type> > closure_type;
    +        typedef typename M::const_iterator1 const_iterator_type;
    +        typedef typename M::iterator1 iterator_type;
    +        typedef typename storage_restrict_traits<typename M::storage_category,
    +                                                 dense_proxy_tag>::storage_category storage_category;
    +
    +        // Construction and destruction
    +        matrix_column ();
    +        matrix_column (matrix_type &data, size_type j);
    +
    +        // Accessors
    +        size_type size () const;
    +        const_matrix_type &data () const;
    +        matrix_type &data ();
    +
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +        reference operator () (size_type i);
    +
    +        const_reference operator [] (size_type i) const;
    +        reference operator [] (size_type i);
    +
    +        // Assignment
    +        matrix_column &operator = (const matrix_column &mc);
    +        matrix_column &assign_temporary (matrix_column &mc);
    +        template<class AE>
    +        matrix_column &operator = (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_column &assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_column &operator += (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_column &plus_assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_column &operator -= (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_column &minus_assign (const vector_expression<AE> &ae);
    +        template<class AT>
    +        matrix_column &operator *= (const AT &at);
    +        template<class AT>
    +        matrix_column &operator /= (const AT &at);
    +
    +        // Swapping
    +        void swap (matrix_column &mc);
    +        friend void swap (matrix_column &mc1, matrix_column &mc2);
    +
    +        class const_iterator;
    +        class iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type i) const;
    +        iterator find_first (size_type i);
    +        const_iterator find_last (size_type i) const;
    +        iterator find_last (size_type i);
    +
    +        // Iterators simply are pointers.
    +
    +        class const_iterator:
    +            public container_const_reference<matrix_column>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef typename M::const_iterator1::iterator_category iterator_category;
    +            typedef typename M::const_iterator1::difference_type difference_type;
    +            typedef typename M::const_iterator1::value_type value_type;
    +            typedef typename M::const_iterator1::reference reference;
    +            typedef typename M::const_iterator1::pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const matrix_column &mc, const const_iterator_type &it);
    +            const_iterator (const iterator &it);
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +            bool operator <(const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        class iterator:
    +            public container_reference<matrix_column>,
    +            public random_access_iterator_base<iterator, value_type> {
    +        public:
    +            typedef typename M::iterator1::iterator_category iterator_category;
    +            typedef typename M::iterator1::difference_type difference_type;
    +            typedef typename M::iterator1::value_type value_type;
    +            typedef typename M::iterator1::reference reference;
    +            typedef typename M::iterator1::pointer pointer;
    +
    +            // Construction and destruction
    +            iterator ();
    +            iterator (matrix_column &mc, const iterator_type &it);
    +
    +            // Arithmetic
    +            iterator &operator ++ ();
    +            iterator &operator -- ();
    +            iterator &operator += (difference_type n);
    +            iterator &operator -= (difference_type n);
    +            difference_type operator - (const iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            iterator &operator = (const iterator &it);
    +
    +            // Comparison
    +            bool operator == (const iterator &it) const;
    +            bool operator <(const iterator &it) const;
    +        };
    +
    +        iterator begin ();
    +        iterator end ();
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +
    +        typedef reverse_iterator_base<iterator> reverse_iterator;
    +
    +        reverse_iterator rbegin ();
    +        reverse_iterator rend ();
    +    };
    + +

    Projections

    + +

    Prototypes

    + +
        template<class M>
    +    matrix_column<M> column (M &data, std::size_t j);
    +    template<class M>
    +    const matrix_column<const M> column (const M &data, std::size_t j);
    + +

    Description

    + +

    The free column functions support the +construction of matrix columns.

    + +

    Definition

    + +

    Defined in the header matrix_proxy.hpp.

    + +

    Type requirements

    + + +
  • M is a model of Matrix Expression.
  • +
    + +

    Preconditions

    + +
      +
    • j < data.size2 ()
    • +
    + +

    Complexity

    + +

    Linear depending from the size of the column.

    + +

    Examples

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    matrix<double> m (3, 3);
    +    for (int j = 0; j < m.size2 (); ++ j) {
    +        for (int i = 0; i < m.size1 (); ++ i)
    +            column (m, j) (i) = 3 * i + j;
    +        std::cout << column (m, j) << std::endl;
    +    }
    +}
    + +

    Vector Range

    + +

    Description

    + +

    The templated class matrix_vector_range<M> allows +addressing a sub vector of a matrix.

    + +

    Example

    + +
    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) 
    +            m (i, j) = 3 * i + j;
    +
    +    matrix_vector_range<matrix<double> > mvr (m, range (0, 3), range (0, 3));
    +    std::cout << mvr << std::endl;
    +}
    + +

    Definition

    + +

    Defined in the header matrix_proxy.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + +
    Parameter Description Default
    M The type of matrix referenced.  
    + +

    Model of

    + +

    Vector Expression.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector Expression.

    + +

    Public base classes

    + +

    vector_expression<matrix_vector_range<M> > +

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    matrix_vector_range (matrix_type &data,
    +  const range &r1, const range &r2)
    Constructs a sub vector.
    size_type size () constReturns the size of the sub vector.
    const_reference operator () (size_type i) constReturns the value of the i-th element.
    reference operator () (size_type i)Returns a reference of the i-th element. +
    matrix_vector_range &operator = (const + matrix_vector_range &mvr)The assignment operator.
    matrix_vector_range &assign_temporary + (matrix_vector_range &mvr)Assigns a temporary. May change the matrix vector + range mvr.
    template<class AE>
    + matrix_vector_range &operator = (const + vector_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    + matrix_vector_range &assign (const + vector_expression<AE> &ae)
    Assigns a vector expression to the sub vector. Left + and right hand side of the assignment should be + independent.
    template<class AE>
    + matrix_vector_range &operator += (const + vector_expression<AE> &ae)
    A computed assignment operator. Adds the vector + expression to the sub vector.
    template<class AE>
    + matrix_vector_range &plus_assign (const + vector_expression<AE> &ae)
    Adds a vector expression to the sub vector. Left and + right hand side of the assignment should be independent.
    template<class AE>
    + matrix_vector_range &operator -= (const + vector_expression<AE> &ae)
    A computed assignment operator. Subtracts the vector + expression from the sub vector.
    template<class AE>
    + matrix_vector_range &minus_assign (const + vector_expression<AE> &ae)
    Subtracts a vector expression from the sub vector. + Left and right hand side of the assignment should be + independent.
    template<class AT>
    + matrix_vector_range &operator *= (const AT &at)
    A computed assignment operator. Multiplies the sub + vector with a scalar.
    template<class AT>
    + matrix_vector_range &operator /= (const AT &at)
    A computed assignment operator. Divides the sub + vector through a scalar.
    void swap (matrix_vector_range &mvr)Swaps the contents of the sub vectors.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the matrix_vector_range.
    const_iterator end () constReturns a const_iterator pointing to the + end of the matrix_vector_range.
    iterator begin () Returns a iterator pointing to the + beginning of the matrix_vector_range.
    iterator end () Returns a iterator pointing to the end + of the matrix_vector_range.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the matrix_vector_range. +
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed matrix_vector_range. +
    reverse_iterator rbegin () Returns a reverse_iterator pointing to + the beginning of the reversed matrix_vector_range. +
    reverse_iterator rend () Returns a reverse_iterator pointing to + the end of the reversed matrix_vector_range. +
    + +

    Interface

    + +
        // Matrix based vector range class
    +    template<class M>
    +    class matrix_vector_range:
    +        public vector_expression<matrix_vector_range<M> > {
    +    public:      
    +        typedef const M const_matrix_type;
    +        typedef M matrix_type;
    +        typedef typename M::size_type size_type;
    +        typedef typename M::difference_type difference_type;
    +        typedef typename M::value_type value_type;
    +        typedef typename M::const_reference const_reference;
    +        typedef typename M::reference reference;
    +        typedef typename M::const_pointer const_pointer;
    +        typedef typename M::pointer pointer;
    +        typedef const vector_const_reference<const matrix_vector_range<matrix_type> > const_closure_type;
    +        typedef vector_reference<matrix_vector_range<matrix_type> > closure_type;
    +        typedef range::const_iterator const_iterator1_type;
    +        typedef range::const_iterator iterator1_type;
    +        typedef range::const_iterator const_iterator2_type;
    +        typedef range::const_iterator iterator2_type;
    +        typedef typename storage_restrict_traits<typename M::storage_category,
    +                                                 dense_proxy_tag>::storage_category storage_category;
    +
    +        // Construction and destruction
    +        matrix_vector_range ();
    +        matrix_vector_range (matrix_type &data, const range &r1, const range &r2);
    +
    +        // Accessors
    +        size_type size () const;
    +        const_matrix_type &data () const;
    +        matrix_type &data ();
    +
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +        reference operator () (size_type i);
    +
    +        const_reference operator [] (size_type i) const;
    +        reference operator [] (size_type i);
    +
    +        // Assignment
    +        matrix_vector_range &operator = (const matrix_vector_range &mvr);
    +        matrix_vector_range &assign_temporary (matrix_vector_range &mvr);
    +        template<class AE>
    +        matrix_vector_range &operator = (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_vector_range &assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_vector_range &operator += (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_vector_range &plus_assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_vector_range &operator -= (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_vector_range &minus_assign (const vector_expression<AE> &ae);
    +        template<class AT>
    +        matrix_vector_range &operator *= (const AT &at);
    +        template<class AT>
    +        matrix_vector_range &operator /= (const AT &at);
    +
    +        // Swapping
    +        void swap (matrix_vector_range &mvr);
    +        friend void swap (matrix_vector_range &mvr1, matrix_vector_range &mvr2);
    +
    +        class const_iterator;
    +        class iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type i) const;
    +        iterator find_first (size_type i);
    +        const_iterator find_last (size_type i) const;
    +        iterator find_last (size_type i);
    +
    +        // Iterators simply are indices.
    +
    +        class const_iterator:
    +            public container_const_reference<matrix_vector_range>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef typename restrict_traits<typename M::const_iterator1::iterator_category,
    +                                             typename M::const_iterator2::iterator_category>::iterator_category iterator_category; 
    +            typedef typename matrix_vector_range::difference_type difference_type;
    +            typedef typename matrix_vector_range::value_type value_type;
    +            typedef typename matrix_vector_range::const_reference reference;
    +            typedef typename matrix_vector_range::const_pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const matrix_vector_range &mvr, const const_iterator1_type &it1, const const_iterator2_type &it2);
    +            const_iterator (const iterator &it);
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type  index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +            bool operator <(const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        class iterator:
    +            public container_reference<matrix_vector_range>,
    +            public random_access_iterator_base<iterator, value_type> {
    +        public:
    +            typedef typename restrict_traits<typename M::iterator1::iterator_category,
    +                                             typename M::iterator2::iterator_category>::iterator_category iterator_category; 
    +            typedef typename matrix_vector_range::difference_type difference_type;
    +            typedef typename matrix_vector_range::value_type value_type;
    +            typedef typename matrix_vector_range::reference reference;
    +            typedef typename matrix_vector_range::pointer pointer;
    +
    +            // Construction and destruction
    +            iterator ();
    +            iterator (matrix_vector_range &mvr, const iterator1_type &it1, const iterator2_type &it2);
    +
    +            // Arithmetic
    +            iterator &operator ++ ();
    +            iterator &operator -- ();
    +            iterator &operator += (difference_type n);
    +            iterator &operator -= (difference_type n);
    +            difference_type operator - (const iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            iterator &operator = (const iterator &it);
    +
    +            // Comparison
    +            bool operator == (const iterator &it) const;
    +            bool operator <(const iterator &it) const;
    +        };
    +
    +        iterator begin ();
    +        iterator end ();
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +
    +        typedef reverse_iterator_base<iterator> reverse_iterator;
    +
    +        reverse_iterator rbegin ();
    +        reverse_iterator rend ();
    +    };
    + +

    Vector Slice

    + +

    Description

    + +

    The templated class matrix_vector_slice<M> allows +addressing a sliced sub vector of a matrix.

    + +

    Example

    + +
    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) 
    +            m (i, j) = 3 * i + j;
    +
    +    matrix_vector_range<matrix<double> > mvs (m, slice (0, 1, 3), slice (0, 1, 3));
    +    std::cout << mvs << std::endl;
    +}
    + +

    Definition

    + +

    Defined in the header matrix_proxy.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + +
    Parameter Description Default
    M The type of matrix referenced.  
    + +

    Model of

    + +

    Vector Expression.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector Expression.

    + +

    Public base classes

    + +

    vector_expression<matrix_vector_slice<M> > +

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    matrix_vector_slice (matrix_type &data,
    +  const slice &s1, const slice &s2)
    Constructs a sub vector.
    size_type size () constReturns the size of the sub vector.
    const_reference operator () (size_type i) constReturns the value of the i-th element.
    reference operator () (size_type i)Returns a reference of the i-th element. +
    matrix_vector_slice &operator = (const + matrix_vector_slice &mvs)The assignment operator.
    matrix_vector_slice &assign_temporary + (matrix_vector_slice &mvs)Assigns a temporary. May change the matrix vector + slice vs.
    template<class AE>
    + matrix_vector_slice &operator = (const + vector_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    + matrix_vector_slice &assign (const + vector_expression<AE> &ae)
    Assigns a vector expression to the sub vector. Left + and right hand side of the assignment should be + independent.
    template<class AE>
    + matrix_vector_slice &operator += (const + vector_expression<AE> &ae)
    A computed assignment operator. Adds the vector + expression to the sub vector.
    template<class AE>
    + matrix_vector_slice &plus_assign (const + vector_expression<AE> &ae)
    Adds a vector expression to the sub vector. Left and + right hand side of the assignment should be independent.
    template<class AE>
    + matrix_vector_slice &operator -= (const + vector_expression<AE> &ae)
    A computed assignment operator. Subtracts the vector + expression from the sub vector.
    template<class AE>
    + matrix_vector_slice &minus_assign (const + vector_expression<AE> &ae)
    Subtracts a vector expression from the sub vector. + Left and right hand side of the assignment should be + independent.
    template<class AT>
    + matrix_vector_slice &operator *= (const AT &at)
    A computed assignment operator. Multiplies the sub + vector with a scalar.
    template<class AT>
    + matrix_vector_slice &operator /= (const AT &at)
    A computed assignment operator. Divides the sub + vector through a scalar.
    void swap (matrix_vector_slice &mvs)Swaps the contents of the sub vectors.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the matrix_vector_slice.
    const_iterator end () constReturns a const_iterator pointing to the + end of the matrix_vector_slice.
    iterator begin () Returns a iterator pointing to the + beginning of the matrix_vector_slice.
    iterator end () Returns a iterator pointing to the end + of the matrix_vector_slice.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed matrix_vector_slice. +
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed matrix_vector_slice. +
    reverse_iterator rbegin () Returns a reverse_iterator pointing to + the beginning of the reversed matrix_vector_slice. +
    reverse_iterator rend () Returns a reverse_iterator pointing to + the end of the reversed matrix_vector_slice. +
    + +

    Interface

    + +
        // Matrix based vector slice class
    +    template<class M>
    +    class matrix_vector_slice:
    +        public vector_expression<matrix_vector_slice<M> > {
    +    public:      
    +        typedef const M const_matrix_type;
    +        typedef M matrix_type;
    +        typedef typename M::size_type size_type;
    +        typedef typename M::difference_type difference_type;
    +        typedef typename M::value_type value_type;
    +        typedef typename M::const_reference const_reference;
    +        typedef typename M::reference reference;
    +        typedef typename M::const_pointer const_pointer;
    +        typedef typename M::pointer pointer;
    +        typedef const vector_const_reference<const matrix_vector_slice<matrix_type> > const_closure_type;
    +        typedef vector_reference<matrix_vector_slice<matrix_type> > closure_type;
    +        typedef slice::const_iterator const_iterator1_type;
    +        typedef slice::const_iterator iterator1_type;
    +        typedef slice::const_iterator const_iterator2_type;
    +        typedef slice::const_iterator iterator2_type;
    +        typedef typename storage_restrict_traits<typename M::storage_category,
    +                                                 dense_proxy_tag>::storage_category storage_category;
    +
    +        // Construction and destruction
    +        matrix_vector_slice ();
    +        matrix_vector_slice (matrix_type &data, const slice &s1, const slice &s2);
    +
    +        // Accessors
    +        size_type size () const;
    +        const_matrix_type &data () const;
    +        matrix_type &data ();
    +
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +        reference operator () (size_type i);
    +
    +        const_reference operator [] (size_type i) const;
    +        reference operator [] (size_type i);
    +
    +        // Assignment
    +        matrix_vector_slice &operator = (const matrix_vector_slice &mvs);
    +        matrix_vector_slice &assign_temporary (matrix_vector_slice &mvs);
    +        template<class AE>
    +        matrix_vector_slice &operator = (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_vector_slice &assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_vector_slice &operator += (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_vector_slice &plus_assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_vector_slice &operator -= (const vector_expression<AE> &ae);
    +        template<class AE>
    +        matrix_vector_slice &minus_assign (const vector_expression<AE> &ae);
    +        template<class AT>
    +        matrix_vector_slice &operator *= (const AT &at);
    +        template<class AT>
    +        matrix_vector_slice &operator /= (const AT &at);
    +
    +        // Swapping
    +        void swap (matrix_vector_slice &mvs);
    +        friend void swap (matrix_vector_slice &mvs1, matrix_vector_slice &mvs2);
    +
    +        class const_iterator;
    +        class iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type i) const;
    +        iterator find_first (size_type i);
    +        const_iterator find_last (size_type i) const;
    +        iterator find_last (size_type i);
    +
    +        // Iterators simply are indices.
    +
    +        class const_iterator:
    +            public container_const_reference<matrix_vector_slice>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef typename restrict_traits<typename M::const_iterator1::iterator_category,
    +                                             typename M::const_iterator2::iterator_category>::iterator_category iterator_category; 
    +            typedef typename matrix_vector_slice::difference_type difference_type;
    +            typedef typename matrix_vector_slice::value_type value_type;
    +            typedef typename matrix_vector_slice::const_reference reference;
    +            typedef typename matrix_vector_slice::const_pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const matrix_vector_slice &mvs, const const_iterator1_type &it1, const const_iterator2_type &it2);
    +            const_iterator (const iterator &it);
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type  index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +            bool operator <(const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        class iterator:
    +            public container_reference<matrix_vector_slice>,
    +            public random_access_iterator_base<iterator, value_type> {
    +        public:
    +            typedef typename restrict_traits<typename M::iterator1::iterator_category,
    +                                             typename M::iterator2::iterator_category>::iterator_category iterator_category; 
    +            typedef typename matrix_vector_slice::difference_type difference_type;
    +            typedef typename matrix_vector_slice::value_type value_type;
    +            typedef typename matrix_vector_slice::reference reference;
    +            typedef typename matrix_vector_slice::pointer pointer;
    +
    +            // Construction and destruction
    +            iterator ();
    +            iterator (matrix_vector_slice &mvs, const iterator1_type &it1, const iterator2_type &it2);
    +
    +            // Arithmetic
    +            iterator &operator ++ ();
    +            iterator &operator -- ();
    +            iterator &operator += (difference_type n);
    +            iterator &operator -= (difference_type n);
    +            difference_type operator - (const iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            iterator &operator = (const iterator &it);
    +
    +            // Comparison
    +            bool operator == (const iterator &it) const;
    +            bool operator <(const iterator &it) const;
    +        };
    +
    +        iterator begin ();
    +        iterator end ();
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +
    +        typedef reverse_iterator_base<iterator> reverse_iterator;
    +
    +        reverse_iterator rbegin ();
    +        reverse_iterator rend ();
    +    };
    + +

    Matrix Range

    + +

    Description

    + +

    The templated class matrix_range<M> allows +addressing a sub matrix of a matrix.

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    matrix<double> m (3, 3);
    +    matrix_range<matrix<double> > mr (m, range (0, 3), range (0, 3));
    +    for (int i = 0; i < mr.size1 (); ++ i) 
    +        for (int j = 0; j < mr.size2 (); ++ j) 
    +            mr (i, j) = 3 * i + j;
    +    std::cout << mr << std::endl;
    +}
    + +

    Definition

    + +

    Defined in the header matrix_proxy.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + +
    Parameter Description Default
    M The type of matrix referenced. 
    + +

    Model of

    + +

    Matrix Expression. +

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Matrix Expression.

    + +

    Public base classes

    + +

    matrix_expression<matrix_range<M> >

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    matrix_range (matrix_type &data,
    +  const range &r1, const range &r2)
    Constructs a sub matrix.
    size_type start1 () constReturns the index of the first row.
    size_type size1 () constReturns the number of rows.
    size_type start2 () constReturns the index of the first column.
    size_type size2 () constReturns the number of columns.
    const_reference operator () (size_type i, + size_type j) constReturns the value of the j-th element in + the i-th row.
    reference operator () (size_type i, size_type + j)Returns a reference of the j-th element + in the i-th row.
    matrix_range &operator = (const + matrix_range &mr)The assignment operator.
    matrix_range &assign_temporary + (matrix_range &mr)Assigns a temporary. May change the matrix range mr.
    template<class AE>
    + matrix_range &operator = (const + matrix_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    + matrix_range &assign (const + matrix_expression<AE> &ae)
    Assigns a matrix expression to the sub matrix. Left + and right hand side of the assignment should be + independent.
    template<class AE>
    + matrix_range &operator += (const + matrix_expression<AE> &ae)
    A computed assignment operator. Adds the matrix + expression to the sub matrix.
    template<class AE>
    + matrix_range &plus_assign (const + matrix_expression<AE> &ae)
    Adds a matrix expression to the sub matrix. Left and + right hand side of the assignment should be independent.
    template<class AE>
    + matrix_range &operator -= (const + matrix_expression<AE> &ae)
    A computed assignment operator. Subtracts the matrix + expression from the sub matrix.
    template<class AE>
    + matrix_range &minus_assign (const + matrix_expression<AE> &ae)
    Subtracts a matrix expression from the sub matrix. + Left and right hand side of the assignment should be + independent.
    template<class AT>
    + matrix_range &operator *= (const AT &at)
    A computed assignment operator. Multiplies the sub + matrix with a scalar.
    template<class AT>
    + matrix_range &operator /= (const AT &at)
    A computed assignment operator. Divides the sub + matrix through a scalar.
    void swap (matrix_range &mr)Swaps the contents of the sub matrices.
    const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the matrix_range.
    const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the matrix_range.
    iterator1 begin1 () Returns a iterator1 pointing to the + beginning of the matrix_range.
    iterator1 end1 () Returns a iterator1 pointing to the end + of the matrix_range.
    const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the matrix_range.
    const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the matrix_range.
    iterator2 begin2 () Returns a iterator2 pointing to the + beginning of the matrix_range.
    iterator2 end2 () Returns a iterator2 pointing to the end + of the matrix_range.
    const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed matrix_range. +
    const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed matrix_range. +
    reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to + the beginning of the reversed matrix_range.
    reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to + the end of the reversed matrix_range.
    const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed matrix_range. +
    const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed matrix_range. +
    reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to + the beginning of the reversed matrix_range.
    reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to + the end of reversed the matrix_range.
    + +

    Interface

    + +
        // Matrix based range class
    +    template<class M>
    +    class matrix_range:
    +        public matrix_expression<matrix_range<M> > {
    +    public:      
    +        typedef const M const_matrix_type;
    +        typedef M matrix_type;
    +        typedef typename M::size_type size_type;
    +        typedef typename M::difference_type difference_type;
    +        typedef typename M::value_type value_type;
    +        typedef typename M::const_reference const_reference;
    +        typedef typename M::reference reference;
    +        typedef typename M::const_pointer const_pointer;
    +        typedef typename M::pointer pointer;
    +        typedef const matrix_const_reference<const matrix_range<matrix_type> > const_closure_type;
    +        typedef matrix_reference<matrix_range<matrix_type> > closure_type;
    +        typedef typename M::const_iterator1 const_iterator1_type;
    +        typedef typename M::iterator1 iterator1_type;
    +        typedef typename M::const_iterator2 const_iterator2_type;
    +        typedef typename M::iterator2 iterator2_type;
    +        typedef typename storage_restrict_traits<typename M::storage_category,
    +                                                 dense_proxy_tag>::storage_category storage_category;
    +        typedef typename M::orientation_category orientation_category;
    +
    +        // Construction and destruction
    +        matrix_range ();
    +        matrix_range (matrix_type &data, const range &r1, const range &r2);
    +
    +        // Accessors
    +        size_type start1 () const;
    +        size_type size1 () const;
    +        size_type start2() const;
    +        size_type size2 () const;
    +        const_matrix_type &data () const;
    +        matrix_type &data ();
    +
    +
    +        // Element access
    +        const_reference operator () (size_type i, size_type j) const;
    +        reference operator () (size_type i, size_type j);
    +
    +        matrix_range<matrix_type> project (const range &r1, const range &r2) const;
    +
    +        // Assignment
    +        matrix_range &operator = (const matrix_range &mr);
    +        matrix_range &assign_temporary (matrix_range &mr);
    +        template<class AE>
    +        matrix_range &operator = (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        matrix_range &assign (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        matrix_range& operator += (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        matrix_range &plus_assign (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        matrix_range& operator -= (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        matrix_range &minus_assign (const matrix_expression<AE> &ae);
    +        template<class AT>
    +        matrix_range& operator *= (const AT &at);
    +        template<class AT>
    +        matrix_range& operator /= (const AT &at);
    +
    +        // Swapping
    +        void swap (matrix_range &mr);
    +        friend void swap (matrix_range &mr1, matrix_range &mr2);
    +
    +        class const_iterator1;
    +        class iterator1;
    +        class const_iterator2;
    +        class iterator2;
    +        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
    +        typedef reverse_iterator_base1<iterator1> reverse_iterator1;
    +        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
    +        typedef reverse_iterator_base2<iterator2> reverse_iterator2;
    +
    +        // Element lookup
    +        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
    +        iterator1 find_first1 (int rank, size_type i, size_type j);
    +        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
    +        iterator1 find_last1 (int rank, size_type i, size_type j);
    +        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
    +        iterator2 find_first2 (int rank, size_type i, size_type j);
    +        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
    +        iterator2 find_last2 (int rank, size_type i, size_type j);
    +
    +        // Iterators simply are pointers.
    +
    +        class const_iterator1:
    +            public container_const_reference<matrix_range>,
    +            public random_access_iterator_base<const_iterator1, value_type> {
    +        public:
    +            typedef typename M::const_iterator1::iterator_category iterator_category;
    +            typedef typename M::const_iterator1::difference_type difference_type;
    +            typedef typename M::const_iterator1::value_type value_type;
    +            typedef typename M::const_iterator1::reference reference;
    +            typedef typename M::const_iterator1::pointer pointer;
    +            typedef const_iterator2 dual_iterator_type;
    +            typedef const_reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator1 ();
    +            const_iterator1 (const matrix_range &mr, const const_iterator1_type &it);
    +            const_iterator1 (const iterator1 &it);
    +
    +            // Arithmetic
    +            const_iterator1 &operator ++ ();
    +            const_iterator1 &operator -- ();
    +            const_iterator1 &operator += (difference_type n);
    +            const_iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator2 begin () const;
    +            const_iterator2 end () const;
    +            const_reverse_iterator2 rbegin () const;
    +            const_reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator1 &operator = (const const_iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator1 &it) const;
    +            bool operator <(const const_iterator1 &it) const;
    +        };
    +
    +        const_iterator1 begin1 () const;
    +        const_iterator1 end1 () const;
    +
    +        class iterator1:
    +            public container_reference<matrix_range>,
    +            public random_access_iterator_base<iterator1, value_type> {
    +        public:
    +            typedef typename M::iterator1::iterator_category iterator_category;
    +            typedef typename M::iterator1::difference_type difference_type;
    +            typedef typename M::iterator1::value_type value_type;
    +            typedef typename M::iterator1::reference reference;
    +            typedef typename M::iterator1::pointer pointer;
    +            typedef iterator2 dual_iterator_type;
    +            typedef reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            iterator1 ();
    +            iterator1 (matrix_range &mr, const iterator1_type &it);
    +
    +            // Arithmetic
    +            iterator1 &operator ++ ();
    +            iterator1 &operator -- ();
    +            iterator1 &operator += (difference_type n);
    +            iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            iterator2 begin () const;
    +            iterator2 end () const;
    +            reverse_iterator2 rbegin () const;
    +            reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            iterator1 &operator = (const iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const iterator1 &it) const;
    +            bool operator <(const iterator1 &it) const;
    +        };
    +
    +        iterator1 begin1 ();
    +        iterator1 end1 ();
    +
    +        class const_iterator2:
    +            public container_const_reference<matrix_range>,
    +            public random_access_iterator_base<const_iterator2, value_type> {
    +        public:
    +            typedef typename M::const_iterator2::iterator_category iterator_category;
    +            typedef typename M::const_iterator2::difference_type difference_type;
    +            typedef typename M::const_iterator2::value_type value_type;
    +            typedef typename M::const_iterator2::reference reference;
    +            typedef typename M::const_iterator2::pointer pointer;
    +            typedef const_iterator1 dual_iterator_type;
    +            typedef const_reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator2 ();
    +            const_iterator2 (const matrix_range &mr, const const_iterator2_type &it);
    +            const_iterator2 (const iterator2 &it);
    +
    +            // Arithmetic
    +            const_iterator2 &operator ++ ();
    +            const_iterator2 &operator -- ();
    +            const_iterator2 &operator += (difference_type n);
    +            const_iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator1 begin () const;
    +            const_iterator1 end () const;
    +            const_reverse_iterator1 rbegin () const;
    +            const_reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator2 &operator = (const const_iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator2 &it) const;
    +            bool operator <(const const_iterator2 &it) const;
    +        };
    +
    +        const_iterator2 begin2 () const;
    +        const_iterator2 end2 () const;
    +
    +        class iterator2:
    +            public container_reference<matrix_range>,
    +            public random_access_iterator_base<iterator2, value_type> {
    +        public:
    +            typedef typename M::iterator2::iterator_category iterator_category;
    +            typedef typename M::iterator2::difference_type difference_type;
    +            typedef typename M::iterator2::value_type value_type;
    +            typedef typename M::iterator2::reference reference;
    +            typedef typename M::iterator2::pointer pointer;
    +            typedef iterator1 dual_iterator_type;
    +            typedef reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            iterator2 ();
    +            iterator2 (matrix_range &mr, const iterator2_type &it);
    +
    +            // Arithmetic
    +            iterator2 &operator ++ ();
    +            iterator2 &operator -- ();
    +            iterator2 &operator += (difference_type n);
    +            iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            iterator1 begin () const;
    +            iterator1 end () const;
    +            reverse_iterator1 rbegin () const;
    +            reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            iterator2 &operator = (const iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const iterator2 &it) const;
    +            bool operator <(const iterator2 &it) const;
    +        };
    +
    +        iterator2 begin2 ();
    +        iterator2 end2 ();
    +
    +        // Reverse iterators
    +
    +        const_reverse_iterator1 rbegin1 () const;
    +        const_reverse_iterator1 rend1 () const;
    +
    +        reverse_iterator1 rbegin1 ();
    +        reverse_iterator1 rend1 ();
    +
    +        const_reverse_iterator2 rbegin2 () const;
    +        const_reverse_iterator2 rend2 () const;
    +
    +        reverse_iterator2 rbegin2 ();
    +        reverse_iterator2 rend2 ();
    +    };
    + +

    Projections

    + +

    Prototypes

    + +
        template<class M>
    +    matrix_range<M> project (M &data, const range &r1, const range &r2);
    +    template<class M>
    +    const matrix_range<const M> project (const M &data, const range &r1, const range &r2);
    +    template<class M>
    +    matrix_range<M> project (const matrix_range<M> &data, const range &r1, const range &r2);
    + +

    Description

    + +

    The free project functions support the +construction of matrix ranges.

    + +

    Definition

    + +

    Defined in the header matrix_proxy.hpp.

    + +

    Type requirements

    + + +
  • M is a model of Matrix Expression.
  • +
    + +

    Preconditions

    + +
      +
    • r1.start () + r1.size () <= data.size1 () +
    • +
    • r2.start () + r2.size () <= data.size2 () +
    • +
    + +

    Complexity

    + +

    Quadratic depending from the size of the ranges.

    + +

    Examples

    + +
    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) 
    +            project (m, range (0, 3), range (0, 3)) (i, j) = 3 * i + j;
    +    std::cout << project (m, range (0, 3), range (0, 3)) << std::endl;
    +}
    + +

    Matrix Slice

    + +

    Description

    + +

    The templated class matrix_slice<M> allows +addressing a sliced sub matrix of a matrix.

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    matrix<double> m (3, 3);
    +    matrix_slice<matrix<double> > ms (m, slice (0, 1, 3), slice (0, 1, 3));
    +    for (int i = 0; i < ms.size1 (); ++ i) 
    +        for (int j = 0; j < ms.size2 (); ++ j) 
    +            ms (i, j) = 3 * i + j;
    +    std::cout << ms << std::endl;
    +}
    + +

    Definition

    + +

    Defined in the header matrix_proxy.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + +
    Parameter Description Default
    M The type of matrix referenced. 
    + +

    Model of

    + +

    Matrix Expression.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Matrix Expression.

    + +

    Public base classes

    + +

    matrix_expression<matrix_slice<M> >

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    matrix_slice (matrix_type &data,
    +  const slice &s1, const slice &s2)
    Constructs a sub matrix.
    size_type size1 () constReturns the number of rows.
    size_type size2 () constReturns the number of columns.
    const_reference operator () (size_type i, + size_type j) constReturns the value of the j-th element in + the i-th row.
    reference operator () (size_type i, size_type + j)Returns a reference of the j-th element + in the i-th row.
    matrix_slice &operator = (const + matrix_slice &ms)The assignment operator.
    matrix_slice &assign_temporary + (matrix_slice &ms)Assigns a temporary. May change the matrix slice ms.
    template<class AE>
    + matrix_slice &operator = (const + matrix_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    + matrix_slice &assign (const + matrix_expression<AE> &ae)
    Assigns a matrix expression to the sub matrix. Left + and right hand side of the assignment should be + independent.
    template<class AE>
    + matrix_slice &operator += (const + matrix_expression<AE> &ae)
    A computed assignment operator. Adds the matrix + expression to the sub matrix.
    template<class AE>
    + matrix_slice &plus_assign (const + matrix_expression<AE> &ae)
    Adds a matrix expression to the sub matrix. Left and + right hand side of the assignment should be independent.
    template<class AE>
    + matrix_slice &operator -= (const + matrix_expression<AE> &ae)
    A computed assignment operator. Subtracts the matrix + expression from the sub matrix.
    template<class AE>
    + matrix_slice &minus_assign (const + matrix_expression<AE> &ae)
    Subtracts a matrix expression from the sub matrix. + Left and right hand side of the assignment should be + independent.
    template<class AT>
    + matrix_slice &operator *= (const AT &at)
    A computed assignment operator. Multiplies the sub + matrix with a scalar.
    template<class AT>
    + matrix_slice &operator /= (const AT &at)
    A computed assignment operator. Multiplies the sub + matrix through a scalar.
    void swap (matrix_slice &ms)Swaps the contents of the sub matrices.
    const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the matrix_slice.
    const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the matrix_slice.
    iterator1 begin1 () Returns a iterator1 pointing to the + beginning of the matrix_slice.
    iterator1 end1 () Returns a iterator1 pointing to the end + of the matrix_slice.
    const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the matrix_slice.
    const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the matrix_slice.
    iterator2 begin2 () Returns a iterator2 pointing to the + beginning of the matrix_slice.
    iterator2 end2 () Returns a iterator2 pointing to the end + of the matrix_slice.
    const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed matrix_slice. +
    const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed matrix_slice. +
    reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to + the beginning of the reversed matrix_slice.
    reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to + the end of the reversed matrix_slice.
    const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed matrix_slice. +
    const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed matrix_slice. +
    reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to + the beginning of the reversed matrix_slice.
    reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to + the end of the reversed matrix_slice.
    + +

    Interface

    + +
        // Matrix based slice class
    +    template<class M>
    +    class matrix_slice:
    +        public matrix_expression<matrix_slice<M> > {
    +    public:      
    +        typedef const M const_matrix_type;
    +        typedef M matrix_type;
    +        typedef typename M::size_type size_type;
    +        typedef typename M::difference_type difference_type;
    +        typedef typename M::value_type value_type;
    +        typedef typename M::const_reference const_reference;
    +        typedef typename M::reference reference;
    +        typedef typename M::const_pointer const_pointer;
    +        typedef typename M::pointer pointer;
    +        typedef const matrix_const_reference<const matrix_slice<matrix_type> > const_closure_type;
    +        typedef matrix_reference<matrix_slice<matrix_type> > closure_type;
    +        typedef slice::const_iterator const_iterator1_type;
    +        typedef slice::const_iterator iterator1_type;
    +        typedef slice::const_iterator const_iterator2_type;
    +        typedef slice::const_iterator iterator2_type;
    +        typedef typename storage_restrict_traits<typename M::storage_category,
    +                                                 dense_proxy_tag>::storage_category storage_category;
    +        typedef typename M::orientation_category orientation_category;
    +
    +        // Construction and destruction
    +        matrix_slice ();
    +        matrix_slice (matrix_type &data, const slice &s1, const slice &s2);
    +
    +        // Accessors
    +        size_type size1 () const;
    +        size_type size2 () const;
    +        const_matrix_type &data () const;
    +        matrix_type &data ();
    +
    +        // Element access
    +        const_reference operator () (size_type i, size_type j) const;
    +        reference operator () (size_type i, size_type j);
    +
    +        matrix_slice<matrix_type> project (const range &r1, const range &r2) const;
    +        matrix_slice<matrix_type> project (const slice &s1, const slice &s2) const;
    +
    +        // Assignment
    +        matrix_slice &operator = (const matrix_slice &ms);
    +        matrix_slice &assign_temporary (matrix_slice &ms);
    +        template<class AE>
    +        matrix_slice &operator = (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        matrix_slice &assign (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        matrix_slice& operator += (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        matrix_slice &plus_assign (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        matrix_slice& operator -= (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        matrix_slice &minus_assign (const matrix_expression<AE> &ae);
    +        template<class AT>
    +        matrix_slice& operator *= (const AT &at);
    +        template<class AT>
    +        matrix_slice& operator /= (const AT &at);
    +
    +        // Swapping
    +        void swap (matrix_slice &ms);
    +        friend void swap (matrix_slice &ms1, matrix_slice &ms2);
    +
    +        class const_iterator1;
    +        class iterator1;
    +        class const_iterator2;
    +        class iterator2;
    +        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
    +        typedef reverse_iterator_base1<iterator1> reverse_iterator1;
    +        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
    +        typedef reverse_iterator_base2<iterator2> reverse_iterator2;
    +
    +        // Element lookup
    +        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
    +        iterator1 find_first1 (int rank, size_type i, size_type j);
    +        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
    +        iterator1 find_last1 (int rank, size_type i, size_type j);
    +        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
    +        iterator2 find_first2 (int rank, size_type i, size_type j);
    +        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
    +        iterator2 find_last2 (int rank, size_type i, size_type j);
    +
    +        // Iterators simply are indices.
    +
    +        class const_iterator1:
    +            public container_const_reference<matrix_slice>,
    +            public random_access_iterator_base<const_iterator1, value_type> {
    +        public:
    +            typedef typename M::const_iterator1::iterator_category iterator_category;
    +            typedef typename M::const_iterator1::difference_type difference_type;
    +            typedef typename M::const_iterator1::value_type value_type;
    +            typedef typename M::const_iterator1::reference reference;
    +            typedef typename M::const_iterator1::pointer pointer;
    +            typedef const_iterator2 dual_iterator_type;
    +            typedef const_reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator1 ();
    +            const_iterator1 (const matrix_slice &ms, const const_iterator1_type &it1, const const_iterator2_type &it2);
    +            const_iterator1 (const iterator1 &it);
    +
    +            // Arithmetic
    +            const_iterator1 &operator ++ ();
    +            const_iterator1 &operator -- ();
    +            const_iterator1 &operator += (difference_type n);
    +            const_iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator2 begin () const;
    +            const_iterator2 end () const;
    +            const_reverse_iterator2 rbegin () const;
    +            const_reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator1 &operator = (const const_iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator1 &it) const;
    +            bool operator <(const const_iterator1 &it) const;
    +        };
    +
    +        const_iterator1 begin1 () const;
    +        const_iterator1 end1 () const;
    +
    +        class iterator1:
    +            public container_reference<matrix_slice>,
    +            public random_access_iterator_base<iterator1, value_type> {
    +        public:
    +            typedef typename M::iterator1::iterator_category iterator_category;
    +            typedef typename M::iterator1::difference_type difference_type;
    +            typedef typename M::iterator1::value_type value_type;
    +            typedef typename M::iterator1::reference reference;
    +            typedef typename M::iterator1::pointer pointer;
    +            typedef iterator2 dual_iterator_type;
    +            typedef reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            iterator1 ();
    +            iterator1 (matrix_slice &ms, const iterator1_type &it1, const iterator2_type &it2);
    +
    +            // Arithmetic
    +            iterator1 &operator ++ ();
    +            iterator1 &operator -- ();
    +            iterator1 &operator += (difference_type n);
    +            iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            iterator2 begin () const;
    +            iterator2 end () const;
    +            reverse_iterator2 rbegin () const;
    +            reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            iterator1 &operator = (const iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const iterator1 &it) const;
    +            bool operator <(const iterator1 &it) const;
    +        };
    +
    +        iterator1 begin1 ();
    +        iterator1 end1 ();
    +
    +        class const_iterator2:
    +            public container_const_reference<matrix_slice>,
    +            public random_access_iterator_base<const_iterator2, value_type> {
    +        public:
    +            typedef typename M::const_iterator2::iterator_category iterator_category;
    +            typedef typename M::const_iterator2::difference_type difference_type;
    +            typedef typename M::const_iterator2::value_type value_type;
    +            typedef typename M::const_iterator2::reference reference;
    +            typedef typename M::const_iterator2::pointer pointer;
    +            typedef const_iterator1 dual_iterator_type;
    +            typedef const_reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator2 ();
    +            const_iterator2 (const matrix_slice &ms, const const_iterator1_type &it1, const const_iterator2_type &it2);
    +            const_iterator2 (const iterator2 &it);
    +
    +            // Arithmetic
    +            const_iterator2 &operator ++ ();
    +            const_iterator2 &operator -- ();
    +            const_iterator2 &operator += (difference_type n);
    +            const_iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator1 begin () const;
    +            const_iterator1 end () const;
    +            const_reverse_iterator1 rbegin () const;
    +            const_reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator2 &operator = (const const_iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator2 &it) const;
    +            bool operator <(const const_iterator2 &it) const;
    +        };
    +
    +        const_iterator2 begin2 () const;
    +        const_iterator2 end2 () const;
    +
    +        class iterator2:
    +            public container_reference<matrix_slice>,
    +            public random_access_iterator_base<iterator2, value_type> {
    +        public:
    +            typedef typename M::iterator2::iterator_category iterator_category;
    +            typedef typename M::iterator2::difference_type difference_type;
    +            typedef typename M::iterator2::value_type value_type;
    +            typedef typename M::iterator2::reference reference;
    +            typedef typename M::iterator2::pointer pointer;
    +            typedef iterator1 dual_iterator_type;
    +            typedef reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            iterator2 ();
    +            iterator2 (matrix_slice &ms, const iterator1_type &it1, const iterator2_type &it2);
    +
    +            // Arithmetic
    +            iterator2 &operator ++ ();
    +            iterator2 &operator -- ();
    +            iterator2 &operator += (difference_type n);
    +            iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            iterator1 begin () const;
    +            iterator1 end () const;
    +            reverse_iterator1 rbegin () const;
    +            reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            iterator2 &operator = (const iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const iterator2 &it) const;
    +            bool operator <(const iterator2 &it) const;
    +        };
    +
    +        iterator2 begin2 ();
    +        iterator2 end2 ();
    +
    +        // Reverse iterators
    +
    +        const_reverse_iterator1 rbegin1 () const;
    +        const_reverse_iterator1 rend1 () const;
    +
    +        reverse_iterator1 rbegin1 ();
    +        reverse_iterator1 rend1 ();
    +
    +        const_reverse_iterator2 rbegin2 () const;
    +        const_reverse_iterator2 rend2 () const;
    +
    +        reverse_iterator2 rbegin2 ();
    +        reverse_iterator2 rend2 ();
    +    };
    + +

    Projections

    + +

    Prototypes

    + +
        template<class M>
    +    matrix_slice<M> project (const matrix_slice<M> &data, const range &r1, const range &r2);
    +    template<class M>
    +    matrix_slice<M> project (M &data, const slice &s1, const slice &s2);
    +    template<class M>
    +    const matrix_slice<const M> project (const M &data, const slice &s1, const slice &s2);
    +    template<class M>
    +    matrix_slice<M> project (const matrix_slice<M> &data, const slice &s1, const slice &s2);
    + +

    Description

    + +

    The free project functions support the +construction of matrix slices.

    + +

    Definition

    + +

    Defined in the header matrix_proxy.hpp.

    + +

    Type requirements

    + + +
  • M is a model of Matrix Expression.
  • +
    + +

    Preconditions

    + +
      +
    • s1.start () + s1.stride () * s1.size () <= data.size1 () +
    • +
    • s2.start () + s2.stride () * s2.size () <= data.size2 () +
    • +
    + +

    Complexity

    + +

    Quadratic depending from the size of the slices.

    + +

    Examples

    + +
    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) 
    +            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;
    +}
    + +
    + +

    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/matrix_sparse.htm b/doc/matrix_sparse.htm new file mode 100644 index 00000000..3fa5dca3 --- /dev/null +++ b/doc/matrix_sparse.htm @@ -0,0 +1,622 @@ + + + + + +Sparse Matrix + + + + +

    c++boost.gifSparse Matrix

    + +

    Sparse Matrix

    + +

    Description

    + +

    The templated class sparse_matrix<T, F, A> is +the base container adaptor for sparse matrices. For a (m x n)-dimensional +sparse matrix and 0 <= i < m, 0 <= j < n +every non-zero element mi, j is +mapped to the (i x n + j)-th element of the container +for row major orientation or the (i + j x m)-th element +of the container for column major orientation.

    + +

    Example

    + +
    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) 
    +            m (i, j) = 3 * i + j;
    +    std::cout << m << std::endl;
    +}
    + +

    Definition

    + +

    Defined in the header matrix_sparse.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    T The type of object stored in the sparse matrix.  
    FFunctor describing the storage organization. [1]row_major
    AThe type of the adapted array. [2]map_array<std::size_t, T>
    + +

    Model of

    + +

    Matrix.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Matrix.

    + +

    Public base classes

    + +

    matrix_expression<sparse_matrix<T, F, A> > +

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    sparse_matrix () Allocates a sparse_matrix that holds at + most zero rows of zero elements.
    sparse_matrix (size_type size1, size_type2, + size_type non_zeros)Allocates a sparse_matrix that holds at + most size1 rows of size2 elements.
    sparse_matrix (const sparse_matrix &m)The copy constructor.
    template<class AE>
    + sparse_matrix (size_type non_zeros, const + matrix_expression<AE> &ae)
    The extended copy constructor.
    void resize (size_type size1, size_type size2, + size_type non_zeros)Reallocates a sparse_matrix to hold at + most size1 rows of size2 elements. + The content of the sparse_matrix is + preserved.
    size_type size1 () constReturns the number of rows.
    size_type size2 () constReturns the number of columns.
    const_reference operator () (size_type i, + size_type j) constReturns the value of the j-th element in + the i-th row.
    reference operator () (size_type i, size_type + j)Returns a reference of the j-th element + in the i-th row.
    sparse_matrix &operator = (const + sparse_matrix &m)The assignment operator.
    sparse_matrix &assign_temporary + (sparse_matrix &m)Assigns a temporary. May change the sparse matrix m.
    template<class AE>
    + sparse_matrix &operator = (const + matrix_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    + sparse_matrix &assign (const + matrix_expression<AE> &ae)
    Assigns a matrix expression to the sparse matrix. + Left and right hand side of the assignment should be + independent.
    template<class AE>
    + sparse_matrix &operator += (const + matrix_expression<AE> &ae)
    A computed assignment operator. Adds the matrix + expression to the sparse matrix.
    template<class AE>
    + sparse_matrix &plus_assign (const + matrix_expression<AE> &ae)
    Adds a matrix expression to the sparse matrix. Left + and right hand side of the assignment should be + independent.
    template<class AE>
    + sparse_matrix &operator -= (const + matrix_expression<AE> &ae)
    A computed assignment operator. Subtracts the matrix + expression from the sparse matrix.
    template<class AE>
    + sparse_matrix &minus_assign (const + matrix_expression<AE> &ae)
    Subtracts a matrix expression from the sparse matrix. + Left and right hand side of the assignment should be + independent.
    template<class AT>
    + sparse_matrix &operator *= (const AT &at)
    A computed assignment operator. Multiplies the sparse + matrix with a scalar.
    template<class AT>
    + sparse_matrix &operator /= (const AT &at)
    A computed assignment operator. Divides the sparse + matrix through a scalar.
    void swap (sparse_matrix &m)Swaps the contents of the sparse matrices.
    void insert (size_type i, size_type j, + const_reference t)Inserts the value t at the j-th + element of the i-th row.
    void erase (size_type i, size_type j)Erases the value at the j-th element of + the i-th row.
    void clear ()Clears the sparse matrix.
    const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the sparse_matrix.
    const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the sparse_matrix.
    iterator1 begin1 () Returns a iterator1 pointing to the + beginning of the sparse_matrix.
    iterator1 end1 () Returns a iterator1 pointing to the end + of the sparse_matrix.
    const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the sparse_matrix.
    const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the sparse_matrix.
    iterator2 begin2 () Returns a iterator2 pointing to the + beginning of the sparse_matrix.
    iterator2 end2 () Returns a iterator2 pointing to the end + of the sparse_matrix.
    const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed sparse_matrix. +
    const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed sparse_matrix. +
    reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to + the beginning of the reversed sparse_matrix. +
    reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to + the end of the reversed sparse_matrix.
    const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed sparse_matrix. +
    const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed sparse_matrix. +
    reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to + the beginning of the reversed sparse_matrix. +
    reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to + the end of the reversed sparse_matrix.
    + +

    Notes

    + +

    [1] Supported parameters for the storage organization are +row_major and column_major.

    + +

    [2] Supported parameters for the adapted array are +map_array<std::size_t, T> and std::map<std::size_t, T>. +

    + +

    Interface

    + +
        // Array based sparse matrix class 
    +    template<class T, class F, class A>
    +    class sparse_matrix: 
    +        public matrix_expression<sparse_matrix<T, F, A> > {
    +    public:      
    +        typedef std::size_t size_type;
    +        typedef std::ptrdiff_t difference_type;
    +        typedef T value_type;
    +        typedef const T &const_reference;
    +        typedef T &reference;
    +        typedef const T *const_pointer;
    +        typedef T *pointer;
    +        typedef F functor_type;
    +        typedef A array_type;
    +        typedef const A const_array_type;
    +        typedef const sparse_matrix<T, F, A> const_self_type;
    +        typedef sparse_matrix<T, F, A> self_type;
    +        typedef const matrix_const_reference<const_self_type> const_closure_type;
    +        typedef matrix_reference<self_type> closure_type;
    +        typedef typename A::const_iterator const_iterator_type;
    +        typedef typename A::iterator iterator_type;
    +        typedef sparse_tag storage_category;
    +        typedef typename F::orientation_category orientation_category;
    +
    +        // Construction and destruction
    +        sparse_matrix ();
    +        sparse_matrix (size_type size1, size_type size2, size_type non_zeros = 0); 
    +        sparse_matrix (const sparse_matrix &m);
    +        template<class AE>
    +        sparse_matrix (const matrix_expression<AE> &ae, size_type non_zeros = 0);
    +
    +        // Accessors
    +        size_type size1 () const;
    +        size_type size2 () const;
    +        size_type non_zeros () const;
    +        const_array_type &data () const;
    +        array_type &data ();
    +
    +        // Resizing
    +        void resize (size_type size1, size_type size2, size_type non_zeros = 0);
    +
    +        // Element access
    +        const_reference operator () (size_type i, size_type j) const;
    +        reference operator () (size_type i, size_type j);
    +
    +        // Assignment
    +        sparse_matrix &operator = (const sparse_matrix &m);
    +        sparse_matrix &assign_temporary (sparse_matrix &m);
    +        template<class AE>
    +        sparse_matrix &operator = (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        sparse_matrix &reset (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        sparse_matrix &assign (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        sparse_matrix& operator += (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        sparse_matrix &plus_assign (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        sparse_matrix& operator -= (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        sparse_matrix &minus_assign (const matrix_expression<AE> &ae);
    +        template<class AT>
    +        sparse_matrix& operator *= (const AT &at);
    +        template<class AT>
    +        sparse_matrix& operator /= (const AT &at);
    +
    +        // Swapping
    +        void swap (sparse_matrix &m);
    +        friend void swap (sparse_matrix &m1, sparse_matrix &m2);
    +
    +        // Element insertion and erasure
    +        void insert (size_type i, size_type j, const_reference t);
    +        void erase (size_type i, size_type j);
    +        void clear ();
    +
    +        class const_iterator1;
    +        class iterator1;
    +        class const_iterator2;
    +        class iterator2;
    +        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
    +        typedef reverse_iterator_base1<iterator1> reverse_iterator1;
    +        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
    +        typedef reverse_iterator_base2<iterator2> reverse_iterator2;
    +
    +        // Element lookup
    +        const_iterator1 find1 (int rank, size_type i, size_type j) const;
    +        iterator1 find1 (int rank, size_type i, size_type j);
    +        const_iterator2 find2 (int rank, size_type i, size_type j) const;
    +        iterator2 find2 (int rank, size_type i, size_type j);
    +        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
    +        iterator1 find_first1 (int rank, size_type i, size_type j);
    +        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
    +        iterator1 find_last1 (int rank, size_type i, size_type j);
    +        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
    +        iterator2 find_first2 (int rank, size_type i, size_type j);
    +        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
    +        iterator2 find_last2 (int rank, size_type i, size_type j);
    +
    +        // Iterators simply are pointers.
    +
    +        class const_iterator1:
    +            public container_const_reference<sparse_matrix>,
    +            public bidirectional_iterator_base<const_iterator1, value_type> {
    +        public:
    +            typedef sparse_bidirectional_iterator_tag iterator_category;
    +            typedef typename sparse_matrix::difference_type difference_type;
    +            typedef typename sparse_matrix::value_type value_type;
    +            typedef typename sparse_matrix::const_reference reference;
    +            typedef typename sparse_matrix::const_pointer pointer;
    +            typedef const_iterator2 dual_iterator_type;
    +            typedef const_reverse_iterator2 dual_reverse_iterator_type;
    +            typedef typename functor_type::functor1_type functor1_type;
    +
    +            // Construction and destruction
    +            const_iterator1 ();
    +            const_iterator1 (const sparse_matrix &m, int rank, size_type i, size_type j, const const_iterator_type &it);
    +            const_iterator1 (const iterator1 &it);
    +
    +            // Arithmetic
    +            const_iterator1 &operator ++ ();
    +            const_iterator1 &operator -- ();
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator2 begin () const;
    +            const_iterator2 end () const;
    +            const_reverse_iterator2 rbegin () const;
    +            const_reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator1 &operator = (const const_iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator1 &it) const;
    +        };
    +
    +        const_iterator1 begin1 () const;
    +        const_iterator1 end1 () const;
    +
    +        class iterator1:
    +            public container_reference<sparse_matrix>,
    +            public bidirectional_iterator_base<iterator1, value_type> {
    +        public:
    +            typedef sparse_bidirectional_iterator_tag iterator_category;
    +            typedef typename sparse_matrix::difference_type difference_type;
    +            typedef typename sparse_matrix::value_type value_type;
    +            typedef typename sparse_matrix::reference reference;
    +            typedef typename sparse_matrix::pointer pointer;
    +            typedef iterator2 dual_iterator_type;
    +            typedef reverse_iterator2 dual_reverse_iterator_type;
    +            typedef typename functor_type::functor1_type functor1_type;
    +
    +            // Construction and destruction
    +            iterator1 ();
    +            iterator1 (sparse_matrix &m, int rank, size_type i, size_type j, const iterator_type &it);
    +
    +            // Arithmetic
    +            iterator1 &operator ++ ();
    +            iterator1 &operator -- ();
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            iterator2 begin () const;
    +            iterator2 end () const;
    +            reverse_iterator2 rbegin () const;
    +            reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            iterator1 &operator = (const iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const iterator1 &it) const;
    +        };
    +
    +        iterator1 begin1 ();
    +        iterator1 end1 ();
    +
    +        class const_iterator2:
    +            public container_const_reference<sparse_matrix>,
    +            public bidirectional_iterator_base<const_iterator2, value_type> {
    +        public:
    +            typedef sparse_bidirectional_iterator_tag iterator_category;
    +            typedef typename sparse_matrix::difference_type difference_type;
    +            typedef typename sparse_matrix::value_type value_type;
    +            typedef typename sparse_matrix::const_reference reference;
    +            typedef typename sparse_matrix::const_pointer pointer;
    +            typedef const_iterator1 dual_iterator_type;
    +            typedef const_reverse_iterator1 dual_reverse_iterator_type;
    +            typedef typename functor_type::functor2_type functor2_type;
    +
    +            // Construction and destruction
    +            const_iterator2 ();
    +            const_iterator2 (const sparse_matrix &m, int rank, size_type i, size_type j, const const_iterator_type &it);
    +            const_iterator2 (const iterator2 &it);
    +
    +            // Arithmetic
    +            const_iterator2 &operator ++ ();
    +            const_iterator2 &operator -- ();
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator1 begin () const;
    +            const_iterator1 end () const;
    +            const_reverse_iterator1 rbegin () const;
    +            const_reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator2 &operator = (const const_iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator2 &it) const;
    +        };
    +
    +        const_iterator2 begin2 () const;
    +        const_iterator2 end2 () const;
    +
    +        class iterator2:
    +            public container_reference<sparse_matrix>,
    +            public bidirectional_iterator_base<iterator2, value_type> {
    +        public:
    +            typedef sparse_bidirectional_iterator_tag iterator_category;
    +            typedef typename sparse_matrix::difference_type difference_type;
    +            typedef typename sparse_matrix::value_type value_type;
    +            typedef typename sparse_matrix::reference reference;
    +            typedef typename sparse_matrix::pointer pointer;
    +            typedef iterator1 dual_iterator_type;
    +            typedef reverse_iterator1 dual_reverse_iterator_type;
    +            typedef typename functor_type::functor2_type functor2_type;
    +
    +            // Construction and destruction
    +            iterator2 ();
    +            iterator2 (sparse_matrix &m, int rank, size_type i, size_type j, const iterator_type &it);
    +
    +            // Arithmetic
    +            iterator2 &operator ++ ();
    +            iterator2 &operator -- ();
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            iterator1 begin () const;
    +            iterator1 end () const;
    +            reverse_iterator1 rbegin () const;
    +            reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            iterator2 &operator = (const iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const iterator2 &it) const;
    +        };
    +
    +        iterator2 begin2 ();
    +        iterator2 end2 ();
    +
    +        // Reverse iterators
    +
    +        const_reverse_iterator1 rbegin1 () const;
    +        const_reverse_iterator1 rend1 () const;
    +
    +        reverse_iterator1 rbegin1 ();
    +        reverse_iterator1 rend1 ();
    +
    +        const_reverse_iterator2 rbegin2 () const;
    +        const_reverse_iterator2 rend2 () const;
    +
    +        reverse_iterator2 rbegin2 ();
    +        reverse_iterator2 rend2 ();
    +    };
    + +
    + +

    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/overview.htm b/doc/overview.htm new file mode 100644 index 00000000..65c16d6e --- /dev/null +++ b/doc/overview.htm @@ -0,0 +1,1534 @@ + + + + + +uBLAS Overview + + + + +

    c++boost.gif uBLAS Overview

    + +

    Rationale

    + +

    It would be nice if every kind of numeric software could +be written in C++ without loss of efficiency, but unless +something can be found that achieves this without compromising +the C++ type system it may be preferable to rely on Fortran, +assembler or architecture-specific extensions (Bjarne +Stroustrup).

    + +

    This C++ library is directed towards scientific computing on +the level of basic linear algebra constructions with matrices and +vectors and their corresponding abstract operations. The primary +design goals were:

    + +
      +
    • mathematical notation
    • +
    • efficiency
    • +
    • functionality
    • +
    • compatibility
    • +
    + +

    Another intention was to evaluate, if the abstraction penalty +resulting from the use of such matrix and vector classes is +acceptable.

    + +

    Resources

    + +

    The development of this library was guided by a couple of +similar efforts:

    + +
      +
    • BLAS + by Jack Dongarra et al.
    • +
    • Blitz++ by + Todd Veldhuizen
    • +
    • POOMA by + Scott Haney et al.
    • +
    • MTL by + Jeremy Siek et al.
    • +
    + +

    BLAS seems to be the most widely used library for basic linear +algebra constructions, so it could be called a de-facto standard. +Its interface is procedural, the individual functions are +somewhat abstracted from simple linear algebra operations. Due to +the fact that is has been implemented using Fortran and its +optimizations, it also seems to be one of the fastest libraries +available. As we decided to design and implement our library in +an object-oriented way, the technical approaches are distinct. +However anyone should be able to express BLAS abstractions in +terms of our library operators and to compare the efficiency of +the implementations.

    + +

    Blitz++ is an impressive library implemented in C++. Its main +design seems to be oriented towards multidimensional arrays and +their associated operators including tensors. The author of +Blitz++ states, that the library achieves performance on par or +better than corresponding Fortran code due to his implementation +technique using expression templates and template metaprograms. +However we see some reasons, to develop an own design and +implementation approach. We do not know whether anybody tries to +implement traditional linear algebra and other numerical +algorithms using Blitz++. We also presume that even today Blitz++ +needs the most advanced C++ compiler technology due to its +implementation idioms. On the other hand, Blitz++ convinced us, +that the use of expression templates is mandatory to reduce the +abstraction penalty to an acceptable limit.

    + +

    POOMA's design goals seem to parallel Blitz++'s in many parts +. It extends Blitz++'s concepts with classes from the domains of +partial differential equations and theoretical physics. The +implementation supports even parallel architectures.

    + +

    MTL is another approach supporting basic linear algebra +operations in C++. Its design mainly seems to be influenced by +BLAS and the C++ Standard Template Library. We share the insight +that a linear algebra library has to provide functionality +comparable to BLAS. On the other hand we think, that the concepts +of the C++ standard library have not yet been proven to support +numerical computations as needed. As another difference MTL +currently does not seem to use expression templates. This may +result in one of two consequences: a possible loss of +expressiveness or a possible loss of performance.

    + +

    Concepts

    + +

    Mathematical Notation

    + +

    The usage of mathematical notation may ease the development of +scientific algorithms. So a C++ library implementing basic linear +algebra concepts carefully should overload selected C++ operators +on matrix and vector classes.

    + +

    We decided to use operator overloading for the following +primitives:

    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    DescriptionOperator
    Indexing of vectors and matricesvector::operator(size_t i);
    + matrix::operator(size_t i, size_t j);
    Assignment of vectors and matricesvector::operator = (const vector_expression + &);
    + vector::operator += (const vector_expression &);
    + vector::operator -= (const vector_expression &);
    + vector::operator *= (const scalar_expression &);
    + matrix::operator = (const matrix_expression &);
    + matrix::operator += (const matrix_expression &);
    + matrix::operator -= (const matrix_expression &);
    + matrix::operator *= (const scalar_expression &);
    Unary operations on vectors and matricesvector_expression operator - (const + vector_expression &);
    + matrix_expression operator - (const matrix_expression + &);
    Binary operations on vectors and matricesvector_expression operator + (const + vector_expression &, const vector_expression &);
    + vector_expression operator - (const vector_expression + &, const vector_expression &);
    + matrix_expression operator + (const matrix_expression + &, const matrix_expression &);
    + matrix_expression operator - (const matrix_expression + &, const matrix_expression &);
    Multiplication of vectors and matrices with a scalarvector_expression operator * (const + scalar_expression &, const vector_expression &);
    + vector_expression operator * (const vector_expression + &, const scalar_expression &);
    + matrix_expression operator * (const scalar_expression + &, const matrix_expression &);
    + matrix_expression operator * (const matrix_expression + &, const scalar_expression &);
    + +

    We decided to use no operator overloading for the following +other primitives:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    DescriptionFunction
    Left multiplication of vectors with a matrixvector_expression prod<vector_type> + (const matrix_expression &, const vector_expression + &);
    + vector_expression prod (const matrix_expression &, + const vector_expression &);
    Right multiplication of vectors with a matrixvector_expression prod<vector_type> + (const vector_expression &, const matrix_expression + &);
    + vector_expression prod (const vector_expression &, + const matrix_expression &);
    +
    Multiplication of matricesmatrix_expression prod<matrix_type> + (const matrix_expression &, const matrix_expression + &);
    + matrix_expression prod (const matrix_expression &, + const matrix_expression &);
    Inner product of vectorsscalar_expression inner_prod (const + vector_expression &, const vector_expression &);
    Outer product of vectorsmatrix_expression outer_prod (const + vector_expression &, const vector_expression &);
    Transpose of a matrixmatrix_expression trans (const + matrix_expression &);
    + +

    Efficiency

    + +

    To achieve the goal of efficiency for numerical computing, one +has to overcome two difficulties in formulating abstractions with +C++, namely temporaries and virtual function calls. Expression +templates solve these problems, but tend to slow down compilation +times.

    + +

    Eliminating Temporaries

    + +

    Abstract formulas on vectors and matrices normally compose a +couple of unary and binary operations. The conventional way of +evaluating such a formula is first to evaluate every leaf +operation of a composition into a temporary and next to evaluate +the composite resulting in another temporary. This method is +expensive in terms of time especially for small and space +especially for large vectors and matrices. The approach to solve +this problem is to use lazy evaluation as known from modern +functional programming languages. The principle of this approach +is to evaluate a complex expression element wise and to assign it +directly to the target.

    + +

    Two interesting and dangerous facts result.

    + +

    First one may get serious side effects using element wise +evaluation on vectors or matrices. Consider the matrix vector +product x = A x. Evaluation of A1x +and assignment to x1 changes the +right hand side, so that the evaluation of A2x +returns a wrong result. Our solution for this problem is to +evaluate the right hand side of an assignment into a temporary +and then to assign this temporary to the left hand side. To allow +further optimizations, we provide a corresponding member function +for every assignment operator. By using this member function a +programmer can confirm, that the left and right hand sides of an +assignment are independent, so that element wise evaluation and +direct assignment to the target is safe.

    + +

    Next one can get worse computational complexity under certain +cirumstances. Consider the chained matrix vector product A (B +x). Conventional evaluation of A (B x) is +quadratic. Deferred evaluation of B xi +is linear. As every element B xi is +needed linearly depending of the size, a completely deferred +evaluation of the chained matrix vector product A (B x) +is cubic. In such cases one needs to reintroduce temporaries in +the expression.

    + +

    Eliminating Virtual Function Calls

    + +

    Lazy expression evaluation normally leads to the definition of +a class hierarchy of terms. This results in the usage of dynamic +polymorphism to access single elements of vectors and matrices, +which is also known to be expensive in terms of time. A solution +was found a couple of years ago independently by David +Vandervoorde and Todd Veldhuizen and is commonly called +expression templates. Expression templates contain lazy +evaluation and replace dynamic polymorphism with static, i.e. +compile time polymorphism. Expression templates heavily depend on +the famous Barton-Nackman trick, also coined 'curiously defined +recursive templates' by Jim Coplien.

    + +

    Expression templates form the base of our implementation.

    + +

    Compilation times

    + +

    It is also a well known fact, that expression templates +challenge currently available compilers. We were able to +significantly reduce the amount of needed expression templates +using the Barton-Nackman trick consequently.

    + +

    We also decided to support a dual conventional implementation +(i.e. not using expression templates) with extensive bounds and +type checking of vector and matrix operations to support the +development cycle. Switching from debug mode to release mode is +controlled by the NDEBUG preprocessor symbol of <cassert>.

    + +

    Functionality

    + +

    Every C++ library supporting linear algebra will be measured +against the long-standing Fortran package BLAS. We now describe +how BLAS calls may be mapped onto our classes.

    + +

    Blas Level 1

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    BLAS CallMapped Library ExpressionMathematical DescriptionComment
    _asumnorm_1 (x) sum |xi|Computes the sum norm of a vector.
    _nrm2norm_2 (x)sqrt (sum |xi|2)Computes the euclidean norm of a vector.
    i_amaxnorm_inf (x)
    + norm_inf_index (x)
    max |xi|Computes the maximum norm of a vector.
    + BLAS computes the index of the first element having this + value.
    _dot
    + _dotu
    + _dotc
    inner_prod (x, y)or
    + inner_prod (conj (x), y)
    xT y or
    + xH y
    Computes the inner product of two vectors.
    + BLAS implements certain loop unrollment.
    dsdot
    + sdsdot
    a + prec_inner_prod (x, y)a + xT yComputes the inner product in double precision.
    _copyx = y
    + y.assign (x)
    x <- yCopies one vector to another.
    + BLAS implements certain loop unrollment.
    _swapswap (x, y)x <-> ySwaps two vectors.
    + BLAS implements certain loop unrollment.
    _scal
    + csscal
    + zdscal
    x *= ax <- a xScales a vector.
    + BLAS implements certain loop unrollment.
    _axpyy += a * xy <- a x + yAdds a scaled vector.
    + BLAS implements certain loop unrollment.
    _rot
    + _rotm
    + csrot
    + zdrot
    t.assign (a * x + b * y),
    + y.assign (- b * x + a * y),
    + x.assign (t)
    (x, y) <- (a x + b y, -b x + a y)Applies a plane rotation.
    _rotg
    + _rotmg
     (a, b) <-
    +   (? a / sqrt (a
    2 + b2), +
    +     ? b / sqrt (a
    2 + b2)) + or
    + (1, 0) <- (0, 0)
    Constructs a plane rotation.
    + +

    Blas Level 2

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    BLAS CallMapped Library ExpressionMathematical DescriptionComment
    _t_mvx = prod (A, x) or
    + x = prod (trans (A), x)
    or
    + x = prod (herm (A), x)
    x <- A x or
    + x <- A
    T x or
    + x <- A
    H x
    Computes the product of a matrix with a vector.
    _t_svx = solve (A, x, tag) or
    + x = solve (trans (A), x, tag) or
    + x = solve (herm (A), x, tag)
    x <- A-1 x or
    + x <- A
    T-1 + x or
    + x <- A
    H-1 + x
    Solves a linear equation for a triangular matrix.
    _g_mv
    + _s_mv
    + _h_mv
    y = a * prod (A, x) + b * y or
    + y = a * prod (trans (A), x) + b * y
    or
    + y = a * prod (herm (A), x) + b * y
    y <- A x + b y or
    + y <- A
    T x + b y
    + y <- A
    H x + b y
    Adds the scaled product of a matrix with a vector.
    _g_r
    + _g_ru
    + _g_rc
    A += a * outer_prod (x, y) or
    + A += a * outer_prod (x, conj (y))
    A <- a x yT + A or
    + A <- a x y
    H + A
    Performs a rank 1 update.
    _s_r
    + _h_r
    A += a * outer_prod (x, x) or
    + A += a * outer_prod (x, conj (x))
    A <- a x xT + A + or
    + A <- a x x
    H + A
    Performs a symmetric or hermitian rank 1 + update.
    _s_r2
    + _h_r2
    A += a * outer_prod (x, y) +
    +  a * outer_prod (y, x))
    or
    + A += a * outer_prod (x, conj (y)) +
    +  conj (a) * outer_prod (y, conj (x)))
    A <- a x yT + a y + xT + A or
    + A <- a x y
    H + a- + y xH + A
    Performs a symmetric or hermitian rank 2 + update.
    + +

    Blas Level 3

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    BLAS CallMapped Library ExpressionMathematical DescriptionComment
    _t_mmB = a * prod (A, B) or
    + B = a * prod (trans (A), B) or
    + B = a * prod (A, trans (B)) or
    + B = a * prod (trans (A), trans (B)) or
    + B = a * prod (herm (A), B) or
    + B = a * prod (A, herm (B)) or
    + B = a * prod (herm (A), trans (B)) or
    + B = a * prod (trans (A), herm (B)) or
    + B = a * prod (herm (A), herm (B))
    B <- a op (A) op (B) with
    +   op (X) = X or
    +   op (X) = XT or
    +   op (X) = XH
    Computes the scaled product of two matrices.
    _t_smB = solve (A, B, tag) or
    + B = solve (trans (A), B, tag) or
    + B = solve (herm (A), B, tag)
    B <- A-1 B or
    + B <- A
    T-1 + B or
    + B <- A
    H-1 + B
    Solves a linear equation for a triangular matrix.
    _g_mm
    + _s_mm
    + _h_mm
    C = a * prod (A, B) + b * C or
    + C = a * prod (trans (A), B) + b * C or
    + C = a * prod (A, trans (B)) + b * C or
    + C = a * prod (trans (A), trans (B)) + b * C or
    + C = a * prod (herm (A), B) + b * C or
    + C = a * prod (A, herm (B)) + b * C or
    + C = a * prod (herm (A), trans (B)) + b * C or
    + C = a * prod (trans (A), herm (B)) + b * C or
    + C = a * prod (herm (A), herm (B)) + b * C
    C <- a op (A) op (B) + b C with
    +   op (X) = X or
    +   op (X) = XT or
    +   op (X) = XH
    Adds the scaled product of two matrices.
    _s_rk
    + _h_rk
    B = a * prod (A, trans (A)) + b * B or
    + B = a * prod (trans (A), A) + b * B or
    + B = a * prod (A, herm (A)) + b * B or
    + B = a * prod (herm (A), A) + b * B
    B <- a A AT + b B + or
    + B <- a A
    T A + b B or
    + B <- a A AH + b B or
    + B <- a A
    H A + b B
    Performs a symmetric or hermitian rank k + update.
    _s_r2k
    + _h_r2k
    C = a * prod (A, trans (B)) +
    +  a * prod (B, trans (A)) + b * C
    or
    + C = a * prod (trans (A), B) +
    +  a * prod (trans (B), A) + b * C
    or
    + C = a * prod (A, herm (B)) +
    +  conj (a) * prod (B, herm (A)) + b * C
    or
    + C = a * prod (herm (A), B) +
    +  conj (a) * prod (herm (B), A) + b * C
    C <- a A BT + a B + AT + b C or
    + C <- a A
    T B + a BTA + + b C or
    + C <- a A B
    H + a- + B AH + b C or
    + C <- a A
    H B + a- + BH A + b C
    Performs a symmetric or hermitian rank 2 k + update.
    + +

    Storage Layouts

    + +

    The library supports conventional dense, packed and basic +sparse vector and matrix storage layouts. The description of the +most common constructions of vectors and matrices comes next.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ConstructionComment
    vector<T,
    +  std::vector<T> >
    +   v (size)
    Constructs a dense vector, storage is provided by a + standard vector.
    + The storage layout usually is BLAS compliant.
    vector<T,
    +  unbounded_array<T> >
    +   v (size)
    Constructs a dense vector, storage is provided by a + heap-based array.
    + The storage layout usually is BLAS compliant.
    vector<T,
    +  bounded_array<T, N> >
    +   v (size)
    Constructs a dense vector, storage is provided by a + stack-based array.
    + The storage layout usually is BLAS compliant.
    unit_vector<T>
    +   v (size, index)
    Constructs the index-th canonical unit + vector.
    zero_vector<T>
    +   v (size)
    Constructs a zero vector.
    sparse_vector<T,
    +  std::map<std::size_t, T> >
    +   v (size, non_zeros)
    Constructs a sparse vector, storage is provided by a + standard map.
    sparse_vector<T,
    +  map_array<std::size_t, T> >
    +   v (size, non_zeros)
    Constructs a sparse vector, storage is provided by a + map array.
    vector_range<V>
    +   vr (v, range)
    Constructs a sub vector of a dense, packed or sparse + vector.
    vector_slice<V>
    +   vs (v, slice)
    Constructs a sub vector of a dense, packed or sparse + vector.
    + This class usually can be used to emulate BLAS vector + slices.
    matrix<T,
    +  row_major,
    +  std::vector<T> >
    +   m (size1, size2)
    Constructs a dense matrix, orientation is row major, + storage is provided by a standard vector.
    matrix<T,
    +  column_major,
    +  std::vector<T> >
    +   m (size1, size2)
    Constructs a dense matrix, orientation is column + major, storage is provided by a standard vector.
    + The storage layout usually is BLAS compliant.
    matrix<T,
    +  row_major,
    +  unbounded_array<T> >
    +   m (size1, size2)
    Constructs a dense matrix, orientation is row major, + storage is provided by a heap-based array.
    matrix<T,
    +  column_major,
    +  unbounded_array<T> >
    +   m (size1, size2)
    Constructs a dense matrix, orientation is column + major, storage is provided by a heap-based array.
    + The storage layout usually is BLAS compliant.
    matrix<T,
    +  row_major,
    +  bounded_array<T, N1 * N2> >
    +   m (size1, size2)
    Constructs a dense matrix, orientation is row major, + storage is provided by a stack-based array.
    matrix<T,
    +  column_major,
    +  bounded_array<T, N1 * N2> >
    +   m (size1, size2)
    Constructs a dense matrix, orientation is column + major, storage is provided by a stack-based array.
    + The storage layout usually is BLAS compliant.
    identity_matrix<T>
    +   m (size)
    Constructs an identity matrix.
    zero_matrix<T>
    +   m (size1, size2)
    Constructs a zero matrix.
    triangular_matrix<T,
    +  row_major, F, A>
    +   m (size)
    Constructs a packed triangular matrix, orientation is + row major.
    triangular_matrix<T,
    +  column_major, F, A>
    +   m (size)
    Constructs a packed triangular matrix, orientation is + column major.
    + The storage layout usually is BLAS compliant.
    banded_matrix<T,
    +  row_major, A>
    +   m (size1, size2, lower, upper)
    Constructs a packed banded matrix, orientation is row + major.
    banded_matrix<T,
    +  column_major, A>
    +   m (size1, size2, lower, upper)
    Constructs a packed banded matrix, orientation is + column major.
    + The storage layout usually is BLAS compliant.
    symmetric_matrix<T,
    +  row_major, F, A>
    +   m (size)
    Constructs a packed symmetric matrix, orientation is + row major.
    symmetric_matrix<T,
    +  column_major, F, A>
    +   m (size)
    Constructs a packed symmetric matrix, orientation is + column major.
    + The storage layout usually is BLAS compliant.
    hermitian_matrix<T,
    +  row_major, F, A>
    +   m (size)
    Constructs a packed hermitian matrix, orientation is + row major.
    hermitian_matrix<T,
    +  column_major, F, A>
    +   m (size)
    Constructs a packed hermitian matrix, orientation is + column major.
    + The storage layout usually is BLAS compliant.
    sparse_matrix<T,
    +  row_major,
    +  std::map<std::size_t, T> >
    +   m (size1, size2, non_zeros)
    Constructs a sparse matrix, orientation is row major, + storage is provided by a standard map.
    sparse_matrix<T,
    +  column_major,
    +  std::map<std::size_t, T> >
    +   m (size1, size2, non_zeros)
    Constructs a sparse matrix, orientation is column + major, storage is provided by a standard map.
    sparse_matrix<T,
    +  row_major,
    +  map_array<std::size_t, T> >
    +   m (size1, size2, non_zeros)
    Constructs a sparse matrix, orientation is row major, + storage is provided by a map array.
    sparse_matrix<T,
    +  column_major,
    +  map_array<std::size_t, T> >
    +   m (size1, size2, non_zeros)
    Constructs a sparse matrix, orientation is column + major, storage is provided by a map array.
    matrix_row<M>
    +   mr (m, i)
    Constructs a sub vector of a dense, packed or sparse + matrix, containing the i-th row.
    matrix_column<M>
    +   mc (m, j)
    Constructs a sub vector of a dense, packed or sparse + matrix, containing the j-th column.
    matrix_range<M>
    +   mr (m, range1, range2)
    Constructs a sub matrix of a dense, packed or sparse + matrix.
    + This class usually can be used to emulate BLAS leading + dimensions.
    matrix_slice<M>
    +   ms (m, slice1, slice2)
    Constructs a sub matrix of a dense, packed or sparse + matrix.
    triangular_adaptor<M, F>
    +   ta (m)
    Constructs a triangular view of a dense, packed or + sparse matrix.
    + This class usually can be used to generate corresponding + BLAS matrix types.
    banded_adaptor<M>
    +   ba (m, lower, upper)
    Constructs a banded view of a dense, packed or sparse + matrix.
    + This class usually can be used to generate corresponding + BLAS matrix types.
    symmetric_adaptor<M>
    +   sa (m)
    Constructs a symmetric view of a dense, packed or + sparse matrix.
    + This class usually can be used to generate corresponding + BLAS matrix types.
    hermitian_adaptor<M>
    +   ha (m)
    Constructs a hermitian view of a dense, packed or + sparse matrix.
    + This class usually can be used to generate corresponding + BLAS matrix types.
    + +

    Compatibility

    + +

    For compatibility reasons we provide array like indexing for +vectors and matrices, although this could be expensive for +matrices due to the needed temporary proxy objects.

    + +

    To support the most widely used C++ compilers our design and +implementation do not depend on partial template specialization +essentially.

    + +

    The library presumes standard compliant allocation through operator +new and operator delete. So programs which +are intended to run under MSVC 6.0 should set a correct new +handler throwing a std::bad_alloc exception via _set_new_handler +to detect out of memory conditions.

    + +

    To get the most performance out of the box with MSVC 6.0, you +should change the preprocessor definition of BOOST_UBLAS_INLINE +to __forceinline in the header file +config.hpp. But we suspect this optimization to be fragile.

    + +

    Reference

    + + + +

    Benchmark Results

    + +

    The following tables contain results of one of our benchmarks. +This benchmark compares a native C implementation ('C array') and +some library based implementations. The safe variants based on +the library assume aliasing, the fast variants do not use +temporaries and are functionally equivalent to the native C +implementation. Besides the generic vector and matrix classes the +benchmark utilizes special classes c_vector and c_matrix, +which are intended to avoid every overhead through genericity.

    + +

    The benchmark program was compiled with MSVC 6.0 and run on an +Intel Pentium II with 333 Mhz. First we comment the results for +double vectors and matrices of dimension 3 and 3 x 3, +respectively.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    OperationImplementationElapsed [s]MFLOP/sComment
    inner_prodC array0.1 47.6837 No significant abstraction penalty
    c_vector0.06 79.4729
    vector<unbounded_array>0.11 43.3488
    vector<std::vector>0.11 43.3488
    vector + vectorC array0.05 114.441 Abstraction penalty: factor 2
    c_vector safe0.22 26.0093
    c_vector fast0.11 52.0186
    vector<unbounded_array> safe1.05 5.44957
    vector<unbounded_array> fast0.16 35.7628
    vector<std::vector> safe1.16 4.9328
    vector<std::vector> fast0.16 35.7628
    outer_prodC array0.06 85.8307 Abstraction penalty: factor 2
    c_matrix, c_vector safe0.22 23.4084
    c_matrix, c_vector fast0.11 46.8167
    matrix<unbounded_array>, + vector<unbounded_array> safe0.38 13.5522
    matrix<unbounded_array>, + vector<unbounded_array> fast0.16 32.1865
    matrix<std::vector>, vector<std::vector> + safe0.5 10.2997
    matrix<std::vector>, vector<std::vector> + fast0.11 46.8167
    prod (matrix, vector)C array0.06 71.5256 No significant abstraction penalty
    c_matrix, c_vector safe0.11 39.0139
    c_matrix, c_vector fast0.11 39.0139
    matrix<unbounded_array>, + vector<unbounded_array> safe0.33 13.0046
    matrix<unbounded_array>, + vector<unbounded_array> fast0.11 39.0139
    matrix<std::vector>, vector<std::vector> + safe0.38 11.2935
    matrix<std::vector>, vector<std::vector> + fast0.05 85.8307
    matrix + matrixC array0.11 46.8167 No significant abstraction penalty
    c_matrix safe0.17 30.2932
    c_matrix fast0.11 46.8167
    matrix<unbounded_array> safe0.44 11.7042
    matrix<unbounded_array> fast0.16 32.1865
    matrix<std::vector> safe0.6 8.58307
    matrix<std::vector> fast0.17 30.2932
    prod (matrix, matrix)C array0.11 39.0139 No significant abstraction penalty
    c_matrix safe0.11 39.0139
    c_matrix fast0.11 39.0139
    matrix<unbounded_array> safe0.22 19.507
    matrix<unbounded_array> fast0.11 39.0139
    matrix<std::vector> safe0.27 15.8946
    matrix<std::vector> fast0.11 39.0139
    + +

    We notice a twofold performance loss for small vectors and +matrices: first the general abstraction penalty for using +classes, and then a small loss when using the generic vector and +matrix classes. The difference w.r.t. alias assumptions is also +significant.

    + +

    Next we comment the results for double vectors and matrices of +dimension 100 and 100 x 100, respectively.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    OperationImplementationElapsed [s]MFLOP/sComment
    inner_prodC array0.05 113.869 No significant abstraction penalty
    c_vector0.06 94.8906
    vector<unbounded_array>0.05 113.869
    vector<std::vector>0.06 94.8906
    vector + vectorC array0.05 114.441 No significant abstraction penalty
    c_vector safe0.11 52.0186
    c_vector fast0.11 52.0186
    vector<unbounded_array> safe0.11 52.0186
    vector<unbounded_array> fast0.06 95.3674
    vector<std::vector> safe0.17 33.6591
    vector<std::vector> fast0.11 52.0186
    outer_prodC array0.05 114.441 No significant abstraction penalty
    c_matrix, c_vector safe0.28 20.4359
    c_matrix, c_vector fast0.11 52.0186
    matrix<unbounded_array>, + vector<unbounded_array> safe0.27 21.1928
    matrix<unbounded_array>, + vector<unbounded_array> fast0.06 95.3674
    matrix<std::vector>, vector<std::vector> + safe0.28 20.4359
    matrix<std::vector>, vector<std::vector> + fast0.11 52.0186
    prod (matrix, vector)C array0.11 51.7585 No significant abstraction penalty
    c_matrix, c_vector safe0.11 51.7585
    c_matrix, c_vector fast0.05 113.869
    matrix<unbounded_array>, + vector<unbounded_array> safe0.11 51.7585
    matrix<unbounded_array>, + vector<unbounded_array> fast0.06 94.8906
    matrix<std::vector>, vector<std::vector> + safe0.1 56.9344
    matrix<std::vector>, vector<std::vector> + fast0.06 94.8906
    matrix + matrixC array0.22 26.0093 No significant abstraction penalty
    c_matrix safe0.49 11.6776
    c_matrix fast0.22 26.0093
    matrix<unbounded_array> safe0.39 14.6719
    matrix<unbounded_array> fast0.22 26.0093
    matrix<std::vector> safe0.44 13.0046
    matrix<std::vector> fast0.27 21.1928
    prod (matrix, matrix)C array0.06 94.8906 No significant abstraction penalty
    c_matrix safe0.06 94.8906
    c_matrix fast0.05 113.869
    matrix<unbounded_array> safe0.11 51.7585
    matrix<unbounded_array> fast0.17 33.4908
    matrix<std::vector> safe0.11 51.7585
    matrix<std::vector> fast0.16 35.584
    + +

    For larger vectors and matrices the general abstraction +penalty for using classes seems to decrease, the small loss when +using generic vector and matrix classes seems to remain. The +difference w.r.t. alias assumptions remains visible, too.

    + +
    + +

    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/readme.txt b/doc/readme.txt new file mode 100644 index 00000000..2b27bf66 --- /dev/null +++ b/doc/readme.txt @@ -0,0 +1,20 @@ +Welcome to the evaluation of our C++ matrix library. + +Installation: +Extract the zip-file to a (new) directory of your choice. Workspace and +project files for MSVC and simple makefiles for BCC and GCC are contained within +the archive. + +Tests and benchmarks: +Test1 contains a couple of basic tests for dense vectors and matrices. +Test2 demonstrates how to emulate BLAS with this matrix library. +Test3 contains a couple of basic tests for sparse vectors and matrices. +Test4 contains a couple of basic tests for banded matrices. +Test5 contains a couple of basic tests for triangular matrices. +Bench1 measures the abstraction penalty using certain dense matrix and vector +operations. +Bench2 measures the performance of sparse matrix and vector operations. +Bench3 measures the performance of vector and matrix proxy's operations. + +If you have any problems installing or using the library, please feel free to contact +us at mailto:ublas@genesys-e.org \ No newline at end of file diff --git a/doc/storage.htm b/doc/storage.htm new file mode 100644 index 00000000..3b0fb33a --- /dev/null +++ b/doc/storage.htm @@ -0,0 +1,860 @@ + + + + + +Storage + + + + +

    c++boost.gifStorage

    + +

    Unbounded Array

    + +

    Description

    + +

    The templated class unbounded_array<T> implements +a simple C-like array using allocation via new/delete.

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    unbounded_array<double> a (3);
    +    for (int i = 0; i < a.size (); ++ i) {
    +        a [i] = i;
    +        std::cout << a [i] << std::endl;
    +    }
    +}
    + +

    Definition

    + +

    Defined in the header storage.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + +
    Parameter Description Default
    T The type of object stored in the array.  
    + +

    Model of

    + +

    Random Access Container.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Random +Access Container.

    + +

    Public base classes

    + +

    None.

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    unbounded_array () Allocates an uninitialized unbounded_array that + holds at most zero elements.
    unbounded_array (size_type size)Allocates an uninitialized unbounded_array that + holds at most size elements.
    unbounded_array (const unbounded_array &a)The copy constructor.
    ~unbounded_array ()Deallocates the unbounded_array itself.
    void resize (size_type size)Reallocates an unbounded_array to hold + at most size elements. The content of the unbounded_array + is not preserved.
    size_type size () constReturns the size of the unbounded_array. +
    const_reference operator [] (size_type i) + constReturns a const reference of the i-th + element.
    reference operator [] (size_type i)Returns a reference of the i-th element. +
    unbounded_array &operator = (const + unbounded_array &a)The assignment operator.
    unbounded_array &assign_temporary + (unbounded_array &a)Assigns a temporary. May change the array a.
    void swap (unbounded_array &a)Swaps the contents of the arrays.
    pointer insert (pointer it, const + value_type &t)Inserts the value t at it.
    void erase (pointer it)Erases the value at it.
    void clear ()Clears the array.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the unbounded_array.
    const_iterator end () constReturns a const_iterator pointing to the + end of the unbounded_array.
    iterator begin () Returns a iterator pointing to the + beginning of the unbounded_array.
    iterator end () Returns a iterator pointing to the end + of the unbounded_array.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed unbounded_array. +
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed unbounded_array. +
    reverse_iterator rbegin () Returns a reverse_iterator pointing to + the beginning of the reversed unbounded_array. +
    reverse_iterator rend () Returns a reverse_iterator pointing to + the end of the reversed unbounded_array.
    + +

    Interface

    + +
        // Unbounded array 
    +    template<class T>
    +    class unbounded_array {
    +    public:      
    +        typedef std::size_t size_type;
    +        typedef std::ptrdiff_t difference_type;
    +        typedef T value_type;
    +        typedef const T &const_reference;
    +        typedef T &reference;
    +        typedef const T *const_pointer;
    +        typedef T *pointer;
    +
    +        // Construction and destruction
    +        unbounded_array ();
    +        unbounded_array (size_type size);
    +        unbounded_array (const unbounded_array &a);
    +        ~unbounded_array ();
    +
    +        // Resizing
    +        void resize (size_type size);
    +
    +        size_type size () const;
    +
    +        // Element access
    +        const_reference operator [] (size_type i) const;
    +        reference operator [] (size_type i);
    +
    +        // Assignment
    +        unbounded_array &operator = (const unbounded_array &a);
    +        unbounded_array &assign_temporary (unbounded_array &a);
    +
    +        // Swapping
    +        void swap (unbounded_array &a);
    +        friend void swap (unbounded_array &a1, unbounded_array &a2);
    +
    +        // Element insertion and deletion
    +        pointer insert (pointer it, const value_type &t);
    +        void insert (pointer it, pointer it1, pointer it2);
    +        void erase (pointer it);
    +        void erase (pointer it1, pointer it2);
    +        void clear ();
    +
    +        // Iterators simply are pointers.
    +
    +        typedef const_pointer const_iterator;
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        typedef pointer iterator;
    +
    +        iterator begin ();
    +        iterator end ();
    +
    +        // Reverse iterators
    +
    +        typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +
    +        typedef std::reverse_iterator<iterator> reverse_iterator;
    +
    +        reverse_iterator rbegin ();
    +        reverse_iterator rend ();
    +    };
    +
    +    template<class T>
    +    unbounded_array<T> &assign_temporary (unbounded_array<T> &a1, unbounded_array<T> &a2);
    + +

    Bounded Array

    + +

    Description

    + +

    The templated class bounded_array<T, N> implements +a simple C-like array.

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    bounded_array<double, 3> a (3);
    +    for (int i = 0; i < a.size (); ++ i) {
    +        a [i] = i;
    +        std::cout << a [i] << std::endl;
    +    }
    +}
    + +

    Definition

    + +

    Defined in the header storage.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    T The type of object stored in the array.  
    NThe allocation size of the array. 
    + +

    Model of

    + +

    Random Access Container.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Random +Access Container.

    + +

    Public base classes

    + +

    None.

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    bounded_array () Allocates an uninitialized bounded_array that + holds at most zero elements.
    bounded_array (size_type size)Allocates an uninitialized bounded_array that + holds at most size elements.
    bounded_array (const bounded_array &a)The copy constructor.
    ~bounded_array ()Deallocates the bounded_array itself.
    void resize (size_type size)Reallocates a bounded_array to hold at + most size elements. The content of the bounded_array + is preserved.
    size_type size () constReturns the size of the bounded_array.
    const_reference operator [] (size_type i) + constReturns a const reference of the i-th + element.
    reference operator [] (size_type i)Returns a reference of the i-th element. +
    bounded_array &operator = (const + bounded_array &a)The assignment operator.
    bounded_array &assign_temporary + (bounded_array &a)Assigns a temporary. May change the array a.
    void swap (bounded_array &a)Swaps the contents of the arrays.
    pointer insert (pointer it, const + value_type &t)Inserts the value t at it.
    void erase (pointer it)Erases the value at it.
    void clear ()Clears the array.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the bounded_array.
    const_iterator end () constReturns a const_iterator pointing to the + end of the bounded_array.
    iterator begin () Returns a iterator pointing to the + beginning of the bounded_array.
    iterator end () Returns a iterator pointing to the end + of the bounded_array.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed bounded_array. +
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed bounded_array. +
    reverse_iterator rbegin () Returns a reverse_iterator pointing to + the beginning of the reversed bounded_array. +
    reverse_iterator rend () Returns a reverse_iterator pointing to + the end of the reversed bounded_array.
    + +

    Interface

    + +
        // Bounded array 
    +    template<class T, std::size_t N>
    +    class bounded_array {
    +    public:      
    +        typedef std::size_t size_type;
    +        typedef std::ptrdiff_t difference_type;
    +        typedef T value_type;
    +        typedef const T &const_reference;
    +        typedef T &reference;
    +        typedef const T *const_pointer;
    +        typedef T *pointer;
    +
    +        // Construction and destruction
    +        bounded_array ();
    +        bounded_array (size_type size);
    +        bounded_array (const bounded_array &a);
    +
    +        // Resizing
    +        void resize (size_type size);
    +
    +        size_type size () const;
    +
    +        // Element access
    +        const_reference operator [] (size_type i) const;
    +        reference operator [] (size_type i);
    +
    +        // Assignment
    +        bounded_array &operator = (const bounded_array &a);
    +        bounded_array &assign_temporary (bounded_array &a);
    +
    +        // Swapping
    +        void swap (bounded_array &a);
    +        friend void swap (bounded_array &a1, bounded_array &a2);
    +
    +        // Element insertion and deletion
    +        pointer insert (pointer it, const value_type &t);
    +        void insert (pointer it, pointer it1, pointer it2);
    +        void erase (pointer it);
    +        void erase (pointer it1, pointer it2);
    +        void clear ();
    +
    +        // Iterators simply are pointers.
    +
    +        typedef const_pointer const_iterator;
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        typedef pointer iterator;
    +
    +        iterator begin ();
    +        iterator end ();
    +
    +        // Reverse iterators
    +
    +        typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +
    +        typedef std::reverse_iterator<iterator, value_type, reference> reverse_iterator;
    +
    +        reverse_iterator rbegin ();
    +        reverse_iterator rend ();
    +    };
    +
    +    template<class T, std::size_t N>
    +    bounded_array<T, N> &assign_temporary (bounded_array<T, N> &a1, bounded_array<T, N> &a2);
    + +

    Range

    + +

    Description

    + +

    The class range implements base functionality +needed to address ranges of vectors and matrices.

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    range r (0, 3);
    +    for (int i = 0; i < r.size (); ++ i) {
    +        std::cout << r (i) << std::endl;
    +    }
    +}
    + +

    Definition

    + +

    Defined in the header storage.hpp.

    + +

    Model of

    + +

    Reversible Container.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of +Reversible Container.

    + +

    Public base classes

    + +

    None.

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    range (size_type start, size_type stop) Constructs a range from start to stop.
    size_type start () constReturns the beginning of the range.
    size_type size () constReturns the size of the range.
    const_reference operator [] (size_type i) constReturns the value start + i of the i-th + element.
    range compose (const range &r) constReturns the composite range from start + + r.start () to start + r.start () + r.size ().
    bool operator == (const range &r) constTests two ranges for equality.
    bool operator != (const range &r) constTests two ranges for inequality.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the range.
    const_iterator end () constReturns a const_iterator pointing to the + end of the range.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed range. +
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed range.
    + +

    Interface

    + +
        // Range class
    +    class range {
    +    public:
    +        typedef std::size_t size_type;
    +        typedef std::ptrdiff_t difference_type;
    +        typedef difference_type value_type;
    +        typedef value_type const_reference;
    +        typedef const_reference reference;
    +        typedef const difference_type *const_pointer;
    +        typedef difference_type *pointer;
    +        typedef size_type const_iterator_type;
    +
    +        // Construction and destruction
    +        range ();
    +        range (size_type start, size_type stop);
    +
    +        size_type start () const;
    +        size_type size () const;
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +
    +        // Composition
    +        range compose (const range &r) const;
    +
    +        // Comparison
    +        bool operator == (const range &r) const;
    +        bool operator != (const range &r) const;
    +
    +        // Iterator simply is a index.
    +
    +        class const_iterator:
    +            public container_const_reference<range>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const range &r, const const_iterator_type &it);
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            const_reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        // Reverse iterator
    +
    +        typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +    };
    + +

    Slice

    + +

    Description

    + +

    The class slice implements base functionality +needed to address slices of vectors and matrices.

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    slice s (0, 1, 3);
    +    for (int i = 0; i < s.size (); ++ i) {
    +        std::cout << s (i) << std::endl;
    +    }
    +}
    + +

    Definition

    + +

    Defined in the header storage.hpp.

    + +

    Model of

    + +

    Reversible Container.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of +Reversible Container.

    + +

    Public base classes

    + +

    None.

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    slice (size_type start, size_type stride, + size_type size) Constructs a slice from start to start + + size with stride stride.
    size_type start () constReturns the beginning of the slice.
    size_type stride () constReturns the stride of the slice.
    size_type size () constReturns the size of the slice.
    const_reference operator [] (size_type i) constReturns the value start + i * stride of + the i-th element.
    slice compose (const range &r) constReturns the composite slice from start + stride + * r.start () to start + stride * (r.start () + + r.size ()) with stride stride.
    slice compose (const slice &s) constReturns the composite slice from start + stride + * s.start () to start + stride * s.stride () + * (s.start () + s.size ()) with stride stride + * s.stride ().
    bool operator == (const slice &s) constTests two slices for equality.
    bool operator != (const slice &s) constTests two slices for inequality.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the slice.
    const_iterator end () constReturns a const_iterator pointing to the + end of the slice.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed slice. +
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed slice.
    + +

    Interface

    + +
        // Slice class
    +    class slice {
    +    public:
    +        typedef std::size_t size_type;
    +        typedef std::ptrdiff_t difference_type;
    +        typedef difference_type value_type;
    +        typedef value_type const_reference;
    +        typedef const_reference reference;
    +        typedef const difference_type *const_pointer;
    +        typedef difference_type *pointer;
    +        typedef size_type const_iterator_type;
    +
    +        // Construction and destruction
    +        slice ();
    +        slice (size_type start, size_type stride, size_type size);
    +
    +        size_type start () const;
    +        size_type stride () const;
    +        size_type size () const;
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +
    +        // Composition
    +        slice compose (const range &r) const;
    +        slice compose (const slice &s) const;
    +
    +        // Comparison
    +        bool operator == (const slice &s) const;
    +        bool operator != (const slice &s) const;
    +
    +        // Iterator simply is a index.
    +
    +        class const_iterator:
    +            public container_const_reference<slice>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const slice &s, const const_iterator_type &it);
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            const_reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        // Reverse iterator
    +
    +        typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +    };
    + +
    + +

    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 new file mode 100644 index 00000000..15f80cf1 --- /dev/null +++ b/doc/storage_sparse.htm @@ -0,0 +1,310 @@ + + + + + +Sparse Storage + + + + +

    c++boost.gifSparse Storage

    + +

    Map Array

    + +

    Description

    + +

    The templated class map_array<I, T> implements +a simple std::map-like associative container as a sorted array.

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    map_array<int, double> a (3);
    +    for (int i = 0; i < a.size (); ++ i) {
    +        a [i] = i;
    +        std::cout << a [i] << std::endl;
    +    }
    +}
    + +

    Definition

    + +

    Defined in the header storage_sparse.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    IThe type of index stored in the array. 
    T The type of object stored in the array.  
    + +

    Model of

    + +

    Reversible Container.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of +Reversible Container.

    + +

    Public base classes

    + +

    None.

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    map_array () Allocates a map_array that holds + at most zero elements.
    map_array (size_type size)Allocates a map_array that holds + at most size elements.
    map_array (const map_array + &a)The copy constructor.
    ~map_array ()Deallocates the map_array itself. +
    void resize (size_type size)Reallocates a map_array to hold + at most size elements. The content of the map_array + is preserved.
    size_type size () constReturns the size of the map_array. +
    data_reference operator [] (index_type i)Returns a reference of the element that is associated + with a particular index. If the map_array + does not already contain such an element, operator[] + inserts the default T ().
    map_array &operator = (const + map_array &a)The assignment operator.
    map_array &assign_temporary + (map_array &a)Assigns a temporary. May change the array a.
    void swap (map_array &a)Swaps the contents of the arrays.
    pointer insert (pointer it, const + value_type &p)Inserts p into the array, using it + as a hint to where it will be inserted.
    void erase (pointer it)Erases the value at it.
    void clear ()Clears the array.
    const_pointer find (index_type i) constFinds an element whose index is i.
    pointer find (index_type i)Finds an element whose index is i.
    const_pointer lower_bound (index_type i) + constFinds the first element whose index is not less than i.
    pointer lower_bound (index_type i)Finds the first element whose index is not less than i. +
    const_pointer upper_bound (index_type i) + constFinds the first element whose index is greater than i. +
    pointer upper_bound (index_type i)Finds the first element whose index is greater than i. +
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the map_array.
    const_iterator end () constReturns a const_iterator pointing to the + end of the map_array.
    iterator begin () Returns a iterator pointing to the + beginning of the map_array.
    iterator end () Returns a iterator pointing to the end + of the map_array.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed map_array. +
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed map_array. +
    reverse_iterator rbegin () Returns a reverse_iterator pointing to + the beginning of the reversed map_array. +
    reverse_iterator rend () Returns a reverse_iterator pointing to + the end of the reversed map_array.
    + +

    Interface

    + +
        // Map array 
    +    template<class I, class T>
    +    class map_array {
    +    public:      
    +        typedef std::size_t size_type;
    +        typedef std::ptrdiff_t difference_type;
    +        typedef I index_type;
    +        typedef T data_value_type;
    +        typedef const T &data_const_reference;
    +        typedef T &data_reference;
    +        typedef std::pair<I, T> value_type;
    +        typedef const std::pair<I, T> &const_reference;
    +        typedef std::pair<I, T> &reference;
    +        typedef const std::pair<I, T> *const_pointer;
    +        typedef std::pair<I, T> *pointer;
    +
    +        // Construction and destruction
    +        map_array ();
    +        map_array (size_type size);
    +        map_array (const map_array &a);
    +        ~map_array ();
    +
    +        // Resizing
    +        void resize (size_type size);
    +
    +        size_type size () const;
    +
    +        // Element access
    +        data_reference operator [] (index_type i);
    +
    +        // Assignment
    +        map_array &operator = (const map_array &a);
    +        map_array &assign_temporary (map_array &a);
    +
    +        // Swapping
    +        void swap (map_array &a);
    +        friend void swap (map_array &a1, map_array &a2);
    +
    +        // Element insertion and deletion
    +        pointer insert (pointer it, const value_type &p);
    +        void insert (pointer it, pointer it1, pointer it2);
    +        void erase (pointer it);
    +        void erase (pointer it1, pointer it2);
    +        void clear ();
    +
    +        // Element lookup
    +        const_pointer find (index_type i) const;
    +        pointer find (index_type i);
    +        const_pointer lower_bound (index_type i) const;
    +        pointer lower_bound (index_type i);
    +        const_pointer upper_bound (index_type i) const;
    +        pointer upper_bound (index_type i);
    +
    +        // Iterators simply are pointers.
    +
    +        typedef const_pointer const_iterator;
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        typedef pointer iterator;
    +
    +        iterator begin ();
    +        iterator end ();
    +
    +        // Reverse iterators
    +
    +        typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +
    +        typedef std::reverse_iterator<iterator> reverse_iterator;
    +
    +        reverse_iterator rbegin ();
    +        reverse_iterator rend ();
    +    };
    +
    +    template<class I, class T>
    +    map_array<I, T> &assign_temporary (map_array<I, T> &a1, map_array<I, T> &a2);
    + +
    + +

    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 new file mode 100644 index 00000000..8388194e --- /dev/null +++ b/doc/symmetric.htm @@ -0,0 +1,1209 @@ + + + + + +Symmetric Matrix + + + + +

    c++boost.gifSymmetric Matrix

    + +

    Symmetric Matrix

    + +

    Description

    + +

    The templated class symmetric_matrix<T, F1, F2, A> +is the base container adaptor for symmetric matrices. For +a (n x n)-dimensional symmetric matrix and 0 <= i +< n, 0 <= j < n holds si, +j = sj, i. The storage of +symmetric matrices is packed.

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    symmetric_matrix<double, lower> ml (3, 3);
    +    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 j = i; j < m.size2 (); ++ j)
    +            mu (i, j) = 3 * i + j;
    +    std::cout << mu << std::endl;
    +}
    + +

    Definition

    + +

    Defined in the header symmetric.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    T The type of object stored in the matrix.  
    F1Functor describing the type of the symmetric matrix. [1]lower
    F2Functor describing the storage organization. [2]row_major
    AThe type of the adapted array. [3]unbounded_array<T>
    + +

    Model of

    + +

    Matrix.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Matrix.

    + +

    Public base classes

    + +

    matrix_expression<symmetric_matrix<T, F1, F2, +A> >

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    symmetric_matrix () Allocates an uninitialized symmetric_matrix + that holds zero rows of zero elements.
    symmetric_matrix (size_type size)Allocates an uninitialized symmetric_matrix + that holds size rows of size + elements.
    symmetric_matrix (const symmetric_matrix + &m)The copy constructor.
    template<class AE>
    + symmetric_matrix (const matrix_expression<AE> + &ae)
    The extended copy constructor.
    void resize (size_type size)Reallocates a symmetric_matrix to hold size + rows of size elements. The content of the symmetric_matrix + is not preserved.
    size_type size1 () constReturns the number of rows.
    size_type size2 () constReturns the number of columns.
    const_reference operator () (size_type i, + size_type j) constReturns a const reference of the j-th + element in the i-th row.
    reference operator () (size_type i, size_type + j)Returns a reference of the j-th element + in the i-th row.
    symmetric_matrix &operator = (const + symmetric_matrix &m)The assignment operator.
    symmetric_matrix &assign_temporary + (symmetric_matrix &m)Assigns a temporary. May change the symmetric matrix m.
    template<class AE>
    + symmetric_matrix &operator = (const + matrix_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    + symmetric_matrix &assign (const + matrix_expression<AE> &ae)
    Assigns a matrix expression to the symmetric matrix. + Left and right hand side of the assignment should be + independent.
    template<class AE>
    + symmetric_matrix &operator += (const + matrix_expression<AE> &ae)
    A computed assignment operator. Adds the matrix + expression to the symmetric matrix.
    template<class AE>
    + symmetric_matrix &plus_assign (const + matrix_expression<AE> &ae)
    Adds a matrix expression to the symmetric matrix. + Left and right hand side of the assignment should be + independent.
    template<class AE>
    + symmetric_matrix &operator -= (const + matrix_expression<AE> &ae)
    A computed assignment operator. Subtracts the matrix + expression from the symmetric matrix.
    template<class AE>
    + symmetric_matrix &minus_assign (const + matrix_expression<AE> &ae)
    Subtracts a matrix expression from the symmetric + matrix. Left and right hand side of the assignment should + be independent.
    template<class AT>
    + symmetric_matrix &operator *= (const AT &at)
    A computed assignment operator. Multiplies the + symmetric matrix with a scalar.
    template<class AT>
    + symmetric_matrix &operator /= (const AT &at)
    A computed assignment operator. Divides the symmetric + matrix through a scalar.
    void swap (symmetric_matrix &m)Swaps the contents of the symmetric matrices.
    void insert (size_type i, size_type j, + const_reference t)Inserts the value t at the j-th + element of the i-th row.
    void erase (size_type i, size_type j)Erases the value at the j-th elemenst of + the i-th row.
    void clear ()Clears the matrix.
    const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the symmetric_matrix.
    const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the symmetric_matrix.
    iterator1 begin1 () Returns a iterator1 pointing to the + beginning of the symmetric_matrix.
    iterator1 end1 () Returns a iterator1 pointing to the end + of the symmetric_matrix.
    const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the symmetric_matrix.
    const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the symmetric_matrix.
    iterator2 begin2 () Returns a iterator2 pointing to the + beginning of the symmetric_matrix.
    iterator2 end2 () Returns a iterator2 pointing to the end + of the symmetric_matrix.
    const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed symmetric_matrix. +
    const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed symmetric_matrix. +
    reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to + the beginning of the reversed symmetric_matrix. +
    reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to + the end of the reversed symmetric_matrix.
    const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed symmetric_matrix. +
    const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed symmetric_matrix. +
    reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to + the beginning of the reversed symmetric_matrix. +
    reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to + the end of the reversed symmetric_matrix.
    + +

    Notes

    + +

    [1] Supported parameters for +the type of the symmetric matrix are lower and upper.

    + +

    [2] Supported parameters for +the storage organization are row_major and column_major.

    + +

    [3] Supported parameters for +the adapted array are unbounded_array<T>, bounded_array<T> +and std::vector<T>.

    + +

    Interface

    + +
        // Array based symmetric matrix class 
    +    template<class T, class F1, class F2, class A>
    +    class symmetric_matrix: 
    +        public matrix_expression<symmetric_matrix<T, F1, F2, A> > {
    +    public:      
    +        typedef std::size_t size_type;
    +        typedef std::ptrdiff_t difference_type;
    +        typedef T value_type;
    +        typedef const T &const_reference;
    +        typedef T &reference;
    +        typedef const T *const_pointer;
    +        typedef T *pointer;
    +        typedef F1 functor1_type;
    +        typedef F2 functor2_type;
    +        typedef A array_type;
    +        typedef const A const_array_type;
    +        typedef const symmetric_matrix<T, F1, F2, A> const_self_type;
    +        typedef symmetric_matrix<T, F1, F2, A> self_type;
    +        typedef const matrix_const_reference<const_self_type> const_closure_type;
    +        typedef matrix_reference<self_type> closure_type;
    +        typedef packed_tag storage_category;
    +        typedef typename F1::packed_category packed_category;
    +        typedef typename F2::orientation_category orientation_category;
    +
    +        // Construction and destruction
    +        symmetric_matrix ();
    +        symmetric_matrix (size_type size);
    +        symmetric_matrix (size_type size1, size_type size2);
    +        symmetric_matrix (const symmetric_matrix &m);
    +        template<class AE>
    +        symmetric_matrix (const matrix_expression<AE> &ae);
    +
    +        // Accessors
    +        size_type size1 () const;
    +        size_type size2 () const;
    +        const_array_type &data () const;
    +        array_type &data ();
    +
    +        // Resizing
    +        void resize (size_type size);
    +        void resize (size_type size1, size_type size2);
    +
    +        // Element access
    +        const_reference operator () (size_type i, size_type j) const;
    +        reference operator () (size_type i, size_type j);
    +
    +        // Assignment
    +        symmetric_matrix &operator = (const symmetric_matrix &m);
    +        symmetric_matrix &assign_temporary (symmetric_matrix &m);
    +        template<class AE>
    +        symmetric_matrix &operator = (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        symmetric_matrix &reset (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        symmetric_matrix &assign (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        symmetric_matrix& operator += (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        symmetric_matrix &plus_assign (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        symmetric_matrix& operator -= (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        symmetric_matrix &minus_assign (const matrix_expression<AE> &ae);
    +        template<class AT>
    +        symmetric_matrix& operator *= (const AT &at);
    +        template<class AT>
    +        symmetric_matrix& operator /= (const AT &at);
    +
    +        // Swapping
    +        void swap (symmetric_matrix &m);
    +        friend void swap (symmetric_matrix &m1, symmetric_matrix &m2);
    +
    +        // Element insertion and erasure
    +        void insert (size_type i, size_type j, const_reference t);
    +        void erase (size_type i, size_type j);
    +        void clear ();
    +
    +        class const_iterator1;
    +        class iterator1;
    +        class const_iterator2;
    +        class iterator2;
    +        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
    +        typedef reverse_iterator_base1<iterator1> reverse_iterator1;
    +        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
    +        typedef reverse_iterator_base2<iterator2> reverse_iterator2;
    +
    +        // Element lookup
    +        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
    +        iterator1 find_first1 (int rank, size_type i, size_type j);
    +        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
    +        iterator1 find_last1 (int rank, size_type i, size_type j);
    +        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
    +        iterator2 find_first2 (int rank, size_type i, size_type j);
    +        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
    +        iterator2 find_last2 (int rank, size_type i, size_type j);
    +
    +        // Iterators simply are indices.
    +
    +        class const_iterator1:
    +            public container_const_reference<symmetric_matrix>,
    +            public random_access_iterator_base<const_iterator1, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename symmetric_matrix::difference_type difference_type;
    +            typedef typename symmetric_matrix::value_type value_type;
    +            typedef typename symmetric_matrix::const_reference reference;
    +            typedef typename symmetric_matrix::const_pointer pointer;
    +            typedef const_iterator2 dual_iterator_type;
    +            typedef const_reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator1 ();
    +            const_iterator1 (const symmetric_matrix &m, size_type it1, size_type it2);
    +            const_iterator1 (const iterator1 &it);
    +
    +            // Arithmetic
    +            const_iterator1 &operator ++ ();
    +            const_iterator1 &operator -- ();
    +            const_iterator1 &operator += (difference_type n);
    +            const_iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator2 begin () const;
    +            const_iterator2 end () const;
    +            const_reverse_iterator2 rbegin () const;
    +            const_reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator1 &operator = (const const_iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator1 &it) const;
    +            bool operator <(const const_iterator1 &it) const;
    +        };
    +
    +        const_iterator1 begin1 () const;
    +        const_iterator1 end1 () const;
    +
    +        class iterator1:
    +            public container_reference<symmetric_matrix>,
    +            public random_access_iterator_base<iterator1, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename symmetric_matrix::difference_type difference_type;
    +            typedef typename symmetric_matrix::value_type value_type;
    +            typedef typename symmetric_matrix::reference reference;
    +            typedef typename symmetric_matrix::pointer pointer;
    +            typedef iterator2 dual_iterator_type;
    +            typedef reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            iterator1 ();
    +            iterator1 (symmetric_matrix &m, size_type it1, size_type it2);
    +
    +            // Arithmetic
    +            iterator1 &operator ++ ();
    +            iterator1 &operator -- ();
    +            iterator1 &operator += (difference_type n);
    +            iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            iterator2 begin () const;
    +            iterator2 end () const;
    +            reverse_iterator2 rbegin () const;
    +            reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            iterator1 &operator = (const iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const iterator1 &it) const;
    +            bool operator <(const iterator1 &it) const;
    +        };
    +
    +        iterator1 begin1 ();
    +        iterator1 end1 ();
    +
    +        class const_iterator2:
    +            public container_const_reference<symmetric_matrix>,
    +            public random_access_iterator_base<const_iterator2, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename symmetric_matrix::difference_type difference_type;
    +            typedef typename symmetric_matrix::value_type value_type;
    +            typedef typename symmetric_matrix::const_reference reference;
    +            typedef typename symmetric_matrix::const_pointer pointer;
    +            typedef const_iterator1 dual_iterator_type;
    +            typedef const_reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator2 ();
    +            const_iterator2 (const symmetric_matrix &m, size_type it1, size_type it2);
    +            const_iterator2 (const iterator2 &it);
    +
    +            // Arithmetic
    +            const_iterator2 &operator ++ ();
    +            const_iterator2 &operator -- ();
    +            const_iterator2 &operator += (difference_type n);
    +            const_iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator1 begin () const;
    +            const_iterator1 end () const;
    +            const_reverse_iterator1 rbegin () const;
    +            const_reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator2 &operator = (const const_iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator2 &it) const;
    +            bool operator <(const const_iterator2 &it) const;
    +        };
    +
    +        const_iterator2 begin2 () const;
    +        const_iterator2 end2 () const;
    +
    +        class iterator2:
    +            public container_reference<symmetric_matrix>,
    +            public random_access_iterator_base<iterator2, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename symmetric_matrix::difference_type difference_type;
    +            typedef typename symmetric_matrix::value_type value_type;
    +            typedef typename symmetric_matrix::reference reference;
    +            typedef typename symmetric_matrix::pointer pointer;
    +            typedef iterator1 dual_iterator_type;
    +            typedef reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            iterator2 ();
    +            iterator2 (symmetric_matrix &m, size_type it1, size_type it2);
    +
    +            // Arithmetic
    +            iterator2 &operator ++ ();
    +            iterator2 &operator -- ();
    +            iterator2 &operator += (difference_type n);
    +            iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            iterator1 begin () const;
    +            iterator1 end () const;
    +            reverse_iterator1 rbegin () const;
    +            reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            iterator2 &operator = (const iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const iterator2 &it) const;
    +            bool operator <(const iterator2 &it) const;
    +        };
    +
    +        iterator2 begin2 ();
    +        iterator2 end2 ();
    +
    +        // Reverse iterators
    +
    +        const_reverse_iterator1 rbegin1 () const;
    +        const_reverse_iterator1 rend1 () const;
    +
    +        reverse_iterator1 rbegin1 ();
    +        reverse_iterator1 rend1 ();
    +
    +        const_reverse_iterator2 rbegin2 () const;
    +        const_reverse_iterator2 rend2 () const;
    +
    +        reverse_iterator2 rbegin2 ();
    +        reverse_iterator2 rend2 ();
    +    };
    + +

    Symmetric Adaptor

    + +

    Description

    + +

    The templated class symmetric_adaptor<M, F> is +a symmetric matrix adaptor for other matrices.

    + +

    Example

    + +
    int main () {
    +    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 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 j = i; j < sau.size2 (); ++ j)
    +            sau (i, j) = 3 * i + j;
    +    std::cout << sau << std::endl;
    +}
    + +

    Definition

    + +

    Defined in the header symmetric.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    MThe type of the adapted matrix. 
    FFunctor describing the type of the symmetric adaptor. + [1]lower
    + +

    Model of

    + +

    Matrix Expression. +

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Matrix Expression.

    + +

    Public base classes

    + +

    matrix_expression<symmetric_adaptor<M, F> > +

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    symmetric_adaptor () Constructs a symmetric_adaptor that + holds zero rows of zero elements.
    symmetric_adaptor (matrix_type &data)Constructs a symmetric_adaptor of a + matrix.
    symmetric_adaptor (const symmetric_adaptor + &m)The copy constructor.
    template<class AE>
    + symmetric_adaptor (const matrix_expression<AE> + &ae)
    The extended copy constructor.
    size_type size1 () constReturns the number of rows.
    size_type size2 () constReturns the number of columns.
    const_reference operator () (size_type i, + size_type j) constReturns a const reference of the j-th + element in the i-th row.
    reference operator () (size_type i, size_type + j)Returns a reference of the j-th element + in the i-th row.
    symmetric_adaptor &operator = (const + symmetric_adaptor &m)The assignment operator.
    symmetric_adaptor &assign_temporary + (symmetric_adaptor &m)Assigns a temporary. May change the symmetric adaptor + m.
    template<class AE>
    + symmetric_adaptor &operator = (const + matrix_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    + symmetric_adaptor &assign (const + matrix_expression<AE> &ae)
    Assigns a matrix expression to the symmetric adaptor. + Left and right hand side of the assignment should be + independent.
    template<class AE>
    + symmetric_adaptor &operator += (const + matrix_expression<AE> &ae)
    A computed assignment operator. Adds the matrix + expression to the symmetric adaptor.
    template<class AE>
    + symmetric_adaptor &plus_assign (const + matrix_expression<AE> &ae)
    Adds a matrix expression to the symmetric adaptor. + Left and right hand side of the assignment should be + independent.
    template<class AE>
    + symmetric_adaptor &operator -= (const + matrix_expression<AE> &ae)
    A computed assignment operator. Subtracts the matrix + expression from the symmetric adaptor.
    template<class AE>
    + symmetric_adaptor &minus_assign (const + matrix_expression<AE> &ae)
    Subtracts a matrix expression from the symmetric + adaptor. Left and right hand side of the assignment + should be independent.
    template<class AT>
    + symmetric_adaptor &operator *= (const AT &at)
    A computed assignment operator. Multiplies the + symmetric adaptor with a scalar.
    template<class AT>
    + symmetric_adaptor &operator /= (const AT &at)
    A computed assignment operator. Divides the symmetric + adaptor through a scalar.
    void swap (symmetric_adaptor &m)Swaps the contents of the symmetric adaptors.
    const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the symmetric_adaptor.
    const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the symmetric_adaptor.
    iterator1 begin1 () Returns a iterator1 pointing to the + beginning of the symmetric_adaptor.
    iterator1 end1 () Returns a iterator1 pointing to the end + of the symmetric_adaptor.
    const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the symmetric_adaptor.
    const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the symmetric_adaptor.
    iterator2 begin2 () Returns a iterator2 pointing to the + beginning of the symmetric_adaptor.
    iterator2 end2 () Returns a iterator2 pointing to the end + of the symmetric_adaptor.
    const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed symmetric_adaptor. +
    const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed symmetric_adaptor. +
    reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to + the beginning of the reversed symmetric_adaptor. +
    reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to + the end of the reversed symmetric_adaptor.
    const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed symmetric_adaptor. +
    const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed symmetric_adaptor. +
    reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to + the beginning of the reversed symmetric_adaptor. +
    reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to + the end of the reversed symmetric_adaptor.
    + +

    Notes

    + +

    [1] Supported parameters +for the type of the symmetric adaptor are lower and upper.

    + +

    Interface

    + +
        // Symmetric matrix adaptor class 
    +    template<class M, class F>
    +    class symmetric_adaptor: 
    +        public matrix_expression<symmetric_adaptor<M, F> > {
    +    public:      
    +        typedef const M const_matrix_type;
    +        typedef M matrix_type;
    +        typedef F functor_type;
    +        typedef typename M::size_type size_type;
    +        typedef typename M::difference_type difference_type;
    +        typedef typename M::value_type value_type;
    +        typedef typename M::const_reference const_reference;
    +        typedef typename M::reference reference;
    +        typedef typename M::const_pointer const_pointer;
    +        typedef typename M::pointer pointer;
    +        typedef const symmetric_adaptor<M, F> const_self_type;
    +        typedef symmetric_adaptor<M, F> self_type;
    +        typedef const matrix_const_reference<const_self_type> const_closure_type;
    +        typedef matrix_reference<self_type> closure_type;
    +        typedef typename storage_restrict_traits<typename M::storage_category,
    +                                                 packed_proxy_tag>::storage_category storage_category;
    +        typedef typename F::packed_category packed_category;
    +        typedef typename M::orientation_category orientation_category;
    +
    +        // Construction and destruction
    +        symmetric_adaptor ();
    +        symmetric_adaptor (matrix_type &data);
    +        symmetric_adaptor (const symmetric_adaptor &m);
    +
    +        // Accessors
    +        size_type size1 () const;
    +        size_type size2 () const;
    +        const_matrix_type &data () const;
    +        matrix_type &data ();
    +
    +
    +        // Element access
    +        const_reference operator () (size_type i, size_type j) const;
    +        reference operator () (size_type i, size_type j);
    +
    +        // Assignment
    +        symmetric_adaptor &operator = (const symmetric_adaptor &m);
    +        symmetric_adaptor &assign_temporary (symmetric_adaptor &m);
    +        template<class AE>
    +        symmetric_adaptor &operator = (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        symmetric_adaptor &assign (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        symmetric_adaptor& operator += (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        symmetric_adaptor &plus_assign (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        symmetric_adaptor& operator -= (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        symmetric_adaptor &minus_assign (const matrix_expression<AE> &ae);
    +        template<class AT>
    +        symmetric_adaptor& operator *= (const AT &at);
    +        template<class AT>
    +        symmetric_adaptor& operator /= (const AT &at);
    +
    +        // Swapping
    +        void swap (symmetric_adaptor &m);
    +        friend void swap (symmetric_adaptor &m1, symmetric_adaptor &m2);
    +
    +        class const_iterator1;
    +        class iterator1;
    +        class const_iterator2;
    +        class iterator2;
    +        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
    +        typedef reverse_iterator_base1<iterator1> reverse_iterator1;
    +        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
    +        typedef reverse_iterator_base2<iterator2> reverse_iterator2;
    +
    +        // Element lookup
    +        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
    +        iterator1 find_first1 (int rank, size_type i, size_type j);
    +        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
    +        iterator1 find_last1 (int rank, size_type i, size_type j);
    +        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
    +        iterator2 find_first2 (int rank, size_type i, size_type j);
    +        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
    +        iterator2 find_last2 (int rank, size_type i, size_type j);
    +
    +        // Iterators simply are indices.
    +
    +        class const_iterator1:
    +            public container_const_reference<symmetric_adaptor>,
    +            public random_access_iterator_base<const_iterator1, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename symmetric_adaptor::difference_type difference_type;
    +            typedef typename symmetric_adaptor::value_type value_type;
    +            typedef typename symmetric_adaptor::const_reference reference;
    +            typedef typename symmetric_adaptor::const_pointer pointer;
    +            typedef const_iterator2 dual_iterator_type;
    +            typedef const_reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator1 ();
    +            const_iterator1 (const symmetric_adaptor &m, size_type it1, size_type it2);
    +            const_iterator1 (const iterator1 &it);
    +
    +            // Arithmetic
    +            const_iterator1 &operator ++ ();
    +            const_iterator1 &operator -- ();
    +            const_iterator1 &operator += (difference_type n);
    +            const_iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator2 begin () const;
    +            const_iterator2 end () const;
    +            const_reverse_iterator2 rbegin () const;
    +            const_reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator1 &operator = (const const_iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator1 &it) const;
    +            bool operator <(const const_iterator1 &it) const;
    +        };
    +
    +        const_iterator1 begin1 () const;
    +        const_iterator1 end1 () const;
    +
    +        class iterator1:
    +            public container_reference<symmetric_adaptor>,
    +            public random_access_iterator_base<iterator1, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename symmetric_adaptor::difference_type difference_type;
    +            typedef typename symmetric_adaptor::value_type value_type;
    +            typedef typename symmetric_adaptor::reference reference;
    +            typedef typename symmetric_adaptor::pointer pointer;
    +            typedef iterator2 dual_iterator_type;
    +            typedef reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            iterator1 ();
    +            iterator1 (symmetric_adaptor &m, size_type it1, size_type it2);
    +
    +            // Arithmetic
    +            iterator1 &operator ++ ();
    +            iterator1 &operator -- ();
    +            iterator1 &operator += (difference_type n);
    +            iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            iterator2 begin () const;
    +            iterator2 end () const;
    +            reverse_iterator2 rbegin () const;
    +            reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            iterator1 &operator = (const iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const iterator1 &it) const;
    +            bool operator <(const iterator1 &it) const;
    +        };
    +
    +        iterator1 begin1 ();
    +        iterator1 end1 ();
    +
    +        class const_iterator2:
    +            public container_const_reference<symmetric_adaptor>,
    +            public random_access_iterator_base<const_iterator2, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename symmetric_adaptor::difference_type difference_type;
    +            typedef typename symmetric_adaptor::value_type value_type;
    +            typedef typename symmetric_adaptor::const_reference reference;
    +            typedef typename symmetric_adaptor::const_pointer pointer;
    +            typedef const_iterator1 dual_iterator_type;
    +            typedef const_reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator2 ();
    +            const_iterator2 (const symmetric_adaptor &m, size_type it1, size_type it2);
    +            const_iterator2 (const iterator2 &it);
    +
    +            // Arithmetic
    +            const_iterator2 &operator ++ ();
    +            const_iterator2 &operator -- ();
    +            const_iterator2 &operator += (difference_type n);
    +            const_iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator1 begin () const;
    +            const_iterator1 end () const;
    +            const_reverse_iterator1 rbegin () const;
    +            const_reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator2 &operator = (const const_iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator2 &it) const;
    +            bool operator <(const const_iterator2 &it) const;
    +        };
    +
    +        const_iterator2 begin2 () const;
    +        const_iterator2 end2 () const;
    +
    +        class iterator2:
    +            public container_reference<symmetric_adaptor>,
    +            public random_access_iterator_base<iterator2, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename symmetric_adaptor::difference_type difference_type;
    +            typedef typename symmetric_adaptor::value_type value_type;
    +            typedef typename symmetric_adaptor::reference reference;
    +            typedef typename symmetric_adaptor::pointer pointer;
    +            typedef iterator1 dual_iterator_type;
    +            typedef reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            iterator2 ();
    +            iterator2 (symmetric_adaptor &m, size_type it1, size_type it2);
    +
    +            // Arithmetic
    +            iterator2 &operator ++ ();
    +            iterator2 &operator -- ();
    +            iterator2 &operator += (difference_type n);
    +            iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            iterator1 begin () const;
    +            iterator1 end () const;
    +            reverse_iterator1 rbegin () const;
    +            reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            iterator2 &operator = (const iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const iterator2 &it) const;
    +            bool operator <(const iterator2 &it) const;
    +        };
    +
    +        iterator2 begin2 ();
    +        iterator2 end2 ();
    +
    +        // Reverse iterators
    +
    +        const_reverse_iterator1 rbegin1 () const;
    +        const_reverse_iterator1 rend1 () const;
    +
    +        reverse_iterator1 rbegin1 ();
    +        reverse_iterator1 rend1 ();
    +
    +        const_reverse_iterator2 rbegin2 () const;
    +        const_reverse_iterator2 rend2 () const;
    +
    +        reverse_iterator2 rbegin2 ();
    +        reverse_iterator2 rend2 ();
    +    };
    + +
    + +

    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/triangular.htm b/doc/triangular.htm new file mode 100644 index 00000000..394fa94d --- /dev/null +++ b/doc/triangular.htm @@ -0,0 +1,1218 @@ + + + + + +Triangular Matrix + + + + +

    c++boost.gifTriangular Matrix

    + +

    Triangular Matrix

    + +

    Description

    + +

    The templated class triangular_matrix<T, F1, F2, +A> is the base container adaptor for triangular +matrices. For a (n x n)-dimensional lower triangular +matrix and 0 <= i < n, 0 <= j < n +holds ti, j = 0, if i +> j. If furthermore holds ti, i= +1 the matrix is called unit lower triangular. For a (n x +n)-dimensional upper triangular matrix and 0 <= i +< n, 0 <= j < n holds ti, +j = 0, if i < j. If furthermore +holds ti, i= 1 the matrix is called +unit lower triangular. The storage of triangular matrices is +packed.

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    triangular_matrix<double, lower> ml (3, 3);
    +    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 j = i; j < m.size2 (); ++ j)
    +            mu (i, j) = 3 * i + j;
    +    std::cout << mu << std::endl;
    +}
    + +

    Definition

    + +

    Defined in the header triangular.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    T The type of object stored in the matrix.  
    F1Functor describing the type of the triangular matrix. + [1]lower
    F2Functor describing the storage organization. [2]row_major
    AThe type of the adapted array. [3]unbounded_array<T>
    + +

    Model of

    + +

    Matrix.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Matrix.

    + +

    Public base classes

    + +

    matrix_expression<triangular_matrix<T, F1, F2, +A> >

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    triangular_matrix () Allocates an uninitialized triangular_matrix + that holds zero rows of zero elements.
    triangular_matrix (size_type size1, size_type + size2)Allocates an uninitialized triangular_matrix + that holds size1 rows of size2 + elements.
    triangular_matrix (const triangular_matrix + &m)The copy constructor.
    template<class AE>
    + triangular_matrix (const matrix_expression<AE> + &ae)
    The extended copy constructor.
    void resize (size_type size1, size_type size2)Reallocates a triangular_matrix to hold size1 + rows of size2 elements. The content of the triangular_matrix + is not preserved.
    size_type size1 () constReturns the number of rows.
    size_type size2 () constReturns the number of columns.
    const_reference operator () (size_type i, + size_type j) constReturns a const reference of the j-th + element in the i-th row.
    reference operator () (size_type i, size_type + j)Returns a reference of the j-th element + in the i-th row.
    triangular_matrix &operator = (const + triangular_matrix &m)The assignment operator.
    triangular_matrix &assign_temporary + (triangular_matrix &m)Assigns a temporary. May change the triangular matrix + m.
    template<class AE>
    + triangular_matrix &operator = (const + matrix_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    + triangular_matrix &assign (const + matrix_expression<AE> &ae)
    Assigns a matrix expression to the triangular matrix. + Left and right hand side of the assignment should be + independent.
    template<class AE>
    + triangular_matrix &operator += (const + matrix_expression<AE> &ae)
    A computed assignment operator. Adds the matrix + expression to the triangular matrix.
    template<class AE>
    + triangular_matrix &plus_assign (const + matrix_expression<AE> &ae)
    Adds a matrix expression to the triangular matrix. + Left and right hand side of the assignment should be + independent.
    template<class AE>
    + triangular_matrix &operator -= (const + matrix_expression<AE> &ae)
    A computed assignment operator. Subtracts the matrix + expression from the triangular matrix.
    template<class AE>
    + triangular_matrix &minus_assign (const + matrix_expression<AE> &ae)
    Subtracts a matrix expression from the triangular + matrix. Left and right hand side of the assignment should + be independent.
    template<class AT>
    + triangular_matrix &operator *= (const AT &at)
    A computed assignment operator. Multiplies the + triangular matrix with a scalar.
    template<class AT>
    + triangular_matrix &operator /= (const AT &at)
    A computed assignment operator. Divides the + triangular matrix through a scalar.
    void swap (triangular_matrix &m)Swaps the contents of the triangular matrices.
    void insert (size_type i, size_type j, + const_reference t)Inserts the value t at the j-th + element of the i-th row.
    void erase (size_type i, size_type j)Erases the value at the j-th elemenst of + the i-th row.
    void clear ()Clears the matrix.
    const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the triangular_matrix.
    const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the triangular_matrix.
    iterator1 begin1 () Returns a iterator1 pointing to the + beginning of the triangular_matrix.
    iterator1 end1 () Returns a iterator1 pointing to the end + of the triangular_matrix.
    const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the triangular_matrix.
    const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the triangular_matrix.
    iterator2 begin2 () Returns a iterator2 pointing to the + beginning of the triangular_matrix.
    iterator2 end2 () Returns a iterator2 pointing to the end + of the triangular_matrix.
    const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed triangular_matrix. +
    const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed triangular_matrix. +
    reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to + the beginning of the reversed triangular_matrix. +
    reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to + the end of the reversed triangular_matrix.
    const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed triangular_matrix. +
    const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed triangular_matrix. +
    reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to + the beginning of the reversed triangular_matrix. +
    reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to + the end of the reversed triangular_matrix.
    + +

    Notes

    + +

    [1] Supported parameters +for the type of the triangular matrix are lower, unit_lower, +upper and unit_upper.

    + +

    [2] Supported parameters +for the storage organization are row_major and column_major.

    + +

    [3] Supported parameters +for the adapted array are unbounded_array<T>, bounded_array<T> +and std::vector<T>.

    + +

    Interface

    + +
        // Array based triangular matrix class 
    +    template<class T, class F1, class F2, class A>
    +    class triangular_matrix: 
    +        public matrix_expression<triangular_matrix<T, F1, F2, A> > {
    +    public:      
    +        typedef std::size_t size_type;
    +        typedef std::ptrdiff_t difference_type;
    +        typedef T value_type;
    +        typedef const T &const_reference;
    +        typedef T &reference;
    +        typedef const T *const_pointer;
    +        typedef T *pointer;
    +        typedef F1 functor1_type;
    +        typedef F2 functor2_type;
    +        typedef A array_type;
    +        typedef const A const_array_type;
    +        typedef const triangular_matrix<T, F1, F2, A> const_self_type;
    +        typedef triangular_matrix<T, F1, F2, A> self_type;
    +        typedef const matrix_const_reference<const_self_type> const_closure_type;
    +        typedef matrix_reference<self_type> closure_type;
    +        typedef packed_tag storage_category;
    +        typedef typename F1::packed_category packed_category;
    +        typedef typename F2::orientation_category orientation_category;
    +
    +        // Construction and destruction
    +        triangular_matrix ();
    +        triangular_matrix (size_type size1, size_type size2);
    +        triangular_matrix (const triangular_matrix &m);
    +        template<class AE>
    +        triangular_matrix (const matrix_expression<AE> &ae);
    +
    +        // Accessors
    +        size_type size1 () const;
    +        size_type size2 () const;
    +        const_array_type &data () const;
    +        array_type &data ();
    +
    +        // Resizing
    +        void resize (size_type size1, size_type size2);
    +
    +        // Element access
    +        const_reference operator () (size_type i, size_type j) const;
    +        reference operator () (size_type i, size_type j);
    +
    +        // Assignment
    +        triangular_matrix &operator = (const triangular_matrix &m);
    +        triangular_matrix &assign_temporary (triangular_matrix &m);
    +        template<class AE>
    +        triangular_matrix &operator = (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        triangular_matrix &reset (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        triangular_matrix &assign (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        triangular_matrix& operator += (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        triangular_matrix &plus_assign (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        triangular_matrix& operator -= (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        triangular_matrix &minus_assign (const matrix_expression<AE> &ae);
    +        template<class AT>
    +        triangular_matrix& operator *= (const AT &at);
    +        template<class AT>
    +        triangular_matrix& operator /= (const AT &at);
    +
    +        // Swapping
    +        void swap (triangular_matrix &m);
    +        friend void swap (triangular_matrix &m1, triangular_matrix &m2);
    +
    +        // Element insertion and erasure
    +        void insert (size_type i, size_type j, const_reference t);
    +        void erase (size_type i, size_type j);
    +        void clear ();
    +
    +        class const_iterator1;
    +        class iterator1;
    +        class const_iterator2;
    +        class iterator2;
    +        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
    +        typedef reverse_iterator_base1<iterator1> reverse_iterator1;
    +        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
    +        typedef reverse_iterator_base2<iterator2> reverse_iterator2;
    +
    +        // Element lookup
    +        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
    +        iterator1 find_first1 (int rank, size_type i, size_type j);
    +        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
    +        iterator1 find_last1 (int rank, size_type i, size_type j);
    +        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
    +        iterator2 find_first2 (int rank, size_type i, size_type j);
    +        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
    +        iterator2 find_last2 (int rank, size_type i, size_type j);
    +
    +        // Iterators simply are indices.
    +
    +        class const_iterator1:
    +            public container_const_reference<triangular_matrix>,
    +            public random_access_iterator_base<const_iterator1, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename triangular_matrix::difference_type difference_type;
    +            typedef typename triangular_matrix::value_type value_type;
    +            typedef typename triangular_matrix::const_reference reference;
    +            typedef typename triangular_matrix::const_pointer pointer;
    +            typedef const_iterator2 dual_iterator_type;
    +            typedef const_reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator1 ();
    +            const_iterator1 (const triangular_matrix &m, size_type it1, size_type it2);
    +            const_iterator1 (const iterator1 &it);
    +
    +            // Arithmetic
    +            const_iterator1 &operator ++ ();
    +            const_iterator1 &operator -- ();
    +            const_iterator1 &operator += (difference_type n);
    +            const_iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator2 begin () const;
    +            const_iterator2 end () const;
    +            const_reverse_iterator2 rbegin () const;
    +            const_reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator1 &operator = (const const_iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator1 &it) const;
    +            bool operator <(const const_iterator1 &it) const;
    +        };
    +
    +        const_iterator1 begin1 () const;
    +        const_iterator1 end1 () const;
    +
    +        class iterator1:
    +            public container_reference<triangular_matrix>,
    +            public random_access_iterator_base<iterator1, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename triangular_matrix::difference_type difference_type;
    +            typedef typename triangular_matrix::value_type value_type;
    +            typedef typename triangular_matrix::reference reference;
    +            typedef typename triangular_matrix::pointer pointer;
    +            typedef iterator2 dual_iterator_type;
    +            typedef reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            iterator1 ();
    +            iterator1 (triangular_matrix &m, size_type it1, size_type it2);
    +
    +            // Arithmetic
    +            iterator1 &operator ++ ();
    +            iterator1 &operator -- ();
    +            iterator1 &operator += (difference_type n);
    +            iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            iterator2 begin () const;
    +            iterator2 end () const;
    +            reverse_iterator2 rbegin () const;
    +            reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            iterator1 &operator = (const iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const iterator1 &it) const;
    +            bool operator <(const iterator1 &it) const;
    +        };
    +
    +        iterator1 begin1 ();
    +        iterator1 end1 ();
    +
    +        class const_iterator2:
    +            public container_const_reference<triangular_matrix>,
    +            public random_access_iterator_base<const_iterator2, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename triangular_matrix::difference_type difference_type;
    +            typedef typename triangular_matrix::value_type value_type;
    +            typedef typename triangular_matrix::const_reference reference;
    +            typedef typename triangular_matrix::const_pointer pointer;
    +            typedef const_iterator1 dual_iterator_type;
    +            typedef const_reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator2 ();
    +            const_iterator2 (const triangular_matrix &m, size_type it1, size_type it2);
    +            const_iterator2 (const iterator2 &it);
    +
    +            // Arithmetic
    +            const_iterator2 &operator ++ ();
    +            const_iterator2 &operator -- ();
    +            const_iterator2 &operator += (difference_type n);
    +            const_iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator1 begin () const;
    +            const_iterator1 end () const;
    +            const_reverse_iterator1 rbegin () const;
    +            const_reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator2 &operator = (const const_iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator2 &it) const;
    +            bool operator <(const const_iterator2 &it) const;
    +        };
    +
    +        const_iterator2 begin2 () const;
    +        const_iterator2 end2 () const;
    +
    +        class iterator2:
    +            public container_reference<triangular_matrix>,
    +            public random_access_iterator_base<iterator2, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename triangular_matrix::difference_type difference_type;
    +            typedef typename triangular_matrix::value_type value_type;
    +            typedef typename triangular_matrix::reference reference;
    +            typedef typename triangular_matrix::pointer pointer;
    +            typedef iterator1 dual_iterator_type;
    +            typedef reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            iterator2 ();
    +            iterator2 (triangular_matrix &m, size_type it1, size_type it2);
    +
    +            // Arithmetic
    +            iterator2 &operator ++ ();
    +            iterator2 &operator -- ();
    +            iterator2 &operator += (difference_type n);
    +            iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            iterator1 begin () const;
    +            iterator1 end () const;
    +            reverse_iterator1 rbegin () const;
    +            reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            iterator2 &operator = (const iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const iterator2 &it) const;
    +            bool operator <(const iterator2 &it) const;
    +        };
    +
    +        iterator2 begin2 ();
    +        iterator2 end2 ();
    +
    +        // Reverse iterators
    +
    +        const_reverse_iterator1 rbegin1 () const;
    +        const_reverse_iterator1 rend1 () const;
    +
    +        reverse_iterator1 rbegin1 ();
    +        reverse_iterator1 rend1 ();
    +
    +        const_reverse_iterator2 rbegin2 () const;
    +        const_reverse_iterator2 rend2 () const;
    +
    +        reverse_iterator2 rbegin2 ();
    +        reverse_iterator2 rend2 ();
    +    };
    + +

    Triangular Adaptor

    + +

    Description

    + +

    The templated class triangular_adaptor<M, F> is +a triangular matrix adaptor for other matrices.

    + +

    Example

    + +
    int main () {
    +    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 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 j = i; j < tau.size2 (); ++ j)
    +            tau (i, j) = 3 * i + j;
    +    std::cout << tau << std::endl;
    +}
    + +

    Definition

    + +

    Defined in the header triangular.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    MThe type of the adapted matrix. 
    FFunctor describing the type of the triangular + adaptor. [1]lower
    + +

    Model of

    + +

    Matrix Expression. +

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Matrix Expression.

    + +

    Public base classes

    + +

    matrix_expression<triangular_adaptor<M, F> > +

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    triangular_adaptor () Constructs a triangular_adaptor that + holds zero rows of zero elements.
    triangular_adaptor (matrix_type &data)Constructs a triangular_adaptor of a + matrix.
    triangular_adaptor (const triangular_adaptor + &m)The copy constructor.
    template<class AE>
    + triangular_adaptor (const matrix_expression<AE> + &ae)
    The extended copy constructor.
    size_type size1 () constReturns the number of rows.
    size_type size2 () constReturns the number of columns.
    const_reference operator () (size_type i, + size_type j) constReturns a const reference of the j-th + element in the i-th row.
    reference operator () (size_type i, size_type + j)Returns a reference of the j-th element + in the i-th row.
    triangular_adaptor &operator = (const + triangular_adaptor &m)The assignment operator.
    triangular_adaptor &assign_temporary + (triangular_adaptor &m)Assigns a temporary. May change the triangular + adaptor m.
    template<class AE>
    + triangular_adaptor &operator = (const + matrix_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    + triangular_adaptor &assign (const + matrix_expression<AE> &ae)
    Assigns a matrix expression to the triangular + adaptor. Left and right hand side of the assignment + should be independent.
    template<class AE>
    + triangular_adaptor &operator += (const + matrix_expression<AE> &ae)
    A computed assignment operator. Adds the matrix + expression to the triangular adaptor.
    template<class AE>
    + triangular_adaptor &plus_assign (const + matrix_expression<AE> &ae)
    Adds a matrix expression to the triangular adaptor. + Left and right hand side of the assignment should be + independent.
    template<class AE>
    + triangular_adaptor &operator -= (const + matrix_expression<AE> &ae)
    A computed assignment operator. Subtracts the matrix + expression from the triangular adaptor.
    template<class AE>
    + triangular_adaptor &minus_assign (const + matrix_expression<AE> &ae)
    Subtracts a matrix expression from the triangular + adaptor. Left and right hand side of the assignment + should be independent.
    template<class AT>
    + triangular_adaptor &operator *= (const AT &at)
    A computed assignment operator. Multiplies the + triangular adaptor with a scalar.
    template<class AT>
    + triangular_adaptor &operator /= (const AT &at)
    A computed assignment operator. Divides the + triangular adaptor through a scalar.
    void swap (triangular_adaptor &m)Swaps the contents of the triangular adaptors.
    const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the triangular_adaptor.
    const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the triangular_adaptor.
    iterator1 begin1 () Returns a iterator1 pointing to the + beginning of the triangular_adaptor.
    iterator1 end1 () Returns a iterator1 pointing to the end + of the triangular_adaptor.
    const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the triangular_adaptor.
    const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the triangular_adaptor.
    iterator2 begin2 () Returns a iterator2 pointing to the + beginning of the triangular_adaptor.
    iterator2 end2 () Returns a iterator2 pointing to the end + of the triangular_adaptor.
    const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed triangular_adaptor. +
    const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed triangular_adaptor. +
    reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to + the beginning of the reversed triangular_adaptor. +
    reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to + the end of the reversed triangular_adaptor.
    const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed triangular_adaptor. +
    const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed triangular_adaptor. +
    reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to + the beginning of the reversed triangular_adaptor. +
    reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to + the end of the reversed triangular_adaptor.
    + +

    Notes

    + +

    [1] Supported parameters +for the type of the triangular adaptor are lower, unit_lower, +upper and unit_upper.

    + +

    Interface

    + +
        // Triangular matrix adaptor class 
    +    template<class M, class F>
    +    class triangular_adaptor: 
    +        public matrix_expression<triangular_adaptor<M, F> > {
    +    public:      
    +        typedef const M const_matrix_type;
    +        typedef M matrix_type;
    +        typedef F functor_type;
    +        typedef typename M::size_type size_type;
    +        typedef typename M::difference_type difference_type;
    +        typedef typename M::value_type value_type;
    +        typedef typename M::const_reference const_reference;
    +        typedef typename M::reference reference;
    +        typedef typename M::const_pointer const_pointer;
    +        typedef typename M::pointer pointer;
    +        typedef const triangular_adaptor<M, F> const_self_type;
    +        typedef triangular_adaptor<M, F> self_type;
    +        typedef const matrix_const_reference<const_self_type> const_closure_type;
    +        typedef matrix_reference<self_type> closure_type;
    +        typedef typename storage_restrict_traits<typename M::storage_category,
    +                                                 packed_proxy_tag>::storage_category storage_category;
    +        typedef typename F::packed_category packed_category;
    +        typedef typename M::orientation_category orientation_category;
    +
    +        // Construction and destruction
    +        triangular_adaptor ();
    +        triangular_adaptor (matrix_type &data);
    +        triangular_adaptor (const triangular_adaptor &m);
    +
    +        // Accessors
    +        size_type size1 () const;
    +        size_type size2 () const;
    +        const_matrix_type &data () const;
    +        matrix_type &data ();
    +
    +
    +        // Element access
    +        const_reference operator () (size_type i, size_type j) const;
    +        reference operator () (size_type i, size_type j);
    +
    +        // Assignment
    +        triangular_adaptor &operator = (const triangular_adaptor &m);
    +        triangular_adaptor &assign_temporary (triangular_adaptor &m);
    +        template<class AE>
    +        triangular_adaptor &operator = (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        triangular_adaptor &assign (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        triangular_adaptor& operator += (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        triangular_adaptor &plus_assign (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        triangular_adaptor& operator -= (const matrix_expression<AE> &ae);
    +        template<class AE>
    +        triangular_adaptor &minus_assign (const matrix_expression<AE> &ae);
    +        template<class AT>
    +        triangular_adaptor& operator *= (const AT &at);
    +        template<class AT>
    +        triangular_adaptor& operator /= (const AT &at);
    +
    +        // Swapping
    +        void swap (triangular_adaptor &m);
    +        friend void swap (triangular_adaptor &m1, triangular_adaptor &m2);
    +
    +        class const_iterator1;
    +        class iterator1;
    +        class const_iterator2;
    +        class iterator2;
    +        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
    +        typedef reverse_iterator_base1<iterator1> reverse_iterator1;
    +        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
    +        typedef reverse_iterator_base2<iterator2> reverse_iterator2;
    +
    +        // Element lookup
    +        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
    +        iterator1 find_first1 (int rank, size_type i, size_type j);
    +        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
    +        iterator1 find_last1 (int rank, size_type i, size_type j);
    +        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
    +        iterator2 find_first2 (int rank, size_type i, size_type j);
    +        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
    +        iterator2 find_last2 (int rank, size_type i, size_type j);
    +
    +        // Iterators simply are indices.
    +
    +        class const_iterator1:
    +            public container_const_reference<triangular_adaptor>,
    +            public random_access_iterator_base<const_iterator1, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename triangular_adaptor::difference_type difference_type;
    +            typedef typename triangular_adaptor::value_type value_type;
    +            typedef typename triangular_adaptor::const_reference reference;
    +            typedef typename triangular_adaptor::const_pointer pointer;
    +            typedef const_iterator2 dual_iterator_type;
    +            typedef const_reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator1 ();
    +            const_iterator1 (const triangular_adaptor &m, size_type it1, size_type it2);
    +            const_iterator1 (const iterator1 &it);
    +
    +            // Arithmetic
    +            const_iterator1 &operator ++ ();
    +            const_iterator1 &operator -- ();
    +            const_iterator1 &operator += (difference_type n);
    +            const_iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator2 begin () const;
    +            const_iterator2 end () const;
    +            const_reverse_iterator2 rbegin () const;
    +            const_reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator1 &operator = (const const_iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator1 &it) const;
    +            bool operator <(const const_iterator1 &it) const;
    +        };
    +
    +        const_iterator1 begin1 () const;
    +        const_iterator1 end1 () const;
    +
    +        class iterator1:
    +            public container_reference<triangular_adaptor>,
    +            public random_access_iterator_base<iterator1, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename triangular_adaptor::difference_type difference_type;
    +            typedef typename triangular_adaptor::value_type value_type;
    +            typedef typename triangular_adaptor::reference reference;
    +            typedef typename triangular_adaptor::pointer pointer;
    +            typedef iterator2 dual_iterator_type;
    +            typedef reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            iterator1 ();
    +            iterator1 (triangular_adaptor &m, size_type it1, size_type it2);
    +
    +            // Arithmetic
    +            iterator1 &operator ++ ();
    +            iterator1 &operator -- ();
    +            iterator1 &operator += (difference_type n);
    +            iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            iterator2 begin () const;
    +            iterator2 end () const;
    +            reverse_iterator2 rbegin () const;
    +            reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            iterator1 &operator = (const iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const iterator1 &it) const;
    +            bool operator <(const iterator1 &it) const;
    +        };
    +
    +        iterator1 begin1 ();
    +        iterator1 end1 ();
    +
    +        class const_iterator2:
    +            public container_const_reference<triangular_adaptor>,
    +            public random_access_iterator_base<const_iterator2, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename triangular_adaptor::difference_type difference_type;
    +            typedef typename triangular_adaptor::value_type value_type;
    +            typedef typename triangular_adaptor::const_reference reference;
    +            typedef typename triangular_adaptor::const_pointer pointer;
    +            typedef const_iterator1 dual_iterator_type;
    +            typedef const_reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator2 ();
    +            const_iterator2 (const triangular_adaptor &m, size_type it1, size_type it2);
    +            const_iterator2 (const iterator2 &it);
    +
    +            // Arithmetic
    +            const_iterator2 &operator ++ ();
    +            const_iterator2 &operator -- ();
    +            const_iterator2 &operator += (difference_type n);
    +            const_iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator1 begin () const;
    +            const_iterator1 end () const;
    +            const_reverse_iterator1 rbegin () const;
    +            const_reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            const_iterator2 &operator = (const const_iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator2 &it) const;
    +            bool operator <(const const_iterator2 &it) const;
    +        };
    +
    +        const_iterator2 begin2 () const;
    +        const_iterator2 end2 () const;
    +
    +        class iterator2:
    +            public container_reference<triangular_adaptor>,
    +            public random_access_iterator_base<iterator2, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename triangular_adaptor::difference_type difference_type;
    +            typedef typename triangular_adaptor::value_type value_type;
    +            typedef typename triangular_adaptor::reference reference;
    +            typedef typename triangular_adaptor::pointer pointer;
    +            typedef iterator1 dual_iterator_type;
    +            typedef reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            iterator2 ();
    +            iterator2 (triangular_adaptor &m, size_type it1, size_type it2);
    +
    +            // Arithmetic
    +            iterator2 &operator ++ ();
    +            iterator2 &operator -- ();
    +            iterator2 &operator += (difference_type n);
    +            iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            iterator1 begin () const;
    +            iterator1 end () const;
    +            reverse_iterator1 rbegin () const;
    +            reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type index2 () const;
    +
    +            // Assignment 
    +            iterator2 &operator = (const iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const iterator2 &it) const;
    +            bool operator <(const iterator2 &it) const;
    +        };
    +
    +        iterator2 begin2 ();
    +        iterator2 end2 ();
    +
    +        // Reverse iterators
    +
    +        const_reverse_iterator1 rbegin1 () const;
    +        const_reverse_iterator1 rend1 () const;
    +
    +        reverse_iterator1 rbegin1 ();
    +        reverse_iterator1 rend1 ();
    +
    +        const_reverse_iterator2 rbegin2 () const;
    +        const_reverse_iterator2 rend2 () const;
    +
    +        reverse_iterator2 rbegin2 ();
    +        reverse_iterator2 rend2 ();
    +    };
    + +
    + +

    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.htm b/doc/vector.htm new file mode 100644 index 00000000..86bae77a --- /dev/null +++ b/doc/vector.htm @@ -0,0 +1,898 @@ + + + + + +Vector + + + + +

    c++boost.gifVector

    + +

    Vector

    + +

    Description

    + +

    The templated class vector<T, A> is the +base container adaptor for dense vectors. For a n-dimensional +vector and 0 <= i < n every element vi +is mapped to the i-th element of the container.

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    vector<double> v (3);
    +    for (int i = 0; i < v.size (); ++ i)
    +        v (i) = i;
    +    std::cout << v << std::endl;
    +}
    + +

    Definition

    + +

    Defined in the header vector.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    T The type of object stored in the vector.  
    AThe type of the adapted array.unbounded_array<T>
    + +

    Model of

    + +

    Vector.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector.

    + +

    Public base classes

    + +

    vector_expression<vector<T, A> >

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    vector () Allocates an uninitialized vector that + holds zero elements.
    vector (size_type size)Allocates an uninitialized vector that + holds size elements.
    vector (const vector &v)The copy constructor.
    template<class AE>
    + vector (const vector_expression<AE> &ae)
    The extended copy constructor.
    void resize (size_type size)Reallocates a vector to hold size + elements. The content of the vector is not + preserved.
    size_type size () constReturns the size of the vector.
    const_reference operator () (size_type i) constReturns a const reference of the i-th + element.
    reference operator () (size_type i)Returns a reference of the i-th element. +
    const_reference operator [] (size_type i) constReturns a const reference of the i-th + element.
    reference operator [] (size_type i)Returns a reference of the i-th element. +
    vector &operator = (const vector &v)The assignment operator.
    vector &assign_temporary (vector &v)Assigns a temporary. May change the vector v.
    template<class AE>
    + vector &operator = (const vector_expression<AE> + &ae)
    The extended assignment operator.
    template<class AE>
    + vector &assign (const vector_expression<AE> + &ae)
    Assigns a vector expression to the vector. Left and + right hand side of the assignment should be independent.
    template<class AE>
    + vector &operator += (const + vector_expression<AE> &ae)
    A computed assignment operator. Adds the vector + expression to the vector.
    template<class AE>
    + vector &plus_assign (const + vector_expression<AE> &ae)
    Adds a vector expression to the vector. Left and + right hand side of the assignment should be independent.
    template<class AE>
    + vector &operator -= (const + vector_expression<AE> &ae)
    A computed assignment operator. Subtracts the vector + expression from the vector.
    template<class AE>
    + vector &minus_assign (const + vector_expression<AE> &ae)
    Subtracts a vector expression from the vector. Left + and right hand side of the assignment should be + independent.
    template<class AT>
    + vector &operator *= (const AT &at)
    A computed assignment operator. Multiplies the vector + with a scalar.
    template<class AT>
    + vector &operator /= (const AT &at)
    A computed assignment operator. Divides the vector + through a scalar.
    void swap (vector &v)Swaps the contents of the vectors.
    void insert (size_type i, const_reference t)Inserts the value t at the i-th + element.
    void erase (size_type i)Erases the value at the i-th element.
    void clear ()Clears the vector.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the vector.
    const_iterator end () constReturns a const_iterator pointing to the + end of the vector.
    iterator begin () Returns a iterator pointing to the + beginning of the vector.
    iterator end () Returns a iterator pointing to the end + of the vector.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed vector. +
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed vector.
    reverse_iterator rbegin () Returns a reverse_iterator pointing to + the beginning of the reversed vector.
    reverse_iterator rend () Returns a reverse_iterator pointing to + the end of the reversed vector.
    + +

    Interface

    + +
        // Array based vector class 
    +    template<class T, class A>
    +    class vector: 
    +        public vector_expression<vector<T, A> > {
    +    public:      
    +        typedef std::size_t size_type;
    +        typedef std::ptrdiff_t difference_type;
    +        typedef T value_type;
    +        typedef const T &const_reference;
    +        typedef T &reference;
    +        typedef const T *const_pointer;
    +        typedef T *pointer;
    +        typedef F functor_type;
    +        typedef A array_type;
    +        typedef const A const_array_type;
    +        typedef const vector<T, A> const_self_type;
    +        typedef vector<T, A> self_type;
    +        typedef const vector_const_reference<const_self_type> const_closure_type;
    +        typedef vector_reference<self_type> closure_type;
    +        typedef typename A::const_iterator const_iterator_type;
    +        typedef typename A::iterator iterator_type;
    +        typedef dense_tag storage_category;
    +
    +        // Construction and destruction
    +        vector ();
    +        vector (size_type size);
    +        vector (const vector &v);
    +        template<class AE>
    +        vector (const vector_expression<AE> &ae);
    +
    +        // Accessors
    +        size_type size () const;
    +        const_array_type &data () const;
    +        array_type &data ();
    +
    +        // Resizing
    +        void resize (size_type size);
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +        reference operator () (size_type i);
    +
    +        const_reference operator [] (size_type i) const;
    +        reference operator [] (size_type i);
    +
    +        // Assignment
    +        vector &operator = (const vector &v);
    +        vector &assign_temporary (vector &v);
    +        template<class AE>
    +        vector &operator = (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector &reset (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector &assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector &operator += (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector &plus_assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector &operator -= (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector &minus_assign (const vector_expression<AE> &ae);
    +        template<class AT>
    +        vector &operator *= (const AT &at);
    +        template<class AT>
    +        vector &operator /= (const AT &at);
    +
    +        // Swapping
    +        void swap (vector &v);
    +        friend void swap (vector &v1, vector &v2);
    +
    +        // Element insertion and erasure
    +        void insert (size_type i, const_reference t);
    +        void erase (size_type i);
    +        void clear ();
    +
    +        class const_iterator;
    +        class iterator;
    +
    +        // Element lookup
    +        const_iterator find (size_type i) const;
    +        iterator find (size_type i);
    +        const_iterator find_first (size_type i) const;
    +        iterator find_first (size_type i);
    +        const_iterator find_last (size_type i) const;
    +        iterator find_last (size_type i);
    +
    +        // Iterators simply are pointers.
    +
    +        class const_iterator:
    +            public container_const_reference<vector>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef dense_random_access_iterator_tag iterator_category;
    +            typedef typename vector::difference_type difference_type;
    +            typedef typename vector::value_type value_type;
    +            typedef typename vector::const_reference reference;
    +            typedef typename vector::const_pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const vector &v, const const_iterator_type &it);
    +            const_iterator (const iterator &it):
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +            bool operator < (const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        class iterator:
    +            public container_reference<vector>,
    +            public random_access_iterator_base<iterator, value_type> {
    +        public:
    +            typedef dense_random_access_iterator_tag iterator_category;
    +            typedef typename vector::difference_type difference_type;
    +            typedef typename vector::value_type value_type;
    +            typedef typename vector::reference reference;
    +            typedef typename vector::pointer pointer;
    +
    +            // Construction and destruction
    +            iterator ();
    +            iterator (vector &v, const iterator_type &it);
    +
    +            // Arithmetic
    +            iterator &operator ++ ();
    +            iterator &operator -- ();
    +            iterator &operator += (difference_type n);
    +            iterator &operator -= (difference_type n);
    +            difference_type operator - (const iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment
    +            iterator &operator = (const iterator &it);
    +
    +            // Comparison
    +            bool operator == (const iterator &it) const;
    +            bool operator < (const const_iterator &it) const;
    +        };
    +
    +        iterator begin ();
    +        iterator end ();
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +
    +        typedef reverse_iterator_base<iterator> reverse_iterator;
    +
    +        reverse_iterator rbegin ();
    +        reverse_iterator rend ();
    +    }; 
    + +

    Unit Vector

    + +

    Description

    + +

    The templated class unit_vector<T> represents +canonical unit vectors. For the k-th n-dimensional +canonical unit vector and 0 <= i < n holds uki += 0, if i <> k, and uki += 1.

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    for (int i = 0; i < 3; ++ i) {
    +        unit_vector<double> v (3, i);
    +        std::cout << v << std::endl;
    +    }
    +}
    + +

    Definition

    + +

    Defined in the header vector.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + +
    Parameter Description Default
    T The type of object stored in the vector.  
    + +

    Model of

    + +

    Vector Expression. +

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector Expression.

    + +

    Public base classes

    + +

    vector_expression<unit_vector<T> >

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    unit_vector () Constructs an unit_vector that holds + zero elements.
    unit_vector (size_type size, size_type index)Constructs the index-th unit_vector + that holds size elements.
    unit_vector (const unit_vector &v)The copy constructor.
    void resize (size_type size)Resizes a unit_vector to hold size + elements.
    size_type size () constReturns the size of the unit_vector.
    size_type index () constReturns the index of the unit_vector.
    const_reference operator () (size_type i) constReturns the value of the i-th element.
    const_reference operator [] (size_type i) constReturns the value of the i-th element.
    unit_vector &operator = (const unit_vector + &v)The assignment operator.
    unit_vector &assign_temporary (unit_vector + &v)Assigns a temporary. May change the unit vector v.
    void swap (unit_vector &v)Swaps the contents of the unit vectors.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the unit_vector.
    const_iterator end () constReturns a const_iterator pointing to the + end of the unit_vector.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed unit_vector. +
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed unit_vector. +
    + +

    Interface

    + +
        // Unit vector class 
    +    template<class T>
    +    class unit_vector: 
    +        public vector_expression<unit_vector<T> > {
    +    public:      
    +        typedef std::size_t size_type;
    +        typedef std::ptrdiff_t difference_type;
    +        typedef T value_type;
    +        typedef const T &const_reference;
    +        typedef T &reference;
    +        typedef const T *const_pointer;
    +        typedef T *pointer;
    +        typedef const unit_vector<T> const_self_type;
    +        typedef unit_vector<T> self_type;
    +        typedef const vector_const_reference<const_self_type> const_closure_type;
    +        typedef size_type const_iterator_type;
    +        typedef packed_tag storage_category;
    +
    +        // Construction and destruction
    +        unit_vector ();
    +        unit_vector (size_type size, size_type index);
    +        unit_vector (const unit_vector &v);
    +
    +        // Accessors
    +        size_type size () const;
    +        size_type index () const;
    +
    +        // Resizing
    +        void resize (size_type size);
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +
    +        const_reference operator [] (size_type i) const;
    +
    +        // Assignment
    +        unit_vector &operator = (const unit_vector &v);
    +        unit_vector &assign_temporary (unit_vector &v);
    +
    +        // Swapping
    +        void swap (unit_vector &v);
    +        friend void swap (unit_vector &v1, unit_vector &v2);
    +
    +        class const_iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type i) const;
    +        const_iterator find_last (size_type i) const;
    +
    +        // Iterator simply is an index.
    +
    +        class const_iterator:
    +            public container_const_reference<unit_vector>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef packed_random_access_iterator_tag iterator_category;
    +            typedef typename unit_vector::difference_type difference_type;
    +            typedef typename unit_vector::value_type value_type;
    +            typedef typename unit_vector::const_reference reference;
    +            typedef typename unit_vector::const_pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const unit_vector &v, const const_iterator_type &it);
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +            bool operator < (const const_iterator &it) const;
    +        };
    +
    +        typedef const_iterator iterator;
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +    };
    + +

    Zero Vector

    + +

    Description

    + +

    The templated class zero_vector<T> represents +zero vectors. For a n-dimensional zero vector and 0 +<= i < n holds zi = 0. +

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    zero_vector<double> v (3);
    +    std::cout << v << std::endl;
    +}
    + +

    Definition

    + +

    Defined in the header vector.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + +
    Parameter Description Default
    T The type of object stored in the vector.  
    + +

    Model of

    + +

    Vector Expression. +

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector Expression.

    + +

    Public base classes

    + +

    vector_expression<zero_vector<T> >

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    zero_vector () Constructs a zero_vector that holds zero + elements.
    zero_vector (size_type size)Constructs a zero_vector that holds size + elements.
    zero_vector (const zero_vector &v)The copy constructor.
    void resize (size_type size)Resizes a zero_vector to hold size + elements.
    size_type size () constReturns the size of the zero_vector.
    const_reference operator () (size_type i) constReturns the value of the i-th element.
    const_reference operator [] (size_type i) constReturns the value of the i-th element.
    zero_vector &operator = (const zero_vector + &v)The assignment operator.
    zero_vector &assign_temporary (zero_vector + &v)Assigns a temporary. May change the zero vector v.
    void swap (zero_vector &v)Swaps the contents of the zero vectors.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the zero_vector.
    const_iterator end () constReturns a const_iterator pointing to the + end of the zero_vector.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed zero_vector. +
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed zero_vector. +
    + +

    Interface

    + +
        // Zero vector class 
    +    template<class T>
    +    class zero_vector: 
    +        public vector_expression<zero_vector<T> > {
    +    public:      
    +        typedef std::size_t size_type;
    +        typedef std::ptrdiff_t difference_type;
    +        typedef T value_type;
    +        typedef const T &const_reference;
    +        typedef T &reference;
    +        typedef const T *const_pointer;
    +        typedef T *pointer;
    +        typedef const zero_vector<T> const_self_type;
    +        typedef zero_vector<T> self_type;
    +        typedef const vector_const_reference<const_self_type> const_closure_type;
    +        typedef size_type const_iterator_type;
    +        typedef sparse_tag storage_category;
    +
    +        // Construction and destruction
    +        zero_vector ();
    +        zero_vector (size_type size);
    +        zero_vector (const zero_vector &v);
    +
    +        // Accessors
    +        size_type size () const;
    +        size_type index () const;
    +
    +        // Resizing
    +        void resize (size_type size);
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +
    +        const_reference operator [] (size_type i) const;
    +
    +        // Assignment
    +        zero_vector &operator = (const zero_vector &v);
    +        zero_vector &assign_temporary (zero_vector &v);
    +
    +        // Swapping
    +        void swap (zero_vector &v);
    +        friend void swap (zero_vector &v1, zero_vector &v2);
    +
    +        class const_iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type i) const;
    +        const_iterator find_last (size_type i) const;
    +
    +        // Iterator simply is an index.
    +
    +        class const_iterator:
    +            public container_const_reference<zero_vector>,
    +            public bidirectional_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef sparse_bidirectional_iterator_tag iterator_category;
    +            typedef typename zero_vector::difference_type difference_type;
    +            typedef typename zero_vector::value_type value_type;
    +            typedef typename zero_vector::const_reference reference;
    +            typedef typename zero_vector::const_pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const zero_vector &v, const const_iterator_type &it);
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +        };
    +
    +        typedef const_iterator iterator;
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +    };
    + +
    + +

    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_expression.htm b/doc/vector_expression.htm new file mode 100644 index 00000000..f0ea2571 --- /dev/null +++ b/doc/vector_expression.htm @@ -0,0 +1,1760 @@ + + + + + +Vector Expressions + + + + +

    c++boost.gifVector Expressions

    + +

    Vector Expression

    + +

    Description

    + +

    The templated class vector_expression<E> forms +the base for all static derived vector expression classes +including class vector itself.

    + +

    Definition

    + +

    Defined in the header vector_expression.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + +
    Parameter Description Default
    E The type of the vector expression.  
    + +

    Model of

    + +

    None.

    + +

    Type requirements

    + +

    None.

    + +

    Public base classes

    + +

    None.

    + +

    Members

    + + + + + + + + + + + + + + +
    Member Description
    const expression_type &operator () () constReturns a const reference of the + expression.
    expression_type &operator () ()Returns a reference of the expression.
    + +

    Interface

    + +
        // Base class for the Barton Nackman trick
    +    template<class E>
    +    struct vector_expression {
    +        typedef E expression_type;
    +        typedef vector_tag type_category;
    +
    +        // 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 
    +        // on MSVC 6.0 (error C2027) - we only implement the casts.
    +
    +        const expression_type &operator () () const;
    +        expression_type &operator () ();
    +    };
    + +

    Vector References

    + +

    Constant Reference

    + +

    Description

    + +

    The templated class vector_const_reference<E> contains +a constant reference to a vector expression.

    + +

    Definition

    + +

    Defined in the header vector_expression.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + +
    Parameter Description Default
    E The type of the vector expression.  
    + +

    Model of

    + +

    Vector Expression.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector Expression.

    + +

    Public base classes

    + +

    vector_expression<vector_const_reference<E> +>

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    vector_const_reference (const expression_type + &e) Constructs a constant reference of the expression.
    size_type size () constReturns the size of the expression.
    const_reference operator () (size_type i) constReturns the value of the i-th element.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the expression.
    const_iterator end () constReturns a const_iterator pointing to the + end of the expression.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed expression.
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed expression.
    + +

    Interface

    + +
        template<class E>
    +    class vector_const_reference:
    +        public vector_expression<vector_const_reference<E> > {
    +    public:
    +        typedef E expression_type;
    +        typedef typename E::size_type size_type;
    +        typedef typename E::difference_type difference_type;
    +        typedef typename E::value_type value_type;
    +        typedef typename E::const_reference const_reference;
    +        typedef const_reference reference;
    +        typedef typename E::const_pointer const_pointer;
    +        typedef const_pointer pointer;
    +        typedef typename E::const_iterator const_iterator_type;
    +        typedef unknown_storage_tag storage_category;
    +
    +        // Construction and destruction
    +        vector_const_reference ();
    +        vector_const_reference (const expression_type &e);
    +
    +        // Accessors
    +        size_type size () const;
    +        const expression_type &expression () const;
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +
    +        const_reference operator [] (size_type i) const;
    +
    +        typedef const_iterator_type const_iterator;
    +        typedef const_iterator iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type i) const;
    +        const_iterator find_last (size_type i) const;
    +
    +        // Iterator is the iterator of the referenced expression.
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +    };
    + +

    Reference

    + +

    Description

    + +

    The templated class vector_reference<E> contains +a reference to a vector expression.

    + +

    Definition

    + +

    Defined in the header vector_expression.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + +
    Parameter Description Default
    E The type of the vector expression.  
    + +

    Model of

    + +

    Vector Expression.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector Expression.

    + +

    Public base classes

    + +

    vector_expression<vector_reference<E> >

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    vector_reference (expression_type &e)Constructs a reference of the expression.
    void resize (size_type size)Resizes the expression to hold at most size + elements.
    size_type size () constReturns the size of the expression.
    const_reference operator () (size_type i) constReturns the value of the i-th element.
    reference operator () (size_type i)Returns a reference of the i-th element. +
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the expression.
    const_iterator end () constReturns a const_iterator pointing to the + end of the expression.
    iterator begin () Returns a iterator pointing to the + beginning of the expression.
    iterator end () Returns a iterator pointing to the end + of the expression.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed expression.
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed expression.
    reverse_iterator rbegin () Returns a reverse_iterator pointing to + the beginning of the reversed expression.
    reverse_iterator rend () Returns a reverse_iterator pointing to + the end of the reversed expression.
    + +

    Interface

    + +
        template<class E>
    +    class vector_reference: 
    +        public vector_expression<vector_reference<E> > {
    +    public:
    +        typedef E expression_type;
    +        typedef typename E::size_type size_type;
    +        typedef typename E::difference_type difference_type;
    +        typedef typename E::value_type value_type;
    +        typedef typename E::const_reference const_reference;
    +        typedef typename E::reference reference;
    +        typedef typename E::const_pointer const_pointer;
    +        typedef typename E::pointer pointer;
    +        typedef typename E::const_iterator const_iterator_type;
    +        typedef typename E::iterator iterator_type;
    +        typedef unknown_storage_tag storage_category;
    +
    +        // Construction and destruction
    +        vector_reference ();
    +        vector_reference (expression_type &e);
    +
    +        // Accessors
    +        size_type size () const;
    +        const expression_type &expression () const;
    +        expression_type &expression ();
    +
    +        // Resizing
    +        void resize (size_type size);
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +        reference operator () (size_type i);
    +
    +        const_reference operator [] (size_type i) const;
    +        reference operator [] (size_type i);
    +
    +        typedef const_iterator_type const_iterator;
    +        typedef iterator_type iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type i) const;
    +        iterator find_first (size_type i);
    +        const_iterator find_last (size_type i) const;
    +        iterator find_last (size_type i);
    +
    +        // Iterator is the iterator of the referenced expression.
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        iterator begin ();
    +        iterator end ();
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +
    +        typedef reverse_iterator_base<iterator> reverse_iterator;
    +
    +        reverse_iterator rbegin ();
    +        reverse_iterator rend ();
    +    };
    + +

    Vector Operations

    + +

    Unary Operation Description

    + +

    Description

    + +

    The templated class vector_unary<E, F> describes +a unary vector operation.

    + +

    Definition

    + +

    Defined in the header vector_expression.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    E The type of the vector expression.  
    FThe type of the operation. 
    + +

    Model of

    + +

    Vector Expression.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector Expression.

    + +

    Public base classes

    + +

    vector_expression<vector_unary<E, F> >

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    vector_unary (const expression_type &e)Constructs a description of the expression.
    size_type size () constReturns the size of the expression.
    const_reference operator () (size_type i) constReturns the value of the i-th element.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the expression.
    const_iterator end () constReturns a const_iterator pointing to the + end of the expression.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed expression.
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed expression.
    + +

    Interface

    + +
        template<class E, class F>
    +    class vector_unary: 
    +        public vector_expression<vector_unary<E, F> > {
    +    public:
    +        typedef E expression_type;
    +        typedef F functor_type;
    +        typedef typename E::size_type size_type;
    +        typedef typename E::difference_type difference_type;
    +        typedef typename F::result_type value_type;
    +        typedef value_type const_reference;
    +        typedef const_reference reference;
    +        typedef const value_type *const_pointer;
    +        typedef const_pointer pointer;
    +        typedef const vector_unary<E, F> const_closure_type;
    +        typedef typename E::const_iterator const_iterator_type;
    +        typedef unknown_storage_tag storage_category;
    +
    +        // Construction and destruction
    +        vector_unary ();
    +        vector_unary (const expression_type &e);
    +
    +        // Accessors
    +        size_type size () const;
    +        const expression_type &expression () const;
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +
    +        const_reference operator [] (size_type i) const;
    +
    +        class const_iterator;
    +        typedef const_iterator iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type i) const;
    +        const_iterator find_last (size_type i) const;
    +
    +        // Iterator enhances the iterator of the referenced expression 
    +        // with the unary functor.
    +
    +        class const_iterator:
    +            public container_const_reference<vector_unary>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef typename E::const_iterator::iterator_category iterator_category;
    +            typedef typename vector_unary::difference_type difference_type;
    +            typedef typename vector_unary::value_type  value_type;
    +            typedef typename vector_unary::const_reference reference;
    +            typedef typename vector_unary::const_pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const vector_unary &vu, const const_iterator_type &it);
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +            bool operator <(const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +    };
    + +

    Unary Operations

    + +

    Prototypes

    + +
        template<class E, class F>
    +    struct vector_unary_traits {
    +        typedef vector_unary<typename E::const_closure_type, F> expression_type;
    +        typedef expression_type result_type; 
    +    };
    +
    +    // (- v) [i] = - v [i]
    +    template<class E> 
    +    typename vector_unary_traits<E, scalar_negate<typename E::value_type> >::result_type
    +    operator - (const vector_expression<E> &e);
    +
    +    // (conj v) [i] = conj (v [i])
    +    template<class E> 
    +    typename vector_unary_traits<E, scalar_conj<typename E::value_type> >::result_type
    +    conj (const vector_expression<E> &e);
    +
    +    // (real v) [i] = real (v [i])
    +    template<class E> 
    +    typename vector_unary_traits<E, scalar_real<typename E::value_type> >::result_type
    +    real (const vector_expression<E> &e);
    +
    +    // (imag v) [i] = imag (v [i])
    +    template<class E> 
    +    typename vector_unary_traits<E, scalar_imag<typename E::value_type> >::result_type
    +    imag (const vector_expression<E> &e);
    +
    +    // (trans v) [i] = v [i]
    +    template<class E> 
    +    typename vector_unary_traits<E, scalar_identity<typename E::value_type> >::result_type
    +    trans (const vector_expression<E> &e);
    +
    +    // (herm v) [i] = conj (v [i])
    +    template<class E> 
    +    typename vector_unary_traits<E, scalar_conj<typename E::value_type> >::result_type
    +    herm (const vector_expression<E> &e);
    + +

    Description

    + +

    operator - computes the additive inverse of a +vector expression. conj computes the complex +conjugate of a vector expression. real and imag +compute the real and imaginary parts of a vector expression. trans +computes the transpose of a vector expression. herm +computes the hermitian, i.e. the complex conjugate of the +transpose of a vector expression.

    + +

    Definition

    + +

    Defined in the header vector_expression.hpp.

    + +

    Type requirements

    + + +
  • E is a model of Vector Expression.
  • +
    + +

    Preconditions

    + +

    None.

    + +

    Complexity

    + +

    Linear depending from the size of the vector expression.

    + +

    Examples

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    vector<std::complex<double> > v (3);
    +    for (int i = 0; i < v.size (); ++ i) 
    +        v (i) = std::complex (i, i);
    +
    +    std::cout << - v << std::endl;
    +    std::cout << conj (v) << std::endl;
    +    std::cout << real (v) << std::endl;
    +    std::cout << imag (v) << std::endl;
    +    std::cout << trans (v) << std::endl;
    +    std::cout << herm (v) << std::endl;
    +}
    + +

    Binary Operation Description

    + +

    Description

    + +

    The templated class vector_binary<E1, E2, F> describes +a binary vector operation.

    + +

    Definition

    + +

    Defined in the header vector_expression.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    E1 The type of the first vector expression.  
    E2The type of the second vector expression.  
    FThe type of the operation. 
    + +

    Model of

    + +

    Vector Expression.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector Expression.

    + +

    Public base classes

    + +

    vector_expression<vector_binary<E1, E2, F> >

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    vector_binary (const expression1_type &e1, + const expression2_type &e2)Constructs a description of the expression.
    size_type size () constReturns the size of the expression.
    const_reference operator () (size_type i) constReturns the value of the i-th element.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the expression.
    const_iterator end () constReturns a const_iterator pointing to the + end of the expression.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed expression.
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed expression.
    + +

    Interface

    + +
        template<class E1, class E2, class F>
    +    class vector_binary:
    +        public vector_expression<vector_binary<E1, E2, F> > {
    +    public:
    +        typedef E1 expression1_type;
    +        typedef E2 expression2_type;
    +        typedef F functor_type;
    +        typedef typename promote_traits<typename E1::size_type, typename E2::size_type>::promote_type size_type;
    +        typedef typename promote_traits<typename E1::difference_type, typename E2::difference_type>::promote_type difference_type;
    +        typedef typename F::result_type value_type;
    +        typedef value_type const_reference;
    +        typedef const_reference reference;
    +        typedef const value_type *const_pointer;
    +        typedef const_pointer pointer;
    +        typedef const vector_binary<E1, E2, F> const_closure_type;
    +        typedef typename E1::const_iterator const_iterator1_type;
    +        typedef typename E2::const_iterator const_iterator2_type;
    +        typedef unknown_storage_tag storage_category;
    +
    +        // Construction and destruction
    +        vector_binary ();
    +        vector_binary (const expression1_type &e1, const expression2_type &e2);
    +
    +        // Accessors
    +        size_type size () const;
    +        const expression1_type &expression1 () const;
    +        const expression2_type &expression2 () const;
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +
    +        const_reference operator [] (size_type i) const;
    +
    +        class const_iterator;
    +        typedef const_iterator iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type i) const;
    +        const_iterator find_last (size_type i) const;
    +
    +        // Iterator merges the iterators of the referenced expressions and  
    +        // enhances them with the binary functor.
    +
    +        class const_iterator:
    +            public container_const_reference<vector_binary>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef typename restrict_traits<typename E1::const_iterator::iterator_category,
    +                                             typename E2::const_iterator::iterator_category>::iterator_category iterator_category;
    +            typedef typename vector_binary::difference_type difference_type;
    +            typedef typename vector_binary::value_type value_type;
    +            typedef typename vector_binary::const_reference reference;
    +            typedef typename vector_binary::const_pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const vector_binary &vb, size_type i,
    +                            const const_iterator1_type &it1, const const_iterator1_type &it1_end,
    +                            const const_iterator2_type &it2, const const_iterator2_type &it2_end);
    +
    +            // Dense specializations
    +            void increment (dense_random_access_iterator_tag);
    +            void decrement (dense_random_access_iterator_tag);
    +            value_type dereference (dense_random_access_iterator_tag) const;
    +
    +            // Packed specializations
    +            void increment (packed_random_access_iterator_tag);
    +            void decrement (packed_random_access_iterator_tag);
    +            value_type dereference (packed_random_access_iterator_tag) const;
    +
    +            // Sparse specializations
    +            void increment (sparse_bidirectional_iterator_tag);
    +            void decrement (sparse_bidirectional_iterator_tag);
    +            value_type dereference (sparse_bidirectional_iterator_tag) const;
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +            bool operator <(const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +    };
    +
    + +

    Binary Operations

    + +

    Prototypes

    + +
        template<class E1, class E2, class F>
    +    struct vector_binary_traits {
    +        typedef vector_binary<typename E1::const_closure_type, 
    +                              typename E2::const_closure_type, F> expression_type;
    +        typedef expression_type result_type; 
    +    };
    +
    +    // (v1 + v2) [i] = v1 [i] + v2 [i]
    +    template<class E1, class E2>
    +    typename vector_binary_traits<E1, E2, scalar_plus<typename E1::value_type, 
    +                                                      typename E2::value_type> >::result_type
    +    operator + (const vector_expression<E1> &e1, 
    +                const vector_expression<E2> &e2);
    +
    +    // (v1 - v2) [i] = v1 [i] - v2 [i]
    +    template<class E1, class E2>
    +    typename vector_binary_traits<E1, E2, scalar_minus<typename E1::value_type, 
    +                                                       typename E2::value_type> >::result_type
    +    operator - (const vector_expression<E1> &e1, 
    +                const vector_expression<E2> &e2);
    + +

    Description

    + +

    operator + computes the sum of two vector +expressions. operator - computes the difference of +two vector expressions.

    + +

    Definition

    + +

    Defined in the header vector_expression.hpp.

    + +

    Type requirements

    + + +
  • E1 is a model of Vector Expression.
  • +
  • E2 is a model of Vector Expression.
  • +
    + +

    Preconditions

    + + +
  • e1 ().size () == e2 ().size ()
  • +
    + +

    Complexity

    + +

    Linear depending from the size of the vector expressions.

    + +

    Examples

    + +
    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) 
    +        v1 (i) = v2 (i) = i;
    +
    +    std::cout << v1 + v2 << std::endl;
    +    std::cout << v1 - v2 << std::endl;
    +}
    + +

    Binary Outer Operation Description

    + +

    Description

    + +

    The templated class vector_matrix_binary<E1, E2, +F> describes a binary outer vector operation.

    + +

    Definition

    + +

    Defined in the header matrix_expression.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    E1 The type of the first vector expression.  
    E2The type of the second vector expression.  
    FThe type of the operation. 
    + +

    Model of

    + +

    Matrix Expression.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Matrix Expression.

    + +

    Public base classes

    + +

    matrix_expression<vector_matrix_binary<E1, E2, +F> >

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    vector_matrix_binary (const expression1_type + &e1, const expression2_type &e2) Constructs a description of the expression.
    size_type size1 () constReturns the number of rows.
    size_type size2 () constReturns the number of columns.
    const_reference operator () (size_type i, size_type + j) constReturns the value of the j-th element in + the i-th row.
    const_iterator1 begin1 () constReturns a const_iterator1 pointing to + the beginning of the expression.
    const_iterator1 end1 () constReturns a const_iterator1 pointing to + the end of the expression.
    const_iterator2 begin2 () constReturns a const_iterator2 pointing to + the beginning of the expression.
    const_iterator2 end2 () constReturns a const_iterator2 pointing to + the end of the expression.
    const_reverse_iterator1 rbegin1 () constReturns a const_reverse_iterator1 + pointing to the beginning of the reversed expression.
    const_reverse_iterator1 rend1 () constReturns a const_reverse_iterator1 + pointing to the end of the reversed expression.
    const_reverse_iterator2 rbegin2 () constReturns a const_reverse_iterator2 + pointing to the beginning of the reversed expression.
    const_reverse_iterator2 rend2 () constReturns a const_reverse_iterator2 + pointing to the end of the reversed expression.
    + +

    Interface

    + +
        template<class E1, class E2, class F>
    +    class vector_matrix_binary:
    +        public matrix_expression<vector_matrix_binary<E1, E2, F> > {
    +    public:
    +        typedef E1 expression1_type;
    +        typedef E2 expression2_type;
    +        typedef F functor_type;
    +        typedef typename promote_traits<typename E1::size_type, typename E2::size_type>::promote_type size_type;
    +        typedef typename promote_traits<typename E1::difference_type, typename E2::difference_type>::promote_type difference_type;
    +        typedef typename F::result_type value_type;
    +        typedef value_type const_reference;
    +        typedef const_reference reference;
    +        typedef const value_type *const_pointer;
    +        typedef const_pointer pointer;
    +        typedef const vector_matrix_binary<E1, E2, F> const_closure_type;
    +        typedef unknown_orientation_tag orientation_category;
    +        typedef typename E1::const_iterator const_iterator1_type;
    +        typedef typename E2::const_iterator const_iterator2_type;
    +        typedef unknown_storage_tag storage_category;
    +
    +        // Construction and destruction 
    +        vector_matrix_binary ();
    +        vector_matrix_binary (const expression1_type &e1, const expression2_type &e2);
    +
    +        // Accessors
    +        size_type size1 () const;
    +        size_type size2 () const;
    +        const expression1_type &expression1 () const;
    +        const expression2_type &expression2 () const;
    +
    +        // Element access
    +        const_reference operator () (size_type i, size_type j) const;
    +
    +        class const_iterator1;
    +        typedef const_iterator1 iterator1;
    +        class const_iterator2;
    +        typedef const_iterator2 iterator2;
    +
    +        // Element lookup
    +        const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
    +        const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
    +        const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
    +        const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
    +
    +        // Iterators enhance the iterators of the referenced expressions
    +        // with the binary functor.
    +
    +        class const_iterator1:
    +            public container_const_reference<vector_matrix_binary>,
    +            public random_access_iterator_base<const_iterator1, value_type> {
    +        public:
    +            typedef typename restrict_traits<typename E1::const_iterator::iterator_category, 
    +                                             typename E2::const_iterator::iterator_category>::iterator_category iterator_category;
    +            typedef typename vector_matrix_binary::difference_type difference_type;
    +            typedef typename vector_matrix_binary::value_type value_type;
    +            typedef typename vector_matrix_binary::const_reference reference;
    +            typedef typename vector_matrix_binary::const_pointer pointer;
    +            typedef const_iterator2 dual_iterator_type;
    +            typedef const_reverse_iterator2 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator1 ();
    +            const_iterator1 (const vector_matrix_binary &vmb, const const_iterator1_type &it1, const const_iterator2_type &it2);
    +
    +            // Arithmetic
    +            const_iterator1 &operator ++ ();
    +            const_iterator1 &operator -- ();
    +            const_iterator1 &operator += (difference_type n);
    +            const_iterator1 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator1 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator2 begin () const;
    +            const_iterator2 end () const;
    +            const_reverse_iterator2 rbegin () const;
    +            const_reverse_iterator2 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type  index2 () const;
    +
    +            // Assignment 
    +            const_iterator1 &operator = (const const_iterator1 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator1 &it) const;
    +            bool operator <(const const_iterator1 &it) const;
    +        };
    +
    +        const_iterator1 begin1 () const;
    +        const_iterator1 end1 () const;
    +
    +        class const_iterator2:
    +            public container_const_reference<vector_matrix_binary>,
    +            public random_access_iterator_base<const_iterator2, value_type> {
    +        public:
    +            typedef typename restrict_traits<typename E1::const_iterator::iterator_category, 
    +                                             typename E2::const_iterator::iterator_category>::iterator_category iterator_category;
    +            typedef typename vector_matrix_binary::difference_type difference_type;
    +            typedef typename vector_matrix_binary::value_type value_type;
    +            typedef typename vector_matrix_binary::const_reference reference;
    +            typedef typename vector_matrix_binary::const_pointer pointer;
    +            typedef const_iterator1 dual_iterator_type;
    +            typedef const_reverse_iterator1 dual_reverse_iterator_type;
    +
    +            // Construction and destruction
    +            const_iterator2 ();
    +            const_iterator2 (const vector_matrix_binary &vmb, const const_iterator1_type &it1, const const_iterator2_type &it2);
    +
    +            // Arithmetic
    +            const_iterator2 &operator ++ ();
    +            const_iterator2 &operator -- ();
    +            const_iterator2 &operator += (difference_type n);
    +            const_iterator2 &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator2 &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            const_iterator1 begin () const;
    +            const_iterator1 end () const;
    +            const_reverse_iterator1 rbegin () const;
    +            const_reverse_iterator1 rend () const;
    +
    +            // Indices
    +            size_type index1 () const;
    +            size_type  index2 () const;
    +
    +            // Assignment 
    +            const_iterator2 &operator = (const const_iterator2 &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator2 &it) const;
    +            bool operator <(const const_iterator2 &it) const;
    +        };
    +
    +        const_iterator2 begin2 () const;
    +        const_iterator2 end2 () const;
    +
    +        // Reverse iterators
    +
    +        const_reverse_iterator1 rbegin1 () const;
    +        const_reverse_iterator1 rend1 () const;
    +
    +        const_reverse_iterator2 rbegin2 () const;
    +        const_reverse_iterator2 rend2 () const;
    +    };
    + +

    Binary Outer Operations

    + +

    Prototypes

    + +
        template<class E1, class E2, class F>
    +    struct vector_matrix_binary_traits {
    +        typedef vector_matrix_binary<typename E1::const_closure_type, 
    +                                     typename E2::const_closure_type, F> expression_type;
    +        typedef expression_type result_type; 
    +    };
    +
    +    // (outer_prod (v1, v2)) [i] [j] = v1 [i] * v2 [j]
    +    template<class E1, class E2>
    +    typename vector_matrix_binary_traits<E1, E2, scalar_multiplies<typename E1::value_type, typename E2::value_type> >::result_type
    +    outer_prod (const vector_expression<E1> &e1, 
    +                const vector_expression<E2> &e2);
    + +

    Description

    + +

    outer_prod computes the outer product of two +vector expressions.

    + +

    Definition

    + +

    Defined in the header matrix_expression.hpp.

    + +

    Type requirements

    + + +
  • E1 is a model of Vector Expression.
  • +
  • E2 is a model of Vector Expression.
  • +
    + +

    Preconditions

    + +

    None.

    + +

    Complexity

    + +

    Quadratic depending from the size of the vector expressions.

    + +

    Examples

    + +
    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) 
    +        v1 (i) = v2 (i) = i;
    +
    +    std::cout << outer_prod (v1, v2) << std::endl;
    +}
    + +

    Scalar Vector Operation Description

    + +

    Description

    + +

    The templated classes vector_binary_scalar1<E1, E2, +F> and vector_binary_scalar2<E1, E2, F> +describe binary operations between a scalar and a vector.

    + +

    Definition

    + +

    Defined in the header vector_expression.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    E1/E2 The type of the scalar expression.  
    E2/E1The type of the vector expression.  
    FThe type of the operation. 
    + +

    Model of

    + +

    Vector Expression.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector Expression.

    + +

    Public base classes

    + +

    vector_expression<vector_binary_scalar1<E1, E2, +F> > and +vector_expression<vector_binary_scalar2<E1, E2, F> > resp.

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    vector_binary_scalar1 (const expression1_type + &e1, const expression2_type &e2)Constructs a description of the expression.
    vector_binary_scalar2 (const expression1_type + &e1, const expression2_type &e2)Constructs a description of the expression.
    size_type size () constReturns the size of the expression.
    const_reference operator () (size_type i) constReturns the value of the i-th element.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the expression.
    const_iterator end () constReturns a const_iterator pointing to the + end of the expression.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed expression.
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed expression.
    + +

    Interface

    + +
        template<class E1, class E2, class F>
    +    class vector_binary_scalar1:
    +        public vector_expression<vector_binary_scalar1<E1, E2, F> > {
    +    public:
    +        typedef E1 expression1_type;
    +        typedef E2 expression2_type;
    +        typedef F functor_type;
    +        typedef typename E2::size_type size_type;
    +        typedef typename E2::difference_type difference_type;
    +        typedef typename F::result_type value_type;
    +        typedef value_type const_reference;
    +        typedef const_reference reference;
    +        typedef const value_type *const_pointer;
    +        typedef const_pointer pointer;
    +        typedef const vector_binary_scalar1<E1, E2, F> const_closure_type;
    +        typedef typename E1::value_type const_iterator1_type;
    +        typedef typename E2::const_iterator const_iterator2_type;
    +        typedef unknown_storage_tag storage_category;
    +
    +        // Construction and destruction
    +        vector_binary_scalar1 ();
    +        vector_binary_scalar1 (const expression1_type &e1, const expression2_type &e2);
    +
    +        // Accessors
    +        size_type size () const;
    +        const expression1_type &expression1 () const;
    +        const expression2_type &expression2 () const;
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +
    +        const_reference operator [] (size_type i) const;
    +
    +        class const_iterator;
    +        typedef const_iterator iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type i) const;
    +        const_iterator find_last (size_type i) const;
    +
    +        // Iterator enhances the iterator of the referenced vector expression
    +        // with the binary functor.
    +
    +        class const_iterator:
    +            public container_const_reference<vector_binary_scalar1>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef typename E2::const_iterator::iterator_category iterator_category;
    +            typedef typename vector_binary_scalar1::difference_type difference_type;
    +            typedef typename vector_binary_scalar1::value_type value_type;
    +            typedef typename vector_binary_scalar1::const_reference reference;
    +            typedef typename vector_binary_scalar1::const_pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const vector_binary_scalar1 &vbs, const const_iterator1_type &it1, const const_iterator2_type &it2);
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +            bool operator <(const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +    };
    +
    +    template<class E1, class E2, class F>
    +    class vector_binary_scalar2:
    +        public vector_expression<vector_binary_scalar2<E1, E2, F> > {
    +    public:
    +        typedef E1 expression1_type;
    +        typedef E2 expression2_type;
    +        typedef F functor_type;
    +        typedef typename E1::size_type size_type;
    +        typedef typename E1::difference_type difference_type;
    +        typedef typename F::result_type value_type;
    +        typedef value_type const_reference;
    +        typedef const_reference reference;
    +        typedef const value_type *const_pointer;
    +        typedef const_pointer pointer;
    +        typedef const vector_binary_scalar2<E1, E2, F> const_closure_type;
    +        typedef typename E1::const_iterator const_iterator1_type;
    +        typedef typename E2::value_type const_iterator2_type;
    +        typedef unknown_storage_tag storage_category;
    +
    +        // Construction and destruction
    +        vector_binary_scalar2 ();
    +        vector_binary_scalar2 (const expression1_type &e1, const expression2_type &e2);
    +
    +        // Accessors
    +        size_type size () const;
    +        const expression1_type &expression1 () const;
    +        const expression2_type &expression2 () const;
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +
    +        const_reference operator [] (size_type i) const ;
    +
    +        class const_iterator;
    +        typedef const_iterator iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type i) const;
    +        const_iterator find_last (size_type i) const;
    +
    +        // Iterator enhances the iterator of the referenced vector expression
    +        // with the binary functor.
    +
    +        class const_iterator:
    +            public container_const_reference<vector_binary_scalar2>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef typename E1::const_iterator::iterator_category iterator_category;
    +            typedef typename vector_binary_scalar2::difference_type difference_type;
    +            typedef typename vector_binary_scalar2::value_type value_type;
    +            typedef typename vector_binary_scalar2::const_reference reference;
    +            typedef typename vector_binary_scalar2::const_pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const vector_binary_scalar2 &vbs, const const_iterator1_type &it1, const const_iterator2_type &it2);
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +            bool operator <(const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +    };
    + +

    Scalar Vector Operations

    + +

    Prototypes

    + +
        template<class T1, class E2, class F>
    +    struct vector_binary_scalar1_traits {
    +        typedef vector_binary_scalar1<scalar_const_reference<T1>, 
    +                                      typename E2::const_closure_type, F> expression_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, 
    +                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; 
    +    };
    +
    +    // (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, 
    +                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, 
    +                const T2 &e2);
    + +

    Description

    + +

    operator * computes the product of a scalar and a +vector expression. operator / multiplies the vector +with the reciprocal of the scalar.

    + +

    Definition

    + +

    Defined in the header vector_expression.hpp.

    + +

    Type requirements

    + + +
  • T1/T2 is a model of Scalar Expression.
  • +
  • E2/E1 is a model of Vector Expression.
  • +
    + +

    Preconditions

    + +

    None.

    + +

    Complexity

    + +

    Linear depending from the size of the vector expression.

    + +

    Examples

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    vector<double> v (3);
    +    for (int i = 0; i < v.size (); ++ i) 
    +        v (i) = i;
    +
    +    std::cout << 2.0 * v << std::endl;
    +    std::cout << v * 2.0 << std::endl;
    +}
    + +

    Vector Reductions

    + +

    Unary Reductions

    + +

    Prototypes

    + +
        template<class E, class F>
    +    struct vector_scalar_unary_traits {
    +         typedef typename F::result_type result_type;
    +    };
    +
    +    // sum v = sum (v [i])
    +    template<class E>
    +    typename vector_scalar_unary_traits<E, vector_sum<typename E::value_type> >::result_type
    +    sum (const vector_expression<E> &e);
    +
    +    // norm_1 v = sum (abs (v [i]))
    +    template<class E>
    +    typename vector_scalar_unary_traits<E, vector_norm_1<typename E::value_type> >::result_type
    +    norm_1 (const vector_expression<E> &e);
    +
    +    // norm_2 v = sqrt (sum (v [i] * v [i]))
    +    template<class E>
    +    typename vector_scalar_unary_traits<E, vector_norm_2<typename E::value_type> >::result_type
    +    norm_2 (const vector_expression<E> &e);
    +
    +    // norm_inf v = max (abs (v [i]))
    +    template<class E>
    +    typename vector_scalar_unary_traits<E, vector_norm_inf<typename E::value_type> >::result_type
    +    norm_inf (const vector_expression<E> &e);
    +
    +    // index_norm_inf v = min (i: abs (v [i]) == max (abs (v [i])))
    +    template<class E>
    +    typename vector_scalar_unary_traits<E, vector_index_norm_inf<typename E::value_type> >::result_type
    +    index_norm_inf (const vector_expression<E> &e);
    + +

    Description

    + +

    sum computes the sum of the vector expression's +elements. norm_1, norm_2 and norm_inf +compute the corresponding ||.||1, ||.||2 +and ||.||inf vector norms. +index_norm_1 computes the index of the vector expression's +first element having maximal absolute value.

    + +

    Definition

    + +

    Defined in the header vector_expression.hpp.

    + +

    Type requirements

    + + +
  • E is a model of Vector + Expression.
  • +
    + +

    Preconditions

    + +

    None.

    + +

    Complexity

    + +

    Linear depending from the size of the vector expression.

    + +

    Examples

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    vector<double> v (3);
    +    for (int i = 0; i < v.size (); ++ i) 
    +        v (i) = i;
    +
    +    std::cout << sum (v) << std::endl;
    +    std::cout << norm_1 (v) << std::endl;
    +    std::cout << norm_2 (v) << std::endl;
    +    std::cout << norm_inf (v) << std::endl;
    +    std::cout << index_norm_inf (v) << std::endl;
    +}
    + +

    Binary Reductions

    + +

    Prototypes

    + +
        template<class E1, class E2, class F>
    +    struct vector_scalar_binary_traits {
    +        typedef typename F::result_type result_type;
    +    };
    +
    +    // 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 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, 
    +                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 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, 
    +                     const vector_expression<E2> &e2);
    + +

    Description

    + +

    inner_prod computes the inner product of the +vector expressions. prec_inner_prod computes the +double precision inner product of the vector expressions.

    + +

    Definition

    + +

    Defined in the header vector_expression.hpp.

    + +

    Type requirements

    + + +
  • E1 is a model of Vector Expression.
  • +
  • E2 is a model of Vector Expression.
  • +
    + +

    Preconditions

    + + +
  • e1 ().size () == e2 ().size ()
  • +
    + +

    Complexity

    + +

    Linear depending from the size of the vector expressions.

    + +

    Examples

    + +
    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) 
    +        v1 (i) = v2 (i) = i;
    +
    +    std::cout << inner_prod (v1, v2) << std::endl;
    +}
    + +
    + +

    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 new file mode 100644 index 00000000..104e20ac --- /dev/null +++ b/doc/vector_proxy.htm @@ -0,0 +1,861 @@ + + + + + +Vector Proxies + + + + +

    c++boost.gifVector Proxies

    + +

    Vector Range

    + +

    Description

    + +

    The templated class vector_range<V> allows +addressing a range of a vector.

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    vector<double> v (3);
    +    vector_range<vector<double> > vr (v, range (0, 3));
    +    for (int i = 0; i < vr.size (); ++ i)
    +        vr (i) = i;
    +    std::cout << vr << std::endl;
    +}
    + +

    Definition

    + +

    Defined in the header vector_proxy.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + +
    Parameter Description Default
    V The type of vector referenced.  
    + +

    Model of

    + +

    Vector Expression. +

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector Expression.

    + +

    Public base classes

    + +

    vector_expression<vector_range<V> >

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    vector_range (vector_type &data, const + range &r)Constructs a sub vector.
    size_type start () constReturns the start of the sub vector.
    size_type size () constReturns the size of the sub vector.
    const_reference operator () (size_type i) constReturns the value of the i-th element.
    reference operator () (size_type i)Returns a reference of the i-th element. +
    const_reference operator [] (size_type i) constReturns the value of the i-th element.
    reference operator [] (size_type i)Returns a reference of the i-th element. +
    vector_range &operator = (const + vector_range &vr)The assignment operator.
    vector_range &assign_temporary + (vector_range &vr)Assigns a temporary. May change the vector range vr.
    template<class AE>
    + vector_range &operator = (const + vector_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    + vector_range &assign (const + vector_expression<AE> &ae)
    Assigns a vector expression to the sub vector. Left + and right hand side of the assignment should be + independent.
    template<class AE>
    + vector_range &operator += (const + vector_expression<AE> &ae)
    A computed assignment operator. Adds the vector + expression to the sub vector.
    template<class AE>
    + vector_range &plus_assign (const + vector_expression<AE> &ae)
    Adds a vector expression to the sub vector. Left and + right hand side of the assignment should be independent.
    template<class AE>
    + vector_range &operator -= (const + vector_expression<AE> &ae)
    A computed assignment operator. Subtracts the vector + expression from the sub vector.
    template<class AE>
    + vector_range &minus_assign (const + vector_expression<AE> &ae)
    Subtracts a vector expression from the sub vector. + Left and right hand side of the assignment should be + independent.
    template<class AT>
    + vector_range &operator *= (const AT &at)
    A computed assignment operator. Multiplies the sub + vector with a scalar.
    template<class AT>
    + vector_range &operator /= (const AT &at)
    A computed assignment operator. Divides the sub + vector through a scalar.
    void swap (vector_range &vr)Swaps the contents of the sub vectors.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the vector_range.
    const_iterator end () constReturns a const_iterator pointing to the + end of the vector_range.
    iterator begin () Returns a iterator pointing to the + beginning of the vector_range.
    iterator end () Returns a iterator pointing to the end + of the vector_range.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed vector_range. +
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed vector_range. +
    reverse_iterator rbegin () Returns a reverse_iterator pointing to + the beginning of the reversed vector_range.
    reverse_iterator rend () Returns a reverse_iterator pointing to + the end of the reversed vector_range.
    + +

    Interface

    + +
        // Vector based range class
    +    template<class V>
    +    class vector_range:
    +        public vector_expression<vector_range<V> > {
    +    public:      
    +        typedef const V const_vector_type;
    +        typedef V vector_type;
    +        typedef typename V::size_type size_type;
    +        typedef typename V::difference_type difference_type;
    +        typedef typename V::value_type value_type;
    +        typedef typename V::const_reference const_reference;
    +        typedef typename V::reference reference;
    +        typedef typename V::const_pointer const_pointer;
    +        typedef typename V::pointer pointer;
    +        typedef const vector_const_reference<const vector_range<vector_type> > const_closure_type;
    +        typedef vector_reference<vector_range<vector_type> > closure_type;
    +        typedef typename V::const_iterator const_iterator_type;
    +        typedef typename V::iterator iterator_type;
    +        typedef typename storage_restrict_traits<typename V::storage_category,
    +                                                 dense_proxy_tag>::storage_category storage_category;
    +
    +        // Construction and destruction
    +        vector_range (); 
    +        vector_range (vector_type &data, const range &r); 
    +
    +        // Accessors
    +        size_type start () const; 
    +        size_type size () const; 
    +        const_vector_type &data () const;
    +        vector_type &data ();
    +
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +        reference operator () (size_type i);
    +
    +        const_reference operator [] (size_type i) const;
    +        reference operator [] (size_type i);
    +
    +        vector_range<vector_type> project (const range &r) const;
    +
    +        // Assignment
    +        vector_range &operator = (const vector_range &vr);
    +        vector_range &assign_temporary (vector_range &vr);
    +        template<class AE>
    +        vector_range &operator = (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector_range &assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector_range &operator += (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector_range &plus_assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector_range &operator -= (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector_range &minus_assign (const vector_expression<AE> &ae);
    +        template<class AT>
    +        vector_range &operator *= (const AT &at);
    +        template<class AT>
    +        vector_range &operator /= (const AT &at);
    +
    +        // Swapping
    +        void swap (vector_range &vr);
    +        friend void swap (vector_range &vr1, vector_range &vr2);
    +
    +        class const_iterator;
    +        class iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type i) const;
    +        iterator find_first (size_type i);
    +        const_iterator find_last (size_type i) const;
    +        iterator find_last (size_type i);
    +
    +        // Iterators simply are pointers.
    +
    +        class const_iterator:
    +            public container_const_reference<vector_range>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef typename V::const_iterator::iterator_category iterator_category;
    +            typedef typename V::const_iterator::difference_type difference_type;
    +            typedef typename V::const_iterator::value_type value_type;
    +            typedef typename V::const_iterator::reference reference;
    +            typedef typename V::const_iterator::pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const vector_range &vr, const const_iterator_type &it);
    +            const_iterator (const iterator &it);
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +            bool operator <(const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        class iterator:
    +            public container_reference<vector_range>,
    +            public random_access_iterator_base<iterator, value_type> {
    +        public:
    +            typedef typename V::iterator::iterator_category iterator_category;
    +            typedef typename V::iterator::difference_type difference_type;
    +            typedef typename V::iterator::value_type value_type;
    +            typedef typename V::iterator::reference reference;
    +            typedef typename V::iterator::pointer pointer;
    +
    +            // Construction and destruction
    +            iterator ();
    +            iterator (vector_range &vr, const iterator_type &it);
    +
    +            // Arithmetic
    +            iterator &operator ++ ();
    +            iterator &operator -- ();
    +            iterator &operator += (difference_type n);
    +            iterator &operator -= (difference_type n);
    +            difference_type operator - (const iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            iterator &operator = (const iterator &it);
    +
    +            // Comparison
    +            bool operator == (const iterator &it) const;
    +            bool operator <(const iterator &it) const;
    +        };
    +
    +        iterator begin ();
    +        iterator end ();
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +
    +        typedef reverse_iterator_base<iterator> reverse_iterator;
    +
    +        reverse_iterator rbegin ();
    +        reverse_iterator rend ();
    +    };
    + +

    Projections

    + +

    Prototypes

    + +
        template<class V>
    +    vector_range<V> project (V &data, const range &r);
    +    template<class V>
    +    const vector_range<const V> project (const V &data, const range &r);
    +    template<class V>
    +    vector_range<V> project (const vector_range<V> &data, const range &r);
    + +

    Description

    + +

    The free project functions support the +construction of vector ranges.

    + +

    Definition

    + +

    Defined in the header vector_proxy.hpp.

    + +

    Type requirements

    + + +
  • V is a model of Vector Expression.
  • +
    + +

    Preconditions

    + + +
  • r.start () + r.size () <= data.size ()
  • +
    + +

    Complexity

    + +

    Linear depending from the size of the range.

    + +

    Examples

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    vector<double> v (3);
    +    for (int i = 0; i < 3; ++ i)
    +        project (v, range (0, 3)) (i) = i;
    +    std::cout << project (v, range (0, 3)) << std::endl;
    +}
    + +

    Vector Slice

    + +

    Description

    + +

    The templated class vector_slice<V> allows +addressing a slice of a vector.

    + +

    Example

    + +
    int main () {
    +    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) 
    +        vs (i) = i;
    +    std::cout << vs << std::endl;
    +}
    + +

    Definition

    + +

    Defined in the header vector_proxy.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + +
    Parameter Description Default
    V The type of vector referenced.  
    + +

    Model of

    + +

    Vector Expression. +

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector Expression.

    + +

    Public base classes

    + +

    vector_expression<vector_slice<V> >

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    vector_slice (vector_type &data, const + slice &s)Constructs a sub vector.
    size_type size () constReturns the size of the sub vector.
    const_reference operator () (size_type i) constReturns the value of the i-th element.
    reference operator () (size_type i)Returns a reference of the i-th element. +
    const_reference operator [] (size_type i) constReturns the value of the i-th element.
    reference operator [] (size_type i)Returns a reference of the i-th element. +
    vector_slice &operator = (const + vector_slice &vs)The assignment operator.
    vector_slice &assign_temporary + (vector_slice &vs)Assigns a temporary. May change the vector slice vs.
    template<class AE>
    + vector_slice &operator = (const + vector_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    + vector_slice &assign (const + vector_expression<AE> &ae)
    Assigns a vector expression to the sub vector. Left + and right hand side of the assignment should be + independent.
    template<class AE>
    + vector_slice &operator += (const + vector_expression<AE> &ae)
    A computed assignment operator. Adds the vector + expression to the sub vector.
    template<class AE>
    + vector_slice &plus_assign (const + vector_expression<AE> &ae)
    Adds a vector expression to the sub vector. Left and + right hand side of the assignment should be independent.
    template<class AE>
    + vector_slice &operator -= (const + vector_expression<AE> &ae)
    A computed assignment operator. Subtracts the vector + expression from the sub vector.
    template<class AE>
    + vector_slice &minus_assign (const + vector_expression<AE> &ae)
    Subtracts a vector expression from the sub vector. + Left and right hand side of the assignment should be + independent.
    template<class AT>
    + vector_slice &operator *= (const AT &at)
    A computed assignment operator. Multiplies the sub + vector with a scalar.
    template<class AT>
    + vector_slice &operator /= (const AT &at)
    A computed assignment operator. Divides the sub + vector through a scalar.
    void swap (vector_slice &vs)Swaps the contents of the sub vectors.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the vector_slice.
    const_iterator end () constReturns a const_iterator pointing to the + end of the vector_slice.
    iterator begin () Returns a iterator pointing to the + beginning of the vector_slice.
    iterator end () Returns a iterator pointing to the end + of the vector_slice.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed vector_slice. +
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed vector_slice. +
    reverse_iterator rbegin () Returns a reverse_iterator pointing to + the beginning of the reversed vector_slice.
    reverse_iterator rend () Returns a reverse_iterator pointing to + the end of the reversed vector_slice.
    + +

    Interface

    + +
        // Vector based slice class
    +    template<class V>
    +    class vector_slice:
    +        public vector_expression<vector_slice<V> > {
    +    public:      
    +        typedef const V const_vector_type;
    +        typedef V vector_type;
    +        typedef typename V::size_type size_type;
    +        typedef typename V::difference_type difference_type;
    +        typedef typename V::value_type value_type;
    +        typedef typename V::const_reference const_reference;
    +        typedef typename V::reference reference;
    +        typedef typename V::const_pointer const_pointer;
    +        typedef typename V::pointer pointer;
    +        typedef const vector_const_reference<const vector_slice<vector_type> > const_closure_type;
    +        typedef vector_reference<vector_slice<vector_type> > closure_type;
    +        typedef slice::const_iterator const_iterator_type;
    +        typedef slice::const_iterator iterator_type;
    +        typedef typename storage_restrict_traits<typename V::storage_category,
    +                                                 dense_proxy_tag>::storage_category storage_category;
    +
    +        // Construction and destruction
    +        vector_slice ();
    +        vector_slice (vector_type &data, const slice &s);
    +
    +        // Accessors
    +        size_type start () const;
    +        size_type stride () const;
    +        size_type size () const;
    +        const_vector_type &data () const;
    +        vector_type &data ();
    +
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +        reference operator () (size_type i);
    +
    +        const_reference operator [] (size_type i) const;
    +        reference operator [] (size_type i);
    +
    +        vector_slice<vector_type> project (const range &r) const;
    +        vector_slice<vector_type> project (const slice &s) const;
    +
    +        // Assignment
    +        vector_slice &operator = (const vector_slice &vs);
    +        vector_slice &assign_temporary (vector_slice &vs);
    +        template<class AE>
    +        vector_slice &operator = (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector_slice &assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector_slice &operator += (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector_slice &plus_assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector_slice &operator -= (const vector_expression<AE> &ae);
    +        template<class AE>
    +        vector_slice &minus_assign (const vector_expression<AE> &ae);
    +        template<class AT>
    +        vector_slice &operator *= (const AT &at);
    +        template<class AT>
    +        vector_slice &operator /= (const AT &at);
    +
    +        // Swapping
    +        void swap (vector_slice &vs);
    +        friend void swap (vector_slice &vs1, vector_slice &vs2);
    +
    +        class const_iterator;
    +        class iterator;
    +
    +        // Element lookup
    +        const_iterator find_first (size_type i) const;
    +        iterator find_first (size_type i);
    +        const_iterator find_last (size_type i) const;
    +        iterator find_last (size_type i);
    +
    +        // Iterators simply are indices.
    +
    +        class const_iterator:
    +            public container_const_reference<vector_slice>,
    +            public random_access_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef typename V::const_iterator::iterator_category iterator_category;
    +            typedef typename V::const_iterator::difference_type difference_type;
    +            typedef typename V::const_iterator::value_type value_type;
    +            typedef typename V::const_iterator::reference reference;
    +            typedef typename V::const_iterator::pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const vector_slice &vs, const const_iterator_type &it);
    +            const_iterator (const iterator &it);
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +            const_iterator &operator += (difference_type n);
    +            const_iterator &operator -= (difference_type n);
    +            difference_type operator - (const const_iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +            bool operator <(const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        class iterator:
    +            public container_reference<vector_slice>,
    +            public random_access_iterator_base<iterator, value_type> {
    +        public:
    +            typedef typename V::iterator::iterator_category iterator_category;
    +            typedef typename V::iterator::difference_type difference_type;
    +            typedef typename V::iterator::value_type value_type;
    +            typedef typename V::iterator::reference reference;
    +            typedef typename V::iterator::pointer pointer;
    +
    +            // Construction and destruction
    +            iterator ();
    +            iterator (vector_slice &vs, const iterator_type &it);
    +
    +            // Arithmetic
    +            iterator &operator ++ ();
    +            iterator &operator -- ();
    +            iterator &operator += (difference_type n);
    +            iterator &operator -= (difference_type n);
    +            difference_type operator - (const iterator &it) const;
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment 
    +            iterator &operator = (const iterator &it);
    +
    +            // Comparison
    +            bool operator == (const iterator &it) const;
    +            bool operator <(const iterator &it) const;
    +        };
    +
    +        iterator begin ();
    +        iterator end ();
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +
    +        typedef reverse_iterator_base<iterator> reverse_iterator;
    +
    +        reverse_iterator rbegin ();
    +        reverse_iterator rend ();
    +    };
    + +

    Projections

    + +

    Prototypes

    + +
        template<class V>
    +    vector_slice<V> project (const vector_slice<V> &data, const range &r);
    +    template<class V>
    +    vector_slice<V> project (V &data, const slice &s);
    +    template<class V>
    +    const vector_slice<const V> project (const V &data, const slice &s);
    +    template<class V>
    +    vector_slice<V> project (const vector_slice<V> &data, const slice &s);
    + +

    Description

    + +

    The free project functions support the +construction of vector slices.

    + +

    Definition

    + +

    Defined in the header vector_proxy.hpp.

    + +

    Type requirements

    + + +
  • V is a model of Vector Expression.
  • +
    + +

    Preconditions

    + +
      +
    • s.start () + s.stride () * s.size () <= + data.size ()
    • +
    + +

    Complexity

    + +

    Linear depending from the size of the slice.

    + +

    Examples

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    vector<double> v (3);
    +    for (int i = 0; i < 3; ++ i)
    +        project (v, slice (0, 1, 3)) (i) = i;
    +    std::cout << project (v, slice (0, 1, 3)) << std::endl;
    +}
    + +
    + +

    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_sparse.htm b/doc/vector_sparse.htm new file mode 100644 index 00000000..ea782e01 --- /dev/null +++ b/doc/vector_sparse.htm @@ -0,0 +1,448 @@ + + + + + +Sparse Vector + + + + +

    c++boost.gifSparse Vector

    + +

    Sparse Vector

    + +

    Description

    + +

    The templated class sparse_vector<T, A> is +the base container adaptor for sparse vectors. For a n-dimensional +sparse vector and 0 <= i < n every non-zero +element vi is mapped to the i-th +element of the container.

    + +

    Example

    + +
    int main () {
    +    using namespace boost::numeric::ublas;
    +    sparse_vector<double> v (3, 3);
    +    for (int i = 0; i < v.size (); ++ i) 
    +        v (i) = i;
    +    std::cout << v << std::endl;
    +}
    + +

    Definition

    + +

    Defined in the header vector_sparse.hpp.

    + +

    Template parameters

    + + + + + + + + + + + + + + + + + + + + + + +
    Parameter Description Default
    T The type of object stored in the sparse vector.  
    FFunctor describing the storage organization.forward
    AThe type of the adapted array.map_array<std::size_t, T>
    + +

    Model of

    + +

    Vector.

    + +

    Type requirements

    + +

    None, except for those imposed by the requirements of Vector.

    + +

    Public base classes

    + +

    vector_expression<sparse_vector<T, A> > +

    + +

    Members

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Member Description
    sparse_vector () Allocates a sparse_vector that holds + zero elements.
    sparse_vector (size_type size, size_type + non_zeros)Allocates a sparse_vector that holds at + most size elements.
    sparse_vector (const sparse_vector &v)The copy constructor.
    template<class AE>
    + sparse_vector (size_type non_zeros, const + vector_expression<AE> &ae)
    The extended copy constructor.
    void resize (size_type size, size_type + non_zeros)Reallocates a sparse_vector to hold at + most size elements. The content of the sparse_vector + is preserved.
    size_type size () constReturns the size of the sparse_vector.
    const_reference operator () (size_type i) constReturns the value of the i-th element.
    reference operator () (size_type i)Returns a reference of the i-th element. +
    const_reference operator [] (size_type i) constReturns the value of the i-th element.
    reference operator [] (size_type i)Returns a reference of the i-th element. +
    sparse_vector &operator = (const + sparse_vector &v)The assignment operator.
    sparse_vector &assign_temporary + (sparse_vector &v)Assigns a temporary. May change the sparse vector v.
    template<class AE>
    + sparse_vector &operator = (const + vector_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    + sparse_vector &assign (const + vector_expression<AE> &ae)
    Assigns a vector expression to the sparse vector. + Left and right hand side of the assignment should be + independent.
    template<class AE>
    + sparse_vector &operator += (const + vector_expression<AE> &ae)
    A computed assignment operator. Adds the vector + expression to the sparse vector.
    template<class AE>
    + sparse_vector &plus_assign (const + vector_expression<AE> &ae)
    Adds a vector expression to the sparse vector. Left + and right hand side of the assignment should be + independent.
    template<class AE>
    + sparse_vector &operator -= (const + vector_expression<AE> &ae)
    A computed assignment operator. Subtracts the vector + expression from the sparse vector.
    template<class AE>
    + sparse_vector &minus_assign (const + vector_expression<AE> &ae)
    Subtracts a vector expression from the sparse vector. + Left and right hand side of the assignment should be + independent.
    template<class AT>
    + sparse_vector &operator *= (const AT &at)
    A computed assignment operator. Multiplies the sparse + vector with a scalar.
    template<class AT>
    + sparse_vector &operator /= (const AT &at)
    A computed assignment operator. Divides the sparse + vector through a scalar.
    void swap (sparse_vector &v)Swaps the contents of the sparse vectors.
    void insert (size_type i, const_reference t)Inserts the value t at the i-th + element.
    void erase (size_type i)Erases the value at the i-th element.
    void clear ()Clears the sparse vector.
    const_iterator begin () constReturns a const_iterator pointing to the + beginning of the sparse_vector.
    const_iterator end () constReturns a const_iterator pointing to the + end of the sparse_vector.
    iterator begin () Returns a iterator pointing to the + beginning of the sparse_vector.
    iterator end () Returns a iterator pointing to the end + of the sparse_vector.
    const_reverse_iterator rbegin () constReturns a const_reverse_iterator + pointing to the beginning of the reversed sparse_vector. +
    const_reverse_iterator rend () constReturns a const_reverse_iterator + pointing to the end of the reversed sparse_vector. +
    reverse_iterator rbegin () Returns a reverse_iterator pointing to + the beginning of the reversed sparse_vector. +
    reverse_iterator rend () Returns a reverse_iterator pointing to + the end of the reversed sparse_vector.
    + +

    Interface

    + +
        // Array based sparse vector class 
    +    template<class T, class A>
    +    class sparse_vector: 
    +        public vector_expression<sparse_vector<T, A> > {
    +    public:      
    +        typedef std::size_t size_type;
    +        typedef std::ptrdiff_t difference_type;
    +        typedef T value_type;
    +        typedef const T &const_reference;
    +        typedef T &reference;
    +        typedef const T *const_pointer;
    +        typedef T *pointer;
    +        typedef F functor_type;
    +        typedef A array_type;
    +        typedef const A const_array_type;
    +        typedef const sparse_vector<T, A> const_self_type;
    +        typedef sparse_vector<T, A> self_type;
    +        typedef const vector_const_reference<const_self_type> const_closure_type;
    +        typedef vector_reference<self_type> closure_type;
    +        typedef typename A::const_iterator const_iterator_type;
    +        typedef typename A::iterator iterator_type;
    +        typedef sparse_tag storage_category;
    +
    +        // Construction and destruction
    +        sparse_vector (); 
    +        sparse_vector (size_type size, size_type non_zeros = 0);
    +        sparse_vector (const sparse_vector &v);
    +        template<class AE>
    +        sparse_vector (const vector_expression<AE> &ae, size_type non_zeros = 0);
    +
    +        // Accessors
    +        size_type size () const;
    +        size_type non_zeros () const;
    +        const_array_type &data () const;
    +        array_type &data ();
    +
    +        // Resizing
    +        void resize (size_type size, size_type non_zeros = 0);
    +
    +        // Element access
    +        const_reference operator () (size_type i) const;
    +        reference operator () (size_type i);
    +
    +        const_reference operator [] (size_type i) const;
    +        reference operator [] (size_type i);
    +
    +        // Assignment
    +        sparse_vector &operator = (const sparse_vector &v);
    +        sparse_vector &assign_temporary (sparse_vector &v);
    +        template<class AE>
    +        sparse_vector &operator = (const vector_expression<AE> &ae);
    +        template<class AE>
    +        sparse_vector &reset (const vector_expression<AE> &ae);
    +        template<class AE>
    +        sparse_vector &assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        sparse_vector &operator += (const vector_expression<AE> &ae);
    +        template<class AE>
    +        sparse_vector &plus_assign (const vector_expression<AE> &ae);
    +        template<class AE>
    +        sparse_vector &operator -= (const vector_expression<AE> &ae);
    +        template<class AE>
    +        sparse_vector &minus_assign (const vector_expression<AE> &ae);
    +        template<class AT>
    +        sparse_vector &operator *= (const AT &at);
    +        template<class AT>
    +        sparse_vector &operator /= (const AT &at);
    +
    +        // Swapping
    +        void swap (sparse_vector &v);
    +        friend void swap (sparse_vector &v1, sparse_vector &v2);
    +
    +        // Element insertion and erasure
    +        void insert (size_type i, const_reference t);
    +        void erase (size_type i);
    +        void clear ();
    +
    +        class const_iterator;
    +        class iterator;
    +
    +        // Element lookup
    +        const_iterator find (size_type i) const;
    +        iterator find (size_type i);
    +        const_iterator find_first (size_type i) const;
    +        iterator find_first (size_type i);
    +        const_iterator find_last (size_type i) const;
    +        iterator find_last (size_type i);
    +
    +        // Iterators simply are pointers.
    +
    +        class const_iterator:
    +            public container_const_reference<sparse_vector>,
    +            public bidirectional_iterator_base<const_iterator, value_type> {
    +        public:
    +            typedef sparse_bidirectional_iterator_tag iterator_category;
    +            typedef typename sparse_vector::difference_type difference_type;
    +            typedef typename sparse_vector::value_type value_type;
    +            typedef typename sparse_vector::const_reference reference;
    +            typedef typename sparse_vector::const_pointer pointer;
    +
    +            // Construction and destruction
    +            const_iterator ();
    +            const_iterator (const sparse_vector &v, const const_iterator_type &it);
    +            const_iterator (const iterator &it);
    +
    +            // Arithmetic
    +            const_iterator &operator ++ ();
    +            const_iterator &operator -- ();
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment
    +            const_iterator &operator = (const const_iterator &it);
    +
    +            // Comparison
    +            bool operator == (const const_iterator &it) const;
    +        };
    +
    +        const_iterator begin () const;
    +        const_iterator end () const;
    +
    +        class iterator:
    +            public container_reference<sparse_vector>,
    +            public bidirectional_iterator_base<iterator, value_type> {
    +        public:
    +            typedef sparse_bidirectional_iterator_tag iterator_category;
    +            typedef typename sparse_vector::difference_type difference_type;
    +            typedef typename sparse_vector::value_type value_type;
    +            typedef typename sparse_vector::reference reference;
    +            typedef typename sparse_vector::pointer pointer;
    +
    +            // Construction and destruction
    +            iterator ();
    +            iterator (sparse_vector &v, const iterator_type &it);
    +
    +            // Arithmetic
    +            iterator &operator ++ ();
    +            iterator &operator -- ();
    +
    +            // Dereference
    +            reference operator * () const;
    +
    +            // Index
    +            size_type index () const;
    +
    +            // Assignment
    +            iterator &operator = (const iterator &it);
    +
    +            // Comparison
    +            bool operator == (const iterator &it) const;
    +        };
    +
    +        iterator begin ();
    +        iterator end ();
    +
    +        // Reverse iterator
    +
    +        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    +
    +        const_reverse_iterator rbegin () const;
    +        const_reverse_iterator rend () const;
    +
    +        typedef reverse_iterator_base<iterator> reverse_iterator;
    +
    +        reverse_iterator rbegin ();
    +        reverse_iterator rend ();
    +    };
    + +
    + +

    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/test1/Jamfile b/test1/Jamfile new file mode 100644 index 00000000..4b29027a --- /dev/null +++ b/test1/Jamfile @@ -0,0 +1,13 @@ +subproject libs/numeric/ublas/test1 ; + +SOURCES = test1 test11 test12 test13 ; + +exe test1 + : $(SOURCES).cpp + : $(BOOST_ROOT) + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" + ; + + + + diff --git a/test1/test1.cpp b/test1/test1.cpp new file mode 100644 index 00000000..2e2fbb80 --- /dev/null +++ b/test1/test1.cpp @@ -0,0 +1,36 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include + +#include "test1.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/test1/test1.dsp b/test1/test1.dsp new file mode 100644 index 00000000..d56610b3 --- /dev/null +++ b/test1/test1.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/test1/test1.hpp b/test1/test1.hpp new file mode 100644 index 00000000..40cc856e --- /dev/null +++ b/test1/test1.hpp @@ -0,0 +1,40 @@ +#ifndef TEST1_H +#define TEST1_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] = 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) = i * size1 + j + 1.f; +} + +void test_vector (); + +void test_matrix_vector (); + +void test_matrix (); + +#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/test1/test11.cpp b/test1/test11.cpp new file mode 100644 index 00000000..3ffe1fcd --- /dev/null +++ b/test1/test11.cpp @@ -0,0 +1,207 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include + +#include "test1.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 = 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 + std::cout << "float, bounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "double, bounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_vector, ublas::bounded_array, 3> >, 3 > () (); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_vector, ublas::bounded_array, 3> >, 3 > () (); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + std::cout << "float, unbounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "double, unbounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_vector, ublas::unbounded_array > >, 3 > () (); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_vector, ublas::unbounded_array > >, 3 > () (); +#endif + +#ifdef USE_STD_VECTOR + std::cout << "float, std::vector" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "double, std::vector" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_vector, std::vector > >, 3 > () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_vector, std::vector > >, 3 > () (); +#endif +} + diff --git a/test1/test12.cpp b/test1/test12.cpp new file mode 100644 index 00000000..5e606c71 --- /dev/null +++ b/test1/test12.cpp @@ -0,0 +1,216 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include + +#include "test1.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 + std::cout << "float, bounded_array" << std::endl; + test_my_matrix_vector >, + ublas::matrix >, 3> () (); + + std::cout << "double, bounded_array" << std::endl; + test_my_matrix_vector >, + ublas::matrix >, 3> () (); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::matrix, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3> () (); + + std::cout << "std::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_UNBOUNDED_ARRAY + std::cout << "float, unbounded_array" << std::endl; + test_my_matrix_vector >, + ublas::matrix >, 3> () (); + + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix_vector >, + ublas::matrix >, 3> () (); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::matrix, ublas::row_major, ublas::unbounded_array > >, 3> () (); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::matrix, ublas::row_major, ublas::unbounded_array > >, 3> () (); +#endif + +#ifdef USE_STD_VECTOR + std::cout << "float, std::vector" << std::endl; + test_my_matrix_vector >, + ublas::matrix >, 3> () (); + + std::cout << "double, std::vector" << std::endl; + test_my_matrix_vector >, + ublas::matrix >, 3> () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix_vector, std::vector > >, + ublas::matrix, ublas::row_major, std::vector > >, 3> () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix_vector, std::vector > >, + ublas::matrix, ublas::row_major, std::vector > >, 3> () (); +#endif +#endif + +#ifdef USE_VECTOR_OF_VECTOR +#ifdef USE_BOUNDED_ARRAY + std::cout << "float, bounded_array" << std::endl; + test_my_matrix_vector >, + ublas::vector_of_vector, 3 + 1> >, 3> () (); + + std::cout << "double, bounded_array" << std::endl; + test_my_matrix_vector >, + ublas::vector_of_vector, 3 + 1> >, 3> () (); + + std::cout << "std::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> () (); + + std::cout << "std::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_UNBOUNDED_ARRAY + std::cout << "float, unbounded_array" << std::endl; + test_my_matrix_vector >, + ublas::vector_of_vector > >, 3> () (); + + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix_vector >, + ublas::vector_of_vector > >, 3> () (); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::vector_of_vector, ublas::row_major, ublas::unbounded_array > > >, 3> () (); + + std::cout << "std::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_STD_VECTOR + std::cout << "float, std::vector" << std::endl; + test_my_matrix_vector >, + ublas::vector_of_vector > >, 3> () (); + + std::cout << "double, std::vector" << std::endl; + test_my_matrix_vector >, + ublas::vector_of_vector > >, 3> () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix_vector, std::vector > >, + ublas::vector_of_vector, ublas::row_major, std::vector > > >, 3> () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix_vector, std::vector > >, + ublas::vector_of_vector, ublas::row_major, std::vector > > >, 3> () (); +#endif +#endif +} + + diff --git a/test1/test13.cpp b/test1/test13.cpp new file mode 100644 index 00000000..5c85729f --- /dev/null +++ b/test1/test13.cpp @@ -0,0 +1,246 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include + +#include "test1.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 + std::cout << "float, bounded_array" << std::endl; + test_my_matrix >, 3 > () (); + + std::cout << "double, bounded_array" << std::endl; + test_my_matrix >, 3 > () (); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + std::cout << "float, unbounded_array" << std::endl; + test_my_matrix >, 3 > () (); + + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix >, 3 > () (); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::unbounded_array > >, 3 > () (); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::unbounded_array > >, 3 > () (); +#endif + +#ifdef USE_STD_VECTOR + std::cout << "float, std::vector" << std::endl; + test_my_matrix >, 3 > () (); + + std::cout << "double, std::vector" << std::endl; + test_my_matrix >, 3 > () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix, ublas::row_major, std::vector > >, 3 > () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix, ublas::row_major, std::vector > >, 3 > () (); +#endif +#endif + +#ifdef USE_VECTOR_OF_VECTOR +#ifdef USE_BOUNDED_ARRAY + std::cout << "float, bounded_array" << std::endl; + test_my_matrix, 3 + 1> >, 3 > () (); + + std::cout << "double, bounded_array" << std::endl; + test_my_matrix, 3 + 1> >, 3 > () (); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::bounded_array, 3>, 3 + 1> >, 3 > () (); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::bounded_array, 3>, 3 + 1> >, 3 > () (); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + std::cout << "float, unbounded_array" << std::endl; + test_my_matrix > >, 3 > () (); + + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix > >, 3 > () (); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::unbounded_array > > >, 3 > () (); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::unbounded_array > > >, 3 > () (); +#endif + +#ifdef USE_STD_VECTOR + std::cout << "float, std::vector" << std::endl; + test_my_matrix > >, 3 > () (); + + std::cout << "double, std::vector" << std::endl; + test_my_matrix > >, 3 > () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix, ublas::row_major, std::vector > > >, 3 > () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix, ublas::row_major, std::vector > > >, 3 > () (); +#endif +#endif +} + + + diff --git a/test2/Jamfile b/test2/Jamfile new file mode 100644 index 00000000..e8d68138 --- /dev/null +++ b/test2/Jamfile @@ -0,0 +1,10 @@ +subproject libs/numeric/ublas/test2 ; + +SOURCES = test2 test21 test22 test23 ; + +exe test2 + : $(SOURCES).cpp + : $(BOOST_ROOT) + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" + ; + diff --git a/test2/test2.cpp b/test2/test2.cpp new file mode 100644 index 00000000..44f3c45b --- /dev/null +++ b/test2/test2.cpp @@ -0,0 +1,81 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include + +#include + +#include "test2.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 + + std::cout << "test_blas_1" << std::endl; + + std::cout << "float" << std::endl; + test_blas_1, 3> () (); + + std::cout << "double" << std::endl; + test_blas_1, 3> () (); + +#ifdef USE_STD_COMPLEX + std::cout << "std::complex" << std::endl; + test_blas_1 >, 3> () (); + + std::cout << "std::complex" << std::endl; + test_blas_1 >, 3> () (); +#endif + + std::cout << "test_blas_2" << std::endl; + + std::cout << "float" << std::endl; + test_blas_2, ublas::matrix, 3> () (); + + std::cout << "double" << std::endl; + test_blas_2, ublas::matrix, 3> () (); + +#ifdef USE_STD_COMPLEX + std::cout << "std::complex" << std::endl; + test_blas_2 >, ublas::matrix >, 3> () (); + + std::cout << "std::complex" << std::endl; + test_blas_2 >, ublas::matrix >, 3> () (); +#endif + + std::cout << "float" << std::endl; + test_blas_3, 3> () (); + + std::cout << "double" << std::endl; + test_blas_3, 3> () (); + +#ifdef USE_STD_COMPLEX + std::cout << "std::complex" << std::endl; + test_blas_3 >, 3> () (); + + std::cout << "std::complex" << std::endl; + test_blas_3 >, 3> () (); +#endif + return 0; +} + diff --git a/test2/test2.dsp b/test2/test2.dsp new file mode 100644 index 00000000..2beeaac3 --- /dev/null +++ b/test2/test2.dsp @@ -0,0 +1,218 @@ +# Microsoft Developer Studio Project File - Name="test2" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=test2 - 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 "test2.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 "test2.mak" CFG="test2 - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "test2 - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "test2 - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName ""$/boost/libs/numeric/ublas/test2", VDCAAAAA" +# PROP Scc_LocalPath "." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "test2 - 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 /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)" == "test2 - 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 "test2 - Win32 Release" +# Name "test2 - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\test2.cpp +# End Source File +# Begin Source File + +SOURCE=.\test21.cpp +# End Source File +# Begin Source File + +SOURCE=.\test22.cpp +# End Source File +# Begin Source File + +SOURCE=.\test23.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=.\test2.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/test2/test2.hpp b/test2/test2.hpp new file mode 100644 index 00000000..2e24c43d --- /dev/null +++ b/test2/test2.hpp @@ -0,0 +1,72 @@ +#ifndef TEST2_H +#define TEST2_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] = i + 1.f; +} + +template +void initialize_matrix (M &m, ublas::lower_tag) { + int size1 = m.size1 (); + int size2 = m.size2 (); + for (int i = 0; i < size1; ++ i) { + int j = 0; + for (; j <= i; ++ j) + m (i, j) = i * size1 + j + 1.f; + for (; j < size2; ++ j) + m (i, j) = 0.f; + } +} +template +void initialize_matrix (M &m, ublas::upper_tag) { + int size1 = m.size1 (); + int size2 = m.size2 (); + for (int i = 0; i < size1; ++ i) { + int j = 0; + for (; j < i; ++ j) + m (i, j) = 0.f; + for (; j < size2; ++ j) + m (i, j) = i * size1 + j + 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) = i * size1 + j + 1.f; +} + +template +struct test_blas_1 { + typedef typename V::value_type value_type; + typedef typename ublas::type_traits::real_type real_type; + + void operator () (); +}; + +template +struct test_blas_2 { + typedef typename V::value_type value_type; + + void operator () (); +}; + +template +struct test_blas_3 { + typedef typename M::value_type value_type; + + void operator () (); +}; + +// #define USE_STD_COMPLEX + +#endif + + diff --git a/test2/test21.cpp b/test2/test21.cpp new file mode 100644 index 00000000..269fc801 --- /dev/null +++ b/test2/test21.cpp @@ -0,0 +1,97 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include + +#include + +#include "test2.hpp" + +template +void test_blas_1::operator () () { + try { + value_type t; + real_type n; + V v1 (N), v2 (N); + + // _asum + initialize_vector (v1); + n = ublas::blas_1::asum (v1); + std::cout << "asum (v1) = " << n << std::endl; + + // _amax + initialize_vector (v1); + n = ublas::blas_1::amax (v1); + std::cout << "amax (v1) = " << n << std::endl; + + // _nrm2 + initialize_vector (v1); + n = ublas::blas_1::nrm2 (v1); + std::cout << "nrm2 (v1) = " << n << std::endl; + + // _dot + // _dotu + // _dotc + initialize_vector (v1); + initialize_vector (v2); + t = ublas::blas_1::dot (v1, v2); + std::cout << "dot (v1, v2) = " << t << std::endl; + t = ublas::blas_1::dot (ublas::conj (v1), v2); + std::cout << "dot (conj (v1), v2) = " << t << std::endl; + + // _copy + initialize_vector (v2); + ublas::blas_1::copy (v1, v2); + std::cout << "copy (v1, v2) = " << v1 << std::endl; + + // _swap + initialize_vector (v1); + initialize_vector (v2); + ublas::blas_1::swap (v1, v2); + std::cout << "swap (v1, v2) = " << v1 << " " << v2 << std::endl; + + // _scal + // csscal + // zdscal + initialize_vector (v1); + ublas::blas_1::scal (v1, value_type (1)); + std::cout << "scal (v1, 1) = " << v1 << std::endl; + + // _axpy + initialize_vector (v1); + initialize_vector (v2); + ublas::blas_1::axpy (v1, value_type (1), v2); + std::cout << "axpy (v1, 1, v2) = " << v1 << std::endl; + + // _rot + initialize_vector (v1); + initialize_vector (v2); + ublas::blas_1::rot (value_type (1), v1, value_type (1), v2); + std::cout << "rot (1, v1, 1, v2) = " << v1 << " " << v2 << std::endl; + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } +} + +template struct test_blas_1, 3>; +template struct test_blas_1, 3>; + +#ifdef USE_STD_COMPLEX +template struct test_blas_1 >, 3>; +template struct test_blas_1 >, 3>; +#endif diff --git a/test2/test22.cpp b/test2/test22.cpp new file mode 100644 index 00000000..e05b28e4 --- /dev/null +++ b/test2/test22.cpp @@ -0,0 +1,150 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include + +#include + +#include "test2.hpp" + +template +void test_blas_2::operator () () { + try { + V v1 (N), v2 (N); + M m (N, N); + + // _t_mv + initialize_vector (v1); + initialize_matrix (m); + ublas::blas_2::tmv (v1, m); + std::cout << "tmv (v1, m) = " << v1 << std::endl; + initialize_vector (v1); + initialize_matrix (m); + ublas::blas_2::tmv (v1, ublas::trans (m)); + std::cout << "tmv (v1, trans (m)) = " << v1 << std::endl; +#ifdef USE_STD_COMPLEX + initialize_vector (v1); + initialize_matrix (m); + ublas::blas_2::tmv (v1, ublas::herm (m)); + std::cout << "tmv (v1, herm (m)) = " << v1 << std::endl; +#endif + + // _t_sv + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m, ublas::lower_tag ()); + ublas::blas_2::tsv (v1, m, ublas::lower_tag ()); + std::cout << "tsv (v1, m) = " << v1 << " " << ublas::prod (m, v1) - v2 << std::endl; + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m, ublas::upper_tag ()); + ublas::blas_2::tsv (v1, ublas::trans (m), ublas::lower_tag ()); + std::cout << "tsv (v1, trans (m)) = " << v1 << " " << ublas::prod (ublas::trans (m), v1) - v2 << std::endl; +#ifdef USE_STD_COMPLEX + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m, ublas::upper_tag ()); + ublas::blas_2::tsv (v1, ublas::herm (m), ublas::lower_tag ()); + std::cout << "tsv (v1, herm (m)) = " << v1 << " " << ublas::prod (ublas::herm (m), v1) - v2 << std::endl; +#endif + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m, ublas::upper_tag ()); + ublas::blas_2::tsv (v1, m, ublas::upper_tag ()); + std::cout << "tsv (v1, m) = " << v1 << " " << ublas::prod (m, v1) - v2 << std::endl; + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m, ublas::lower_tag ()); + ublas::blas_2::tsv (v1, ublas::trans (m), ublas::upper_tag ()); + std::cout << "tsv (v1, trans (m)) = " << v1 << " " << ublas::prod (ublas::trans (m), v1) - v2 << std::endl; +#ifdef USE_STD_COMPLEX + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m, ublas::lower_tag ()); + ublas::blas_2::tsv (v1, ublas::herm (m), ublas::upper_tag ()); + std::cout << "tsv (v1, herm (m)) = " << v1 << " " << ublas::prod (ublas::herm (m), v1) - v2 << std::endl; +#endif + + // _g_mv + // _s_mv + // _h_mv + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m); + ublas::blas_2::gmv (v1, value_type (1), value_type (1), m, v2); + std::cout << "gmv (v1, 1, 1, m, v2) = " << v1 << std::endl; + ublas::blas_2::gmv (v1, value_type (1), value_type (1), ublas::trans (m), v2); + std::cout << "gmv (v1, 1, 1, trans (m), v2) = " << v1 << std::endl; +#ifdef USE_STD_COMPLEX + ublas::blas_2::gmv (v1, value_type (1), value_type (1), ublas::herm (m), v2); + std::cout << "gmv (v1, 1, 1, herm (m), v2) = " << v1 << std::endl; +#endif + + // _g_r + // _g_ru + // _g_rc + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m); + ublas::blas_2::gr (m, value_type (1), v1, v2); + std::cout << "gr (m, 1, v1, v2) = " << m << std::endl; + ublas::blas_2::gr (m, value_type (1), v1, ublas::conj (v2)); + std::cout << "gr (m, 1, v1, conj (v2)) = " << m << std::endl; + + // _s_r + initialize_vector (v1); + initialize_matrix (m); + ublas::blas_2::sr (m, value_type (1), v1); + std::cout << "sr (m, 1, v1) = " << m << std::endl; + +#ifdef USE_STD_COMPLEX + // _h_r + initialize_vector (v1); + initialize_matrix (m); + ublas::blas_2::hr (m, value_type (1), v1); + std::cout << "hr (m, 1, v1) = " << m << std::endl; +#endif + + // _s_r2 + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m); + ublas::blas_2::sr2 (m, value_type (1), v1, v2); + std::cout << "sr2 (m, 1, v1, v2) = " << m << std::endl; + +#ifdef USE_STD_COMPLEX + // _h_r2 + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m); + ublas::blas_2::hr2 (m, value_type (1), v1, v2); + std::cout << "hr2 (m, 1, v1, v2) = " << m << std::endl; +#endif + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } +} + +template struct test_blas_2, ublas::matrix, 3>; +template struct test_blas_2, ublas::matrix, 3>; + +#ifdef USE_STD_COMPLEX +template struct test_blas_2 >, ublas::matrix >, 3>; +template struct test_blas_2 >, ublas::matrix >, 3>; +#endif + diff --git a/test2/test23.cpp b/test2/test23.cpp new file mode 100644 index 00000000..7eb94cba --- /dev/null +++ b/test2/test23.cpp @@ -0,0 +1,210 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include + +#include + +#include "test2.hpp" + +template +void test_blas_3::operator () () { + try { + M m1 (N, N), m2 (N, N), m3 (N, N); + + // _t_mm + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), m2, m1); + std::cout << "tmm (m1, 1, m2, m1) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), m2, ublas::trans (m1)); + std::cout << "tmm (m1, 1, m2, trans (m1)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), ublas::trans (m2), m1); + std::cout << "tmm (m1, 1, trans (m2), m1) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), ublas::trans (m2), ublas::trans (m1)); + std::cout << "tmm (m1, 1, trans (m2), trans (m1)) = " << m1 << std::endl; +#ifdef USE_STD_COMPLEX + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), m2, ublas::herm (m1)); + std::cout << "tmm (m1, 1, m2, herm (m1)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), ublas::herm (m2), m1); + std::cout << "tmm (m1, 1, herm (m2), m1) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), ublas::trans (m2), ublas::herm (m1)); + std::cout << "tmm (m1, 1, trans (m2), herm (m1)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), ublas::herm (m2), ublas::trans (m1)); + std::cout << "tmm (m1, 1, herm (m2), trans (m1)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), ublas::herm (m2), ublas::herm (m1)); + std::cout << "tmm (m1, 1, herm (m2), herm (m1)) = " << m1 << std::endl; +#endif + + // _t_sm + initialize_matrix (m1); + 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; + 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; +#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; +#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; + 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; +#ifdef USE_STD_COMPLEX + initialize_matrix (m1); + initialize_matrix (m2, ublas::lower_tag ()); + ublas::blas_3::tsm (m1, value_type (1), ublas::herm (m2), ublas::upper_tag ()); + std::cout << "tsm (m1, 1, herm (m2)) = " << m1 << " " << ublas::prod (ublas::herm (m2), m1) - value_type (1) * m3 << std::endl; +#endif + + // _g_mm + // _s_mm + // _h_mm + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), m2, m3); + std::cout << "gmm (m1, 1, 1, m2, m3) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), ublas::trans (m2), m3); + std::cout << "gmm (m1, 1, 1, trans (m2), m3) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), m2, ublas::trans (m3)); + std::cout << "gmm (m1, 1, 1, m2, trans (m3)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), ublas::trans (m2), ublas::trans (m3)); + std::cout << "gmm (m1, 1, 1, trans (m2), trans (m3)) = " << m1 << std::endl; +#ifdef USE_STD_COMPLEX + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), ublas::herm (m2), m3); + std::cout << "gmm (m1, 1, 1, herm (m2), m3) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), m2, ublas::herm (m3)); + std::cout << "gmm (m1, 1, 1, m2, herm (m3)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), ublas::herm (m2), ublas::trans (m3)); + std::cout << "gmm (m1, 1, 1, herm (m2), trans (m3)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), ublas::trans (m2), ublas::herm (m3)); + std::cout << "gmm (m1, 1, 1, trans (m2), herm (m3)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), ublas::herm (m2), ublas::herm (m3)); + std::cout << "gmm (m1, 1, 1, herm (m2), herm (m3)) = " << m1 << std::endl; +#endif + + // s_rk + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::srk (m1, value_type (1), value_type (1), m2); + std::cout << "srk (m1, 1, 1, m2) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::srk (m1, value_type (1), value_type (1), ublas::trans (m2)); + std::cout << "srk (m1, 1, 1, trans (m2)) = " << m1 << std::endl; + +#ifdef USE_STD_COMPLEX + // h_rk + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::hrk (m1, value_type (1), value_type (1), m2); + std::cout << "hrk (m1, 1, 1, m2) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::hrk (m1, value_type (1), value_type (1), ublas::herm (m2)); + std::cout << "hrk (m1, 1, 1, herm (m2)) = " << m1 << std::endl; +#endif + + // s_r2k + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::sr2k (m1, value_type (1), value_type (1), m2, m3); + std::cout << "sr2k (m1, 1, 1, m2, m3) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::sr2k (m1, value_type (1), value_type (1), ublas::trans (m2), ublas::trans (m3)); + std::cout << "sr2k (m1, 1, 1, trans (m2), trans (m3)) = " << m1 << std::endl; + +#ifdef USE_STD_COMPLEX + // h_r2k + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::hr2k (m1, value_type (1), value_type (1), m2, m3); + std::cout << "hr2k (m1, 1, 1, m2, m3) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::hr2k (m1, value_type (1), value_type (1), ublas::herm (m2), ublas::herm (m3)); + std::cout << "hr2k (m1, 1, 1, herm (m2), herm (m3)) = " << m1 << std::endl; +#endif + } + catch (std::exception &e) { + std::cout << e.what () << std::endl; + } + catch (...) { + std::cout << "unknown exception" << std::endl; + } +} + +template struct test_blas_3, 3>; +template struct test_blas_3, 3>; + +#ifdef USE_STD_COMPLEX +template struct test_blas_3 >, 3>; +template struct test_blas_3 >, 3>; +#endif diff --git a/test3/Jamfile b/test3/Jamfile new file mode 100644 index 00000000..16ddc185 --- /dev/null +++ b/test3/Jamfile @@ -0,0 +1,10 @@ +subproject libs/numeric/ublas/test3 ; + +SOURCES = test3 test31 test32 test33 ; + +exe test3 + : $(SOURCES).cpp + : $(BOOST_ROOT) + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" + ; + diff --git a/test3/test3.cpp b/test3/test3.cpp new file mode 100644 index 00000000..c7124f44 --- /dev/null +++ b/test3/test3.cpp @@ -0,0 +1,37 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include +#include + +#include "test3.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/test3/test3.dsp b/test3/test3.dsp new file mode 100644 index 00000000..be2cd916 --- /dev/null +++ b/test3/test3.dsp @@ -0,0 +1,219 @@ +# Microsoft Developer Studio Project File - Name="test3" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=test3 - 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 "test3.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 "test3.mak" CFG="test3 - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "test3 - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "test3 - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName ""$/boost/libs/numeric/ublas/test3", WDCAAAAA" +# PROP Scc_LocalPath "." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "test3 - 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)" == "test3 - 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 "test3 - Win32 Release" +# Name "test3 - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\test3.cpp +# End Source File +# Begin Source File + +SOURCE=.\test31.cpp +# End Source File +# Begin Source File + +SOURCE=.\test32.cpp +# End Source File +# Begin Source File + +SOURCE=.\test33.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=.\test3.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/test3/test3.hpp b/test3/test3.hpp new file mode 100644 index 00000000..bba4551e --- /dev/null +++ b/test3/test3.hpp @@ -0,0 +1,48 @@ +#ifndef TEST3_H +#define TEST3_H + +namespace ublas = boost::numeric::ublas; + +template +void initialize_vector (V &v) { + int size = v.size (); + for (int i = 0; i < size; i += 2) + v [i] = i + 1.f; +} + +template +void initialize_matrix (M &m) { + int size1 = m.size1 (); + int size2 = m.size2 (); + for (int i = 0; i < size1; i += 2) + for (int j = 0; j < size2; j += 2) + m (i, j) = i * size1 + j + 1.f; +} + +void test_vector (); + +void test_matrix_vector (); + +void test_matrix (); + +// Borland gets a VIRDEF error?! +#ifndef __BORLANDC__ +#define USE_RANGE +// #define USE_SLICE +#endif + +#define USE_MAP_ARRAY +// #define USE_STD_MAP + +#define USE_SPARSE_VECTOR +// #define USE_COMPRESSED_VECTOR + +#define USE_SPARSE_MATRIX +// #define USE_SPARSE_VECTOR_OF_SPARSE_VECTOR +// #define USE_COMPRESSED_MATRIX + +#endif + + + + diff --git a/test3/test31.cpp b/test3/test31.cpp new file mode 100644 index 00000000..33698f6d --- /dev/null +++ b/test3/test31.cpp @@ -0,0 +1,211 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include +#include + +#include "test3.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 = 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, N), v2 (N, N), v3 (N, 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_SPARSE_VECTOR +#ifdef USE_MAP_ARRAY + std::cout << "float, map_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "double, map_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "std::complex, map_array" << std::endl; + test_my_vector, ublas::map_array > >, 3 > () (); + + std::cout << "std::complex, map_array" << std::endl; + test_my_vector, ublas::map_array > >, 3 > () (); +#endif + +#ifdef USE_STD_MAP + std::cout << "float, std::map" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "double, std::map" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "std::complex, std::map" << std::endl; + test_my_vector, std::map > >, 3 > () (); + + std::cout << "std::complex, std::map" << std::endl; + test_my_vector, std::map > > , 3 > () (); +#endif +#endif + +#ifdef USE_COMPRESSED_VECTOR + std::cout << "float" << std::endl; + test_my_vector, 3 > () (); + + std::cout << "double" << std::endl; + test_my_vector, 3 > () (); + + std::cout << "std::complex" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "std::complex" << std::endl; + test_my_vector >, 3 > () (); +#endif +} + diff --git a/test3/test32.cpp b/test3/test32.cpp new file mode 100644 index 00000000..371e5c5c --- /dev/null +++ b/test3/test32.cpp @@ -0,0 +1,200 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include +#include + +#include "test3.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, N), v2 (N, N); + M m1 (N, N, N * N); + + (*this) (v1, v2, m1); + + ublas::matrix_row mr1 (m1, 0), mr2 (m1, N - 1); + (*this) (mr1, mr2, m1); + + ublas::matrix_column mc1 (m1, 0), mc2 (m1, N - 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_SPARSE_MATRIX +#ifdef USE_MAP_ARRAY + std::cout << "float, map_array" << std::endl; + test_my_matrix_vector >, + ublas::sparse_matrix >, 3 > () (); + + std::cout << "double, map_array" << std::endl; + test_my_matrix_vector >, + ublas::sparse_matrix >, 3 > () (); + + std::cout << "std::complex, map_array" << std::endl; + test_my_matrix_vector, ublas::map_array > >, + ublas::sparse_matrix, ublas::row_major, ublas::map_array > >, 3 > () (); + + std::cout << "std::complex, map_array" << std::endl; + test_my_matrix_vector, ublas::map_array > >, + ublas::sparse_matrix, ublas::row_major, ublas::map_array > >, 3 > () (); +#endif + +#ifdef USE_STD_MAP + std::cout << "float, std::map" << std::endl; + test_my_matrix_vector >, + ublas::sparse_matrix >, 3 > () (); + + std::cout << "double, std::map" << std::endl; + test_my_matrix_vector >, + ublas::sparse_matrix >, 3 > () (); + + std::cout << "std::complex, std::map" << std::endl; + test_my_matrix_vector, std::map > >, + ublas::sparse_matrix, ublas::row_major, std::map > >, 3 > () (); + + std::cout << "std::complex, std::map" << std::endl; + test_my_matrix_vector, std::map > >, + ublas::sparse_matrix, ublas::row_major, std::map > >, 3 > () (); +#endif +#endif + +#ifdef USE_SPARSE_VECTOR_OF_SPARSE_VECTOR +#ifdef USE_MAP_ARRAY + std::cout << "float, map_array" << std::endl; + test_my_matrix_vector >, + ublas::sparse_vector_of_sparse_vector > >, 3 > () (); + + std::cout << "double, map_array" << std::endl; + test_my_matrix_vector >, + ublas::sparse_vector_of_sparse_vector > >, 3 > () (); + + std::cout << "std::complex, map_array" << std::endl; + test_my_matrix_vector, ublas::map_array > >, + ublas::sparse_vector_of_sparse_vector, ublas::row_major, ublas::map_array > > >, 3 > () (); + + std::cout << "std::complex, map_array" << std::endl; + test_my_matrix_vector, ublas::map_array > >, + ublas::sparse_vector_of_sparse_vector, ublas::row_major, ublas::map_array > > >, 3 > () (); +#endif + +#ifdef USE_STD_MAP + std::cout << "float, std::map" << std::endl; + test_my_matrix_vector >, + ublas::sparse_vector_of_sparse_vector > >, 3 > () (); + + std::cout << "double, std::map" << std::endl; + test_my_matrix_vector >, + ublas::sparse_vector_of_sparse_vector > >, 3 > () (); + + std::cout << "std::complex, std::map" << std::endl; + test_my_matrix_vector, std::map > >, + ublas::sparse_vector_of_sparse_vector, ublas::row_major, std::map > > >, 3 > () (); + + std::cout << "std::complex, std::map" << std::endl; + test_my_matrix_vector, std::map > >, + ublas::sparse_vector_of_sparse_vector, ublas::row_major, std::map > > >, 3 > () (); +#endif +#endif + +#ifdef USE_COMPRESSED_MATRIX + std::cout << "float" << std::endl; + test_my_matrix_vector, + ublas::compressed_matrix, 3 > () (); + + std::cout << "double" << std::endl; + test_my_matrix_vector, + ublas::compressed_matrix, 3 > () (); + + std::cout << "std::complex" << std::endl; + test_my_matrix_vector >, + ublas::compressed_matrix >, 3 > () (); + + std::cout << "std::complex" << std::endl; + test_my_matrix_vector >, + ublas::compressed_matrix >, 3 > () (); +#endif +} + diff --git a/test3/test33.cpp b/test3/test33.cpp new file mode 100644 index 00000000..2fe8f3a4 --- /dev/null +++ b/test3/test33.cpp @@ -0,0 +1,233 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include +#include + +#include "test3.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, N * N), m2 (N, N, N * N), m3 (N, N, 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_SPARSE_MATRIX +#ifdef USE_MAP_ARRAY + std::cout << "float, map_array" << std::endl; + test_my_matrix >, 3 > () (); + + std::cout << "double, map_array" << std::endl; + test_my_matrix >, 3 > () (); + + std::cout << "std::complex, map_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::map_array > >, 3 > () (); + + std::cout << "std::complex, map_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::map_array > >, 3 > () (); +#endif + +#ifdef USE_STD_MAP + std::cout << "float, std::map" << std::endl; + test_my_matrix >, 3 > () (); + + std::cout << "double, std::map" << std::endl; + test_my_matrix >, 3 > () (); + + std::cout << "std::complex, std::map" << std::endl; + test_my_matrix, ublas::row_major, std::map > >, 3 > () (); + + std::cout << "std::complex, std::map" << std::endl; + test_my_matrix, ublas::row_major, std::map > >, 3 > () (); +#endif +#endif + +#ifdef USE_SPARSE_VECTOR_OF_SPARSE_VECTOR +#ifdef USE_MAP_ARRAY + std::cout << "float, map_array" << std::endl; + test_my_matrix > >, 3 > () (); + + std::cout << "double, map_array" << std::endl; + test_my_matrix > >, 3 > () (); + + std::cout << "std::complex, map_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::map_array > > >, 3 > () (); + + std::cout << "std::complex, map_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::map_array > > >, 3 > () (); +#endif + +#ifdef USE_STD_MAP + std::cout << "float, std::map" << std::endl; + test_my_matrix > >, 3 > () (); + + std::cout << "double, std::map" << std::endl; + test_my_matrix > >, 3 > () (); + + std::cout << "std::complex, std::map" << std::endl; + test_my_matrix, ublas::row_major, std::map > > >, 3 > () (); + + std::cout << "std::complex, std::map" << std::endl; + test_my_matrix, ublas::row_major, std::map > > >, 3 > () (); +#endif +#endif + +#ifdef USE_COMPRESSED_MATRIX + std::cout << "float" << std::endl; + test_my_matrix, 3 > () (); + + std::cout << "double" << std::endl; + test_my_matrix, 3 > () (); + + std::cout << "std::complex" << std::endl; + test_my_matrix >, 3 > () (); + + std::cout << "std::complex" << std::endl; + test_my_matrix >, 3 > () (); +#endif +} + + diff --git a/test4/Jamfile b/test4/Jamfile new file mode 100644 index 00000000..32995735 --- /dev/null +++ b/test4/Jamfile @@ -0,0 +1,10 @@ +subproject libs/numeric/ublas/test4 ; + +SOURCES = test4 test41 test42 test43 ; + +exe test4 + : $(SOURCES).cpp + : $(BOOST_ROOT) + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" + ; + diff --git a/test4/test4.cpp b/test4/test4.cpp new file mode 100644 index 00000000..8d7921c5 --- /dev/null +++ b/test4/test4.cpp @@ -0,0 +1,36 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include + +#include "test4.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/test4/test4.dsp b/test4/test4.dsp new file mode 100644 index 00000000..3c9da3f4 --- /dev/null +++ b/test4/test4.dsp @@ -0,0 +1,219 @@ +# Microsoft Developer Studio Project File - Name="test4" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=test4 - 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 "test4.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 "test4.mak" CFG="test4 - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "test4 - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "test4 - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName ""$/boost/libs/numeric/ublas/test4", XDCAAAAA" +# PROP Scc_LocalPath "." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "test4 - 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)" == "test4 - 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 "test4 - Win32 Release" +# Name "test4 - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\test4.cpp +# End Source File +# Begin Source File + +SOURCE=.\test41.cpp +# End Source File +# Begin Source File + +SOURCE=.\test42.cpp +# End Source File +# Begin Source File + +SOURCE=.\test43.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=.\test4.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/test4/test4.hpp b/test4/test4.hpp new file mode 100644 index 00000000..7def5412 --- /dev/null +++ b/test4/test4.hpp @@ -0,0 +1,40 @@ +#ifndef TEST4_H +#define TEST4_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] = 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 = std::max (i - 1, 0); j < std::min (i + 2, size2); ++ j) + m (i, j) = i * size1 + j + 1.f; +} + +void test_vector (); + +void test_matrix_vector (); + +void test_matrix (); + +// Borland gets out of memory! +#ifndef __BORLANDC__ +#define USE_RANGE +// #define USE_SLICE +#endif + +// #define USE_BOUNDED_ARRAY +#define USE_UNBOUNDED_ARRAY +// #define USE_STD_VECTOR + +#endif + + diff --git a/test4/test41.cpp b/test4/test41.cpp new file mode 100644 index 00000000..ac647c94 --- /dev/null +++ b/test4/test41.cpp @@ -0,0 +1,208 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include + +#include "test4.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 = 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 + std::cout << "float, bounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "double, bounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_vector, ublas::bounded_array, 3> >, 3 > () (); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_vector, ublas::bounded_array, 3> >, 3 > () (); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + std::cout << "float, unbounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "double, unbounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_vector, ublas::unbounded_array > >, 3 > () (); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_vector, ublas::unbounded_array > >, 3 > () (); +#endif + +#ifdef USE_STD_VECTOR + std::cout << "float, std::vector" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "double, std::vector" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_vector, std::vector > >, 3 > () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_vector, std::vector > >, 3 > () (); +#endif +} + diff --git a/test4/test42.cpp b/test4/test42.cpp new file mode 100644 index 00000000..234a57e0 --- /dev/null +++ b/test4/test42.cpp @@ -0,0 +1,226 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include + +#include "test4.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) { + v2 = ublas::row (m1, i); + std::cout << "row (m, " << i << ") = " << v2 << std::endl; + v2 = ublas::column (m1, i); + std::cout << "column (m, " << i << ") = " << v2 << std::endl; + } + + // Outer product + initialize_vector (v1); + initialize_vector (v2); + v1 (0) = 0; + v1 (N - 1) = 0; + 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, 1, 1); + (*this) (v1, v2, m1); + + ublas::matrix_row mr1 (m1, 1), mr2 (m1, 1); + (*this) (mr1, mr2, m1); + + ublas::matrix_column mc1 (m1, 1), 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; + } + } + void operator () (int) const { + try { + V v1 (N), v2 (N); + M m1 (N, N, 1, 1); + ublas::banded_adaptor bam1 (m1, 1, 1); + (*this) (v1, v2, bam1); + + ublas::matrix_row > mr1 (bam1, 1), mr2 (bam1, 1); + (*this) (mr1, mr2, bam1); + + ublas::matrix_column > mc1 (bam1, 1), mc2 (bam1, 1); + (*this) (mc1, mc2, bam1); + +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL +#ifdef USE_RANGE_AND_SLICE + ublas::matrix_vector_range > mvr1 (bam1, ublas::range<> (0, N), ublas::range<> (0, N)), + mvr2 (bam1, ublas::range<> (0, N), ublas::range<> (0, N)); + (*this) (mvr1, mvr2, bam1); + + ublas::matrix_vector_slice > mvs1 (bam1, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)), + mvs2 (bam1, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)); + (*this) (mvs1, mvs2, bam1); +#endif +#else +#ifdef USE_RANGE_AND_SLICE + ublas::matrix_vector_range > mvr1 (bam1, ublas::range (0, N), ublas::range (0, N)), + mvr2 (bam1, ublas::range (0, N), ublas::range (0, N)); + (*this) (mvr1, mvr2, bam1); + + ublas::matrix_vector_slice > mvs1 (bam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + mvs2 (bam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + (*this) (mvs1, mvs2, bam1); +#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_BOUNDED_ARRAY + std::cout << "float, bounded_array" << std::endl; + test_my_matrix_vector >, + ublas::banded_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::banded_matrix >, 3> () (0); + + std::cout << "double, bounded_array" << std::endl; + test_my_matrix_vector >, + ublas::banded_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::banded_matrix >, 3> () (0); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::banded_matrix, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3> () (); + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::banded_matrix, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3> () (0); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::banded_matrix, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3> () (); + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::banded_matrix, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3> () (0); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + std::cout << "float, unbounded_array" << std::endl; + test_my_matrix_vector >, + ublas::banded_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::banded_matrix >, 3> () (0); + + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix_vector >, + ublas::banded_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::banded_matrix >, 3> () (0); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::banded_matrix, ublas::row_major, ublas::unbounded_array > >, 3> () (); + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::banded_matrix, ublas::row_major, ublas::unbounded_array > >, 3> () (0); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::banded_matrix, ublas::row_major, ublas::unbounded_array > >, 3> () (); + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::banded_matrix, ublas::row_major, ublas::unbounded_array > >, 3> () (0); +#endif + +#ifdef USE_STD_VECTOR + std::cout << "float, std::vector" << std::endl; + test_my_matrix_vector >, + ublas::banded_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::banded_matrix >, 3> () (0); + + std::cout << "double, std::vector" << std::endl; + test_my_matrix_vector >, + ublas::banded_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::banded_matrix >, 3> () (0); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix_vector, std::vector > >, + ublas::banded_matrix, ublas::row_major, std::vector > >, 3> () (); + test_my_matrix_vector, std::vector > >, + ublas::banded_matrix, ublas::row_major, std::vector > >, 3> () (0); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix_vector, std::vector > >, + ublas::banded_matrix, ublas::row_major, std::vector > >, 3> () (); + test_my_matrix_vector, std::vector > >, + ublas::banded_matrix, ublas::row_major, std::vector > >, 3> () (0); +#endif +} + diff --git a/test4/test43.cpp b/test4/test43.cpp new file mode 100644 index 00000000..1a4e3f5e --- /dev/null +++ b/test4/test43.cpp @@ -0,0 +1,255 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include + +#include "test4.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); + // Banded times banded isn't banded + std::cout << "prod (m1, m2) = " << ublas::prod (m1, m2) << 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, 1, 1), m2 (N, N, 1, 1), m3 (N, N, 1, 1); + (*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; + } + } + void operator () (int) const { + try { + M m1 (N, N, 1, 1), m2 (N, N, 1, 1), m3 (N, N, 1, 1); + ublas::banded_adaptor bam1 (m1, 1, 1), bam2 (m2, 1, 1), bam3 (m3, 1, 1); + (*this) (bam1, bam2, bam3); + +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL +#ifdef USE_RANGE + ublas::matrix_range > mr1 (bam1, ublas::range<> (0, N), ublas::range<> (0, N)), + mr2 (bam2, ublas::range<> (0, N), ublas::range<> (0, N)), + mr3 (bam3, ublas::range<> (0, N), ublas::range<> (0, N)); + (*this) (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice > ms1 (bam1, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)), + ms2 (bam2, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)), + ms3 (bam3, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)); + (*this) (ms1, ms2, ms3); +#endif +#else +#ifdef USE_RANGE + ublas::matrix_range > mr1 (bam1, ublas::range (0, N), ublas::range (0, N)), + mr2 (bam2, ublas::range (0, N), ublas::range (0, N)), + mr3 (bam3, ublas::range (0, N), ublas::range (0, N)); + (*this) (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice > ms1 (bam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms2 (bam2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms3 (bam3, 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_BOUNDED_ARRAY + std::cout << "float, bounded_array" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "double, bounded_array" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (); + test_my_matrix, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (0); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (); + test_my_matrix, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (0); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + std::cout << "float, unbounded_array" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::unbounded_array > >, 3 > () (); + test_my_matrix, ublas::row_major, ublas::unbounded_array > >, 3 > () (0); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix, ublas::row_major, ublas::unbounded_array > >, 3 > () (); + test_my_matrix, ublas::row_major, ublas::unbounded_array > >, 3 > () (0); +#endif + +#ifdef USE_STD_VECTOR + std::cout << "float, std::vector" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "double, std::vector" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix, ublas::row_major, std::vector > >, 3 > () (); + test_my_matrix, ublas::row_major, std::vector > >, 3 > () (0); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix, ublas::row_major, std::vector > >, 3 > () (); + test_my_matrix, ublas::row_major, std::vector > >, 3 > () (0); +#endif +} + + diff --git a/test5/Jamfile b/test5/Jamfile new file mode 100644 index 00000000..c523e6f3 --- /dev/null +++ b/test5/Jamfile @@ -0,0 +1,10 @@ +subproject libs/numeric/ublas/test5 ; + +SOURCES = test5 test51 test52 test53 ; + +exe test5 + : $(SOURCES).cpp + : $(BOOST_ROOT) + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" + ; + diff --git a/test5/test5.cpp b/test5/test5.cpp new file mode 100644 index 00000000..ffe2e8c6 --- /dev/null +++ b/test5/test5.cpp @@ -0,0 +1,36 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include + +#include "test5.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/test5/test5.dsp b/test5/test5.dsp new file mode 100644 index 00000000..730b744c --- /dev/null +++ b/test5/test5.dsp @@ -0,0 +1,219 @@ +# Microsoft Developer Studio Project File - Name="test5" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=test5 - 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 "test5.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 "test5.mak" CFG="test5 - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "test5 - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "test5 - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName ""$/boost/libs/numeric/ublas/test5", YDCAAAAA" +# PROP Scc_LocalPath "." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "test5 - 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)" == "test5 - 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 "test5 - Win32 Release" +# Name "test5 - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\test5.cpp +# End Source File +# Begin Source File + +SOURCE=.\test51.cpp +# End Source File +# Begin Source File + +SOURCE=.\test52.cpp +# End Source File +# Begin Source File + +SOURCE=.\test53.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=.\test5.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/test5/test5.hpp b/test5/test5.hpp new file mode 100644 index 00000000..e9686b4f --- /dev/null +++ b/test5/test5.hpp @@ -0,0 +1,65 @@ +#ifndef TEST5_H +#define TEST5_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] = i + 1.f; +} + +template +void initialize_matrix (M &m, ublas::lower_tag) { + int size1 = m.size1 (); +// int size2 = m.size2 (); + for (int i = 0; i < size1; ++ i) { + int j = 0; + for (; j <= i; ++ j) + m (i, j) = i * size1 + j + 1.f; +// for (; j < size2; ++ j) +// m (i, j) = 0.f; + } +} +template +void initialize_matrix (M &m, ublas::upper_tag) { + int size1 = m.size1 (); + int size2 = m.size2 (); + for (int i = 0; i < size1; ++ i) { + int j = 0; +// for (; j < i; ++ j) +// m (i, j) = 0.f; + for (; j < size2; ++ j) + m (i, j) = i * size1 + j + 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) = i * size1 + j + 1; +} + + +void test_vector (); + +void test_matrix_vector (); + +void test_matrix (); + +// Borland gets out of memory! +#ifndef __BORLANDC__ +#define USE_RANGE +// #define USE_SLICE +#endif + +// #define USE_BOUNDED_ARRAY +#define USE_UNBOUNDED_ARRAY +// #define USE_STD_VECTOR + +#endif + + diff --git a/test5/test51.cpp b/test5/test51.cpp new file mode 100644 index 00000000..8168bf8d --- /dev/null +++ b/test5/test51.cpp @@ -0,0 +1,208 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include + +#include "test5.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 = 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 + std::cout << "float, bounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "double, bounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_vector, ublas::bounded_array, 3> >, 3 > () (); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_vector, ublas::bounded_array, 3> >, 3 > () (); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + std::cout << "float, unbounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "double, unbounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_vector, ublas::unbounded_array > >, 3 > () (); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_vector, ublas::unbounded_array > >, 3 > () (); +#endif + +#ifdef USE_STD_VECTOR + std::cout << "float, std::vector" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "double, std::vector" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_vector, std::vector > >, 3 > () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_vector, std::vector > >, 3 > () (); +#endif +} + diff --git a/test5/test52.cpp b/test5/test52.cpp new file mode 100644 index 00000000..21a61280 --- /dev/null +++ b/test5/test52.cpp @@ -0,0 +1,226 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include + +#include "test5.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, ublas::lower_tag ()); + for (int i = 0; i < N; ++ i) { + v2 = ublas::row (m1, i); + std::cout << "row (m, " << i << ") = " << v2 << std::endl; + v2 = ublas::column (m1, i); + std::cout << "column (m, " << i << ") = " << v2 << std::endl; + } + + // Outer product + initialize_vector (v1); + initialize_vector (v2); + v1 (0) = 0; + v2 (N - 1) = 0; + m1 = ublas::outer_prod (v1, v2); + std::cout << "outer_prod (v1, v2) = " << m1 << std::endl; + + // Matrix vector product + initialize_matrix (m1, ublas::lower_tag ()); + 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, N - 1), mr2 (m1, N - 1); + (*this) (mr1, mr2, m1); + + ublas::matrix_column mc1 (m1, 0), mc2 (m1, 0); + (*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; + } + } + void operator () (int) const { + try { + V v1 (N), v2 (N); + M m1 (N, N); + ublas::triangular_adaptor tam1 (m1); + (*this) (v1, v2, tam1); + + ublas::matrix_row > mr1 (tam1, N - 1), mr2 (tam1, N - 1); + (*this) (mr1, mr2, tam1); + + ublas::matrix_column > mc1 (tam1, 0), mc2 (tam1, 0); + (*this) (mc1, mc2, tam1); + +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL +#ifdef USE_RANGE_AND_SLICE + ublas::matrix_vector_range > mvr1 (tam1, ublas::range<> (0, N), ublas::range<> (0, N)), + mvr2 (tam1, ublas::range<> (0, N), ublas::range<> (0, N)); + (*this) (mvr1, mvr2, tam1); + + ublas::matrix_vector_slice > mvs1 (tam1, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)), + mvs2 (tam1, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)); + (*this) (mvs1, mvs2, tam1); +#endif +#else +#ifdef USE_RANGE_AND_SLICE + ublas::matrix_vector_range > mvr1 (tam1, ublas::range (0, N), ublas::range (0, N)), + mvr2 (tam1, ublas::range (0, N), ublas::range (0, N)); + (*this) (mvr1, mvr2, tam1); + + ublas::matrix_vector_slice > mvs1 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + mvs2 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + (*this) (mvs1, mvs2, tam1); +#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_BOUNDED_ARRAY + std::cout << "float, bounded_array" << std::endl; + test_my_matrix_vector >, + ublas::triangular_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::triangular_matrix >, 3> () (0); + + std::cout << "double, bounded_array" << std::endl; + test_my_matrix_vector >, + ublas::triangular_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::triangular_matrix >, 3> () (0); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::triangular_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3> () (); + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::triangular_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3> () (0); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::triangular_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3> () (); + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::triangular_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3> () (0); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + std::cout << "float, unbounded_array" << std::endl; + test_my_matrix_vector >, + ublas::triangular_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::triangular_matrix >, 3> () (0); + + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix_vector >, + ublas::triangular_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::triangular_matrix >, 3> () (0); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::triangular_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3> () (); + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::triangular_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3> () (0); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::triangular_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3> () (); + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::triangular_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3> () (0); +#endif + +#ifdef USE_STD_VECTOR + std::cout << "float, std::vector" << std::endl; + test_my_matrix_vector >, + ublas::triangular_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::triangular_matrix >, 3> () (0); + + std::cout << "double, std::vector" << std::endl; + test_my_matrix_vector >, + ublas::triangular_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::triangular_matrix >, 3> () (0); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix_vector, std::vector > >, + ublas::triangular_matrix, ublas::lower, ublas::row_major, std::vector > >, 3> () (); + test_my_matrix_vector, std::vector > >, + ublas::triangular_matrix, ublas::lower, ublas::row_major, std::vector > >, 3> () (0); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix_vector, std::vector > >, + ublas::triangular_matrix, ublas::lower, ublas::row_major, std::vector > >, 3> () (); + test_my_matrix_vector, std::vector > >, + ublas::triangular_matrix, ublas::lower, ublas::row_major, std::vector > >, 3> () (0); +#endif +} + diff --git a/test5/test53.cpp b/test5/test53.cpp new file mode 100644 index 00000000..b4842892 --- /dev/null +++ b/test5/test53.cpp @@ -0,0 +1,255 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include + +#include "test5.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, ublas::lower_tag ()); + initialize_matrix (m2, ublas::lower_tag ()); + 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, ublas::lower_tag ()); + 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, ublas::lower_tag ()); + initialize_matrix (m2, ublas::lower_tag ()); + 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, ublas::lower_tag ()); + 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, ublas::lower_tag ()); + 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, ublas::lower_tag ()); + initialize_matrix (m2, ublas::lower_tag ()); +#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, ublas::lower_tag ()); + // Transpose of a triangular isn't triangular of the same kind + std::cout << "trans (m1) = " << ublas::trans (m1) << std::endl; + + // Hermitian + initialize_matrix (m1, ublas::lower_tag ()); + // Hermitian of a triangular isn't hermitian of the same kind + std::cout << "herm (m1) = " << ublas::herm (m1) << std::endl; + + // Matrix multiplication + initialize_matrix (m1, ublas::lower_tag ()); + initialize_matrix (m2, ublas::lower_tag ()); + 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; + } + } + void operator () (int) const { + try { + M m1 (N, N), m2 (N, N), m3 (N, N); + ublas::triangular_adaptor tam1 (m1), tam2 (m2), tam3 (m3); + (*this) (tam1, tam2, tam3); + +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL +#ifdef USE_RANGE + ublas::matrix_range > mr1 (tam1, ublas::range<> (0, N), ublas::range<> (0, N)), + mr2 (tam2, ublas::range<> (0, N), ublas::range<> (0, N)), + mr3 (tam3, ublas::range<> (0, N), ublas::range<> (0, N)); + (*this) (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice > ms1 (tam1, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)), + ms2 (tam2, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)), + ms3 (tam3, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)); + (*this) (ms1, ms2, ms3); +#endif +#else +#ifdef USE_RANGE + ublas::matrix_range > mr1 (tam1, ublas::range (0, N), ublas::range (0, N)), + mr2 (tam2, ublas::range (0, N), ublas::range (0, N)), + mr3 (tam3, ublas::range (0, N), ublas::range (0, N)); + (*this) (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice > ms1 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms2 (tam2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms3 (tam3, 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_BOUNDED_ARRAY + std::cout << "float, bounded_array" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "double, bounded_array" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (); + test_my_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (0); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (); + test_my_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (0); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + std::cout << "float, unbounded_array" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3 > () (); + test_my_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3 > () (0); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3 > () (); + test_my_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3 > () (0); +#endif + +#ifdef USE_STD_VECTOR + std::cout << "float, std::vector" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "double, std::vector" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix, ublas::lower, ublas::row_major, std::vector > >, 3 > () (); + test_my_matrix, ublas::lower, ublas::row_major, std::vector > >, 3 > () (0); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix, ublas::lower, ublas::row_major, std::vector > >, 3 > () (); + test_my_matrix, ublas::lower, ublas::row_major, std::vector > >, 3 > () (0); +#endif +} + + diff --git a/test6/Jamfile b/test6/Jamfile new file mode 100644 index 00000000..552de7c1 --- /dev/null +++ b/test6/Jamfile @@ -0,0 +1,10 @@ +subproject libs/numeric/ublas/test6 ; + +SOURCES = test6 test61 test62 test63 ; + +exe test6 + : $(SOURCES).cpp + : $(BOOST_ROOT) + <*>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092" + ; + diff --git a/test6/test6.cpp b/test6/test6.cpp new file mode 100644 index 00000000..8052a81a --- /dev/null +++ b/test6/test6.cpp @@ -0,0 +1,37 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include +#include + +#include "test6.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/test6/test6.dsp b/test6/test6.dsp new file mode 100644 index 00000000..543a8992 --- /dev/null +++ b/test6/test6.dsp @@ -0,0 +1,219 @@ +# Microsoft Developer Studio Project File - Name="test6" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=test6 - 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 "test6.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 "test6.mak" CFG="test6 - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "test6 - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "test6 - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName ""$/boost/libs/numeric/ublas/test6", ZDCAAAAA" +# PROP Scc_LocalPath "." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "test6 - 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)" == "test6 - 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 "test6 - Win32 Release" +# Name "test6 - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\test6.cpp +# End Source File +# Begin Source File + +SOURCE=.\test61.cpp +# End Source File +# Begin Source File + +SOURCE=.\test62.cpp +# End Source File +# Begin Source File + +SOURCE=.\test63.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=.\test6.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/test6/test6.hpp b/test6/test6.hpp new file mode 100644 index 00000000..a21b691c --- /dev/null +++ b/test6/test6.hpp @@ -0,0 +1,65 @@ +#ifndef TEST6_H +#define TEST6_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] = i + 1.f; +} + +template +void initialize_matrix (M &m, ublas::lower_tag) { + int size1 = m.size1 (); +// int size2 = m.size2 (); + for (int i = 0; i < size1; ++ i) { + int j = 0; + for (; j <= i; ++ j) + m (i, j) = i * size1 + j + 1.f; +// for (; j < size2; ++ j) +// m (i, j) = 0.f; + } +} +template +void initialize_matrix (M &m, ublas::upper_tag) { + int size1 = m.size1 (); + int size2 = m.size2 (); + for (int i = 0; i < size1; ++ i) { + int j = 0; +// for (; j < i; ++ j) +// m (i, j) = 0.f; + for (; j < size2; ++ j) + m (i, j) = i * size1 + j + 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) = i * size1 + j + 1.f; +} + + +void test_vector (); + +void test_matrix_vector (); + +void test_matrix (); + +// Borland gets out of memory! +#ifndef __BORLANDC__ +#define USE_RANGE +// #define USE_SLICE +#endif + +// #define USE_BOUNDED_ARRAY +#define USE_UNBOUNDED_ARRAY +// #define USE_STD_VECTOR + +#endif + + diff --git a/test6/test61.cpp b/test6/test61.cpp new file mode 100644 index 00000000..6fafccbe --- /dev/null +++ b/test6/test61.cpp @@ -0,0 +1,209 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include +#include + +#include "test6.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 = 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 + std::cout << "float, bounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "double, bounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_vector, ublas::bounded_array, 3> >, 3 > () (); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_vector, ublas::bounded_array, 3> >, 3 > () (); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + std::cout << "float, unbounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "double, unbounded_array" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_vector, ublas::unbounded_array > >, 3 > () (); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_vector, ublas::unbounded_array > >, 3 > () (); +#endif + +#ifdef USE_STD_VECTOR + std::cout << "float, std::vector" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "double, std::vector" << std::endl; + test_my_vector >, 3 > () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_vector, std::vector > >, 3 > () (); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_vector, std::vector > >, 3 > () (); +#endif +} + diff --git a/test6/test62.cpp b/test6/test62.cpp new file mode 100644 index 00000000..885a1d58 --- /dev/null +++ b/test6/test62.cpp @@ -0,0 +1,229 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include +#include + +#include "test6.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, ublas::lower_tag ()); + for (int i = 0; i < N; ++ i) { + v2 = ublas::row (m1, i); + std::cout << "row (m, " << i << ") = " << v2 << std::endl; + v2 = ublas::column (m1, i); + std::cout << "column (m, " << i << ") = " << v2 << std::endl; + } + + // Outer product + initialize_vector (v1); + initialize_vector (v2); + v1 (0) = 0; + v1 (N - 1) = 0; + v2 (0) = 0; + v2 (N - 1) = 0; + m1 = ublas::outer_prod (v1, v2); + std::cout << "outer_prod (v1, v2) = " << m1 << std::endl; + + // Matrix vector product + initialize_matrix (m1, ublas::lower_tag ()); + 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, N - 1), mr2 (m1, N - 1); + (*this) (mr1, mr2, m1); + + ublas::matrix_column mc1 (m1, 0), mc2 (m1, 0); + (*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; + } + } + void operator () (int) const { + try { + V v1 (N), v2 (N); + M m1 (N, N); + ublas::symmetric_adaptor tam1 (m1); + (*this) (v1, v2, tam1); + + ublas::matrix_row > mr1 (tam1, N - 1), mr2 (tam1, N - 1); + (*this) (mr1, mr2, tam1); + + ublas::matrix_column > mc1 (tam1, 0), mc2 (tam1, 0); + (*this) (mc1, mc2, tam1); + +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL +#ifdef USE_RANGE_AND_SLICE + ublas::matrix_vector_range > mvr1 (tam1, ublas::range<> (0, N), ublas::range<> (0, N)), + mvr2 (tam1, ublas::range<> (0, N), ublas::range<> (0, N)); + (*this) (mvr1, mvr2, tam1); + + ublas::matrix_vector_slice > mvs1 (tam1, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)), + mvs2 (tam1, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)); + (*this) (mvs1, mvs2, tam1); +#endif +#else +#ifdef USE_RANGE_AND_SLICE + ublas::matrix_vector_range > mvr1 (tam1, ublas::range (0, N), ublas::range (0, N)), + mvr2 (tam1, ublas::range (0, N), ublas::range (0, N)); + (*this) (mvr1, mvr2, tam1); + + ublas::matrix_vector_slice > mvs1 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + mvs2 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + (*this) (mvs1, mvs2, tam1); +#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_BOUNDED_ARRAY + std::cout << "float, bounded_array" << std::endl; + test_my_matrix_vector >, + ublas::symmetric_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::symmetric_matrix >, 3> () (0); + + std::cout << "double, bounded_array" << std::endl; + test_my_matrix_vector >, + ublas::symmetric_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::symmetric_matrix >, 3> () (0); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::symmetric_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3> () (); + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::symmetric_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3> () (0); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::symmetric_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3> () (); + test_my_matrix_vector, ublas::bounded_array, 3> >, + ublas::symmetric_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3> () (0); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + std::cout << "float, unbounded_array" << std::endl; + test_my_matrix_vector >, + ublas::symmetric_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::symmetric_matrix >, 3> () (0); + + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix_vector >, + ublas::symmetric_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::symmetric_matrix >, 3> () (0); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::symmetric_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3> () (); + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::symmetric_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3> () (0); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::symmetric_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3> () (); + test_my_matrix_vector, ublas::unbounded_array > >, + ublas::symmetric_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3> () (0); +#endif + +#ifdef USE_STD_VECTOR + std::cout << "float, std::vector" << std::endl; + test_my_matrix_vector >, + ublas::symmetric_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::symmetric_matrix >, 3> () (0); + + std::cout << "double, std::vector" << std::endl; + test_my_matrix_vector >, + ublas::symmetric_matrix >, 3> () (); + test_my_matrix_vector >, + ublas::symmetric_matrix >, 3> () (0); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix_vector, std::vector > >, + ublas::symmetric_matrix, ublas::lower, ublas::row_major, std::vector > >, 3> () (); + test_my_matrix_vector, std::vector > >, + ublas::symmetric_matrix, ublas::lower, ublas::row_major, std::vector > >, 3> () (0); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix_vector, std::vector > >, + ublas::symmetric_matrix, ublas::lower, ublas::row_major, std::vector > >, 3> () (); + test_my_matrix_vector, std::vector > >, + ublas::symmetric_matrix, ublas::lower, ublas::row_major, std::vector > >, 3> () (0); +#endif +} + diff --git a/test6/test63.cpp b/test6/test63.cpp new file mode 100644 index 00000000..0b5138ac --- /dev/null +++ b/test6/test63.cpp @@ -0,0 +1,256 @@ +#ifdef BOOST_MSVC + +#pragma warning (disable: 4355) +#pragma warning (disable: 4503) +#pragma warning (disable: 4786) + +#endif + +#include + +#include +#include +#include +#include +#include +#include + +#include "test6.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, ublas::lower_tag ()); + initialize_matrix (m2, ublas::lower_tag ()); + 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, ublas::lower_tag ()); + 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, ublas::lower_tag ()); + initialize_matrix (m2, ublas::lower_tag ()); + 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, ublas::lower_tag ()); + 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, ublas::lower_tag ()); + 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, ublas::lower_tag ()); + initialize_matrix (m2, ublas::lower_tag ()); +#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, ublas::lower_tag ()); + m2 = ublas::trans (m1); + std::cout << "trans (m1) = " << m2 << std::endl; + + // Hermitean + initialize_matrix (m1, ublas::lower_tag ()); + m2 = ublas::herm (m1); + std::cout << "herm (m1) = " << m2 << std::endl; + + // Matrix multiplication + initialize_matrix (m1, ublas::lower_tag ()); + initialize_matrix (m2, ublas::lower_tag ()); + 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; + } + } + void operator () (int) const { + try { + M m1 (N, N), m2 (N, N), m3 (N, N); + ublas::symmetric_adaptor sam1 (m1), sam2 (m2), sam3 (m3); + (*this) (sam1, sam2, sam3); + +#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL +#ifdef USE_RANGE + ublas::matrix_range > mr1 (sam1, ublas::range<> (0, N), ublas::range<> (0, N)), + mr2 (sam2, ublas::range<> (0, N), ublas::range<> (0, N)), + mr3 (sam3, ublas::range<> (0, N), ublas::range<> (0, N)); + (*this) (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice > ms1 (sam1, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)), + ms2 (sam2, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)), + ms3 (sam3, ublas::slice<> (0, 1, N), ublas::slice<> (0, 1, N)); + (*this) (ms1, ms2, ms3); +#endif +#else +#ifdef USE_RANGE + ublas::matrix_range > mr1 (sam1, ublas::range (0, N), ublas::range (0, N)), + mr2 (sam2, ublas::range (0, N), ublas::range (0, N)), + mr3 (sam3, ublas::range (0, N), ublas::range (0, N)); + (*this) (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice > ms1 (sam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms2 (sam2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms3 (sam3, 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_BOUNDED_ARRAY + std::cout << "float, bounded_array" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "double, bounded_array" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (); + test_my_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (0); + + std::cout << "std::complex, bounded_array" << std::endl; + test_my_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (); + test_my_matrix, ublas::lower, ublas::row_major, ublas::bounded_array, 3 * 3> >, 3 > () (0); +#endif + +#ifdef USE_UNBOUNDED_ARRAY + std::cout << "float, unbounded_array" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3 > () (); + test_my_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3 > () (0); + + std::cout << "std::complex, unbounded_array" << std::endl; + test_my_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3 > () (); + test_my_matrix, ublas::lower, ublas::row_major, ublas::unbounded_array > >, 3 > () (0); +#endif + +#ifdef USE_STD_VECTOR + std::cout << "float, std::vector" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "double, std::vector" << std::endl; + test_my_matrix >, 3 > () (); + test_my_matrix >, 3 > () (0); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix, ublas::lower, ublas::row_major, std::vector > >, 3 > () (); + test_my_matrix, ublas::lower, ublas::row_major, std::vector > >, 3 > () (0); + + std::cout << "std::complex, std::vector" << std::endl; + test_my_matrix, ublas::lower, ublas::row_major, std::vector > >, 3 > () (); + test_my_matrix, ublas::lower, ublas::row_major, std::vector > >, 3 > () (0); +#endif +} + + diff --git a/ublas.dsw b/ublas.dsw new file mode 100644 index 00000000..23b3185b --- /dev/null +++ b/ublas.dsw @@ -0,0 +1,181 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "bench1"=.\bench1\bench1.dsp - Package Owner=<4> + +Package=<5> +{{{ + begin source code control + "$/boost/libs/numeric/ublas/bench1", DDCAAAAA + .\bench1 + end source code control +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "bench2"=.\bench2\bench2.dsp - Package Owner=<4> + +Package=<5> +{{{ + begin source code control + "$/boost/libs/numeric/ublas/bench2", LDCAAAAA + .\bench2 + end source code control +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "bench3"=.\bench3\bench3.dsp - Package Owner=<4> + +Package=<5> +{{{ + begin source code control + "$/boost/libs/numeric/ublas/bench3", SDCAAAAA + .\bench3 + end source code control +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "concepts"=.\concepts.dsp - Package Owner=<4> + +Package=<5> +{{{ + begin source code control + "$/boost/libs/numeric/ublas", ECCAAAAA + . + end source code control +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "test1"=.\test1\test1.dsp - Package Owner=<4> + +Package=<5> +{{{ + begin source code control + "$/boost/libs/numeric/ublas/test1", TDCAAAAA + .\test1 + end source code control +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "test2"=.\test2\test2.dsp - Package Owner=<4> + +Package=<5> +{{{ + begin source code control + "$/boost/libs/numeric/ublas/test2", VDCAAAAA + .\test2 + end source code control +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "test3"=.\test3\test3.dsp - Package Owner=<4> + +Package=<5> +{{{ + begin source code control + "$/boost/libs/numeric/ublas/test3", WDCAAAAA + .\test3 + end source code control +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "test4"=.\test4\test4.dsp - Package Owner=<4> + +Package=<5> +{{{ + begin source code control + "$/boost/libs/numeric/ublas/test4", XDCAAAAA + .\test4 + end source code control +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "test5"=.\test5\test5.dsp - Package Owner=<4> + +Package=<5> +{{{ + begin source code control + "$/boost/libs/numeric/ublas/test5", YDCAAAAA + .\test5 + end source code control +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "test6"=.\test6\test6.dsp - Package Owner=<4> + +Package=<5> +{{{ + begin source code control + "$/boost/libs/numeric/ublas/test6", ZDCAAAAA + .\test6 + end source code control +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ + begin source code control + "$/boost/libs/numeric/ublas", ECCAAAAA + . + end source code control +}}} + +Package=<3> +{{{ +}}} + +############################################################################### +