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

cleanup of fixmatvec submodule

parent fd9ce2da
......@@ -27,7 +27,7 @@ namespace Dec
using model = Self;
using value_type = T;
using field_type = FieldType_t<T>;
using const_reference = T const&;
/** Constructors
* @{
......
......@@ -44,7 +44,7 @@ namespace Dec
{
using model = Model;
using value_type = T;
using field_type = FieldType_t<T>;
using const_reference = T const;
/// @{
......
......@@ -156,17 +156,20 @@ namespace Dec
struct DiagonalMat
: public MatExpr<DiagonalMat<E,T,N>, T, N, N>
{
using const_reference = typename E::const_reference;
DiagonalMat(E const& expr)
: vec_(expr)
{}
auto at(std::size_t i, std::size_t j) const
const_reference at(std::size_t i, std::size_t j) const
{
return i==j ? vec_.at(i) : T(0);
return i==j ? vec_.at(i) : zero;
}
private:
E const& vec_;
T zero = T(0);
};
......@@ -177,11 +180,13 @@ namespace Dec
struct DiagonalVec
: public MatExpr<DiagonalVec<E,T,N>, T, N, 1>
{
using const_reference = typename E::const_reference;
DiagonalVec(E const& expr)
: mat_(expr)
{}
auto at(std::size_t i, std::size_t = 0) const
const_reference at(std::size_t i, std::size_t = 0) const
{
return mat_.at(i, i);
}
......@@ -341,7 +346,7 @@ namespace Dec
* \brief Returns an expression representing a unit matrix
**/
template <class T, std::size_t N>
expression::Eye<T, N> eye()
expression::Eye<T, N> eye(index_<N> = {})
{
return {};
}
......@@ -350,7 +355,7 @@ namespace Dec
* \brief Returns an expression representing a constant matrix = 1
**/
template <class T, std::size_t N, std::size_t M=N>
expression::Constant<T, N, M> ones()
expression::Constant<T, N, M> ones(index_<N> = {}, index_<M> = {})
{
return {T(1)};
}
......@@ -359,7 +364,7 @@ namespace Dec
* \brief Returns an expression representing a constant matrix = 0
**/
template <class T, std::size_t N, std::size_t M=N>
expression::Constant<T, N, M> zeros()
expression::Constant<T, N, M> zeros(index_<N> = {}, index_<M> = {})
{
return {T(0)};
}
......@@ -465,7 +470,7 @@ namespace Dec
, expr1_(expr1)
{}
T at(std::size_t i, std::size_t j) const
T at(std::size_t i, std::size_t j) const // NOTE: use `auto` here?
{
return expr0_.at(i) * expr1_.at(j);
}
......@@ -567,13 +572,15 @@ namespace Dec
struct Minore
: public MatExpr<Minore<E, T, N, M>, T, N-1, M-1>
{
using const_reference = typename E::const_reference;
Minore(E const& expr, std::size_t row, std::size_t col)
: mat_(expr)
, row_(row)
, col_(col)
{}
T at(std::size_t i, std::size_t j) const
const_reference 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;
......@@ -641,17 +648,19 @@ namespace Dec
struct RowPermutation
: public MatExpr<RowPermutation<E, T, N, M, Vec>, T, N, M>
{
using const_reference = typename E::const_reference;
RowPermutation(E const& expr, Vec const& p)
: mat_(expr)
, perm_(p)
{}
T const& at(std::size_t i, std::size_t j) const
const_reference at(std::size_t i, std::size_t j) const
{
return mat_.at(perm_[i], j);
}
T const& at(std::size_t idx) const
const_reference at(std::size_t idx) const
{
std::size_t i = idx/M;
std::size_t j = idx%M;
......
......@@ -23,6 +23,8 @@ namespace Dec
struct SubMatImpl<true, E, T, I0, I1, J0, J1>
: public MatExpr<SubMatImpl<true, E,T,I0,I1,J0,J1>, T, I1-I0, J1-J0>
{
using const_reference = typename E::const_reference;
static constexpr std::size_t N = I1-I0;
static constexpr std::size_t M = J1-J0;
......@@ -30,13 +32,13 @@ namespace Dec
: mat_(expr)
{}
T const at(std::size_t i, std::size_t j) const
const_reference at(std::size_t i, std::size_t j) const
{
assert( i < N && j < M );
return mat_(I0+i, J0+j);
}
T const at(std::size_t i) const
const_reference at(std::size_t i) const
{
return M == 1 ? mat_(I0+i, J0) : mat_(I0, J0+i);
}
......@@ -200,18 +202,20 @@ namespace Dec
struct RowVec
: public MatExpr<RowVec<E,T,M>, T, 1, M>
{
using const_reference = typename E::const_reference;
RowVec(E const& expr, std::size_t row)
: mat_(expr)
, row_(row)
{}
T const at(std::size_t /*i = 0*/, std::size_t j) const
const_reference at(std::size_t /*i = 0*/, std::size_t j) const
{
assert( j < M );
return mat_(row_, j);
}
T const at(std::size_t j) const
const_reference at(std::size_t j) const
{
assert( j < M );
return mat_(row_, j);
......@@ -228,12 +232,14 @@ namespace Dec
struct ColumnVec
: public MatExpr<ColumnVec<E,T,N>, T, N, 1>
{
using const_reference = typename E::const_reference;
ColumnVec(E const& expr, std::size_t col)
: mat_(expr)
, col_(col)
{}
T const at(std::size_t i, std::size_t = 0) const
const_reference at(std::size_t i, std::size_t = 0) const
{
assert( i < N );
return mat_(i, col_);
......@@ -250,17 +256,20 @@ namespace Dec
struct Upper
: public MatExpr<Upper<E,T,N,M>, T, N, M>
{
using const_reference = typename E::const_reference;
Upper(E const& expr)
: mat_(expr)
{}
T const at(std::size_t i, std::size_t j) const
const_reference at(std::size_t i, std::size_t j) const
{
return i <= j ? mat_(i, j) : T(0);
return i <= j ? mat_(i, j) : zero;
}
private:
E const& mat_;
T zero = T(0);
};
......@@ -269,17 +278,20 @@ namespace Dec
struct Lower
: public MatExpr<Lower<E,T,N,M>, T, N, M>
{
using const_reference = typename E::const_reference;
Lower(E const& expr)
: mat_(expr)
{}
T const at(std::size_t i, std::size_t j) const
const_reference at(std::size_t i, std::size_t j) const
{
return i >= j ? mat_(i, j) : T(0);
return i >= j ? mat_(i, j) : zero;
}
private:
E const& mat_;
T zero = T(0);
};
} // end namespace view
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment