diff --git a/mat_ref.cpp b/mat_ref.cpp index 5a53db2..895e832 100644 --- a/mat_ref.cpp +++ b/mat_ref.cpp @@ -425,20 +425,26 @@ double paz::MatRef::dot(const MatRef& rhs) const paz::MatRef paz::MatRef::block(std::size_t startRow, std::size_t startCol, std:: size_t numRows, std::size_t numCols) const { -throw std::logic_error("RETURNING TEMP"); //TEMP - return Mat(*this).block(startRow, startCol, numRows, numCols); + if(startRow + numRows > rows() || startCol + numCols > cols()) + { + throw std::runtime_error("Block is out of range."); + } + auto res = *this; + res._begin.ptr += startRow + _begin.origRows*startCol; + res._begin.row = 0; + res._begin.blockRows = numRows; + res._blockCols = numCols; + return res; } paz::MatRef paz::MatRef::row(std::size_t m) const { -throw std::logic_error("RETURNING TEMP"); //TEMP - return Mat(*this).row(m); + return block(m, 0, 1, cols()); } paz::MatRef paz::MatRef::col(std::size_t n) const { -throw std::logic_error("RETURNING TEMP"); //TEMP - return Mat(*this).col(n); + return block(0, n, rows(), 1); } bool paz::MatRef::hasNan() const diff --git a/test/test.cpp b/test/test.cpp index 174ba77..7c76419 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -133,4 +133,5 @@ int main() std::cout << std::setprecision(0); PRINT(seq) PRINT(seq.block(1, 2, 3, 5)); + PRINT(seq.block(1, 2, 3, 5).block(1, 1, 2, 4)) }