Skip to content

Commit 7c312d6

Browse files
committed
hook for some polymorphic matrices
1 parent 5b9c410 commit 7c312d6

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/maxplus/algebra/mpmatrix.h

+3
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ class Matrix {
177177
[[nodiscard]] virtual Matrix getSubMatrix(const std::list<unsigned int> &rowIndices,
178178
const std::list<unsigned int> &colIndices) const;
179179

180+
[[nodiscard]] virtual std::shared_ptr<Matrix> getSubMatrixPtr(const std::list<unsigned int> &rowIndices,
181+
const std::list<unsigned int> &colIndices) const;
182+
180183
[[nodiscard]] Matrix getSubMatrix(const std::list<unsigned int> &indices) const;
181184

182185
[[nodiscard]] Matrix getSubMatrixNonSquare(const std::list<unsigned int> &indices) const;

src/algebra/mpmatrix.cc

+19
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,25 @@ Matrix Matrix::getSubMatrix(const std::list<unsigned int> &rowIndices,
581581
return newMatrix;
582582
}
583583

584+
std::shared_ptr<Matrix> Matrix::getSubMatrixPtr(const std::list<unsigned int> &rowIndices,
585+
const std::list<unsigned int> &colIndices) const {
586+
auto NR = static_cast<unsigned int>(rowIndices.size());
587+
auto NC = static_cast<unsigned int>(colIndices.size());
588+
auto newMatrix = std::make_shared<Matrix>(NR, NC);
589+
590+
auto rit = rowIndices.begin();
591+
for (unsigned int r = 0; r < NR; r++, rit++) {
592+
unsigned int ri = (*rit);
593+
auto cit = colIndices.begin();
594+
for (unsigned int c = 0; c < NC; c++, cit++) {
595+
unsigned int ci = (*cit);
596+
newMatrix->put(r, c, this->get(ri, ci));
597+
}
598+
}
599+
return newMatrix;
600+
}
601+
602+
584603
/**
585604
* Make sub matrix with indices in list from square matrix
586605
*/

0 commit comments

Comments
 (0)