ulfben icon

submatrix chatgpt

ulfben | PRO | 02/05/23 03:54:58 PM UTC | 0 ⭐ | 2313 👁️ | Never ⏰ | []
C++ |

670 B

|

None

|

0 👍

/

0 👎

//chatgpt optimized submatrix to reduce branching
 
 
constexpr auto submatrix(size_type remove_row, size_type remove_column) const noexcept {
    assert(remove_row < rows() && remove_column < columns() && "submatrix: row and column to remove must be inside the original matrix.");
    Matrix<ROWS - 1, COLUMNS - 1> r;          
    uint8_t ri = 0;
    for (size_type i = 0; i < rows(); i++) {
        if (i == remove_row) {
            continue;
        }
        for (size_type j = 0; j < columns(); j++) {
            if (j == remove_column) {
                continue;
            }
            r[ri++] = _data[i * columns() + j];
        }
    }     
    return r;
}
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎