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 4564 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 META_MATH_LOOP2_INCLUDE
#define META_MATH_LOOP2_INCLUDE
// See loop3.hpp for example
namespace meta_math {
template <std::size_t Index0, std::size_t Max0, std::size_t Index1, std::size_t Max1>
struct loop2
{
static const std::size_t index0= Index0 - 1, next_index0= Index0,
index1= Index1 - 1, next_index1= Index1 + 1;
};
template <std::size_t Index0, std::size_t Max0, std::size_t Max1>
struct loop2<Index0, Max0, Max1, Max1>
{
static const std::size_t index0= Index0 - 1, next_index0= Index0 + 1,
index1= Max1 - 1, next_index1= 1;
};
template <std::size_t Max0, std::size_t Max1>
struct loop2<Max0, Max0, Max1, Max1>
{
static const std::size_t index0= Max0 - 1,
index1= Max1 - 1;
};
} // namespace meta_math
#endif // META_MATH_LOOP2_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 META_MATH_LOOP3_INCLUDE
#define META_MATH_LOOP3_INCLUDE
// See below for example
namespace meta_math {
template <std::size_t Index0, std::size_t Max0, std::size_t Index1, std::size_t Max1,
std::size_t Index2, std::size_t Max2>
struct loop3
{
static std::size_t const index0= Index0 - 1, next_index0= Index0,
index1= Index1 - 1, next_index1= Index1,
index2= Index2 - 1, next_index2= Index2 + 1;
};
template <std::size_t Index0, std::size_t Max0, std::size_t Index1, std::size_t Max1,
std::size_t Max2>
struct loop3<Index0, Max0, Index1, Max1, Max2, Max2>
{
static std::size_t const index0= Index0 - 1, next_index0= Index0,
index1= Index1 - 1, next_index1= Index1 + 1,
index2= Max2 - 1, next_index2= 1;
};
template <std::size_t Index0, std::size_t Max0, std::size_t Max1, std::size_t Max2>
struct loop3<Index0, Max0, Max1, Max1, Max2, Max2>
{
static std::size_t const index0= Index0 - 1, next_index0= Index0 + 1,
index1= Max1 - 1, next_index1= 1,
index2= Max2 - 1, next_index2= 1;
};
template <std::size_t Max0, std::size_t Max1, std::size_t Max2>
struct loop3<Max0, Max0, Max1, Max1, Max2, Max2>
{
static std::size_t const index0= Max0 - 1,
index1= Max1 - 1,
index2= Max2 - 1;
};
#if 0
// ============================
// Use the meta loop like this:
// ============================
template <std::size_t Index0, std::size_t Max0, std::size_t Index1, std::size_t Max1,
std::size_t Index2, std::size_t Max2>
struct loop3_trace : public loop3<Index0, Max0, Index1, Max1, Index2, Max2>
{
typedef loop3<Index0, Max0, Index1, Max1, Index2, Max2> base;
typedef loop3_trace<base::next_index0, Max0, base::next_index1, Max1, base::next_index2, Max2> next_t;
void operator() ()
{
std::cout << this->index0 << " : " << this->index1 << " : " << this->index2 << "\n";
next_t() ();
}
};
template <std::size_t Max0, std::size_t Max1, std::size_t Max2>
struct loop3_trace<Max0, Max0, Max1, Max1, Max2, Max2>
: public loop3<Max0, Max0, Max1, Max1, Max2, Max2>
{
void operator() ()
{
std::cout << this->index0 << " : " << this->index1 << " : " << this->index2 << "\n";
}
};
#endif
} // namespace meta_math
#endif // META_MATH_LOOP3_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 META_MATH_MAX_INCLUDE
#define META_MATH_MAX_INCLUDE
namespace meta_math {
template <long int x, long int y>
struct max
{
typedef long int type;
static long int const value = x < y ? y : x;
};
} // namespace meta_math
#endif // META_MATH_MAX_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 META_MATH_MIN_INCLUDE
#define META_MATH_MIN_INCLUDE
namespace meta_math {
template <long int x, long int y>
struct min
{
typedef long int type;
static long int const value = x < y ? x : y;
};
} // namespace meta_math
#endif // META_MATH_MIN_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 META_MATH_POWER_OF_2_INCLUDE
#define META_MATH_POWER_OF_2_INCLUDE
namespace meta_math {
// Computes the n-th power of 2
// So simple, everybody could do it, it is only there for the sake of completeness
template <unsigned long N>
struct power_of_2
{
static const unsigned long value= 1 << N;
};
} // namespace meta_math
#endif // META_MATH_POWER_OF_2_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 META_MATH_SQRT_INCLUDE
#define META_MATH_SQRT_INCLUDE
#include <boost/numeric/meta_math/abs.hpp>
namespace meta_math {
template <long int root, long int x>
struct sqrt_check
{
static bool const value = root * root <= x && (root+1) * (root+1) > x;
};
namespace impl {
template <long int guess, long int x, bool Converged>
struct sqrt_impl
{
typedef long int type;
typedef sqrt_impl self;
static long int const quotient = x / guess,
new_value = (quotient + guess) / 2;
static bool const converging = abs<guess - quotient>::value < 2;
static long int const value = sqrt_impl<new_value, x, converging>::value;
};
// If the condition becomes true the guessed root will be the returned value
template <long int guess, long int x>
struct sqrt_impl<guess, x, true>
{
static long int const value = guess;
};
}
template <long int x>
struct sqrt
{
typedef long int type;
static long int const value = impl::sqrt_impl<1, x, false>::value;
};
} // namespace meta_math
#endif // META_MATH_SQRT_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_COLLECTION_INCLUDE
#define MTL_COLLECTION_INCLUDE
#include <boost/type_traits/remove_const.hpp>
#include <boost/numeric/mtl/mtl_fwd.hpp>
#include <vector>
#ifdef __GXX_CONCEPTS__
# include <concepts>
#else
# include <boost/numeric/linear_algebra/pseudo_concept.hpp>
# include <boost/numeric/mtl/concept/std_concept.hpp>
#endif
#include <boost/numeric/mtl/utility/transposed_orientation.hpp>
namespace mtl {
/** @addtogroup Concepts
* @{
*/
#ifdef __GXX_CONCEPTS__
auto concept Collection<typename T>
{
typename value_type;
typename const_reference;
typename size_type;
};
#else
/// Concept Collection
template <typename T>
struct Collection
{
/// Associated type: elements in the collection
typedef associated_type value_type;
/// Associated type: return type of const element access (however implemented)
typedef associated_type const_reference;
/// Associated type: size type used for indexing in collection
typedef associated_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
auto concept MutableCollection<typename T>
: Collection<T>
{
typename reference;
}
#else
/// Concept MutableCollection
template <typename T>
struct MutableCollection
: public Collection<T>
{
/// Associated type: return type of non-const element access (however implemented)
typedef associated_type reference;
};
#endif
#ifdef __GXX_CONCEPTS__
concept ConstantSizeCollection<typename T>
: Collection<T>
{};
#else
/// Concept ConstantSizeCollection: size parameters of collection are completely given at compile time
/* Which parameters determine collection size depends on type of collection, e.g. different for vector and matrix
\par Refinement of:
- Collection < T >
*/
template <typename T>
struct ConstantSizeCollection
: Collection<T>
{};
#endif
#ifdef __GXX_CONCEPTS__
auto concept AlgebraicCollection<typename T>
: Collection<T>
{
size_type num_rows(T);
size_type num_cols(T);
size_type size(T);
};
#else
/// Concept AlgebraicCollection: common requirements of matrices, vectors, and scalars in computations
/** For more design clarity we consider them all as matrices (as Matlab does) and we regard
Scalar and Vector as special cases (see there). However, the implementation of vectors
is supposed to differ from the ones of matrices in order to provide efficient computations and storage.
\par Refinement of:
- Collection < T >
\par Notation:
- X is a type that models AlgebraicCollection
- x is an object of type X
\par Valid expressions:
- Number of rows: \n num_rows(x) \n Return Type: size_type
- Number of columns: \n num_cols(x) \n Return Type: size_type
- Number of elements: \n size(x) \n Return Type: size_type
\n Sematics: num_rows(x) * num_cols(x) (but possibly faster implemented)
*/
template <typename T>
struct AlgebraicCollection
: public Collection<T>
{};
#endif
#ifdef __GXX_CONCEPTS__
auto concept ConstantSizeAlgebraicCollection<typename T>
: AlgebraicCollection<T>,
ConstantSizeCollection<T>
{
#if 0
// Is there a way to require static members????
static Collection<T>::size_type T::static_num_rows;
static Collection<T>::size_type T::static_num_cols;
static Collection<T>::size_type T::static_size;
#endif
};
#else
/// Concept ConstantSizeAlgebraicCollection: extension of AlgebraicCollection with meta-functions
/** This concept is used for algebraic collections with sizes known at compile time.
The motivation is that if the size of the collection is
is small, arithmetic operations can be unrolled at compile time.
\par Refinement of:
- Collection < T >
\par Notation:
- X is a type that models ConstantSizeAlgebraicCollection
- x is an object of type X
\par Valid expressions:
- Number of rows: \n static_num_rows<X>::value
- Number of columns: \n static_num_cols<X>::value
- Number of elements: \n static_size<X>::value
\n Sematics: static_num_rows<X>::value * static_size<X>::value
\note
-# For more design clarity we consider them all as matrices (as Matlab does) and we regard
Scalar and Vector as special cases (see there). However, the implementation of vectors
is supposed to differ from the ones of matrices in order to provide efficient computations and storage.
*/
template <typename T>
struct ConstantSizeAlgebraicCollection
: public AlgebraicCollection<T>,
public ConstantSizeCollection<T>
{
/// Associated type: meta-function for number of rows
typedef associated_type static_num_rows;
/// Associated type: meta-function for number of columns
typedef associated_type static_num_cols;
/// Associated type: meta-function for number of elements
typedef associated_type static_size;
};
#endif
#ifdef __GXX_CONCEPTS__
auto concept TraversableCollection<typename Tag, typename C>
: Collection<C>
{
#if 0
// This might be impossible to declare with concepts
typename cursor_type;
cursor_type begin<Tag>(const C& c);
cursor_type end<Tag>(const C& c);
#endif
// Maybe we switch to this syntax for the sake of concepts
typename cursor_type;
cursor_type begin(const C& c, Tag);
cursor_type end(const C& c, Tag);
}
#else
/// Concept TraversableCollection: collections that can be traversed by cursor or iterator
template <typename Tag, typename C>
struct TraversableCollection
: public Collection<C>
{
/// Associated type: return type of tagged begin and end function
typedef associated_type cursor_type;
/// Tagged free function that returns a cursor or iterator at the begin of an interval
/** The interval is specified by the Tag, i.e. the function is called begin<Tag>(c); */
cursor_type begin(const C& c);
/// Tagged free function that returns a cursor or iterator at the end of an interval
/** The interval is specified by the Tag, i.e. the function is called end<Tag>(c); */
cursor_type end(const C& c);
};
#endif
#ifdef __GXX_CONCEPTS__
auto concept TraversableMutableCollection<typename Tag, typename C>
: MutableCollection<C>
{
#if 0
typename cursor_type;
cursor_type begin<Tag>(C& c);
cursor_type end<Tag>(C& c);
#endif
// Maybe we switch to this syntax for the sake of concepts
typename cursor_type;
cursor_type begin(C& c, Tag);
cursor_type end(C& c, Tag);
}
#else
/// Concept TraversableMutableCollection: collections that can be traversed by (mutable) iterator
template <typename Tag, typename C>
struct TraversableMutableCollection
: public MutableCollection<C>
{
/// Associated type: return type of tagged begin function
typedef associated_type cursor_type;
/// Tagged free function that returns a cursor or iterator at the begin of an interval
/** The interval is specified by the Tag, i.e. the function is called begin<Tag>(c); */
cursor_type begin(const C& c);
/// Tagged free function that returns a cursor or iterator at the end of an interval
/** The interval is specified by the Tag, i.e. the function is called end<Tag>(c); */
cursor_type end(const C& c);
};
#endif
#ifdef __GXX_CONCEPTS__
#if 0
concept CategorizedType<typename T>
{
typedef associated_type type;
};
#endif
#endif
#ifdef __GXX_CONCEPTS__
concept OrientedCollection<typename T>
: Collection<T>
{
typename orientation;
};
#else
/// Concept OrientedCollection: collections with concept-awareness in terms of associated type
/** Concept-awareness is given for matrices as well as for vectors consistent to the unification in
AlgebraicCollection. The orientation of vectors determines whether it is a row or a column vector.
The orientation of matrices only characterizes the internal representation and has no semantic consequences.
\par Refinement of:
- Collection < T >
\par Associated type:
- orientation
*/
template <typename T>
struct OrientedCollection
: public Collection<T>
{
/// Associated type for orientation; by default identical with member type
typedef typename T::orientation orientation;
};
#endif
// ============================================
// Concept maps (and emulations as type traits)
// ============================================
#ifdef __GXX_CONCEPTS__
// Needs redefinition in refinements (at least in conceptg++)
// -> as a consequence we define it directly there
#else
template <typename Value, typename Parameters>
struct Collection<mtl::matrix::dense2D<Value, Parameters> >
{
typedef Value value_type;
typedef const Value& const_reference;
// Alleged ambiguity with mtl::tag::dense2D on MSVC
typedef typename mtl::matrix::dense2D<Value, Parameters>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Value, std::size_t Mask, typename Parameters>
struct Collection<mtl::matrix::morton_dense<Value, Mask, Parameters> >
{
typedef Value value_type;
typedef const Value& const_reference;
typedef typename Parameters::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Value, typename Parameters>
concept_map Collection<mtl::matrix::compressed2D<Value, Parameters> >
{
typedef Value value_type;
typedef Value const_reference;
typedef typename mtl::matrix::compressed2D<Value, Parameters>::size_type size_type;
};
#else
template <typename Value, typename Parameters>
struct Collection<mtl::matrix::compressed2D<Value, Parameters> >
{
typedef Value value_type;
typedef Value const_reference;
typedef typename Parameters::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Value, typename Parameters>
struct Collection<mtl::matrix::coordinate2D<Value, Parameters> >
{
typedef Value value_type;
typedef Value const_reference;
typedef typename Parameters::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Value, typename Parameters>
struct Collection<mtl::matrix::sparse_banded<Value, Parameters> >
{
typedef Value value_type;
typedef Value const_reference;
typedef typename Parameters::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Vector>
concept_map Collection<mtl::matrix::multi_vector<Vector> >
{
typedef typename mtl::matrix::multi_vector<Vector>::value_type value_type;
typedef typename mtl::matrix::multi_vector<Vector>::const_reference const_reference;
typedef typename mtl::matrix::multi_vector<Vector>::size_type size_type;
};
#else
template <typename Vector>
struct Collection<mtl::matrix::multi_vector<Vector> >
{
typedef typename mtl::matrix::multi_vector<Vector>::value_type value_type;
typedef typename mtl::matrix::multi_vector<Vector>::const_reference const_reference;
typedef typename mtl::matrix::multi_vector<Vector>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Vector>
concept_map Collection<mtl::matrix::multi_vector_range<Vector> >
{
typedef typename mtl::matrix::multi_vector_range<Vector>::value_type value_type;
typedef typename mtl::matrix::multi_vector_range<Vector>::const_reference const_reference;
typedef typename mtl::matrix::multi_vector_range<Vector>::size_type size_type;
};
#else
template <typename Vector>
struct Collection<mtl::matrix::multi_vector_range<Vector> >
{
typedef typename mtl::matrix::multi_vector_range<Vector>::value_type value_type;
typedef typename mtl::matrix::multi_vector_range<Vector>::const_reference const_reference;
typedef typename mtl::matrix::multi_vector_range<Vector>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Value>
struct Collection<matrix::element_structure<Value> >
{
typedef Value value_type;
// typedef Value const_reference;
// typedef typename mtl::matrix::compressed2D<Value, Parameters>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Value, typename Parameters>
struct Collection<matrix::ell_matrix<Value, Parameters> >
{
typedef Value value_type;
typedef Value const_reference;
typedef typename Parameters::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Scaling, typename Coll>
concept_map Collection<matrix::scaled_view<Scaling, Coll> >
{
typedef typename matrix::scaled_view<Scaling, Coll>::value_type value_type;
typedef typename matrix::scaled_view<Scaling, Coll>::const_reference const_reference;
typedef typename matrix::scaled_view<Scaling, Coll>::size_type size_type;
};
#else
template <typename Scaling, typename Coll>
struct Collection<matrix::scaled_view<Scaling, Coll> >
{
typedef typename matrix::scaled_view<Scaling, Coll>::value_type value_type;
typedef typename matrix::scaled_view<Scaling, Coll>::const_reference const_reference;
typedef typename matrix::scaled_view<Scaling, Coll>::size_type size_type;
};
#endif
// added by Hui Li
#ifdef __GXX_CONCEPTS__
template <typename Coll, typename RScaling>
concept_map Collection<matrix::rscaled_view<Coll,RScaling> >
{
typedef typename matrix::rscaled_view<Coll,RScaling>::value_type value_type;
typedef typename matrix::rscaled_view<Coll,RScaling>::const_reference const_reference;
typedef typename matrix::rscaled_view<Coll,RScaling>::size_type size_type;
};
#else
template <typename Coll, typename RScaling>
struct Collection<matrix::rscaled_view<Coll,RScaling> >
{
typedef typename matrix::rscaled_view<Coll,RScaling>::value_type value_type;
typedef typename matrix::rscaled_view<Coll,RScaling>::const_reference const_reference;
typedef typename matrix::rscaled_view<Coll,RScaling>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
// template <typename Functor, typename Coll>
// concept_map Collection< vector::map_view<Functor, Coll> >
// {
// typedef typename vector::map_view<Functor, Coll>::value_type value_type;
// typedef typename vector::map_view<Functor, Coll>::const_reference const_reference;
// typedef typename vector::map_view<Functor, Coll>::size_type size_type;
// };
#else
template <typename Functor, typename Coll>
struct Collection< vector::map_view<Functor, Coll> >
{
// typedef typename Functor::result_type value_type;
// typedef typename Functor::result_type const_reference;
// typedef typename Collection<Coll>::size_type size_type;
typedef typename vector::map_view<Functor, Coll>::value_type value_type;
typedef typename vector::map_view<Functor, Coll>::const_reference const_reference;
typedef typename vector::map_view<Functor, Coll>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Scaling, typename Coll>
struct Collection<vector::scaled_view<Scaling, Coll> >
: Collection< vector::map_view<tfunctor::rscale<typename Collection<Coll>::value_type, Scaling>, Coll> >
{
// typedef typename vector::scaled_view<Scaling, Coll>::value_type value_type;
// typedef typename vector::scaled_view<Scaling, Coll>::const_reference const_reference;
// typedef typename vector::scaled_view<Scaling, Coll>::size_type size_type;
};
#endif
// added by Hui Li
#ifdef __GXX_CONCEPTS__
template <typename Coll, typename RScaling>
concept_map Collection<vector::rscaled_view<Coll,RScaling> >
{
typedef typename vector::rscaled_view<Coll,RScaling>::value_type value_type;
typedef typename vector::rscaled_view<Coll,RScaling>::const_reference const_reference;
typedef typename vector::rscaled_view<Coll,RScaling>::size_type size_type;
};
#else
template <typename Coll, typename RScaling>
struct Collection<vector::rscaled_view<Coll,RScaling> >
: Collection< vector::map_view<tfunctor::rscale<typename Collection<Coll>::value_type, RScaling>, Coll> >
{
// typedef typename vector::rscaled_view<Coll,RScaling>::value_type value_type;
// typedef typename vector::rscaled_view<Coll,RScaling>::const_reference const_reference;
// typedef typename vector::rscaled_view<Coll,RScaling>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Coll>
concept_map Collection<vector::conj_view<Coll> >
{
typedef typename vector::conj_view<Coll>::value_type value_type;
typedef typename vector::conj_view<Coll>::const_reference const_reference;
typedef typename vector::conj_view<Coll>::size_type size_type;
};
#else
template <typename Coll>
struct Collection<vector::conj_view<Coll> >
{
typedef typename vector::conj_view<Coll>::value_type value_type;
typedef typename vector::conj_view<Coll>::const_reference const_reference;
typedef typename vector::conj_view<Coll>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Coll>
struct Collection<vector::real_view<Coll> >
{
typedef typename vector::real_view<Coll>::value_type value_type;
typedef typename vector::real_view<Coll>::const_reference const_reference;
typedef typename vector::real_view<Coll>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Coll>
struct Collection<vector::imag_view<Coll> >
{
typedef typename vector::imag_view<Coll>::value_type value_type;
typedef typename vector::imag_view<Coll>::const_reference const_reference;
typedef typename vector::imag_view<Coll>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Coll>
concept_map Collection<vector::negate_view<Coll> >
{
typedef typename vector::negate_view<Coll>::value_type value_type;
typedef typename vector::negate_view<Coll>::const_reference const_reference;
typedef typename vector::negate_view<Coll>::size_type size_type;
};
#else
template <typename Coll>
struct Collection<vector::negate_view<Coll> >
{
typedef typename vector::negate_view<Coll>::value_type value_type;
typedef typename vector::negate_view<Coll>::const_reference const_reference;
typedef typename vector::negate_view<Coll>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <class E1, class E2, typename SFunctor>
struct Collection< vector::vec_scal_aop_expr<E1, E2, SFunctor> >
{
typedef typename Collection<E1>::value_type value_type;
typedef value_type const_reference;
typedef typename Collection<E1>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <class E1, class E2>
struct Collection<vector::vec_scal_asgn_expr<E1, E2> >
: Collection< vector::vec_scal_aop_expr<E1, E2, mtl::sfunctor::assign<typename Collection<E1>::value_type, E2> > >
{};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <unsigned BSize, typename Vector>
struct Collection<vector::unrolled1<BSize, Vector> >
{
typedef typename Collection<Vector>::value_type value_type;
typedef value_type const_reference;
typedef typename Collection<Vector>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Coll>
concept_map Collection<matrix::conj_view<Coll> >
{
typedef typename matrix::conj_view<Coll>::value_type value_type;
typedef typename matrix::conj_view<Coll>::const_reference const_reference;
typedef typename matrix::conj_view<Coll>::size_type size_type;
};
#else
template <typename Coll>
struct Collection<matrix::conj_view<Coll> >
{
typedef typename matrix::conj_view<Coll>::value_type value_type;
typedef typename matrix::conj_view<Coll>::const_reference const_reference;
typedef typename matrix::conj_view<Coll>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Coll>
concept_map Collection<matrix::imag_view<Coll> >
{
typedef typename matrix::imag_view<Coll>::value_type value_type;
typedef typename matrix::imag_view<Coll>::const_reference const_reference;
typedef typename matrix::imag_view<Coll>::size_type size_type;
};
#else
template <typename Coll>
struct Collection<matrix::imag_view<Coll> >
{
typedef typename matrix::imag_view<Coll>::value_type value_type;
typedef typename matrix::imag_view<Coll>::const_reference const_reference;
typedef typename matrix::imag_view<Coll>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Coll>
concept_map Collection<matrix::negate_view<Coll> >
{
typedef typename matrix::negate_view<Coll>::value_type value_type;
typedef typename matrix::negate_view<Coll>::const_reference const_reference;
typedef typename matrix::negate_view<Coll>::size_type size_type;
};
#else
template <typename Coll>
struct Collection<matrix::negate_view<Coll> >
{
typedef typename matrix::negate_view<Coll>::value_type value_type;
typedef typename matrix::negate_view<Coll>::const_reference const_reference;
typedef typename matrix::negate_view<Coll>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Coll>
concept_map Collection<matrix::real_view<Coll> >
{
typedef typename matrix::real_view<Coll>::value_type value_type;
typedef typename matrix::real_view<Coll>::const_reference const_reference;
typedef typename matrix::real_view<Coll>::size_type size_type;
};
#else
template <typename Coll>
struct Collection<matrix::real_view<Coll> >
{
typedef typename matrix::real_view<Coll>::value_type value_type;
typedef typename matrix::real_view<Coll>::const_reference const_reference;
typedef typename matrix::real_view<Coll>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Functor>
concept_map Collection<matrix::implicit_dense<Functor> >
{
typedef typename matrix::implicit_dense<Functor>::value_type value_type;
typedef typename matrix::implicit_dense<Functor>::const_reference const_reference;
typedef typename matrix::implicit_dense<Functor>::size_type size_type;
};
#else
template <typename Functor>
struct Collection<matrix::implicit_dense<Functor> >
{
typedef typename matrix::implicit_dense<Functor>::value_type value_type;
typedef typename matrix::implicit_dense<Functor>::const_reference const_reference;
typedef typename matrix::implicit_dense<Functor>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Value>
concept_map Collection<matrix::ones_matrix<Value> >
{
typedef typename matrix::ones_matrix<Value>::value_type value_type;
typedef typename matrix::ones_matrix<Value>::const_reference const_reference;
typedef typename matrix::ones_matrix<Value>::size_type size_type;
};
#else
template <typename Value>
struct Collection<matrix::ones_matrix<Value> >
{
typedef typename matrix::ones_matrix<Value>::value_type value_type;
typedef typename matrix::ones_matrix<Value>::const_reference const_reference;
typedef typename matrix::ones_matrix<Value>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Value>
concept_map Collection<matrix::hilbert_matrix<Value> >
{
typedef typename matrix::hilbert_matrix<Value>::value_type value_type;
typedef typename matrix::hilbert_matrix<Value>::const_reference const_reference;
typedef typename matrix::hilbert_matrix<Value>::size_type size_type;
};
#else
template <typename Value>
struct Collection<matrix::hilbert_matrix<Value> >
{
typedef typename matrix::hilbert_matrix<Value>::value_type value_type;
typedef typename matrix::hilbert_matrix<Value>::const_reference const_reference;
typedef typename matrix::hilbert_matrix<Value>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Vector1, typename Vector2>
concept_map Collection<matrix::outer_product_matrix<Vector1, Vector2> >
{
typedef typename matrix::outer_product_matrix<Vector1, Vector2>::value_type value_type;
typedef typename matrix::outer_product_matrix<Vector1, Vector2>::const_reference const_reference;
typedef typename matrix::outer_product_matrix<Vector1, Vector2>::size_type size_type;
};
#else
template <typename Vector1, typename Vector2>
struct Collection<matrix::outer_product_matrix<Vector1, Vector2> >
{
typedef typename matrix::outer_product_matrix<Vector1, Vector2>::value_type value_type;
typedef typename matrix::outer_product_matrix<Vector1, Vector2>::const_reference const_reference;
typedef typename matrix::outer_product_matrix<Vector1, Vector2>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Matrix>
concept_map Collection<mtl::matrix::transposed_view<Matrix> >
{
typedef typename mtl::matrix::transposed_view<Matrix>::value_type value_type;
typedef typename mtl::matrix::transposed_view<Matrix>::const_reference const_reference;
typedef typename mtl::matrix::transposed_view<Matrix>::size_type size_type;
};
#else
template <typename Matrix>
struct Collection<mtl::matrix::transposed_view<Matrix> >
{
typedef typename mtl::matrix::transposed_view<Matrix>::value_type value_type;
typedef typename mtl::matrix::transposed_view<Matrix>::const_reference const_reference;
typedef typename mtl::matrix::transposed_view<Matrix>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Matrix>
concept_map Collection<matrix::hermitian_view<Matrix> >
{
typedef typename Collection<Matrix>::value_type value_type;
typedef typename Collection<Matrix>::const_reference const_reference;
typedef typename Collection<Matrix>::size_type size_type;
};
#else
template <typename Matrix>
struct Collection<matrix::hermitian_view<Matrix> >
{
typedef typename Collection<Matrix>::value_type value_type;
typedef typename Collection<Matrix>::const_reference const_reference;
typedef typename Collection<Matrix>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Coll>
concept_map Collection< matrix::banded_view<Coll> >
{
typedef typename matrix::banded_view<Coll>::value_type value_type;
typedef typename matrix::banded_view<Coll>::const_reference const_reference;
typedef typename matrix::banded_view<Coll>::size_type size_type;
};
#else
template <typename Coll>
struct Collection< matrix::banded_view<Coll> >
{
typedef typename matrix::banded_view<Coll>::value_type value_type;
typedef typename matrix::banded_view<Coll>::const_reference const_reference;
typedef typename matrix::banded_view<Coll>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Matrix>
struct Collection< matrix::indirect<Matrix> >
{
typedef typename Collection<Matrix>::value_type value_type;
typedef value_type const_reference; // maybe change later
typedef typename Collection<Matrix>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Matrix, typename Tag, int level>
struct Collection<traits::detail::sub_matrix_cursor<Matrix, Tag, level> >
{
typedef typename Collection<Matrix>::value_type value_type;
typedef typename Collection<Matrix>::const_reference const_reference;
typedef typename Collection<Matrix>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename E1, typename E2>
struct Collection<matrix::mat_mat_times_expr<E1, E2> >
{
typedef typename Collection<E1>::value_type ft;
typedef typename Collection<E2>::value_type st;
typedef typename Multiplicable<ft, st>::result_type value_type;
typedef const value_type& const_reference;
typedef typename Collection<E1>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename E1, typename E2>
struct Collection<matrix::mat_mat_plus_expr<E1, E2> >
{
typedef typename Collection<E1>::value_type ft;
typedef typename Collection<E2>::value_type st;
typedef typename Addable<ft, st>::result_type value_type;
typedef const value_type& const_reference;
typedef typename Collection<E1>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename E1, typename E2>
struct Collection<matrix::mv_mv_plus_expr<E1, E2> >
: Collection<matrix::mat_mat_plus_expr<E1, E2> >
{};
#endif
#ifdef __GXX_CONCECPTS__
#else
template< typename Matrix, typename Vector>
struct Collection<mtl::mat_cvec_times_expr<Matrix, Vector> >
{
typedef typename Collection< Matrix >::value_type value_type;
typedef const value_type& const_reference;
typedef typename Collection< Matrix >::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Value, typename Parameters>
struct Collection<mtl::vector::dense_vector<Value, Parameters> >
{
typedef Value value_type;
typedef const Value& const_reference;
typedef typename Parameters::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Value, typename Parameters>
struct Collection<mtl::vector::strided_vector_ref<Value, Parameters> >
{
typedef typename boost::remove_const<Value>::type value_type;
typedef const Value& const_reference;
typedef typename mtl::vector::strided_vector_ref<Value, Parameters>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Value, typename Parameters>
struct Collection<mtl::vector::sparse_vector<Value, Parameters> >
{
typedef Value value_type;
typedef value_type const_reference;
typedef typename Parameters::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <class E1, class E2, typename SFunctor>
struct Collection<mtl::vector::vec_vec_ele_prod_expr<E1, E2, SFunctor> >
{
typedef typename Multiplicable<typename Collection<E1>::value_type,
typename Collection<E2>::value_type>::result_type value_type;
typedef const value_type& const_reference;
typedef typename Collection<E1>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <class E1, class E2, typename SFunctor>
struct Collection<mtl::vector::vec_vec_pmop_expr<E1, E2, SFunctor> >
{
typedef typename Addable<typename Collection<E1>::value_type,
typename Collection<E2>::value_type>::result_type value_type;
typedef const value_type& const_reference;
typedef typename Collection<E1>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <class E1, class E2, typename SFunctor>
struct Collection<mtl::vector::vec_vec_op_expr<E1, E2, SFunctor> >
{
typedef typename SFunctor::result_type value_type;
typedef const value_type& const_reference;
typedef typename Collection<E1>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <class E1, class E2, typename SFunctor>
struct Collection<mtl::vector::vec_vec_aop_expr<E1, E2, SFunctor> >
{
typedef typename Collection<E1>::value_type value_type;
typedef const value_type& const_reference;
typedef typename Collection<E1>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Matrix, typename VectorIn>
struct Collection<mtl::vector::mat_cvec_multiplier<Matrix, VectorIn> >
{
typedef typename Multiplicable<typename Collection<Matrix>::value_type,
typename Collection<VectorIn>::value_type>::result_type value_type;
typedef const value_type& const_reference;
typedef typename Collection<Matrix>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
// Dunno if this is really a good idea
template <typename T>
struct Collection<T const>
: Collection<T>
{};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Value>
struct Collection<std::vector<Value> >
{
typedef typename std::vector<Value>::value_type value_type;
typedef typename std::vector<Value>::const_reference const_reference;
typedef typename std::vector<Value>::size_type size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Vector, typename Functor>
struct Collection<mtl::vector::lazy_reduction<Vector, Functor> >
{
typedef std::size_t size_type;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Value, typename Parameters>
concept_map MutableCollection<mtl::matrix::dense2D<Value, Parameters> >
{
typedef Value value_type;
typedef const Value& const_reference;
typedef typename mtl::matrix::dense2D<Value, Parameters>::size_type size_type;
typedef Value& reference;
};
#else
template <typename Value, typename Parameters>
struct MutableCollection<mtl::matrix::dense2D<Value, Parameters> >
: public Collection<mtl::matrix::dense2D<Value, Parameters> >
{
typedef Value& reference;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Value, unsigned long Mask, typename Parameters>
concept_map MutableCollection<mtl::matrix::morton_dense<Value, Mask, Parameters> >
{
typedef Value value_type;
typedef const Value& const_reference;
typedef typename mtl::matrix::morton_dense<Value, Mask, Parameters>::size_type size_type;
typedef Value& reference;
};
#else
template <typename Value, unsigned long Mask, typename Parameters>
struct MutableCollection<mtl::matrix::morton_dense<Value, Mask, Parameters> >
: public Collection<mtl::matrix::morton_dense<Value, Mask, Parameters> >
{
typedef Value& reference;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Value, typename Parameters>
concept_map MutableCollection<mtl::vector::strided_vector_ref<Value, Parameters> >
{
typedef typename boost::remove_const<Value>::type value_type;
typedef const Value& const_reference;
typedef typename mtl::vector::strided_vector_ref<Value, Parameters>::size_type size_type;
typedef Value& reference;
};
#else
template <typename Value, typename Parameters>
struct MutableCollection<mtl::vector::strided_vector_ref<Value, Parameters> >
: public Collection<mtl::vector::strided_vector_ref<Value, Parameters> >
{
typedef Value& reference;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Value>
concept_map MutableCollection<<std::vector<Value> >
{
typedef typename std::vector<Value>::value_type value_type;
typedef typename std::vector<Value>::const_reference const_reference;
typedef typename std::vector<Value>::size_type size_type;
typedef typename std::vector<Value>::reference reference;
};
#else
template <typename Value>
struct MutableCollection<std::vector<Value> >
: public Collection<std::vector<Value> >
{
typedef typename std::vector<Value>::reference reference;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename T>
struct OrientedCollection<const T>
: OrientedCollection<T>
{};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Value, typename Parameters>
concept_map OrientedCollection<mtl::matrix::dense2D<Value, Parameters> >
{
typedef Value value_type;
typedef const Value& const_reference;
typedef typename mtl::matrix::dense2D<Value, Parameters>::size_type size_type;
typedef typename mtl::matrix::dense2D<Value, Parameters>::orientation orientation;
};
#else
template <typename Value, typename Parameters>
struct OrientedCollection<mtl::matrix::dense2D<Value, Parameters> >
: public Collection<mtl::matrix::dense2D<Value, Parameters> >
{
typedef typename mtl::matrix::dense2D<Value, Parameters>::orientation orientation;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Value, unsigned long Mask, typename Parameters>
concept_map OrientedCollection<mtl::matrix::morton_dense<Value, Mask, Parameters> >
{
typedef Value value_type;
typedef const Value& const_reference;
typedef typename mtl::matrix::morton_dense<Value, Mask, Parameters>::size_type size_type;
typedef typename mtl::matrix::morton_dense<Value, Mask, Parameters>::orientation orientation;
};
#else
template <typename Value, unsigned long Mask, typename Parameters>
struct OrientedCollection<mtl::matrix::morton_dense<Value, Mask, Parameters> >
: public Collection<mtl::matrix::morton_dense<Value, Mask, Parameters> >
{
typedef typename mtl::matrix::morton_dense<Value, Mask, Parameters>::orientation orientation;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Value, typename Parameters>
concept_map OrientedCollection<mtl::matrix::compressed2D<Value, Parameters> >
{
typedef Value value_type;
typedef const Value& const_reference;
typedef typename mtl::matrix::compressed2D<Value, Parameters>::size_type size_type;
typedef typename mtl::matrix::compressed2D<Value, Parameters>::orientation orientation;
};
#else
template <typename Value, typename Parameters>
struct OrientedCollection<mtl::matrix::compressed2D<Value, Parameters> >
: public Collection<mtl::matrix::compressed2D<Value, Parameters> >
{
typedef typename mtl::matrix::compressed2D<Value, Parameters>::orientation orientation;
};
#endif
#ifdef __GXX_CONCEPTS__
#else
template <typename Matrix>
struct OrientedCollection<mtl::matrix::indirect<Matrix> >
: public Collection<mtl::matrix::indirect<Matrix> >
{
typedef row_major orientation;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Value, typename Parameters>
concept_map OrientedCollection<mtl::vector::dense_vector<Value, Parameters> >
{
typedef Value value_type;
typedef const Value& const_reference;
typedef typename mtl::vector::dense_vector<Value, Parameters>::size_type size_type;
typedef typename mtl::vector::dense_vector<Value, Parameters>::orientation orientation;
};
#else
template <typename Value, typename Parameters>
struct OrientedCollection<mtl::vector::dense_vector<Value, Parameters> >
: public Collection<mtl::vector::dense_vector<Value, Parameters> >
{
typedef typename mtl::vector::dense_vector<Value, Parameters>::orientation orientation;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Value, typename Parameters>
concept_map OrientedCollection<mtl::vector::strided_vector_ref<Value, Parameters> >
{
typedef typename boost::remove_const<Value>::type value_type;
typedef const Value& const_reference;
typedef typename mtl::vector::strided_vector_ref<Value, Parameters>::size_type size_type;
typedef typename mtl::vector::strided_vector_ref<Value, Parameters>::orientation orientation;
};
#else
template <typename Value, typename Parameters>
struct OrientedCollection<mtl::vector::strided_vector_ref<Value, Parameters> >
: public Collection<mtl::vector::strided_vector_ref<Value, Parameters> >
{
typedef typename mtl::vector::strided_vector_ref<Value, Parameters>::orientation orientation;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Value>
concept_map OrientedCollection<std::vector<Value> >
{
typedef Value value_type;
typedef const Value& const_reference;
typedef typename std::vector<Value>::size_type size_type;
typedef mtl::tag::col_major orientation;
};
#else
template <typename Value>
struct OrientedCollection<std::vector<Value> >
: public Collection<std::vector<Value> >
{
typedef mtl::tag::col_major orientation;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Scaling, typename Coll>
concept_map OrientedCollection< matrix::scaled_view<Scaling, Coll> >
{
typedef typename matrix::scaled_view<Scaling, Coll>::value_type value_type;
typedef typename matrix::scaled_view<Scaling, Coll>::const_reference const_reference;
typedef typename matrix::scaled_view<Scaling, Coll>::size_type size_type;
typedef typename OrientedCollection<Coll>::orientation orientation;
};
#else
template <typename Scaling, typename Coll>
struct OrientedCollection< matrix::scaled_view<Scaling, Coll> >
: public Collection< matrix::scaled_view<Scaling, Coll> >
{
typedef typename OrientedCollection<Coll>::orientation orientation;
};
#endif
// added by Hui Li
#ifdef __GXX_CONCEPTS__
template <typename Coll, typename RScaling>
concept_map OrientedCollection< matrix::rscaled_view<Coll,RScaling> >
{
typedef typename matrix::rscaled_view<Coll,RScaling>::value_type value_type;
typedef typename matrix::rscaled_view<Coll,RScaling>::const_reference const_reference;
typedef typename matrix::rscaled_view<Coll,RScaling>::size_type size_type;
typedef typename OrientedCollection<Coll>::orientation orientation;
};
#else
template <typename Coll, typename RScaling>
struct OrientedCollection< matrix::rscaled_view<Coll,RScaling> >
: public Collection< matrix::rscaled_view<Coll,RScaling> >
{
typedef typename OrientedCollection<Coll>::orientation orientation;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Scaling, typename Coll>
concept_map OrientedCollection< mtl::vector::scaled_view<Scaling, Coll> >
{
typedef typename mtl::vector::scaled_view<Scaling, Coll>::value_type value_type;
typedef typename mtl::vector::scaled_view<Scaling, Coll>::const_reference const_reference;
typedef typename mtl::vector::scaled_view<Scaling, Coll>::size_type size_type;
typedef typename OrientedCollection<Coll>::orientation orientation;
};
#else
template <typename Scaling, typename Coll>
struct OrientedCollection< mtl::vector::scaled_view<Scaling, Coll> >
: public Collection< mtl::vector::scaled_view<Scaling, Coll> >
{
typedef typename OrientedCollection<Coll>::orientation orientation;
};
#endif
//added by Hui Li
#ifdef __GXX_CONCEPTS__
template <typename Coll, typename RScaling>
concept_map OrientedCollection< mtl::vector::rscaled_view<Coll,RScaling> >
{
typedef typename mtl::vector::rscaled_view<Coll,RScaling>::value_type value_type;
typedef typename mtl::vector::rscaled_view<Coll,RScaling>::const_reference const_reference;
typedef typename mtl::vector::rscaled_view<Coll,RScaling>::size_type size_type;
typedef typename OrientedCollection<Coll>::orientation orientation;
};
#else
template <typename Coll, typename RScaling>
struct OrientedCollection< mtl::vector::rscaled_view<Coll,RScaling> >
: public Collection< mtl::vector::rscaled_view<Coll,RScaling> >
{
typedef typename OrientedCollection<Coll>::orientation orientation;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Coll>
concept_map OrientedCollection<matrix::conj_view<Coll> >
{
typedef typename matrix::conj_view<Coll>::value_type value_type;
typedef typename matrix::conj_view<Coll>::const_reference const_reference;
typedef typename matrix::conj_view<Coll>::size_type size_type;
typedef typename OrientedCollection<Coll>::orientation orientation;
};
#else
template <typename Coll>
struct OrientedCollection<matrix::conj_view<Coll> >
: public Collection<matrix::conj_view<Coll> >
{
typedef typename OrientedCollection<Coll>::orientation orientation;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Coll>
concept_map OrientedCollection<mtl::vector::conj_view<Coll> >
{
typedef typename mtl::vector::conj_view<Coll>::value_type value_type;
typedef typename mtl::vector::conj_view<Coll>::const_reference const_reference;
typedef typename mtl::vector::conj_view<Coll>::size_type size_type;
typedef typename OrientedCollection<Coll>::orientation orientation;
};
#else
template <typename Coll>
struct OrientedCollection<mtl::vector::conj_view<Coll> >
: public Collection<mtl::vector::conj_view<Coll> >
{
typedef typename OrientedCollection<Coll>::orientation orientation;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Functor, typename Coll>
concept_map OrientedCollection< mtl::vector::map_view<Functor, Coll> >
{
typedef typename mtl::vector::map_view<Functor, Coll>::value_type value_type;
typedef typename mtl::vector::map_view<Functor, Coll>::const_reference const_reference;
typedef typename mtl::vector::map_view<Functor, Coll>::size_type size_type;
typedef typename OrientedCollection<Coll>::orientation orientation;
};
#else
template <typename Functor, typename Coll>
struct OrientedCollection< mtl::vector::map_view<Functor, Coll> >
: public Collection< mtl::vector::map_view<Functor, Coll> >
{
typedef typename OrientedCollection<Coll>::orientation orientation;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Coll>
concept_map OrientedCollection<mtl::matrix::transposed_view<Coll> >
{
typedef typename mtl::matrix::transposed_view<Coll>::value_type value_type;
typedef typename mtl::matrix::transposed_view<Coll>::const_reference const_reference;
typedef typename mtl::matrix::transposed_view<Coll>::size_type size_type;
typedef typename mtl::traits::transposed_orientation<typename OrientedCollection<Coll>::orientation>::type orientation;
};
#else
template <typename Coll>
struct OrientedCollection<mtl::matrix::transposed_view<Coll> >
: public Collection<mtl::matrix::transposed_view<Coll> >
{
typedef typename mtl::traits::transposed_orientation<typename OrientedCollection<Coll>::orientation>::type orientation;
};
#endif
#ifdef __GXX_CONCEPTS__
template <typename Coll>
concept_map OrientedCollection<matrix::hermitian_view<Coll> >
{
typedef typename matrix::hermitian_view<Coll>::value_type value_type;
typedef typename matrix::hermitian_view<Coll>::const_reference const_reference;
typedef typename matrix::hermitian_view<Coll>::size_type size_type;
typedef typename mtl::traits::transposed_orientation<typename OrientedCollection<Coll>::orientation>::type orientation;
};
#else
template <typename Coll>
struct OrientedCollection<matrix::hermitian_view<Coll> >
: public Collection<matrix::hermitian_view<Coll> >
{
typedef typename mtl::traits::transposed_orientation<typename OrientedCollection<Coll>::orientation>::type orientation;
};
#endif
/*@}*/ // end of group Concepts
} // namespace mtl
#endif // MTL_COLLECTION_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_MAGNITUDE_INCLUDE
#define MTL_MAGNITUDE_INCLUDE
#include <complex>
namespace mtl {
// =================================================
// Concept to specify return type of abs (and norms)
// =================================================
#ifdef __GXX_CONCEPTS__
// Concept to specify to specify projection of scalar value to comparable type
// For instance as return type of abs
// Minimalist definition for maximal applicability
auto concept Magnitude<typename T>
{
typename type = T;
};
template <typename T>
concept_map Magnitude<std::complex<T> >
{
typedef T type;
}
// Concept for norms etc., which are real values in mathematical definitions
auto concept RealMagnitude<typename T>
: Magnitude<T>
{
requires std::EqualityComparable<type>;
requires std::LessThanComparable<type>;
#ifndef CONCEPTS_WITHOUT_OVERLOADED_REQUIREMENTS
requires Field<type>;
#endif
type sqrt(type);
type abs(T);
}
#else // now without concepts
/// Concept/Type-trait for magnitudes of scalar values
/** This name is overloaded: when MTL4 is compiled with a concept-compiler
Magnitude is a concept otherwise a type-trait.
It is used for instance in norms.
**/
template <typename T>
struct Magnitude
{
/// Associated type; the default is T; must be specialized appropriately
typedef T type;
};
/// Specialization for complex numbers
template <typename T>
struct Magnitude<std::complex<T> >
{
/// The associated type is defined to the complex's value type
typedef T type;
};
template <typename T> struct RealMagnitude
: public Magnitude<T>
{};
#endif // __GXX_CONCEPTS__
} // namespace mtl
#endif // MTL_MAGNITUDE_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_CONCEPT_INCLUDE
#define MTL_MATRIX_CONCEPT_INCLUDE
#include <boost/numeric/mtl/mtl_fwd.hpp>
#include <boost/numeric/mtl/concept/collection.hpp>
#ifdef __GXX_CONCEPTS__
# include <concepts>
#else
# include <boost/numeric/linear_algebra/pseudo_concept.hpp>
#endif
namespace mtl {
/** @addtogroup Concepts
* @{
*/
#ifdef __GXX_CONCEPTS__
concept Matrix<typename T>
: AlgebraicCollection<T>
{
const_reference T::operator() (size_type row, size_type col) const;
size_type nnz(T);
// A[r][c] equivalent to A(r, c)
};
#else
/// Concept Matrix
/**
\par Refinement of:
- AlgebraicCollection < T >
\par Notation:
- X is a type that models Matrix
- A is an object of type X
- r, c are objects of size_type
\par Valid expressions:
- Element access: \n A(r, c) \n Return Type: const_reference
\n Semantics: Element in row \p r and column \p c
- Element access: \n A[r][c] \n Equivalent to A(r, c)
\par Models:
- dense2D
- morton_dense
- compressed2D
\note
-# The access via A[r][c] is supposed to be implemented by means of A(r, c) (typically via CRTP and proxies).
If it would become (extremely) important to support 2D C arrays, it might be necessary to drop the requirement
of element access by A(r, c).
-# The name const_reference does not imply that the return type is necessarily referrable. For instance compressed2D
returns value_type.
*/
template <typename T>
struct Matrix
: public AlgebraicCollection<T>
{
/// Element access
const_reference T::operator() (size_type row, size_type col) const;
};
#endif
#ifdef __GXX_CONCEPTS__
concept MatrixInserter<typename T>
{
typename matrix_type;
// typename T::matrix_type;
requires Matrix<matrix_type>;
typename proxy_type;
proxy_type operator() (Matrix<matrix_type>::size_type row, Matrix<matrix_type>::size_type col);
T operator<< (proxy_type, Matrix<matrix_type>::value_type>);
};
#else
/// Concept MatrixInserter: classes that enable efficient insertion into matrices, esp. compressed sparse.
/**
Used to fill non-mutable matrices like compressed2D. Matrix inserters might be parametrizable with
update functor. This allow to perform different operations when entry already exist, e.g. overwriting,
incrementing, minimum, ... The most important updates are certainly overwrite and increment (add).
\par Associated types
- matrix_type
\par Requires:
- Matrix<matrix_type>
\par Notation:
- X is a type that models MatrixInserter
- A is an object of type X
- r, c are objects of type Matrix<matrix_type>::size_type
- v is an object of type Matrix<matrix_type>::value_type
\par Valid expressions:
- Insertion with shift operator: \n
A(r, c) << v \n
Return type: T
\par Models:
- mtl::matrix::inserter < T >
\note
-# Used in concept InsertableMatrix
*/
template <typename T>
struct MatrixInserter
{
/// Type of matrix into which is inserted
typedef associated_type matrix_type;
/// Return type of element access; only proxy
typedef associated_type proxy_type;
/// Element access; returns a proxy that handles insertion
proxy_type operator() (Matrix<matrix_type>::size_type row, Matrix<matrix_type>::size_type col);
};
#endif
#ifdef __GXX_CONCEPTS__
concept InsertableMatrix<typename T>
: Matrix<T>
{
requires MatrixInserter<mtl::matrix::inserter<T> >;
};
#else
/// Concept InsertableMatrix: %matrix that can be filled by means of inserter
/**
\par Requires:
- MatrixInserter < mtl::matrix::inserter< T > >
\par Models:
- dense2D
- morton_dense
- compressed2D
\note
-# All matrices in MTL model this concept in order and all future matrices are supposed to.
*/
template <typename T>
struct InsertableMatrix
: Matrix < T >
{};
#endif
#ifdef __GXX_CONCEPTS__
concept MutableMatrix<typename T>
: Matrix<T>,
MutableCollection<T>
{
reference T::operator() (size_type row, size_type col);
// A[r][c] equivalent to A(r, c)
};
#else
/// Concept MutableMatrix
/**
\par Refinement of:
- Matrix < T >
- MutableCollection < T >
\par Notation:
- X is a type that models MutableMatrix
- A is an object of type X
- r, c are objects of size_type
\par Valid expressions:
- Element access: \n A(r, c) \n Return Type: reference
\n Semantics: Element in row \p r and column \p c
- Element access: \n A[r][c] \n Equivalent to A(r, c)
\par Models:
- dense2D
- morton_dense
\note
-# The access via A[r][c] is supposed to be implemented by means of A(r, c) (typically via CRTP and proxies).
If it would become (extremely) important to support 2D C arrays, it might be necessary to drop the requirement
of element access by A(r, c).
*/
template <typename T>
struct MutableMatrix
: public Matrix<T>,
public MutableCollection<T>
{
/// Element access (in addition to const access)
reference T::operator() (size_type row, size_type col);
};
#endif
#ifdef __GXX_CONCEPTS__
concept ConstantSizeMatrix<typename T>
: Matrix<T>,
ConstantSizeAlgebraicCollection<T>
{};
#else
/// Concept ConstantSizeMatrix
/**
\par Refinement of:
- Matrix < T >
- ConstantSizeAlgebraicCollection < T >
*/
template <typename T>
struct ConstantSizeMatrix
: public Matrix<T>,
public ConstantSizeAlgebraicCollection<T>
{};
#endif
#ifdef __GXX_CONCEPTS__
concept ResizeableMatrix<typename T>
: Matrix<T>
{
void T::resize(size_type r, size_type c);
};
#else
/// Concept ResizeableMatrix
/**
\par Refinement of:
- Matrix < T >
*/
template <typename T>
struct ResizeableMatrix
: public Matrix<T>
{
/// Resize function
/** If new memory should be allocated only if total size changes */
void resize(size_type r, size_type c);
};
#endif
#ifdef __GXX_CONCEPTS__
concept RowTraversableMatrix<typename M>
: Matrix<M>,
TraversableCollection<mtl::tag::row, M>
{};
#else
/// Concept RowTraversableMatrix: provides begin and end cursor to traverse rows
/**
\par Refinement of:
- Matrix < M >
- TraversableCollection <mtl::tag::row, M>
*/
template <typename M>
struct RowTraversableMatrix
: public Matrix<M>,
public TraversableCollection<mtl::tag::row, M>
{};
#endif
#ifdef __GXX_CONCEPTS__
concept ColumnTraversableMatrix<typename M>
: Matrix<M>,
TraversableCollection<mtl::tag::col, M>
{};
#else
/// Concept ColumnTraversableMatrix: provides begin and end cursor to traverse columns
/**
\par Refinement of:
- Matrix < M >
- TraversableCollection <mtl::tag::col, M>
*/
template <typename M>
struct ColumnTraversableMatrix
: public Matrix<M>,
public TraversableCollection<mtl::tag::col, M>
{};
#endif
#ifdef __GXX_CONCEPTS__
concept MajorTraversableMatrix<typename M>
: Matrix<M>,
TraversableCollection<mtl::tag::major, M>
{};
#else
/// Concept MajorTraversableMatrix: traversable on major dimension
/**
Concept for matrices that are traversable along the major dimension, i.e.
traversing the rows of a row-major matrix and the columns of a column-major matrices.
The cursors begin and end are provided.
\par Refinement of:
- Matrix < M >
- TraversableCollection <mtl::tag::major, M>
\note
-# This traversal corresponds to the iterator design in MTL 2.
*/
template <typename M>
struct MajorTraversableMatrix
: public Matrix<M>,
public TraversableCollection<mtl::tag::major, M>
{};
#endif
#ifdef __GXX_CONCEPTS__
concept MinorTraversableMatrix<typename M>
: Matrix<M>,
TraversableCollection<mtl::tag::minor, M>
{};
#else
/// Concept MinorTraversableMatrix: traversable on minor dimension
/**
Concept for matrices that are traversable along the minor dimension, i.e.
traversing the columns of a row-major matrix and the rows of a column-major matrices.
The cursors begin and end are provided.
\par Refinement of:
- Matrix < M >
- TraversableCollection <mtl::tag::minor, M>
\note
-# This traversal corresponds to the iterator design in MTL 2.
*/
template <typename M>
struct MinorTraversableMatrix
: public Matrix<M>,
public TraversableCollection<mtl::tag::minor, M>
{};
#endif
#ifdef __GXX_CONCEPTS__
concept AllTraversableMatrix<typename M>
: Matrix<M>,
TraversableCollection<mtl::tag::all, M>
{};
#else
/// Concept AllTraversableMatrix: provides traversion over all elements
/**
All elements of a matrix are traversed, including structural zeros. Can be used, e.g.,
for printing.
The cursors begin and end are provided.
\par Refinement of:
- Matrix < M >
- TraversableCollection <mtl::tag::all, M>
\note
-# For dense matrices the concept is equivalent to NonZeroTraversableMatrix.
*/
template <typename M>
struct AllTraversableMatrix
: public Matrix<M>,
public TraversableCollection<mtl::tag::all, M>
{};
#endif
#ifdef __GXX_CONCEPTS__
concept NonZeroTraversableMatrix<typename M>
: Matrix<M>,
TraversableCollection<mtl::tag::nz, M>
{};
#else
/// Concept NonZeroTraversableMatrix: provides traversion over all structural non-zeros
/**
All structural non-zero elements of a matrix are traversed. Can be used, e.g.,
for copying.
The cursors begin and end are provided.
\par Refinement of:
- Matrix < M >
- TraversableCollection <mtl::tag::all, M>
\note
-# For dense matrices the concept is equivalent to AllTraversableMatrix.
*/
template <typename M>
struct AllTraversableMatrix
: public Matrix<M>,
public TraversableCollection<mtl::tag::all, M>
{};
#endif
#ifdef __GXX_CONCEPTS__
concept AllTraversableSubMatrix<typename Tag, typename M>
: Matrix<M>,
TraversableCollection<Tag, M>,
TraversableCollection<mtl::tag::all, TraversableCollection<Tag, M>::result_type>
{};
#else
/// Concept AllTraversableSubMatrix: provides traversion of rows, columns of matrices
/**
All elements of a row or a column, according to the Tag, are traversed.
The cursors begin and end are provided.
\par Refinement of:
- Matrix < M >
- TraversableCollection<Tag, M>,
- TraversableCollection<mtl::tag::all, TraversableCollection<Tag, M>::result_type>
*/
template <typename Tag, typename M>
struct AllTraversableMatrix
: public Matrix<M>,
public TraversableCollection<Tag, M>,
public TraversableCollection<mtl::tag::all, TraversableCollection<Tag, M>::result_type>
{};
#endif
#ifdef __GXX_CONCEPTS__
concept NonZeroTraversableSubMatrix<typename Tag, typename M>
: Matrix<M>,
TraversableCollection<Tag, M>,
TraversableCollection<mtl::tag::nz, TraversableCollection<Tag, M>::result_type>
{};
#else
/// Concept NonZeroTraversableSubMatrix: provides traversion of non-zero in rows or columns of matrices
/**
All structural non-zero elements of a row or a column, according to the Tag, are traversed.
The cursors begin and end are provided.
\par Refinement of:
- Matrix < M >
- TraversableCollection<Tag, M>,
- TraversableCollection<mtl::tag::nz, TraversableCollection<Tag, M>::result_type>
*/
template <typename Tag, typename M>
struct NonZeroTraversableSubMatrix
: public Matrix<M>,
public TraversableCollection<Tag, M>,
public TraversableCollection<mtl::tag::nz, TraversableCollection<Tag, M>::result_type>
{};
#endif
#ifdef __GXX_CONCEPTS__
concept IteratableSubMatrix<typename Tag, typename ITag, typename M>
: Matrix<M>,
TraversableCollection<Tag, M>,
TraversableCollection<ITag, TraversableCollection<Tag, M>::result_type>
{};
#else
/// Concept IteratableSubMatrix: provides iteration over elements within rows or columns of matrices
/**
This concepts actually combines four sub-concepts. The iteration can be either performed over
all elements or only over structural non-zero elements whereby the iterator can be a const-iterator
or a mutable iterator. These four combinations are specified by the tags mtl::tag::iter::all,
mtl::tag::iter::nz, mtl::tag::const_iter::all, and
mtl::tag::const_iter::nz for ITag. The template parameter Tag can be mtl::tag::major or mtl::tag::column.
The cursors begin and end are provided.
\par Refinement of:
- Matrix < M >
- TraversableCollection<Tag, M>,
- TraversableCollection<ITag, TraversableCollection<Tag, M>::result_type>
*/
template <typename Tag, typename ITag, typename M>
struct IteratableSubMatrix
: public Matrix<M>,
public TraversableCollection<Tag, M>,
public TraversableCollection<ITag, TraversableCollection<Tag, M>::result_type>
{};
#endif
/*@}*/ // end of group Concepts
} // namespace mtl
#endif // MTL_MATRIX_CONCEPT_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_STATIC_FUNCTOR_INCLUDE
#define MTL_STATIC_FUNCTOR_INCLUDE
#include <complex>
namespace mtl {
#ifdef __GXX_CONCEPTS__
// Concept to specify static unary functors
auto concept StaticUnaryFunctor<typename T>
{
typename argument_type = T::argument_type;
typename result_type = T::result_type;
static result_type apply(argument_type);
result_type T::operator()(argument_type);
};
auto concept StaticBinaryFunctor<typename T>
{
typename first_argument_type = T::first_argument_type;
typename second_argument_type = T::second_argument_type;
typename result_type = T::result_type;
static result_type apply(first_argument_type, second_argument_type);
result_type T::operator()(first_argument_type, second_argument_type);
};
#else // now without concepts
/// Concept/Type-trait for static unary functors
/** This name is overloaded: when MTL4 is compiled with a concept-compiler
StaticUnaryFunctor is a concept otherwise a type-trait.
**/
template <typename T>
struct StaticUnaryFunctor
{
/// Associated type for argument, by default set to class's internal typedef (specialize if not present)
typedef typename T::argument_type argument_type;
/// Associated type for result, by default set to class's internal typedef (specialize if not present)
typedef typename T::result_type result_type;
};
/// Concept/Type-trait for static binary functors
/** This name is overloaded: when MTL4 is compiled with a concept-compiler
StaticBinaryFunctor is a concept otherwise a type-trait.
**/
template <typename T>
struct StaticBinaryFunctor
{
/// Associated type for 1st argument, by default set to class's internal typedef (specialize if not present)
typedef typename T::first_argument_type first_argument_type;
/// Associated type for 2nd argument, by default set to class's internal typedef (specialize if not present)
typedef typename T::second_argument_type second_argument_type;
/// Associated type for result, by default set to class's internal typedef (specialize if not present)
typedef typename T::result_type result_type;
};
#endif // __GXX_CONCEPTS__
} // namespace mtl
#endif // MTL_STATIC_FUNCTOR_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_STD_CONCEPT_INCLUDE
#define MTL_STD_CONCEPT_INCLUDE
#ifdef __GXX_CONCEPTS__
# include <concepts>
#else
// Use Joel de Guzman's return type deduction
# include <boost/numeric/ublas/detail/returntype_deduction.hpp>
# include <boost/mpl/at.hpp>
# include <boost/numeric/linear_algebra/pseudo_concept.hpp>
#endif
// #include <boost/numeric/mtl/utility/is_what.hpp> -> leads to cyclic inclusions
// #include <boost/numeric/mtl/operation/mult_result.hpp>
namespace mtl {
/**
* \defgroup Concepts Concepts
*/
/*@{*/
#ifdef __GXX_CONCEPTS__
// Stay with the old names (for the moment)
auto concept Addable<typename T, typename U = T> : std::HasPlus<T, U> {}
auto concept Subtractable<typename T, typename U = T> : std::HasMinus<T, U> {}
auto concept Multiplicable<typename T, typename U = T> : std::HasMultiply<T, U> {}
auto concept Divisible<typename T, typename U = T> : std::HasDivide<T, U> {}
#if 0
using std::Addable;
using std::Subtractable;
using std::Multiplicable;
auto concept Divisible<typename T, typename U = T>
{
typename result_type;
result_type operator/(const T& t, const U& u);
};
#endif
#else // without concepts
// Use Joel de Guzman's return type deduction
// Adapted from uBLAS
// Differences:
// - Separate types for all operations
// - result_type like in concept
/// Concept Addable: Binary operation
/** In concept-free compilations also used for return type deduction */
template<class X, class Y>
class Addable
{
typedef boost::numeric::ublas::type_deduction_detail::base_result_of<X, Y> base_type;
static typename base_type::x_type x;
static typename base_type::y_type y;
static const std::size_t size = sizeof (
boost::numeric::ublas::type_deduction_detail::test<
typename base_type::x_type
, typename base_type::y_type
>(x + y)
);
static const std::size_t index = (size / sizeof (char)) - 1;
typedef typename boost::mpl::at_c<
typename base_type::types, index>::type id;
public:
/// Result of addition
typedef typename id::type result_type;
};
/// Concept Subtractable: Binary operation
/** In concept-free compilations also used for return type deduction */
template<class X, class Y>
class Subtractable
{
typedef boost::numeric::ublas::type_deduction_detail::base_result_of<X, Y> base_type;
static typename base_type::x_type x;
static typename base_type::y_type y;
static const std::size_t size = sizeof (
boost::numeric::ublas::type_deduction_detail::test<
typename base_type::x_type
, typename base_type::y_type
>(x - y)
);
static const std::size_t index = (size / sizeof (char)) - 1;
typedef typename boost::mpl::at_c<
typename base_type::types, index>::type id;
public:
/// Result of subtraction
typedef typename id::type result_type;
};
#if 0 // doesn't work
template<class X, class Y>
class Multiplicable_aux<X, Y, true>
{
typedef typename mtl::traits::mult_result<X, Y>::type type;
};
/// Concept Multiplicable: Binary operation
/** In concept-free compilations also used for return type deduction */
template<class X, class Y, bool B>
class Multiplicable_aux
{
typedef boost::numeric::ublas::type_deduction_detail::base_result_of<X, Y> base_type;
static typename base_type::x_type x;
static typename base_type::y_type y;
static const std::size_t size = sizeof (
boost::numeric::ublas::type_deduction_detail::test<
typename base_type::x_type
, typename base_type::y_type
>(x * y)
);
static const std::size_t index = (size / sizeof (char)) - 1;
typedef typename boost::mpl::at_c<
typename base_type::types, index>::type id;
public:
/// Result of multiplication
typedef typename id::type result_type;
};
/// Concept Multiplicable: Binary operation
/** In concept-free compilations also used for return type deduction */
template<class X, class Y>
class Multiplicable
: Multiplicable_aux<X, Y, mtl::traits::is_scalar<X>::value && mtl::traits::is_scalar<Y>::value>
{};
#endif
/// Concept Multiplicable: Binary operation
/** In concept-free compilations also used for return type deduction */
template<class X, class Y>
class Multiplicable
{
typedef boost::numeric::ublas::type_deduction_detail::base_result_of<X, Y> base_type;
static typename base_type::x_type x;
static typename base_type::y_type y;
static const std::size_t size = sizeof (
boost::numeric::ublas::type_deduction_detail::test<
typename base_type::x_type
, typename base_type::y_type
>(x * y)
);
static const std::size_t index = (size / sizeof (char)) - 1;
typedef typename boost::mpl::at_c<
typename base_type::types, index>::type id;
public:
/// Result of multiplication
typedef typename id::type result_type;
};
/// Concept Divisible: Binary operation
/** In concept-free compilations also used for return type deduction */
template<class X, class Y>
class Divisible
{
typedef boost::numeric::ublas::type_deduction_detail::base_result_of<X, Y> base_type;
static typename base_type::x_type x;
static typename base_type::y_type y;
static const std::size_t size = sizeof (
boost::numeric::ublas::type_deduction_detail::test<
typename base_type::x_type
, typename base_type::y_type
>(x * y)
);
static const std::size_t index = (size / sizeof (char)) - 1;
typedef typename boost::mpl::at_c<
typename base_type::types, index>::type id;
public:
/// Result of division
typedef typename id::type result_type;
};
#endif
#ifdef __GXX_CONCEPTS__
concept UnaryStaticFunctor<typename F, typename T>
: std::Callable1<F, T>
{
typename result_type;
static result_type F::apply(T);
};
#else
/// Concept UnaryFunctor
/** With concept corresponds to std::Callable1 */
template <typename T>
struct UnaryFunctor
{
/// Result type of operator()
typedef associated_type result_type;
/// The unary function
result_type operator()(T);
};
/// Concept UnaryStaticFunctor
/**
\par Refinement of:
- std::Callable1 < T >
*/
template <typename T>
struct UnaryStaticFunctor
: public UnaryFunctor<T>
{
/// Result type of apply
typedef associated_type result_type;
/// The unary static function
static result_type apply(T);
/// The application operator behaves like apply. Exists for compatibility with UnaryFunctor
result_type operator()(T);
};
#endif
#ifdef __GXX_CONCEPTS__
auto concept BinaryStaticFunctor<typename F, typename T, typename U>
: std::Callable2<F, T, U>
{
typename result_type;
static result_type F::apply(T, U);
};
#else
/// Concept BinaryFunctor
/** With concept corresponds to std::Callable2 */
template <typename T, typename U>
struct BinaryFunctor
{
/// Result type of operator()
typedef associated_type result_type;
/// The unary function
result_type operator()(T, U);
};
/// Concept BinaryStaticFunctor
/**
\par Refinement of:
- BinaryFunctor <T, U>
*/
template <typename T, typename U>
struct BinaryStaticFunctor
: public BinaryFunctor <T, U>
{
/// Result type of apply
typedef associated_type result_type;
/// The unary static function
static result_type apply(T, U);
/// The application operator behaves like apply. Exists for compatibility with BinaryFunctor
result_type operator()(T, U);
};
#endif
/*@}*/ // end of group Concepts
} // namespace mtl
#endif // MTL_STD_CONCEPT_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_VECTOR_CONCEPTS_INCLUDE
#define MTL_VECTOR_CONCEPTS_INCLUDE
#include <boost/numeric/mtl/mtl_fwd.hpp>
#include <boost/numeric/mtl/concept/collection.hpp>
#ifdef __GXX_CONCEPTS__
# include <concepts>
#else
# include <boost/numeric/linear_algebra/pseudo_concept.hpp>
#endif
namespace mtl {
/** @addtogroup Concepts
* @{
*/
#ifdef __GXX_CONCEPTS__
concept Vector<typename T>
: AlgebraicCollection<T>
{
const_reference T::operator() (size_type index) const;
const_reference T::operator[] (size_type index) const;
size_type nnz(T); // maybe into AlgebraicCollection?
};
#else
/// Concept Vector
/**
\par Refinement of:
- AlgebraicCollection < T >
\par Notation:
- X is a type that models Vector
- v is an object of type X
- r are objects of size_type
\par Valid expressions:
- Element access: \n v(r) \n Return Type: const_reference
\n Semantics: Element in row \p r and column \p c
- Element access: \n v[r] \n Equivalent to v(r)
\invariant
- Either num_cols(v), in case of a column vector, or num_rows(v),
in case of a row vector, must be 1! Otherwise it would be
a matrix.
\par Models:
- dense_vector
\note
-# If it would become (extremely) important to support 1D C arrays as Vector,
it might be necessary to drop the requirement
of element access by v(r).
*/
template <typename T>
struct Vector
: public AlgebraicCollection<T>
{
/// Element access
const_reference T::operator() (size_type index) const;
/// Element access
const_reference T::operator[] (size_type index) const;
};
#endif
#ifdef __GXX_CONCEPTS__
concept MutableVector<typename T>
: Vector<T>,
MutableCollection<T>
{
reference T::operator() (size_type index);
reference T::operator[] (size_type index);
};
#else
/// Concept MutableVector
/**
\par Refinement of:
- Vector < T >
- MutableCollection < T >
\par Notation:
- X is a type that models Vector
- v is an object of type X
- r are objects of size_type
\par Valid expressions:
- Element access: \n v(r) \n Return Type: reference
\n Semantics: Element in row \p r for a column vector or in column \p c for a row vector
- Element access: \n v[r] \n Equivalent to v(r)
\par Models:
- dense_vector
\note
-# If it would become (extremely) important to support 1D C arrays as Vector,
it might be necessary to drop the requirement
of element access by v(r).
*/
template <typename T>
struct MutableVector
: public Vector<T>,
public MutableCollection<T>
{};
#endif
#ifdef __GXX_CONCEPTS__
concept ConstantSizeVector<typename T>
: Vector<T>,
ConstantSizeAlgebraicCollection<T>
{};
#else
/// Concept ConstantSizeVector
/**
\par Refinement of:
- Vector < T >
- ConstantSizeAlgebraicCollection < T >
*/
template <typename T>
struct ConstantSizeVector
: public Vector<T>,
public ConstantSizeAlgebraicCollection<T>
{};
#endif
/*@}*/ // end of group Concepts
} // namespace mtl
#endif // MTL_VECTOR_CONCEPTS_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_CONFIG_INCLUDE
#define MTL_CONFIG_INCLUDE
namespace mtl {
namespace matrix {
// parameters for dense operations
# ifdef MTL_MATRIX_DENSE_NON_RECURSIVE_PRODUCT_LIMIT
const std::size_t dense_non_recursive_product_limit= MTL_MATRIX_DENSE_NON_RECURSIVE_PRODUCT_LIMIT;
# else
/// Maximal matrix size of dense matrices that is multiplied without recursion
/** Can be reset with a macro definition or corresponding compiler flag,
e.g. {-D|/D}MTL_MATRIX_DENSE_NON_RECURSIVE_PRODUCT_LIMIT=4000 **/
const std::size_t dense_non_recursive_product_limit= 10000;
# endif
# ifdef MTL_STRAIGHT_DMAT_DMAT_MULT_LIMIT
const std::size_t straight_dmat_dmat_mult_limit= MTL_STRAIGHT_DMAT_DMAT_MULT_LIMIT;
# else
/// Defines the maximal number of entries in each matrix for which the dense matrix product is computed in C++.
/** Above this limit the computation is performed with BLAS if available.
Can be reset with a macro definition or corresponding compiler flag,
e.g. {-D|/D}MTL_STRAIGHT_DMAT_DMAT_MULT_LIMIT=4000 **/
const std::size_t straight_dmat_dmat_mult_limit= 1000;
# endif
# ifdef MTL_FULLY_UNROLL_DMAT_DMAT_MULT_LIMIT
const std::size_t fully_unroll_dmat_dmat_mult_limit= MTL_FULLY_UNROLL_DMAT_DMAT_MULT_LIMIT;
# else
/// Defines the maximal number of entries in each matrix for which the dense matrix product is fully unrolled.
/** Above this limit the computation is performed with a tiled loop implementation.
Applies only to statically sized matrices.
Can be reset with a macro definition or corresponding compiler flag,
e.g. {-D|/D}MTL_FULLY_UNROLL_DMAT_DMAT_MULT_LIMIT=40 **/
const std::size_t fully_unroll_dmat_dmat_mult_limit= 10;
# endif
// parameters for sparse operations
# ifdef MTL_MATRIX_COMPRESSED_LINEAR_SEARCH_LIMIT
const std::size_t compressed_linear_search_limit= MTL_MATRIX_COMPRESSED_LINEAR_SEARCH_LIMIT;
# else
/// Maximal number of entries that is searched linearly within a row/column of a CRS/CCS matrix
/** Above this std::lower_bound is used.
Can be reset with a macro definition or corresponding compiler flag,
e.g. {-D|/D}MTL_MATRIX_COMPRESSED_LINEAR_SEARCH_LIMIT=16 **/
const std::size_t compressed_linear_search_limit= 10;
# endif
# ifdef MTL_SORTED_BLOCK_INSERTION_LIMIT
const std::size_t sorted_block_insertion_limit= MTL_SORTED_BLOCK_INSERTION_LIMIT;
# else
/// Maximal number of columns in block that is inserted separately; above this the block is presorted (only row-major sparse matrices).
/** Can be reset with a macro definition or corresponding compiler flag,
e.g. {-D|/D}MTL_SORTED_BLOCK_INSERTION_LIMIT=8
Default is 5. **/
const std::size_t sorted_block_insertion_limit= 5;
# endif
# ifdef MTL_CRS_CVEC_MULT_BLOCK_SIZE
const std::size_t crs_cvec_mult_block_size= MTL_CRS_CVEC_MULT_BLOCK_SIZE;
# else
/// Number of rows that are handled independently in each iteration of CRS times vector product
/** The independent treatment of multiple matrix rows enables concurrency
(although we do not explicit parallelize the matrix product here).
The default is treating 4 rows in each iteration.
This default can be changed with a macro definition or corresponding compiler flag,
e.g. {-D|/D}MTL_CRS_CVEC_MULT_BLOCK_SIZE=8
At the same the macro MTL_CRS_CVEC_MULT_TUNING must be defined. **/
const std::size_t crs_cvec_mult_block_size= 4;
# endif
}
} // namespace mtl
#endif // MTL_CONFIG_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_BASE_CURSOR_INCLUDE
#define MTL_BASE_CURSOR_INCLUDE
namespace mtl { namespace detail {
// base class for different cursors, works with pointers and integers
template <class Key> class base_cursor
{
public:
typedef Key key_type;
typedef base_cursor self;
base_cursor () {}
base_cursor (key_type key) : key(key) {}
key_type operator*() const
{
return key;
}
key_type value() const
{
return key;
}
self& operator++ ()
{
++key; return *this;
}
self operator++ (int)
{
self tmp = *this;
++key;
return tmp;
}
self& operator-- ()
{
--key;
return *this;
}
self operator-- (int)
{
self tmp = *this;
--key;
return tmp;
}
self& operator+=(int n)
{
key += n;
return *this;
}
self operator+(int n) const
{
self tmp = *this;
tmp+= n;
return tmp;
}
self& operator-=(int n)
{
key -= n;
return *this;
}
int operator-(const self& cc) const
{
return this->key - cc.key;
}
bool operator==(const self& cc) const
{
return key == cc.key;
}
bool operator!=(const self& cc) const
{
return !(*this == cc);
}
key_type key;
}; // base_cursor
}} // namespace mtl::detail
#endif // MTL_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_CONTIGUOUS_MEMORY_BLOCK_INCLUDE
#define MTL_CONTIGUOUS_MEMORY_BLOCK_INCLUDE
#include <cassert>
#include <algorithm>
#include <boost/static_assert.hpp>
#include <boost/numeric/mtl/mtl_fwd.hpp>
#include <boost/numeric/mtl/utility/tag.hpp>
#include <boost/numeric/mtl/utility/exception.hpp>
#include <boost/numeric/mtl/matrix/dimension.hpp>
#include <boost/numeric/mtl/detail/index.hpp>
#include <boost/numeric/mtl/operation/clone.hpp>
namespace mtl { namespace detail {
using std::size_t;
// Macro MTL_ENABLE_ALIGNMENT is by default not set
// Minimal size of memory allocation using alignment
#ifndef MTL_ALIGNMENT_LIMIT
# define MTL_ALIGNMENT_LIMIT 1024
#endif
// Alignment in memory
#ifndef MTL_ALIGNMENT
# define MTL_ALIGNMENT 128
#endif
// Size helper for static size
template <unsigned Size>
struct size_helper
{
typedef size_helper self;
size_helper() {}
explicit size_helper(std::size_t size)
{
set_size(size);
}
# ifndef MTL_IGNORE_STATIC_SIZE_VIOLATION
void set_size(std::size_t MTL_DEBUG_ARG(size))
{ MTL_DEBUG_THROW_IF(Size != size, change_static_size()); }
# else
void set_size(std::size_t) {}
# endif
std::size_t used_memory() const { return Size; }
friend void swap(self&, self&) {}
};
// Manage size only if template parameter is 0, i.e. dynamic size
template <>
struct size_helper<0>
{
typedef size_helper self;
size_helper(std::size_t size= 0) : my_used_memory(size) {}
void set_size(std::size_t size)
{
my_used_memory= size;
}
std::size_t used_memory() const
{
return my_used_memory;
}
friend void swap(self& x, self& y)
{
std::swap(x.my_used_memory, y.my_used_memory);
}
protected:
std::size_t my_used_memory;
};
// Encapsulate behavior of alignment
# ifdef MTL_ENABLE_ALIGNMENT
template <typename Value>
struct alignment_helper
{
typedef alignment_helper self;
alignment_helper() : malloc_address(0) {}
Value* alligned_alloc(std::size_t size)
{
if (size == 0)
return 0;
bool align= size * sizeof(value_type) >= MTL_ALIGNMENT_LIMIT;
std::size_t bytes= size * sizeof(value_type);
if (align)
bytes+= MTL_ALIGNMENT - 1;
char* p= malloc_address= new char[bytes];
if (align)
while ((long int)(p) % MTL_ALIGNMENT) p++;
// p+= MTL_ALIGNMENT - (long int)(p) % MTL_ALIGNMENT;
return reinterpret_cast<value_type*>(p);
}
void aligned_delete(bool is_own, Value*& data)
{
if (is_own && malloc_address) delete[] malloc_address;
data= 0;
}
friend void swap(self& x, self& y)
{
using std::swap
swap(x.malloc_address, y.malloc_address);
}
private:
char* malloc_address;
};
# else
template <typename Value>
struct alignment_helper
{
typedef alignment_helper self;
Value* alligned_alloc(std::size_t size) { return size > 0 ? new Value[size] : (Value*)(0); }
void aligned_delete(bool is_own, Value*& data)
{
if (is_own && data != 0) // std::cout << "Delete " << data << '\n',
delete[] data, data= 0;
}
friend void swap(self&, self&) {}
};
# endif
template <typename Value, bool OnStack, unsigned Size>
struct memory_crtp
// : public contiguous_memory_block<Value, OnStack, Size>
{
typedef contiguous_memory_block<Value, OnStack, Size> base;
static bool const on_stack= OnStack;
typedef Value value_type;
typedef value_type* pointer_type;
typedef const value_type* const_pointer_type;
// offset of key (pointer) w.r.t. data
// values must be stored consecutively
size_t offset(const Value* p) const
{
return p - static_cast<const base&>(*this).data;
}
// returns pointer to data
pointer_type elements()
{
return static_cast<base&>(*this).data;
}
// returns const pointer to data
const_pointer_type elements() const
{
return static_cast<const base&>(*this).data;
}
// returns n-th value in consecutive memory
// (whatever this means in the corr. matrix format)
value_type& value_n(size_t offset)
{
return static_cast<base&>(*this).data[offset];
}
// returns n-th value in consecutive memory
// (whatever this means in the corr. matrix format)
const value_type& value_n(size_t offset) const
{
return static_cast<const base&>(*this).data[offset];
}
};
// OnStack == false -> data on heap
template <typename Value, bool OnStack, unsigned Size>
struct contiguous_memory_block
: public size_helper<Size>,
public alignment_helper<Value>,
public memory_crtp<Value, OnStack, Size>
{
typedef Value value_type;
typedef contiguous_memory_block self;
typedef size_helper<Size> size_base;
typedef alignment_helper<Value> alignment_base;
typedef memory_crtp<Value, OnStack, Size> crtp_base;
/// Category of memory, determines behaviour
enum c_t {own, //< My own memory: allocate and free it
external, //< Memory, complete memory block of other item, only reference
view //< View of other's memory (e.g. sub-matrix), different construction than external
};
private:
void alloc(std::size_t size)
{
category= own;
this->set_size(size);
data= this->alligned_alloc(this->used_memory());
}
void delete_it()
{
this->aligned_delete(category == own, data);
}
template <typename Other>
void copy_construction(const Other& other)
{
using std::copy;
category= own;
// std::cout << "Copied in copy constructor.\n";
alloc(other.used_memory());
// std::cout << "My address: " << data << ", other address: " << other.data << '\n';
copy(other.data, other.data + other.used_memory(), data);
}
void move_construction(self& other)
{
// std::cout << "Data moved in constructor.\n";
category= own; data= 0;
swap(*this, other);
}
// Copy the arguments of a view (shallowly) and leave original as it is
void copy_view(const self& other)
{
// std::cout << "View copied (shallowly).\n";
assert(other.category == view);
category= view;
this->set_size(other.used_memory());
data= other.data;
}
template <typename Other>
void copy_assignment(const Other& other)
{
// std::cout << "Copied in assignment.\n";
if (this->used_memory() == 0)
alloc(other.used_memory());
MTL_DEBUG_THROW_IF(this->used_memory() != other.used_memory(), incompatible_size());
std::copy(other.data, other.data + other.used_memory(), data);
}
public:
contiguous_memory_block() : category(own), data(0) {}
explicit contiguous_memory_block(Value *data, std::size_t size, bool is_view= false)
: size_base(size), category(is_view ? view : external), data(data)
{}
explicit contiguous_memory_block(std::size_t size) : category(own)
{
// std::cout << "Constructor with size.\n";
alloc(size);
// std::cout << "New block at " << data << '\n';
}
// Default copy constructor
contiguous_memory_block(const self& other) : size_base(other)
{
// std::cout << "Copy constructor (same type).\n";
if (other.category == view)
copy_view(other);
else
copy_construction(other);
}
// Force copy construction
contiguous_memory_block(const self& other, clone_ctor)
{
// std::cout << "(Forced) Copy constructor (same type).\n";
copy_construction(other);
}
// Other types must be copied always
template<typename Value2, bool OnStack2, unsigned Size2>
explicit contiguous_memory_block(const contiguous_memory_block<Value2, OnStack2, Size2>& other)
{
std::cout << "Copy constructor (different type).\n";
copy_construction(other);
}
#ifdef MTL_WITH_MOVE
self& operator=(self&& other)
{
move_assignment(other);
return *this;
}
self& operator=(const self& other)
{
copy_assignment(other);
return *this;
}
#elif defined(MTL_MEMORY_BLOCK_MOVE_EMULATION)
// Operator takes parameter by value and consumes it
self& operator=(self other)
{
move_assignment(other);
return *this;
}
#else
self& operator=(self other)
{
copy_assignment(other);
return *this;
}
#endif
// Same behavior as consuming assignment, to be used by derived classes
protected:
void move_assignment(self& other)
{
// std::cout << "Consuming assignment operator (if same type).\n";
if (category == own && other.category == own)
swap(*this, other);
else
copy_assignment(other);
}
public:
template<typename Value2, bool OnStack2, unsigned Size2>
self& operator=(const contiguous_memory_block<Value2, OnStack2, Size2>& other)
{
// std::cout << "Assignment from different array type -> Copy.\n";
copy_assignment(other);
return *this;
}
void set_view() { category= view; }
void realloc(std::size_t size)
{
if (Size == 0) {
// If already have memory of the right size we can keep it
if (size == this->used_memory())
return;
MTL_DEBUG_THROW_IF(category != own,
logic_error("Can't change the size of collections with external memory"));
delete_it();
alloc(size);
} else {
MTL_DEBUG_THROW_IF(size != Size, logic_error("Can't change static size"));
}
}
~contiguous_memory_block()
{
//std::cout << "Delete block with address " << data << '\n';
delete_it();
}
friend void swap(self& x, self& y)
{
using std::swap;
swap(x.category, y.category);
std::swap(x.data, y.data);
swap(static_cast<size_base&>(x), static_cast<size_base&>(y));
swap(static_cast<alignment_base&>(x), static_cast<alignment_base&>(y));
}
protected:
enum c_t category;
public:
Value *data;
};
// OnStack == true
template <typename Value, unsigned Size>
struct contiguous_memory_block<Value, true, Size>
: public alignment_helper<Value>,
public memory_crtp<Value, true, Size>
{
typedef Value value_type;
typedef contiguous_memory_block self;
//static bool const on_stack= true;
Value data[Size];
# ifdef NDEBUG
contiguous_memory_block() {} // default constructor in release mode
explicit contiguous_memory_block(std::size_t) {}
# else
explicit contiguous_memory_block(std::size_t size= Size)
{
MTL_DEBUG_THROW_IF(Size != size, incompatible_size());
}
# endif
// Move-semantics ignored for arrays on stack
contiguous_memory_block(const self& other)
{
// std::cout << "Copied in copy constructor (same type).\n";
std::copy(other.data, other.data+Size, data);
}
template<typename Value2, bool OnStack2, unsigned Size2>
explicit contiguous_memory_block(const contiguous_memory_block<Value2, OnStack2, Size2>& other)
{
// std::cout << "Copied in copy constructor (different type).\n";
MTL_DEBUG_THROW_IF(Size != other.used_memory(), incompatible_size());
std::copy(other.data, other.data + other.used_memory(), data);
}
self& operator=(const self& other)
{
// std::cout << "Assignment from same type.\n";
std::copy(other.data, other.data+Size, data);
return *this;
}
// For consistency with non-static blocks, to be used by derived classes
protected:
void move_assignment(self& other)
{
std::copy(other.data, other.data+Size, data);
}
public:
template<typename Value2, bool OnStack2, unsigned Size2>
self& operator=(const contiguous_memory_block<Value2, OnStack2, Size2>& other)
{
// std::cout << "Assignment from different type.\n";
MTL_DEBUG_THROW_IF(Size != other.used_memory(), incompatible_size());
std::copy(other.data, other.data + other.used_memory(), data);
return *this;
}
void realloc(std::size_t MTL_DEBUG_ARG(s))
{
// Arrays on stack cannot be reallocated but if the size isn't changed we are fine
assert(s == Size);
}
std::size_t used_memory() const
{
return Size;
}
protected:
enum c_t {own};
static const c_t category= own;
};
}} // namespace mtl::detail
namespace mtl {
template <typename Value, bool OnStack, unsigned Size>
struct is_clonable< detail::contiguous_memory_block<Value, OnStack, Size> > : boost::mpl::bool_<!OnStack> {};
}
#endif // MTL_CONTIGUOUS_MEMORY_BLOCK_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.
//
// Written by Jiahu Deng and Peter Gottschling
#ifndef MTL_DILATED_INT_INCLUDE
#define MTL_DILATED_INT_INCLUDE
#include <boost/numeric/mtl/detail/masked_dilation_tables.hpp>
#include <iostream>
namespace mtl { namespace dilated {
template <typename T>
struct even_bits
{
static T const value = T(-1) / T(3);
};
template <typename T>
struct odd_bits
{
static T const value = ~even_bits<T>::value;
};
// And is mostly used with original mask
template <typename T, T BitMask, bool Normalized>
struct masking
{
inline void operator() (T& x) const
{
x &= BitMask;
}
};
// Or is mostly used with complementary mask
template <typename T, T BitMask>
struct masking<T, BitMask, false>
{
inline void operator() (T& x) const
{
static T const anti_mask = ~BitMask;
x |= anti_mask;
}
};
template <typename T, T BitMask>
struct last_bit;
template <typename T, T BitMask, bool IsZero>
struct last_bit_helper {
static T const tmp = BitMask >> 1;
static T const value = BitMask & 1 ? 1 : last_bit_helper<T, tmp, tmp == 0>::value << 1;
};
template <typename T, T BitMask>
struct last_bit_helper<T, BitMask, true> {
static T const value = 0;
};
template <typename T, T BitMask>
struct last_bit
{
static T const value = last_bit_helper<T, BitMask, BitMask == 0>::value;
};
template <typename T, T BitMask, bool Normalized>
struct dilated_int
{
typedef T value_type;
typedef dilated_int<T, BitMask, Normalized> self;
typedef masking<T, BitMask, Normalized> clean_carry;
typedef masking<T, BitMask, !Normalized> init_carry;
static T const bit_mask = BitMask,
anti_mask = ~BitMask,
dilated_zero = Normalized ? 0 : anti_mask,
dilated_one = dilated_zero + last_bit<T, bit_mask>::value;
protected:
// masked_dilation_tables<T, bit_mask> mask_tables;
// masked_dilation_tables<T, anti_mask> anti_tables; probably not needed
// will be protected later
public:
T i;
void dilate(T x)
{
static const T to_switch_on = Normalized ? 0 : anti_mask;
i = mask<bit_mask>(x) | to_switch_on;
}
public:
// Default constructor
dilated_int()
{
i = Normalized ? 0 : anti_mask;
}
// Only works for odd and even bits and 4-byte-int at this point !!!!!!!!!!!!!!!!!!!
explicit dilated_int(T x)
{
dilate(x);
}
// Only works for odd and even bits and 4-byte-int at this point !!!!!!!!!!!!!!!!!!!
T undilate()
{
return unmask<bit_mask>(i);
}
T dilated_value() const
{
return i;
}
self& operator= (self const& x)
{
i = x.i;
return *this;
}
self& operator= (T x)
{
dilate(x);
return *this;
}
self& operator++ ()
{
static T const x = Normalized ? bit_mask : T(-1);
i -= x;
clean_carry()(i);
return *this;
}
self operator++ (int)
{
self tmp(*this);
++*this;
return tmp;
}
self& operator+= (self const& x)
{
init_carry()(i);
i+= x.i;
clean_carry()(i);
return *this;
}
self operator+ (self const& x)
{
self tmp(*this);
return tmp += x;
}
self& operator-- ()
{
i -= dilated_one;
clean_carry()(i);
return *this;
}
self operator-- (int)
{
self tmp(*this);
--*this;
return tmp;
}
self& operator-= (self const& x)
{
i -= x.i;
clean_carry()(i);
return *this;
}
self operator- (self const& x) const
{
self tmp(*this);
return tmp -= x;
}
// advance in both directions, special care is needed for negative values
self& advance(int inc)
{
value_type incv(inc >= 0 ? inc : -inc);
self incd(incv);
if (inc >= 0)
operator+=(incd);
else
operator-=(incd);
return *this;
}
bool operator== (self const& x) const
{
return i == x.i;
}
bool operator!= (self const& x) const
{
return i != x.i;
}
bool operator<= (self const& x) const
{
return i <= x.i;
}
bool operator< (self const& x) const
{
return i < x.i;
}
bool operator>= (self const& x) const
{
return i >= x.i;
}
bool operator> (self const& x) const
{
return i > x.i;
}
};
} // namespace mtl::dilated
using dilated::dilated_int;
} // namespace mtl
template <typename T, T BitMask, bool Normalized>
inline std::ostream& operator<< (std::ostream& os, mtl::dilated::dilated_int<T, BitMask, Normalized> d)
{
os.setf(std::ios_base::hex, std::ios_base::basefield);
return os << d.i;
}
#endif // MTL_DILATED_INT_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.
//
// Written by Jiahu Deng and Peter Gottschling
/* This is designed for 16-bit undilated integers and 32-bit dilated
* integers. If we want to scale that up, it's an easy change but you will
* need to make it. - Greg 00/05/12
*/
/* Rewrote by Jiahu Deng 06/08/2005
modified the undilated-lookup table, use the algorithms from
Prof.Wise's paper, Converting to and from Dilated Integers.
Added supports for anti-dilated integers.
*/
#ifndef MTL_DILATION_TABLE_INCLUDE
#define MTL_DILATION_TABLE_INCLUDE
namespace mtl { namespace dilated {
static const unsigned short int dilate_lut[256] = {
0x0000, 0x0001, 0x0004, 0x0005, 0x0010, 0x0011, 0x0014, 0x0015,
0x0040, 0x0041, 0x0044, 0x0045, 0x0050, 0x0051, 0x0054, 0x0055,
0x0100, 0x0101, 0x0104, 0x0105, 0x0110, 0x0111, 0x0114, 0x0115,
0x0140, 0x0141, 0x0144, 0x0145, 0x0150, 0x0151, 0x0154, 0x0155,
0x0400, 0x0401, 0x0404, 0x0405, 0x0410, 0x0411, 0x0414, 0x0415,
0x0440, 0x0441, 0x0444, 0x0445, 0x0450, 0x0451, 0x0454, 0x0455,
0x0500, 0x0501, 0x0504, 0x0505, 0x0510, 0x0511, 0x0514, 0x0515,
0x0540, 0x0541, 0x0544, 0x0545, 0x0550, 0x0551, 0x0554, 0x0555,
0x1000, 0x1001, 0x1004, 0x1005, 0x1010, 0x1011, 0x1014, 0x1015,
0x1040, 0x1041, 0x1044, 0x1045, 0x1050, 0x1051, 0x1054, 0x1055,
0x1100, 0x1101, 0x1104, 0x1105, 0x1110, 0x1111, 0x1114, 0x1115,
0x1140, 0x1141, 0x1144, 0x1145, 0x1150, 0x1151, 0x1154, 0x1155,
0x1400, 0x1401, 0x1404, 0x1405, 0x1410, 0x1411, 0x1414, 0x1415,
0x1440, 0x1441, 0x1444, 0x1445, 0x1450, 0x1451, 0x1454, 0x1455,
0x1500, 0x1501, 0x1504, 0x1505, 0x1510, 0x1511, 0x1514, 0x1515,
0x1540, 0x1541, 0x1544, 0x1545, 0x1550, 0x1551, 0x1554, 0x1555,
0x4000, 0x4001, 0x4004, 0x4005, 0x4010, 0x4011, 0x4014, 0x4015,
0x4040, 0x4041, 0x4044, 0x4045, 0x4050, 0x4051, 0x4054, 0x4055,
0x4100, 0x4101, 0x4104, 0x4105, 0x4110, 0x4111, 0x4114, 0x4115,
0x4140, 0x4141, 0x4144, 0x4145, 0x4150, 0x4151, 0x4154, 0x4155,
0x4400, 0x4401, 0x4404, 0x4405, 0x4410, 0x4411, 0x4414, 0x4415,
0x4440, 0x4441, 0x4444, 0x4445, 0x4450, 0x4451, 0x4454, 0x4455,
0x4500, 0x4501, 0x4504, 0x4505, 0x4510, 0x4511, 0x4514, 0x4515,
0x4540, 0x4541, 0x4544, 0x4545, 0x4550, 0x4551, 0x4554, 0x4555,
0x5000, 0x5001, 0x5004, 0x5005, 0x5010, 0x5011, 0x5014, 0x5015,
0x5040, 0x5041, 0x5044, 0x5045, 0x5050, 0x5051, 0x5054, 0x5055,
0x5100, 0x5101, 0x5104, 0x5105, 0x5110, 0x5111, 0x5114, 0x5115,
0x5140, 0x5141, 0x5144, 0x5145, 0x5150, 0x5151, 0x5154, 0x5155,
0x5400, 0x5401, 0x5404, 0x5405, 0x5410, 0x5411, 0x5414, 0x5415,
0x5440, 0x5441, 0x5444, 0x5445, 0x5450, 0x5451, 0x5454, 0x5455,
0x5500, 0x5501, 0x5504, 0x5505, 0x5510, 0x5511, 0x5514, 0x5515,
0x5540, 0x5541, 0x5544, 0x5545, 0x5550, 0x5551, 0x5554, 0x5555,
};
static const unsigned short int anti_dilate_lut[256] = {
0xaaaa,0xaaab,0xaaae,0xaaaf,0xaaba,0xaabb,0xaabe,0xaabf,
0xaaea,0xaaeb,0xaaee,0xaaef,0xaafa,0xaafb,0xaafe,0xaaff,
0xabaa,0xabab,0xabae,0xabaf,0xabba,0xabbb,0xabbe,0xabbf,
0xabea,0xabeb,0xabee,0xabef,0xabfa,0xabfb,0xabfe,0xabff,
0xaeaa,0xaeab,0xaeae,0xaeaf,0xaeba,0xaebb,0xaebe,0xaebf,
0xaeea,0xaeeb,0xaeee,0xaeef,0xaefa,0xaefb,0xaefe,0xaeff,
0xafaa,0xafab,0xafae,0xafaf,0xafba,0xafbb,0xafbe,0xafbf,
0xafea,0xafeb,0xafee,0xafef,0xaffa,0xaffb,0xaffe,0xafff,
0xbaaa,0xbaab,0xbaae,0xbaaf,0xbaba,0xbabb,0xbabe,0xbabf,
0xbaea,0xbaeb,0xbaee,0xbaef,0xbafa,0xbafb,0xbafe,0xbaff,
0xbbaa,0xbbab,0xbbae,0xbbaf,0xbbba,0xbbbb,0xbbbe,0xbbbf,
0xbbea,0xbbeb,0xbbee,0xbbef,0xbbfa,0xbbfb,0xbbfe,0xbbff,
0xbeaa,0xbeab,0xbeae,0xbeaf,0xbeba,0xbebb,0xbebe,0xbebf,
0xbeea,0xbeeb,0xbeee,0xbeef,0xbefa,0xbefb,0xbefe,0xbeff,
0xbfaa,0xbfab,0xbfae,0xbfaf,0xbfba,0xbfbb,0xbfbe,0xbfbf,
0xbfea,0xbfeb,0xbfee,0xbfef,0xbffa,0xbffb,0xbffe,0xbfff,
0xeaaa,0xeaab,0xeaae,0xeaaf,0xeaba,0xeabb,0xeabe,0xeabf,
0xeaea,0xeaeb,0xeaee,0xeaef,0xeafa,0xeafb,0xeafe,0xeaff,
0xebaa,0xebab,0xebae,0xebaf,0xebba,0xebbb,0xebbe,0xebbf,
0xebea,0xebeb,0xebee,0xebef,0xebfa,0xebfb,0xebfe,0xebff,
0xeeaa,0xeeab,0xeeae,0xeeaf,0xeeba,0xeebb,0xeebe,0xeebf,
0xeeea,0xeeeb,0xeeee,0xeeef,0xeefa,0xeefb,0xeefe,0xeeff,
0xefaa,0xefab,0xefae,0xefaf,0xefba,0xefbb,0xefbe,0xefbf,
0xefea,0xefeb,0xefee,0xefef,0xeffa,0xeffb,0xeffe,0xefff,
0xfaaa,0xfaab,0xfaae,0xfaaf,0xfaba,0xfabb,0xfabe,0xfabf,
0xfaea,0xfaeb,0xfaee,0xfaef,0xfafa,0xfafb,0xfafe,0xfaff,
0xfbaa,0xfbab,0xfbae,0xfbaf,0xfbba,0xfbbb,0xfbbe,0xfbbf,
0xfbea,0xfbeb,0xfbee,0xfbef,0xfbfa,0xfbfb,0xfbfe,0xfbff,
0xfeaa,0xfeab,0xfeae,0xfeaf,0xfeba,0xfebb,0xfebe,0xfebf,
0xfeea,0xfeeb,0xfeee,0xfeef,0xfefa,0xfefb,0xfefe,0xfeff,
0xffaa,0xffab,0xffae,0xffaf,0xffba,0xffbb,0xffbe,0xffbf,
0xffea,0xffeb,0xffee,0xffef,0xfffa,0xfffb,0xfffe,0xffff,
};
static const unsigned short int undilate_lut[256] = {
0x00, 0x01, 0x10, 0x11, 0x02, 0x03, 0x12, 0x13,
0x20, 0x21, 0x30, 0x31, 0x22, 0x23, 0x32, 0x33,
0x04, 0x05, 0x14, 0x15, 0x06, 0x07, 0x16, 0x17,
0x24, 0x25, 0x34, 0x35, 0x26, 0x27, 0x36, 0x37,
0x40, 0x41, 0x50, 0x51, 0x42, 0x43, 0x52, 0x53,
0x60, 0x61, 0x70, 0x71, 0x62, 0x63, 0x72, 0x73,
0x44, 0x45, 0x54, 0x55, 0x46, 0x47, 0x56, 0x57,
0x64, 0x65, 0x74, 0x75, 0x66, 0x67, 0x76, 0x77,
0x08, 0x09, 0x18, 0x19, 0x0a, 0x0b, 0x1a, 0x1b,
0x28, 0x29, 0x38, 0x39, 0x2a, 0x2b, 0x3a, 0x3b,
0x0c, 0x0d, 0x1c, 0x1d, 0x0e, 0x0f, 0x1e, 0x1f,
0x2c, 0x2d, 0x3c, 0x3d, 0x2e, 0x2f, 0x3e, 0x3f,
0x48, 0x49, 0x58, 0x59, 0x4a, 0x4b, 0x5a, 0x5b,
0x68, 0x69, 0x78, 0x79, 0x6a, 0x6b, 0x7a, 0x7b,
0x4c, 0x4d, 0x5c, 0x5d, 0x4e, 0x4f, 0x5e, 0x5f,
0x6c, 0x6d, 0x7c, 0x7d, 0x6e, 0x6f, 0x7e, 0x7f,
0x80, 0x81, 0x90, 0x91, 0x82, 0x83, 0x92, 0x93,
0xa0, 0xa1, 0xb0, 0xb1, 0xa2, 0xa3, 0xb2, 0xb3,
0x84, 0x85, 0x94, 0x95, 0x86, 0x87, 0x96, 0x97,
0xa4, 0xa5, 0xb4, 0xb5, 0xa6, 0xa7, 0xb6, 0xb7,
0xc0, 0xc1, 0xd0, 0xd1, 0xc2, 0xc3, 0xd2, 0xd3,
0xe0, 0xe1, 0xf0, 0xf1, 0xe2, 0xe3, 0xf2, 0xf3,
0xc4, 0xc5, 0xd4, 0xd5, 0xc6, 0xc7, 0xd6, 0xd7,
0xe4, 0xe5, 0xf4, 0xf5, 0xe6, 0xe7, 0xf6, 0xf7,
0x88, 0x89, 0x98, 0x99, 0x8a, 0x8b, 0x9a, 0x9b,
0xa8, 0xa9, 0xb8, 0xb9, 0xaa, 0xab, 0xba, 0xbb,
0x8c, 0x8d, 0x9c, 0x9d, 0x8e, 0x8f, 0x9e, 0x9f,
0xac, 0xad, 0xbc, 0xbd, 0xae, 0xaf, 0xbe, 0xbf,
0xc8, 0xc9, 0xd8, 0xd9, 0xca, 0xcb, 0xda, 0xdb,
0xe8, 0xe9, 0xf8, 0xf9, 0xea, 0xeb, 0xfa, 0xfb,
0xcc, 0xcd, 0xdc, 0xdd, 0xce, 0xcf, 0xde, 0xdf,
0xec, 0xed, 0xfc, 0xfd, 0xee, 0xef, 0xfe, 0xff,
};
}} // namespace mtl::dilated
#endif // MTL_DILATION_TABLE_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_INDEX_INCLUDE
#define MTL_INDEX_INCLUDE
// The whole idea of changing indices is insane!
// Thus, the file shouldn't exist at all.
#include <boost/mpl/if.hpp>
namespace mtl { namespace index {
// Index like in C (identical with internal representation)
struct c_index {};
// Index like Fortran
struct f_index {};
#if 0
// Which index has type T
template <class T> struct which_index
{
typedef typename boost::mpl::if_c<
traits::is_mtl_type<T>::value
, typename T::index_type // mtl data shall know their type
, c_index // others are by default c
>::type type;
};
#endif
template <class T> struct which_index
{
typedef typename T::index_type type;
};
// Change from internal representation to requested index type
template <class T> inline T change_to(c_index, T i)
{
return i;
}
template <class T> inline T change_to(f_index, T i)
{
return i + 1;
}
// Change from requested index type to internal representation
template <class T> inline T change_from(c_index, T i)
{
return i;
}
template <class T> inline T change_from(f_index, T i)
{
return i - 1;
}
}} // namespace mtl::index
#endif // MTL_INDEX_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_MASKED_DILATION_TABLES_INCLUDE
#define MTL_MASKED_DILATION_TABLES_INCLUDE
#include <iostream>
#include <iomanip>
#include <cassert>
namespace mtl { namespace dilated {
template <class T, T Mask>
struct masked_dilation_tables
{
typedef masked_dilation_tables self;
typedef T value_type;
const static T mask= Mask;
static const T n_bytes= sizeof(T); // number of bytes of the unmasked value of this type
typedef T lookup_type[n_bytes][256];
typedef T mp_type[n_bytes];
typedef T it_type[n_bytes]; // why int ??? switch to T
protected:
static lookup_type* my_mask_lut, *my_unmask_lut;
static mp_type* my_mask_piece;
static it_type* my_mask_size, *my_mask_shift_table, *my_unmask_shift_table;
static int n_valid_table, instances;
public:
masked_dilation_tables()
{
if (instances++ == 0)
compute_tables();
}
~masked_dilation_tables()
{
if (--instances == 0) {
delete[] my_mask_lut;
delete[] my_unmask_lut;
delete[] my_mask_piece;
delete[] my_mask_size;
delete[] my_mask_shift_table;
delete[] my_unmask_shift_table;
}
}
lookup_type& mask_lut() { return *my_mask_lut; }
lookup_type& unmask_lut() { return *my_unmask_lut; }
mp_type& mask_piece() { return *my_mask_piece; }
it_type& mask_size() { return *my_mask_size; }
it_type& mask_shift_table() { return *my_mask_shift_table; }
it_type& unmask_shift_table() { return *my_unmask_shift_table; }
private:
// get mask of the style 0xfff...
static T get_f_mask(int n_bits) { return (1 << n_bits) - 1; }
T inc(T i, T mask) { return ((i - mask) & mask); }
void compute_tables()
{
// std::cout << "computing tables! " << std::endl;
init();
// compute the mask table
for (int j = 0; j < n_valid_table; ++j) {
T f_mask = get_f_mask(mask_size()[j]), i, ii;
for (i = 0, ii = 0; i < 256; ++i, ii = inc(ii, mask_piece()[j]))
mask_lut()[j][i] = (ii & f_mask) << mask_shift_table()[j]; // need to shift
}
// compute the unmask table
T f_mask = get_f_mask(8);
for (T j = 0; j < sizeof(T); ++j) {
T t_mask = (Mask >> (8*j)) & f_mask, i, ii;
for(i = 0, ii = 0; ii < t_mask; ii = inc(ii, t_mask), ++i)
unmask_lut()[j][ii] = i << unmask_shift_table()[j];
// set the value for the last one
unmask_lut()[j][t_mask] = i << unmask_shift_table()[j];
}
}
void allocate()
{
my_mask_lut= new lookup_type[1];
my_unmask_lut= new lookup_type[1];
my_mask_piece= new mp_type[1];
my_mask_size= new it_type[1];
my_mask_shift_table= new it_type[1];
my_unmask_shift_table= new it_type[1];
}
// initialize needed parameters
void init()
{
allocate();
assert(count_n_ones(Mask) > 0);
n_valid_table= (count_n_ones(Mask) + 7) / 8; // calculate the number of valid table
set_mask();
}
// return the number of 1's in the mask
int count_n_ones(T t)
{
int n_ones = 0;
for (; t; t>>= 1)
if(t & 1) ++n_ones;
return n_ones;
}
// return the number of valid bits in the mask
int count_bits(T t)
{
int bits = 0;
for (; t; t>>= 1)
++bits;
return bits;
}
// set mask pieces
void set_mask()
{
// set the unmask shift table
unmask_shift_table()[0] = 0;
T t_mask = Mask, tmp, count;
for (T i = 1; i < n_bytes; ++i) {
tmp = t_mask & get_f_mask(8);
count = count_n_ones(tmp);
unmask_shift_table()[i] = count + unmask_shift_table()[i - 1];
t_mask >>= 8;
}
mask_shift_table()[0] = 0; // don't need shift for the first table
// if there is only 8 or less 1's in the mask,
// only one table is needed
if (n_valid_table == 1) {
mask_piece()[0] = Mask;
mask_size()[0] = count_bits(Mask);
return;
}
t_mask = Mask;
for (int i = 0; i < n_valid_table - 1; ++i) {
T n_bits = 0, tmp = t_mask;
for (T n_ones= 0; n_ones < 8; ++n_bits) {
if ((t_mask & 0x01) == 1) ++n_ones;
t_mask = t_mask >>1;
}
// set the ith piece of mask, which must contains 8 1's
mask_piece()[i] = get_f_mask(n_bits) & tmp;
// set the mask size table
mask_size()[i] = n_bits;
// set shift table
mask_shift_table()[i + 1] = n_bits + mask_shift_table()[i];
}
// set the last piece of mask, which may contain less than 8 1's
// set the number of bits of the last mask
mask_piece()[n_valid_table - 1 ] = t_mask;
mask_size()[n_valid_table - 1] = count_bits(t_mask);
}
public:
// convert to masked integer
T to_masked(T x)
{
T result = 0;
for (int i = 0; i < n_valid_table; ++i)
result += mask_lut()[i][0xff & (x >> (8*i)) ];
return result;
}
// convert to unmasked integer
T to_unmasked(T x)
{
T result = 0;
x &= Mask;
for (T i = 0; i < n_bytes; ++i) {
result += unmask_lut()[i][0xff & (x >> (8*i)) ];
}
return result;
}
};
template <class T, T Mask>
typename masked_dilation_tables<T, Mask>::lookup_type* masked_dilation_tables<T, Mask>::my_mask_lut= 0;
template <class T, T Mask>
typename masked_dilation_tables<T, Mask>::lookup_type* masked_dilation_tables<T, Mask>::my_unmask_lut= 0;
template <class T, T Mask>
typename masked_dilation_tables<T, Mask>::mp_type* masked_dilation_tables<T, Mask>::my_mask_piece= 0;
template <class T, T Mask>
typename masked_dilation_tables<T, Mask>::it_type* masked_dilation_tables<T, Mask>::my_mask_size= 0;
template <class T, T Mask>
typename masked_dilation_tables<T, Mask>::it_type* masked_dilation_tables<T, Mask>::my_mask_shift_table= 0;
template <class T, T Mask>
typename masked_dilation_tables<T, Mask>::it_type* masked_dilation_tables<T, Mask>::my_unmask_shift_table= 0;
template <class T, T Mask>
int masked_dilation_tables<T, Mask>::n_valid_table= 0;
template <class T, T Mask>
int masked_dilation_tables<T, Mask>::instances= 0;
// Masking: syntax e.g. mask<0x55555555>(7);
// Mask must be in front of T -> need casting :-(
template <long unsigned Mask, typename T>
inline T mask(T const& value)
{
static masked_dilation_tables<T, T(Mask)> tables;
return tables.to_masked(value);
}
// Masking: syntax e.g. mask(7, table_object);
template <typename T, T Mask>
inline T mask(T const& value, masked_dilation_tables<T, Mask> tables)
{
return tables.to_masked(value);
}
// Unmasking: syntax e.g. unmask<0x55555555>(7);
// Mask must be in front of T -> need casting :-(
template <long unsigned Mask, typename T>
inline T unmask(T const& value)
{
static masked_dilation_tables<T, T(Mask)> tables;
return tables.to_unmasked(value);
}
// Unmasking: syntax e.g. unmask(7, table_object);
template <typename T, T Mask>
inline T unmask(T const& value, masked_dilation_tables<T, Mask> tables)
{
return tables.to_unmasked(value);
}
// Conversion from Mask1 to Mask2
// syntax e.g. from Morton to Doppler convert<0x55555555, 0x5555ff00>(7);
// Mask must be in front of T -> need casting :-(
template <long unsigned Mask1, long unsigned Mask2, typename T>
inline T convert(T const& value)
{
return mask<Mask2>(unmask<Mask1>(value));
}
// Conversion from Mask1 to Mask2
template <long unsigned Mask1, long unsigned Mask2, typename T>
inline T convert(T const& value, masked_dilation_tables<T, Mask1> const& tables1,
masked_dilation_tables<T, Mask2> const& tables2)
{
return tables2.to_masked(tables1.to_unmasked(value));
}
} // namespace mtl::dilated
//using dilated::dilated_int;
} // namespace mtl
#endif // MTL_MASKED_DILATION_TABLES_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_DETAIL_RANGE_GENERATOR_INCLUDE
#define MTL_DETAIL_RANGE_GENERATOR_INCLUDE
#include <boost/numeric/mtl/mtl_fwd.hpp>
#include <boost/numeric/mtl/concept/collection.hpp>
#include <boost/numeric/mtl/utility/glas_tag.hpp>
#include <boost/numeric/mtl/utility/complexity.hpp>
#include <boost/numeric/mtl/detail/base_cursor.hpp>
#include <boost/mpl/less.hpp>
namespace mtl { namespace traits { namespace detail {
/// Range generator that traverses all elements of some densely stored collection
/** - Or contiguous parts of such collection
- Works for matrices and vectors when derived from contiguous_memory_block
**/
template <typename Collection, typename Cursor, typename Complexity>
struct dense_element_range_generator
{
typedef Complexity complexity;
typedef Cursor type;
static int const level = 1;
type begin(Collection const& collection)
{
return collection.elements();
}
type end(Collection const& collection)
{
return collection.elements() + collection.used_memory();
}
};
/// Range generator that traverses all elements of some collection stored in strides
template <typename Collection, typename Ref, typename Traversor>
struct strided_element_range_generator
{
typedef complexity_classes::linear complexity;
typedef Traversor type;
static int const level = 1;
type begin(Ref& c)
{
return type(c.address_data(), c.stride());
}
type end(Ref& c)
{
using mtl::size;
return type(c.address_data() + size(c) + c.stride(), c.stride());
}
};
// Like above over all elements but in terms of offsets
// Also with reference to collection in cursor
template <typename Matrix, typename Cursor, typename Complexity>
struct all_offsets_range_generator
{
typedef Complexity complexity;
typedef Cursor type;
static int const level = 1;
type begin(Matrix const& matrix) const
{
return type(matrix, 0);
}
type end(Matrix const& matrix) const
{
return type(matrix, matrix.nnz());
}
};
// Cursor to some submatrix (e.g. row, column, block matrix, block row)
// This cursor is intended to be used by range generators to iterate
// over subsets of the submatrix this cursor refers to.
// For instance if this cursor refers to a row then a range
// can iterate over the elements in this row.
// If this cursor refers to a block then a range can iterate over the rows in this block.
// The level of a generated cursor must be of course at least one level less
// The tag serves to dispatching between row and column cursors
template <typename Matrix, typename Tag, int Level>
struct sub_matrix_cursor
: mtl::detail::base_cursor<int>
{
typedef sub_matrix_cursor self;
typedef mtl::detail::base_cursor<int> base;
typedef Matrix ref_type;
static int const level = Level;
sub_matrix_cursor(int i, Matrix const& c)
: base(i), ref(c)
{}
self operator+(int offset) const
{
return self(key + offset, ref);
}
// otherwise base_cursor returns an int and ranged for doesn't work
// for getting the key of base_cursor use this->value()
self operator*() const { return *this; }
Matrix const& ref;
};
// Key for canonically referring to its elements with row and column index
template <typename Matrix>
struct matrix_element_key
{
typedef typename Collection<Matrix>::size_type size_type;
typedef matrix_element_key self;
matrix_element_key(Matrix const& ref, size_type r, size_type c) : ref(ref)
{
indices[0]= r; indices[1]= c;
}
bool operator==(const self& cc) const { return &ref == &cc.ref && indices[0] == cc.indices[0] && indices[1] == cc.indices[1]; }
bool operator!=(const self& cc) const { return !(*this == cc); }
size_type indices[2];
Matrix const& ref;
};
// Cursor for canonically referring to its elements with row and column index
// Increments row for pos==0 and column for pos==1
// Referring operator returns matrix_element_key
template <typename Matrix, int pos>
struct matrix_element_cursor
{
typedef typename Collection<Matrix>::size_type size_type;
typedef matrix_element_cursor self;
typedef matrix_element_key<Matrix> key_type;
static int const level = 2;
matrix_element_cursor(Matrix const& ref, size_type r, size_type c) : ref(ref)
{
indices[0]= r; indices[1]= c;
}
key_type operator*() const { return key_type(ref, indices[0], indices[1]); }
self& operator++() { ++indices[pos]; return *this; }
self operator++(int) { self tmp(*this); ++indices[pos]; return tmp; }
self& operator+=(int n) { indices[pos]+= n; return *this; }
self& operator+(int n) const { self tmp = *this; tmp+= n; return tmp; }
self& operator--() { indices[pos]--; return *this; }
self operator--(int) { self tmp(*this); indices[pos]--; return tmp; }
self& operator-=(int n) { indices[pos]-= n; return *this; }
self& operator-(int n) const { self tmp = *this; tmp-= n; return tmp; }
bool operator==(const self& cc) const { return &ref == &cc.ref && indices[0] == cc.indices[0] && indices[1] == cc.indices[1]; }
bool operator!=(const self& cc) const { return !(*this == cc); }
size_type indices[2];
Matrix const& ref;
};
template <typename Matrix, typename Complexity, int Level>
struct all_rows_range_generator
{
typedef Complexity complexity;
static int const level = Level;
typedef Matrix ref_type;
typedef sub_matrix_cursor<Matrix, glas::tag::row, Level> type;
typedef typename Collection<Matrix>::size_type size_type;
type begin(Matrix const& c) const
{
return type(0, c); // return type(c.begin_row(), c); get rid of obsolete stuff
}
type end(Matrix const& c) const
{
using mtl::num_rows; using mtl::matrix::num_rows;
return type(num_rows(c), c); //return type(c.end_row(), c);
}
type lower_bound(Matrix const& c, size_type position) const
{
using mtl::num_rows;
return type(std::min(num_rows(c), position), c);
}
};
template <typename Cursor>
struct all_cols_in_row_range_generator
{
typedef complexity_classes::linear complexity;
static int const level = 1;
typedef typename Cursor::ref_type ref_type;
typedef typename Collection<ref_type>::size_type size_type;
typedef matrix_element_cursor<ref_type, 1> type;
type begin(Cursor const& c) const { return type(c.ref, c.value(), size_type(0)); }
type end(Cursor const& c) const { using mtl::num_cols; return type(c.ref, c.value(), num_cols(c.ref)); }
type lower_bound(Cursor const& c, size_type position) const
{
using mtl::num_cols;
return type(c.ref, c.value, std::min(num_cols(c.ref), position));
}
};
template <typename Matrix, typename Complexity, int Level>
struct all_cols_range_generator
{
typedef Complexity complexity;
static int const level = Level;
typedef sub_matrix_cursor<Matrix, glas::tag::col, Level> type;
typedef typename Collection<Matrix>::size_type size_type;
type begin(Matrix const& c) const
{
return type(0, c); // return type(c.begin_col(), c);
}
type end(Matrix const& c) const
{
using mtl::num_cols;
return type(num_cols(c), c); // return type(c.end_col(), c);
}
type lower_bound(Matrix const& c, size_type position) const
{
using mtl::num_cols;
return type(std::min(num_cols(c), position), c);
}
};
template <typename Cursor>
struct all_rows_in_col_range_generator
{
typedef complexity_classes::linear complexity;
static int const level = 1;
typedef typename Cursor::ref_type ref_type;
typedef typename Collection<ref_type>::size_type size_type;
typedef matrix_element_cursor<ref_type, 0> type;
type begin(Cursor const& c) const { return type(c.ref, 0, c.value()); }
type end(Cursor const& c) const { using mtl::num_rows; return type(c.ref, num_rows(c.ref), c.value()); }
type lower_bound(Cursor const& c, size_type position) const
{
using mtl::num_rows;
return type(c.ref, std::min(num_rows(c.ref), position), c.value());
}
};
// Use RangeGenerator for Collection by applying to .ref
template <typename Coll, typename RangeGenerator>
struct referred_range_generator
{
typedef typename RangeGenerator::complexity complexity;
static int const level = RangeGenerator::level;
typedef typename RangeGenerator::type type;
typedef typename Collection<Coll>::size_type size_type;
type begin(const Coll& c)
{
return RangeGenerator().begin(c.ref);
}
type end(const Coll& c)
{
return RangeGenerator().end(c.ref);
}
type lower_bound(const Coll& c, size_type position)
{
return RangeGenerator().lower_bound(c.ref, position);
}
};
} // namespace detail
namespace range {
template <typename Range1, typename Range2>
struct min
: public boost::mpl::if_<
boost::mpl::less<
typename Range1::complexity,
typename Range2::complexity>
, Range1
, Range2
>
{};
}
}} // namespace mtl::traits
#endif // MTL_DETAIL_RANGE_GENERATOR_INCLUDE