Commit d196221a authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

files in folder vector and utility adopted to c++11

parent 47fe1d0b
// 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_CASE_MATRIX_INCLUDE
#define MTL_BASE_CASE_MATRIX_INCLUDE
#include <type_traits>
#include <boost/numeric/mtl/utility/static_assert.hpp>
#include <boost/numeric/meta_math/is_power_of_2.hpp>
#include <boost/numeric/meta_math/log_2.hpp>
......@@ -33,11 +35,11 @@ struct base_case_matrix<mtl::mat::morton_dense<Elt, Mask, Parameters>, BaseCaseT
MTL_STATIC_ASSERT(meta_math::is_power_of_2<BaseCaseTest::base_case_size>::value, "Static base case size must be power of two");
static const unsigned long base_case_bits= meta_math::log_2<BaseCaseTest::base_case_size>::value;
typedef typename boost::mpl::if_<
is_k_power_base_case_row_major<base_case_bits, Mask>
typedef typename std::conditional<
is_k_power_base_case_row_major<base_case_bits, Mask>::value
, mtl::mat::dense2D<Elt, mat::parameters<row_major> >
, typename boost::mpl::if_<
is_k_power_base_case_col_major<base_case_bits, Mask>
, typename std::conditional<
is_k_power_base_case_col_major<base_case_bits, Mask>::value
, mtl::mat::dense2D<Elt, mat::parameters<col_major> >
, mtl::mat::morton_dense<Elt, Mask, Parameters>
>::type
......
// 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_BIT_MASKING_INCLUDE
#define MTL_BIT_MASKING_INCLUDE
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/if.hpp>
#include <type_traits>
#include <boost/numeric/mtl/utility/tag.hpp>
......@@ -27,14 +26,14 @@ namespace mtl {
i-order (cyrillic i):
---------------------
binary: 01010101 ... 01
0x55555555
z-order:
--------
binary: 10101010 ... 10
0xaaaaaaaa
......@@ -149,7 +148,7 @@ template <unsigned long K, unsigned long Mask>
struct is_k_power_base_case_row_major
{
static const bool value= same_mask<lsb_bits<2*K, Mask>::value, row_major_mask<K>::value>::value;
// typedef
// typedef
};
......@@ -235,7 +234,7 @@ template<> struct z_order_mask<0> : public lsb_mask<0> {}; // set to 0
/** Generate arbitrary hybrid mask.
\param IOrder if true then i-order otherwise z-order
\param K 2^K by 2^K base case
\param K 2^K by 2^K base case
\param Orientation mtl::row_major or mtl::col_major
\param T 2^T tooth length
**/
......@@ -244,8 +243,8 @@ class generate_mask
{
static const unsigned long rec_size= 8 * sizeof(unsigned long) - 2 * K,
rec_part= (IOrder ? i_order_mask<rec_size>::value : z_order_mask<rec_size>::value) << 2*K;
typedef typename boost::mpl::if_<
boost::is_same<Orientation, row_major>
typedef typename std::conditional<
std::is_same<Orientation, row_major>::value
, row_major_shark_mask<K, T>
, col_major_shark_mask<K, T>
>::type base_part_type;
......
// 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_RECURATOR_INCLUDE
#define MTL_MATRIX_RECURATOR_INCLUDE
#include <cmath>
#include <boost/shared_ptr.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <memory>
#include <type_traits>
#include <boost/numeric/mtl/concept/collection.hpp>
#include <boost/numeric/mtl/operation/sub_matrix.hpp>
#include <boost/numeric/mtl/operation/print_matrix.hpp>
......@@ -38,11 +39,11 @@ void inline equalize_depth(Recursator1& r1, Recursator2& r2, Recursator3& r3);
How to use this class is described in the \ref rec_intro "recursion introduction".
\sa \ref mtl::mat::north_west, \ref mtl::mat::north_east,
\ref mtl::mat::south_west, \ref mtl::mat::south_east,
\ref mtl::mat::is_empty(const recursator<Matrix>&),
\ref mtl::mat::is_full(const recursator<Matrix>&),
\ref mtl::mat::num_rows(const recursator<Matrix>&),
\sa \ref mtl::mat::north_west, \ref mtl::mat::north_east,
\ref mtl::mat::south_west, \ref mtl::mat::south_east,
\ref mtl::mat::is_empty(const recursator<Matrix>&),
\ref mtl::mat::is_full(const recursator<Matrix>&),
\ref mtl::mat::num_rows(const recursator<Matrix>&),
\ref mtl::mat::num_cols(const recursator<Matrix>&),
\ref mtl::mat::size(const recursator<Matrix>&)
**/
......@@ -58,7 +59,7 @@ struct recursator
typedef recursion::outer_bound_splitter<self> splitter_type;
private:
template <typename MatrixType> // why was it templated ???
sub_matrix_type constructor_helper(MatrixType const& matrix)
{
......@@ -70,16 +71,16 @@ private:
template <typename MatrixType>
sub_matrix_type constructor_helper(transposed_view<MatrixType> const& view)
{
typedef typename boost::remove_const<MatrixType>::type tmp_type;
typedef typename std::remove_const<MatrixType>::type tmp_type;
typedef typename sub_matrix_t<tmp_type>::sub_matrix_type ref_sub_type;
typedef boost::shared_ptr<ref_sub_type> pointer_type;
typedef std::shared_ptr<ref_sub_type> pointer_type;
typedef typename transposed_view<MatrixType>::other ref_type;
// Submatrix of referred matrix, colums and rows interchanged
// Create a submatrix, whos address will be kept by transposed_view
pointer_type p(new ref_sub_type(sub_matrix(const_cast<ref_type&>(view.ref), view.begin_col(), view.end_col(),
pointer_type p(new ref_sub_type(sub_matrix(const_cast<ref_type&>(view.ref), view.begin_col(), view.end_col(),
view.begin_row(), view.end_row())));
return sub_matrix_type(p);
return sub_matrix_type(p);
}
public:
......@@ -93,7 +94,7 @@ public:
**/
explicit recursator(Matrix const& matrix,
size_type bound= 0
)
)
: my_sub_matrix(constructor_helper(matrix)), my_bound(recursion::outer_bound(matrix)),
my_first_row(0), my_first_col(0) // splitter(*this)
{
......@@ -101,7 +102,7 @@ public:
my_bound= recursion::outer_bound(matrix);
else {
MTL_DEBUG_THROW_IF(!recursion::is_power_of_2(bound), range_error("Bound must be a power of 2"));
MTL_DEBUG_THROW_IF(bound < num_rows(matrix) || bound < num_cols(matrix),
MTL_DEBUG_THROW_IF(bound < num_rows(matrix) || bound < num_cols(matrix),
range_error("Bound must not be smaller than matrix dimensions"));
my_bound= bound;
}
......@@ -111,22 +112,22 @@ public:
private:
template <typename SubMatrix>
sub_matrix_type get_value_dispatch(const SubMatrix& ,
sub_matrix_type get_value_dispatch(const SubMatrix& ,
size_type br, size_type er, size_type bc, size_type ec) const
{
return sub_matrix(my_sub_matrix, br, er, bc, ec);
}
template <typename SubMatrix>
sub_matrix_type get_value_dispatch(transposed_view<SubMatrix> view,
sub_matrix_type get_value_dispatch(transposed_view<SubMatrix> view,
size_type br, size_type er, size_type bc, size_type ec) const
{
typedef typename sub_matrix_t<SubMatrix>::sub_matrix_type ref_sub_type;
typedef boost::shared_ptr<ref_sub_type> pointer_type;
typedef std::shared_ptr<ref_sub_type> pointer_type;
typedef typename transposed_view<SubMatrix>::other ref_type;
pointer_type p(new ref_sub_type(sub_matrix(const_cast<ref_type&>(view.ref), bc, ec, br, er)));
return sub_matrix_type(p);
return sub_matrix_type(p);
}
......@@ -209,7 +210,7 @@ public:
my_bound= b;
}
template <typename R1, typename R2> friend void equalize_depth (R1&, R2&);
template <typename R1, typename R2> friend void equalize_depth (R1&, R2&);
template <typename R1, typename R2, typename R3> friend void equalize_depth (R1&, R2&, R3&);
template <typename M> friend typename recursator<M>::size_type num_rows(const recursator<M>& rec);
......@@ -225,12 +226,12 @@ public:
{
return &my_sub_matrix[my_first_row][my_first_col];
}
protected:
sub_matrix_type my_sub_matrix; /// Referred matrix (from which the sub-matrices are built)
size_type my_bound, /// Virtual matrix size, i.e. upper bound for size of sub-matrix.
my_first_row, /// Row of first entry in submatrix
my_first_col; /// Row of first entry in submatrix
my_first_col; /// Row of first entry in submatrix
};
#if 0
......@@ -249,7 +250,7 @@ struct recursator_s
// typedef outer_bound_splitter<self> splitter_type;
private:
// template <typename Matrix> why was it templated ???
sub_matrix_type constructor_helper(Matrix const& matrix)
{
......@@ -266,16 +267,16 @@ private:
// Submatrix of referred matrix, colums and rows interchanged
// Create a submatrix, whos address will be kept by transposed_view
pointer_type p(new ref_sub_type(sub_matrix(matrix.ref, matrix.begin_col(), matrix.end_col(),
pointer_type p(new ref_sub_type(sub_matrix(matrix.ref, matrix.begin_col(), matrix.end_col(),
matrix.begin_row(), matrix.end_row())));
return sub_matrix_type(p);
return sub_matrix_type(p);
}
public:
// Constructor takes the whole matrix as sub-matrix
// This allows to have different type for the matrix and the sub-matrix
// This also enables matrices to have references as sub-matrices
explicit recursator_s(Matrix const& matrix, size_type bound= 0)
explicit recursator_s(Matrix const& matrix, size_type bound= 0)
: my_sub_matrix(constructor_helper(matrix)), my_bound(outer_bound(matrix)),
splitter(my_sub_matrix)
{
......@@ -290,7 +291,7 @@ public:
// Sub-matrices are copied directly
// explicit recursator(sub_matrix_type sub_matrix) : my_sub_matrix(sub_matrix) {}
sub_matrix_type& get_value()
{
return my_sub_matrix;
......@@ -313,7 +314,7 @@ public:
self south_west()
{
sub_matrix_type sm(sub_matrix(my_sub_matrix, splitter.row_split(), my_sub_matrix.end_row(),
sub_matrix_type sm(sub_matrix(my_sub_matrix, splitter.row_split(), my_sub_matrix.end_row(),
my_sub_matrix.begin_col(), splitter.col_split()));
self tmp(sm, my_bound / 2);
return tmp;
......@@ -329,7 +330,7 @@ public:
self south_east()
{
sub_matrix_type sm(sub_matrix(my_sub_matrix, splitter.row_split(), my_sub_matrix.end_row(),
sub_matrix_type sm(sub_matrix(my_sub_matrix, splitter.row_split(), my_sub_matrix.end_row(),
splitter.col_split(), my_sub_matrix.end_col()));
self tmp(sm, my_bound / 2);
return tmp;
......@@ -345,15 +346,15 @@ public:
return tmp;
}
self const south_west() const
self const south_west() const
{
sub_matrix_type sm(sub_matrix(const_cast<self*>(this)->my_sub_matrix, splitter.row_split(), my_sub_matrix.end_row(),
sub_matrix_type sm(sub_matrix(const_cast<self*>(this)->my_sub_matrix, splitter.row_split(), my_sub_matrix.end_row(),
my_sub_matrix.begin_col(), splitter.col_split()));
self tmp(sm, my_bound / 2);
return tmp;
}
self const north_east() const
self const north_east() const
{
sub_matrix_type sm(sub_matrix(const_cast<self*>(this)->my_sub_matrix, my_sub_matrix.begin_row(), splitter.row_split(),
splitter.col_split(), my_sub_matrix.end_col()));
......@@ -361,9 +362,9 @@ public:
return tmp;
}
self const south_east() const
self const south_east() const
{
sub_matrix_type sm(sub_matrix(const_cast<self*>(this)->my_sub_matrix, splitter.row_split(), my_sub_matrix.end_row(),
sub_matrix_type sm(sub_matrix(const_cast<self*>(this)->my_sub_matrix, splitter.row_split(), my_sub_matrix.end_row(),
splitter.col_split(), my_sub_matrix.end_col()));
self tmp(sm, my_bound / 2);
return tmp;
......@@ -389,7 +390,7 @@ public:
bool south_east_empty() const
{
return splitter.row_split() == my_sub_matrix.end_row()
return splitter.row_split() == my_sub_matrix.end_row()
|| splitter.col_split() == my_sub_matrix.end_col();
}
......@@ -412,7 +413,7 @@ public:
return my_bound;
}
template <typename R1, typename R2> friend void equalize_depth (R1&, R2&);
template <typename R1, typename R2> friend void equalize_depth (R1&, R2&);
template <typename R1, typename R2, typename R3> friend void equalize_depth (R1&, R2&, R3&);
protected:
......
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
//
// Copyright (c) 2007 The Trustees of Indiana University.
// 2008 Dresden University of Technology and the Trustees of Indiana University.
// 2010 SimuNova UG, www.simunova.com.
// 2010 SimuNova UG, www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
//
// This file is part of the Matrix Template Library
//
//
// See also tools/license/license.mtl.txt in the distribution.
#ifndef MTL_TRAITS_ALGEBRAIC_CATEGORY_INCLUDE
......@@ -18,16 +18,16 @@
namespace mtl { namespace traits {
/// Meta-function for categorizing types into tag::scalar, tag::vector, and tag::matrix
/** Automatically derived from category
/** Automatically derived from category
@ingroup Tags
*/
template <typename T>
struct algebraic_category
: boost::mpl::if_<
is_matrix<T>
: std::conditional<
is_matrix<T>::value
, tag::matrix
, typename boost::mpl::if_<
is_vector<T>
, typename std::conditional<
is_vector<T>::value
, tag::vector
, tag::scalar
>::type
......
// 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_ASHAPE_INCLUDE
......@@ -30,7 +30,7 @@
# include <initializer_list>
#endif
namespace mtl {
namespace mtl {
/// Namespace for algebraic shapes; used for sophisticated dispatching between operations
namespace ashape {
......@@ -61,7 +61,7 @@ template <typename Value> struct future : nonscal {};
/// Meta-function for algebraic shape of T
/** Unknown types are treated like scalars. ashape of collections are template
parameterized with ashape of their elements, e.g., ashape< matrix < vector < double > > >::type is
mat< rvec < scal > > >.
mat< rvec < scal > > >.
Implemented with ashape_aux after type is cleaned up with mtl::traits::root.
**/
template <typename T>
......@@ -78,8 +78,8 @@ struct ashape_aux
template <typename Value, typename Parameters>
struct ashape_aux<mtl::vec::dense_vector<Value, Parameters> >
{
typedef typename boost::mpl::if_<
boost::is_same<typename Parameters::orientation, row_major>
typedef typename std::conditional<
std::is_same<typename Parameters::orientation, row_major>::value
, rvec<typename ashape<Value>::type>
, cvec<typename ashape<Value>::type>
>::type type;
......@@ -101,15 +101,13 @@ struct ashape_aux<Value[Rows]>
{
typedef rvec<typename ashape<Value>::type> type;
};
#ifdef MTL_WITH_INITLIST
/// Non-nested initializer_list have rvec ashape, nested lists are matrices see below
template <typename Value>
struct ashape_aux<std::initializer_list<Value> >
{
typedef rvec<typename ashape<Value>::type> type;
};
#endif
/// std::vectors have rvec ashape
template <typename Value, typename Allocator>
......@@ -117,18 +115,18 @@ struct ashape_aux<std::vector<Value, Allocator> >
{
typedef rvec<typename ashape<Value>::type> type;
};
/// One-dimensional arrays have rvec ashape; 2D arrays are matrices see below
template <typename Value>
struct ashape_aux<Value*>
{
typedef rvec<typename ashape<Value>::type> type;
};
template <typename E1, typename E2, typename SFunctor>
struct ashape_aux< vec::vec_vec_pmop_expr<E1, E2, SFunctor> >
{
MTL_STATIC_ASSERT((boost::is_same<typename ashape<E1>::type,
MTL_STATIC_ASSERT((std::is_same<typename ashape<E1>::type,
typename ashape<E2>::type>::value), "Operands must have same algebraic shape.");
typedef typename ashape<E1>::type type;
};
......@@ -137,7 +135,7 @@ template <typename E1, typename E2, typename SFunctor>
struct ashape_aux< vec::vec_vec_op_expr<E1, E2, SFunctor> >
{
#if 0 // not sure if this is true in all operations
MTL_STATIC_ASSERT((boost::is_same<typename ashape<E1>::type,
MTL_STATIC_ASSERT((boost::is_same<typename ashape<E1>::type,
typename ashape<E2>::type>::value), "Operands must have same algebraic shape.");
#endif
typedef typename ashape<E1>::type type;
......@@ -189,7 +187,7 @@ struct ashape_aux<mtl::mat::dense2D<Value, Parameters> >
{
typedef mat<typename ashape<Value>::type> type;
};
template <typename Value, std::size_t Mask, typename Parameters>
struct ashape_aux<mtl::mat::morton_dense<Value, Mask, Parameters> >
{
......@@ -216,21 +214,19 @@ struct ashape_aux<Value (*)[Cols]>
typedef mat<typename ashape<Value>::type> type;
};
#ifdef MTL_WITH_INITLIST
/// Nested initializer_list are matrices, non-nested are vectors see above
template <typename Value>
struct ashape_aux<std::initializer_list<std::initializer_list<Value> > >
{
typedef mat<typename ashape<Value>::type> type;
};
#endif
template <typename Vector>
struct ashape_aux<mtl::mat::multi_vector<Vector> >
{
typedef mat<typename ashape<typename mtl::Collection<mtl::mat::multi_vector<Vector> >::value_type>::type> type;
};
template <typename Value>
struct ashape_aux<mtl::mat::element_structure<Value> >
{
......@@ -243,22 +239,22 @@ struct ashape_aux<mtl::mat::ell_matrix<Value, Parameters> >
typedef mat<typename ashape<Value>::type> type;
};
template <typename Vector>
struct ashape_aux<mtl::mat::multi_vector_range<Vector> >
{
typedef mat<typename ashape<typename mtl::Collection<mtl::mat::multi_vector_range<Vector> >::value_type>::type> type;
};
template <> struct ashape_aux<mtl::mat::identity2D>
{
typedef nonscal type;
template <> struct ashape_aux<mtl::mat::identity2D>
{
typedef nonscal type;
};
template <typename E1, typename E2, typename SFunctor>
struct ashape_aux< mtl::mat::mat_mat_op_expr<E1, E2, SFunctor> >
{
MTL_STATIC_ASSERT((boost::is_same<typename ashape<E1>::type,
MTL_STATIC_ASSERT((std::is_same<typename ashape<E1>::type,
typename ashape<E2>::type>::value), "Operands must have same algebraic shape.");
typedef typename ashape<E1>::type type;
};
......@@ -266,12 +262,12 @@ struct ashape_aux< mtl::mat::mat_mat_op_expr<E1, E2, SFunctor> >
template <typename Vector1, typename Vector2>
struct ashape< mtl::mat::outer_product_matrix<Vector1, Vector2> >
{
// BOOST_STATIC_ASSERT((boost::is_same<typename ashape<E1>::type,
// typename transposed_shape<typename ashape<E2>::type>::type>::value));
// BOOST_STATIC_ASSERT((std::is_same<typename ashape<E1>::type,
// typename transposed_shape<typename ashape<E2>::type>::type>::value));
typedef mat<typename ashape<typename mtl::Collection<Vector1>::value_type>::type> type;
};
template <typename Matrix, typename VectorIn>
template <typename Matrix, typename VectorIn>
struct ashape< mtl::vec::mat_cvec_multiplier<Matrix, VectorIn> >
{
typedef cvec<scal> type;
......@@ -312,7 +308,7 @@ struct ashape_aux<mtl::vec::imag_view<Coll> >
};
#if 1
// shouldn't be needed
// shouldn't be needed
template <typename Coll>
struct ashape_aux<mtl::mat::transposed_view<const mtl::mat::conj_view<Coll> > >
{
......@@ -340,7 +336,7 @@ struct ashape_aux<mtl::mat::indirect<Matrix> >
// Rule out other types as algebraic shape
template <typename IFStream, typename OFStream>
struct ashape_aux<io::matrix_file<IFStream, OFStream> >
struct ashape_aux<io::matrix_file<IFStream, OFStream> >
{
typedef ndef type;
};
......@@ -376,13 +372,13 @@ struct mat_scal_mult {};
// Results of operations
// =====================
/*
/*
s cv rv m
-------------------
s | s cv* rv* m*
cv | cv* x m x
rv | rv* s x rv
m | m* cv x m
m | m* cv x m
* only on outer level, forbidden for elements of collections
......@@ -393,7 +389,7 @@ rv | rv* s x rv
/// Algebraic shape of multiplication's result when elements of collections are multiplied.
/** The types are the same as for multiplications of entire collections except that scalar *
matrix (or vector) is excluded to avoid ambiguities.
matrix (or vector) is excluded to avoid ambiguities.
emult_shape <Shape1, Shape2> is only properly defined if emult_op <Shape1, Shape2>::type is not ndef!
**/
template <typename Shape1, typename Shape2>
......@@ -436,8 +432,8 @@ template <typename Value1, typename Value2>
struct emult_op<cvec<Value1>, rvec<Value2> >
{
// if product of elements is undefined then product is undefined too
typedef typename boost::mpl::if_<
boost::is_same<typename emult_op<Value1, Value2>::type, ndef>
typedef typename std::conditional<
std::is_same<typename emult_op<Value1, Value2>::type, ndef>::value
, ndef
, cvec_rvec_mult
>::type type;
......@@ -455,8 +451,8 @@ template <typename Value1, typename Value2>
struct emult_op<rvec<Value1>, cvec<Value2> >
{
// if product of elements is undefined then product is undefined too
typedef typename boost::mpl::if_<
boost::is_same<typename emult_op<Value1, Value2>::type, ndef>
typedef typename std::conditional<
std::is_same<typename emult_op<Value1, Value2>::type, ndef>::value
, ndef