Commit 6ea82cf9 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

fixmatvec cleanup

parent 816416d3
......@@ -40,6 +40,12 @@ namespace Dec
{
using type = T;
};
template <class T, class = void>
struct StoreType
{
using type = T;
};
}
template <class T>
......@@ -51,6 +57,9 @@ namespace Dec
template <class T>
using Value_t = typename aux::ValueType<Decay_t<T>>::type;
template <class T>
using Store_t = typename aux::StoreType<Decay_t<T>>::type;
/// Variadic type list
template <class... Ts>
struct Types {};
......
......@@ -15,21 +15,21 @@ namespace Dec
: public MatExpr<UnaryExpr<E,Operation,T,N,M>, T, N, M>
{
UnaryExpr(E const& expr, Operation const& op)
: expr(expr)
, op(op)
: expr_(expr)
, op_(op)
{}
template <class... Int>
auto at(Int... i) const
{
static_assert( and_< concepts::Integral<Int>... >, "Requires integer indices!" );
return op(expr.at(i...));
return op_(expr_.at(i...));
}
private:
E const& expr;
E const& expr_;
Operation op;
Operation op_;
};
......@@ -42,23 +42,23 @@ namespace Dec
: public MatExpr<BinaryExpr<E0,E1,Operation,T,N,M>, T, N, M>
{
BinaryExpr(E0 const& lhs, E1 const& rhs, Operation const& op)
: lhs(lhs)
, rhs(rhs)
, op(op)
: lhs_(lhs)
, rhs_(rhs)
, op_(op)
{}
template <class... Int>
auto at(Int... i) const
{
static_assert( and_< concepts::Integral<Int>... >, "Requires integer indices!" );
return op(lhs.at(i...), rhs.at(i...));
return op_(lhs_.at(i...), rhs_.at(i...));
}
private:
E0 const& lhs;
E1 const& rhs;
E0 const& lhs_;
E1 const& rhs_;
Operation op;
Operation op_;
};
} // end namespace expression
......
......@@ -27,6 +27,7 @@ namespace Dec
using model = Self;
using value_type = T;
using field_type = FieldType_t<T>;
/** Constructors
* @{
......@@ -165,7 +166,7 @@ namespace Dec
/// Access the (i,j)th element of the matrix
T& operator()(std::size_t i, std::size_t j)
{
std::size_t idx = i*M + j;
std::size_t const idx = i*M + j;
return static_cast<Super&>(*this)[idx];
}
......@@ -222,14 +223,14 @@ namespace Dec
return {*this};
}
using Expr::operator();
using Expr::operator[];
using Expr::operator(); // const element access
using Expr::operator[]; // const element access
/// @cond HIDDEN_SYMBOLS
T const& at(std::size_t i, std::size_t j) const
{
std::size_t idx = i*M + j;
std::size_t const idx = i*M + j;
return static_cast<Super const&>(*this)[idx];
}
......@@ -278,6 +279,20 @@ namespace Dec
using FixVec = typename aux::FixVec<T,N,col_vec>::type;
namespace aux
{
template <class, class E, class T, std::size_t N, std::size_t M>
FixMat<T,N,M> store_type_impl(MatExpr<E,T,N,M> const&);
template <class E>
struct StoreType<T, Void_t<decltype(store_type_impl<E>(std::declval<E>()))>>
{
using type = decltype(store_type_impl<E>(std::declval<E>()));
};
} // end namespace aux
/// Output shift operator for fixed sizes matrices/vectors (expressions), \relates FixMat
template <class CharT, class Traits, class E, class T, std::size_t N, std::size_t M>
std::basic_ostream<CharT, Traits>&
......
......@@ -44,6 +44,7 @@ namespace Dec
{
using model = Model;
using value_type = T;
using field_type = FieldType_t<T>;
/// @{
......@@ -131,51 +132,51 @@ namespace Dec
: public MatExpr<IdentityExpr<T,N,M>, T, N, M>
{
IdentityExpr(T const& value)
: value(value)
: value_(value)
{}
template <class... Int>
auto const& at(Int...) const
{
return value;
return value_;
}
private:
T value;
T value_;
};
// A placeholder for a matrix expression
template <class E, class T, std::size_t N, std::size_t M>
struct matrix_expression_c {};
namespace aux
{
template <class, class E, class T, std::size_t N, std::size_t M>
matrix_expression_c<E,T,N,M>
base_type(MatExpr<E,T,N,M> const&) { return {}; }
template <class E>
using Base_t = decltype(base_type<E>(std::declval<E>()));
} // end namespace aux
// template <class E, class T, std::size_t N, std::size_t M>
// struct matrix_expression_c {};
//
//
// namespace aux
// {
// template <class, class E, class T, std::size_t N, std::size_t M>
// matrix_expression_c<E,T,N,M>
// base_type(MatExpr<E,T,N,M> const&) { return {}; }
//
// template <class E>
// using Base_t = decltype(base_type<E>(std::declval<E>()));
//
// } // end namespace aux
// template <class E>
// struct Collection;
//
//
// template <class Model, class T, std::size_t N, std::size_t M>
// struct Collection<matrix_expression_c<Model, T, N, M>>
// {
// using Expr = Model;
// using value_type = T;
//
//
// static constexpr std::size_t rows = N;
// static constexpr std::size_t cols = M;
// static constexpr std::size_t size = N*M;
// };
//
//
// template <class Expr>
// struct Collection : Collection<aux::Base_t<Expr>> {};
......
......@@ -85,7 +85,7 @@ namespace Dec
REQUIRES(concepts::Addable<T0,T1>) >
auto operator+(MatExpr<E0,T0,N,M> const& lhs, MatExpr<E1,T1,N,M> const& rhs)
{
using T = Decay_t<decltype( std::declval<T0>() + std::declval<T1>() )>;
using T = Store_t<decltype( std::declval<T0>() + std::declval<T1>() )>;
using Expr = expression::BinaryExpr<E0, E1, operation::plus, T, N, M>;
return Expr{lhs.get(), rhs.get(), operation::plus{}};
}
......@@ -94,7 +94,7 @@ namespace Dec
REQUIRES(concepts::Subtractable<T0,T1>) >
auto operator-(MatExpr<E0,T0,N,M> const& lhs, MatExpr<E1,T1,N,M> const& rhs)
{
using T = Decay_t<decltype( std::declval<T0>() - std::declval<T1>() )>;
using T = Store_t<decltype( std::declval<T0>() - std::declval<T1>() )>;
using Expr = expression::BinaryExpr<E0, E1, operation::minus, T, N, M>;
return Expr{lhs.get(), rhs.get(), operation::minus{}};
}
......@@ -102,7 +102,7 @@ namespace Dec
template <class E, class T, std::size_t N, std::size_t M>
auto operator-(MatExpr<E,T,N,M> const& mat)
{
using T_ = Decay_t<decltype( -std::declval<T>() )>;
using T_ = Store_t<decltype( -std::declval<T>() )>;
using Expr = expression::UnaryExpr<E, operation::negate, T_, N, M>;
return Expr{mat.get(), operation::negate{}};
}
......@@ -111,7 +111,7 @@ namespace Dec
REQUIRES(concepts::Arithmetic<T1> && concepts::Multiplicable<T0,T1>) >
auto operator*(MatExpr<E0,T0,N,M> const& e, T1 const& s)
{
using T = Decay_t<decltype( std::declval<T0>() * std::declval<T1>() )>;
using T = Store_t<decltype( std::declval<T0>() * std::declval<T1>() )>;
using Expr = expression::UnaryExpr<E0, operation::times_scalar<T1>, T, N, M>;
return Expr{e.get(), operation::times_scalar<T1>(s)};
}
......@@ -120,7 +120,7 @@ namespace Dec
REQUIRES(concepts::Arithmetic<T1> && concepts::Multiplicable<T0,T1>) >
auto operator*(T1 const& s, MatExpr<E0,T0,N,M> const& e)
{
using T = Decay_t<decltype( std::declval<T1>() * std::declval<T0>() )>;
using T = Store_t<decltype( std::declval<T1>() * std::declval<T0>() )>;
using Expr = expression::UnaryExpr<E0, operation::times_scalar<T1>, T, N, M>;
return Expr{e.get(), operation::times_scalar<T1>(s)};
}
......@@ -129,7 +129,7 @@ namespace Dec
REQUIRES(concepts::Arithmetic<T1> && concepts::Divisible<T0,T1>) >
auto operator/(MatExpr<E0,T0,N,M> const& e, T1 const& s)
{
using T = Decay_t<decltype( std::declval<T0>() / std::declval<T1>() )>;
using T = Store_t<decltype( std::declval<T0>() / std::declval<T1>() )>;
using Expr = expression::UnaryExpr<E0, operation::divides_scalar<T1>, T, N, M>;
return Expr{e.get(), operation::divides_scalar<T1>(s)};
}
......@@ -138,7 +138,7 @@ namespace Dec
REQUIRES(concepts::Multiplicable<T0,T1> /*&& concepts::Multiplicable<T0,T1>*/) >
auto multiply(MatExpr<E0,T0,N,M> const& lhs, MatExpr<E1,T1,N,M> const& rhs)
{
using T = Decay_t<decltype( std::declval<T0>() * std::declval<T1>() )>;
using T = Store_t<decltype( std::declval<T0>() * std::declval<T1>() )>;
using Expr = expression::BinaryExpr<E0, E1, operation::times, T, N, M>;
return Expr{lhs.get(), rhs.get(), operation::times{}};
}
......@@ -157,16 +157,16 @@ namespace Dec
: public MatExpr<DiagonalMat<E,T,N>, T, N, N>
{
DiagonalMat(E const& expr)
: vec(expr)
: vec_(expr)
{}
auto at(std::size_t i, std::size_t j) const
{
return i==j ? vec.at(i) : T(0);
return i==j ? vec_.at(i) : T(0);
}
private:
E const& vec;
E const& vec_;
};
......@@ -178,16 +178,16 @@ namespace Dec
: public MatExpr<DiagonalVec<E,T,N>, T, N, 1>
{
DiagonalVec(E const& expr)
: mat(expr)
: mat_(expr)
{}
auto at(std::size_t i, std::size_t = 0) const
{
return mat.at(i, i);
return mat_.at(i, i);
}
private:
E const& mat;
E const& mat_;
};
} // end namespace expression
......@@ -234,17 +234,17 @@ namespace Dec
{
using E = typename V::model;
Cross2(E const& expr)
: a(expr)
: a_(expr)
{}
auto at(std::size_t i, std::size_t = 0) const
{
const std::size_t i0 = (i+1)%2;
return (1-2*int(i)) * a[i0];
return (1-2*int(i)) * a_[i0];
}
private:
E const& a;
E const& a_;
};
......@@ -258,19 +258,19 @@ namespace Dec
using E0 = typename V0::model;
using E1 = typename V1::model;
Cross3(E0 const& expr0, E1 const& expr1)
: a(expr0)
, b(expr1)
: a_(expr0)
, b_(expr1)
{}
auto at(std::size_t i, std::size_t = 0) const
{
const std::size_t i0 = (i+1)%3, i1 = (i+2)%3;
return a[i0]*b[i1] - a[i1]*b[i0];
return a_[i0]*b_[i1] - a_[i1]*b_[i0];
}
private:
E0 const& a;
E1 const& b;
E0 const& a_;
E1 const& b_;
};
} // end namespace expression
......@@ -322,16 +322,16 @@ namespace Dec
: public MatExpr<Constant<T,N,M>, T, N, M>
{
Constant(T value)
: value(value)
: value_(value)
{}
T at(std::size_t, std::size_t = 0) const
{
return value;
return value_;
}
private:
T value;
T value_;
};
} // end namespace expression
......@@ -412,16 +412,16 @@ namespace Dec
: public MatExpr<Hermitian<E,T,N,M>, T, M, N>
{
Hermitian(E const& expr)
: expr(expr)
: expr_(expr)
{}
T at(std::size_t i, std::size_t j) const
{
return conj_op(expr.at(j,i));
return conj_op(expr_.at(j,i));
}
private:
E const& expr;
E const& expr_;
operation::hermitian<T> conj_op;
};
......@@ -461,18 +461,18 @@ namespace Dec
using E0 = typename V0::model;
using E1 = typename V1::model;
OuterProduct(E0 const& expr0, E1 const& expr1)
: expr0(expr0)
, expr1(expr1)
: expr0_(expr0)
, expr1_(expr1)
{}
T at(std::size_t i, std::size_t j) const
{
return expr0.at(i) * expr1.at(j);
return expr0_.at(i) * expr1_.at(j);
}
private:
E0 const& expr0;
E1 const& expr1;
E0 const& expr0_;
E1 const& expr1_;
};
} // end namespace expression
......@@ -568,21 +568,22 @@ namespace Dec
: public MatExpr<Minore<E, T, N, M>, T, N-1, M-1>
{
Minore(E const& expr, std::size_t row, std::size_t col)
: mat(expr)
, row(row)
, col(col)
: mat_(expr)
, row_(row)
, col_(col)
{}
T at(std::size_t i, std::size_t j) const
{
std::size_t i0 = i < row ? i : i+1, j0 = j < col ? j : j+1;
return mat(i0, j0);
std::size_t i0 = i < row_ ? i : i+1,
j0 = j < col_ ? j : j+1;
return mat_(i0, j0);
}
private:
E const& mat;
std::size_t row;
std::size_t col;
E const& mat_;
std::size_t row_;
std::size_t col_;
};
} // end namespace expression
......@@ -641,25 +642,25 @@ namespace Dec
: public MatExpr<RowPermutation<E, T, N, M, Vec>, T, N, M>
{
RowPermutation(E const& expr, Vec const& p)
: mat(expr)
, perm(p)
: mat_(expr)
, perm_(p)
{}
T const& at(std::size_t i, std::size_t j) const
{
return mat.at(perm[i], j);
return mat_.at(perm_[i], j);
}
T const& at(std::size_t idx) const
{
std::size_t i = idx/M;
std::size_t j = idx%M;
return mat.at(perm[i]*M + j);
return mat_.at(perm_[i]*M + j);
}
private:
E const& mat;
Vec const& perm;
E const& mat_;
Vec const& perm_;
};
} // end namespace expression
......
......@@ -27,22 +27,22 @@ namespace Dec
static constexpr std::size_t M = J1-J0;
SubMatImpl(E const& expr)
: mat(expr)
: mat_(expr)
{}
T const at(std::size_t i, std::size_t j) const
{
assert( i < N && j < M );
return mat(I0+i, J0+j);
return mat_(I0+i, J0+j);
}
T const at(std::size_t i) const
{
return M == 1 ? mat(I0+i, J0) : mat(I0, J0+i);
return M == 1 ? mat_(I0+i, J0) : mat_(I0, J0+i);
}
private:
E const& mat;
E const& mat_;
};
......@@ -59,7 +59,7 @@ namespace Dec
SubMatImpl(E& expr)
: Super(expr)
, mat(expr)
, mat_(expr)
{}
/// @{
......@@ -106,7 +106,7 @@ namespace Dec
{
for (std::size_t i = I0; i < I1; ++i)
for (std::size_t j = J0; j < J1; ++j)
mat(i, j) = scalar;
mat_(i, j) = scalar;
return *this;
}
......@@ -116,7 +116,7 @@ namespace Dec
{
for (std::size_t i = I0; i < I1; ++i)
for (std::size_t j = J0; j < J1; ++j)
mat(i, j) += scalar;
mat_(i, j) += scalar;
return *this;
}
......@@ -126,7 +126,7 @@ namespace Dec
{
for (std::size_t i = I0; i < I1; ++i)
for (std::size_t j = J0; j < J1; ++j)
mat(i, j) -= scalar;
mat_(i, j) -= scalar;
return *this;
}
......@@ -136,7 +136,7 @@ namespace Dec
{
for (std::size_t i = I0; i < I1; ++i)
for (std::size_t j = J0; j < J1; ++j)
mat(i, j) *= scalar;
mat_(i, j) *= scalar;
return *this;
}
......@@ -146,7 +146,7 @@ namespace Dec
{
for (std::size_t i = I0; i < I1; ++i)
for (std::size_t j = J0; j < J1; ++j)
mat(i, j) /= scalar;
mat_(i, j) /= scalar;
return *this;
}
......@@ -156,12 +156,12 @@ namespace Dec
T& operator()(std::size_t i, std::size_t j)
{
assert( i < N && j < M );
return mat(I0+i, J0+j);
return mat_(I0+i, J0+j);
}
T& operator[](std::size_t i)
{
return M == 1 ? mat(I0+i, J0) : mat(I0, J0+i);
return M == 1 ? mat_(I0+i, J0) : mat_(I0, J0+i);
}
using Super::operator();
......@@ -174,12 +174,12 @@ namespace Dec
{
for (std::size_t i = 0; i < N; ++i)
for (std::size_t j = 0; j < M; ++j)
assign(mat(I0+i, J0+j), expr(i,j));
assign(mat_(I0+i, J0+j), expr(i,j));
return *this;
}
private:
E& mat;
E& mat_;
};
} // end namespace _aux
......@@ -201,25 +201,25 @@ namespace Dec
: public MatExpr<RowVec<E,T,M>, T, 1, M>
{
RowVec(E const& expr, std::size_t row)
: mat(expr)
, row(row)
: mat_(expr)
, row_(row)
{}
T const at(std::size_t /*i = 0*/, std::size_t j) const
{
assert( j < M );