Advertisement
ulfben

submatrix chatgpt

Feb 5th, 2023
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. //chatgpt optimized submatrix to reduce branching
  2.  
  3.  
  4. constexpr auto submatrix(size_type remove_row, size_type remove_column) const noexcept {
  5.     assert(remove_row < rows() && remove_column < columns() && "submatrix: row and column to remove must be inside the original matrix.");
  6.     Matrix<ROWS - 1, COLUMNS - 1> r;          
  7.     uint8_t ri = 0;
  8.     for (size_type i = 0; i < rows(); i++) {
  9.         if (i == remove_row) {
  10.             continue;
  11.         }
  12.         for (size_type j = 0; j < columns(); j++) {
  13.             if (j == remove_column) {
  14.                 continue;
  15.             }
  16.             r[ri++] = _data[i * columns() + j];
  17.         }
  18.     }    
  19.     return r;
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement