Skip to content

Commit

Permalink
Adds the ability to take block references within block references.
Browse files Browse the repository at this point in the history
  • Loading branch information
pazmivaniye committed Jul 11, 2024
1 parent 6e87c6b commit 47ee51c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 12 additions & 6 deletions mat_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 47ee51c

Please sign in to comment.