11 #ifndef INCLUDE_MOLASSEMBLER_TEMPLE_CONSTEXPR_TRIANGULAR_MATRIX_H
12 #define INCLUDE_MOLASSEMBLER_TEMPLE_CONSTEXPR_TRIANGULAR_MATRIX_H
18 namespace Molassembler {
20 namespace UpperTriangularMatrixImpl {
26 template<
typename T,
size_t size>
29 namespace index_conversion {
31 template<
size_t N,
typename Un
signedType>
32 PURITY_STRONG constexpr
unsigned toSingleIndex(
const UnsignedType i,
const UnsignedType j) {
35 - (N - i) * ((N - i) - 1) / 2
41 template<
size_t N,
typename Un
signedType>
42 PURITY_STRONG constexpr std::pair<UnsignedType, UnsignedType> toDoubleIndex(
const UnsignedType k) {
45 -
static_cast<unsigned>(
63 + (N - i) * ((N - i) - 1) / 2
70 PURITY_STRONG constexpr
bool isValidMatrixSize(
const size_t dataSize) {
71 auto root = Math::sqrt(1.0 + 8.0 * dataSize);
74 Floating::isCloseRelative(
76 static_cast<double>(Math::floor(root)),
83 PURITY_STRONG constexpr
size_t getMatrixSize(
const size_t dataSize) {
85 1 + Math::sqrt(1.0 + 8.0 * dataSize)
96 template<
typename ValueType,
size_t dataSize>
103 static constexpr
unsigned N = UpperTriangularMatrixImpl::getMatrixSize(dataSize);
113 template<
typename,
size_t>
class ArrayType
115 const ArrayType<ValueType, dataSize>& data
119 UpperTriangularMatrixImpl::isValidMatrixSize(dataSize) && dataSize > 0,
120 "Passed data size is not consistent with an upper triangular matrix!"
132 constexpr ValueType&
at(
const unsigned i,
const unsigned j) {
133 if(i >= j || i >= N || j >= N) {
134 throw "Index out of bounds!";
138 UpperTriangularMatrixImpl::index_conversion::toSingleIndex<N>(i, j)
151 if(i >= j || i >= N || j >= N) {
152 throw "Index out of bounds!";
156 UpperTriangularMatrixImpl::index_conversion::toSingleIndex<N>(i, j)
173 template<
typename,
size_t>
class ArrayType,
177 const ArrayType<ValueType, size>& data
constexpr const DataType & getData() const
Get full underlying data in raw form.
Definition: UpperTriangularMatrix.h:162
constexpr UpperTriangularMatrix< ValueType, size > makeUpperTriangularMatrix(const ArrayType< ValueType, size > &data)
Helper constructing function that deduces the required type signature.
Definition: UpperTriangularMatrix.h:176
constexpr ValueType & at(const unsigned i, const unsigned j)
Modifiable matrix accessor.
Definition: UpperTriangularMatrix.h:132
constexpr UpperTriangularMatrix(const ArrayType< ValueType, dataSize > &data)
Constructor from existing data.
Definition: UpperTriangularMatrix.h:114
#define PURITY_WEAK
Definition: Preprocessor.h:36
constexpr UpperTriangularMatrix()
Default constructor.
Definition: UpperTriangularMatrix.h:109
Temple::Array< T, size > ArrayType
Definition: Properties.h:144
Strictly upper triangular matrix.
Definition: UpperTriangularMatrix.h:97
PURITY_WEAK constexpr const ValueType & at(const unsigned i, const unsigned j) const
Definition: UpperTriangularMatrix.h:147
#define PURITY_STRONG
Definition: Preprocessor.h:65
Helpers for comparing floating point values.