Maybe this does not make a difference, and it's a bit ugly, but I was thinking this change would allow the methods in question to be more readily inlined by the compiler.
parent
98ae00f1ef
commit
15a69fa1ca
|
@ -58,13 +58,25 @@ protected:
|
||||||
DenseIndex rowEnd_; ///< Changes apparent matrix view, see class comments.
|
DenseIndex rowEnd_; ///< Changes apparent matrix view, see class comments.
|
||||||
DenseIndex blockStart_; ///< Changes apparent matrix view, see class comments.
|
DenseIndex blockStart_; ///< Changes apparent matrix view, see class comments.
|
||||||
|
|
||||||
|
#define ASSERT_INVARIANTS \
|
||||||
|
assert(matrix_.cols() == variableColOffsets_.back());\
|
||||||
|
assert(blockStart_ < (DenseIndex)variableColOffsets_.size());\
|
||||||
|
assert(rowStart_ <= matrix_.rows());\
|
||||||
|
assert(rowEnd_ <= matrix_.rows());\
|
||||||
|
assert(rowStart_ <= rowEnd_);\
|
||||||
|
|
||||||
|
#define CHECK_BLOCK(block) \
|
||||||
|
assert(matrix_.cols() == variableColOffsets_.back());\
|
||||||
|
assert(block < (DenseIndex)variableColOffsets_.size() - 1);\
|
||||||
|
assert(variableColOffsets_[block] < matrix_.cols() && variableColOffsets_[block+1] <= matrix_.cols());
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** Construct an empty VerticalBlockMatrix */
|
/** Construct an empty VerticalBlockMatrix */
|
||||||
VerticalBlockMatrix() :
|
VerticalBlockMatrix() :
|
||||||
rowStart_(0), rowEnd_(0), blockStart_(0) {
|
rowStart_(0), rowEnd_(0), blockStart_(0) {
|
||||||
variableColOffsets_.push_back(0);
|
variableColOffsets_.push_back(0);
|
||||||
assertInvariants();
|
ASSERT_INVARIANTS
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Construct from a container of the sizes of each vertical block. */
|
/** Construct from a container of the sizes of each vertical block. */
|
||||||
|
@ -73,7 +85,7 @@ public:
|
||||||
rowStart_(0), rowEnd_(height), blockStart_(0) {
|
rowStart_(0), rowEnd_(height), blockStart_(0) {
|
||||||
fillOffsets(dimensions.begin(), dimensions.end());
|
fillOffsets(dimensions.begin(), dimensions.end());
|
||||||
matrix_.resize(height, variableColOffsets_.back());
|
matrix_.resize(height, variableColOffsets_.back());
|
||||||
assertInvariants();
|
ASSERT_INVARIANTS
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,7 +99,7 @@ public:
|
||||||
if (variableColOffsets_.back() != matrix_.cols())
|
if (variableColOffsets_.back() != matrix_.cols())
|
||||||
throw std::invalid_argument(
|
throw std::invalid_argument(
|
||||||
"Requested to create a VerticalBlockMatrix with dimensions that do not sum to the total columns of the provided matrix.");
|
"Requested to create a VerticalBlockMatrix with dimensions that do not sum to the total columns of the provided matrix.");
|
||||||
assertInvariants();
|
ASSERT_INVARIANTS
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,7 +110,7 @@ public:
|
||||||
rowStart_(0), rowEnd_(height), blockStart_(0) {
|
rowStart_(0), rowEnd_(height), blockStart_(0) {
|
||||||
fillOffsets(firstBlockDim, lastBlockDim);
|
fillOffsets(firstBlockDim, lastBlockDim);
|
||||||
matrix_.resize(height, variableColOffsets_.back());
|
matrix_.resize(height, variableColOffsets_.back());
|
||||||
assertInvariants();
|
ASSERT_INVARIANTS
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,40 +130,40 @@ public:
|
||||||
DenseIndex height);
|
DenseIndex height);
|
||||||
|
|
||||||
/// Row size
|
/// Row size
|
||||||
DenseIndex rows() const {
|
inline DenseIndex rows() const {
|
||||||
assertInvariants();
|
ASSERT_INVARIANTS
|
||||||
return rowEnd_ - rowStart_;
|
return rowEnd_ - rowStart_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Column size
|
/// Column size
|
||||||
DenseIndex cols() const {
|
inline DenseIndex cols() const {
|
||||||
assertInvariants();
|
ASSERT_INVARIANTS
|
||||||
return variableColOffsets_.back() - variableColOffsets_[blockStart_];
|
return variableColOffsets_.back() - variableColOffsets_[blockStart_];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Block count
|
/// Block count
|
||||||
DenseIndex nBlocks() const {
|
inline DenseIndex nBlocks() const {
|
||||||
assertInvariants();
|
ASSERT_INVARIANTS
|
||||||
return variableColOffsets_.size() - 1 - blockStart_;
|
return variableColOffsets_.size() - 1 - blockStart_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Access a single block in the underlying matrix with read/write access */
|
/** Access a single block in the underlying matrix with read/write access */
|
||||||
Block operator()(DenseIndex block) {
|
inline Block operator()(DenseIndex block) {
|
||||||
return range(block, block + 1);
|
return range(block, block + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Access a const block view */
|
/** Access a const block view */
|
||||||
const constBlock operator()(DenseIndex block) const {
|
inline const constBlock operator()(DenseIndex block) const {
|
||||||
return range(block, block + 1);
|
return range(block, block + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** access ranges of blocks at a time */
|
/** access ranges of blocks at a time */
|
||||||
Block range(DenseIndex startBlock, DenseIndex endBlock) {
|
Block range(DenseIndex startBlock, DenseIndex endBlock) {
|
||||||
assertInvariants();
|
ASSERT_INVARIANTS
|
||||||
DenseIndex actualStartBlock = startBlock + blockStart_;
|
DenseIndex actualStartBlock = startBlock + blockStart_;
|
||||||
DenseIndex actualEndBlock = endBlock + blockStart_;
|
DenseIndex actualEndBlock = endBlock + blockStart_;
|
||||||
if (startBlock != 0 || endBlock != 0) {
|
if (startBlock != 0 || endBlock != 0) {
|
||||||
checkBlock(actualStartBlock);
|
CHECK_BLOCK(actualStartBlock);
|
||||||
assert(actualEndBlock < (DenseIndex)variableColOffsets_.size());
|
assert(actualEndBlock < (DenseIndex)variableColOffsets_.size());
|
||||||
}
|
}
|
||||||
const DenseIndex startCol = variableColOffsets_[actualStartBlock];
|
const DenseIndex startCol = variableColOffsets_[actualStartBlock];
|
||||||
|
@ -160,11 +172,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
const constBlock range(DenseIndex startBlock, DenseIndex endBlock) const {
|
const constBlock range(DenseIndex startBlock, DenseIndex endBlock) const {
|
||||||
assertInvariants();
|
ASSERT_INVARIANTS
|
||||||
DenseIndex actualStartBlock = startBlock + blockStart_;
|
DenseIndex actualStartBlock = startBlock + blockStart_;
|
||||||
DenseIndex actualEndBlock = endBlock + blockStart_;
|
DenseIndex actualEndBlock = endBlock + blockStart_;
|
||||||
if (startBlock != 0 || endBlock != 0) {
|
if (startBlock != 0 || endBlock != 0) {
|
||||||
checkBlock(actualStartBlock);
|
CHECK_BLOCK(actualStartBlock);
|
||||||
assert(actualEndBlock < (DenseIndex)variableColOffsets_.size());
|
assert(actualEndBlock < (DenseIndex)variableColOffsets_.size());
|
||||||
}
|
}
|
||||||
const DenseIndex startCol = variableColOffsets_[actualStartBlock];
|
const DenseIndex startCol = variableColOffsets_[actualStartBlock];
|
||||||
|
@ -175,82 +187,76 @@ public:
|
||||||
|
|
||||||
/** Return the full matrix, *not* including any portions excluded by
|
/** Return the full matrix, *not* including any portions excluded by
|
||||||
* rowStart(), rowEnd(), and firstBlock() */
|
* rowStart(), rowEnd(), and firstBlock() */
|
||||||
Block full() {
|
inline Block full() {
|
||||||
return range(0, nBlocks());
|
return range(0, nBlocks());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the full matrix, *not* including any portions excluded by
|
/** Return the full matrix, *not* including any portions excluded by
|
||||||
* rowStart(), rowEnd(), and firstBlock() */
|
* rowStart(), rowEnd(), and firstBlock() */
|
||||||
const constBlock full() const {
|
inline const constBlock full() const {
|
||||||
return range(0, nBlocks());
|
return range(0, nBlocks());
|
||||||
}
|
}
|
||||||
|
|
||||||
DenseIndex offset(DenseIndex block) const {
|
inline DenseIndex offset(DenseIndex block) const {
|
||||||
assertInvariants();
|
ASSERT_INVARIANTS
|
||||||
DenseIndex actualBlock = block + blockStart_;
|
DenseIndex actualBlock = block + blockStart_;
|
||||||
checkBlock(actualBlock);
|
CHECK_BLOCK(actualBlock);
|
||||||
return variableColOffsets_[actualBlock];
|
return variableColOffsets_[actualBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get/set the apparent first row of the underlying matrix for all operations
|
/// Get/set the apparent first row of the underlying matrix for all operations
|
||||||
DenseIndex& rowStart() {
|
inline DenseIndex& rowStart() {
|
||||||
return rowStart_;
|
return rowStart_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get/set the apparent last row
|
/** Get/set the apparent last row
|
||||||
* (exclusive, i.e. rows() == rowEnd() - rowStart())
|
* (exclusive, i.e. rows() == rowEnd() - rowStart())
|
||||||
* of the underlying matrix for all operations */
|
* of the underlying matrix for all operations */
|
||||||
DenseIndex& rowEnd() {
|
inline DenseIndex& rowEnd() {
|
||||||
return rowEnd_;
|
return rowEnd_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get/set the apparent first block for all operations */
|
/** Get/set the apparent first block for all operations */
|
||||||
DenseIndex& firstBlock() {
|
inline DenseIndex& firstBlock() {
|
||||||
return blockStart_;
|
return blockStart_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the apparent first row of the underlying matrix for all operations */
|
/** Get the apparent first row of the underlying matrix for all operations */
|
||||||
DenseIndex rowStart() const {
|
inline DenseIndex rowStart() const {
|
||||||
return rowStart_;
|
return rowStart_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the apparent last row (exclusive, i.e. rows() == rowEnd() - rowStart())
|
/** Get the apparent last row (exclusive, i.e. rows() == rowEnd() - rowStart())
|
||||||
* of the underlying matrix for all operations */
|
* of the underlying matrix for all operations */
|
||||||
DenseIndex rowEnd() const {
|
inline DenseIndex rowEnd() const {
|
||||||
return rowEnd_;
|
return rowEnd_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the apparent first block for all operations */
|
/** Get the apparent first block for all operations */
|
||||||
DenseIndex firstBlock() const {
|
inline DenseIndex firstBlock() const {
|
||||||
return blockStart_;
|
return blockStart_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Access to full matrix (*including* any portions excluded by rowStart(),
|
/** Access to full matrix (*including* any portions excluded by rowStart(),
|
||||||
* rowEnd(), and firstBlock()) */
|
* rowEnd(), and firstBlock()) */
|
||||||
const Matrix& matrix() const {
|
inline const Matrix& matrix() const {
|
||||||
return matrix_;
|
return matrix_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Non-const access to full matrix (*including* any portions excluded by
|
/** Non-const access to full matrix (*including* any portions excluded by
|
||||||
* rowStart(), rowEnd(), and firstBlock()) */
|
* rowStart(), rowEnd(), and firstBlock()) */
|
||||||
Matrix& matrix() {
|
inline Matrix& matrix() {
|
||||||
return matrix_;
|
return matrix_;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void assertInvariants() const {
|
void assertInvariants() const {
|
||||||
assert(matrix_.cols() == variableColOffsets_.back());
|
ASSERT_INVARIANTS
|
||||||
assert(blockStart_ < (DenseIndex)variableColOffsets_.size());
|
|
||||||
assert(rowStart_ <= matrix_.rows());
|
|
||||||
assert(rowEnd_ <= matrix_.rows());
|
|
||||||
assert(rowStart_ <= rowEnd_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkBlock(DenseIndex block) const {
|
void checkBlock(DenseIndex block) const {
|
||||||
assert(matrix_.cols() == variableColOffsets_.back());
|
CHECK_BLOCK(block)
|
||||||
assert(block < (DenseIndex)variableColOffsets_.size() - 1);
|
|
||||||
assert(
|
|
||||||
variableColOffsets_[block] < matrix_.cols() && variableColOffsets_[block+1] <= matrix_.cols());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ITERATOR>
|
template<typename ITERATOR>
|
||||||
|
|
Loading…
Reference in New Issue