7#ifndef REAL_TIME_TRANSPORT_BLOCK_MATRICES_BLOCK_HELPER_H
8#define REAL_TIME_TRANSPORT_BLOCK_MATRICES_BLOCK_HELPER_H
13#include <SciCore/Definitions.h>
15namespace RealTimeTransport
18template <
typename FuncT>
19void foreachCommonElement(FuncT&& f,
const std::set<
int>& x,
const std::set<
int>& y)
21 auto it_x = x.begin();
22 auto it_y = y.begin();
24 while (it_x != x.end() && it_y != y.end())
30 else if (*it_y < *it_x)
45template <
typename MatrixT>
46MatrixT extractDenseBlock(
const MatrixT& A,
int i,
int j,
const std::vector<
int>& blockDims)
50 for (
int k = 0; k < i; ++k)
52 startRow += blockDims[k];
56 for (
int k = 0; k < j; ++k)
58 startCol += blockDims[k];
62 int numRows = blockDims[i];
63 int numCols = blockDims[j];
66 return A.block(startRow, startCol, numRows, numCols);
69template <
typename MatrixT>
70bool isBlockDiagonal(
const MatrixT& matrix,
const std::vector<
int>& blockDimensions)
73 int numBlocks =
static_cast<
int>(blockDimensions.size());
74 for (
int i = 0; i < numBlocks; ++i)
77 for (
int j = 0; j < numBlocks; ++j)
82 auto block = matrix.block(currentRow, currentCol, blockDimensions[i], blockDimensions[j]);
85 if (block.isZero() ==
false)
90 currentCol += blockDimensions[j];
92 currentRow += blockDimensions[i];