Solved: 47 - MDSpan
This commit is contained in:
@@ -2,23 +2,22 @@
|
||||
|
||||
namespace cpp23 {
|
||||
|
||||
auto make_row_major_matrix(int rows, int cols, int fill) -> std::vector<int> {
|
||||
(void)rows; (void)cols; (void)fill;
|
||||
return {};
|
||||
auto make_row_major_matrix(const int rows, const int cols, const int fill) -> std::vector<int> {
|
||||
return std::vector(static_cast<size_t>(rows * cols), fill);
|
||||
}
|
||||
|
||||
auto matrix_element(
|
||||
std::mdspan<const int, std::extents<int, std::dynamic_extent, std::dynamic_extent>> matrix,
|
||||
int row, int col) -> int {
|
||||
(void)matrix; (void)row; (void)col;
|
||||
return 0;
|
||||
auto matrix_element(const std::mdspan<const int, std::extents<int, std::dynamic_extent, std::dynamic_extent>> matrix, const int row, const int col) -> int {
|
||||
return matrix[row, col];
|
||||
}
|
||||
|
||||
auto row_sums(
|
||||
std::mdspan<const int, std::extents<int, std::dynamic_extent, std::dynamic_extent>> matrix)
|
||||
-> std::vector<int> {
|
||||
(void)matrix;
|
||||
return {};
|
||||
auto row_sums(const std::mdspan<const int, std::extents<int, std::dynamic_extent, std::dynamic_extent>> matrix) -> std::vector<int> {
|
||||
auto sums = std::vector<int>(matrix.extent(0));
|
||||
for (auto i = 0; i < matrix.extent(0); ++i) {
|
||||
for (auto j = 0; j < matrix.extent(1); ++j) {
|
||||
sums[i] += matrix[i, j];
|
||||
}
|
||||
}
|
||||
return sums;
|
||||
}
|
||||
|
||||
} // namespace cpp23
|
||||
|
||||
Reference in New Issue
Block a user