17#ifndef __connectome_mat2vec_h__
18#define __connectome_mat2vec_h__
25#include "connectome/connectome.h"
31 namespace Connectome {
45 const uint64_t i64 (i);
46 const uint64_t j64 (j);
48 return j64 + (uint64_t(dim) * i64) - ((i64 * (i64+1)) / 2);
50 return i64 + (uint64_t(dim) * j64) - ((j64 * (j64+1)) / 2);
53 std::pair<node_t, node_t>
operator() (
const uint64_t i)
const
55 static const uint64_t temp = 2*dim+1;
56 static const uint64_t temp_sq = temp * temp;
57 const uint64_t row =
std::floor ((temp - std::sqrt(temp_sq - (8*i))) / 2);
58 const uint64_t col = i - (uint64_t(dim)*row) + ((row * (row+1))/2);
65 uint64_t
vec_size()
const {
return (uint64_t(dim) * (uint64_t(dim)+1) / 2); }
68 template <
class MatType,
class VecType>
70 template <
class VecType,
class MatType>
74 template <
class MatType>
76 template <
class VecType>
87 template <
class MatType,
class VecType>
90 assert (m.rows() == m.cols());
91 assert (m.rows() == dim);
94 const std::pair<node_t, node_t> row_col = (*this) (
index);
95 v[
index] = m (row_col.first, row_col.second);
100 template <
class VecType,
class MatType>
103 assert (
size_t (v.size()) ==
vec_size());
105 for (
node_t row = 0; row != dim; ++row) {
106 for (
node_t col = 0; col != dim; ++col)
107 m (row, col) = v[(*this) (row, col)];
112 template <
class MatType>
120 template <
class VecType>
VecType & M2V(const MatType &, VecType &) const
MatType & V2M(const VecType &, MatType &) const
uint64_t operator()(const node_t i, const node_t j) const
uint64_t vec_size() const
constexpr I floor(const T x)
template function with cast to different type
Eigen::Array< value_type, Eigen::Dynamic, Eigen::Dynamic > matrix_type
Eigen::Array< value_type, Eigen::Dynamic, 1 > vector_type
Eigen::Matrix< default_type, 3, 1 > VecType
Eigen::Matrix< default_type, 3, 3 > MatType