mirror of
https://github.com/boostorg/ublas.git
synced 2026-02-19 02:42:16 +00:00
Merge.
[SVN r15321]
This commit is contained in:
20
Jamfile
Normal file
20
Jamfile
Normal file
@@ -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
|
||||
: <include>$(BOOST_ROOT)
|
||||
: <define>EXTERNAL
|
||||
<borland><*><cxxflags>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092"
|
||||
;
|
||||
|
||||
24
bench1/Jamfile
Normal file
24
bench1/Jamfile
Normal file
@@ -0,0 +1,24 @@
|
||||
subproject libs/numeric/ublas/bench1 ;
|
||||
|
||||
SOURCES = bench1 bench11 bench12 bench13 ;
|
||||
|
||||
exe bench1
|
||||
: $(SOURCES).cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
<borland><*><cxxflags>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092"
|
||||
<intel-linux><*><cxxflags>"-tpp7"
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
220
bench1/bench1.cpp
Normal file
220
bench1/bench1.cpp
Normal file
@@ -0,0 +1,220 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
|
||||
#include <boost/timer.hpp>
|
||||
|
||||
#include "bench1.hpp"
|
||||
|
||||
void header (std::string text) {
|
||||
std::cout << text << std::endl;
|
||||
std::cerr << text << std::endl;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
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<value_type> () (0, 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class T>
|
||||
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<value_type> () (0, 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
void peak<T>::operator () (int runs) {
|
||||
header ("peak");
|
||||
|
||||
header ("plus");
|
||||
peak_c_plus<T> () (runs);
|
||||
|
||||
header ("multiplies");
|
||||
peak_c_multiplies<T> () (runs);
|
||||
}
|
||||
|
||||
template struct peak<float>;
|
||||
template struct peak<double>;
|
||||
template struct peak<std::complex<float> >;
|
||||
template struct peak<std::complex<double> >;
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
// Standard new handler is not standard compliant.
|
||||
#include <new.h>
|
||||
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<float> () (100000000);
|
||||
|
||||
header ("double");
|
||||
peak<double> () (100000000);
|
||||
|
||||
#ifdef USE_COMPLEX
|
||||
header ("std:complex<float>");
|
||||
peak<std::complex<float> > () (100000000);
|
||||
|
||||
header ("std:complex<double>");
|
||||
peak<std::complex<double> > () (100000000);
|
||||
#endif
|
||||
|
||||
int scale = 1;
|
||||
if (argc > 1)
|
||||
scale = atoi (argv [1]);
|
||||
|
||||
header ("float, 3");
|
||||
|
||||
bench_1<float, 3> () (1000000 * scale);
|
||||
bench_2<float, 3> () (300000 * scale);
|
||||
bench_3<float, 3> () (100000 * scale);
|
||||
|
||||
header ("float, 10");
|
||||
|
||||
bench_1<float, 10> () (300000 * scale);
|
||||
bench_2<float, 10> () (30000 * scale);
|
||||
bench_3<float, 10> () (3000 * scale);
|
||||
|
||||
header ("float, 30");
|
||||
|
||||
bench_1<float, 30> () (100000 * scale);
|
||||
bench_2<float, 30> () (3000 * scale);
|
||||
bench_3<float, 30> () (100 * scale);
|
||||
|
||||
header ("float, 100");
|
||||
|
||||
bench_1<float, 100> () (30000 * scale);
|
||||
bench_2<float, 100> () (300 * scale);
|
||||
bench_3<float, 100> () (3 * scale);
|
||||
|
||||
header ("double, 3");
|
||||
|
||||
bench_1<double, 3> () (1000000 * scale);
|
||||
bench_2<double, 3> () (300000 * scale);
|
||||
bench_3<double, 3> () (100000 * scale);
|
||||
|
||||
header ("double, 10");
|
||||
|
||||
bench_1<double, 10> () (300000 * scale);
|
||||
bench_2<double, 10> () (30000 * scale);
|
||||
bench_3<double, 10> () (3000 * scale);
|
||||
|
||||
header ("double, 30");
|
||||
|
||||
bench_1<double, 30> () (100000 * scale);
|
||||
bench_2<double, 30> () (3000 * scale);
|
||||
bench_3<double, 30> () (100 * scale);
|
||||
|
||||
header ("double, 100");
|
||||
|
||||
bench_1<double, 100> () (30000 * scale);
|
||||
bench_2<double, 100> () (300 * scale);
|
||||
bench_3<double, 100> () (3 * scale);
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
header ("std::complex<float>, 3");
|
||||
|
||||
bench_1<std::complex<float>, 3> () (1000000 * scale);
|
||||
bench_2<std::complex<float>, 3> () (300000 * scale);
|
||||
bench_3<std::complex<float>, 3> () (100000 * scale);
|
||||
|
||||
header ("std::complex<float>, 10");
|
||||
|
||||
bench_1<std::complex<float>, 10> () (300000 * scale);
|
||||
bench_2<std::complex<float>, 10> () (30000 * scale);
|
||||
bench_3<std::complex<float>, 10> () (3000 * scale);
|
||||
|
||||
header ("std::complex<float>, 30");
|
||||
|
||||
bench_1<std::complex<float>, 30> () (100000 * scale);
|
||||
bench_2<std::complex<float>, 30> () (3000 * scale);
|
||||
bench_3<std::complex<float>, 30> () (100 * scale);
|
||||
|
||||
header ("std::complex<float>, 100");
|
||||
|
||||
bench_1<std::complex<float>, 100> () (30000 * scale);
|
||||
bench_2<std::complex<float>, 100> () (300 * scale);
|
||||
bench_3<std::complex<float>, 100> () (3 * scale);
|
||||
|
||||
header ("std::complex<double>, 3");
|
||||
|
||||
bench_1<std::complex<double>, 3> () (1000000 * scale);
|
||||
bench_2<std::complex<double>, 3> () (300000 * scale);
|
||||
bench_3<std::complex<double>, 3> () (100000 * scale);
|
||||
|
||||
header ("std::complex<double>, 10");
|
||||
|
||||
bench_1<std::complex<double>, 10> () (300000 * scale);
|
||||
bench_2<std::complex<double>, 10> () (30000 * scale);
|
||||
bench_3<std::complex<double>, 10> () (3000 * scale);
|
||||
|
||||
header ("std::complex<double>, 30");
|
||||
|
||||
bench_1<std::complex<double>, 30> () (100000 * scale);
|
||||
bench_2<std::complex<double>, 30> () (3000 * scale);
|
||||
bench_3<std::complex<double>, 30> () (100 * scale);
|
||||
|
||||
header ("std::complex<double>, 100");
|
||||
|
||||
bench_1<std::complex<double>, 100> () (30000 * scale);
|
||||
bench_2<std::complex<double>, 100> () (300 * scale);
|
||||
bench_3<std::complex<double>, 100> () (3 * scale);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
214
bench1/bench1.dsp
Normal file
214
bench1/bench1.dsp
Normal file
@@ -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
|
||||
156
bench1/bench1.hpp
Normal file
156
bench1/bench1.hpp
Normal file
@@ -0,0 +1,156 @@
|
||||
#ifndef BENCH1_H
|
||||
#define BENCH1_H
|
||||
|
||||
namespace ublas = boost::numeric::ublas;
|
||||
|
||||
void header (std::string text);
|
||||
|
||||
template<class T>
|
||||
struct footer {
|
||||
void operator () (int multiplies, int plus, int runs, double elapsed) {
|
||||
std::cout << "elapsed: " << elapsed << " s, "
|
||||
<< (multiplies * ublas::type_traits<T>::multiplies_complexity +
|
||||
plus * ublas::type_traits<T>::plus_complexity) * runs /
|
||||
(1024 * 1024 * elapsed) << " Mflops" << std::endl;
|
||||
std::cerr << "elapsed: " << elapsed << " s, "
|
||||
<< (multiplies * ublas::type_traits<T>::multiplies_complexity +
|
||||
plus * ublas::type_traits<T>::plus_complexity) * runs /
|
||||
(1024 * 1024 * elapsed) << " Mflops" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct c_vector_traits {
|
||||
typedef T type [N];
|
||||
};
|
||||
template<class T, int N, int M>
|
||||
struct c_matrix_traits {
|
||||
typedef T type [N] [M];
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct initialize_c_vector {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (typename c_vector_traits<T, N>::type v) {
|
||||
#else
|
||||
void operator () (typename c_vector_traits<T, N>::type &v) {
|
||||
#endif
|
||||
for (int i = 0; i < N; ++ i)
|
||||
v [i] = rand () * 1.f;
|
||||
// v [i] = 0.f;
|
||||
}
|
||||
};
|
||||
template<class V>
|
||||
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<class T, int N, int M>
|
||||
struct initialize_c_matrix {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (typename c_matrix_traits<T, N, M>::type m) {
|
||||
#else
|
||||
void operator () (typename c_matrix_traits<T, N, M>::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<class M>
|
||||
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<class T>
|
||||
BOOST_UBLAS_INLINE
|
||||
void sink_scalar (const T &s) {
|
||||
static T g_s = s;
|
||||
}
|
||||
|
||||
template<class T, int N>
|
||||
struct sink_c_vector {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (const typename c_vector_traits<T, N>::type v) {
|
||||
#else
|
||||
void operator () (const typename c_vector_traits<T, N>::type &v) {
|
||||
#endif
|
||||
static typename c_vector_traits<T, N>::type g_v;
|
||||
for (int i = 0; i < N; ++ i)
|
||||
g_v [i] = v [i];
|
||||
}
|
||||
};
|
||||
template<class V>
|
||||
BOOST_UBLAS_INLINE
|
||||
void sink_vector (const V &v) {
|
||||
static V g_v (v);
|
||||
}
|
||||
|
||||
template<class T, int N, int M>
|
||||
struct sink_c_matrix {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (const typename c_matrix_traits<T, N, M>::type m) {
|
||||
#else
|
||||
void operator () (const typename c_matrix_traits<T, N, M>::type &m) {
|
||||
#endif
|
||||
static typename c_matrix_traits<T, N, M>::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<class M>
|
||||
BOOST_UBLAS_INLINE
|
||||
void sink_matrix (const M &m) {
|
||||
static M g_m (m);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
struct peak {
|
||||
void operator () (int runs);
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_1 {
|
||||
void operator () (int runs);
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_2 {
|
||||
void operator () (int runs);
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
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
|
||||
|
||||
|
||||
307
bench1/bench11.cpp
Normal file
307
bench1/bench11.cpp
Normal file
@@ -0,0 +1,307 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
|
||||
#include <boost/timer.hpp>
|
||||
|
||||
#include "bench1.hpp"
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_inner_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_vector_traits<T, N>::type v1, v2;
|
||||
initialize_c_vector<T, N> () (v1);
|
||||
initialize_c_vector<T, N> () (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<value_type> () (N, N - 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
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<value_type> () (N, N - 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
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<value_type> () (N, N - 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_vector_add {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_vector_traits<T, N>::type v1, v2, v3;
|
||||
initialize_c_vector<T, N> () (v1);
|
||||
initialize_c_vector<T, N> () (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<T, N> () (v3);
|
||||
}
|
||||
footer<value_type> () (0, 2 * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
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<value_type> () (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<value_type> () (0, 2 * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
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<value_type> () (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<class T, int N>
|
||||
void bench_1<T, N>::operator () (int runs) {
|
||||
header ("bench_1");
|
||||
|
||||
header ("inner_prod");
|
||||
|
||||
header ("C array");
|
||||
bench_c_inner_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_vector");
|
||||
bench_my_inner_prod<ublas::c_vector<T, N>, N> () (runs);
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("vector<bounded_array>");
|
||||
bench_my_inner_prod<ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs);
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("vector<unbounded_array>");
|
||||
bench_my_inner_prod<ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("vector<std::valarray>");
|
||||
bench_my_inner_prod<ublas::vector<T, std::valarray<T> >, N> () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("vector<std::vector>");
|
||||
bench_my_inner_prod<ublas::vector<T, std::vector<T> >, N> () (runs);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_inner_prod<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
|
||||
header ("vector + vector");
|
||||
|
||||
header ("C array");
|
||||
bench_c_vector_add<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_vector safe");
|
||||
bench_my_vector_add<ublas::c_vector<T, N>, N> () (runs, safe_tag ());
|
||||
|
||||
header ("c_vector fast");
|
||||
bench_my_vector_add<ublas::c_vector<T, N>, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("vector<bounded_array> safe");
|
||||
bench_my_vector_add<ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("vector<bounded_array> fast");
|
||||
bench_my_vector_add<ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("vector<unbounded_array> safe");
|
||||
bench_my_vector_add<ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("vector<unbounded_array> fast");
|
||||
bench_my_vector_add<ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("vector<std::valarray> safe");
|
||||
bench_my_vector_add<ublas::vector<T, std::valarray<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("vector<std::valarray> fast");
|
||||
bench_my_vector_add<ublas::vector<T, std::valarray<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("vector<std::vector> safe");
|
||||
bench_my_vector_add<ublas::vector<T, std::vector<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("vector<std::vector> fast");
|
||||
bench_my_vector_add<ublas::vector<T, std::vector<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_vector_add<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
}
|
||||
|
||||
template struct bench_1<float, 3>;
|
||||
template struct bench_1<float, 10>;
|
||||
template struct bench_1<float, 30>;
|
||||
template struct bench_1<float, 100>;
|
||||
|
||||
template struct bench_1<double, 3>;
|
||||
template struct bench_1<double, 10>;
|
||||
template struct bench_1<double, 30>;
|
||||
template struct bench_1<double, 100>;
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
|
||||
template struct bench_1<std::complex<float>, 3>;
|
||||
template struct bench_1<std::complex<float>, 10>;
|
||||
template struct bench_1<std::complex<float>, 30>;
|
||||
template struct bench_1<std::complex<float>, 100>;
|
||||
|
||||
template struct bench_1<std::complex<double>, 3>;
|
||||
template struct bench_1<std::complex<double>, 10>;
|
||||
template struct bench_1<std::complex<double>, 30>;
|
||||
template struct bench_1<std::complex<double>, 100>;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
524
bench1/bench12.cpp
Normal file
524
bench1/bench12.cpp
Normal file
@@ -0,0 +1,524 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
|
||||
#include <boost/timer.hpp>
|
||||
|
||||
#include "bench1.hpp"
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_outer_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m;
|
||||
static typename c_vector_traits<T, N>::type v1, v2;
|
||||
initialize_c_vector<T, N> () (v1);
|
||||
initialize_c_vector<T, N> () (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<T, N, N> () (m);
|
||||
}
|
||||
footer<value_type> () (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<class M, class V, int N>
|
||||
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<value_type> () (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<value_type> () (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<class M, class V, int N>
|
||||
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<value_type> () (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<class T, int N>
|
||||
struct bench_c_matrix_vector_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m;
|
||||
static typename c_vector_traits<T, N>::type v1, v2;
|
||||
initialize_c_matrix<T, N, N> () (m);
|
||||
initialize_c_vector<T, N> () (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<T, N> () (v2);
|
||||
}
|
||||
footer<value_type> () (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<class M, class V, int N>
|
||||
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<value_type> () (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<value_type> () (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<class M, class V, int N>
|
||||
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<value_type> row (m [std::slice (N * j, N, 1)]);
|
||||
v2 [j] = (row * v1).sum ();
|
||||
}
|
||||
// sink_vector (v2);
|
||||
}
|
||||
footer<value_type> () (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<class T, int N>
|
||||
struct bench_c_matrix_add {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m1, m2, m3;
|
||||
initialize_c_matrix<T, N, N> () (m1);
|
||||
initialize_c_matrix<T, N, N> () (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<T, N, N> () (m3);
|
||||
}
|
||||
footer<value_type> () (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<class M, int N>
|
||||
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<value_type> () (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<value_type> () (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<class M, int N>
|
||||
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<value_type> () (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<class T, int N>
|
||||
void bench_2<T, N>::operator () (int runs) {
|
||||
header ("bench_2");
|
||||
|
||||
header ("outer_prod");
|
||||
|
||||
header ("C array");
|
||||
bench_c_outer_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_matrix, c_vector safe");
|
||||
bench_my_outer_prod<ublas::c_matrix<T, N, N>,
|
||||
ublas::c_vector<T, N>, N> () (runs, safe_tag ());
|
||||
|
||||
header ("c_matrix, c_vector fast");
|
||||
bench_my_outer_prod<ublas::c_matrix<T, N, N>,
|
||||
ublas::c_vector<T, N>, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("matrix<bounded_array>, vector<bounded_array> safe");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >,
|
||||
ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<bounded_array>, vector<bounded_array> fast");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >,
|
||||
ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("matrix<unbounded_array>, vector<unbounded_array> safe");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >,
|
||||
ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<unbounded_array>, vector<unbounded_array> fast");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >,
|
||||
ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("matrix<std::valarray>, vector<std::valarray> safe");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >,
|
||||
ublas::vector<T, std::valarray<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::valarray>, vector<std::valarray> fast");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >,
|
||||
ublas::vector<T, std::valarray<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("matrix<std::vector>, vector<std::vector> safe");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >,
|
||||
ublas::vector<T, std::vector<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::vector>, vector<std::vector> fast");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >,
|
||||
ublas::vector<T, std::vector<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_outer_prod<std::valarray<T>, std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
|
||||
header ("prod (matrix, vector)");
|
||||
|
||||
header ("C array");
|
||||
bench_c_matrix_vector_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_matrix, c_vector safe");
|
||||
bench_my_matrix_vector_prod<ublas::c_matrix<T, N, N>,
|
||||
ublas::c_vector<T, N>, N> () (runs, safe_tag ());
|
||||
|
||||
header ("c_matrix, c_vector fast");
|
||||
bench_my_matrix_vector_prod<ublas::c_matrix<T, N, N>,
|
||||
ublas::c_vector<T, N>, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("matrix<bounded_array>, vector<bounded_array> safe");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >,
|
||||
ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<bounded_array>, vector<bounded_array> fast");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >,
|
||||
ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("matrix<unbounded_array>, vector<unbounded_array> safe");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >,
|
||||
ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<unbounded_array>, vector<unbounded_array> fast");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >,
|
||||
ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("matrix<std::valarray>, vector<std::valarray> safe");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >,
|
||||
ublas::vector<T, std::valarray<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::valarray>, vector<std::valarray> fast");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >,
|
||||
ublas::vector<T, std::valarray<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("matrix<std::vector>, vector<std::vector> safe");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >,
|
||||
ublas::vector<T, std::vector<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::vector>, vector<std::vector> fast");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >,
|
||||
ublas::vector<T, std::vector<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_matrix_vector_prod<std::valarray<T>, std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
|
||||
header ("matrix + matrix");
|
||||
|
||||
header ("C array");
|
||||
bench_c_matrix_add<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_matrix safe");
|
||||
bench_my_matrix_add<ublas::c_matrix<T, N, N>, N> () (runs, safe_tag ());
|
||||
|
||||
header ("c_matrix fast");
|
||||
bench_my_matrix_add<ublas::c_matrix<T, N, N>, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("matrix<bounded_array> safe");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<bounded_array> fast");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("matrix<unbounded_array> safe");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<unbounded_array> fast");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("matrix<std::valarray> safe");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, std::valarray<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::valarray> fast");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, std::valarray<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("matrix<std::vector> safe");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, std::vector<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::vector> fast");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, std::vector<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_matrix_add<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
}
|
||||
|
||||
template struct bench_2<float, 3>;
|
||||
template struct bench_2<float, 10>;
|
||||
template struct bench_2<float, 30>;
|
||||
template struct bench_2<float, 100>;
|
||||
|
||||
template struct bench_2<double, 3>;
|
||||
template struct bench_2<double, 10>;
|
||||
template struct bench_2<double, 30>;
|
||||
template struct bench_2<double, 100>;
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
|
||||
template struct bench_2<std::complex<float>, 3>;
|
||||
template struct bench_2<std::complex<float>, 10>;
|
||||
template struct bench_2<std::complex<float>, 30>;
|
||||
template struct bench_2<std::complex<float>, 100>;
|
||||
|
||||
template struct bench_2<std::complex<double>, 3>;
|
||||
template struct bench_2<std::complex<double>, 10>;
|
||||
template struct bench_2<std::complex<double>, 30>;
|
||||
template struct bench_2<std::complex<double>, 100>;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
206
bench1/bench13.cpp
Normal file
206
bench1/bench13.cpp
Normal file
@@ -0,0 +1,206 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
|
||||
#include <boost/timer.hpp>
|
||||
|
||||
#include "bench1.hpp"
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_matrix_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m1, m2, m3;
|
||||
initialize_c_matrix<T, N, N> () (m1);
|
||||
initialize_c_matrix<T, N, N> () (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<T, N, N> () (m3);
|
||||
}
|
||||
footer<value_type> () (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<class M, int N>
|
||||
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<value_type> () (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<value_type> () (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<class M, int N>
|
||||
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<value_type> row (m1 [std::slice (N * j, N, 1)]);
|
||||
for (int k = 0; k < N; ++ k) {
|
||||
std::valarray<value_type> column (m2 [std::slice (k, N, N)]);
|
||||
m3 [N * j + k] = (row * column).sum ();
|
||||
}
|
||||
}
|
||||
// sink_vector (m3);
|
||||
}
|
||||
footer<value_type> () (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<class T, int N>
|
||||
void bench_3<T, N>::operator () (int runs) {
|
||||
header ("bench_3");
|
||||
|
||||
header ("prod (matrix, matrix)");
|
||||
|
||||
header ("C array");
|
||||
bench_c_matrix_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_matrix safe");
|
||||
bench_my_matrix_prod<ublas::c_matrix<T, N, N>, N> () (runs, safe_tag ());
|
||||
|
||||
header ("c_matrix fast");
|
||||
bench_my_matrix_prod<ublas::c_matrix<T, N, N>, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("matrix<bounded_array> safe");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<bounded_array> fast");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("matrix<unbounded_array> safe");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<unbounded_array> fast");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("matrix<std::valarray> safe");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::valarray> fast");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("matrix<std::vector> safe");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::vector> fast");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_matrix_prod<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
}
|
||||
|
||||
template struct bench_3<float, 3>;
|
||||
template struct bench_3<float, 10>;
|
||||
template struct bench_3<float, 30>;
|
||||
template struct bench_3<float, 100>;
|
||||
|
||||
template struct bench_3<double, 3>;
|
||||
template struct bench_3<double, 10>;
|
||||
template struct bench_3<double, 30>;
|
||||
template struct bench_3<double, 100>;
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
|
||||
template struct bench_3<std::complex<float>, 3>;
|
||||
template struct bench_3<std::complex<float>, 10>;
|
||||
template struct bench_3<std::complex<float>, 30>;
|
||||
template struct bench_3<std::complex<float>, 100>;
|
||||
|
||||
template struct bench_3<std::complex<double>, 3>;
|
||||
template struct bench_3<std::complex<double>, 10>;
|
||||
template struct bench_3<std::complex<double>, 30>;
|
||||
template struct bench_3<std::complex<double>, 100>;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
10
bench2/Jamfile
Normal file
10
bench2/Jamfile
Normal file
@@ -0,0 +1,10 @@
|
||||
subproject libs/numeric/ublas/bench2 ;
|
||||
|
||||
SOURCES = bench2 bench21 bench22 bench23 ;
|
||||
|
||||
exe bench2
|
||||
: $(SOURCES).cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
<borland><*><cxxflags>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092"
|
||||
;
|
||||
|
||||
219
bench2/bench2.cpp
Normal file
219
bench2/bench2.cpp
Normal file
@@ -0,0 +1,219 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/vector_sparse.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/matrix_sparse.hpp>
|
||||
|
||||
#include <boost/timer.hpp>
|
||||
|
||||
#include "bench2.hpp"
|
||||
|
||||
void header (std::string text) {
|
||||
std::cout << text << std::endl;
|
||||
std::cerr << text << std::endl;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
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<value_type> () (0, 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class T>
|
||||
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<value_type> () (0, 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
void peak<T>::operator () (int runs) {
|
||||
header ("peak");
|
||||
|
||||
header ("plus");
|
||||
peak_c_plus<T> () (runs);
|
||||
|
||||
header ("multiplies");
|
||||
peak_c_multiplies<T> () (runs);
|
||||
}
|
||||
|
||||
template struct peak<float>;
|
||||
template struct peak<double>;
|
||||
template struct peak<std::complex<float> >;
|
||||
template struct peak<std::complex<double> >;
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
// Standard new handler is not standard compliant.
|
||||
#include <new.h>
|
||||
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<float> () (100000000);
|
||||
|
||||
header ("double");
|
||||
peak<double> () (100000000);
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
header ("std:complex<float>");
|
||||
peak<std::complex<float> > () (100000000);
|
||||
|
||||
header ("std:complex<double>");
|
||||
peak<std::complex<double> > () (100000000);
|
||||
#endif
|
||||
|
||||
int scale = 1;
|
||||
if (argc > 1)
|
||||
scale = atoi (argv [1]);
|
||||
|
||||
header ("float, 3");
|
||||
|
||||
bench_1<float, 3> () (1000000 * scale);
|
||||
bench_2<float, 3> () (300000 * scale);
|
||||
bench_3<float, 3> () (100000 * scale);
|
||||
|
||||
header ("float, 10");
|
||||
|
||||
bench_1<float, 10> () (300000 * scale);
|
||||
bench_2<float, 10> () (30000 * scale);
|
||||
bench_3<float, 10> () (3000 * scale);
|
||||
|
||||
header ("float, 30");
|
||||
|
||||
bench_1<float, 30> () (100000 * scale);
|
||||
bench_2<float, 30> () (3000 * scale);
|
||||
bench_3<float, 30> () (100 * scale);
|
||||
|
||||
header ("float, 100");
|
||||
|
||||
bench_1<float, 100> () (30000 * scale);
|
||||
bench_2<float, 100> () (300 * scale);
|
||||
bench_3<float, 100> () (3 * scale);
|
||||
|
||||
header ("double, 3");
|
||||
|
||||
bench_1<double, 3> () (1000000 * scale);
|
||||
bench_2<double, 3> () (300000 * scale);
|
||||
bench_3<double, 3> () (100000 * scale);
|
||||
|
||||
header ("double, 10");
|
||||
|
||||
bench_1<double, 10> () (300000 * scale);
|
||||
bench_2<double, 10> () (30000 * scale);
|
||||
bench_3<double, 10> () (3000 * scale);
|
||||
|
||||
header ("double, 30");
|
||||
|
||||
bench_1<double, 30> () (100000 * scale);
|
||||
bench_2<double, 30> () (3000 * scale);
|
||||
bench_3<double, 30> () (100 * scale);
|
||||
|
||||
header ("double, 100");
|
||||
|
||||
bench_1<double, 100> () (30000 * scale);
|
||||
bench_2<double, 100> () (300 * scale);
|
||||
bench_3<double, 100> () (3 * scale);
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
header ("std::complex<float>, 3");
|
||||
|
||||
bench_1<std::complex<float>, 3> () (1000000 * scale);
|
||||
bench_2<std::complex<float>, 3> () (300000 * scale);
|
||||
bench_3<std::complex<float>, 3> () (100000 * scale);
|
||||
|
||||
header ("std::complex<float>, 10");
|
||||
|
||||
bench_1<std::complex<float>, 10> () (300000 * scale);
|
||||
bench_2<std::complex<float>, 10> () (30000 * scale);
|
||||
bench_3<std::complex<float>, 10> () (3000 * scale);
|
||||
|
||||
header ("std::complex<float>, 30");
|
||||
|
||||
bench_1<std::complex<float>, 30> () (100000 * scale);
|
||||
bench_2<std::complex<float>, 30> () (3000 * scale);
|
||||
bench_3<std::complex<float>, 30> () (100 * scale);
|
||||
|
||||
header ("std::complex<float>, 100");
|
||||
|
||||
bench_1<std::complex<float>, 100> () (30000 * scale);
|
||||
bench_2<std::complex<float>, 100> () (300 * scale);
|
||||
bench_3<std::complex<float>, 100> () (3 * scale);
|
||||
|
||||
header ("std::complex<double>, 3");
|
||||
|
||||
bench_1<std::complex<double>, 3> () (1000000 * scale);
|
||||
bench_2<std::complex<double>, 3> () (300000 * scale);
|
||||
bench_3<std::complex<double>, 3> () (100000 * scale);
|
||||
|
||||
header ("std::complex<double>, 10");
|
||||
|
||||
bench_1<std::complex<double>, 10> () (300000 * scale);
|
||||
bench_2<std::complex<double>, 10> () (30000 * scale);
|
||||
bench_3<std::complex<double>, 10> () (3000 * scale);
|
||||
|
||||
header ("std::complex<double>, 30");
|
||||
|
||||
bench_1<std::complex<double>, 30> () (100000 * scale);
|
||||
bench_2<std::complex<double>, 30> () (3000 * scale);
|
||||
bench_3<std::complex<double>, 30> () (100 * scale);
|
||||
|
||||
header ("std::complex<double>, 100");
|
||||
|
||||
bench_1<std::complex<double>, 100> () (30000 * scale);
|
||||
bench_2<std::complex<double>, 100> () (300 * scale);
|
||||
bench_3<std::complex<double>, 100> () (3 * scale);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
214
bench2/bench2.dsp
Normal file
214
bench2/bench2.dsp
Normal file
@@ -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
|
||||
170
bench2/bench2.hpp
Normal file
170
bench2/bench2.hpp
Normal file
@@ -0,0 +1,170 @@
|
||||
#ifndef BENCH2_H
|
||||
#define BENCH2_H
|
||||
|
||||
namespace ublas = boost::numeric::ublas;
|
||||
|
||||
void header (std::string text);
|
||||
|
||||
template<class T>
|
||||
struct footer {
|
||||
void operator () (int multiplies, int plus, int runs, double elapsed) {
|
||||
std::cout << "elapsed: " << elapsed << " s, "
|
||||
<< (multiplies * ublas::type_traits<T>::multiplies_complexity +
|
||||
plus * ublas::type_traits<T>::plus_complexity) * runs /
|
||||
(1024 * 1024 * elapsed) << " Mflops" << std::endl;
|
||||
std::cerr << "elapsed: " << elapsed << " s, "
|
||||
<< (multiplies * ublas::type_traits<T>::multiplies_complexity +
|
||||
plus * ublas::type_traits<T>::plus_complexity) * runs /
|
||||
(1024 * 1024 * elapsed) << " Mflops" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct c_vector_traits {
|
||||
typedef T type [N];
|
||||
};
|
||||
template<class T, int N, int M>
|
||||
struct c_matrix_traits {
|
||||
typedef T type [N] [M];
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct initialize_c_vector {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (typename c_vector_traits<T, N>::type v) {
|
||||
#else
|
||||
void operator () (typename c_vector_traits<T, N>::type &v) {
|
||||
#endif
|
||||
for (int i = 0; i < N; ++ i)
|
||||
v [i] = rand () * 1.f;
|
||||
// v [i] = 0.f;
|
||||
}
|
||||
};
|
||||
template<class V>
|
||||
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<class T, int N, int M>
|
||||
struct initialize_c_matrix {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (typename c_matrix_traits<T, N, M>::type m) {
|
||||
#else
|
||||
void operator () (typename c_matrix_traits<T, N, M>::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<class M>
|
||||
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<class M>
|
||||
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<class M>
|
||||
BOOST_UBLAS_INLINE
|
||||
void initialize_matrix (M &m) {
|
||||
typedef BOOST_UBLAS_TYPENAME M::orientation_category orientation_category;
|
||||
initialize_matrix (m, orientation_category ());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BOOST_UBLAS_INLINE
|
||||
void sink_scalar (const T &s) {
|
||||
static T g_s = s;
|
||||
}
|
||||
|
||||
template<class T, int N>
|
||||
struct sink_c_vector {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (const typename c_vector_traits<T, N>::type v) {
|
||||
#else
|
||||
void operator () (const typename c_vector_traits<T, N>::type &v) {
|
||||
#endif
|
||||
static typename c_vector_traits<T, N>::type g_v;
|
||||
for (int i = 0; i < N; ++ i)
|
||||
g_v [i] = v [i];
|
||||
}
|
||||
};
|
||||
template<class V>
|
||||
BOOST_UBLAS_INLINE
|
||||
void sink_vector (const V &v) {
|
||||
static V g_v (v);
|
||||
}
|
||||
|
||||
template<class T, int N, int M>
|
||||
struct sink_c_matrix {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (const typename c_matrix_traits<T, N, M>::type m) {
|
||||
#else
|
||||
void operator () (const typename c_matrix_traits<T, N, M>::type &m) {
|
||||
#endif
|
||||
static typename c_matrix_traits<T, N, M>::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<class M>
|
||||
BOOST_UBLAS_INLINE
|
||||
void sink_matrix (const M &m) {
|
||||
static M g_m (m);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
struct peak {
|
||||
void operator () (int runs);
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_1 {
|
||||
void operator () (int runs);
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_2 {
|
||||
void operator () (int runs);
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
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
|
||||
|
||||
|
||||
270
bench2/bench21.cpp
Normal file
270
bench2/bench21.cpp
Normal file
@@ -0,0 +1,270 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/vector_sparse.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/matrix_sparse.hpp>
|
||||
|
||||
#include <boost/timer.hpp>
|
||||
|
||||
#include "bench2.hpp"
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_inner_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_vector_traits<T, N>::type v1, v2;
|
||||
initialize_c_vector<T, N> () (v1);
|
||||
initialize_c_vector<T, N> () (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<value_type> () (N, N - 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
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<value_type> () (N, N - 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
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<value_type> () (N, N - 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_vector_add {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_vector_traits<T, N>::type v1, v2, v3;
|
||||
initialize_c_vector<T, N> () (v1);
|
||||
initialize_c_vector<T, N> () (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<T, N> () (v3);
|
||||
}
|
||||
footer<value_type> () (0, 2 * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
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<value_type> () (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<value_type> () (0, 2 * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
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<value_type> () (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<class T, int N>
|
||||
void bench_1<T, N>::operator () (int runs) {
|
||||
header ("bench_1");
|
||||
|
||||
header ("inner_prod");
|
||||
|
||||
header ("C array");
|
||||
bench_c_inner_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_MAP_ARRAY
|
||||
header ("sparse_vector<map_array>");
|
||||
bench_my_inner_prod<ublas::sparse_vector<T, ublas::map_array<std::size_t, T> >, N> () (runs);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_MAP
|
||||
header ("sparse_vector<std::map>");
|
||||
bench_my_inner_prod<ublas::sparse_vector<T, std::map<std::size_t, T> >, N> () (runs);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_inner_prod<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
|
||||
header ("sparse_vector + sparse_vector");
|
||||
|
||||
header ("C array");
|
||||
bench_c_vector_add<T, N> () (runs);
|
||||
|
||||
#ifdef USE_MAP_ARRAY
|
||||
header ("sparse_vector<map_array> safe");
|
||||
bench_my_vector_add<ublas::sparse_vector<T, ublas::map_array<std::size_t, T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("sparse_vector<map_array> fast");
|
||||
bench_my_vector_add<ublas::sparse_vector<T, ublas::map_array<std::size_t, T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_MAP
|
||||
header ("sparse_vector<std::map> safe");
|
||||
bench_my_vector_add<ublas::sparse_vector<T, std::map<std::size_t, T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("sparse_vector<std::map> fast");
|
||||
bench_my_vector_add<ublas::sparse_vector<T, std::map<std::size_t, T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_vector_add<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
}
|
||||
|
||||
template struct bench_1<float, 3>;
|
||||
template struct bench_1<float, 10>;
|
||||
template struct bench_1<float, 30>;
|
||||
template struct bench_1<float, 100>;
|
||||
|
||||
template struct bench_1<double, 3>;
|
||||
template struct bench_1<double, 10>;
|
||||
template struct bench_1<double, 30>;
|
||||
template struct bench_1<double, 100>;
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
|
||||
template struct bench_1<std::complex<float>, 3>;
|
||||
template struct bench_1<std::complex<float>, 10>;
|
||||
template struct bench_1<std::complex<float>, 30>;
|
||||
template struct bench_1<std::complex<float>, 100>;
|
||||
|
||||
template struct bench_1<std::complex<double>, 3>;
|
||||
template struct bench_1<std::complex<double>, 10>;
|
||||
template struct bench_1<std::complex<double>, 30>;
|
||||
template struct bench_1<std::complex<double>, 100>;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
442
bench2/bench22.cpp
Normal file
442
bench2/bench22.cpp
Normal file
@@ -0,0 +1,442 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/vector_sparse.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/matrix_sparse.hpp>
|
||||
|
||||
#include <boost/timer.hpp>
|
||||
|
||||
#include "bench2.hpp"
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_outer_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m;
|
||||
static typename c_vector_traits<T, N>::type v1, v2;
|
||||
initialize_c_vector<T, N> () (v1);
|
||||
initialize_c_vector<T, N> () (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<T, N, N> () (m);
|
||||
}
|
||||
footer<value_type> () (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<class M, class V, int N>
|
||||
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<value_type> () (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<value_type> () (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<class M, class V, int N>
|
||||
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<value_type> () (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<class T, int N>
|
||||
struct bench_c_matrix_vector_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m;
|
||||
static typename c_vector_traits<T, N>::type v1, v2;
|
||||
initialize_c_matrix<T, N, N> () (m);
|
||||
initialize_c_vector<T, N> () (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<T, N> () (v2);
|
||||
}
|
||||
footer<value_type> () (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<class M, class V, int N>
|
||||
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<value_type> () (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<value_type> () (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<class M, class V, int N>
|
||||
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<value_type> row (m [std::slice (N * j, N, 1)]);
|
||||
v2 [j] = (row * v1).sum ();
|
||||
}
|
||||
// sink_vector (v2);
|
||||
}
|
||||
footer<value_type> () (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<class T, int N>
|
||||
struct bench_c_matrix_add {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m1, m2, m3;
|
||||
initialize_c_matrix<T, N, N> () (m1);
|
||||
initialize_c_matrix<T, N, N> () (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<T, N, N> () (m3);
|
||||
}
|
||||
footer<value_type> () (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<class M, int N>
|
||||
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<value_type> () (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<value_type> () (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<class M, int N>
|
||||
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<value_type> () (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<class T, int N>
|
||||
void bench_2<T, N>::operator () (int runs) {
|
||||
header ("bench_2");
|
||||
|
||||
header ("outer_prod");
|
||||
|
||||
header ("C array");
|
||||
bench_c_outer_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_MAP_ARRAY
|
||||
header ("sparse_matrix<map_array>, sparse_vector<map_array> safe");
|
||||
bench_my_outer_prod<ublas::sparse_matrix<T, ublas::row_major, ublas::map_array<std::size_t, T> >,
|
||||
ublas::sparse_vector<T, ublas::map_array<std::size_t, T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("sparse_matrix<map_array>, sparse_vector<map_array> fast");
|
||||
bench_my_outer_prod<ublas::sparse_matrix<T, ublas::row_major, ublas::map_array<std::size_t, T> >,
|
||||
ublas::sparse_vector<T, ublas::map_array<std::size_t, T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_MAP
|
||||
header ("sparse_matrix<std::map>, sparse_vector<std::map> safe");
|
||||
bench_my_outer_prod<ublas::sparse_matrix<T, ublas::row_major, std::map<std::size_t, T> >,
|
||||
ublas::sparse_vector<T, std::map<std::size_t, T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("sparse_matrix<std::map>, sparse_vector<std::map> fast");
|
||||
bench_my_outer_prod<ublas::sparse_matrix<T, ublas::row_major, std::map<std::size_t, T> >,
|
||||
ublas::sparse_vector<T, std::map<std::size_t, T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_outer_prod<std::valarray<T>, std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
|
||||
header ("prod (sparse_matrix, sparse_vector)");
|
||||
|
||||
header ("C array");
|
||||
bench_c_matrix_vector_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_MAP_ARRAY
|
||||
header ("sparse_matrix<map_array>, sparse_vector<map_array> safe");
|
||||
bench_my_matrix_vector_prod<ublas::sparse_matrix<T, ublas::row_major, ublas::map_array<std::size_t, T> >,
|
||||
ublas::sparse_vector<T, ublas::map_array<std::size_t, T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("sparse_matrix<map_array>, sparse_vector<map_array> fast");
|
||||
bench_my_matrix_vector_prod<ublas::sparse_matrix<T, ublas::row_major, ublas::map_array<std::size_t, T> >,
|
||||
ublas::sparse_vector<T, ublas::map_array<std::size_t, T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_MAP
|
||||
header ("sparse_matrix<std::map>, sparse_vector<std::map> safe");
|
||||
bench_my_matrix_vector_prod<ublas::sparse_matrix<T, ublas::row_major, std::map<std::size_t, T> >,
|
||||
ublas::sparse_vector<T, std::map<std::size_t, T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("sparse_matrix<std::map>, sparse_vector<std::map> fast");
|
||||
bench_my_matrix_vector_prod<ublas::sparse_matrix<T, ublas::row_major, std::map<std::size_t, T> >,
|
||||
ublas::sparse_vector<T, std::map<std::size_t, T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_matrix_vector_prod<std::valarray<T>, std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
|
||||
header ("sparse_matrix + sparse_matrix");
|
||||
|
||||
header ("C array");
|
||||
bench_c_matrix_add<T, N> () (runs);
|
||||
|
||||
#ifdef USE_MAP_ARRAY
|
||||
header ("sparse_matrix<map_array> safe");
|
||||
bench_my_matrix_add<ublas::sparse_matrix<T, ublas::row_major, ublas::map_array<std::size_t, T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("sparse_matrix<map_array> fast");
|
||||
bench_my_matrix_add<ublas::sparse_matrix<T, ublas::row_major, ublas::map_array<std::size_t, T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_MAP
|
||||
header ("sparse_matrix<std::map> safe");
|
||||
bench_my_matrix_add<ublas::sparse_matrix<T, ublas::row_major, std::map<std::size_t, T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("sparse_matrix<std::map> fast");
|
||||
bench_my_matrix_add<ublas::sparse_matrix<T, ublas::row_major, std::map<std::size_t, T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_matrix_add<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
}
|
||||
|
||||
template struct bench_2<float, 3>;
|
||||
template struct bench_2<float, 10>;
|
||||
template struct bench_2<float, 30>;
|
||||
template struct bench_2<float, 100>;
|
||||
|
||||
template struct bench_2<double, 3>;
|
||||
template struct bench_2<double, 10>;
|
||||
template struct bench_2<double, 30>;
|
||||
template struct bench_2<double, 100>;
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
|
||||
template struct bench_2<std::complex<float>, 3>;
|
||||
template struct bench_2<std::complex<float>, 10>;
|
||||
template struct bench_2<std::complex<float>, 30>;
|
||||
template struct bench_2<std::complex<float>, 100>;
|
||||
|
||||
template struct bench_2<std::complex<double>, 3>;
|
||||
template struct bench_2<std::complex<double>, 10>;
|
||||
template struct bench_2<std::complex<double>, 30>;
|
||||
template struct bench_2<std::complex<double>, 100>;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
189
bench2/bench23.cpp
Normal file
189
bench2/bench23.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/vector_sparse.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/matrix_sparse.hpp>
|
||||
|
||||
#include <boost/timer.hpp>
|
||||
|
||||
#include "bench2.hpp"
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_matrix_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m1, m2, m3;
|
||||
initialize_c_matrix<T, N, N> () (m1);
|
||||
initialize_c_matrix<T, N, N> () (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<T, N, N> () (m3);
|
||||
}
|
||||
footer<value_type> () (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<class M1, class M2, int N>
|
||||
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<value_type> () (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<value_type> () (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<class M, int N>
|
||||
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<value_type> row (m1 [std::slice (N * j, N, 1)]);
|
||||
for (int k = 0; k < N; ++ k) {
|
||||
std::valarray<value_type> column (m2 [std::slice (k, N, N)]);
|
||||
m3 [N * j + k] = (row * column).sum ();
|
||||
}
|
||||
}
|
||||
// sink_vector (m3);
|
||||
}
|
||||
footer<value_type> () (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<class T, int N>
|
||||
void bench_3<T, N>::operator () (int runs) {
|
||||
header ("bench_3");
|
||||
|
||||
header ("prod (sparse_matrix, sparse_matrix)");
|
||||
|
||||
header ("C array");
|
||||
bench_c_matrix_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_MAP_ARRAY
|
||||
header ("sparse_matrix<map_array, row_major>, sparse_matrix<map_array, column_major> safe");
|
||||
bench_my_matrix_prod<ublas::sparse_matrix<T, ublas::row_major, ublas::map_array<std::size_t, T> >,
|
||||
ublas::sparse_matrix<T, ublas::column_major, ublas::map_array<std::size_t, T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("sparse_matrix<map_array, row_major>, sparse_matrix<map_array, column_major> fast");
|
||||
bench_my_matrix_prod<ublas::sparse_matrix<T, ublas::row_major, ublas::map_array<std::size_t, T> >,
|
||||
ublas::sparse_matrix<T, ublas::column_major, ublas::map_array<std::size_t, T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_MAP
|
||||
header ("sparse_matrix<std::map, row_major>, sparse_matrix<std::map, column_major> safe");
|
||||
bench_my_matrix_prod<ublas::sparse_matrix<T, ublas::row_major, std::map<std::size_t, T> >,
|
||||
ublas::sparse_matrix<T, ublas::column_major, std::map<std::size_t, T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("sparse_matrix<std::map, row_major>, sparse_matrix<std::map, column_major> fast");
|
||||
bench_my_matrix_prod<ublas::sparse_matrix<T, ublas::row_major, std::map<std::size_t, T> >,
|
||||
ublas::sparse_matrix<T, ublas::column_major, std::map<std::size_t, T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_matrix_prod<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
}
|
||||
|
||||
template struct bench_3<float, 3>;
|
||||
template struct bench_3<float, 10>;
|
||||
template struct bench_3<float, 30>;
|
||||
template struct bench_3<float, 100>;
|
||||
|
||||
template struct bench_3<double, 3>;
|
||||
template struct bench_3<double, 10>;
|
||||
template struct bench_3<double, 30>;
|
||||
template struct bench_3<double, 100>;
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
|
||||
template struct bench_3<std::complex<float>, 3>;
|
||||
template struct bench_3<std::complex<float>, 10>;
|
||||
template struct bench_3<std::complex<float>, 30>;
|
||||
template struct bench_3<std::complex<float>, 100>;
|
||||
|
||||
template struct bench_3<std::complex<double>, 3>;
|
||||
template struct bench_3<std::complex<double>, 10>;
|
||||
template struct bench_3<std::complex<double>, 30>;
|
||||
template struct bench_3<std::complex<double>, 100>;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
11
bench3/Jamfile
Normal file
11
bench3/Jamfile
Normal file
@@ -0,0 +1,11 @@
|
||||
subproject libs/numeric/ublas/bench3 ;
|
||||
|
||||
SOURCES = bench3 bench31 bench32 bench33 ;
|
||||
|
||||
exe bench3
|
||||
: $(SOURCES).cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
<borland><*><cxxflags>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092"
|
||||
;
|
||||
|
||||
|
||||
217
bench3/bench3.cpp
Normal file
217
bench3/bench3.cpp
Normal file
@@ -0,0 +1,217 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
|
||||
#include <boost/timer.hpp>
|
||||
|
||||
#include "bench3.hpp"
|
||||
|
||||
void header (std::string text) {
|
||||
std::cout << text << std::endl;
|
||||
std::cerr << text << std::endl;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
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<value_type> () (0, 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class T>
|
||||
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<value_type> () (0, 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
void peak<T>::operator () (int runs) {
|
||||
header ("peak");
|
||||
|
||||
header ("plus");
|
||||
peak_c_plus<T> () (runs);
|
||||
|
||||
header ("multiplies");
|
||||
peak_c_multiplies<T> () (runs);
|
||||
}
|
||||
|
||||
template struct peak<float>;
|
||||
template struct peak<double>;
|
||||
template struct peak<std::complex<float> >;
|
||||
template struct peak<std::complex<double> >;
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
// Standard new handler is not standard compliant.
|
||||
#include <new.h>
|
||||
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<float> () (100000000);
|
||||
|
||||
header ("double");
|
||||
peak<double> () (100000000);
|
||||
|
||||
#ifdef USE_COMPLEX
|
||||
header ("std:complex<float>");
|
||||
peak<std::complex<float> > () (100000000);
|
||||
|
||||
header ("std:complex<double>");
|
||||
peak<std::complex<double> > () (100000000);
|
||||
#endif
|
||||
|
||||
int scale = 1;
|
||||
if (argc > 1)
|
||||
scale = atoi (argv [1]);
|
||||
|
||||
header ("float, 3");
|
||||
|
||||
bench_1<float, 3> () (1000000 * scale);
|
||||
bench_2<float, 3> () (300000 * scale);
|
||||
bench_3<float, 3> () (100000 * scale);
|
||||
|
||||
header ("float, 10");
|
||||
|
||||
bench_1<float, 10> () (300000 * scale);
|
||||
bench_2<float, 10> () (30000 * scale);
|
||||
bench_3<float, 10> () (3000 * scale);
|
||||
|
||||
header ("float, 30");
|
||||
|
||||
bench_1<float, 30> () (100000 * scale);
|
||||
bench_2<float, 30> () (3000 * scale);
|
||||
bench_3<float, 30> () (100 * scale);
|
||||
|
||||
header ("float, 100");
|
||||
|
||||
bench_1<float, 100> () (30000 * scale);
|
||||
bench_2<float, 100> () (300 * scale);
|
||||
bench_3<float, 100> () (3 * scale);
|
||||
|
||||
header ("double, 3");
|
||||
|
||||
bench_1<double, 3> () (1000000 * scale);
|
||||
bench_2<double, 3> () (300000 * scale);
|
||||
bench_3<double, 3> () (100000 * scale);
|
||||
|
||||
header ("double, 10");
|
||||
|
||||
bench_1<double, 10> () (300000 * scale);
|
||||
bench_2<double, 10> () (30000 * scale);
|
||||
bench_3<double, 10> () (3000 * scale);
|
||||
|
||||
header ("double, 30");
|
||||
|
||||
bench_1<double, 30> () (100000 * scale);
|
||||
bench_2<double, 30> () (3000 * scale);
|
||||
bench_3<double, 30> () (100 * scale);
|
||||
|
||||
header ("double, 100");
|
||||
|
||||
bench_1<double, 100> () (30000 * scale);
|
||||
bench_2<double, 100> () (300 * scale);
|
||||
bench_3<double, 100> () (3 * scale);
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
header ("std::complex<float>, 3");
|
||||
|
||||
bench_1<std::complex<float>, 3> () (1000000 * scale);
|
||||
bench_2<std::complex<float>, 3> () (300000 * scale);
|
||||
bench_3<std::complex<float>, 3> () (100000 * scale);
|
||||
|
||||
header ("std::complex<float>, 10");
|
||||
|
||||
bench_1<std::complex<float>, 10> () (300000 * scale);
|
||||
bench_2<std::complex<float>, 10> () (30000 * scale);
|
||||
bench_3<std::complex<float>, 10> () (3000 * scale);
|
||||
|
||||
header ("std::complex<float>, 30");
|
||||
|
||||
bench_1<std::complex<float>, 30> () (100000 * scale);
|
||||
bench_2<std::complex<float>, 30> () (3000 * scale);
|
||||
bench_3<std::complex<float>, 30> () (100 * scale);
|
||||
|
||||
header ("std::complex<float>, 100");
|
||||
|
||||
bench_1<std::complex<float>, 100> () (30000 * scale);
|
||||
bench_2<std::complex<float>, 100> () (300 * scale);
|
||||
bench_3<std::complex<float>, 100> () (3 * scale);
|
||||
|
||||
header ("std::complex<double>, 3");
|
||||
|
||||
bench_1<std::complex<double>, 3> () (1000000 * scale);
|
||||
bench_2<std::complex<double>, 3> () (300000 * scale);
|
||||
bench_3<std::complex<double>, 3> () (100000 * scale);
|
||||
|
||||
header ("std::complex<double>, 10");
|
||||
|
||||
bench_1<std::complex<double>, 10> () (300000 * scale);
|
||||
bench_2<std::complex<double>, 10> () (30000 * scale);
|
||||
bench_3<std::complex<double>, 10> () (3000 * scale);
|
||||
|
||||
header ("std::complex<double>, 30");
|
||||
|
||||
bench_1<std::complex<double>, 30> () (100000 * scale);
|
||||
bench_2<std::complex<double>, 30> () (3000 * scale);
|
||||
bench_3<std::complex<double>, 30> () (100 * scale);
|
||||
|
||||
header ("std::complex<double>, 100");
|
||||
|
||||
bench_1<std::complex<double>, 100> () (30000 * scale);
|
||||
bench_2<std::complex<double>, 100> () (300 * scale);
|
||||
bench_3<std::complex<double>, 100> () (3 * scale);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
214
bench3/bench3.dsp
Normal file
214
bench3/bench3.dsp
Normal file
@@ -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
|
||||
156
bench3/bench3.hpp
Normal file
156
bench3/bench3.hpp
Normal file
@@ -0,0 +1,156 @@
|
||||
#ifndef BENCH3_H
|
||||
#define BENCH3_H
|
||||
|
||||
namespace ublas = boost::numeric::ublas;
|
||||
|
||||
void header (std::string text);
|
||||
|
||||
template<class T>
|
||||
struct footer {
|
||||
void operator () (int multiplies, int plus, int runs, double elapsed) {
|
||||
std::cout << "elapsed: " << elapsed << " s, "
|
||||
<< (multiplies * ublas::type_traits<T>::multiplies_complexity +
|
||||
plus * ublas::type_traits<T>::plus_complexity) * runs /
|
||||
(1024 * 1024 * elapsed) << " Mflops" << std::endl;
|
||||
std::cerr << "elapsed: " << elapsed << " s, "
|
||||
<< (multiplies * ublas::type_traits<T>::multiplies_complexity +
|
||||
plus * ublas::type_traits<T>::plus_complexity) * runs /
|
||||
(1024 * 1024 * elapsed) << " Mflops" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct c_vector_traits {
|
||||
typedef T type [N];
|
||||
};
|
||||
template<class T, int N, int M>
|
||||
struct c_matrix_traits {
|
||||
typedef T type [N] [M];
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct initialize_c_vector {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (typename c_vector_traits<T, N>::type v) {
|
||||
#else
|
||||
void operator () (typename c_vector_traits<T, N>::type &v) {
|
||||
#endif
|
||||
for (int i = 0; i < N; ++ i)
|
||||
v [i] = rand () * 1.f;
|
||||
// v [i] = 0.f;
|
||||
}
|
||||
};
|
||||
template<class V>
|
||||
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<class T, int N, int M>
|
||||
struct initialize_c_matrix {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (typename c_matrix_traits<T, N, M>::type m) {
|
||||
#else
|
||||
void operator () (typename c_matrix_traits<T, N, M>::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<class M>
|
||||
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<class T>
|
||||
BOOST_UBLAS_INLINE
|
||||
void sink_scalar (const T &s) {
|
||||
static T g_s = s;
|
||||
}
|
||||
|
||||
template<class T, int N>
|
||||
struct sink_c_vector {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (const typename c_vector_traits<T, N>::type v) {
|
||||
#else
|
||||
void operator () (const typename c_vector_traits<T, N>::type &v) {
|
||||
#endif
|
||||
static typename c_vector_traits<T, N>::type g_v;
|
||||
for (int i = 0; i < N; ++ i)
|
||||
g_v [i] = v [i];
|
||||
}
|
||||
};
|
||||
template<class V>
|
||||
BOOST_UBLAS_INLINE
|
||||
void sink_vector (const V &v) {
|
||||
static V g_v (v);
|
||||
}
|
||||
|
||||
template<class T, int N, int M>
|
||||
struct sink_c_matrix {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (const typename c_matrix_traits<T, N, M>::type m) {
|
||||
#else
|
||||
void operator () (const typename c_matrix_traits<T, N, M>::type &m) {
|
||||
#endif
|
||||
static typename c_matrix_traits<T, N, M>::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<class M>
|
||||
BOOST_UBLAS_INLINE
|
||||
void sink_matrix (const M &m) {
|
||||
static M g_m (m);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
struct peak {
|
||||
void operator () (int runs);
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_1 {
|
||||
void operator () (int runs);
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_2 {
|
||||
void operator () (int runs);
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
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
|
||||
|
||||
|
||||
336
bench3/bench31.cpp
Normal file
336
bench3/bench31.cpp
Normal file
@@ -0,0 +1,336 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
|
||||
#include <boost/timer.hpp>
|
||||
|
||||
#include "bench3.hpp"
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_inner_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_vector_traits<T, N>::type v1, v2;
|
||||
initialize_c_vector<T, N> () (v1);
|
||||
initialize_c_vector<T, N> () (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<value_type> () (N, N - 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
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<V> vr1 (v1, ublas::range<> (0, N)),
|
||||
vr2 (v2, ublas::range<> (0, N));
|
||||
#else
|
||||
static V v1 (N), v2 (N);
|
||||
ublas::vector_range<V> 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<value_type> () (N, N - 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
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<value_type> () (N, N - 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_vector_add {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_vector_traits<T, N>::type v1, v2, v3;
|
||||
initialize_c_vector<T, N> () (v1);
|
||||
initialize_c_vector<T, N> () (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<T, N> () (v3);
|
||||
}
|
||||
footer<value_type> () (0, 2 * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
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<V> 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<V> 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<value_type> () (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<V> 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<V> 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<value_type> () (0, 2 * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
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<value_type> () (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<class T, int N>
|
||||
void bench_1<T, N>::operator () (int runs) {
|
||||
header ("bench_1");
|
||||
|
||||
header ("inner_prod");
|
||||
|
||||
header ("C array");
|
||||
bench_c_inner_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_vector");
|
||||
bench_my_inner_prod<ublas::c_vector<T, N>, N> () (runs);
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("vector<bounded_array>");
|
||||
bench_my_inner_prod<ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs);
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("vector<unbounded_array>");
|
||||
bench_my_inner_prod<ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("vector<std::valarray>");
|
||||
bench_my_inner_prod<ublas::vector<T, std::valarray<T> >, N> () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("vector<std::vector>");
|
||||
bench_my_inner_prod<ublas::vector<T, std::vector<T> >, N> () (runs);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_inner_prod<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
|
||||
header ("vector + vector");
|
||||
|
||||
header ("C array");
|
||||
bench_c_vector_add<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_vector safe");
|
||||
bench_my_vector_add<ublas::c_vector<T, N>, N> () (runs, safe_tag ());
|
||||
|
||||
header ("c_vector fast");
|
||||
bench_my_vector_add<ublas::c_vector<T, N>, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("vector<bounded_array> safe");
|
||||
bench_my_vector_add<ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("vector<bounded_array> fast");
|
||||
bench_my_vector_add<ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("vector<unbounded_array> safe");
|
||||
bench_my_vector_add<ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("vector<unbounded_array> fast");
|
||||
bench_my_vector_add<ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("vector<std::valarray> safe");
|
||||
bench_my_vector_add<ublas::vector<T, std::valarray<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("vector<std::valarray> fast");
|
||||
bench_my_vector_add<ublas::vector<T, std::valarray<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("vector<std::vector> safe");
|
||||
bench_my_vector_add<ublas::vector<T, std::vector<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("vector<std::vector> fast");
|
||||
bench_my_vector_add<ublas::vector<T, std::vector<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_vector_add<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
}
|
||||
|
||||
template struct bench_1<float, 3>;
|
||||
template struct bench_1<float, 10>;
|
||||
template struct bench_1<float, 30>;
|
||||
template struct bench_1<float, 100>;
|
||||
|
||||
template struct bench_1<double, 3>;
|
||||
template struct bench_1<double, 10>;
|
||||
template struct bench_1<double, 30>;
|
||||
template struct bench_1<double, 100>;
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
|
||||
template struct bench_1<std::complex<float>, 3>;
|
||||
template struct bench_1<std::complex<float>, 10>;
|
||||
template struct bench_1<std::complex<float>, 30>;
|
||||
template struct bench_1<std::complex<float>, 100>;
|
||||
|
||||
template struct bench_1<std::complex<double>, 3>;
|
||||
template struct bench_1<std::complex<double>, 10>;
|
||||
template struct bench_1<std::complex<double>, 30>;
|
||||
template struct bench_1<std::complex<double>, 100>;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
568
bench3/bench32.cpp
Normal file
568
bench3/bench32.cpp
Normal file
@@ -0,0 +1,568 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
|
||||
#include <boost/timer.hpp>
|
||||
|
||||
#include "bench3.hpp"
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_outer_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m;
|
||||
static typename c_vector_traits<T, N>::type v1, v2;
|
||||
initialize_c_vector<T, N> () (v1);
|
||||
initialize_c_vector<T, N> () (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<T, N, N> () (m);
|
||||
}
|
||||
footer<value_type> () (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<class M, class V, int N>
|
||||
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<M> mr (m, ublas::range<> (0, N), ublas::range<> (0, N));
|
||||
static V v1 (N), v2 (N);
|
||||
ublas::vector_range<V> vr1 (v1, ublas::range<> (0, N)),
|
||||
vr2 (v2, ublas::range<> (0, N));
|
||||
#else
|
||||
static M m (N, N);
|
||||
ublas::matrix_range<M> mr (m, ublas::range (0, N), ublas::range (0, N));
|
||||
static V v1 (N), v2 (N);
|
||||
ublas::vector_range<V> 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<value_type> () (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<M> mr (m, ublas::range<> (0, N), ublas::range<> (0, N));
|
||||
static V v1 (N), v2 (N);
|
||||
ublas::vector_range<V> vr1 (v1, ublas::range<> (0, N)),
|
||||
vr2 (v2, ublas::range<> (0, N));
|
||||
#else
|
||||
static M m (N, N);
|
||||
ublas::matrix_range<M> mr (m, ublas::range (0, N), ublas::range (0, N));
|
||||
static V v1 (N), v2 (N);
|
||||
ublas::vector_range<V> 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<value_type> () (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<class M, class V, int N>
|
||||
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<value_type> () (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<class T, int N>
|
||||
struct bench_c_matrix_vector_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m;
|
||||
static typename c_vector_traits<T, N>::type v1, v2;
|
||||
initialize_c_matrix<T, N, N> () (m);
|
||||
initialize_c_vector<T, N> () (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<T, N> () (v2);
|
||||
}
|
||||
footer<value_type> () (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<class M, class V, int N>
|
||||
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<M> mr (m, ublas::range<> (0, N), ublas::range<> (0, N));
|
||||
static V v1 (N), v2 (N);
|
||||
ublas::vector_range<V> vr1 (v1, ublas::range<> (0, N)),
|
||||
vr2 (v2, ublas::range<> (0, N));
|
||||
#else
|
||||
static M m (N, N);
|
||||
ublas::matrix_range<M> mr (m, ublas::range (0, N), ublas::range (0, N));
|
||||
static V v1 (N), v2 (N);
|
||||
ublas::vector_range<V> 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<value_type> () (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<M> mr (m, ublas::range<> (0, N), ublas::range<> (0, N));
|
||||
static V v1 (N), v2 (N);
|
||||
ublas::vector_range<V> vr1 (v1, ublas::range<> (0, N)),
|
||||
vr2 (v2, ublas::range<> (0, N));
|
||||
#else
|
||||
static M m (N, N);
|
||||
ublas::matrix_range<M> mr (m, ublas::range (0, N), ublas::range (0, N));
|
||||
static V v1 (N), v2 (N);
|
||||
ublas::vector_range<V> 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<value_type> () (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<class M, class V, int N>
|
||||
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<value_type> row (m [std::slice (N * j, N, 1)]);
|
||||
v2 [j] = (row * v1).sum ();
|
||||
}
|
||||
// sink_vector (v2);
|
||||
}
|
||||
footer<value_type> () (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<class T, int N>
|
||||
struct bench_c_matrix_add {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m1, m2, m3;
|
||||
initialize_c_matrix<T, N, N> () (m1);
|
||||
initialize_c_matrix<T, N, N> () (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<T, N, N> () (m3);
|
||||
}
|
||||
footer<value_type> () (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<class M, int N>
|
||||
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<value_type> () (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<value_type> () (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<class M, int N>
|
||||
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<value_type> () (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<class T, int N>
|
||||
void bench_2<T, N>::operator () (int runs) {
|
||||
header ("bench_2");
|
||||
|
||||
header ("outer_prod");
|
||||
|
||||
header ("C array");
|
||||
bench_c_outer_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_matrix, c_vector safe");
|
||||
bench_my_outer_prod<ublas::c_matrix<T, N, N>,
|
||||
ublas::c_vector<T, N>, N> () (runs, safe_tag ());
|
||||
|
||||
header ("c_matrix, c_vector fast");
|
||||
bench_my_outer_prod<ublas::c_matrix<T, N, N>,
|
||||
ublas::c_vector<T, N>, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("matrix<bounded_array>, vector<bounded_array> safe");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >,
|
||||
ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<bounded_array>, vector<bounded_array> fast");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >,
|
||||
ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("matrix<unbounded_array>, vector<unbounded_array> safe");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >,
|
||||
ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<unbounded_array>, vector<unbounded_array> fast");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >,
|
||||
ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("matrix<std::valarray>, vector<std::valarray> safe");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >,
|
||||
ublas::vector<T, std::valarray<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::valarray>, vector<std::valarray> fast");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >,
|
||||
ublas::vector<T, std::valarray<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("matrix<std::vector>, vector<std::vector> safe");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >,
|
||||
ublas::vector<T, std::vector<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::vector>, vector<std::vector> fast");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >,
|
||||
ublas::vector<T, std::vector<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_outer_prod<std::valarray<T>, std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
|
||||
header ("prod (matrix, vector)");
|
||||
|
||||
header ("C array");
|
||||
bench_c_matrix_vector_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_matrix, c_vector safe");
|
||||
bench_my_matrix_vector_prod<ublas::c_matrix<T, N, N>,
|
||||
ublas::c_vector<T, N>, N> () (runs, safe_tag ());
|
||||
|
||||
header ("c_matrix, c_vector fast");
|
||||
bench_my_matrix_vector_prod<ublas::c_matrix<T, N, N>,
|
||||
ublas::c_vector<T, N>, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("matrix<bounded_array>, vector<bounded_array> safe");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >,
|
||||
ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<bounded_array>, vector<bounded_array> fast");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >,
|
||||
ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("matrix<unbounded_array>, vector<unbounded_array> safe");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >,
|
||||
ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<unbounded_array>, vector<unbounded_array> fast");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >,
|
||||
ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("matrix<std::valarray>, vector<std::valarray> safe");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >,
|
||||
ublas::vector<T, std::valarray<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::valarray>, vector<std::valarray> fast");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >,
|
||||
ublas::vector<T, std::valarray<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("matrix<std::vector>, vector<std::vector> safe");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >,
|
||||
ublas::vector<T, std::vector<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::vector>, vector<std::vector> fast");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >,
|
||||
ublas::vector<T, std::vector<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_matrix_vector_prod<std::valarray<T>, std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
|
||||
header ("matrix + matrix");
|
||||
|
||||
header ("C array");
|
||||
bench_c_matrix_add<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_matrix safe");
|
||||
bench_my_matrix_add<ublas::c_matrix<T, N, N>, N> () (runs, safe_tag ());
|
||||
|
||||
header ("c_matrix fast");
|
||||
bench_my_matrix_add<ublas::c_matrix<T, N, N>, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("matrix<bounded_array> safe");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<bounded_array> fast");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("matrix<unbounded_array> safe");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<unbounded_array> fast");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("matrix<std::valarray> safe");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, std::valarray<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::valarray> fast");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, std::valarray<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("matrix<std::vector> safe");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, std::vector<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::vector> fast");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, std::vector<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_matrix_add<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
}
|
||||
|
||||
template struct bench_2<float, 3>;
|
||||
template struct bench_2<float, 10>;
|
||||
template struct bench_2<float, 30>;
|
||||
template struct bench_2<float, 100>;
|
||||
|
||||
template struct bench_2<double, 3>;
|
||||
template struct bench_2<double, 10>;
|
||||
template struct bench_2<double, 30>;
|
||||
template struct bench_2<double, 100>;
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
|
||||
template struct bench_2<std::complex<float>, 3>;
|
||||
template struct bench_2<std::complex<float>, 10>;
|
||||
template struct bench_2<std::complex<float>, 30>;
|
||||
template struct bench_2<std::complex<float>, 100>;
|
||||
|
||||
template struct bench_2<std::complex<double>, 3>;
|
||||
template struct bench_2<std::complex<double>, 10>;
|
||||
template struct bench_2<std::complex<double>, 30>;
|
||||
template struct bench_2<std::complex<double>, 100>;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
223
bench3/bench33.cpp
Normal file
223
bench3/bench33.cpp
Normal file
@@ -0,0 +1,223 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
|
||||
#include <boost/timer.hpp>
|
||||
|
||||
#include "bench3.hpp"
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_matrix_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m1, m2, m3;
|
||||
initialize_c_matrix<T, N, N> () (m1);
|
||||
initialize_c_matrix<T, N, N> () (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<T, N, N> () (m3);
|
||||
}
|
||||
footer<value_type> () (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<class M, int N>
|
||||
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<M> 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<M> 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<value_type> () (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<M> 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<M> 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<value_type> () (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<class M, int N>
|
||||
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<value_type> row (m1 [std::slice (N * j, N, 1)]);
|
||||
for (int k = 0; k < N; ++ k) {
|
||||
std::valarray<value_type> column (m2 [std::slice (k, N, N)]);
|
||||
m3 [N * j + k] = (row * column).sum ();
|
||||
}
|
||||
}
|
||||
// sink_vector (m3);
|
||||
}
|
||||
footer<value_type> () (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<class T, int N>
|
||||
void bench_3<T, N>::operator () (int runs) {
|
||||
header ("bench_3");
|
||||
|
||||
header ("prod (matrix, matrix)");
|
||||
|
||||
header ("C array");
|
||||
bench_c_matrix_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_matrix safe");
|
||||
bench_my_matrix_prod<ublas::c_matrix<T, N, N>, N> () (runs, safe_tag ());
|
||||
|
||||
header ("c_matrix fast");
|
||||
bench_my_matrix_prod<ublas::c_matrix<T, N, N>, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("matrix<bounded_array> safe");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<bounded_array> fast");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("matrix<unbounded_array> safe");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<unbounded_array> fast");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("matrix<std::valarray> safe");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::valarray> fast");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("matrix<std::vector> safe");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::vector> fast");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_matrix_prod<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
}
|
||||
|
||||
template struct bench_3<float, 3>;
|
||||
template struct bench_3<float, 10>;
|
||||
template struct bench_3<float, 30>;
|
||||
template struct bench_3<float, 100>;
|
||||
|
||||
template struct bench_3<double, 3>;
|
||||
template struct bench_3<double, 10>;
|
||||
template struct bench_3<double, 30>;
|
||||
template struct bench_3<double, 100>;
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
|
||||
template struct bench_3<std::complex<float>, 3>;
|
||||
template struct bench_3<std::complex<float>, 10>;
|
||||
template struct bench_3<std::complex<float>, 30>;
|
||||
template struct bench_3<std::complex<float>, 100>;
|
||||
|
||||
template struct bench_3<std::complex<double>, 3>;
|
||||
template struct bench_3<std::complex<double>, 10>;
|
||||
template struct bench_3<std::complex<double>, 30>;
|
||||
template struct bench_3<std::complex<double>, 100>;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
57
concepts.cpp
Normal file
57
concepts.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/vector_sparse.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/banded.hpp>
|
||||
#include <boost/numeric/ublas/triangular.hpp>
|
||||
#include <boost/numeric/ublas/symmetric.hpp>
|
||||
#include <boost/numeric/ublas/hermitian.hpp>
|
||||
#include <boost/numeric/ublas/matrix_sparse.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include <boost/numeric/ublas/concepts.hpp>
|
||||
|
||||
namespace ublas = boost::numeric::ublas;
|
||||
|
||||
int main () {
|
||||
void (* check) (void) = ublas::concept_checks;
|
||||
ublas::ignore_unused_variable_warning (check);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
282
concepts.dsp
Normal file
282
concepts.dsp
Normal file
@@ -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
|
||||
1206
doc/banded.htm
Normal file
1206
doc/banded.htm
Normal file
File diff suppressed because it is too large
Load Diff
BIN
doc/c++boost.gif
Normal file
BIN
doc/c++boost.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
393
doc/container.htm
Normal file
393
doc/container.htm
Normal file
@@ -0,0 +1,393 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
|
||||
<title>Container Concepts</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<h1><img src="c++boost.gif" alt="c++boost.gif" align="center">Container Concepts</h1>
|
||||
|
||||
<h2><a name="vector"></a>Vector </h2>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>A Vector describes common aspects of dense, packed and sparse vectors.
|
||||
</p>
|
||||
|
||||
<h4>Refinement of </h4>
|
||||
|
||||
<p><a href="expression.htm#vector_expression">Vector Expression</a>.</p>
|
||||
|
||||
<h4>Associated types</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<td>Value type </td>
|
||||
<td><code>value_type</code> </td>
|
||||
<td>The type of the vector. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Distance type </td>
|
||||
<td><code>difference_type</code> </td>
|
||||
<td>A signed integral type used to represent the distance
|
||||
between two of the vector's iterators. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Size type </td>
|
||||
<td><code>size_type</code> </td>
|
||||
<td>An unsigned integral type that can represent any
|
||||
nonnegative value of the vector's distance type. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Notation</h4>
|
||||
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td><code>V</code> </td>
|
||||
<td>A type that is a model of Vector</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>v</code></td>
|
||||
<td>Objects of type <code>V</code> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>n, i</code></td>
|
||||
<td>Objects of a type convertible to <code>size_type</code>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>t</code></td>
|
||||
<td>Object of a type convertible to <code>value_type</code>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Definitions</h4>
|
||||
|
||||
<h4>Valid expressions</h4>
|
||||
|
||||
<p>In addition to the expressions defined in <a
|
||||
href="expression.htm#vector_expression">Vector Expression</a> the
|
||||
following expressions must be valid. </p>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Name </th>
|
||||
<th>Expression </th>
|
||||
<th>Type requirements </th>
|
||||
<th>Return type </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Sizing constructor </td>
|
||||
<td><code>V v (n)</code> </td>
|
||||
<td> </td>
|
||||
<td><code>V</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Insert </td>
|
||||
<td><code>v.insert (i, t)</code> </td>
|
||||
<td><code>v</code> is mutable.</td>
|
||||
<td><code>void</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Erase </td>
|
||||
<td><code>v.erase (i)</code> </td>
|
||||
<td><code>v</code> is mutable.</td>
|
||||
<td><code>void</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Clear </td>
|
||||
<td><code>v.clear ()</code> </td>
|
||||
<td><code>v</code> is mutable.</td>
|
||||
<td><code>void</code> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Resize </td>
|
||||
<td><code>v.resize (n)</code> </td>
|
||||
<td><code>v</code> is mutable.</td>
|
||||
<td><code>void</code> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Expression semantics</h4>
|
||||
|
||||
<p>Semantics of an expression is defined only where it differs
|
||||
from, or is not defined in <a
|
||||
href="expression.htm#vector_expression">Vector Expression</a>.</p>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Name </th>
|
||||
<th>Expression </th>
|
||||
<th>Precondition </th>
|
||||
<th>Semantics </th>
|
||||
<th>Postcondition </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Sizing constructor </td>
|
||||
<td><code>V v (n)</code> </td>
|
||||
<td><code>n >= 0</code> </td>
|
||||
<td>Creates a vector of <code>n</code> elements. </td>
|
||||
<td><code>v.size () == n</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Insert </td>
|
||||
<td><code>v.insert (i, t)</code> </td>
|
||||
<td><code>0 <= i < v.size ()</code> and <br>
|
||||
<code>v (i)</code> is a copy of <code>value_type ()</code>.</td>
|
||||
<td>A copy of <code>t</code> is inserted in <code>v</code>.
|
||||
</td>
|
||||
<td><code>v (i)</code> is a copy of <code>t</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Erase </td>
|
||||
<td><code>v.erase (i)</code> </td>
|
||||
<td><code>0 <= i < v.size ()</code> </td>
|
||||
<td>Destroys the element <code>v (i)</code> and replaces
|
||||
it with <code>value_type ()</code>. </td>
|
||||
<td><code>v (i)</code> is a copy of <code>value_type ()</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Clear </td>
|
||||
<td><code>v.clear ()</code> </td>
|
||||
<td> </td>
|
||||
<td>Equivalent to <br>
|
||||
<code>for (i = 0; i < v.size (); ++ i)</code><br>
|
||||
<code>v.erase (i);</code> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Resize </td>
|
||||
<td><code>v.resize (n)</code> </td>
|
||||
<td> </td>
|
||||
<td>Modifies the vector so that it can hold <code>n</code>
|
||||
elements. </td>
|
||||
<td><code>v.size () == n</code>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Complexity guarantees</h4>
|
||||
|
||||
<p>The run-time complexity of the sizing constructor is linear in
|
||||
the vector's size. </p>
|
||||
|
||||
<p>The run-time complexity of insert and erase is specific for
|
||||
the vector.</p>
|
||||
|
||||
<h4>Invariants</h4>
|
||||
|
||||
<h4>Models</h4>
|
||||
|
||||
<ul>
|
||||
<li><code>vector<T, A></code></li>
|
||||
<li><code>unit_vector<T></code></li>
|
||||
<li><code>zero_vector<T></code></li>
|
||||
<li><code>sparse_vector<T, A></code></li>
|
||||
</ul>
|
||||
|
||||
<h2><a name="matrix"></a>Matrix </h2>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>A Matrix describes common aspects of dense, packed and sparse
|
||||
matrices. </p>
|
||||
|
||||
<h4>Refinement of </h4>
|
||||
|
||||
<p><a href="expression.htm#matrix_expression">Matrix Expression</a>.</p>
|
||||
|
||||
<h4>Associated types</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<td>Value type </td>
|
||||
<td><code>value_type</code> </td>
|
||||
<td>The type of the matrix. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Distance type </td>
|
||||
<td><code>difference_type</code> </td>
|
||||
<td>A signed integral type used to represent the distance
|
||||
between two of the matrix's iterators. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Size type </td>
|
||||
<td><code>size_type</code> </td>
|
||||
<td>An unsigned integral type that can represent any
|
||||
nonnegative value of the matrix's distance type. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Notation</h4>
|
||||
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td><code>M</code> </td>
|
||||
<td>A type that is a model of Matrix</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>m</code></td>
|
||||
<td>Objects of type <code>M</code> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>n1, n2, i, j</code></td>
|
||||
<td>Objects of a type convertible to <code>size_type</code>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>t</code></td>
|
||||
<td>Object of a type convertible to <code>value_type</code>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Definitions</h4>
|
||||
|
||||
<h4>Valid expressions</h4>
|
||||
|
||||
<p>In addition to the expressions defined in <a
|
||||
href="expression.htm#matrix_expression">Matrix Expression</a> the
|
||||
following expressions must be valid. </p>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Name </th>
|
||||
<th>Expression </th>
|
||||
<th>Type requirements </th>
|
||||
<th>Return type </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Sizing constructor </td>
|
||||
<td><code>M m (n1, n2)</code> </td>
|
||||
<td> </td>
|
||||
<td><code>M</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Insert </td>
|
||||
<td><code>m.insert (i, j, t)</code> </td>
|
||||
<td><code>m</code> is mutable.</td>
|
||||
<td><code>void</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Erase </td>
|
||||
<td><code>m.erase (i, j)</code> </td>
|
||||
<td><code>m</code> is mutable.</td>
|
||||
<td><code>void</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Clear </td>
|
||||
<td><code>m.clear ()</code> </td>
|
||||
<td><code>m</code> is mutable.</td>
|
||||
<td><code>void</code> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Resize </td>
|
||||
<td><code>m.resize (n1, n2)</code> </td>
|
||||
<td><code>m</code> is mutable.</td>
|
||||
<td><code>void</code> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Expression semantics</h4>
|
||||
|
||||
<p>Semantics of an expression is defined only where it differs
|
||||
from, or is not defined in <a
|
||||
href="expression.htm#matrix_expression">Matrix Expression</a>.</p>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Name </th>
|
||||
<th>Expression </th>
|
||||
<th>Precondition </th>
|
||||
<th>Semantics </th>
|
||||
<th>Postcondition </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Sizing constructor </td>
|
||||
<td><code>M m (n1, n2)</code> </td>
|
||||
<td><code>n1 >= 0</code> and<code> n2 >= 0</code></td>
|
||||
<td>Creates a matrix of <code>n1 </code>rows and <code>n2</code>
|
||||
columns. </td>
|
||||
<td><code>m.size1 () == n1</code> and <code>m.size2 () ==
|
||||
n2</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Insert </td>
|
||||
<td><code>m.insert (i, j, t)</code> </td>
|
||||
<td><code>0 <= i < m.size1 ()</code>, <br>
|
||||
<code>0 <= j < m.size2 ()</code>and <code><br>
|
||||
m (i, j)</code> is a copy of <code>value_type ()</code>.</td>
|
||||
<td>A copy of <code>t</code> is inserted in <code>m</code>.
|
||||
</td>
|
||||
<td><code>m (i, j)</code> is a copy of <code>t</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Erase </td>
|
||||
<td><code>m.erase (i, j)</code> </td>
|
||||
<td><code>0 <= i < m.size1 ()</code>and <code><br>
|
||||
0 <= j < m.size2 </code></td>
|
||||
<td>Destroys the element <code>m (i, j)</code> and
|
||||
replaces it with <code>value_type ()</code>. </td>
|
||||
<td><code>m (i, j)</code> is a copy of <code>value_type
|
||||
()</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Clear </td>
|
||||
<td><code>m.clear ()</code> </td>
|
||||
<td> </td>
|
||||
<td>Equivalent to<br>
|
||||
<code>for (i = 0; i < m.size1 (); ++ i)</code><br>
|
||||
<code>for (j = 0; j < m.size2 (); ++ j)</code><br>
|
||||
<code>m.erase (i, j);</code> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Resize </td>
|
||||
<td><code>m.resize (n1, n2)</code> </td>
|
||||
<td> </td>
|
||||
<td>Modifies the vector so that it can hold <code>n1 </code>rows
|
||||
and <code>n2</code> columns. </td>
|
||||
<td><code>m.size1 () == n1</code> and <code>m.size2 () ==
|
||||
n2</code>.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Complexity guarantees</h4>
|
||||
|
||||
<p>The run-time complexity of the sizing constructor is quadratic
|
||||
in the matrix's size. </p>
|
||||
|
||||
<p>The run-time complexity of insert and erase is specific for
|
||||
the matrix.</p>
|
||||
|
||||
<h4>Invariants</h4>
|
||||
|
||||
<h4>Models</h4>
|
||||
|
||||
<ul>
|
||||
<li><code>matrix<T, F, A></code></li>
|
||||
<li><code>identity_matrix<T></code></li>
|
||||
<li><code>zero_matrix<T></code></li>
|
||||
<li><code>triangular_matrix<T, F1, F2, A></code></li>
|
||||
<li><code>symmetric_matrix<T, F1, F2, A></code></li>
|
||||
<li><code>banded_matrix<T, F, A></code></li>
|
||||
<li><code>sparse_matrix<T, F, A></code></li>
|
||||
</ul>
|
||||
<hr>
|
||||
|
||||
<p>Copyright (©) 2000-2002 Joerg Walter, Mathias Koch <br>
|
||||
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.</p>
|
||||
|
||||
<p>Last revised: 8/3/2002</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
1033
doc/expression.htm
Normal file
1033
doc/expression.htm
Normal file
File diff suppressed because it is too large
Load Diff
1208
doc/hermitian.htm
Normal file
1208
doc/hermitian.htm
Normal file
File diff suppressed because it is too large
Load Diff
316
doc/index.htm
Normal file
316
doc/index.htm
Normal file
@@ -0,0 +1,316 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
|
||||
<title>Boost Basic Linear Algebra</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<h1><img src="c++boost.gif" alt="c++boost.gif" align="center"
|
||||
width="277" height="86"> Basic Linear Algebra</h1>
|
||||
|
||||
<p>uBLAS is a C++ template class library that provides <a
|
||||
href="http://www.netlib.org/blas">BLAS</a> 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. </p>
|
||||
|
||||
<h2>Functionality</h2>
|
||||
|
||||
<p>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
|
||||
<a href="http://www.sgi.com/tech/stl">STL</a> conforming iterator
|
||||
interface.</p>
|
||||
|
||||
<p>Dense, packed and sparse matrix classes are being tested with the <a
|
||||
href="http://www.netlib.org/clapack">CLAPACK</a> test suite.</p>
|
||||
|
||||
<p>Known limitations:</p>
|
||||
|
||||
<ul type="disc">
|
||||
<li>The implementation assumes a linear memory address model.</li>
|
||||
<li>Tuning was focussed on dense matrices.</li>
|
||||
</ul>
|
||||
|
||||
<h2>Documentation</h2>
|
||||
|
||||
<ul>
|
||||
<li><a href="overview.htm">Overview</a></li>
|
||||
<li><a href="expression.htm">Expression Concepts</a><ul
|
||||
type="circle">
|
||||
<li><a href="expression.htm#scalar_expression">Scalar
|
||||
Expression</a></li>
|
||||
<li><a href="expression.htm#vector_expression">Vector
|
||||
Expression</a></li>
|
||||
<li><a href="expression.htm#matrix_expression">Matrix
|
||||
Expression</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="container.htm">Container Concepts</a><ul
|
||||
type="circle">
|
||||
<li><a href="container.htm#vector">Vector</a></li>
|
||||
<li><a href="container.htm#matrix">Matrix</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="iterator.htm">Iterator Concepts</a><ul
|
||||
type="circle">
|
||||
<li><a
|
||||
href="iterator.htm#indexed_bidirectional_iterator">Indexed
|
||||
Bidirectional Iterator</a></li>
|
||||
<li><a
|
||||
href="iterator.htm#indexed_random_access_iterator">Indexed
|
||||
Random Access Iterator</a></li>
|
||||
<li><a
|
||||
href="iterator.htm#indexed_bidirectional_cr_iterator">Indexed
|
||||
Bidirectional Column/Row Iterator</a></li>
|
||||
<li><a
|
||||
href="iterator.htm#indexed_random_access_cr_iterator">Indexed
|
||||
Random Access Column/Row Iterator</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="storage.htm">Storage</a><ul type="circle">
|
||||
<li><a href="storage.htm#unbounded_array">Unbounded
|
||||
Array</a></li>
|
||||
<li><a href="storage.htm#bounded_array">Bounded Array</a></li>
|
||||
<li><a href="storage.htm#range">Range</a></li>
|
||||
<li><a href="storage.htm#slice">Slice</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="storage_sparse.htm">Sparse Storage</a><ul
|
||||
type="circle">
|
||||
<li><a href="storage_sparse.htm#map_array">Map Array</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="vector.htm">Vector</a><ul type="circle">
|
||||
<li><a href="vector.htm#vector">Vector</a></li>
|
||||
<li><a href="vector.htm#unit_vector">Unit Vector</a></li>
|
||||
<li><a href="vector.htm#zero_vector">Zero Vector</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="vector_sparse.htm">Sparse Vector</a><ul
|
||||
type="circle">
|
||||
<li><a href="vector_sparse.htm#sparse_vector">Sparse
|
||||
Vector</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="vector_proxy.htm">Vector Proxies</a><ul
|
||||
type="circle">
|
||||
<li><a href="vector_proxy.htm#vector_range">Vector
|
||||
Range</a></li>
|
||||
<li><a href="vector_proxy.htm#vector_slice">Vector
|
||||
Slice</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="vector_expression.htm">Vector Expressions</a><ul
|
||||
type="circle">
|
||||
<li><a href="vector_expression.htm#vector_expression">Vector
|
||||
Expression</a></li>
|
||||
<li><a href="vector_expression.htm#vector_references">Vector
|
||||
References</a></li>
|
||||
<li><a href="vector_expression.htm#vector_operations">Vector
|
||||
Operations</a></li>
|
||||
<li><a href="vector_expression.htm#vector_reductions">Vector
|
||||
Reductions</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="matrix.htm">Matrix</a><ul type="circle">
|
||||
<li><a href="matrix.htm#matrix">Matrix</a></li>
|
||||
<li><a href="matrix.htm#identity_matrix">Identity
|
||||
Matrix</a></li>
|
||||
<li><a href="matrix.htm#zero_matrix">Zero Matrix</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="triangular.htm">Triangular Matrix</a><ul
|
||||
type="circle">
|
||||
<li><a href="triangular.htm#triangular_matrix">Triangular
|
||||
Matrix</a></li>
|
||||
<li><a href="triangular.htm#triangular_adaptor">Triangular
|
||||
Adaptor</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="symmetric.htm">Symmetric Matrix</a><ul
|
||||
type="circle">
|
||||
<li><a href="symmetric.htm#symmetric_matrix">Symmetric
|
||||
Matrix</a></li>
|
||||
<li><a href="symmetric.htm#symmetric_adaptor">Symmetric
|
||||
Adaptor</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="hermitian.htm">Hermitian Matrix</a><ul
|
||||
type="circle">
|
||||
<li><a href="hermitian.htm#hermitian_matrix">Hermitian
|
||||
Matrix</a></li>
|
||||
<li><a href="hermitian.htm#hermitian_adaptor">Hermitian
|
||||
Adaptor</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="banded.htm">Banded Matrix</a><ul type="circle">
|
||||
<li><a href="banded.htm#banded_matrix">Banded Matrix</a></li>
|
||||
<li><a href="banded.htm#banded_adaptor">Banded
|
||||
Adaptor</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="matrix_sparse.htm">Sparse Matrix</a><ul
|
||||
type="circle">
|
||||
<li><a href="matrix_sparse.htm#sparse_matrix">Sparse
|
||||
Matrix</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="matrix_proxy.htm">Matrix Proxies</a><ul
|
||||
type="circle">
|
||||
<li><a href="matrix_proxy.htm#matrix_row">Matrix Row</a></li>
|
||||
<li><a href="matrix_proxy.htm#matrix_column">Matrix
|
||||
Column</a></li>
|
||||
<li><a href="matrix_proxy.htm#vector_range">Vector
|
||||
Range</a></li>
|
||||
<li><a href="matrix_proxy.htm#vector_slice">Vector
|
||||
Slice</a></li>
|
||||
<li><a href="matrix_proxy.htm#matrix_range">Matrix
|
||||
Range</a></li>
|
||||
<li><a href="matrix_proxy.htm#matrix_slice">Matrix
|
||||
Slice</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="matrix_expression.htm">Matrix Expressions</a><ul
|
||||
type="circle">
|
||||
<li><a href="matrix_expression.htm#matrix_expression">Matrix
|
||||
Expression</a></li>
|
||||
<li><a href="matrix_expression.htm#matrix_references">Matrix
|
||||
References</a></li>
|
||||
<li><a href="matrix_expression.htm#matrix_operations">Matrix
|
||||
Operations</a></li>
|
||||
<li><a href="matrix_expression.htm#matrix_reductions">Matrix
|
||||
Reductions</a></li>
|
||||
<li><a
|
||||
href="matrix_expression.htm#matrix_vector_operations">Matrix
|
||||
Vector Operations</a></li>
|
||||
<li><a
|
||||
href="matrix_expression.htm#matrix_matrix_operations">Matrix
|
||||
Matrix Operations</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h2>Supported Platforms</h2>
|
||||
|
||||
<p>As main development platform for uBLAS we used MSVC 6.0 with
|
||||
Dinkumware STL. Other compilers known to accept the library are</p>
|
||||
|
||||
<ul>
|
||||
<li>MSVC 6.0 with STLPort-4.5.3</li>
|
||||
<li>BCC 5.5</li>
|
||||
<li>GCC 2.95.x, 3.0.x, 3.1</li>
|
||||
<li>ICC 5.0, 6.0</li>
|
||||
<li>Comeau 4.2.x</li>
|
||||
<li>MWCW</li>
|
||||
</ul>
|
||||
|
||||
<h2>Download</h2>
|
||||
|
||||
<p>You can download the current stable release of the source code
|
||||
from <a href="http://www.genesys-e.org/ublas/downloads/ublas.zip">here</a>.
|
||||
Prerequisite is the latest stable release of the <a
|
||||
href="http://www.boost.org">Boost</a> libraries Configuration,
|
||||
Timer and optionally SmartPointer.</p>
|
||||
|
||||
<h2>CVS Access</h2>
|
||||
|
||||
<p>You can also check out the latest version via anonymous CVS.
|
||||
Here's how: </p>
|
||||
|
||||
<pre> 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</pre>
|
||||
|
||||
<p>If you have gzip installed on your system, you can speed up
|
||||
the transfer using</p>
|
||||
|
||||
<pre> 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</pre>
|
||||
|
||||
<p>You can also <a
|
||||
href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/boost">view</a>
|
||||
the CVS archive. You may find the library <a
|
||||
href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/boost/boost/boost/numeric/ublas/?only_with_tag=matrix_development">here</a>.
|
||||
Documentation and test programs reside <a
|
||||
href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/boost/boost/libs/numeric/ublas/?only_with_tag=matrix_development">here</a>.</p>
|
||||
|
||||
<h2>Mailing lists</h2>
|
||||
|
||||
<p>uBLAS has no dedicated mailing list. Feel free to use the
|
||||
mailing lists of <a href="http://www.boost.org">Boost</a>.</p>
|
||||
|
||||
<h2>Authors and Credits</h2>
|
||||
|
||||
<p>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 <a
|
||||
href="http://www.boost.org">Boost</a></p>
|
||||
|
||||
<h2>Frequently Asked Questions</h2>
|
||||
|
||||
<p>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?<br>
|
||||
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 <code>NDEBUG</code>
|
||||
of <code>cassert</code> is defined. <code>NDEBUG</code> enables
|
||||
release mode, which in turn uses expression templates.</p>
|
||||
|
||||
<p>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?<br>
|
||||
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 <code>NDEBUG</code>
|
||||
of <code>cassert</code> is defined. <code>NDEBUG</code> disables
|
||||
debug mode, which is needed to get size and type conformance
|
||||
checks.</p>
|
||||
|
||||
<p>Q: I've written some uBLAS benchmarks to measure the
|
||||
performance of matrix chain multiplications like <code>prod (A,
|
||||
prod (B, C))</code> and see a significant performance penalty due
|
||||
to the use of expression templates. How can I disable expression
|
||||
templates?<br>
|
||||
A: You do not need to disable expression templates. Please try
|
||||
reintroducing temporaries using either <code>prod (A, </code><code><em>matrix_type</em></code><code>
|
||||
(prod (B, C)))</code> or <code>prod (A, prod<</code><code><em>matrix_type</em></code><code>>
|
||||
(B, C))</code>.</p>
|
||||
|
||||
<h2>Contact Information</h2>
|
||||
|
||||
<p>If you have a problem, or have found a bug, please send us a <a
|
||||
href="mailto:ublas@genesys-e.org">note</a>. </p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Copyright (©) 2000-2002 Joerg Walter, Mathias Koch <br>
|
||||
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.</p>
|
||||
|
||||
<p>Last revised: 8/3/2002</p>
|
||||
</body>
|
||||
</html>
|
||||
1251
doc/iterator.htm
Normal file
1251
doc/iterator.htm
Normal file
File diff suppressed because it is too large
Load Diff
1242
doc/matrix.htm
Normal file
1242
doc/matrix.htm
Normal file
File diff suppressed because it is too large
Load Diff
3002
doc/matrix_expression.htm
Normal file
3002
doc/matrix_expression.htm
Normal file
File diff suppressed because it is too large
Load Diff
2727
doc/matrix_proxy.htm
Normal file
2727
doc/matrix_proxy.htm
Normal file
File diff suppressed because it is too large
Load Diff
622
doc/matrix_sparse.htm
Normal file
622
doc/matrix_sparse.htm
Normal file
@@ -0,0 +1,622 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
|
||||
<title>Sparse Matrix</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<h1><img src="c++boost.gif" alt="c++boost.gif" align="center"
|
||||
width="277" height="86">Sparse Matrix</h1>
|
||||
|
||||
<h2><a name="sparse_matrix"></a>Sparse Matrix</h2>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>The templated class <code>sparse_matrix<T, F, A> </code>is
|
||||
the base container adaptor for sparse matrices. For a <em>(m x n</em>)-dimensional
|
||||
sparse matrix and <em>0 <= i < m</em>,<em> 0 <= j < n</em>
|
||||
every non-zero element <em>m</em><sub><em>i, j</em></sub> is
|
||||
mapped to the <em>(i x n + j)-</em>th element of the container
|
||||
for row major orientation or the <em>(i + j x m)-</em>th element
|
||||
of the container for column major orientation.</p>
|
||||
|
||||
<h4>Example</h4>
|
||||
|
||||
<pre>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;
|
||||
}</pre>
|
||||
|
||||
<h4>Definition</h4>
|
||||
|
||||
<p>Defined in the header matrix_sparse.hpp.</p>
|
||||
|
||||
<h4>Template parameters</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Parameter </th>
|
||||
<th>Description </th>
|
||||
<th>Default </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>T</code> </td>
|
||||
<td>The type of object stored in the sparse matrix. </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>F</code></td>
|
||||
<td>Functor describing the storage organization. <a href="#sparse_matrix_1">[1]</a></td>
|
||||
<td><code>row_major</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>A</code></td>
|
||||
<td>The type of the adapted array. <a href="#sparse_matrix_2">[2]</a></td>
|
||||
<td><code>map_array<std::size_t, T></code></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Model of</h4>
|
||||
|
||||
<p><a href="container.htm#matrix">Matrix</a>. </p>
|
||||
|
||||
<h4>Type requirements</h4>
|
||||
|
||||
<p>None, except for those imposed by the requirements of <a
|
||||
href="container.htm#matrix">Matrix</a>.</p>
|
||||
|
||||
<h4>Public base classes</h4>
|
||||
|
||||
<p><code>matrix_expression<sparse_matrix<T, F, A> ></code>
|
||||
</p>
|
||||
|
||||
<h4>Members</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Member </th>
|
||||
<th>Description </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>sparse_matrix ()</code> </td>
|
||||
<td>Allocates a <code>sparse_matrix </code>that holds at
|
||||
most zero rows of zero elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>sparse_matrix (size_type size1, size_type2,
|
||||
size_type non_zeros)</code></td>
|
||||
<td>Allocates a <code>sparse_matrix </code>that holds at
|
||||
most <code>size1 </code>rows of <code>size2 </code>elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>sparse_matrix (const sparse_matrix &m)</code></td>
|
||||
<td>The copy constructor.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
sparse_matrix (size_type non_zeros, const
|
||||
matrix_expression<AE> &ae)</code></td>
|
||||
<td>The extended copy constructor.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void resize (size_type size1, size_type size2,
|
||||
size_type non_zeros)</code></td>
|
||||
<td>Reallocates a <code>sparse_matrix </code>to hold at
|
||||
most <code>size1 </code>rows of <code>size2 </code>elements.
|
||||
The content of the <code>sparse_matrix </code>is
|
||||
preserved.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type size1 () const</code></td>
|
||||
<td>Returns the number of rows. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type size2 () const</code></td>
|
||||
<td>Returns the number of columns. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator () (size_type i,
|
||||
size_type j) const</code></td>
|
||||
<td>Returns the value of the <code>j</code>-th element in
|
||||
the<code> i</code>-th row. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reference operator () (size_type i, size_type
|
||||
j)</code></td>
|
||||
<td>Returns a reference of the <code>j</code>-th element
|
||||
in the<code> i</code>-th row. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>sparse_matrix &operator = (const
|
||||
sparse_matrix &m)</code></td>
|
||||
<td>The assignment operator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>sparse_matrix &assign_temporary
|
||||
(sparse_matrix &m)</code></td>
|
||||
<td>Assigns a temporary. May change the sparse matrix <code>m</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
sparse_matrix &operator = (const
|
||||
matrix_expression<AE> &ae)</code></td>
|
||||
<td>The extended assignment operator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
sparse_matrix &assign (const
|
||||
matrix_expression<AE> &ae)</code></td>
|
||||
<td>Assigns a matrix expression to the sparse matrix.
|
||||
Left and right hand side of the assignment should be
|
||||
independent.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
sparse_matrix &operator += (const
|
||||
matrix_expression<AE> &ae)</code></td>
|
||||
<td>A computed assignment operator. Adds the matrix
|
||||
expression to the sparse matrix.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
sparse_matrix &plus_assign (const
|
||||
matrix_expression<AE> &ae)</code></td>
|
||||
<td>Adds a matrix expression to the sparse matrix. Left
|
||||
and right hand side of the assignment should be
|
||||
independent.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
sparse_matrix &operator -= (const
|
||||
matrix_expression<AE> &ae)</code></td>
|
||||
<td>A computed assignment operator. Subtracts the matrix
|
||||
expression from the sparse matrix.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
sparse_matrix &minus_assign (const
|
||||
matrix_expression<AE> &ae)</code></td>
|
||||
<td>Subtracts a matrix expression from the sparse matrix.
|
||||
Left and right hand side of the assignment should be
|
||||
independent.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AT><br>
|
||||
sparse_matrix &operator *= (const AT &at)</code></td>
|
||||
<td>A computed assignment operator. Multiplies the sparse
|
||||
matrix with a scalar.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AT><br>
|
||||
sparse_matrix &operator /= (const AT &at)</code></td>
|
||||
<td>A computed assignment operator. Divides the sparse
|
||||
matrix through a scalar.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void swap (sparse_matrix &m)</code></td>
|
||||
<td>Swaps the contents of the sparse matrices. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void insert (size_type i, size_type j,
|
||||
const_reference t)</code></td>
|
||||
<td>Inserts the value <code>t</code> at the <code>j</code>-th
|
||||
element of the <code>i</code>-th row.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void erase (size_type i, size_type j)</code></td>
|
||||
<td>Erases the value at the <code>j</code>-th element of
|
||||
the <code>i</code>-th row.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void clear ()</code></td>
|
||||
<td>Clears the sparse matrix.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator1 begin1 () const</code></td>
|
||||
<td>Returns a <code>const_iterator1</code> pointing to
|
||||
the beginning of the <code>sparse_matrix</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator1 end1 () const</code></td>
|
||||
<td>Returns a <code>const_iterator1</code> pointing to
|
||||
the end of the <code>sparse_matrix</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator1 begin1 () </code></td>
|
||||
<td>Returns a <code>iterator1</code> pointing to the
|
||||
beginning of the <code>sparse_matrix</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator1 end1 () </code></td>
|
||||
<td>Returns a <code>iterator1</code> pointing to the end
|
||||
of the <code>sparse_matrix</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator2 begin2 () const</code></td>
|
||||
<td>Returns a <code>const_iterator2</code> pointing to
|
||||
the beginning of the <code>sparse_matrix</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator2 end2 () const</code></td>
|
||||
<td>Returns a <code>const_iterator2</code> pointing to
|
||||
the end of the <code>sparse_matrix</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator2 begin2 () </code></td>
|
||||
<td>Returns a <code>iterator2</code> pointing to the
|
||||
beginning of the <code>sparse_matrix</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator2 end2 () </code></td>
|
||||
<td>Returns a <code>iterator2</code> pointing to the end
|
||||
of the <code>sparse_matrix</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator1 rbegin1 () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator1</code>
|
||||
pointing to the beginning of the reversed <code>sparse_matrix</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator1 rend1 () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator1</code>
|
||||
pointing to the end of the reversed <code>sparse_matrix</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator1 rbegin1 () </code></td>
|
||||
<td>Returns a <code>reverse_iterator1</code> pointing to
|
||||
the beginning of the reversed <code>sparse_matrix</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator1 rend1 () </code></td>
|
||||
<td>Returns a <code>reverse_iterator1</code> pointing to
|
||||
the end of the reversed <code>sparse_matrix</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator2 rbegin2 () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator2</code>
|
||||
pointing to the beginning of the reversed <code>sparse_matrix</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator2 rend2 () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator2</code>
|
||||
pointing to the end of the reversed <code>sparse_matrix</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator2 rbegin2 () </code></td>
|
||||
<td>Returns a <code>reverse_iterator2</code> pointing to
|
||||
the beginning of the reversed <code>sparse_matrix</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator2 rend2 () </code></td>
|
||||
<td>Returns a <code>reverse_iterator2</code> pointing to
|
||||
the end of the reversed <code>sparse_matrix</code>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Notes</h4>
|
||||
|
||||
<p><a name="#sparse_matrix_1">[1]</a> Supported parameters for the storage organization are
|
||||
<code>row_major</code> and <code>column_major</code>.</p>
|
||||
|
||||
<p><a name="#sparse_matrix_2">[2]</a> Supported parameters for the adapted array are
|
||||
<code>map_array<std::size_t, T></code> and <code>std::map<std::size_t, T></code>.
|
||||
</p>
|
||||
|
||||
<h4>Interface</h4>
|
||||
|
||||
<pre><code> // 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 ();
|
||||
};</code></pre>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Copyright (©) 2000-2002 Joerg Walter, Mathias Koch <br>
|
||||
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.</p>
|
||||
|
||||
<p>Last revised: 8/3/2002</p>
|
||||
</body>
|
||||
</html>
|
||||
1534
doc/overview.htm
Normal file
1534
doc/overview.htm
Normal file
File diff suppressed because it is too large
Load Diff
20
doc/readme.txt
Normal file
20
doc/readme.txt
Normal file
@@ -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
|
||||
860
doc/storage.htm
Normal file
860
doc/storage.htm
Normal file
@@ -0,0 +1,860 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
|
||||
<title>Storage</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<h1><img src="c++boost.gif" alt="c++boost.gif" align="center">Storage</h1>
|
||||
|
||||
<h2><a name="unbounded_array"></a>Unbounded Array</h2>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>The templated class <code>unbounded_array<T> </code>implements
|
||||
a simple C-like array using allocation via <code>new/delete</code>.</p>
|
||||
|
||||
<h4>Example</h4>
|
||||
|
||||
<pre>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;
|
||||
}
|
||||
}</pre>
|
||||
|
||||
<h4>Definition</h4>
|
||||
|
||||
<p>Defined in the header storage.hpp.</p>
|
||||
|
||||
<h4>Template parameters</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Parameter </th>
|
||||
<th>Description </th>
|
||||
<th>Default </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>T</code> </td>
|
||||
<td>The type of object stored in the array. </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Model of</h4>
|
||||
|
||||
<p>Random Access Container. </p>
|
||||
|
||||
<h4>Type requirements</h4>
|
||||
|
||||
<p>None, except for those imposed by the requirements of Random
|
||||
Access Container. </p>
|
||||
|
||||
<h4>Public base classes</h4>
|
||||
|
||||
<p>None. </p>
|
||||
|
||||
<h4>Members</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Member </th>
|
||||
<th>Description </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>unbounded_array ()</code> </td>
|
||||
<td>Allocates an uninitialized <code>unbounded_array </code>that
|
||||
holds at most zero elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>unbounded_array (size_type size)</code></td>
|
||||
<td>Allocates an uninitialized <code>unbounded_array </code>that
|
||||
holds at most <code>size</code> elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>unbounded_array (const unbounded_array &a)</code></td>
|
||||
<td>The copy constructor.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>~unbounded_array ()</code></td>
|
||||
<td>Deallocates the <code>unbounded_array </code>itself. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void resize (size_type size)</code></td>
|
||||
<td>Reallocates an <code>unbounded_array </code>to hold
|
||||
at most <code>size</code> elements. The content of the <code>unbounded_array
|
||||
</code>is not preserved.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type size () const</code></td>
|
||||
<td>Returns the size of the <code>unbounded_array</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator [] (size_type i)
|
||||
const</code></td>
|
||||
<td>Returns a <code>const </code>reference of the <code>i</code>-th
|
||||
element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reference operator [] (size_type i)</code></td>
|
||||
<td>Returns a reference of the <code>i</code>-th element.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>unbounded_array &operator = (const
|
||||
unbounded_array &a)</code></td>
|
||||
<td>The assignment operator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>unbounded_array &assign_temporary
|
||||
(unbounded_array &a)</code></td>
|
||||
<td>Assigns a temporary. May change the array <code>a</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void swap (unbounded_array &a)</code></td>
|
||||
<td>Swaps the contents of the arrays. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>pointer insert (pointer it, const
|
||||
value_type &t)</code></td>
|
||||
<td>Inserts the value <code>t</code> at <code>it</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void erase (pointer it)</code></td>
|
||||
<td>Erases the value at <code>it</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void clear ()</code></td>
|
||||
<td>Clears the array. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator begin () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
beginning of the <code>unbounded_array</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator end () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
end of the <code>unbounded_array</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator begin () </code></td>
|
||||
<td>Returns a <code>iterator</code> pointing to the
|
||||
beginning of the <code>unbounded_array</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator end () </code></td>
|
||||
<td>Returns a <code>iterator</code> pointing to the end
|
||||
of the <code>unbounded_array</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rbegin () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the beginning of the reversed <code>unbounded_array</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rend () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the end of the reversed <code>unbounded_array</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator rbegin () </code></td>
|
||||
<td>Returns a <code>reverse_iterator</code> pointing to
|
||||
the beginning of the reversed <code>unbounded_array</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator rend () </code></td>
|
||||
<td>Returns a <code>reverse_iterator</code> pointing to
|
||||
the end of the reversed <code>unbounded_array</code>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Interface</h4>
|
||||
|
||||
<pre><code> // 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);</code></pre>
|
||||
|
||||
<h2><a name="bounded_array"></a>Bounded Array</h2>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>The templated class <code>bounded_array<T, N> </code>implements
|
||||
a simple C-like array.</p>
|
||||
|
||||
<h4>Example</h4>
|
||||
|
||||
<pre>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;
|
||||
}
|
||||
}</pre>
|
||||
|
||||
<h4>Definition</h4>
|
||||
|
||||
<p>Defined in the header storage.hpp.</p>
|
||||
|
||||
<h4>Template parameters</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Parameter </th>
|
||||
<th>Description </th>
|
||||
<th>Default </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>T</code> </td>
|
||||
<td>The type of object stored in the array. </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>N</code></td>
|
||||
<td>The allocation size of the array.</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Model of</h4>
|
||||
|
||||
<p>Random Access Container. </p>
|
||||
|
||||
<h4>Type requirements</h4>
|
||||
|
||||
<p>None, except for those imposed by the requirements of Random
|
||||
Access Container. </p>
|
||||
|
||||
<h4>Public base classes</h4>
|
||||
|
||||
<p>None. </p>
|
||||
|
||||
<h4>Members</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Member </th>
|
||||
<th>Description </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>bounded_array ()</code> </td>
|
||||
<td>Allocates an uninitialized <code>bounded_array </code>that
|
||||
holds at most zero elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>bounded_array (size_type size)</code></td>
|
||||
<td>Allocates an uninitialized <code>bounded_array </code>that
|
||||
holds at most <code>size</code> elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>bounded_array (const bounded_array &a)</code></td>
|
||||
<td>The copy constructor.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>~bounded_array ()</code></td>
|
||||
<td>Deallocates the <code>bounded_array </code>itself. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void resize (size_type size)</code></td>
|
||||
<td>Reallocates a <code>bounded_array </code>to hold at
|
||||
most <code>size</code> elements. The content of the <code>bounded_array
|
||||
</code>is preserved.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type size () const</code></td>
|
||||
<td>Returns the size of the <code>bounded_array</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator [] (size_type i)
|
||||
const</code></td>
|
||||
<td>Returns a <code>const </code>reference of the <code>i</code>-th
|
||||
element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reference operator [] (size_type i)</code></td>
|
||||
<td>Returns a reference of the <code>i</code>-th element.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>bounded_array &operator = (const
|
||||
bounded_array &a)</code></td>
|
||||
<td>The assignment operator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>bounded_array &assign_temporary
|
||||
(bounded_array &a)</code></td>
|
||||
<td>Assigns a temporary. May change the array <code>a</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void swap (bounded_array &a)</code></td>
|
||||
<td>Swaps the contents of the arrays. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>pointer insert (pointer it, const
|
||||
value_type &t)</code></td>
|
||||
<td>Inserts the value <code>t</code> at <code>it</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void erase (pointer it)</code></td>
|
||||
<td>Erases the value at <code>it</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void clear ()</code></td>
|
||||
<td>Clears the array. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator begin () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
beginning of the <code>bounded_array</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator end () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
end of the <code>bounded_array</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator begin () </code></td>
|
||||
<td>Returns a <code>iterator</code> pointing to the
|
||||
beginning of the <code>bounded_array</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator end () </code></td>
|
||||
<td>Returns a <code>iterator</code> pointing to the end
|
||||
of the <code>bounded_array</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rbegin () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the beginning of the reversed <code>bounded_array</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rend () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the end of the reversed <code>bounded_array</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator rbegin () </code></td>
|
||||
<td>Returns a <code>reverse_iterator</code> pointing to
|
||||
the beginning of the reversed <code>bounded_array</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator rend () </code></td>
|
||||
<td>Returns a <code>reverse_iterator</code> pointing to
|
||||
the end of the reversed <code>bounded_array</code>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Interface</h4>
|
||||
|
||||
<pre><code> // 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);</code></pre>
|
||||
|
||||
<h2><a name="range"></a>Range</h2>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>The class <code>range </code>implements base functionality
|
||||
needed to address ranges of vectors and matrices.</p>
|
||||
|
||||
<h4>Example</h4>
|
||||
|
||||
<pre>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;
|
||||
}
|
||||
}</pre>
|
||||
|
||||
<h4>Definition</h4>
|
||||
|
||||
<p>Defined in the header storage.hpp.</p>
|
||||
|
||||
<h4>Model of</h4>
|
||||
|
||||
<p>Reversible Container. </p>
|
||||
|
||||
<h4>Type requirements</h4>
|
||||
|
||||
<p>None, except for those imposed by the requirements of
|
||||
Reversible Container. </p>
|
||||
|
||||
<h4>Public base classes</h4>
|
||||
|
||||
<p>None. </p>
|
||||
|
||||
<h4>Members</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Member </th>
|
||||
<th>Description </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>range (size_type start, size_type stop)</code> </td>
|
||||
<td>Constructs a range from <code>start </code>to <code>stop</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type start () const</code></td>
|
||||
<td>Returns the beginning of the <code>range</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type size () const</code></td>
|
||||
<td>Returns the size of the <code>range</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator [] (size_type i) const</code></td>
|
||||
<td>Returns the value <code>start + i</code> of the <code>i</code>-th
|
||||
element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>range compose (const range &r) const</code></td>
|
||||
<td>Returns the composite range from <code>start +
|
||||
r.start ()</code> to <code>start + r.start () + r.size ()</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>bool operator == (const range &r) const</code></td>
|
||||
<td>Tests two ranges for equality.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>bool operator != (const range &r) const</code></td>
|
||||
<td>Tests two ranges for inequality.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator begin () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
beginning of the <code>range</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator end () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
end of the <code>range</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rbegin () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the beginning of the reversed <code>range</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rend () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the end of the reversed <code>range</code>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Interface</h4>
|
||||
|
||||
<pre><code> // 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;
|
||||
};</code></pre>
|
||||
|
||||
<h2><a name="slice"></a>Slice</h2>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>The class <code>slice </code>implements base functionality
|
||||
needed to address slices of vectors and matrices.</p>
|
||||
|
||||
<h4>Example</h4>
|
||||
|
||||
<pre>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;
|
||||
}
|
||||
}</pre>
|
||||
|
||||
<h4>Definition</h4>
|
||||
|
||||
<p>Defined in the header storage.hpp.</p>
|
||||
|
||||
<h4>Model of</h4>
|
||||
|
||||
<p>Reversible Container. </p>
|
||||
|
||||
<h4>Type requirements</h4>
|
||||
|
||||
<p>None, except for those imposed by the requirements of
|
||||
Reversible Container. </p>
|
||||
|
||||
<h4>Public base classes</h4>
|
||||
|
||||
<p>None. </p>
|
||||
|
||||
<h4>Members</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Member </th>
|
||||
<th>Description </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>slice (size_type start, size_type stride,
|
||||
size_type size)</code> </td>
|
||||
<td>Constructs a slice from <code>start </code>to <code>start
|
||||
+ size </code>with stride <code>stride</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type start () const</code></td>
|
||||
<td>Returns the beginning of the <code>slice</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type stride () const</code></td>
|
||||
<td>Returns the stride of the <code>slice</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type size () const</code></td>
|
||||
<td>Returns the size of the <code>slice</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator [] (size_type i) const</code></td>
|
||||
<td>Returns the value <code>start + i * stride</code> of
|
||||
the <code>i</code>-th element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>slice compose (const range &r) const</code></td>
|
||||
<td>Returns the composite slice from <code>start + stride
|
||||
* r.start ()</code> to <code>start + stride * (r.start ()
|
||||
+ r.size ()) </code>with stride <code>stride</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>slice compose (const slice &s) const</code></td>
|
||||
<td>Returns the composite slice from <code>start + stride
|
||||
* s.start ()</code> to <code>start + stride * s.stride ()
|
||||
* (s.start () + s.size ()) </code>with stride <code>stride
|
||||
* s.stride ()</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>bool operator == (const slice &s) const</code></td>
|
||||
<td>Tests two slices for equality.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>bool operator != (const slice &s) const</code></td>
|
||||
<td>Tests two slices for inequality.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator begin () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
beginning of the <code>slice</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator end () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
end of the <code>slice</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rbegin () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the beginning of the reversed <code>slice</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rend () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the end of the reversed <code>slice</code>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Interface</h4>
|
||||
|
||||
<pre><code> // 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;
|
||||
};</code></pre>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Copyright (©) 2000-2002 Joerg Walter, Mathias Koch <br>
|
||||
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.</p>
|
||||
|
||||
<p>Last revised: 8/3/2002</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
310
doc/storage_sparse.htm
Normal file
310
doc/storage_sparse.htm
Normal file
@@ -0,0 +1,310 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
|
||||
<title>Sparse Storage</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<h1><img src="c++boost.gif" alt="c++boost.gif" align="center">Sparse Storage</h1>
|
||||
|
||||
<h2><a name="map_array"></a>Map Array</h2>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>The templated class <code>map_array<I, T> </code>implements
|
||||
a simple std::map-like associative container as a sorted array.</p>
|
||||
|
||||
<h4>Example</h4>
|
||||
|
||||
<pre>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;
|
||||
}
|
||||
}</pre>
|
||||
|
||||
<h4>Definition</h4>
|
||||
|
||||
<p>Defined in the header storage_sparse.hpp.</p>
|
||||
|
||||
<h4>Template parameters</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Parameter </th>
|
||||
<th>Description </th>
|
||||
<th>Default </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>I</code></td>
|
||||
<td>The type of index stored in the array.</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>T</code> </td>
|
||||
<td>The type of object stored in the array. </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Model of</h4>
|
||||
|
||||
<p>Reversible Container. </p>
|
||||
|
||||
<h4>Type requirements</h4>
|
||||
|
||||
<p>None, except for those imposed by the requirements of
|
||||
Reversible Container.</p>
|
||||
|
||||
<h4>Public base classes</h4>
|
||||
|
||||
<p>None. </p>
|
||||
|
||||
<h4>Members</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Member </th>
|
||||
<th>Description </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>map_array ()</code> </td>
|
||||
<td>Allocates a <code>map_array </code>that holds
|
||||
at most zero elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>map_array (size_type size)</code></td>
|
||||
<td>Allocates a <code>map_array </code>that holds
|
||||
at most <code>size</code> elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>map_array (const map_array
|
||||
&a)</code></td>
|
||||
<td>The copy constructor.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>~map_array ()</code></td>
|
||||
<td>Deallocates the <code>map_array </code>itself.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void resize (size_type size)</code></td>
|
||||
<td>Reallocates a <code>map_array </code>to hold
|
||||
at most <code>size</code> elements. The content of the <code>map_array
|
||||
</code>is preserved.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type size () const</code></td>
|
||||
<td>Returns the size of the <code>map_array</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>data_reference operator [] (index_type i)</code></td>
|
||||
<td>Returns a reference of the element that is associated
|
||||
with a particular index. If the <code>map_array</code>
|
||||
does not already contain such an element, <code>operator[]</code>
|
||||
inserts the default<code> T ()</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>map_array &operator = (const
|
||||
map_array &a)</code></td>
|
||||
<td>The assignment operator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>map_array &assign_temporary
|
||||
(map_array &a)</code></td>
|
||||
<td>Assigns a temporary. May change the array <code>a</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void swap (map_array &a)</code></td>
|
||||
<td>Swaps the contents of the arrays. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>pointer insert (pointer it, const
|
||||
value_type &p)</code></td>
|
||||
<td>Inserts <code>p</code> into the array, using <code>it</code>
|
||||
as a hint to where it will be inserted. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void erase (pointer it)</code></td>
|
||||
<td>Erases the value at <code>it</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void clear ()</code></td>
|
||||
<td>Clears the array. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_pointer find (index_type i) const</code></td>
|
||||
<td>Finds an element whose index is <code>i</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>pointer find (index_type i)</code></td>
|
||||
<td>Finds an element whose index is <code>i</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_pointer lower_bound (index_type i)
|
||||
const</code></td>
|
||||
<td>Finds the first element whose index is not less than <code>i</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>pointer lower_bound (index_type i)</code></td>
|
||||
<td>Finds the first element whose index is not less than <code>i</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_pointer upper_bound (index_type i)
|
||||
const</code></td>
|
||||
<td>Finds the first element whose index is greater than <code>i</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>pointer upper_bound (index_type i)</code></td>
|
||||
<td>Finds the first element whose index is greater than <code>i</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator begin () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
beginning of the <code>map_array</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator end () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
end of the <code>map_array</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator begin () </code></td>
|
||||
<td>Returns a <code>iterator</code> pointing to the
|
||||
beginning of the <code>map_array</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator end () </code></td>
|
||||
<td>Returns a <code>iterator</code> pointing to the end
|
||||
of the <code>map_array</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rbegin () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the beginning of the reversed <code>map_array</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rend () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the end of the reversed <code>map_array</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator rbegin () </code></td>
|
||||
<td>Returns a <code>reverse_iterator</code> pointing to
|
||||
the beginning of the reversed <code>map_array</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator rend () </code></td>
|
||||
<td>Returns a <code>reverse_iterator</code> pointing to
|
||||
the end of the reversed <code>map_array</code>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Interface</h4>
|
||||
|
||||
<pre><code> // 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);</code></pre>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Copyright (©) 2000-2002 Joerg Walter, Mathias Koch <br>
|
||||
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.</p>
|
||||
|
||||
<p>Last revised: 8/3/2002</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
1209
doc/symmetric.htm
Normal file
1209
doc/symmetric.htm
Normal file
File diff suppressed because it is too large
Load Diff
1218
doc/triangular.htm
Normal file
1218
doc/triangular.htm
Normal file
File diff suppressed because it is too large
Load Diff
898
doc/vector.htm
Normal file
898
doc/vector.htm
Normal file
@@ -0,0 +1,898 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
|
||||
<title>Vector</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<h1><img src="c++boost.gif" alt="c++boost.gif" align="center"
|
||||
width="277" height="86">Vector</h1>
|
||||
|
||||
<h2><a name="vector"></a>Vector</h2>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>The templated class <code>vector<T, A> </code>is the
|
||||
base container adaptor for dense vectors. For a <em>n</em>-dimensional
|
||||
vector and <em>0 <= i < n </em>every element <em>v</em><sub><em>i</em></sub>
|
||||
is mapped to the <em>i-</em>th element of the container.</p>
|
||||
|
||||
<h4>Example</h4>
|
||||
|
||||
<pre>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;
|
||||
}</pre>
|
||||
|
||||
<h4>Definition</h4>
|
||||
|
||||
<p>Defined in the header vector.hpp.</p>
|
||||
|
||||
<h4>Template parameters</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Parameter </th>
|
||||
<th>Description </th>
|
||||
<th>Default </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>T</code> </td>
|
||||
<td>The type of object stored in the vector. </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>A</code></td>
|
||||
<td>The type of the adapted array.</td>
|
||||
<td><code>unbounded_array<T></code></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Model of</h4>
|
||||
|
||||
<p><a href="container.htm#vector">Vector</a>. </p>
|
||||
|
||||
<h4>Type requirements</h4>
|
||||
|
||||
<p>None, except for those imposed by the requirements of <a
|
||||
href="container.htm#vector">Vector</a>.</p>
|
||||
|
||||
<h4>Public base classes</h4>
|
||||
|
||||
<p><code>vector_expression<vector<T, A> ></code> </p>
|
||||
|
||||
<h4>Members</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Member </th>
|
||||
<th>Description </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>vector ()</code> </td>
|
||||
<td>Allocates an uninitialized <code>vector</code> that
|
||||
holds zero elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>vector (size_type size)</code></td>
|
||||
<td>Allocates an uninitialized <code>vector</code> that
|
||||
holds <code>size</code> elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>vector (const vector &v)</code></td>
|
||||
<td>The copy constructor.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector (const vector_expression<AE> &ae)</code></td>
|
||||
<td>The extended copy constructor.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void resize (size_type size)</code></td>
|
||||
<td>Reallocates a <code>vector</code> to hold <code>size</code>
|
||||
elements. The content of the <code>vector</code> is not
|
||||
preserved.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type size () const</code></td>
|
||||
<td>Returns the size of the <code>vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator () (size_type i) const</code></td>
|
||||
<td>Returns a <code>const </code>reference of the <code>i</code>-th
|
||||
element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reference operator () (size_type i)</code></td>
|
||||
<td>Returns a reference of the <code>i</code>-th element.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator [] (size_type i) const</code></td>
|
||||
<td>Returns a <code>const </code>reference of the <code>i</code>-th
|
||||
element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reference operator [] (size_type i)</code></td>
|
||||
<td>Returns a reference of the <code>i</code>-th element.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>vector &operator = (const vector &v)</code></td>
|
||||
<td>The assignment operator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>vector &assign_temporary (vector &v)</code></td>
|
||||
<td>Assigns a temporary. May change the vector <code>v</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector &operator = (const vector_expression<AE>
|
||||
&ae)</code></td>
|
||||
<td>The extended assignment operator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector &assign (const vector_expression<AE>
|
||||
&ae)</code></td>
|
||||
<td>Assigns a vector expression to the vector. Left and
|
||||
right hand side of the assignment should be independent.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector &operator += (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>A computed assignment operator. Adds the vector
|
||||
expression to the vector.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector &plus_assign (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>Adds a vector expression to the vector. Left and
|
||||
right hand side of the assignment should be independent.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector &operator -= (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>A computed assignment operator. Subtracts the vector
|
||||
expression from the vector.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector &minus_assign (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>Subtracts a vector expression from the vector. Left
|
||||
and right hand side of the assignment should be
|
||||
independent.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AT><br>
|
||||
vector &operator *= (const AT &at)</code></td>
|
||||
<td>A computed assignment operator. Multiplies the vector
|
||||
with a scalar.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AT><br>
|
||||
vector &operator /= (const AT &at)</code></td>
|
||||
<td>A computed assignment operator. Divides the vector
|
||||
through a scalar.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void swap (vector &v)</code></td>
|
||||
<td>Swaps the contents of the vectors. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void insert (size_type i, const_reference t)</code></td>
|
||||
<td>Inserts the value <code>t</code> at the <code>i</code>-th
|
||||
element.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void erase (size_type i)</code></td>
|
||||
<td>Erases the value at the <code>i</code>-th element.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void clear ()</code></td>
|
||||
<td>Clears the vector.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator begin () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
beginning of the <code>vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator end () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
end of the <code>vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator begin () </code></td>
|
||||
<td>Returns a <code>iterator</code> pointing to the
|
||||
beginning of the <code>vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator end () </code></td>
|
||||
<td>Returns a <code>iterator</code> pointing to the end
|
||||
of the <code>vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rbegin () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the beginning of the reversed <code>vector</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rend () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the end of the reversed <code>vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator rbegin () </code></td>
|
||||
<td>Returns a <code>reverse_iterator</code> pointing to
|
||||
the beginning of the reversed <code>vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator rend () </code></td>
|
||||
<td>Returns a <code>reverse_iterator</code> pointing to
|
||||
the end of the reversed <code>vector</code>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Interface</h4>
|
||||
|
||||
<pre><code> // 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 ();
|
||||
}; </code></pre>
|
||||
|
||||
<h2><a name="unit_vector"></a>Unit Vector</h2>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>The templated class <code>unit_vector<T> </code>represents
|
||||
canonical unit vectors. For the <em>k</em>-th <em>n</em>-dimensional
|
||||
canonical unit vector and <em>0 <= i < n </em>holds <em>u</em><sup><em>k</em></sup><sub><em>i</em></sub><em>
|
||||
= 0</em>, if <em>i <> k</em>, and <em>u</em><sup><em>k</em></sup><sub><em>i</em></sub><em>
|
||||
= 1</em>. </p>
|
||||
|
||||
<h4>Example</h4>
|
||||
|
||||
<pre>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;
|
||||
}
|
||||
}</pre>
|
||||
|
||||
<h4>Definition</h4>
|
||||
|
||||
<p>Defined in the header vector.hpp.</p>
|
||||
|
||||
<h4>Template parameters</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Parameter </th>
|
||||
<th>Description </th>
|
||||
<th>Default </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>T</code> </td>
|
||||
<td>The type of object stored in the vector. </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Model of</h4>
|
||||
|
||||
<p><a href="expression.htm#vector_expression">Vector Expression</a>.
|
||||
</p>
|
||||
|
||||
<h4>Type requirements</h4>
|
||||
|
||||
<p>None, except for those imposed by the requirements of <a
|
||||
href="expression.htm#vector_expression">Vector Expression</a>.</p>
|
||||
|
||||
<h4>Public base classes</h4>
|
||||
|
||||
<p><code>vector_expression<unit_vector<T> ></code> </p>
|
||||
|
||||
<h4>Members</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Member </th>
|
||||
<th>Description </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>unit_vector ()</code> </td>
|
||||
<td>Constructs an <code>unit_vector</code> that holds
|
||||
zero elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>unit_vector (size_type size, size_type index)</code></td>
|
||||
<td>Constructs the <code>index</code>-th <code>unit_vector</code>
|
||||
that holds <code>size</code> elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>unit_vector (const unit_vector &v)</code></td>
|
||||
<td>The copy constructor.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void resize (size_type size)</code></td>
|
||||
<td>Resizes a <code>unit_vector</code> to hold <code>size</code>
|
||||
elements. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type size () const</code></td>
|
||||
<td>Returns the size of the <code>unit_vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type index () const</code></td>
|
||||
<td>Returns the index of the <code>unit_vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator () (size_type i) const</code></td>
|
||||
<td>Returns the value of the <code>i</code>-th element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator [] (size_type i) const</code></td>
|
||||
<td>Returns the value of the <code>i</code>-th element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>unit_vector &operator = (const unit_vector
|
||||
&v)</code></td>
|
||||
<td>The assignment operator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>unit_vector &assign_temporary (unit_vector
|
||||
&v)</code></td>
|
||||
<td>Assigns a temporary. May change the unit vector <code>v</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void swap (unit_vector &v)</code></td>
|
||||
<td>Swaps the contents of the unit vectors. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator begin () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
beginning of the <code>unit_vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator end () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
end of the <code>unit_vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rbegin () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the beginning of the reversed <code>unit_vector</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rend () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the end of the reversed <code>unit_vector</code>.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Interface</h4>
|
||||
|
||||
<pre><code> // 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;
|
||||
};</code></pre>
|
||||
|
||||
<h2><a name="zero_vector"></a>Zero Vector</h2>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>The templated class <code>zero_vector<T> </code>represents
|
||||
zero vectors. For a <em>n</em>-dimensional zero vector and <em>0
|
||||
<= i < n </em>holds <em>z</em><sub><em>i</em></sub><em> = 0</em>.
|
||||
</p>
|
||||
|
||||
<h4>Example</h4>
|
||||
|
||||
<pre>int main () {
|
||||
using namespace boost::numeric::ublas;
|
||||
zero_vector<double> v (3);
|
||||
std::cout << v << std::endl;
|
||||
}</pre>
|
||||
|
||||
<h4>Definition</h4>
|
||||
|
||||
<p>Defined in the header vector.hpp.</p>
|
||||
|
||||
<h4>Template parameters</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Parameter </th>
|
||||
<th>Description </th>
|
||||
<th>Default </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>T</code> </td>
|
||||
<td>The type of object stored in the vector. </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Model of</h4>
|
||||
|
||||
<p><a href="expression.htm#vector_expression">Vector Expression</a>.
|
||||
</p>
|
||||
|
||||
<h4>Type requirements</h4>
|
||||
|
||||
<p>None, except for those imposed by the requirements of <a
|
||||
href="expression.htm#vector_expression">Vector Expression</a>.</p>
|
||||
|
||||
<h4>Public base classes</h4>
|
||||
|
||||
<p><code>vector_expression<zero_vector<T> ></code> </p>
|
||||
|
||||
<h4>Members</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Member </th>
|
||||
<th>Description </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>zero_vector ()</code> </td>
|
||||
<td>Constructs a <code>zero_vector</code> that holds zero
|
||||
elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>zero_vector (size_type size)</code></td>
|
||||
<td>Constructs a <code>zero_vector</code> that holds <code>size</code>
|
||||
elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>zero_vector (const zero_vector &v)</code></td>
|
||||
<td>The copy constructor.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void resize (size_type size)</code></td>
|
||||
<td>Resizes a <code>zero_vector</code> to hold <code>size</code>
|
||||
elements. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type size () const</code></td>
|
||||
<td>Returns the size of the <code>zero_vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator () (size_type i) const</code></td>
|
||||
<td>Returns the value of the <code>i</code>-th element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator [] (size_type i) const</code></td>
|
||||
<td>Returns the value of the <code>i</code>-th element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>zero_vector &operator = (const zero_vector
|
||||
&v)</code></td>
|
||||
<td>The assignment operator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>zero_vector &assign_temporary (zero_vector
|
||||
&v)</code></td>
|
||||
<td>Assigns a temporary. May change the zero vector <code>v</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void swap (zero_vector &v)</code></td>
|
||||
<td>Swaps the contents of the zero vectors. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator begin () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
beginning of the <code>zero_vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator end () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
end of the <code>zero_vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rbegin () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the beginning of the reversed <code>zero_vector</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rend () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the end of the reversed <code>zero_vector</code>.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Interface</h4>
|
||||
|
||||
<pre><code> // 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;
|
||||
};</code></pre>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Copyright (©) 2000-2002 Joerg Walter, Mathias Koch <br>
|
||||
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.</p>
|
||||
|
||||
<p>Last revised: 8/3/2002</p>
|
||||
</body>
|
||||
</html>
|
||||
1760
doc/vector_expression.htm
Normal file
1760
doc/vector_expression.htm
Normal file
File diff suppressed because it is too large
Load Diff
861
doc/vector_proxy.htm
Normal file
861
doc/vector_proxy.htm
Normal file
@@ -0,0 +1,861 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
|
||||
<title>Vector Proxies</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<h1><img src="c++boost.gif" alt="c++boost.gif" align="center"
|
||||
width="277" height="86">Vector Proxies</h1>
|
||||
|
||||
<h2><a name="vector_range"></a>Vector Range</h2>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>The templated class <code>vector_range<V> </code>allows
|
||||
addressing a range of a vector.</p>
|
||||
|
||||
<h4>Example</h4>
|
||||
|
||||
<pre>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;
|
||||
}</pre>
|
||||
|
||||
<h4>Definition</h4>
|
||||
|
||||
<p>Defined in the header vector_proxy.hpp.</p>
|
||||
|
||||
<h4>Template parameters</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Parameter </th>
|
||||
<th>Description </th>
|
||||
<th>Default </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>V</code> </td>
|
||||
<td>The type of vector referenced. </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Model of</h4>
|
||||
|
||||
<p><a href="expression.htm#vector_expressio">Vector Expression</a>.
|
||||
</p>
|
||||
|
||||
<h4>Type requirements</h4>
|
||||
|
||||
<p>None, except for those imposed by the requirements of <a
|
||||
href="expression.htm#vector_expression">Vector Expression</a>.</p>
|
||||
|
||||
<h4>Public base classes</h4>
|
||||
|
||||
<p><code>vector_expression<vector_range<V> ></code> </p>
|
||||
|
||||
<h4>Members</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Member </th>
|
||||
<th>Description </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>vector_range (vector_type &data, const
|
||||
range &r)</code></td>
|
||||
<td>Constructs a sub vector.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type start () const</code></td>
|
||||
<td>Returns the start of the sub vector.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type size () const</code></td>
|
||||
<td>Returns the size of the sub vector.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator () (size_type i) const</code></td>
|
||||
<td>Returns the value of the <code>i</code>-th element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reference operator () (size_type i)</code></td>
|
||||
<td>Returns a reference of the <code>i</code>-th element.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator [] (size_type i) const</code></td>
|
||||
<td>Returns the value of the <code>i</code>-th element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reference operator [] (size_type i)</code></td>
|
||||
<td>Returns a reference of the <code>i</code>-th element.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>vector_range &operator = (const
|
||||
vector_range &vr)</code></td>
|
||||
<td>The assignment operator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>vector_range &assign_temporary
|
||||
(vector_range &vr)</code></td>
|
||||
<td>Assigns a temporary. May change the vector range <code>vr</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector_range &operator = (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>The extended assignment operator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector_range &assign (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>Assigns a vector expression to the sub vector. Left
|
||||
and right hand side of the assignment should be
|
||||
independent.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector_range &operator += (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>A computed assignment operator. Adds the vector
|
||||
expression to the sub vector.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector_range &plus_assign (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>Adds a vector expression to the sub vector. Left and
|
||||
right hand side of the assignment should be independent.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector_range &operator -= (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>A computed assignment operator. Subtracts the vector
|
||||
expression from the sub vector.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector_range &minus_assign (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>Subtracts a vector expression from the sub vector.
|
||||
Left and right hand side of the assignment should be
|
||||
independent.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AT><br>
|
||||
vector_range &operator *= (const AT &at)</code></td>
|
||||
<td>A computed assignment operator. Multiplies the sub
|
||||
vector with a scalar.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AT><br>
|
||||
vector_range &operator /= (const AT &at)</code></td>
|
||||
<td>A computed assignment operator. Divides the sub
|
||||
vector through a scalar.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void swap (vector_range &vr)</code></td>
|
||||
<td>Swaps the contents of the sub vectors. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator begin () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
beginning of the <code>vector_range</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator end () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
end of the <code>vector_range</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator begin () </code></td>
|
||||
<td>Returns a <code>iterator</code> pointing to the
|
||||
beginning of the <code>vector_range</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator end () </code></td>
|
||||
<td>Returns a <code>iterator</code> pointing to the end
|
||||
of the <code>vector_range</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rbegin () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the beginning of the reversed <code>vector_range</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rend () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the end of the reversed <code>vector_range</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator rbegin () </code></td>
|
||||
<td>Returns a <code>reverse_iterator</code> pointing to
|
||||
the beginning of the reversed <code>vector_range</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator rend () </code></td>
|
||||
<td>Returns a <code>reverse_iterator</code> pointing to
|
||||
the end of the reversed <code>vector_range</code>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Interface</h4>
|
||||
|
||||
<pre><code> // 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 ();
|
||||
};</code></pre>
|
||||
|
||||
<h3>Projections</h3>
|
||||
|
||||
<h4>Prototypes</h4>
|
||||
|
||||
<pre><code> 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);</code></pre>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>The free <code>project</code> functions support the
|
||||
construction of vector ranges.</p>
|
||||
|
||||
<h4>Definition</h4>
|
||||
|
||||
<p>Defined in the header vector_proxy.hpp.</p>
|
||||
|
||||
<h4>Type requirements</h4>
|
||||
|
||||
<dir>
|
||||
<li><code>V</code> is a model of <a
|
||||
href="expression.htm#vector_expression">Vector Expression</a>.</li>
|
||||
</dir>
|
||||
|
||||
<h4>Preconditions</h4>
|
||||
|
||||
<dir>
|
||||
<li><code>r.start () + r.size () <= data.size ()</code></li>
|
||||
</dir>
|
||||
|
||||
<h4>Complexity</h4>
|
||||
|
||||
<p>Linear depending from the size of the range.</p>
|
||||
|
||||
<h4>Examples</h4>
|
||||
|
||||
<pre>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;
|
||||
}</pre>
|
||||
|
||||
<h2><a name="vector_slice"></a>Vector Slice</h2>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>The templated class <code>vector_slice<V> </code>allows
|
||||
addressing a slice of a vector.</p>
|
||||
|
||||
<h4>Example</h4>
|
||||
|
||||
<pre>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;
|
||||
}</pre>
|
||||
|
||||
<h4>Definition</h4>
|
||||
|
||||
<p>Defined in the header vector_proxy.hpp.</p>
|
||||
|
||||
<h4>Template parameters</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Parameter </th>
|
||||
<th>Description </th>
|
||||
<th>Default </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>V</code> </td>
|
||||
<td>The type of vector referenced. </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Model of</h4>
|
||||
|
||||
<p><a href="expression.htm#vector_expression">Vector Expression</a>.
|
||||
</p>
|
||||
|
||||
<h4>Type requirements</h4>
|
||||
|
||||
<p>None, except for those imposed by the requirements of <a
|
||||
href="expression.htm#vector_expression">Vector Expression</a>.</p>
|
||||
|
||||
<h4>Public base classes</h4>
|
||||
|
||||
<p><code>vector_expression<vector_slice<V> ></code> </p>
|
||||
|
||||
<h4>Members</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Member </th>
|
||||
<th>Description </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>vector_slice (vector_type &data, const
|
||||
slice &s)</code></td>
|
||||
<td>Constructs a sub vector.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type size () const</code></td>
|
||||
<td>Returns the size of the sub vector.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator () (size_type i) const</code></td>
|
||||
<td>Returns the value of the <code>i</code>-th element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reference operator () (size_type i)</code></td>
|
||||
<td>Returns a reference of the <code>i</code>-th element.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator [] (size_type i) const</code></td>
|
||||
<td>Returns the value of the <code>i</code>-th element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reference operator [] (size_type i)</code></td>
|
||||
<td>Returns a reference of the <code>i</code>-th element.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>vector_slice &operator = (const
|
||||
vector_slice &vs)</code></td>
|
||||
<td>The assignment operator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>vector_slice &assign_temporary
|
||||
(vector_slice &vs)</code></td>
|
||||
<td>Assigns a temporary. May change the vector slice <code>vs</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector_slice &operator = (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>The extended assignment operator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector_slice &assign (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>Assigns a vector expression to the sub vector. Left
|
||||
and right hand side of the assignment should be
|
||||
independent.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector_slice &operator += (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>A computed assignment operator. Adds the vector
|
||||
expression to the sub vector.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector_slice &plus_assign (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>Adds a vector expression to the sub vector. Left and
|
||||
right hand side of the assignment should be independent.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector_slice &operator -= (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>A computed assignment operator. Subtracts the vector
|
||||
expression from the sub vector.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
vector_slice &minus_assign (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>Subtracts a vector expression from the sub vector.
|
||||
Left and right hand side of the assignment should be
|
||||
independent.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AT><br>
|
||||
vector_slice &operator *= (const AT &at)</code></td>
|
||||
<td>A computed assignment operator. Multiplies the sub
|
||||
vector with a scalar.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AT><br>
|
||||
vector_slice &operator /= (const AT &at)</code></td>
|
||||
<td>A computed assignment operator. Divides the sub
|
||||
vector through a scalar.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void swap (vector_slice &vs)</code></td>
|
||||
<td>Swaps the contents of the sub vectors. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator begin () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
beginning of the <code>vector_slice</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator end () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
end of the <code>vector_slice</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator begin () </code></td>
|
||||
<td>Returns a <code>iterator</code> pointing to the
|
||||
beginning of the <code>vector_slice</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator end () </code></td>
|
||||
<td>Returns a <code>iterator</code> pointing to the end
|
||||
of the <code>vector_slice</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rbegin () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the beginning of the reversed <code>vector_slice</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rend () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the end of the reversed <code>vector_slice</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator rbegin () </code></td>
|
||||
<td>Returns a <code>reverse_iterator</code> pointing to
|
||||
the beginning of the reversed <code>vector_slice</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator rend () </code></td>
|
||||
<td>Returns a <code>reverse_iterator</code> pointing to
|
||||
the end of the reversed <code>vector_slice</code>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Interface</h4>
|
||||
|
||||
<pre><code> // 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 ();
|
||||
};</code></pre>
|
||||
|
||||
<h3>Projections</h3>
|
||||
|
||||
<h4>Prototypes</h4>
|
||||
|
||||
<pre><code> 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);</code></pre>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>The free <code>project</code> functions support the
|
||||
construction of vector slices.</p>
|
||||
|
||||
<h4>Definition</h4>
|
||||
|
||||
<p>Defined in the header vector_proxy.hpp.</p>
|
||||
|
||||
<h4>Type requirements</h4>
|
||||
|
||||
<dir>
|
||||
<li><code>V</code> is a model of <a
|
||||
href="expression.htm#vector_expression">Vector Expression</a>.</li>
|
||||
</dir>
|
||||
|
||||
<h4>Preconditions</h4>
|
||||
|
||||
<ul type="disc">
|
||||
<li><code>s.start () + s.stride () * s.size () <=
|
||||
data.size ()</code></li>
|
||||
</ul>
|
||||
|
||||
<h4>Complexity</h4>
|
||||
|
||||
<p>Linear depending from the size of the slice.</p>
|
||||
|
||||
<h4>Examples</h4>
|
||||
|
||||
<pre>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;
|
||||
}</pre>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Copyright (©) 2000-2002 Joerg Walter, Mathias Koch <br>
|
||||
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.</p>
|
||||
|
||||
<p>Last revised: 8/3/2002</p>
|
||||
</body>
|
||||
</html>
|
||||
448
doc/vector_sparse.htm
Normal file
448
doc/vector_sparse.htm
Normal file
@@ -0,0 +1,448 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
|
||||
<title>Sparse Vector</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<h1><img src="c++boost.gif" alt="c++boost.gif" align="center"
|
||||
width="277" height="86">Sparse Vector</h1>
|
||||
|
||||
<h2><a name="sparse_vector"></a>Sparse Vector</h2>
|
||||
|
||||
<h4>Description</h4>
|
||||
|
||||
<p>The templated class <code>sparse_vector<T, A> </code>is
|
||||
the base container adaptor for sparse vectors. For a <em>n</em>-dimensional
|
||||
sparse vector and <em>0 <= i < n </em>every non-zero
|
||||
element <em>v</em><sub><em>i</em></sub> is mapped to the <em>i-</em>th
|
||||
element of the container.</p>
|
||||
|
||||
<h4>Example</h4>
|
||||
|
||||
<pre>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;
|
||||
}</pre>
|
||||
|
||||
<h4>Definition</h4>
|
||||
|
||||
<p>Defined in the header vector_sparse.hpp.</p>
|
||||
|
||||
<h4>Template parameters</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Parameter </th>
|
||||
<th>Description </th>
|
||||
<th>Default </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>T</code> </td>
|
||||
<td>The type of object stored in the sparse vector. </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>F</code></td>
|
||||
<td>Functor describing the storage organization.</td>
|
||||
<td><code>forward</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>A</code></td>
|
||||
<td>The type of the adapted array.</td>
|
||||
<td><code>map_array<std::size_t, T></code></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Model of</h4>
|
||||
|
||||
<p><a href="container.htm#vector">Vector</a>. </p>
|
||||
|
||||
<h4>Type requirements</h4>
|
||||
|
||||
<p>None, except for those imposed by the requirements of <a
|
||||
href="container.htm#vector">Vector</a>.</p>
|
||||
|
||||
<h4>Public base classes</h4>
|
||||
|
||||
<p><code>vector_expression<sparse_vector<T, A> ></code>
|
||||
</p>
|
||||
|
||||
<h4>Members</h4>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Member </th>
|
||||
<th>Description </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>sparse_vector ()</code> </td>
|
||||
<td>Allocates a <code>sparse_vector </code>that holds
|
||||
zero elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>sparse_vector (size_type size, size_type
|
||||
non_zeros)</code></td>
|
||||
<td>Allocates a <code>sparse_vector </code>that holds at
|
||||
most <code>size</code> elements.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>sparse_vector (const sparse_vector &v)</code></td>
|
||||
<td>The copy constructor.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
sparse_vector (size_type non_zeros, const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>The extended copy constructor.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void resize (size_type size, size_type
|
||||
non_zeros)</code></td>
|
||||
<td>Reallocates a <code>sparse_vector </code>to hold at
|
||||
most <code>size</code> elements. The content of the <code>sparse_vector
|
||||
</code>is preserved.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>size_type size () const</code></td>
|
||||
<td>Returns the size of the <code>sparse_vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator () (size_type i) const</code></td>
|
||||
<td>Returns the value of the <code>i</code>-th element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reference operator () (size_type i)</code></td>
|
||||
<td>Returns a reference of the <code>i</code>-th element.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reference operator [] (size_type i) const</code></td>
|
||||
<td>Returns the value of the <code>i</code>-th element. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reference operator [] (size_type i)</code></td>
|
||||
<td>Returns a reference of the <code>i</code>-th element.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>sparse_vector &operator = (const
|
||||
sparse_vector &v)</code></td>
|
||||
<td>The assignment operator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>sparse_vector &assign_temporary
|
||||
(sparse_vector &v)</code></td>
|
||||
<td>Assigns a temporary. May change the sparse vector <code>v</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
sparse_vector &operator = (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>The extended assignment operator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
sparse_vector &assign (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>Assigns a vector expression to the sparse vector.
|
||||
Left and right hand side of the assignment should be
|
||||
independent.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
sparse_vector &operator += (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>A computed assignment operator. Adds the vector
|
||||
expression to the sparse vector.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
sparse_vector &plus_assign (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>Adds a vector expression to the sparse vector. Left
|
||||
and right hand side of the assignment should be
|
||||
independent.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
sparse_vector &operator -= (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>A computed assignment operator. Subtracts the vector
|
||||
expression from the sparse vector.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AE><br>
|
||||
sparse_vector &minus_assign (const
|
||||
vector_expression<AE> &ae)</code></td>
|
||||
<td>Subtracts a vector expression from the sparse vector.
|
||||
Left and right hand side of the assignment should be
|
||||
independent.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AT><br>
|
||||
sparse_vector &operator *= (const AT &at)</code></td>
|
||||
<td>A computed assignment operator. Multiplies the sparse
|
||||
vector with a scalar.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>template<class AT><br>
|
||||
sparse_vector &operator /= (const AT &at)</code></td>
|
||||
<td>A computed assignment operator. Divides the sparse
|
||||
vector through a scalar.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void swap (sparse_vector &v)</code></td>
|
||||
<td>Swaps the contents of the sparse vectors. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void insert (size_type i, const_reference t)</code></td>
|
||||
<td>Inserts the value <code>t</code> at the <code>i</code>-th
|
||||
element.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void erase (size_type i)</code></td>
|
||||
<td>Erases the value at the <code>i</code>-th element.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>void clear ()</code></td>
|
||||
<td>Clears the sparse vector.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator begin () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
beginning of the <code>sparse_vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_iterator end () const</code></td>
|
||||
<td>Returns a <code>const_iterator</code> pointing to the
|
||||
end of the <code>sparse_vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator begin () </code></td>
|
||||
<td>Returns a <code>iterator</code> pointing to the
|
||||
beginning of the <code>sparse_vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>iterator end () </code></td>
|
||||
<td>Returns a <code>iterator</code> pointing to the end
|
||||
of the <code>sparse_vector</code>. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rbegin () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the beginning of the reversed <code>sparse_vector</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>const_reverse_iterator rend () const</code></td>
|
||||
<td>Returns a <code>const_reverse_iterator</code>
|
||||
pointing to the end of the reversed <code>sparse_vector</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator rbegin () </code></td>
|
||||
<td>Returns a <code>reverse_iterator</code> pointing to
|
||||
the beginning of the reversed <code>sparse_vector</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>reverse_iterator rend () </code></td>
|
||||
<td>Returns a <code>reverse_iterator</code> pointing to
|
||||
the end of the reversed <code>sparse_vector</code>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Interface</h4>
|
||||
|
||||
<pre><code> // 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 ();
|
||||
};</code></pre>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Copyright (©) 2000-2002 Joerg Walter, Mathias Koch <br>
|
||||
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.</p>
|
||||
|
||||
<p>Last revised: 8/3/2002</p>
|
||||
</body>
|
||||
</html>
|
||||
13
test1/Jamfile
Normal file
13
test1/Jamfile
Normal file
@@ -0,0 +1,13 @@
|
||||
subproject libs/numeric/ublas/test1 ;
|
||||
|
||||
SOURCES = test1 test11 test12 test13 ;
|
||||
|
||||
exe test1
|
||||
: $(SOURCES).cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
<borland><*><cxxflags>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092"
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
36
test1/test1.cpp
Normal file
36
test1/test1.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test1.hpp"
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
// Standard new handler is not standard compliant.
|
||||
#include <new.h>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
221
test1/test1.dsp
Normal file
221
test1/test1.dsp
Normal file
@@ -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
|
||||
40
test1/test1.hpp
Normal file
40
test1/test1.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef TEST1_H
|
||||
#define TEST1_H
|
||||
|
||||
namespace ublas = boost::numeric::ublas;
|
||||
|
||||
template<class V>
|
||||
void initialize_vector (V &v) {
|
||||
int size = v.size ();
|
||||
for (int i = 0; i < size; ++ i)
|
||||
v [i] = i + 1.f;
|
||||
}
|
||||
|
||||
template<class M>
|
||||
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
|
||||
|
||||
|
||||
207
test1/test11.cpp
Normal file
207
test1/test11.cpp
Normal file
@@ -0,0 +1,207 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test1.hpp"
|
||||
|
||||
// Test vector expression templates
|
||||
template<class V, int N>
|
||||
struct test_my_vector {
|
||||
typedef typename V::value_type value_type;
|
||||
typedef typename V::size_type size_type;
|
||||
typedef typename ublas::type_traits<value_type>::real_type real_type;
|
||||
|
||||
template<class VP>
|
||||
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<V> 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<V> 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<V> 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<V> 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<ublas::vector<float, ublas::bounded_array<float, 3> >, 3 > () ();
|
||||
|
||||
std::cout << "double, bounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, bounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, bounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
std::cout << "float, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<float, ublas::unbounded_array<float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<double, ublas::unbounded_array<double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
std::cout << "float, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<float, std::vector<float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<double, std::vector<double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, 3 > () ();
|
||||
#endif
|
||||
}
|
||||
|
||||
216
test1/test12.cpp
Normal file
216
test1/test12.cpp
Normal file
@@ -0,0 +1,216 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test1.hpp"
|
||||
|
||||
// Test matrix & vector expression templates
|
||||
template<class V, class M, int N>
|
||||
struct test_my_matrix_vector {
|
||||
typedef typename V::value_type value_type;
|
||||
|
||||
template<class VP, class MP>
|
||||
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<M> mr1 (m1, 0), mr2 (m1, 1);
|
||||
(*this) (mr1, mr2, m1);
|
||||
|
||||
ublas::matrix_column<M> 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<M> 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<M> 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<M> 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<M> 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::vector<float, ublas::bounded_array<float, 3> >,
|
||||
ublas::matrix<float, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () ();
|
||||
|
||||
std::cout << "double, bounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
|
||||
ublas::matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () ();
|
||||
|
||||
std::cout << "std::complex<float>, bounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >,
|
||||
ublas::matrix<std::complex<float>, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () ();
|
||||
|
||||
std::cout << "std::complex<double>, bounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
|
||||
ublas::matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
std::cout << "float, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >,
|
||||
ublas::matrix<float, ublas::row_major, ublas::unbounded_array<float> >, 3> () ();
|
||||
|
||||
std::cout << "double, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
|
||||
ublas::matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3> () ();
|
||||
|
||||
std::cout << "std::complex<float>, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >,
|
||||
ublas::matrix<std::complex<float>, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () ();
|
||||
|
||||
std::cout << "std::complex<double>, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
|
||||
ublas::matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
std::cout << "float, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<float, std::vector<float> >,
|
||||
ublas::matrix<float, ublas::row_major, std::vector<float> >, 3> () ();
|
||||
|
||||
std::cout << "double, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
|
||||
ublas::matrix<double, ublas::row_major, std::vector<double> >, 3> () ();
|
||||
|
||||
std::cout << "std::complex<float>, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >,
|
||||
ublas::matrix<std::complex<float>, ublas::row_major, std::vector<std::complex<float> > >, 3> () ();
|
||||
|
||||
std::cout << "std::complex<double>, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
|
||||
ublas::matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 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<float, ublas::bounded_array<float, 3> >,
|
||||
ublas::vector_of_vector<float, ublas::row_major, ublas::bounded_array<ublas::bounded_array<float, 3>, 3 + 1> >, 3> () ();
|
||||
|
||||
std::cout << "double, bounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
|
||||
ublas::vector_of_vector<double, ublas::row_major, ublas::bounded_array<ublas::bounded_array<double, 3>, 3 + 1> >, 3> () ();
|
||||
|
||||
std::cout << "std::complex<float>, bounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >,
|
||||
ublas::vector_of_vector<std::complex<float>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<std::complex<float>, 3>, 3 + 1> >, 3> () ();
|
||||
|
||||
std::cout << "std::complex<double>, bounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
|
||||
ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<std::complex<double>, 3>, 3 + 1> >, 3> () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
std::cout << "float, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >,
|
||||
ublas::vector_of_vector<float, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<float> > >, 3> () ();
|
||||
|
||||
std::cout << "double, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
|
||||
ublas::vector_of_vector<double, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<double> > >, 3> () ();
|
||||
|
||||
std::cout << "std::complex<float>, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >,
|
||||
ublas::vector_of_vector<std::complex<float>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<float> > > >, 3> () ();
|
||||
|
||||
std::cout << "std::complex<double>, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
|
||||
ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<double> > > >, 3> () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
std::cout << "float, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<float, std::vector<float> >,
|
||||
ublas::vector_of_vector<float, ublas::row_major, std::vector<std::vector<float> > >, 3> () ();
|
||||
|
||||
std::cout << "double, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
|
||||
ublas::vector_of_vector<double, ublas::row_major, std::vector<std::vector<double> > >, 3> () ();
|
||||
|
||||
std::cout << "std::complex<float>, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >,
|
||||
ublas::vector_of_vector<std::complex<float>, ublas::row_major, std::vector<std::vector<std::complex<float> > > >, 3> () ();
|
||||
|
||||
std::cout << "std::complex<double>, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
|
||||
ublas::vector_of_vector<std::complex<double>, ublas::row_major, std::vector<std::vector<std::complex<double> > > >, 3> () ();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
246
test1/test13.cpp
Normal file
246
test1/test13.cpp
Normal file
@@ -0,0 +1,246 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test1.hpp"
|
||||
|
||||
// Test matrix expression templates
|
||||
template<class M, int N>
|
||||
struct test_my_matrix {
|
||||
typedef typename M::value_type value_type;
|
||||
|
||||
template<class MP>
|
||||
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<M> 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<M> 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<M> 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<M> 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<ublas::matrix<float, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3 > () ();
|
||||
|
||||
std::cout << "double, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::matrix<std::complex<float>, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
std::cout << "float, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::matrix<float, ublas::row_major, ublas::unbounded_array<float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::matrix<std::complex<float>, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
std::cout << "float, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::matrix<float, ublas::row_major, std::vector<float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::matrix<double, ublas::row_major, std::vector<double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::matrix<std::complex<float>, ublas::row_major, std::vector<std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3 > () ();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_VECTOR_OF_VECTOR
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
std::cout << "float, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::vector_of_vector<float, ublas::row_major, ublas::bounded_array<ublas::bounded_array<float, 3>, 3 + 1> >, 3 > () ();
|
||||
|
||||
std::cout << "double, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::vector_of_vector<double, ublas::row_major, ublas::bounded_array<ublas::bounded_array<double, 3>, 3 + 1> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::vector_of_vector<std::complex<float>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<std::complex<float>, 3>, 3 + 1> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<std::complex<double>, 3>, 3 + 1> >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
std::cout << "float, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::vector_of_vector<float, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "double, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::vector_of_vector<double, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<double> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::vector_of_vector<std::complex<float>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<float> > > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<double> > > >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
std::cout << "float, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::vector_of_vector<float, ublas::row_major, std::vector<std::vector<float > > >, 3 > () ();
|
||||
|
||||
std::cout << "double, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::vector_of_vector<double, ublas::row_major, std::vector<std::vector<double> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::vector_of_vector<std::complex<float>, ublas::row_major, std::vector<std::vector<std::complex<float> > > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::vector_of_vector<std::complex<double>, ublas::row_major, std::vector<std::vector<std::complex<double> > > >, 3 > () ();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
10
test2/Jamfile
Normal file
10
test2/Jamfile
Normal file
@@ -0,0 +1,10 @@
|
||||
subproject libs/numeric/ublas/test2 ;
|
||||
|
||||
SOURCES = test2 test21 test22 test23 ;
|
||||
|
||||
exe test2
|
||||
: $(SOURCES).cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
<borland><*><cxxflags>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092"
|
||||
;
|
||||
|
||||
81
test2/test2.cpp
Normal file
81
test2/test2.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/triangular.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include <boost/numeric/ublas/blas.hpp>
|
||||
|
||||
#include "test2.hpp"
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
// Standard new handler is not standard compliant.
|
||||
#include <new.h>
|
||||
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<ublas::vector<float>, 3> () ();
|
||||
|
||||
std::cout << "double" << std::endl;
|
||||
test_blas_1<ublas::vector<double>, 3> () ();
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
std::cout << "std::complex<float>" << std::endl;
|
||||
test_blas_1<ublas::vector<std::complex<float> >, 3> () ();
|
||||
|
||||
std::cout << "std::complex<double>" << std::endl;
|
||||
test_blas_1<ublas::vector<std::complex<double> >, 3> () ();
|
||||
#endif
|
||||
|
||||
std::cout << "test_blas_2" << std::endl;
|
||||
|
||||
std::cout << "float" << std::endl;
|
||||
test_blas_2<ublas::vector<float>, ublas::matrix<float>, 3> () ();
|
||||
|
||||
std::cout << "double" << std::endl;
|
||||
test_blas_2<ublas::vector<double>, ublas::matrix<double>, 3> () ();
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
std::cout << "std::complex<float>" << std::endl;
|
||||
test_blas_2<ublas::vector<std::complex<float> >, ublas::matrix<std::complex<float> >, 3> () ();
|
||||
|
||||
std::cout << "std::complex<double>" << std::endl;
|
||||
test_blas_2<ublas::vector<std::complex<double> >, ublas::matrix<std::complex<double> >, 3> () ();
|
||||
#endif
|
||||
|
||||
std::cout << "float" << std::endl;
|
||||
test_blas_3<ublas::matrix<float>, 3> () ();
|
||||
|
||||
std::cout << "double" << std::endl;
|
||||
test_blas_3<ublas::matrix<double>, 3> () ();
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
std::cout << "std::complex<float>" << std::endl;
|
||||
test_blas_3<ublas::matrix<std::complex<float> >, 3> () ();
|
||||
|
||||
std::cout << "std::complex<double>" << std::endl;
|
||||
test_blas_3<ublas::matrix<std::complex<double> >, 3> () ();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
218
test2/test2.dsp
Normal file
218
test2/test2.dsp
Normal file
@@ -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
|
||||
72
test2/test2.hpp
Normal file
72
test2/test2.hpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef TEST2_H
|
||||
#define TEST2_H
|
||||
|
||||
namespace ublas = boost::numeric::ublas;
|
||||
|
||||
template<class V>
|
||||
void initialize_vector (V &v) {
|
||||
int size = v.size ();
|
||||
for (int i = 0; i < size; ++ i)
|
||||
v [i] = i + 1.f;
|
||||
}
|
||||
|
||||
template<class M>
|
||||
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<class M>
|
||||
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<class M>
|
||||
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<class V, int N>
|
||||
struct test_blas_1 {
|
||||
typedef typename V::value_type value_type;
|
||||
typedef typename ublas::type_traits<value_type>::real_type real_type;
|
||||
|
||||
void operator () ();
|
||||
};
|
||||
|
||||
template<class V, class M, int N>
|
||||
struct test_blas_2 {
|
||||
typedef typename V::value_type value_type;
|
||||
|
||||
void operator () ();
|
||||
};
|
||||
|
||||
template<class M, int N>
|
||||
struct test_blas_3 {
|
||||
typedef typename M::value_type value_type;
|
||||
|
||||
void operator () ();
|
||||
};
|
||||
|
||||
// #define USE_STD_COMPLEX
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
97
test2/test21.cpp
Normal file
97
test2/test21.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/triangular.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include <boost/numeric/ublas/blas.hpp>
|
||||
|
||||
#include "test2.hpp"
|
||||
|
||||
template<class V, int N>
|
||||
void test_blas_1<V, N>::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<ublas::vector<float>, 3>;
|
||||
template struct test_blas_1<ublas::vector<double>, 3>;
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
template struct test_blas_1<ublas::vector<std::complex<float> >, 3>;
|
||||
template struct test_blas_1<ublas::vector<std::complex<double> >, 3>;
|
||||
#endif
|
||||
150
test2/test22.cpp
Normal file
150
test2/test22.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/triangular.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include <boost/numeric/ublas/blas.hpp>
|
||||
|
||||
#include "test2.hpp"
|
||||
|
||||
template<class V, class M, int N>
|
||||
void test_blas_2<V, M, N>::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::vector<float>, ublas::matrix<float>, 3>;
|
||||
template struct test_blas_2<ublas::vector<double>, ublas::matrix<double>, 3>;
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
template struct test_blas_2<ublas::vector<std::complex<float> >, ublas::matrix<std::complex<float> >, 3>;
|
||||
template struct test_blas_2<ublas::vector<std::complex<double> >, ublas::matrix<std::complex<double> >, 3>;
|
||||
#endif
|
||||
|
||||
210
test2/test23.cpp
Normal file
210
test2/test23.cpp
Normal file
@@ -0,0 +1,210 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/triangular.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include <boost/numeric/ublas/blas.hpp>
|
||||
|
||||
#include "test2.hpp"
|
||||
|
||||
template<class M, int N>
|
||||
void test_blas_3<M, N>::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<ublas::matrix<float>, 3>;
|
||||
template struct test_blas_3<ublas::matrix<double>, 3>;
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
template struct test_blas_3<ublas::matrix<std::complex<float> >, 3>;
|
||||
template struct test_blas_3<ublas::matrix<std::complex<double> >, 3>;
|
||||
#endif
|
||||
10
test3/Jamfile
Normal file
10
test3/Jamfile
Normal file
@@ -0,0 +1,10 @@
|
||||
subproject libs/numeric/ublas/test3 ;
|
||||
|
||||
SOURCES = test3 test31 test32 test33 ;
|
||||
|
||||
exe test3
|
||||
: $(SOURCES).cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
<borland><*><cxxflags>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092"
|
||||
;
|
||||
|
||||
37
test3/test3.cpp
Normal file
37
test3/test3.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/vector_sparse.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/matrix_sparse.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test3.hpp"
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
// Standard new handler is not standard compliant.
|
||||
#include <new.h>
|
||||
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;
|
||||
}
|
||||
|
||||
219
test3/test3.dsp
Normal file
219
test3/test3.dsp
Normal file
@@ -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
|
||||
48
test3/test3.hpp
Normal file
48
test3/test3.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef TEST3_H
|
||||
#define TEST3_H
|
||||
|
||||
namespace ublas = boost::numeric::ublas;
|
||||
|
||||
template<class V>
|
||||
void initialize_vector (V &v) {
|
||||
int size = v.size ();
|
||||
for (int i = 0; i < size; i += 2)
|
||||
v [i] = i + 1.f;
|
||||
}
|
||||
|
||||
template<class M>
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
211
test3/test31.cpp
Normal file
211
test3/test31.cpp
Normal file
@@ -0,0 +1,211 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/vector_sparse.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/matrix_sparse.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test3.hpp"
|
||||
|
||||
// Test vector expression templates
|
||||
template<class V, int N>
|
||||
struct test_my_vector {
|
||||
typedef typename V::value_type value_type;
|
||||
typedef typename V::size_type size_type;
|
||||
typedef typename ublas::type_traits<value_type>::real_type real_type;
|
||||
|
||||
template<class VP>
|
||||
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<V> 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<V> 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<V> 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<V> 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<ublas::sparse_vector<float, ublas::map_array<std::size_t, float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, map_array" << std::endl;
|
||||
test_my_vector<ublas::sparse_vector<double, ublas::map_array<std::size_t, double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, map_array" << std::endl;
|
||||
test_my_vector<ublas::sparse_vector<std::complex<float>, ublas::map_array<std::size_t, std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, map_array" << std::endl;
|
||||
test_my_vector<ublas::sparse_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_MAP
|
||||
std::cout << "float, std::map" << std::endl;
|
||||
test_my_vector<ublas::sparse_vector<float, std::map<size_t, float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, std::map" << std::endl;
|
||||
test_my_vector<ublas::sparse_vector<double, std::map<size_t, double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, std::map" << std::endl;
|
||||
test_my_vector<ublas::sparse_vector<std::complex<float>, std::map<size_t, std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, std::map" << std::endl;
|
||||
test_my_vector<ublas::sparse_vector<std::complex<double>, std::map<size_t, std::complex<double> > > , 3 > () ();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_COMPRESSED_VECTOR
|
||||
std::cout << "float" << std::endl;
|
||||
test_my_vector<ublas::compressed_vector<float>, 3 > () ();
|
||||
|
||||
std::cout << "double" << std::endl;
|
||||
test_my_vector<ublas::compressed_vector<double>, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>" << std::endl;
|
||||
test_my_vector<ublas::compressed_vector<std::complex<float> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>" << std::endl;
|
||||
test_my_vector<ublas::compressed_vector<std::complex<double> >, 3 > () ();
|
||||
#endif
|
||||
}
|
||||
|
||||
200
test3/test32.cpp
Normal file
200
test3/test32.cpp
Normal file
@@ -0,0 +1,200 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/vector_sparse.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/matrix_sparse.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test3.hpp"
|
||||
|
||||
// Test matrix & vector expression templates
|
||||
template<class V, class M, int N>
|
||||
struct test_my_matrix_vector {
|
||||
typedef typename V::value_type value_type;
|
||||
|
||||
template<class VP, class MP>
|
||||
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<M> mr1 (m1, 0), mr2 (m1, N - 1);
|
||||
(*this) (mr1, mr2, m1);
|
||||
|
||||
ublas::matrix_column<M> 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<M> 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<M> 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<M> 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<M> 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_vector<float, ublas::map_array<std::size_t, float> >,
|
||||
ublas::sparse_matrix<float, ublas::row_major, ublas::map_array<std::size_t, float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, map_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::sparse_vector<double, ublas::map_array<std::size_t, double> >,
|
||||
ublas::sparse_matrix<double, ublas::row_major, ublas::map_array<std::size_t, double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, map_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::sparse_vector<std::complex<float>, ublas::map_array<std::size_t, std::complex<float> > >,
|
||||
ublas::sparse_matrix<std::complex<float>, ublas::row_major, ublas::map_array<std::size_t, std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, map_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::sparse_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >,
|
||||
ublas::sparse_matrix<std::complex<double>, ublas::row_major, ublas::map_array<std::size_t, std::complex<double> > >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_MAP
|
||||
std::cout << "float, std::map" << std::endl;
|
||||
test_my_matrix_vector<ublas::sparse_vector<float, std::map<std::size_t, float> >,
|
||||
ublas::sparse_matrix<float, ublas::row_major, std::map<std::size_t, float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, std::map" << std::endl;
|
||||
test_my_matrix_vector<ublas::sparse_vector<double, std::map<std::size_t, double> >,
|
||||
ublas::sparse_matrix<double, ublas::row_major, std::map<std::size_t, double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, std::map" << std::endl;
|
||||
test_my_matrix_vector<ublas::sparse_vector<std::complex<float>, std::map<std::size_t, std::complex<float> > >,
|
||||
ublas::sparse_matrix<std::complex<float>, ublas::row_major, std::map<std::size_t, std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, std::map" << std::endl;
|
||||
test_my_matrix_vector<ublas::sparse_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > >,
|
||||
ublas::sparse_matrix<std::complex<double>, ublas::row_major, std::map<std::size_t, std::complex<double> > >, 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<float, ublas::map_array<std::size_t, float> >,
|
||||
ublas::sparse_vector_of_sparse_vector<float, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, float> > >, 3 > () ();
|
||||
|
||||
std::cout << "double, map_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::sparse_vector<double, ublas::map_array<std::size_t, double> >,
|
||||
ublas::sparse_vector_of_sparse_vector<double, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, double> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, map_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::sparse_vector<std::complex<float>, ublas::map_array<std::size_t, std::complex<float> > >,
|
||||
ublas::sparse_vector_of_sparse_vector<std::complex<float>, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, std::complex<float> > > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, map_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::sparse_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >,
|
||||
ublas::sparse_vector_of_sparse_vector<std::complex<double>, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, std::complex<double> > > >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_MAP
|
||||
std::cout << "float, std::map" << std::endl;
|
||||
test_my_matrix_vector<ublas::sparse_vector<float, std::map<std::size_t, float> >,
|
||||
ublas::sparse_vector_of_sparse_vector<float, ublas::row_major, std::map<std::size_t, std::map<std::size_t, float> > >, 3 > () ();
|
||||
|
||||
std::cout << "double, std::map" << std::endl;
|
||||
test_my_matrix_vector<ublas::sparse_vector<double, std::map<std::size_t, double> >,
|
||||
ublas::sparse_vector_of_sparse_vector<double, ublas::row_major, std::map<std::size_t, std::map<std::size_t, double> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, std::map" << std::endl;
|
||||
test_my_matrix_vector<ublas::sparse_vector<std::complex<float>, std::map<std::size_t, std::complex<float> > >,
|
||||
ublas::sparse_vector_of_sparse_vector<std::complex<float>, ublas::row_major, std::map<std::size_t, std::map<std::size_t, std::complex<float> > > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, std::map" << std::endl;
|
||||
test_my_matrix_vector<ublas::sparse_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > >,
|
||||
ublas::sparse_vector_of_sparse_vector<std::complex<double>, ublas::row_major, std::map<std::size_t, std::map<std::size_t, std::complex<double> > > >, 3 > () ();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_COMPRESSED_MATRIX
|
||||
std::cout << "float" << std::endl;
|
||||
test_my_matrix_vector<ublas::compressed_vector<float>,
|
||||
ublas::compressed_matrix<float>, 3 > () ();
|
||||
|
||||
std::cout << "double" << std::endl;
|
||||
test_my_matrix_vector<ublas::compressed_vector<double>,
|
||||
ublas::compressed_matrix<double>, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>" << std::endl;
|
||||
test_my_matrix_vector<ublas::compressed_vector<std::complex<float> >,
|
||||
ublas::compressed_matrix<std::complex<float> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>" << std::endl;
|
||||
test_my_matrix_vector<ublas::compressed_vector<std::complex<double> >,
|
||||
ublas::compressed_matrix<std::complex<double> >, 3 > () ();
|
||||
#endif
|
||||
}
|
||||
|
||||
233
test3/test33.cpp
Normal file
233
test3/test33.cpp
Normal file
@@ -0,0 +1,233 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/vector_sparse.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/matrix_sparse.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test3.hpp"
|
||||
|
||||
// Test matrix expression templates
|
||||
template<class M, int N>
|
||||
struct test_my_matrix {
|
||||
typedef typename M::value_type value_type;
|
||||
|
||||
template<class MP>
|
||||
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<M> 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<M> 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<M> 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<M> 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<ublas::sparse_matrix<float, ublas::row_major, ublas::map_array<std::size_t, float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, map_array" << std::endl;
|
||||
test_my_matrix<ublas::sparse_matrix<double, ublas::row_major, ublas::map_array<std::size_t, double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, map_array" << std::endl;
|
||||
test_my_matrix<ublas::sparse_matrix<std::complex<float>, ublas::row_major, ublas::map_array<std::size_t, std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, map_array" << std::endl;
|
||||
test_my_matrix<ublas::sparse_matrix<std::complex<double>, ublas::row_major, ublas::map_array<std::size_t, std::complex<double> > >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_MAP
|
||||
std::cout << "float, std::map" << std::endl;
|
||||
test_my_matrix<ublas::sparse_matrix<float, ublas::row_major, std::map<std::size_t, float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, std::map" << std::endl;
|
||||
test_my_matrix<ublas::sparse_matrix<double, ublas::row_major, std::map<std::size_t, double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, std::map" << std::endl;
|
||||
test_my_matrix<ublas::sparse_matrix<std::complex<float>, ublas::row_major, std::map<std::size_t, std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, std::map" << std::endl;
|
||||
test_my_matrix<ublas::sparse_matrix<std::complex<double>, ublas::row_major, std::map<std::size_t, std::complex<double> > >, 3 > () ();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_SPARSE_VECTOR_OF_SPARSE_VECTOR
|
||||
#ifdef USE_MAP_ARRAY
|
||||
std::cout << "float, map_array" << std::endl;
|
||||
test_my_matrix<ublas::sparse_vector_of_sparse_vector<float, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, float> > >, 3 > () ();
|
||||
|
||||
std::cout << "double, map_array" << std::endl;
|
||||
test_my_matrix<ublas::sparse_vector_of_sparse_vector<double, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, double> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, map_array" << std::endl;
|
||||
test_my_matrix<ublas::sparse_vector_of_sparse_vector<std::complex<float>, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, std::complex<float> > > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, map_array" << std::endl;
|
||||
test_my_matrix<ublas::sparse_vector_of_sparse_vector<std::complex<double>, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, std::complex<double> > > >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_MAP
|
||||
std::cout << "float, std::map" << std::endl;
|
||||
test_my_matrix<ublas::sparse_vector_of_sparse_vector<float, ublas::row_major, std::map<std::size_t, std::map<std::size_t, float> > >, 3 > () ();
|
||||
|
||||
std::cout << "double, std::map" << std::endl;
|
||||
test_my_matrix<ublas::sparse_vector_of_sparse_vector<double, ublas::row_major, std::map<std::size_t, std::map<std::size_t, double> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, std::map" << std::endl;
|
||||
test_my_matrix<ublas::sparse_vector_of_sparse_vector<std::complex<float>, ublas::row_major, std::map<std::size_t, std::map<std::size_t, std::complex<float> > > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, std::map" << std::endl;
|
||||
test_my_matrix<ublas::sparse_vector_of_sparse_vector<std::complex<double>, ublas::row_major, std::map<std::size_t, std::map<std::size_t, std::complex<double> > > >, 3 > () ();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_COMPRESSED_MATRIX
|
||||
std::cout << "float" << std::endl;
|
||||
test_my_matrix<ublas::compressed_matrix<float>, 3 > () ();
|
||||
|
||||
std::cout << "double" << std::endl;
|
||||
test_my_matrix<ublas::compressed_matrix<double>, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>" << std::endl;
|
||||
test_my_matrix<ublas::compressed_matrix<std::complex<float> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>" << std::endl;
|
||||
test_my_matrix<ublas::compressed_matrix<std::complex<double> >, 3 > () ();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
10
test4/Jamfile
Normal file
10
test4/Jamfile
Normal file
@@ -0,0 +1,10 @@
|
||||
subproject libs/numeric/ublas/test4 ;
|
||||
|
||||
SOURCES = test4 test41 test42 test43 ;
|
||||
|
||||
exe test4
|
||||
: $(SOURCES).cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
<borland><*><cxxflags>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092"
|
||||
;
|
||||
|
||||
36
test4/test4.cpp
Normal file
36
test4/test4.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/banded.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test4.hpp"
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
// Standard new handler is not standard compliant.
|
||||
#include <new.h>
|
||||
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;
|
||||
}
|
||||
|
||||
219
test4/test4.dsp
Normal file
219
test4/test4.dsp
Normal file
@@ -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
|
||||
40
test4/test4.hpp
Normal file
40
test4/test4.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef TEST4_H
|
||||
#define TEST4_H
|
||||
|
||||
namespace ublas = boost::numeric::ublas;
|
||||
|
||||
template<class V>
|
||||
void initialize_vector (V &v) {
|
||||
int size = v.size ();
|
||||
for (int i = 0; i < size; ++ i)
|
||||
v [i] = i + 1.f;
|
||||
}
|
||||
|
||||
template<class M>
|
||||
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
|
||||
|
||||
|
||||
208
test4/test41.cpp
Normal file
208
test4/test41.cpp
Normal file
@@ -0,0 +1,208 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/banded.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test4.hpp"
|
||||
|
||||
// Test vector expression templates
|
||||
template<class V, int N>
|
||||
struct test_my_vector {
|
||||
typedef typename V::value_type value_type;
|
||||
typedef typename V::size_type size_type;
|
||||
typedef typename ublas::type_traits<value_type>::real_type real_type;
|
||||
|
||||
template<class VP>
|
||||
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<V> 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<V> 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<V> 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<V> 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<ublas::vector<float, ublas::bounded_array<float, 3> >, 3 > () ();
|
||||
|
||||
std::cout << "double, bounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, bounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, bounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
std::cout << "float, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<float, ublas::unbounded_array<float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<double, ublas::unbounded_array<double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
std::cout << "float, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<float, std::vector<float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<double, std::vector<double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, 3 > () ();
|
||||
#endif
|
||||
}
|
||||
|
||||
226
test4/test42.cpp
Normal file
226
test4/test42.cpp
Normal file
@@ -0,0 +1,226 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/banded.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test4.hpp"
|
||||
|
||||
// Test matrix & vector expression templates
|
||||
template<class V, class M, int N>
|
||||
struct test_my_matrix_vector {
|
||||
typedef typename V::value_type value_type;
|
||||
|
||||
template<class VP, class MP>
|
||||
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<M> mr1 (m1, 1), mr2 (m1, 1);
|
||||
(*this) (mr1, mr2, m1);
|
||||
|
||||
ublas::matrix_column<M> 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<M> 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<M> 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<M> 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<M> 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<M> bam1 (m1, 1, 1);
|
||||
(*this) (v1, v2, bam1);
|
||||
|
||||
ublas::matrix_row<ublas::banded_adaptor<M> > mr1 (bam1, 1), mr2 (bam1, 1);
|
||||
(*this) (mr1, mr2, bam1);
|
||||
|
||||
ublas::matrix_column<ublas::banded_adaptor<M> > 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<ublas::banded_adaptor<M> > 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<ublas::banded_adaptor<M> > 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<ublas::banded_adaptor<M> > 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<ublas::banded_adaptor<M> > 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::vector<float, ublas::bounded_array<float, 3> >,
|
||||
ublas::banded_matrix<float, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<float, ublas::bounded_array<float, 3> >,
|
||||
ublas::banded_matrix<float, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () (0);
|
||||
|
||||
std::cout << "double, bounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
|
||||
ublas::banded_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
|
||||
ublas::banded_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<float>, bounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >,
|
||||
ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >,
|
||||
ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<double>, bounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
|
||||
ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
|
||||
ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
std::cout << "float, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >,
|
||||
ublas::banded_matrix<float, ublas::row_major, ublas::unbounded_array<float> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >,
|
||||
ublas::banded_matrix<float, ublas::row_major, ublas::unbounded_array<float> >, 3> () (0);
|
||||
|
||||
std::cout << "double, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
|
||||
ublas::banded_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
|
||||
ublas::banded_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<float>, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >,
|
||||
ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >,
|
||||
ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<double>, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
|
||||
ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
|
||||
ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
std::cout << "float, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<float, std::vector<float> >,
|
||||
ublas::banded_matrix<float, ublas::row_major, std::vector<float> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<float, std::vector<float> >,
|
||||
ublas::banded_matrix<float, ublas::row_major, std::vector<float> >, 3> () (0);
|
||||
|
||||
std::cout << "double, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
|
||||
ublas::banded_matrix<double, ublas::row_major, std::vector<double> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
|
||||
ublas::banded_matrix<double, ublas::row_major, std::vector<double> >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<float>, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >,
|
||||
ublas::banded_matrix<std::complex<float>, ublas::row_major, std::vector<std::complex<float> > >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >,
|
||||
ublas::banded_matrix<std::complex<float>, ublas::row_major, std::vector<std::complex<float> > >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<double>, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
|
||||
ublas::banded_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
|
||||
ublas::banded_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3> () (0);
|
||||
#endif
|
||||
}
|
||||
|
||||
255
test4/test43.cpp
Normal file
255
test4/test43.cpp
Normal file
@@ -0,0 +1,255 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/banded.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test4.hpp"
|
||||
|
||||
// Test matrix expression templates
|
||||
template<class M, int N>
|
||||
struct test_my_matrix {
|
||||
typedef typename M::value_type value_type;
|
||||
|
||||
template<class MP>
|
||||
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<M> 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<M> 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<M> 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<M> 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<M> 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<ublas::banded_adaptor<M> > 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<ublas::banded_adaptor<M> > 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<ublas::banded_adaptor<M> > 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<ublas::banded_adaptor<M> > 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<ublas::banded_matrix<float, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3 > () ();
|
||||
test_my_matrix<ublas::banded_matrix<float, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3 > () (0);
|
||||
|
||||
std::cout << "double, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::banded_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () ();
|
||||
test_my_matrix<ublas::banded_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<float>, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3 > () ();
|
||||
test_my_matrix<ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<double>, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () ();
|
||||
test_my_matrix<ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () (0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
std::cout << "float, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::banded_matrix<float, ublas::row_major, ublas::unbounded_array<float> >, 3 > () ();
|
||||
test_my_matrix<ublas::banded_matrix<float, ublas::row_major, ublas::unbounded_array<float> >, 3 > () (0);
|
||||
|
||||
std::cout << "double, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::banded_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3 > () ();
|
||||
test_my_matrix<ublas::banded_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<float>, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3 > () ();
|
||||
test_my_matrix<ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<double>, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () ();
|
||||
test_my_matrix<ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () (0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
std::cout << "float, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::banded_matrix<float, ublas::row_major, std::vector<float> >, 3 > () ();
|
||||
test_my_matrix<ublas::banded_matrix<float, ublas::row_major, std::vector<float> >, 3 > () (0);
|
||||
|
||||
std::cout << "double, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::banded_matrix<double, ublas::row_major, std::vector<double> >, 3 > () ();
|
||||
test_my_matrix<ublas::banded_matrix<double, ublas::row_major, std::vector<double> >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<float>, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::banded_matrix<std::complex<float>, ublas::row_major, std::vector<std::complex<float> > >, 3 > () ();
|
||||
test_my_matrix<ublas::banded_matrix<std::complex<float>, ublas::row_major, std::vector<std::complex<float> > >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<double>, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::banded_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3 > () ();
|
||||
test_my_matrix<ublas::banded_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3 > () (0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
10
test5/Jamfile
Normal file
10
test5/Jamfile
Normal file
@@ -0,0 +1,10 @@
|
||||
subproject libs/numeric/ublas/test5 ;
|
||||
|
||||
SOURCES = test5 test51 test52 test53 ;
|
||||
|
||||
exe test5
|
||||
: $(SOURCES).cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
<borland><*><cxxflags>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092"
|
||||
;
|
||||
|
||||
36
test5/test5.cpp
Normal file
36
test5/test5.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/triangular.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test5.hpp"
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
// Standard new handler is not standard compliant.
|
||||
#include <new.h>
|
||||
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;
|
||||
}
|
||||
|
||||
219
test5/test5.dsp
Normal file
219
test5/test5.dsp
Normal file
@@ -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
|
||||
65
test5/test5.hpp
Normal file
65
test5/test5.hpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef TEST5_H
|
||||
#define TEST5_H
|
||||
|
||||
namespace ublas = boost::numeric::ublas;
|
||||
|
||||
template<class V>
|
||||
void initialize_vector (V &v) {
|
||||
int size = v.size ();
|
||||
for (int i = 0; i < size; ++ i)
|
||||
v [i] = i + 1.f;
|
||||
}
|
||||
|
||||
template<class M>
|
||||
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<class M>
|
||||
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<class M>
|
||||
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
|
||||
|
||||
|
||||
208
test5/test51.cpp
Normal file
208
test5/test51.cpp
Normal file
@@ -0,0 +1,208 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/triangular.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test5.hpp"
|
||||
|
||||
// Test vector expression templates
|
||||
template<class V, int N>
|
||||
struct test_my_vector {
|
||||
typedef typename V::value_type value_type;
|
||||
typedef typename V::size_type size_type;
|
||||
typedef typename ublas::type_traits<value_type>::real_type real_type;
|
||||
|
||||
template<class VP>
|
||||
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<V> 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<V> 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<V> 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<V> 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<ublas::vector<float, ublas::bounded_array<float, 3> >, 3 > () ();
|
||||
|
||||
std::cout << "double, bounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, bounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, bounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
std::cout << "float, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<float, ublas::unbounded_array<float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<double, ublas::unbounded_array<double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
std::cout << "float, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<float, std::vector<float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<double, std::vector<double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, 3 > () ();
|
||||
#endif
|
||||
}
|
||||
|
||||
226
test5/test52.cpp
Normal file
226
test5/test52.cpp
Normal file
@@ -0,0 +1,226 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/triangular.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test5.hpp"
|
||||
|
||||
// Test matrix & vector expression templates
|
||||
template<class V, class M, int N>
|
||||
struct test_my_matrix_vector {
|
||||
typedef typename V::value_type value_type;
|
||||
|
||||
template<class VP, class MP>
|
||||
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<M> mr1 (m1, N - 1), mr2 (m1, N - 1);
|
||||
(*this) (mr1, mr2, m1);
|
||||
|
||||
ublas::matrix_column<M> 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<M> 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<M> 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<M> 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<M> 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<M> tam1 (m1);
|
||||
(*this) (v1, v2, tam1);
|
||||
|
||||
ublas::matrix_row<ublas::triangular_adaptor<M> > mr1 (tam1, N - 1), mr2 (tam1, N - 1);
|
||||
(*this) (mr1, mr2, tam1);
|
||||
|
||||
ublas::matrix_column<ublas::triangular_adaptor<M> > 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<ublas::triangular_adaptor<M> > 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<ublas::triangular_adaptor<M> > 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<ublas::triangular_adaptor<M> > 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<ublas::triangular_adaptor<M> > 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::vector<float, ublas::bounded_array<float, 3> >,
|
||||
ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<float, ublas::bounded_array<float, 3> >,
|
||||
ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () (0);
|
||||
|
||||
std::cout << "double, bounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
|
||||
ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
|
||||
ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<float>, bounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >,
|
||||
ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >,
|
||||
ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<double>, bounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
|
||||
ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
|
||||
ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
std::cout << "float, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >,
|
||||
ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::unbounded_array<float> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >,
|
||||
ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::unbounded_array<float> >, 3> () (0);
|
||||
|
||||
std::cout << "double, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
|
||||
ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
|
||||
ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<float>, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >,
|
||||
ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >,
|
||||
ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<double>, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
|
||||
ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
|
||||
ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
std::cout << "float, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<float, std::vector<float> >,
|
||||
ublas::triangular_matrix<float, ublas::lower, ublas::row_major, std::vector<float> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<float, std::vector<float> >,
|
||||
ublas::triangular_matrix<float, ublas::lower, ublas::row_major, std::vector<float> >, 3> () (0);
|
||||
|
||||
std::cout << "double, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
|
||||
ublas::triangular_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
|
||||
ublas::triangular_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<float>, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >,
|
||||
ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, std::vector<std::complex<float> > >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >,
|
||||
ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, std::vector<std::complex<float> > >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<double>, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
|
||||
ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
|
||||
ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3> () (0);
|
||||
#endif
|
||||
}
|
||||
|
||||
255
test5/test53.cpp
Normal file
255
test5/test53.cpp
Normal file
@@ -0,0 +1,255 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/triangular.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test5.hpp"
|
||||
|
||||
// Test matrix expression templates
|
||||
template<class M, int N>
|
||||
struct test_my_matrix {
|
||||
typedef typename M::value_type value_type;
|
||||
|
||||
template<class MP>
|
||||
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<M> 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<M> 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<M> 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<M> 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<M> tam1 (m1), tam2 (m2), tam3 (m3);
|
||||
(*this) (tam1, tam2, tam3);
|
||||
|
||||
#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL
|
||||
#ifdef USE_RANGE
|
||||
ublas::matrix_range<ublas::triangular_adaptor<M> > 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<ublas::triangular_adaptor<M> > 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<ublas::triangular_adaptor<M> > 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<ublas::triangular_adaptor<M> > 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<ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3 > () ();
|
||||
test_my_matrix<ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3 > () (0);
|
||||
|
||||
std::cout << "double, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () ();
|
||||
test_my_matrix<ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<float>, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3 > () ();
|
||||
test_my_matrix<ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<double>, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () ();
|
||||
test_my_matrix<ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () (0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
std::cout << "float, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::unbounded_array<float> >, 3 > () ();
|
||||
test_my_matrix<ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::unbounded_array<float> >, 3 > () (0);
|
||||
|
||||
std::cout << "double, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3 > () ();
|
||||
test_my_matrix<ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<float>, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3 > () ();
|
||||
test_my_matrix<ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<double>, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () ();
|
||||
test_my_matrix<ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () (0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
std::cout << "float, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::triangular_matrix<float, ublas::lower, ublas::row_major, std::vector<float> >, 3 > () ();
|
||||
test_my_matrix<ublas::triangular_matrix<float, ublas::lower, ublas::row_major, std::vector<float> >, 3 > () (0);
|
||||
|
||||
std::cout << "double, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::triangular_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3 > () ();
|
||||
test_my_matrix<ublas::triangular_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<float>, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, std::vector<std::complex<float> > >, 3 > () ();
|
||||
test_my_matrix<ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, std::vector<std::complex<float> > >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<double>, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3 > () ();
|
||||
test_my_matrix<ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3 > () (0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
10
test6/Jamfile
Normal file
10
test6/Jamfile
Normal file
@@ -0,0 +1,10 @@
|
||||
subproject libs/numeric/ublas/test6 ;
|
||||
|
||||
SOURCES = test6 test61 test62 test63 ;
|
||||
|
||||
exe test6
|
||||
: $(SOURCES).cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
<borland><*><cxxflags>"-w-8026 -w-8027 -w-8057 -w-8084 -w-8092"
|
||||
;
|
||||
|
||||
37
test6/test6.cpp
Normal file
37
test6/test6.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/triangular.hpp>
|
||||
#include <boost/numeric/ublas/symmetric.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test6.hpp"
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
// Standard new handler is not standard compliant.
|
||||
#include <new.h>
|
||||
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;
|
||||
}
|
||||
|
||||
219
test6/test6.dsp
Normal file
219
test6/test6.dsp
Normal file
@@ -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
|
||||
65
test6/test6.hpp
Normal file
65
test6/test6.hpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef TEST6_H
|
||||
#define TEST6_H
|
||||
|
||||
namespace ublas = boost::numeric::ublas;
|
||||
|
||||
template<class V>
|
||||
void initialize_vector (V &v) {
|
||||
int size = v.size ();
|
||||
for (int i = 0; i < size; ++ i)
|
||||
v [i] = i + 1.f;
|
||||
}
|
||||
|
||||
template<class M>
|
||||
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<class M>
|
||||
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<class M>
|
||||
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
|
||||
|
||||
|
||||
209
test6/test61.cpp
Normal file
209
test6/test61.cpp
Normal file
@@ -0,0 +1,209 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/triangular.hpp>
|
||||
#include <boost/numeric/ublas/symmetric.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test6.hpp"
|
||||
|
||||
// Test vector expression templates
|
||||
template<class V, int N>
|
||||
struct test_my_vector {
|
||||
typedef typename V::value_type value_type;
|
||||
typedef typename V::size_type size_type;
|
||||
typedef typename ublas::type_traits<value_type>::real_type real_type;
|
||||
|
||||
template<class VP>
|
||||
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<V> 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<V> 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<V> 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<V> 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<ublas::vector<float, ublas::bounded_array<float, 3> >, 3 > () ();
|
||||
|
||||
std::cout << "double, bounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, bounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, bounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
std::cout << "float, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<float, ublas::unbounded_array<float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<double, ublas::unbounded_array<double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, unbounded_array" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, 3 > () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
std::cout << "float, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<float, std::vector<float> >, 3 > () ();
|
||||
|
||||
std::cout << "double, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<double, std::vector<double> >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<float>, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >, 3 > () ();
|
||||
|
||||
std::cout << "std::complex<double>, std::vector" << std::endl;
|
||||
test_my_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, 3 > () ();
|
||||
#endif
|
||||
}
|
||||
|
||||
229
test6/test62.cpp
Normal file
229
test6/test62.cpp
Normal file
@@ -0,0 +1,229 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/triangular.hpp>
|
||||
#include <boost/numeric/ublas/symmetric.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test6.hpp"
|
||||
|
||||
// Test matrix & vector expression templates
|
||||
template<class V, class M, int N>
|
||||
struct test_my_matrix_vector {
|
||||
typedef typename V::value_type value_type;
|
||||
|
||||
template<class VP, class MP>
|
||||
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<M> mr1 (m1, N - 1), mr2 (m1, N - 1);
|
||||
(*this) (mr1, mr2, m1);
|
||||
|
||||
ublas::matrix_column<M> 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<M> 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<M> 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<M> 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<M> 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<M> tam1 (m1);
|
||||
(*this) (v1, v2, tam1);
|
||||
|
||||
ublas::matrix_row<ublas::symmetric_adaptor<M> > mr1 (tam1, N - 1), mr2 (tam1, N - 1);
|
||||
(*this) (mr1, mr2, tam1);
|
||||
|
||||
ublas::matrix_column<ublas::symmetric_adaptor<M> > 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<ublas::symmetric_adaptor<M> > 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<ublas::symmetric_adaptor<M> > 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<ublas::symmetric_adaptor<M> > 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<ublas::symmetric_adaptor<M> > 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::vector<float, ublas::bounded_array<float, 3> >,
|
||||
ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<float, ublas::bounded_array<float, 3> >,
|
||||
ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () (0);
|
||||
|
||||
std::cout << "double, bounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
|
||||
ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
|
||||
ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<float>, bounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >,
|
||||
ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >,
|
||||
ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<double>, bounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
|
||||
ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
|
||||
ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
std::cout << "float, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >,
|
||||
ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, ublas::unbounded_array<float> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >,
|
||||
ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, ublas::unbounded_array<float> >, 3> () (0);
|
||||
|
||||
std::cout << "double, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
|
||||
ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
|
||||
ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<float>, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >,
|
||||
ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >,
|
||||
ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<double>, unbounded_array" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
|
||||
ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
|
||||
ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
std::cout << "float, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<float, std::vector<float> >,
|
||||
ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, std::vector<float> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<float, std::vector<float> >,
|
||||
ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, std::vector<float> >, 3> () (0);
|
||||
|
||||
std::cout << "double, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
|
||||
ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
|
||||
ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<float>, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >,
|
||||
ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, std::vector<std::complex<float> > >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >,
|
||||
ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, std::vector<std::complex<float> > >, 3> () (0);
|
||||
|
||||
std::cout << "std::complex<double>, std::vector" << std::endl;
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
|
||||
ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3> () ();
|
||||
test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
|
||||
ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3> () (0);
|
||||
#endif
|
||||
}
|
||||
|
||||
256
test6/test63.cpp
Normal file
256
test6/test63.cpp
Normal file
@@ -0,0 +1,256 @@
|
||||
#ifdef BOOST_MSVC
|
||||
|
||||
#pragma warning (disable: 4355)
|
||||
#pragma warning (disable: 4503)
|
||||
#pragma warning (disable: 4786)
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/numeric/ublas/config.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/triangular.hpp>
|
||||
#include <boost/numeric/ublas/symmetric.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include "test6.hpp"
|
||||
|
||||
// Test matrix expression templates
|
||||
template<class M, int N>
|
||||
struct test_my_matrix {
|
||||
typedef typename M::value_type value_type;
|
||||
|
||||
template<class MP>
|
||||
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<M> 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<M> 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<M> 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<M> 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<M> sam1 (m1), sam2 (m2), sam3 (m3);
|
||||
(*this) (sam1, sam2, sam3);
|
||||
|
||||
#ifdef BOOST_UBLAS_ENABLE_INDEX_SET_ALL
|
||||
#ifdef USE_RANGE
|
||||
ublas::matrix_range<ublas::symmetric_adaptor<M> > 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<ublas::symmetric_adaptor<M> > 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<ublas::symmetric_adaptor<M> > 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<ublas::symmetric_adaptor<M> > 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<ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3 > () ();
|
||||
test_my_matrix<ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3 > () (0);
|
||||
|
||||
std::cout << "double, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () ();
|
||||
test_my_matrix<ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<float>, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3 > () ();
|
||||
test_my_matrix<ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<double>, bounded_array" << std::endl;
|
||||
test_my_matrix<ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () ();
|
||||
test_my_matrix<ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () (0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
std::cout << "float, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, ublas::unbounded_array<float> >, 3 > () ();
|
||||
test_my_matrix<ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, ublas::unbounded_array<float> >, 3 > () (0);
|
||||
|
||||
std::cout << "double, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3 > () ();
|
||||
test_my_matrix<ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<float>, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3 > () ();
|
||||
test_my_matrix<ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<double>, unbounded_array" << std::endl;
|
||||
test_my_matrix<ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () ();
|
||||
test_my_matrix<ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () (0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
std::cout << "float, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, std::vector<float> >, 3 > () ();
|
||||
test_my_matrix<ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, std::vector<float> >, 3 > () (0);
|
||||
|
||||
std::cout << "double, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3 > () ();
|
||||
test_my_matrix<ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<float>, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, std::vector<std::complex<float> > >, 3 > () ();
|
||||
test_my_matrix<ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, std::vector<std::complex<float> > >, 3 > () (0);
|
||||
|
||||
std::cout << "std::complex<double>, std::vector" << std::endl;
|
||||
test_my_matrix<ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3 > () ();
|
||||
test_my_matrix<ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3 > () (0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
181
ublas.dsw
Normal file
181
ublas.dsw
Normal file
@@ -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>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Reference in New Issue
Block a user