6 #include <cuda_runtime.h>
13 if (row_index < 0 || row_index >= rows) {
14 throw std::out_of_range(
"Invalid row index");
18 if (image_size_x * image_size_y > cols) {
19 throw std::invalid_argument(
"Image dimensions exceed matrix column count");
23 double* h_data =
new double[cols];
26 cudaMemcpy(h_data, d_data + row_index * cols, cols *
sizeof(
double), cudaMemcpyDeviceToHost);
29 for (
int i = 0; i < image_size_x; ++i) {
31 for (
int j = 0; j < image_size_y; ++j) {
33 int index = i * image_size_y + j;
36 int value =
static_cast<int>(std::round(h_data[index]));
43 std::cout << std::setw(3) << value <<
" ";
47 std::cout << std::endl;
50 std::cout << std::endl;
void preview_image(int row_index, int image_size_x, int image_size_y) const
Preview a single image from the matrix.
Defines the Matrix class for GPU-accelerated matrix operations.