Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • iwr/amdis
  • backofen/amdis
  • aland/amdis
3 results
Show changes
Showing
with 2646 additions and 0 deletions
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
#ifndef MTL_STRIDED_BASE_CURSOR_INCLUDE
#define MTL_STRIDED_BASE_CURSOR_INCLUDE
#include <boost/numeric/mtl/detail/base_cursor.hpp>
namespace mtl { namespace detail {
template <class Key> struct strided_base_cursor
: base_cursor<Key>
{
typedef Key key_type;
typedef base_cursor<Key> base;
typedef strided_base_cursor self;
strided_base_cursor () {}
strided_base_cursor (key_type key, std::size_t stride)
: base(key), stride(stride)
{}
self& operator++ ()
{
this->key+= stride; return *this;
}
self operator++ (int)
{
self tmp = *this;
this->key+= stride;
return tmp;
}
self& operator-- ()
{
this->key-= stride;
return *this;
}
self operator-- (int)
{
self tmp = *this;
this->key-= stride;
return tmp;
}
self& operator+=(int n)
{
this->key += stride * n;
return *this;
}
self operator+(int n) const
{
self tmp(*this);
tmp+= n;
return tmp;
}
self& operator-=(int n)
{
this->key -= stride * n;
return *this;
}
int operator-(const self& cc) const
{
return (this->key - cc.key) / stride;
}
std::size_t stride;
};
}} // namespace mtl::detail
#endif // MTL_STRIDED_BASE_CURSOR_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
#ifndef MTL_TRIVIAL_INSERTER_INCLUDE
#define MTL_TRIVIAL_INSERTER_INCLUDE
#include <boost/numeric/mtl/operation/update.hpp>
#include <boost/numeric/mtl/operation/size.hpp>
#include <boost/numeric/mtl/matrix/element_matrix.hpp>
#include <boost/numeric/mtl/matrix/element_array.hpp>
namespace mtl { namespace detail {
// Matrix must have direct write access, i.e. matrix(row, col) must return a non-const reference
template <typename Matrix, typename Updater = mtl::operations::update_store<typename Matrix::value_type> >
struct trivial_inserter
{
typedef trivial_inserter self;
typedef Matrix matrix_type;
typedef typename matrix_type::size_type size_type;
typedef typename matrix_type::value_type value_type;
typedef operations::update_proxy<self, size_type> proxy_type;
explicit trivial_inserter(matrix_type& matrix, size_type) : matrix(matrix) {}
proxy_type operator() (size_type row, size_type col)
{
return proxy_type(*this, row, col);
}
private:
struct bracket_proxy
{
bracket_proxy(self& ref, size_type row) : ref(ref), row(row) {}
proxy_type operator[](size_type col)
{
return proxy_type(ref, row, col);
}
self& ref;
size_type row;
};
public:
bracket_proxy operator[] (size_type row)
{
return bracket_proxy(*this, row);
}
template <typename Value>
void update(size_type row, size_type col, Value val)
{
Updater() (matrix(row, col), val);
}
template <typename Modifier, typename Value>
void modify(size_type row, size_type col, Value val)
{
Modifier() (matrix(row, col), val);
}
template <typename EMatrix, typename Rows, typename Cols>
self& operator<< (const matrix::element_matrix_t<EMatrix, Rows, Cols>& elements)
{
using mtl::size;
for (unsigned ri= 0; ri < size(elements.rows); ri++)
for (unsigned ci= 0; ci < size(elements.cols); ci++)
update (elements.rows[ri], elements.cols[ci], elements.matrix(ri, ci));
return *this;
}
template <typename EMatrix, typename Rows, typename Cols>
self& operator<< (const matrix::element_array_t<EMatrix, Rows, Cols>& elements)
{
using mtl::size;
for (unsigned ri= 0; ri < size(elements.rows); ri++)
for (unsigned ci= 0; ci < size(elements.cols); ci++)
update (elements.rows[ri], elements.cols[ci], elements.array[ri][ci]);
return *this;
}
protected:
matrix_type& matrix;
};
}} // namespace mtl::detail
#endif // MTL_TRIVIAL_INSERTER_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
#ifndef MTL_ARPREC_INCLUDE
#define MTL_ARPREC_INCLUDE
#ifdef MTL_HAS_ARPREC
#include <arprec/mp_real.h>
#include <arprec/mp_complex.h>
#include <boost/numeric/mtl/concept/magnitude.hpp>
#include <boost/numeric/mtl/utility/true_copy.hpp>
#include <boost/numeric/linear_algebra/identity.hpp>
namespace mtl {
/// Specialization for ARPREC complex numbers
template <>
struct Magnitude<mp_complex>
{
/// The associated type is ARPREC real
typedef mp_real type;
};
namespace traits {
template <>
struct true_copy<mp_real_temp>
{
typedef mp_real type;
};
}
} // namespace mtl
namespace math {
template <>
struct identity_t< add<mp_complex>, mp_complex >
: public std::binary_function<add<mp_complex>, mp_complex, mp_complex>
{
mp_complex operator() (const add<mp_complex>&, const mp_complex& /*ref*/) const
{
return mp_complex("0", "0");
}
};
} // math
#endif // MTL_HAS_ARPREC
#endif // MTL_ARPREC_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
#ifndef MTL_BLAS_INCLUDE
#define MTL_BLAS_INCLUDE
#ifdef MTL_HAS_BLAS
// #include "mtl/mtl_config.h"
#if 0
#include "mtl/mtl_complex.h"
using std::complex;
#endif
/*--------------------------------------------------------
Basic Linear Algebra Subprograms for C/C++
Version 1.0
Matthew E. Gaston
May 6, 1998
----------------------------------------------------------*/
#define MTL_BLAS_NAME(name) name##_
#ifdef __cplusplus
extern "C" {
#endif
/*---------------------------------------------------------
Level 1 BLAS
-----------------------------------------------------------*/
/*
// Dot product functions
*/
float MTL_BLAS_NAME(sdot)(int*, float*, int*, float*, int*);
double MTL_BLAS_NAME(dsdot)(int*, float*, int*, float*, int*);
float MTL_BLAS_NAME(sdsdot)(int*, float*, float*, int*, float*, int*);
double MTL_BLAS_NAME(ddot)(int*, double*, int*, double*, int*);
/*
AXPY
*/
void MTL_BLAS_NAME(saxpy)(int*, float*, float*, int*, float*, int*);
void MTL_BLAS_NAME(daxpy)(int*, double*, double*, int*, double*, int*);
/*
Copy
*/
void MTL_BLAS_NAME(scopy)(int*, float*, int*, float*, int*);
void MTL_BLAS_NAME(dcopy)(int*, double*, int*, double*, int*);
/*
Swap
*/
void MTL_BLAS_NAME(sswap)(int*, float*, int*, float*, int*);
void MTL_BLAS_NAME(dswap)(int*, double*, int*, double*, int*);
/*
2 Norm
*/
float MTL_BLAS_NAME(snrm2)(int *, float*, int*);
double MTL_BLAS_NAME(dnrm2)(int *, double*, int*);
/*
Sum of Absolute Values
*/
float MTL_BLAS_NAME(sasum)(int *, float*, int*);
double MTL_BLAS_NAME(dasum)(int *, double*, int*);
/*
Scale
*/
void MTL_BLAS_NAME(sscal)(int*, float*, float*, int*);
void MTL_BLAS_NAME(dscal)(int*, double*, double*, int*);
/*
Maximum absolute value
*/
int MTL_BLAS_NAME(isamax)(int *, float*, int*);
int MTL_BLAS_NAME(idamax)(int *, double*, int*);
/*
Givens Plane Rotation
*/
void MTL_BLAS_NAME(srotg)(float*, float*, float*, float*);
void MTL_BLAS_NAME(drotg)(double*, double*, double*, double*);
#if 0
void MTL_BLAS_NAME(crotg)(complex<float>*,complex<float>*,float*,complex<float>*);
void MTL_BLAS_NAME(zrotg)(complex<double>*,complex<double>*,double*,complex<double>*);
#endif
void MTL_BLAS_NAME(srot)(int*, float*, int*, float*, int*, float*, float*);
void MTL_BLAS_NAME(drot)(int*, double*, int*, double*, int*, double*, double*);
#if 0
/* MTL implements ccrot and zzrot */
void MTL_BLAS_NAME(csrot)(int*, complex<float>*, int*, complex<float>*, int*,
complex<float>*, complex<float>*);
void MTL_BLAS_NAME(zdrot)(int*, complex<double>*, int*, complex<double>*, int*,
double*, double*);
#endif
/*---------------------------------------------------------
Level 2 BLAS
-----------------------------------------------------------*/
void MTL_BLAS_NAME(dgemv)(char*, int*, int*, double*, double*, int*,
double*, int*, double*, double*, int*);
void MTL_BLAS_NAME(dger)(int*, int*, double*, double*, int*, double*,
int*, double*, int*);
void MTL_BLAS_NAME(dgbmv)(char*, int*, int*, int*, int*, double*, double*, int*,
double*, int*, double*, double*, int*);
void MTL_BLAS_NAME(dtrsv)(char* uplo, char* trans, char* diag, int* n, double *da,
int* lda, double *dx, int* incx);
/*---------------------------------------------------------
Level 3 BLAS
-----------------------------------------------------------*/
void MTL_BLAS_NAME(sgemm)(const char* transa, const char* transb,
const int* m, const int* n, const int* k,
const float* alpha, const float *da, const int* lda,
const float *db, const int* ldb, const float* dbeta,
float *dc, const int* ldc);
void MTL_BLAS_NAME(dgemm)(const char* transa, const char* transb,
const int* m, const int* n, const int* k,
const double* alpha, const double *da, const int* lda,
const double *db, const int* ldb, const double* dbeta,
double *dc, const int* ldc);
void MTL_BLAS_NAME(cgemm)(const char* transa, const char* transb,
const int* m, const int* n, const int* k,
const std::complex<float>* alpha, const std::complex<float> *da, const int* lda,
const std::complex<float> *db, const int* ldb, const std::complex<float>* dbeta,
std::complex<float> *dc, const int* ldc);
void MTL_BLAS_NAME(zgemm)(const char* transa, const char* transb,
const int* m, const int* n, const int* k,
const std::complex<double>* alpha, const std::complex<double> *da, const int* lda,
const std::complex<double> *db, const int* ldb, const std::complex<double>* dbeta,
std::complex<double> *dc, const int* ldc);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // MTL_HAS_BLAS
#endif // MTL_BLAS_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
#ifndef MTL_LAPACK_INCLUDE
#define MTL_LAPACK_INCLUDE
#include <complex>
#ifdef __cplusplus
extern "C" {
#endif
// Cholesky Factorization
void spotrf_(const char* uplo, const int* n, float *a, const int* ld, int* info);
void dpotrf_(const char* uplo, const int* n, double *a, const int* ld, int* info);
void cpotrf_(const char* uplo, const int* n, std::complex<float> *a, const int* ld, int* info);
void zpotrf_(const char* uplo, const int* n, std::complex<double> *a, const int* ld, int* info);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // MTL_LAPACK_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
#ifndef MTL_MATRIX_UMFPACK_SOLVE_INCLUDE
#define MTL_MATRIX_UMFPACK_SOLVE_INCLUDE
#ifdef MTL_HAS_UMFPACK
#include <iostream>
#include <cassert>
#include <algorithm>
#include <boost/mpl/bool.hpp>
#include <boost/numeric/mtl/matrix/compressed2D.hpp>
#include <boost/numeric/mtl/matrix/parameter.hpp>
#include <boost/numeric/mtl/concept/collection.hpp>
#include <boost/numeric/mtl/utility/exception.hpp>
#include <boost/numeric/mtl/utility/make_copy_or_reference.hpp>
#include <boost/numeric/mtl/operation/merge_complex_vector.hpp>
#include <boost/numeric/mtl/operation/split_complex_vector.hpp>
#include <boost/numeric/mtl/interface/vpt.hpp>
extern "C" {
# include <umfpack.h>
}
namespace mtl { namespace matrix {
/// Namespace for Umfpack solver
namespace umfpack {
// conversion for value_type needed if not double or complex<double> (where possible)
template <typename Value> struct value {};
template<> struct value<long double> { typedef double type; };
template<> struct value<double> { typedef double type; };
template<> struct value<float> { typedef double type; };
template<> struct value<std::complex<long double> > { typedef std::complex<double> type; };
template<> struct value<std::complex<double> > { typedef std::complex<double> type; };
template<> struct value<std::complex<float> > { typedef std::complex<double> type; };
template <typename Value> struct use_long { static const bool value= sizeof(Value) > sizeof(int); };
template <bool Larger> struct index_aux { typedef int type; };
#if defined(UF_long)
template<> struct index_aux<true> { typedef UF_long type; };
#elif defined(SuiteSparse_long)
template<> struct index_aux<true> { typedef SuiteSparse_long type; };
#else
template<> struct index_aux<true> { typedef long type; };
#endif
template <typename Value> struct index
: index_aux<use_long<Value>::value> {};
template <typename Matrix, typename Value, typename Orientation>
struct matrix_copy {};
// If arbitrary compressed matrix -> copy
template <typename Value, typename Parameters, typename Orientation>
struct matrix_copy<compressed2D<Value, Parameters>, Value, Orientation>
{
typedef typename value<Value>::type value_type;
typedef compressed2D<value_type, parameters<col_major> > matrix_type;
typedef compressed2D<Value, Parameters> in_matrix_type;
matrix_copy(const in_matrix_type& A) : matrix(A) {}
matrix_type matrix;
};
struct error : public domain_error
{
error(const char *s, int code) : domain_error(s), code(code) {}
int code;
};
inline void check(int res, const char* s)
{
MTL_THROW_IF(res != UMFPACK_OK, error(s, res));
}
/// Class for repeated Umfpack solutions
/** Keeps symbolic and numeric preprocessing. Numeric part can be updated.
Only defined for compressed2D<double> and compressed2D<complex<double> >. **/
template <typename T>
class solver {
public:
/// Constructor referring to matrix \p A (not changed) and optionally Umfpack's strategy and alloc_init (look for the specializations)
// \ref solver<compressed2D<double, Parameters> > and \ref solver<compressed2D<std::complex<double>, Parameters> >)
explicit solver(const T& A) {}
/// Update numeric part, for matrices that kept the sparsity and changed the values
void update_numeric() {}
/// Update symbolic and numeric part
void update() {}
/// Solve system A*x == b with matrix passed in constructor
/** Please note that the order of b and x is different than in solve() !!! **/
template <typename VectorX, typename VectorB>
int operator()(VectorX& x, const VectorB& b) const {return 0;}
/// Solve system A*x == b with matrix passed in constructor
/** Please note that the order of b and x is different than in operator() !!! **/
template <typename VectorB, typename VectorX>
int operator()(const VectorB& b, VectorX& x) const {return 0;}
};
/// Speciatization of solver for \ref matrix::compressed2D with double values
template <typename Parameters>
class solver<compressed2D<double, Parameters> >
{
typedef double value_type;
typedef compressed2D<value_type, Parameters> matrix_type;
typedef typename matrix_type::size_type size_type;
typedef typename index<size_type>::type index_type;
static const bool copy_indices= sizeof(index_type) != sizeof(size_type),
long_indices= use_long<size_type>::value;
typedef boost::mpl::bool_<long_indices> blong;
typedef boost::mpl::true_ true_;
typedef boost::mpl::false_ false_;
// typedef parameters<col_major> Parameters;
void assign_pointers()
{
if (copy_indices) {
if (Apc == 0) Apc= new index_type[n + 1];
if (my_nnz != A.nnz() && Aic) { delete[] Aic; Aic= 0; }
if (Aic == 0) Aic= new index_type[A.nnz()];
std::copy(A.address_major(), A.address_major() + n + 1, Apc);
std::copy(A.address_minor(), A.address_minor() + A.nnz(), Aic);
Ap= Apc;
Ai= Aic;
} else {
Ap= reinterpret_cast<const index_type*>(A.address_major());
Ai= reinterpret_cast<const index_type*>(A.address_minor());
}
Ax= A.address_data();
}
void init_aux(true_)
{
check(umfpack_dl_symbolic(n, n, Ap, Ai, Ax, &Symbolic, Control, Info), "Error in dl_symbolic");
check(umfpack_dl_numeric(Ap, Ai, Ax, Symbolic, &Numeric, Control, Info), "Error in dl_numeric");
}
void init_aux(false_)
{
check(umfpack_di_symbolic(n, n, Ap, Ai, Ax, &Symbolic, Control, Info), "Error in di_symbolic");
#if 0
std::cout << "=== INFO of umfpack_*_symbolic ===\n";
std::cout << " UMFPACK_STATUS: " << (Info[UMFPACK_STATUS] == UMFPACK_OK ? "OK" : "ERROR") << "\n";
std::cout << " UMFPACK_NROW: " << Info[UMFPACK_NROW] << "\n";
std::cout << " UMFPACK_NCOL: " << Info[UMFPACK_NCOL] << "\n";
std::cout << " UMFPACK_NZ: " << Info[UMFPACK_NZ] << "\n";
std::cout << " UMFPACK_SIZE_OF_UNIT: " << Info[UMFPACK_SIZE_OF_UNIT] << "\n";
std::cout << " UMFPACK_NDENSE_ROW: " << Info[UMFPACK_NDENSE_ROW] << "\n";
std::cout << " UMFPACK_NEMPTY_ROW: " << Info[UMFPACK_NEMPTY_ROW] << "\n";
std::cout << " UMFPACK_NDENSE_COL: " << Info[UMFPACK_NDENSE_COL] << "\n";
std::cout << " UMFPACK_NEMPTY_COL: " << Info[UMFPACK_NEMPTY_COL] << "\n";
std::cout << " UMFPACK_SYMBOLIC_DEFRAG: " << Info[UMFPACK_SYMBOLIC_DEFRAG] << "\n";
std::cout << " UMFPACK_SYMBOLIC_PEAK_MEMORY: " << Info[UMFPACK_SYMBOLIC_PEAK_MEMORY] << "\n";
std::cout << " UMFPACK_SYMBOLIC_SIZE: " << Info[UMFPACK_SYMBOLIC_SIZE] << "\n";
std::cout << " UMFPACK_VARIABLE_PEAK_ESTIMATE: " << Info[UMFPACK_VARIABLE_PEAK_ESTIMATE] << "\n";
std::cout << " UMFPACK_NUMERIC_SIZE_ESTIMATE: " << Info[UMFPACK_NUMERIC_SIZE_ESTIMATE] << "\n";
std::cout << " UMFPACK_PEAK_MEMORY_ESTIMATE: " << Info[UMFPACK_PEAK_MEMORY_ESTIMATE] << "\n";
std::cout << " UMFPACK_FLOPS_ESTIMATE: " << Info[UMFPACK_FLOPS_ESTIMATE] << "\n";
std::cout << " UMFPACK_LNZ_ESTIMATE: " << Info[UMFPACK_LNZ_ESTIMATE] << "\n";
std::cout << " UMFPACK_UNZ_ESTIMATE: " << Info[UMFPACK_UNZ_ESTIMATE] << "\n";
std::cout << " UMFPACK_MAX_FRONT_SIZE_ESTIMATE: " << Info[UMFPACK_MAX_FRONT_SIZE_ESTIMATE] << "\n";
std::cout << " UMFPACK_SYMBOLIC_TIME: " << Info[UMFPACK_SYMBOLIC_TIME] << "\n";
std::cout << " UMFPACK_SYMBOLIC_WALLTIME: " << Info[UMFPACK_SYMBOLIC_WALLTIME] << "\n";
if (Info[UMFPACK_STRATEGY_USED] == UMFPACK_STRATEGY_SYMMETRIC)
std::cout << " UMFPACK_STRATEGY_USED: SYMMETRIC\n";
else {
if(Info[UMFPACK_STRATEGY_USED] == UMFPACK_STRATEGY_UNSYMMETRIC)
std::cout << " UMFPACK_STRATEGY_USED: UNSYMMETRIC\n";
else {
if (Info[UMFPACK_STRATEGY_USED] == UMFPACK_STRATEGY_2BY2)
std::cout << " UMFPACK_STRATEGY_USED: 2BY2\n";
else
std::cout << " UMFPACK_STRATEGY_USED: UNKOWN STRATEGY " << Info[UMFPACK_STRATEGY_USED] << "\n";
}
}
std::cout << " UMFPACK_ORDERING_USED: " << Info[UMFPACK_ORDERING_USED] << "\n";
std::cout << " UMFPACK_QFIXED: " << Info[UMFPACK_QFIXED] << "\n";
std::cout << " UMFPACK_DIAG_PREFERRED: " << Info[UMFPACK_DIAG_PREFERRED] << "\n";
std::cout << " UMFPACK_ROW_SINGLETONS: " << Info[UMFPACK_ROW_SINGLETONS] << "\n";
std::cout << " UMFPACK_COL_SINGLETONS: " << Info[UMFPACK_COL_SINGLETONS] << "\n";
std::cout << " UMFPACK_PATTERN_SYMMETRY: " << Info[UMFPACK_PATTERN_SYMMETRY] << "\n";
std::cout << " UMFPACK_NZ_A_PLUS_AT: " << Info[UMFPACK_NZ_A_PLUS_AT] << "\n";
std::cout << " UMFPACK_NZDIAG: " << Info[UMFPACK_NZDIAG] << "\n";
std::cout << " UMFPACK_N2: " << Info[UMFPACK_N2] << "\n";
std::cout << " UMFPACK_S_SYMMETRIC: " << Info[UMFPACK_S_SYMMETRIC] << "\n";
std::cout << " UMFPACK_MAX_FRONT_NROWS_ESTIMATE: " << Info[UMFPACK_MAX_FRONT_NROWS_ESTIMATE] << "\n";
std::cout << " UMFPACK_MAX_FRONT_NCOLS_ESTIMATE: " << Info[UMFPACK_MAX_FRONT_NCOLS_ESTIMATE] << "\n";
std::cout << " UMFPACK_SYMMETRIC_LUNZ: " << Info[UMFPACK_SYMMETRIC_LUNZ] << "\n";
std::cout << " UMFPACK_SYMMETRIC_FLOPS: " << Info[UMFPACK_SYMMETRIC_FLOPS] << "\n";
std::cout << " UMFPACK_SYMMETRIC_NDENSE: " << Info[UMFPACK_SYMMETRIC_NDENSE] << "\n";
std::cout << " UMFPACK_SYMMETRIC_DMAX: " << Info[UMFPACK_SYMMETRIC_DMAX] << "\n";
#endif
check(umfpack_di_numeric(Ap, Ai, Ax, Symbolic, &Numeric, Control, Info), "Error in di_numeric");
#if 0
std::cout << "=== INFO of umfpack_*_numeric ===\n";
std::cout << " UMFPACK_STATUS: " << (Info[UMFPACK_STATUS] == UMFPACK_OK ? "OK" : "ERROR") << "\n";
std::cout << " UMFPACK_VARIABLE_PEAK: " << Info[UMFPACK_VARIABLE_PEAK] << "\n";
std::cout << " UMFPACK_PEAK_MEMORY: " << Info[UMFPACK_PEAK_MEMORY] << "\n";
std::cout << " UMFPACK_FLOPS: " << Info[UMFPACK_FLOPS] << "\n";
std::cout << " UMFPACK_LNZ: " << Info[UMFPACK_LNZ] << "\n";
std::cout << " UMFPACK_UNZ: " << Info[UMFPACK_UNZ] << "\n";
std::cout << " UMFPACK_NUMERIC_DEFRAG: " << Info[UMFPACK_NUMERIC_DEFRAG] << "\n";
std::cout << " UMFPACK_NUMERIC_REALLOC: " << Info[UMFPACK_NUMERIC_REALLOC] << "\n";
std::cout << " UMFPACK_NUMERIC_COSTLY_REALLOC: " << Info[UMFPACK_NUMERIC_COSTLY_REALLOC] << "\n";
std::cout << " UMFPACK_COMPRESSED_PATTERN: " << Info[UMFPACK_COMPRESSED_PATTERN] << "\n";
std::cout << " UMFPACK_LU_ENTRIES: " << Info[UMFPACK_LU_ENTRIES] << "\n";
std::cout << " UMFPACK_NUMERIC_TIME: " << Info[UMFPACK_NUMERIC_TIME] << "\n";
std::cout << " UMFPACK_RCOND: " << Info[UMFPACK_RCOND] << "\n";
std::cout << " UMFPACK_UDIAG_NZ: " << Info[UMFPACK_UDIAG_NZ] << "\n";
std::cout << " UMFPACK_UMIN: " << Info[UMFPACK_UMIN] << "\n";
std::cout << " UMFPACK_UMAX: " << Info[UMFPACK_UMAX] << "\n";
std::cout << " UMFPACK_MAX_FRONT_NROWS: " << Info[UMFPACK_MAX_FRONT_NROWS] << "\n";
std::cout << " UMFPACK_MAX_FRONT_NCOLS: " << Info[UMFPACK_MAX_FRONT_NCOLS] << "\n";
std::cout << " UMFPACK_ALL_LNZ: " << Info[UMFPACK_ALL_LNZ] << "\n";
std::cout << " UMFPACK_ALL_UNZ: " << Info[UMFPACK_ALL_UNZ] << "\n";
#endif
}
void init()
{
MTL_THROW_IF(num_rows(A) != num_cols(A), matrix_not_square());
n= num_rows(A);
assign_pointers();
init_aux(blong());
}
public:
/// Constructor referring to matrix \p A (not changed) and optionally Umfpack's strategy and alloc_init
solver(const matrix_type& A, int strategy = UMFPACK_STRATEGY_AUTO, double alloc_init = 0.7)
: A(A), Apc(0), Aic(0), my_nnz(0), Symbolic(0), Numeric(0)
{
vampir_trace<5060> trace;
// Use default setings.
if (long_indices)
umfpack_dl_defaults(Control);
else
umfpack_di_defaults(Control);
Control[UMFPACK_STRATEGY] = strategy;
Control[UMFPACK_ALLOC_INIT] = alloc_init;
init();
}
~solver()
{
vampir_trace<5061> trace;
if (long_indices) {
umfpack_dl_free_numeric(&Numeric);
umfpack_dl_free_symbolic(&Symbolic);
} else {
umfpack_di_free_numeric(&Numeric);
umfpack_di_free_symbolic(&Symbolic);
}
if (Apc) delete[] Apc;
if (Aic) delete[] Aic;
}
void update_numeric_aux(true_)
{
umfpack_dl_free_numeric(&Numeric);
check(umfpack_dl_numeric(Ap, Ai, Ax, Symbolic, &Numeric, Control, Info), "Error in dl_numeric");
}
void update_numeric_aux(false_)
{
umfpack_di_free_numeric(&Numeric);
check(umfpack_di_numeric(Ap, Ai, Ax, Symbolic, &Numeric, Control, Info), "Error in di_numeric");
}
/// Update numeric part, for matrices that kept the sparsity and changed the values
void update_numeric()
{
assign_pointers();
update_numeric_aux(blong());
}
/// Update symbolic and numeric part
void update()
{
if (long_indices) {
umfpack_dl_free_numeric(&Numeric);
umfpack_dl_free_symbolic(&Symbolic);
} else {
umfpack_di_free_numeric(&Numeric);
umfpack_di_free_symbolic(&Symbolic);
}
init();
}
template <typename VectorX, typename VectorB>
void solve_aux(int sys, VectorX& xx, const VectorB& bb, true_)
{
check(umfpack_dl_solve(sys, Ap, Ai, Ax, &xx.value[0], &bb.value[0], Numeric, Control, Info), "Error in dl_solve");
}
template <typename VectorX, typename VectorB>
void solve_aux(int sys, VectorX& xx, const VectorB& bb, false_)
{
check(umfpack_di_solve(sys, Ap, Ai, Ax, &xx.value[0], &bb.value[0], Numeric, Control, Info), "Error in di_solve");
}
/// Solve double system
template <typename VectorX, typename VectorB>
int operator()(VectorX& x, const VectorB& b)
{
vampir_trace<5062> trace;
MTL_THROW_IF(num_rows(A) != size(x) || num_rows(A) != size(b), incompatible_size());
make_in_out_copy_or_reference<dense_vector<value_type>, VectorX> xx(x);
make_in_copy_or_reference<dense_vector<value_type>, VectorB> bb(b);
int sys= mtl::traits::is_row_major<Parameters>::value ? UMFPACK_At : UMFPACK_A;
solve_aux(sys, xx, bb, blong());
return UMFPACK_OK;
}
/// Solve double system
template <typename VectorB, typename VectorX>
int solve(const VectorB& b, VectorX& x) const
{
// return (*this)(x, b);
return const_cast<solver&>(*this)(x, b); // evil hack because Umfpack has no const
}
private:
const matrix_type& A;
int n;
const index_type *Ap, *Ai;
index_type *Apc, *Aic;
size_type my_nnz;
const double *Ax;
double Control[UMFPACK_CONTROL], Info[UMFPACK_INFO];
void *Symbolic, *Numeric;
};
/// Speciatization of solver for \ref matrix::compressed2D with double values
template <typename Parameters>
class solver<compressed2D<std::complex<double>, Parameters> >
{
typedef std::complex<double> value_type;
typedef compressed2D<value_type, Parameters> matrix_type;
typedef typename matrix_type::size_type size_type;
typedef typename index<size_type>::type index_type;
static const bool copy_indices= sizeof(index_type) != sizeof(size_type),
long_indices= use_long<size_type>::value;
typedef boost::mpl::bool_<long_indices> blong;
typedef boost::mpl::true_ true_;
typedef boost::mpl::false_ false_;
void assign_pointers()
{
if (copy_indices) {
if (Apc == 0) Apc= new index_type[n + 1];
if (Aic == 0) Aic= new index_type[A.nnz()];
std::copy(A.address_major(), A.address_major() + n + 1, Apc);
std::copy(A.address_minor(), A.address_minor() + A.nnz(), Aic);
Ap= Apc;
Ai= Aic;
} else {
Ap= reinterpret_cast<const index_type*>(A.address_major());
Ai= reinterpret_cast<const index_type*>(A.address_minor());
}
split_complex_vector(A.data, Ax, Az);
}
void init_aux(true_)
{
check(umfpack_zl_symbolic(n, n, Ap, Ai, &Ax[0], &Az[0], &Symbolic, Control, Info), "Error in zl_symbolic");
check(umfpack_zl_numeric(Ap, Ai, &Ax[0], &Az[0], Symbolic, &Numeric, Control, Info), "Error in zl_numeric");
}
void init_aux(false_)
{
check(umfpack_zi_symbolic(n, n, Ap, Ai, &Ax[0], &Az[0], &Symbolic, Control, Info), "Error in zi_symbolic");
check(umfpack_zi_numeric(Ap, Ai, &Ax[0], &Az[0], Symbolic, &Numeric, Control, Info), "Error in zi_numeric");
}
void initialize()
{
MTL_THROW_IF(num_rows(A) != num_cols(A), matrix_not_square());
n= num_rows(A);
assign_pointers();
init_aux(blong());
}
public:
/// Constructor referring to matrix \p A (not changed) and optionally Umfpack's strategy and alloc_init (look for the specializations)
explicit solver(const compressed2D<value_type, Parameters>& A, int strategy = UMFPACK_STRATEGY_AUTO, double alloc_init = 0.7)
: A(A), Apc(0), Aic(0)
{
vampir_trace<5060> trace;
// Use default setings.
if (long_indices)
umfpack_zl_defaults(Control);
else
umfpack_zi_defaults(Control);
// umfpack_zi_defaults(Control);
Control[UMFPACK_STRATEGY] = strategy;
Control[UMFPACK_ALLOC_INIT] = alloc_init;
initialize();
}
~solver()
{
vampir_trace<5061> trace;
if (long_indices) {
umfpack_zl_free_numeric(&Numeric);
umfpack_zl_free_symbolic(&Symbolic);
} else {
umfpack_zi_free_numeric(&Numeric);
umfpack_zi_free_symbolic(&Symbolic);
}
if (Apc) delete[] Apc;
if (Aic) delete[] Aic;
}
void update_numeric_aux(true_)
{
umfpack_zl_free_numeric(&Numeric);
check(umfpack_zl_numeric(Ap, Ai, &Ax[0], &Az[0], Symbolic, &Numeric, Control, Info), "Error in dl_numeric D");
}
void update_numeric_aux(false_)
{
umfpack_zi_free_numeric(&Numeric);
check(umfpack_zi_numeric(Ap, Ai, &Ax[0], &Az[0], Symbolic, &Numeric, Control, Info), "Error in di_numeric");
}
/// Update numeric part, for matrices that kept the sparsity and changed the values
void update_numeric()
{
assign_pointers();
update_numeric_aux(blong());
}
/// Update symbolic and numeric part
void update()
{
Ax.change_dim(0); Az.change_dim(0);
if (long_indices) {
umfpack_zl_free_numeric(&Numeric);
umfpack_zl_free_symbolic(&Symbolic);
} else {
umfpack_zi_free_numeric(&Numeric);
umfpack_zi_free_symbolic(&Symbolic);
}
initialize();
}
template <typename VectorX, typename VectorB>
void solve_aux(int sys, VectorX& Xx, VectorX& Xz, const VectorB& Bx, const VectorB& Bz, true_)
{
check(umfpack_zl_solve(sys, Ap, Ai, &Ax[0], &Az[0], &Xx[0], &Xz[0], &Bx[0], &Bz[0], Numeric, Control, Info),
"Error in zi_solve");
}
template <typename VectorX, typename VectorB>
void solve_aux(int sys, VectorX& Xx, VectorX& Xz, const VectorB& Bx, const VectorB& Bz, false_)
{
check(umfpack_zi_solve(sys, Ap, Ai, &Ax[0], &Az[0], &Xx[0], &Xz[0], &Bx[0], &Bz[0], Numeric, Control, Info),
"Error in zi_solve");
}
/// Solve complex system
template <typename VectorX, typename VectorB>
int operator()(VectorX& x, const VectorB& b)
{
vampir_trace<5062> trace;
MTL_THROW_IF(num_rows(A) != size(x) || num_rows(A) != size(b), incompatible_size());
dense_vector<double> Xx(size(x)), Xz(size(x)), Bx, Bz;
split_complex_vector(b, Bx, Bz);
int sys= mtl::traits::is_row_major<Parameters>::value ? UMFPACK_Aat : UMFPACK_A;
solve_aux(sys, Xx, Xz, Bx, Bz, blong());
merge_complex_vector(Xx, Xz, x);
return UMFPACK_OK;
}
/// Solve complex system
template <typename VectorB, typename VectorX>
int solve(const VectorB& b, VectorX& x)
{
return (*this)(x, b);
}
private:
const matrix_type& A;
int n;
const index_type *Ap, *Ai;
index_type *Apc, *Aic;
dense_vector<double> Ax, Az;
double Control[UMFPACK_CONTROL], Info[UMFPACK_INFO];
void *Symbolic, *Numeric;
};
template <typename Value, typename Parameters>
class solver<compressed2D<Value, Parameters> >
: matrix_copy<compressed2D<Value, Parameters>, Value, typename Parameters::orientation>,
public solver<typename matrix_copy<compressed2D<Value, Parameters>, Value, typename Parameters::orientation>::matrix_type >
{
typedef matrix_copy<compressed2D<Value, Parameters>, Value, typename Parameters::orientation> copy_type;
typedef solver<typename matrix_copy<compressed2D<Value, Parameters>, Value, typename Parameters::orientation>::matrix_type > solver_type;
public:
explicit solver(const compressed2D<Value, Parameters>& A)
: copy_type(A), solver_type(copy_type::matrix), A(A)
{}
void update()
{
copy_type::matrix= A;
solver_type::update();
}
void update_numeric()
{
copy_type::matrix= A;
solver_type::update_numeric();
}
private:
const compressed2D<Value, Parameters>& A;
};
} // umfpack
/// Solve A*x == b with umfpack
/** Only available when compiled with enabled macro MTL_HAS_UMFPACK.
Uses classes umfpack::solver internally.
If you want more control on single operations or to keep umfpack's
internal factorization, use this class.
**/
template <typename Value, typename Parameters, typename VectorX, typename VectorB>
int umfpack_solve(const compressed2D<Value, Parameters>& A, VectorX& x, const VectorB& b)
{
umfpack::solver<compressed2D<Value, Parameters> > solver(A);
return solver(x, b);
}
}} // namespace mtl::matrix
#endif
#endif // MTL_MATRIX_UMFPACK_SOLVE_INCLUDE
#include <boost/numeric/mtl/interface/vpt.hpp>
#ifdef MTL_HAS_VPT
namespace mtl {
/// Namespace for Vampir Trace interface
namespace vpt {
// Categories:
// Utilities + very small functions: 0000
// Static size operations: 1000
// Vector operations: 2000
// Matrix Vector & single matrix: 3000
// Matrix matrix operations: 4000
// Factorizations, preconditioners: 5000
// Fused operations: 6000
// Iterative solvers: 7000
// Multigrid: 8000
// Utilities: < 1000
template <> std::string vampir_trace<1>::name("copysign");
template <> std::string vampir_trace<2>::name("Elem_raw_copy");
template <> std::string vampir_trace<3>::name("Get_real_part");
template <> std::string vampir_trace<4>::name("Info_contruct_vector");
template <> std::string vampir_trace<5>::name("right_scale_inplace");
template <> std::string vampir_trace<6>::name("sign_real_part_of_complex");
template <> std::string vampir_trace<7>::name("unrolling_expresion");
template <> std::string vampir_trace<8>::name("");
template <> std::string vampir_trace<9>::name("");
template <> std::string vampir_trace<10>::name("squared_abs_magnitudes");
template <> std::string vampir_trace<11>::name("squared_abs_complex");
template <> std::string vampir_trace<12>::name("squared_abs_magnitudes_template");
template <> std::string vampir_trace<13>::name("update_store");
template <> std::string vampir_trace<14>::name("update_plus");
template <> std::string vampir_trace<15>::name("update_minus");
template <> std::string vampir_trace<16>::name("update_times");
template <> std::string vampir_trace<17>::name("update_adapter");
template <> std::string vampir_trace<18>::name("");
template <> std::string vampir_trace<19>::name("");
template <> std::string vampir_trace<20>::name("update_proxy_<<");
template <> std::string vampir_trace<21>::name("update_proxy_=");
template <> std::string vampir_trace<22>::name("update_proxy_+=");
template <> std::string vampir_trace<23>::name("sfunctor::plus");
template <> std::string vampir_trace<24>::name("sfunctor::minus");
template <> std::string vampir_trace<25>::name("sfunctor::times");
template <> std::string vampir_trace<26>::name("sfunctor::divide");
template <> std::string vampir_trace<27>::name("sfunctor::assign");
template <> std::string vampir_trace<28>::name("sfunctor::plus_assign");
template <> std::string vampir_trace<29>::name("sfunctor::minus_assign");
template <> std::string vampir_trace<30>::name("sfunctor::times_assign");
template <> std::string vampir_trace<31>::name("sfunctor::divide_assign");
template <> std::string vampir_trace<32>::name("sfunctor::identity");
template <> std::string vampir_trace<33>::name("sfunctor::abs");
template <> std::string vampir_trace<34>::name("sfunctor::sqrt");
template <> std::string vampir_trace<35>::name("sfunctor::square");
template <> std::string vampir_trace<36>::name("sfunctor::negate");
template <> std::string vampir_trace<37>::name("sfunctor::compose");
template <> std::string vampir_trace<38>::name("sfunctor::compose_first");
template <> std::string vampir_trace<39>::name("sfunctor::compose_second");
template <> std::string vampir_trace<40>::name("sfunctor::compose_both");
template <> std::string vampir_trace<41>::name("sfunctor::compose_binary");
template <> std::string vampir_trace<42>::name("");
template <> std::string vampir_trace<43>::name("");
template <> std::string vampir_trace<44>::name("");
template <> std::string vampir_trace<45>::name("");
// Fine-grained vector operations
template <> std::string vampir_trace<236>::name("Vector_swapped_row");
// Static size operations: 1000
template <> std::string vampir_trace<1001>::name("stat_vec_expr");
template <> std::string vampir_trace<1002>::name("fsize_dmat_dmat_mult");
template <> std::string vampir_trace<1003>::name("vector_size_static");
template <> std::string vampir_trace<1004>::name("static_dispatch"); // ?? row_in_matrix.hpp:74
template <> std::string vampir_trace<1005>::name("copy_blocks_forward");
template <> std::string vampir_trace<1006>::name("copy_blocks_backward");
template <> std::string vampir_trace<1007>::name("Static_Size");
template <> std::string vampir_trace<1008>::name("fsize_mat_vect_mult");
template <> std::string vampir_trace<1009>::name("");
template <> std::string vampir_trace<1010>::name("");
template <> std::string vampir_trace<1011>::name("");
template <> std::string vampir_trace<1012>::name("");
template <> std::string vampir_trace<1013>::name("");
template <> std::string vampir_trace<1014>::name("");
template <> std::string vampir_trace<1015>::name("");
template <> std::string vampir_trace<1016>::name("");
template <> std::string vampir_trace<1017>::name("");
template <> std::string vampir_trace<1018>::name("");
template <> std::string vampir_trace<1019>::name("");
template <> std::string vampir_trace<1020>::name("");
// Vector operations: 2000
template <> std::string vampir_trace<2001>::name("gen_vector_copy");
template <> std::string vampir_trace<2002>::name("cross");
template <> std::string vampir_trace<2003>::name("dot");
template <> std::string vampir_trace<2004>::name("householder");
template <> std::string vampir_trace<2005>::name("householder_s");
template <> std::string vampir_trace<2006>::name("vector::infinity_norm");
template <> std::string vampir_trace<2007>::name("vector::look_at_each_nonzero");
template <> std::string vampir_trace<2008>::name("vector::look_at_each_nonzero_pos");
template <> std::string vampir_trace<2009>::name("vector::reduction");
template <> std::string vampir_trace<2010>::name("vector::max");
template <> std::string vampir_trace<2011>::name("vector::max_abs_pos");
template <> std::string vampir_trace<2012>::name("max_of_sums");
template <> std::string vampir_trace<2013>::name("vector::max_pos");
template <> std::string vampir_trace<2014>::name("merge_complex_vector");
template <> std::string vampir_trace<2015>::name("vector::one_norm");
template <> std::string vampir_trace<2016>::name("vector::diagonal");
template <> std::string vampir_trace<2017>::name("dyn_vec_expr");
template <> std::string vampir_trace<2018>::name("Orthogonalize_Vectors");
template <> std::string vampir_trace<2019>::name("Orthogonalize_Factors");
template <> std::string vampir_trace<2020>::name("Vector_product");
template <> std::string vampir_trace<2021>::name("Vector_random");
template <> std::string vampir_trace<2022>::name("Vec_Vec_rank_update");
template <> std::string vampir_trace<2023>::name("Vector_dispatch");
template <> std::string vampir_trace<2024>::name("Vector_rscale");
template <> std::string vampir_trace<2025>::name("Multi-vector_mult");
template <> std::string vampir_trace<2026>::name("Transp_Multi-vector_mult");
template <> std::string vampir_trace<2027>::name("Hermitian_Multi-vector_mult");
template <> std::string vampir_trace<2028>::name("Vector_scal");
template <> std::string vampir_trace<2029>::name("Vector_set_zero");
template <> std::string vampir_trace<2030>::name("Vector_size1D");
template <> std::string vampir_trace<2031>::name("Vector_size_runtime");
template <> std::string vampir_trace<2032>::name("Vect_quicksort_lo_to_hi");
template <> std::string vampir_trace<2033>::name("Vect_quicksort_permutaion_lo_to_hi");
template <> std::string vampir_trace<2034>::name("split_complex_vector");
template <> std::string vampir_trace<2035>::name("Vect_entries_sum");
template <> std::string vampir_trace<2037>::name("Vector_const_trans");
template <> std::string vampir_trace<2038>::name("Vector_trans");
template <> std::string vampir_trace<2039>::name("vector::two_norm");
template <> std::string vampir_trace<2040>::name("dot_simple");
template <> std::string vampir_trace<2041>::name("unary_dot");
template <> std::string vampir_trace<2042>::name("dense_vector::copy_ctor");
template <> std::string vampir_trace<2043>::name("dense_vector::tpl_copy_ctor");
template <> std::string vampir_trace<2044>::name("");
template <> std::string vampir_trace<2045>::name("");
template <> std::string vampir_trace<2046>::name("");
template <> std::string vampir_trace<2047>::name("");
template <> std::string vampir_trace<2048>::name("");
template <> std::string vampir_trace<2049>::name("");
template <> std::string vampir_trace<2050>::name("");
template <> std::string vampir_trace<2051>::name("");
template <> std::string vampir_trace<2052>::name("");
// Matrix Vector & single matrix: 3000
template <> std::string vampir_trace<3001>::name("matrix_copy_ele_times");
template <> std::string vampir_trace<3002>::name("gen_matrix_copy");
template <> std::string vampir_trace<3003>::name("copy");
template <> std::string vampir_trace<3004>::name("clone");
template <> std::string vampir_trace<3005>::name("compute_summand");
template <> std::string vampir_trace<3006>::name("crop");
template <> std::string vampir_trace<3007>::name("matrix::diagonal");
template <> std::string vampir_trace<3008>::name("assign_each_nonzero");
template <> std::string vampir_trace<3009>::name("fill");
template <> std::string vampir_trace<3010>::name("frobenius_norm");
template <> std::string vampir_trace<3011>::name("matrix::infinity_norm");
template <> std::string vampir_trace<3012>::name("invert_diagonal");
template <> std::string vampir_trace<3013>::name("iota");
template <> std::string vampir_trace<3014>::name("left_scale_inplace");
template <> std::string vampir_trace<3015>::name("matrix::look_at_each_nonzero");
template <> std::string vampir_trace<3016>::name("matrix::look_at_each_nonzero_pos");
template <> std::string vampir_trace<3017>::name("fsize_dense_mat_cvec_mult");
template <> std::string vampir_trace<3018>::name("dense_mat_cvec_mult");
template <> std::string vampir_trace<3019>::name("mvec_cvec_mult");
template <> std::string vampir_trace<3020>::name("trans_mvec_cvec_mult");
template <> std::string vampir_trace<3021>::name("herm_mvec_cvec_mult");
template <> std::string vampir_trace<3022>::name("sparse_row_cvec_mult"); // generic row-major sparse
template <> std::string vampir_trace<3023>::name("ccs_cvec_mult");
template <> std::string vampir_trace<3024>::name("matrix::max_abs_pos");
template <> std::string vampir_trace<3025>::name("matrix::one_norm");
template <> std::string vampir_trace<3026>::name("invert_diagonal(compressed)");
template <> std::string vampir_trace<3027>::name("mat_vect_mult");
template <> std::string vampir_trace<3028>::name("Vect_sparse_mat_mult");
template <> std::string vampir_trace<3029>::name("Matrix_scal");
template <> std::string vampir_trace<3030>::name("Vector_Secular_Equation");
template <> std::string vampir_trace<3031>::name("Matrix_set_zero");
template <> std::string vampir_trace<3032>::name("Matrix_size1D");
template <> std::string vampir_trace<3033>::name("Matrix_size_runtime");
template <> std::string vampir_trace<3034>::name("Matrix_LU");
template <> std::string vampir_trace<3035>::name("Vector_Matrix_LU");
template <> std::string vampir_trace<3036>::name("Sub_matrix_indices");
template <> std::string vampir_trace<3037>::name("Matrix_svd_reference");
template <> std::string vampir_trace<3038>::name("Matrix_svd_triplet");
template <> std::string vampir_trace<3039>::name("Matrix_swapped");
template <> std::string vampir_trace<3040>::name("Matrix_Trace");
template <> std::string vampir_trace<3041>::name("Matrix_const_trans");
template <> std::string vampir_trace<3042>::name("Matrix_trans");
template <> std::string vampir_trace<3043>::name("Matrix_upper_trisolve");
template <> std::string vampir_trace<3044>::name("Matrix_upper_trisolve_diagonal");
template <> std::string vampir_trace<3045>::name("Matrix_upper_trisolve_invers_diag");
template <> std::string vampir_trace<3046>::name("Matrix_upper_trisolve_DiaTag");
template <> std::string vampir_trace<3047>::name("scalar_assign");
template <> std::string vampir_trace<3048>::name("elest_cvec_mult");
template <> std::string vampir_trace<3049>::name("crs_cvec_mult");
template <> std::string vampir_trace<3050>::name("sparse_ins::ctor");
template <> std::string vampir_trace<3051>::name("sparse_ins::dtor");
template <> std::string vampir_trace<3052>::name("sparse_ins::stretch");
template <> std::string vampir_trace<3053>::name("sparse_ins::final_place");
template <> std::string vampir_trace<3054>::name("sparse_ins::insert_spare");
template <> std::string vampir_trace<3055>::name("mat_crtp_scal_assign");
template <> std::string vampir_trace<3056>::name("mat_crtp_mat_assign");
template <> std::string vampir_trace<3057>::name("mat_crtp_sum_assign");
template <> std::string vampir_trace<3058>::name("mat_crtp_diff_assign");
template <> std::string vampir_trace<3059>::name("mat_crtp_array_assign");
template <> std::string vampir_trace<3060>::name("mat_crtp_mvec_assign");
template <> std::string vampir_trace<3061>::name("copy_band_to_sparse");
template <> std::string vampir_trace<3062>::name("block_dia_times_cvec");
template <> std::string vampir_trace<3063>::name("laplacian_setup");
template <> std::string vampir_trace<3064>::name("vsmat_cvec_mult");
template <> std::string vampir_trace<3065>::name("adapt_crs_cvec_mult");
template <> std::string vampir_trace<3066>::name("dense2D_cvec_mult");
template <> std::string vampir_trace<3067>::name("square_cvec_mult");
template <> std::string vampir_trace<3068>::name("mat_cvec_multiplier");
template <> std::string vampir_trace<3069>::name("sbanded_cvec_mult");
template <> std::string vampir_trace<3070>::name("");
template <> std::string vampir_trace<3071>::name("");
template <> std::string vampir_trace<3072>::name("");
template <> std::string vampir_trace<3073>::name("");
template <> std::string vampir_trace<3074>::name("");
template <> std::string vampir_trace<3075>::name("");
template <> std::string vampir_trace<3076>::name("");
template <> std::string vampir_trace<3077>::name("");
template <> std::string vampir_trace<3078>::name("");
template <> std::string vampir_trace<3079>::name("");
// Matrix matrix operations: 4000
template <> std::string vampir_trace<4001>::name("cursor_dmat_dmat_mult");
template <> std::string vampir_trace<4002>::name("dmat_dmat_mult");
template <> std::string vampir_trace<4003>::name("tiling_dmat_dmat_mult");
template <> std::string vampir_trace<4004>::name("tiling_44_dmat_dmat_mult");
template <> std::string vampir_trace<4005>::name("tiling_22_dmat_dmat_mult");
template <> std::string vampir_trace<4006>::name("wrec_dmat_dmat_mult");
template <> std::string vampir_trace<4007>::name("recursive_dmat_dmat_mult");
template <> std::string vampir_trace<4008>::name("xgemm");
template <> std::string vampir_trace<4009>::name("");
template <> std::string vampir_trace<4010>::name("mult");
template <> std::string vampir_trace<4011>::name("gen_mult");
template <> std::string vampir_trace<4012>::name("mat_mat_mult");
template <> std::string vampir_trace<4013>::name("matrix_qr");
template <> std::string vampir_trace<4014>::name("matrix_qr_factors");
template <> std::string vampir_trace<4015>::name("matrix_random");
template <> std::string vampir_trace<4016>::name("matrix_scale_inplace");
template <> std::string vampir_trace<4017>::name("matrix_rscale");
template <> std::string vampir_trace<4018>::name("matrix_gen_smat_dmat_mult");
template <> std::string vampir_trace<4019>::name("matrix_gen_tiling_smat_dmat_mult");
template <> std::string vampir_trace<4020>::name("matrix_smat_smat_mult");
template <> std::string vampir_trace<4021>::name("");
template <> std::string vampir_trace<4022>::name("");
template <> std::string vampir_trace<4023>::name("");
template <> std::string vampir_trace<4024>::name("");
template <> std::string vampir_trace<4025>::name("");
template <> std::string vampir_trace<4026>::name("");
template <> std::string vampir_trace<4027>::name("");
template <> std::string vampir_trace<4028>::name("");
template <> std::string vampir_trace<4029>::name("");
template <> std::string vampir_trace<4030>::name("");
template <> std::string vampir_trace<4031>::name("");
template <> std::string vampir_trace<4032>::name("");
template <> std::string vampir_trace<4033>::name("");
template <> std::string vampir_trace<4034>::name("");
template <> std::string vampir_trace<4035>::name("");
template <> std::string vampir_trace<4036>::name("read_el_matrix");
template <> std::string vampir_trace<4037>::name("");
template <> std::string vampir_trace<4038>::name("");
template <> std::string vampir_trace<4039>::name("");
template <> std::string vampir_trace<4040>::name("");
template <> std::string vampir_trace<4041>::name("");
// Factorizations, preconditioners: 5000
template <> std::string vampir_trace<5001>::name("cholesky_base");
template <> std::string vampir_trace<5002>::name("cholesky_solve_base");
template <> std::string vampir_trace<5003>::name("cholesky_schur_base");
template <> std::string vampir_trace<5004>::name("cholesky_update_base");
template <> std::string vampir_trace<5005>::name("cholesky_schur_update");
template <> std::string vampir_trace<5006>::name("cholesky_tri_solve");
template <> std::string vampir_trace<5007>::name("cholesky_tri_schur");
template <> std::string vampir_trace<5008>::name("recursive cholesky");
template <> std::string vampir_trace<5009>::name("fill_matrix_for_cholesky");
template <> std::string vampir_trace<5010>::name("qr_sym_imp");
template <> std::string vampir_trace<5011>::name("qr_algo");
template <> std::string vampir_trace<5012>::name("eigenvalue_symmetric");
template <> std::string vampir_trace<5013>::name("hessenberg_q");
template <> std::string vampir_trace<5014>::name("hessenberg_factors");
template <> std::string vampir_trace<5015>::name("extract_householder_hessenberg");
template <> std::string vampir_trace<5016>::name("householder_hessenberg");
template <> std::string vampir_trace<5017>::name("extract_hessenberg");
template <> std::string vampir_trace<5018>::name("hessenberg");
template <> std::string vampir_trace<5019>::name("inv_upper");
template <> std::string vampir_trace<5020>::name("inv_lower");
template <> std::string vampir_trace<5021>::name("inv");
template <> std::string vampir_trace<5022>::name("lower_trisolve");
template <> std::string vampir_trace<5023>::name("lu");
template <> std::string vampir_trace<5024>::name("lu(pivot)");
template <> std::string vampir_trace<5025>::name("lu_f");
template <> std::string vampir_trace<5026>::name("lu_solve_straight");
template <> std::string vampir_trace<5027>::name("lu_apply");
template <> std::string vampir_trace<5028>::name("lu_solve");
template <> std::string vampir_trace<5029>::name("lu_adjoint_apply");
template <> std::string vampir_trace<5030>::name("lu_adjoint_solve");
template <> std::string vampir_trace<5031>::name("pc::id::solve");
template <> std::string vampir_trace<5032>::name("pc::id.solve");
template <> std::string vampir_trace<5033>::name("pc::id::adjoint_solve");
template <> std::string vampir_trace<5034>::name("pc::id.adjoint_solve");
template <> std::string vampir_trace<5035>::name("ic_0::factorize");
template <> std::string vampir_trace<5036>::name("ic_0::solve");
template <> std::string vampir_trace<5037>::name("ic_0::solve_nocopy");
template <> std::string vampir_trace<5038>::name("ilu_0::factorize");
template <> std::string vampir_trace<5039>::name("ilu_0::solve");
template <> std::string vampir_trace<5040>::name("ilu_0::adjoint_solve");
template <> std::string vampir_trace<5041>::name("lower_trisolve_kernel");
template <> std::string vampir_trace<5042>::name("upper_trisolve_row");
template <> std::string vampir_trace<5043>::name("upper_trisolve_col");
template <> std::string vampir_trace<5044>::name("ic_0::adjoint_solve");
template <> std::string vampir_trace<5045>::name("ic_0::adjoint_solve_nocopy");
template <> std::string vampir_trace<5046>::name("upper_trisolve_crs_compact");
template <> std::string vampir_trace<5047>::name("lower_trisolve_crs_compact");
template <> std::string vampir_trace<5048>::name("lower_unit_trisolve_crs_compact");
template <> std::string vampir_trace<5049>::name("ilut::factorize");
template <> std::string vampir_trace<5050>::name("diagonal::setup");
template <> std::string vampir_trace<5051>::name("diagonal::solve");
template <> std::string vampir_trace<5052>::name("imf::factor");
template <> std::string vampir_trace<5053>::name("imf::ctor");
template <> std::string vampir_trace<5054>::name("imf::solve");
template <> std::string vampir_trace<5055>::name("pc::solver::assign_to");
template <> std::string vampir_trace<5056>::name("sub_matrix_pc::solve");
template <> std::string vampir_trace<5057>::name("sub_matrix_pc::adjoint_solve");
template <> std::string vampir_trace<5058>::name("pc::concat::solve");
template <> std::string vampir_trace<5059>::name("pc::concat::adjoint_solve");
template <> std::string vampir_trace<5060>::name("umfpack::solver::ctor");
template <> std::string vampir_trace<5061>::name("umfpack::solver::dtor");
template <> std::string vampir_trace<5062>::name("umfpack::solve");
// Fused operations: 6000
template <> std::string vampir_trace<6001>::name("fused::fwd_eval_loop");
template <> std::string vampir_trace<6002>::name("fused::fwd_eval_loop_unrolled");
template <> std::string vampir_trace<6003>::name("fused::bwd_eval_loop");
template <> std::string vampir_trace<6004>::name("fused::bwd_eval_loop_unrolled");
// Iterative solvers: 7000
template <> std::string vampir_trace<7001>::name("cg_without_pc");
template <> std::string vampir_trace<7002>::name("cg");
template <> std::string vampir_trace<7003>::name("bicg");
template <> std::string vampir_trace<7004>::name("bicgstab");
template <> std::string vampir_trace<7005>::name("bicgstab_2");
template <> std::string vampir_trace<7006>::name("bicgstab_ell");
template <> std::string vampir_trace<7007>::name("cgs");
template <> std::string vampir_trace<7008>::name("qmr");
template <> std::string vampir_trace<7009>::name("tfqmr");
template <> std::string vampir_trace<7010>::name("idr_s");
// OpenMP
template <> std::string vampir_trace<8001>::name("omp::dot");
template <> std::string vampir_trace<8002>::name("omp::reduction");
template <> std::string vampir_trace<8003>::name("omp::dyn_vec_expr");
template <> std::string vampir_trace<8004>::name("omp::crs_cvec_mult");
// multigrid
template <> std::string vampir_trace<8501>::name("mtl::mg::v_cycle");
template <> std::string vampir_trace<8502>::name("mtl::mg::w_cycle");
template <> std::string vampir_trace<8503>::name("mtl::mg::fmg");
template <> std::string vampir_trace<8504>::name("mtl::mg::two_grid_cycle");
template <> std::string vampir_trace<8510>::name("mtl::mg::geometric_multigrid_solver_impl");
template <> std::string vampir_trace<8511>::name("mtl::mg::geometric_multigrid_solver_solve1");
template <> std::string vampir_trace<8512>::name("mtl::mg::geometric_multigrid_solver_solve2");
template <> std::string vampir_trace<8515>::name("mtl::mg::algebraic_multigrid_solver");
template <> std::string vampir_trace<8516>::name("amg_pc::solve");
template <> std::string vampir_trace<8520>::name("mtl::mg::linear_restriction");
template <> std::string vampir_trace<8521>::name("mtl::mg::linear_prolongation");
template <> std::string vampir_trace<8530>::name("mtl::mg::gauss_elimination");
template <> std::string vampir_trace<8531>::name("mtl::mg::back_substitution");
template <> std::string vampir_trace<8550>::name("mtl::mg::jacobi");
template <> std::string vampir_trace<8551>::name("mtl::mg::gauss_seidel");
template <> std::string vampir_trace<8552>::name("mtl::mg::jor");
template <> std::string vampir_trace<8553>::name("mtl::mg::sor");
template <> std::string vampir_trace<8572>::name("boundaries");
template <> std::string vampir_trace<8573>::name("viscosity");
template <> std::string vampir_trace<8574>::name("pressure_correction");
template <> std::string vampir_trace<8590>::name("mtl::mg::util::vtk_exporter");
template <> std::string vampir_trace<8591>::name("mtl::mg::util::csv_exporter");
template <> std::string vampir_trace<8610>::name("amg::amg_matrix_hierarchy");
template <> std::string vampir_trace<8611>::name("amg::compute_influence");
template <> std::string vampir_trace<8612>::name("amg::default_coarse_grid_detection::compute_C");
template <> std::string vampir_trace<8614>::name("amg::utils::compute_potentials");
template <> std::string vampir_trace<8615>::name("amg::utils::find_max_pos");
template <> std::string vampir_trace<8617>::name("amg::amg_prolongation");
template <> std::string vampir_trace<8618>::name("amg::compute_weight");
template <> std::string vampir_trace<8619>::name("amg::compute_mfactors");
template <> std::string vampir_trace<8620>::name("amg::strongly_influenced_points");
template <> std::string vampir_trace<8621>::name("amg::is_strongly_influenced");
template <> std::string vampir_trace<8622>::name("amg::strongly_influencing_points");
template <> std::string vampir_trace<8630>::name("amg::amg_operators::amg_restriction");
template <> std::string vampir_trace<8631>::name("amg::amg_operators::amg_prolongation");
template <> std::string vampir_trace<8635>::name("amg::amg_operators::amg_weight");
template <> std::string vampir_trace<8900>::name("NaSto::solve()");
template <> std::string vampir_trace<8910>::name("NaSto::computeGamma()");
template <> std::string vampir_trace<8920>::name("NaSto::computeBoundaries()");
template <> std::string vampir_trace<8930>::name("NaSto::computeImplViscosity()");
template <> std::string vampir_trace<8940>::name("NaSto::computePressureCorr()");
// Test blocks for performance debugging
template <> std::string vampir_trace<9901>::name("tb1");
template <> std::string vampir_trace<9902>::name("tb2");
template <> std::string vampir_trace<9903>::name("tb3");
template <> std::string vampir_trace<9904>::name("tb4");
template <> std::string vampir_trace<9999>::name("main");
// Only for testing
template <> std::string vampir_trace<9990>::name("helper_function");
template <> std::string vampir_trace<9991>::name("function");
}} //mtl::vpt
#endif //MTL_HAS_VPT
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
#ifndef MTL_VPT_VPT_INCLUDE
#define MTL_VPT_VPT_INCLUDE
#ifdef MTL_HAS_VPT
#include <vt_user.h>
#include <boost/mpl/bool.hpp>
#endif
#include <math.h>
#include <string>
namespace mtl {
/// Namespace for Vampir Trace interface
namespace vpt {
#ifdef MTL_HAS_VPT
#ifndef MTL_VPT_LEVEL
# define MTL_VPT_LEVEL 2
#endif
/// Class for Vampir Trace
template <int N>
class vampir_trace
{
// Statically determine whether the event is traced; just in case you wanted to know how.
typedef boost::mpl::bool_<(MTL_VPT_LEVEL * 1000 < N)> to_print;
public:
/// Default constructor defines the start point of a trace
vampir_trace() { entry(to_print()); }
void entry(boost::mpl::false_) {}
void entry(boost::mpl::true_)
{
VT_USER_START(name.c_str());
// std::cout << "vpt_entry(" << N << ")\n";
}
/// Destructor defines the end point of a trace
~vampir_trace() { end(to_print()); }
void end(boost::mpl::false_) {}
void end(boost::mpl::true_)
{
VT_USER_END(name.c_str());
// std::cout << "vpt_end(" << N << ")\n";
}
/// Function to check whether this event is traced with the current setting
bool is_traced() { return to_print::value; }
private:
static std::string name;
};
#else
// Dummy when Vampir Trace is not supported
template <int N>
class vampir_trace
{
public:
vampir_trace() {}
void show_vpt_level() {}
bool is_traced() { return false; }
private:
static std::string name;
};
#endif
// names defined in vpt.cpp !!!
} // namespace vpt
/// Import of vpt::vampir_trace
using vpt::vampir_trace;
} // namespace mtl
#endif // MTL_VPT_VPT_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
#ifndef MTL_INTERFACES_INCLUDE
#define MTL_INTERFACES_INCLUDE
#include <boost/numeric/mtl/interface/vpt.hpp>
#endif // MTL_INTERFACES_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG, www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also tools/license/license.mtl.txt in the distribution.
#ifndef MTL_IO_FUNCTOR_SYMBOL_INCLUDE
#define MTL_IO_FUNCTOR_SYMBOL_INCLUDE
#include <boost/numeric/mtl/mtl_fwd.hpp>
namespace mtl { namespace io {
template <typename Value>
std::string functor_symbol(const sfunctor::conj<Value>&)
{ return "conj"; }
template <typename Value>
std::string functor_symbol(const sfunctor::imag<Value>&)
{ return "imag"; }
template <typename Value>
std::string functor_symbol(const sfunctor::real<Value>&)
{ return "real"; }
template <typename Value>
std::string functor_symbol(const sfunctor::identity<Value>&)
{ return "identity"; }
template <typename Value>
std::string functor_symbol(const sfunctor::abs<Value>&)
{ return "abs"; }
template <typename Value>
std::string functor_symbol(const sfunctor::sqrt<Value>&)
{ return "sqrt"; }
template <typename Value>
std::string functor_symbol(const sfunctor::square<Value>&)
{ return "square"; }
template <typename Value>
std::string functor_symbol(const sfunctor::negate<Value>&)
{ return "-"; }
template <typename Value1, typename Value2>
std::string functor_symbol(const sfunctor::minus<Value1, Value2>&)
{ return "-"; }
template <typename Value1, typename Value2>
std::string functor_symbol(const sfunctor::plus<Value1, Value2>&)
{ return "+"; }
template <typename Value1, typename Value2>
std::string functor_symbol(const sfunctor::times<Value1, Value2>&)
{ return "*"; }
template <typename Value1, typename Value2>
std::string functor_symbol(const sfunctor::divide<Value1, Value2>&)
{ return "/"; }
template <typename Value1, typename Value2>
std::string functor_symbol(const sfunctor::assign<Value1, Value2>&)
{ return "="; }
template <typename Value1, typename Value2>
std::string functor_symbol(const sfunctor::plus_assign<Value1, Value2>&)
{ return "+="; }
template <typename Value1, typename Value2>
std::string functor_symbol(const sfunctor::minus_assign<Value1, Value2>&)
{ return "-="; }
template <typename Value1, typename Value2>
std::string functor_symbol(const sfunctor::times_assign<Value1, Value2>&)
{ return "*="; }
template <typename Value1, typename Value2>
std::string functor_symbol(const sfunctor::divide_assign<Value1, Value2>&)
{ return "/="; }
}} // namespace mtl::io
#endif // MTL_IO_FUNCTOR_SYMBOL_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
#ifndef MTL_IO_MATRIX_FILE_INCLUDE
#define MTL_IO_MATRIX_FILE_INCLUDE
namespace mtl { namespace io {
template <typename MatrixIFStream, typename MatrixOFStream>
class matrix_file
{
public:
explicit matrix_file(const std::string& fname) : fname(fname) {}
explicit matrix_file(const char* fname) : fname(fname) {}
std::string file_name() const { return fname; }
template <typename Collection>
matrix_file& operator=(const Collection& c)
{
MatrixOFStream stream(fname);
stream << c;
return *this;
}
protected:
std::string fname;
};
}} // namespace mtl::io
#endif // MTL_IO_MATRIX_FILE_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
#ifndef MTL_IO_MATRIX_MARKET_INCLUDE
#define MTL_IO_MATRIX_MARKET_INCLUDE
#include <string>
#include <fstream>
#include <iostream>
#include <limits>
#include <locale>
#include <complex>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_floating_point.hpp>
#include <boost/type_traits/is_integral.hpp>
// #include <boost/algorithm/string/case_conv.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <boost/numeric/mtl/io/matrix_file.hpp>
#include <boost/numeric/mtl/io/read_filter.hpp>
#include <boost/numeric/mtl/utility/property_map.hpp>
#include <boost/numeric/mtl/utility/range_generator.hpp>
#include <boost/numeric/mtl/utility/exception.hpp>
#include <boost/numeric/mtl/utility/tag.hpp>
#include <boost/numeric/mtl/utility/category.hpp>
#include <boost/numeric/mtl/utility/string_to_enum.hpp>
#include <boost/numeric/mtl/matrix/inserter.hpp>
#include <boost/numeric/mtl/operation/set_to_zero.hpp>
namespace mtl { namespace io {
/// Input file stream for files in matrix market format
class matrix_market_istream
{
class pattern_type {};
typedef matrix_market_istream self;
void check_stream(const std::string& file_name= std::string()) // not const to delete new_stream
{
if (!my_stream.good()) {
std::string message("matrix_market_istream: Error in input stream!\n");
if (file_name != std::string())
message+= "Probably file " + file_name + " not found.\n";
std::cerr << message;
if (new_stream)
delete new_stream, new_stream= 0; // To get valgrind quite
throw(file_not_found(message.c_str()));
}
}
public:
explicit matrix_market_istream(const char* p) : new_stream(new std::ifstream(p)), my_stream(*new_stream) { check_stream(p); }
explicit matrix_market_istream(const std::string& s) : new_stream(new std::ifstream(s.c_str())), my_stream(*new_stream) { check_stream(s); }
explicit matrix_market_istream(std::istream& s= std::cin) : new_stream(0), my_stream(s) { check_stream(); }
~matrix_market_istream()
{ if (new_stream) delete new_stream; }
template <typename Coll>
self& operator>>(Coll& c)
{ return read(c, typename mtl::traits::category<Coll>::type()); }
/// Close only my own file, i.e. if filename and not stream is passed in constructor
void close() { if (new_stream) new_stream->close(); }
protected:
template <typename Matrix> self& read(Matrix& A, tag::matrix);
void to_lower(std::string& s) const
{
using namespace std;
for (unsigned i= 0; i < s.size(); i++)
s[i]= tolower(s[i]);
}
void set_symmetry(std::string& symmetry_text)
{
to_lower(symmetry_text);
const char* symmetry_options[]= {"general", "symmetric", "skew-symmetric", "hermitian"};
my_symmetry= string_to_enum(symmetry_text, symmetry_options, symmetry());
}
void set_sparsity(std::string& sparsity_text)
{
to_lower(sparsity_text);
const char* sparsity_options[]= {"coordinate", "array"};
my_sparsity= string_to_enum(sparsity_text, sparsity_options, sparsity());
}
template <typename Inserter, typename Value>
void read_matrix(Inserter& ins, Value)
{
typedef typename Collection<typename Inserter::matrix_type>::size_type size_type;
read_filter<Inserter> filter(ins);
if (my_sparsity == coordinate) // sparse
// while (my_stream) { // sometimes does an extra erroneous loop
for (std::size_t i= 0; i < nnz; i++) {
size_type r, c;
my_stream >> r >> c;
if (!my_stream) break; // in case while(my_stream) caught an empty line at the end
insert_value(ins, r-1, c-1, filter, Value());
}
else // dense
for (std::size_t c= 0; c < ncols; c++)
for (std::size_t r= 0; r < nrows; r++)
insert_value(ins, r, c, filter, Value());
}
template <typename Inserter, typename Filter, typename Value>
void insert_value(Inserter& ins, std::size_t r, std::size_t c, const Filter& filter, Value)
{
using mtl::conj;
typedef typename Collection<typename Inserter::matrix_type>::value_type mvt;
Value v;
read_value(v);
// std::cout << "Going to insert at [" << r << "][" << c << "] value " << which_value(v, mvt()) << "\n";
if (filter(r, c))
ins[r][c] << which_value(v, mvt());
if (r != c && filter(c, r))
switch(my_symmetry) {
case symmetric: ins[c][r] << which_value(v, mvt()); break;
case skew: ins[c][r] << -which_value(v, mvt()); break;
case Hermitian: ins[c][r] << conj(which_value(v, mvt())); break;
default: ; // do nothing
}
}
void read_value(pattern_type) {}
void read_value(double& v) { my_stream >> v;}
void read_value(long& v) { my_stream >> v;}
void read_value(std::complex<double>& v)
{
double r, i; my_stream >> r >> i; v= std::complex<double>(r, i);
}
// Which value to be inserted? Itself if exist and 0 for pattern; complex are
template <typename Value, typename MValue> MValue which_value(Value v, MValue) { return boost::numeric_cast<MValue>(v); }
template <typename MValue> MValue which_value(pattern_type, MValue) { return boost::numeric_cast<MValue>(0.0); }
template <typename MValue> MValue which_value(std::complex<double>, MValue) { MTL_THROW(runtime_error("Cannot convert complex value in real\n")); return 1; }
std::complex<long double> which_value(std::complex<double> v, std::complex<long double>) { return boost::numeric_cast<std::complex<long double> >(v); }
std::complex<double> which_value(std::complex<double> v, std::complex<double>) { return v; }
std::complex<float> which_value(std::complex<double> v, std::complex<float>) { return std::complex<float>(float(real(v)), float(imag(v))); }
std::ifstream *new_stream;
std::istream &my_stream;
enum symmetry {general, symmetric, skew, Hermitian} my_symmetry;
enum sparsity {coordinate, array} my_sparsity;
std::size_t nrows, ncols, nnz;
};
// Matrix version
template <typename Matrix>
matrix_market_istream& matrix_market_istream::read(Matrix& A, tag::matrix)
{
std::string marker, type, sparsity_text, value_format, symmetry_text;
my_stream >> marker >> type >> sparsity_text >> value_format >> symmetry_text;
#if 0
std::cout << marker << ", " << type << ", " << sparsity_text << ", "
<< value_format << ", " << symmetry_text << "\n";
#endif
MTL_THROW_IF(marker != std::string("%%MatrixMarket"),
runtime_error("File not in Matrix Market format"));
MTL_THROW_IF(type != std::string("matrix"),
runtime_error("Try to read matrix from non-matrix file"));
set_symmetry(symmetry_text);
set_sparsity(sparsity_text);
char first, comment[80];
do {
my_stream >> first;
if (first == '%') // comments start with % -> ignore them
my_stream.getline(comment, 80, '\n'); // read rest of line
else
my_stream.putback(first); // if not commment we still need it
} while (first == '%');
my_stream >> nrows >> ncols;
// std::cout << nrows << "x" << ncols << ", " << nnz << " non-zeros\n";
A.change_dim(nrows, ncols);
set_to_zero(A);
std::size_t slot_size;
if (sparsity_text == std::string("coordinate")) {
my_stream >> nnz; slot_size= std::max(std::size_t(double(nnz) / double(A.dim1()) * 1.25), std::size_t(1));
} else
slot_size= A.dim2(); // maximal value (if A is dense it does not matter anyway)
// Create enough space in sparse matrices
matrix::inserter<Matrix> ins(A, slot_size);
if (value_format == std::string("real"))
read_matrix(ins, double());
else if (value_format == std::string("integer"))
read_matrix(ins, long());
else if (value_format == std::string("complex"))
read_matrix(ins, std::complex<double>());
else if (value_format == std::string("pattern"))
read_matrix(ins, pattern_type());
else
MTL_THROW(runtime_error("Unknown tag for matrix value type in file"));
return *this;
}
class matrix_market_ostream
{
typedef matrix_market_ostream self;
public:
explicit matrix_market_ostream(const char* p) : new_stream(new std::ofstream(p)), my_stream(*new_stream) {}
explicit matrix_market_ostream(const std::string& s) : new_stream(new std::ofstream(s.c_str())), my_stream(*new_stream) {}
explicit matrix_market_ostream(std::ostream& s= std::cout) : new_stream(0), my_stream(s) {}
~matrix_market_ostream() { if (new_stream) delete new_stream; }
template <typename Coll>
self& operator<<(const Coll& c)
{
return write(c, typename mtl::traits::category<Coll>::type());
}
/// Close only my own file, i.e. if filename and not stream is passed in constructor
void close() { if (new_stream) new_stream->close(); }
private:
template <typename Matrix> self& write(const Matrix& A, tag::matrix)
{
matrix_status_line(A);
if (sparsity(A) == std::string("coordinate "))
return write_sparse_matrix(A);
else
return write_dense_matrix(A);
}
template <typename Matrix> self& write_sparse_matrix(const Matrix& A)
{
my_stream << num_rows(A) << " " << num_cols(A) << " " << A.nnz() << "\n";
typename mtl::traits::row<Matrix>::type row(A);
typename mtl::traits::col<Matrix>::type col(A);
typename mtl::traits::const_value<Matrix>::type value(A);
typedef typename mtl::traits::range_generator<tag::major, Matrix>::type cursor_type;
typedef typename mtl::traits::range_generator<tag::nz, cursor_type>::type icursor_type;
for (cursor_type cursor = begin<tag::major>(A), cend = end<tag::major>(A); cursor != cend; ++cursor)
for (icursor_type icursor = begin<tag::nz>(cursor), icend = end<tag::nz>(cursor); icursor != icend; ++icursor)
my_stream << row(*icursor)+1 << " " << col(*icursor)+1 << " ", write_value(value(*icursor)), my_stream << "\n";
return *this;
}
template <typename Matrix> self& write_dense_matrix(const Matrix& A)
{
my_stream << num_rows(A) << " " << num_cols(A) << "\n";
for (std::size_t c = 0; c < num_cols(A); ++c)
for (std::size_t r = 0; r < num_rows(A); ++r) {
write_value(A[r][c]), my_stream << " ";
my_stream << "\n";
}
return *this;
}
template <typename Value>
typename boost::enable_if<boost::is_integral<Value> >::type
write_value(const Value& v) { my_stream << v; }
template <typename Value>
typename boost::enable_if<boost::is_floating_point<Value> >::type
write_value(const Value& v)
{
my_stream.precision(std::numeric_limits<Value>::digits10 + 1);
my_stream.setf(std::ios::scientific);
my_stream << v;
my_stream.unsetf(std::ios::scientific);
}
template <typename Value>
void write_value(const std::complex<Value>& v)
{
my_stream.precision(std::numeric_limits<Value>::digits10 + 1);
my_stream.setf(std::ios::scientific);
my_stream << real(v) << " " << imag(v);
my_stream.unsetf(std::ios::scientific);
}
// Will be generalized via traits::is_symmetric and alike
template <typename Matrix>
std::string symmetry(const Matrix&) const { return std::string("general\n"); }
template <typename Matrix>
std::string sparsity(const Matrix&) const
{
return std::string( mtl::traits::is_sparse<Matrix>::value ? "coordinate " : "array " );
}
template <typename Value>
typename boost::enable_if<boost::is_integral<Value>, std::string>::type
value(const Value&) const { return std::string("integer "); }
template <typename Value>
typename boost::enable_if<boost::is_floating_point<Value>, std::string>::type
value(const Value&) const { return std::string("real "); }
template <typename Value>
std::string value(const std::complex<Value>&) const { return std::string("complex "); }
template <typename Matrix>
void matrix_status_line(const Matrix& A) const
{
typedef typename Collection<Matrix>::value_type value_type;
std::string st(std::string("%%MatrixMarket matrix ") + sparsity(A) + value(value_type()) + symmetry(A));
my_stream << st;
}
protected:
std::ofstream *new_stream;
std::ostream &my_stream;
};
}} // namespace mtl::io
#endif // MTL_IO_MATRIX_MARKET_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
#ifndef MTL_IO_PATH_INCLUDE
#define MTL_IO_PATH_INCLUDE
namespace mtl { namespace io {
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
const static char delim = '\\';
#else
const static char delim = '/';
#endif
/// Join the directory and file
/** It concatenates both with the os-specific slash unless directory is empty, then only file is returned **/
std::string inline join(std::string directory, std::string file)
{
return directory.empty() ? file : directory + delim + file;
}
/// Directory name in s that is everything before last slash
std::string inline directory_name(std::string s)
{
for (int i= s.size() - 1; i >= 0; i--)
if (s[i] == delim)
return s.substr(0, i);
return std::string();
}
/// File name in s that is everything after last slash
std::string inline file_name(std::string s)
{
for (int i= s.size() - 1; i >= 0; i--)
if (s[i] == delim)
return s.substr(i + 1);
return s;
}
}} // namespace mtl::io
#endif // MTL_IO_PATH_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
//
// Algorithm inspired by Nick Vannieuwenhoven, written by Cornelius Steinhardt
#ifndef MTL_MATRIX_READ_EL_MATRIX
#define MTL_MATRIX_READ_EL_MATRIX
#include <string>
#include <iostream>
#include <istream>
#include <set>
#include <vector>
#include <valarray>
#include <boost/numeric/mtl/interface/vpt.hpp>
#include <boost/numeric/mtl/matrix/element.hpp>
#include <boost/numeric/mtl/matrix/element_structure.hpp>
namespace mtl { namespace matrix {
// Read a value from the stream. The stream is advanced.
template <class T, class StreamType>
inline T read_value(StreamType& stream)
{
T value;
stream >> value;
return value;
}
// Reads the element structure from a given file.
//
// It is assumed the nodes are numbered consecutively, i.e. there are no unused
// node numbers.
template < typename StreamType, typename ValueType>
void read_el_matrix(StreamType& file, element_structure<ValueType>& A)
{
// Type definitions
typedef element<ValueType> element_type;
// typedef typename element_type::value_type value_type;
typedef typename element_type::index_type indices;
typedef typename element_type::matrix_type matrix;
vampir_trace<4036> trace;
// Read element type information.
int nb_elements = 0;
file >> nb_elements;
file.ignore(500,'\n');
std::cout << "nb elements: " << nb_elements << "\n";
// Compatibility with older files
file.ignore(500,'\n');
assert(nb_elements >= 0);
element_type* elements = new element_type[nb_elements];
// Read elements from file.
int el_nbr = 0;
int nb_total_vars = 0;
while( el_nbr < nb_elements ) {
// Read the node numbers.
std::string line;
getline(file, line, '\n');
std::stringstream node_line(line), read_node_line(line);
int read_num=0, i=0;
while( !read_node_line.eof() ) {
int idx = 0;
read_node_line >> idx;
++read_num;
}
read_num--;
mtl::vector::dense_vector<int> nodes(read_num, 0);
while( !node_line.eof() ) {
int idx = 0;
node_line >> idx;
if (i<read_num)
nodes[i]=idx;
if(idx > nb_total_vars)
nb_total_vars = idx;
i++;
}
indices index(nodes);
// Read the values.
const int nb_vars = int(size(nodes));
matrix vals(nb_vars, nb_vars);
for(int i = 0; i < nb_vars*nb_vars; ++i)
vals(i / nb_vars, i % nb_vars) = read_value<ValueType>(file);
file.ignore(500,'\n');
file.ignore(500,'\n');
element_type elem(el_nbr, index, vals);
elements[el_nbr] = elem;
if(el_nbr == 0){
std::cout<< "elem=" << elem << "\n";
}
++el_nbr;
}
// Construct mapping.
++nb_total_vars;
assert(nb_total_vars >= 0);
std::vector<int>* node_element_map = new std::vector<int>[nb_total_vars];
for( int i = 0; i < nb_elements; ++i ) {
element_type& el = elements[i];
indices& idx = el.get_indices();
for(int j = 0; j < el.nb_vars(); ++j)
node_element_map[ idx(j) ].push_back(el.get_id());
}
// Construct neighborhood information.
for( int i = 0; i < nb_elements; ++i ) {
element_type& el = elements[i];
indices& idx = el.get_indices();
std::set<int> neighs;
for(int j = 0; j < el.nb_vars(); ++j)
neighs.insert(node_element_map[ idx(j) ].begin(),
node_element_map[ idx(j) ].end());
for(std::set<int>::iterator it = neighs.begin(); it != neighs.end(); ++it)
if( *it != el.get_id() )
el.get_neighbors().push_back( elements+(*it) );
// Sort data.
el.sort_indices();
}
delete[] node_element_map;
A.consume(nb_elements, nb_total_vars, elements);
}
template <typename ValueType>
inline void read_el_matrix(std::string& mat_file, element_structure<ValueType>& A)
{ read_el_matrix(mat_file.c_str(), A); }
template <typename ValueType>
void read_el_matrix(const char* mat_file, element_structure<ValueType>& A)
{
std::ifstream file;
file.open( mat_file );
if( !file.is_open() ) {
std::cout << "The file \"" << mat_file << "\" could not be opened." <<
std::endl;
throw "File could not be opened";
}
read_el_matrix(file, A);
file.close();
}
}} // end namespace mtl::matrix
#endif // MTL_MATRIX_READ_EL_MATRIX
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
#ifndef MTL_IO_READ_FILTER_INCLUDE
#define MTL_IO_READ_FILTER_INCLUDE
#include <boost/numeric/mtl/concept/collection.hpp>
namespace mtl { namespace io {
/// Utility to filter entries in the read process
/** Depending on type only certain entries are considered for insertion.
Particularly interesting for distributed collections (inserters). **/
template <typename Inserter>
class read_filter
{
public:
explicit read_filter(const Inserter& inserter) : inserter(inserter) {}
/// Default for vectors is to consider every entry
bool operator()(std::size_t) const { return true; }
/// Default for matrices is to consider every entry
bool operator()(std::size_t, std::size_t) const { return true; }
private:
const Inserter& inserter;
};
}} // namespace mtl::io
#endif // MTL_IO_READ_FILTER_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
#ifndef MTL_TEST_OSTREAM_INCLUDE
#define MTL_TEST_OSTREAM_INCLUDE
#include <ostream>
namespace mtl { namespace io {
/// ostream class whose objects only write if MTL_VERBOSE_TEST is defined
struct test_ostream
{
#ifdef MTL_VERBOSE_TEST
/// Constructor for out or std::cout
test_ostream(std::ostream& out = std::cout) : out(out) {}
template <typename T>
test_ostream& operator<<(const T& v)
{
out << v;
return *this;
}
test_ostream& operator<<(test_ostream& (*pf)(test_ostream&))
{ return pf(*this); }
void flush() { out.flush(); }
private:
std::ostream& out;
#else
test_ostream() {}
test_ostream(std::ostream&) {}
/// Print on outstream
template <typename T> test_ostream& operator<<(const T&) { return *this; }
/// Interface for manipulators
test_ostream& operator<<(test_ostream& (*)(test_ostream&)) { return *this; }
/// Flush output
void flush() {}
#endif
};
/// Output stream that writes if MTL_VERBOSE_TEST is defined
static test_ostream tout;
}} // namespace mtl::io
namespace std {
inline mtl::io::test_ostream& endl(mtl::io::test_ostream& os) { os << '\n'; os.flush(); return os; }
}
#endif // MTL_TEST_OSTREAM_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG, www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also tools/license/license.mtl.txt in the distribution.
#ifndef MTL_IO_WRITE_AST_INCLUDE
#define MTL_IO_WRITE_AST_INCLUDE
#include <fstream>
#include <boost/numeric/mtl/io/write_ast_dispatch.hpp>
namespace mtl { namespace io {
/// write the abstract syntax tree (AST) to file name \p fname
template <typename Expr>
void write_ast(const Expr& expr, const char* fname)
{
std::ofstream f(fname);
f << "digraph G {\n ordering = out;\n edge [arrowhead=none];\n\n";
write_ast_dispatch(expr, "t", f);
f << "}\n";
}
}} // namespace mtl::io
#endif // MTL_IO_WRITE_AST_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG, www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also tools/license/license.mtl.txt in the distribution.
#ifndef MTL_IO_WRITE_AST_DISPATCH_INCLUDE
#define MTL_IO_WRITE_AST_DISPATCH_INCLUDE
#include <string>
#include <sstream>
#include <fstream>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_floating_point.hpp>
#include <boost/numeric/mtl/mtl_fwd.hpp>
#include <boost/numeric/mtl/io/functor_symbol.hpp>
#include <boost/numeric/mtl/vector/vec_vec_aop_expr.hpp>
namespace mtl { namespace io {
template <typename Value, typename Parameters>
void write_ast_dispatch(const mtl::vector::dense_vector<Value, Parameters>& v, std::string s, std::ofstream& f);
template <typename E1, typename E2, typename SFunctor>
void write_ast_dispatch(const mtl::vector::vec_vec_aop_expr<E1, E2, SFunctor>& expr, std::string s, std::ofstream& f);
template <class E1, class E2, typename SFunctor>
void write_ast_dispatch(const mtl::vector::vec_vec_pmop_expr<E1, E2, SFunctor>& expr, std::string s, std::ofstream& f);
template <typename Functor, typename Vector>
void write_ast_dispatch(const mtl::vector::map_view<Functor, Vector>& expr, std::string s, std::ofstream& f);
template <typename Scaling, typename Vector>
void write_ast_dispatch(const mtl::vector::scaled_view<Scaling, Vector>& expr, std::string s, std::ofstream& f);
template <typename Matrix, typename Vector>
void write_ast_dispatch(const mtl::mat_cvec_times_expr<Matrix, Vector>& expr, std::string s, std::ofstream& f);
template <typename Expr>
void write_ast_dispatch(const mtl::operation::compute_summand<Expr>& expr, std::string s, std::ofstream& f);
template <typename Matrix, typename Vector>
void write_ast_dispatch(const mtl::operation::compute_summand<mtl::mat_cvec_times_expr<Matrix, Vector> >& expr, std::string s, std::ofstream& f);
template <typename Vector1, typename Vector2>
void write_ast_dispatch(const mtl::matrix::outer_product_matrix<Vector1, Vector2>& expr, std::string s, std::ofstream& f);
template <typename Value>
typename boost::enable_if_c<boost::is_floating_point<Value>::value || boost::is_integral<Value>::value>::type
write_ast_dispatch(const Value& v, std::string s, std::ofstream& f)
{
f << " " << s << "[shape=box,label=\"scalar\\n" << v << "\"]\n";
}
template <typename Value, typename Parameters>
void write_ast_dispatch(const mtl::vector::dense_vector<Value, Parameters>& v, std::string s, std::ofstream& f)
{
f << " " << s << "[shape=box,label=\"vector\\n" << &v << "\"]\n";
}
template <typename E1, typename E2, typename SFunctor>
void write_ast_dispatch(const mtl::vector::vec_vec_aop_expr<E1, E2, SFunctor>& expr, std::string s, std::ofstream& f)
{
f << " " << s << "[label=\"" << functor_symbol(SFunctor()) << "\"]\n";
std::string target= s + "t", source= s + "s";
write_ast_dispatch(expr.first_argument(), target, f);
write_ast_dispatch(expr.second_argument(), source, f);
f << " " << s << "->" << target << '\n';
f << " " << s << "->" << source << '\n';
}
template <class E1, class E2, typename SFunctor>
void write_ast_dispatch(const mtl::vector::vec_vec_pmop_expr<E1, E2, SFunctor>& expr, std::string s, std::ofstream& f)
{
f << " " << s << "[label=\"" << functor_symbol(SFunctor()) << "\"]\n";
std::string first= s + "f", second= s + "s";
write_ast_dispatch(expr.first_argument(), first, f);
write_ast_dispatch(expr.second_argument(), second, f);
f << " " << s << "->" << first << '\n';
f << " " << s << "->" << second << '\n';
}
template <typename Scaling, typename Vector>
void write_ast_dispatch(const mtl::vector::scaled_view<Scaling, Vector>& expr, std::string s, std::ofstream& f)
{
f << " " << s << "[label=\"scaled_view\"]\n";
std::string functor= s + "f", ref= s + "r";
write_ast_dispatch(expr.functor.value, functor, f);
write_ast_dispatch(expr.ref, ref, f);
f << " " << s << "->" << functor << '\n';
f << " " << s << "->" << ref << '\n';
}
template <typename Value1, typename Value2>
void write_ast_dispatch(const mtl::tfunctor::scale<Value1, Value2, mtl::tag::scalar>& expr, std::string s, std::ofstream& f)
{
f << " " << s << "[label=\"scale\"]\n";
std::string factor= s + "f", ref= s + "r";
write_ast_dispatch(expr.value(), factor, f);
f << " " << ref << "[label=\".\"]\n";
f << " " << s << "->" << factor << '\n';
f << " " << s << "->" << ref << '\n';
}
template <typename Functor, typename Vector>
void write_ast_dispatch(const mtl::vector::map_view<Functor, Vector>& expr, std::string s, std::ofstream& f)
{
f << " " << s << "[label=\"map\"]\n";
std::string functor= s + "f", ref= s + "r";
write_ast_dispatch(expr.functor, functor, f);
write_ast_dispatch(expr.ref, ref, f);
f << " " << s << "->" << functor << '\n';
f << " " << s << "->" << ref << '\n';
}
// template <typename Matrix, typename Vector>
// void write_ast_dispatch(const mtl::mat_cvec_times_expr<Matrix, Vector>& expr, std::string s, std::ofstream& f)
// {
// }
template <typename Expr>
void write_ast_dispatch(const mtl::operation::compute_summand<Expr>& expr, std::string s, std::ofstream& f)
{
write_ast_dispatch(expr.value, s, f);
}
template <typename Matrix, typename Vector>
void write_ast_dispatch(const mtl::operation::compute_summand<mtl::mat_cvec_times_expr<Matrix, Vector> >& expr, std::string s, std::ofstream& f)
{
# ifdef NDEBUG
write_ast_dispatch(expr.value, s, f);
# else
f << " " << s << "[label=\"*\"]\n";
std::string first= s + "f", second= s + "s";
write_ast_dispatch(expr.first, first, f);
write_ast_dispatch(expr.second, second, f);
f << " " << s << "->" << first << '\n';
f << " " << s << "->" << second << '\n';
# endif
}
template <typename Vector1, typename Vector2>
void write_ast_dispatch(const mtl::matrix::outer_product_matrix<Vector1, Vector2>& expr, std::string s, std::ofstream& f)
{
f << " " << s << "[label=\"outer product\"]\n";
std::string first= s + "f", second= s + "s";
write_ast_dispatch(expr.v1(), first, f);
write_ast_dispatch(expr.v2(), second, f);
f << " " << s << "->" << first << '\n';
f << " " << s << "->" << second << '\n';
}
}} // namespace mtl::io
#endif // MTL_IO_WRITE_AST_DISPATCH_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
#ifndef MTL_MATRICES_INCLUDE
#define MTL_MATRICES_INCLUDE
#include <boost/numeric/mtl/matrix/dense2D.hpp>
#include <boost/numeric/mtl/matrix/morton_dense.hpp>
#include <boost/numeric/mtl/matrix/compressed2D.hpp>
#include <boost/numeric/mtl/matrix/sparse_banded.hpp>
#include <boost/numeric/mtl/matrix/multi_vector.hpp>
#include <boost/numeric/mtl/matrix/multi_vector_range.hpp>
#include <boost/numeric/mtl/matrix/element_matrix.hpp>
#include <boost/numeric/mtl/matrix/element.hpp>
#include <boost/numeric/mtl/matrix/implicit_dense.hpp>
#include <boost/numeric/mtl/matrix/block_diagonal2D.hpp>
#include <boost/numeric/mtl/matrix/ell_matrix.hpp>
#include <boost/numeric/mtl/matrix/inserter.hpp>
#include <boost/numeric/mtl/matrix/shifted_inserter.hpp>
#include <boost/numeric/mtl/matrix/mapped_inserter.hpp>
#include <boost/numeric/mtl/matrix/map_view.hpp>
#include <boost/numeric/mtl/matrix/transposed_view.hpp>
#include <boost/numeric/mtl/matrix/hermitian_view.hpp>
#include <boost/numeric/mtl/matrix/banded_view.hpp>
#include <boost/numeric/mtl/matrix/indirect.hpp>
#include <boost/numeric/mtl/matrix/parameter.hpp>
#include <boost/numeric/mtl/matrix/laplacian_setup.hpp>
#include <boost/numeric/mtl/matrix/hessian_setup.hpp>
#include <boost/numeric/mtl/matrix/poisson2D_dirichlet.hpp>
#include <boost/numeric/mtl/matrix/identity2D.hpp>
#include <boost/numeric/mtl/recursion/predefined_masks.hpp>
#endif // MTL_MATRICES_INCLUDE
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.
#ifndef MTL_ALL_MAT_EXPR_INCLUDE
#define MTL_ALL_MAT_EXPR_INCLUDE
#include <boost/numeric/mtl/matrix/mat_expr.hpp>
#include <boost/numeric/mtl/matrix/mat_mat_minus_expr.hpp>
#include <boost/numeric/mtl/matrix/mat_mat_plus_expr.hpp>
#include <boost/numeric/mtl/matrix/mat_mat_times_expr.hpp>
#include <boost/numeric/mtl/matrix/mat_mat_ele_times_expr.hpp>
#include <boost/numeric/mtl/matrix/mat_mat_asgn_expr.hpp>
#include <boost/numeric/mtl/matrix/mat_negate_expr.hpp>
#if 0
#include <boost/numeric/mtl/matrix/mat_mat_plus_asgn_expr.hpp>
#endif
#endif // MTL_ALL_MAT_EXPR_INCLUDE