21 lines
597 B
C++
21 lines
597 B
C++
#include "matrix.hpp"
|
|
#include <array>
|
|
|
|
Matrix::Matrix(int rows, int cols) : data(rows*cols, 0.0), rows(rows), cols(cols) {}
|
|
|
|
std::array<int, 2> Matrix::size() const {return {rows, cols};}
|
|
|
|
double& Matrix::operator()(int i, int j) {return data[i*cols+j];}
|
|
double Matrix::operator()(int i, int j) const {return data[i*cols+j];}
|
|
|
|
void Matrix::print() const {
|
|
std::cout << "---\n";
|
|
for (int x=0; x<rows; x++) {
|
|
for (int y=0; y<cols; y++) {
|
|
std::cout << data[x*cols+y] << " ";
|
|
}
|
|
std::cout << "\n";
|
|
}
|
|
std::cout << "---";
|
|
std::cout << std::endl;
|
|
} |