11 std::vector<T> m_data;
14 m_nRow(0), m_nCol(0) {
17 m_nRow(nRow), m_nCol(nCol) {
18 m_data.resize(m_nRow * m_nCol);
20 BasicArray(
int nRow,
int nCol,
const T* data) :
21 m_nRow(nRow), m_nCol(nCol), m_data(data, data+nRow*nCol) {
24 m_nRow(x.m_nRow), m_nCol(x.m_nCol), m_data(x.m_data) {
26 void resize(
int nRow,
int nCol) {
29 m_data.resize(m_nRow * m_nCol);
41 BasicArray block(
int startRow,
int startCol,
int nRow,
int nCol)
const {
43 out.resize(nRow, nCol);
44 for (
int iRow = 0; iRow < nRow; ++iRow) {
45 for (
int iCol = 0; iCol < nCol; ++iCol) {
46 out(iRow, iCol) = at(iRow + startRow, iCol + startCol);
51 std::vector<T> rblock(
int startRow,
int startCol,
int nCol)
const {
52 std::vector<T> out(nCol);
53 for (
int iCol = 0; iCol < nCol; ++iCol) {
54 out[iCol] = at(startRow, iCol + startCol);
60 out.resize(n, m_nCol);
61 for (
int i = start; i < start + n; ++i) {
62 for (
int j = 0; j < m_nCol; ++j) {
69 return middleRows(0, n);
72 return middleRows(m_nRow - n, n);
75 const T& at(
int row,
int col)
const {
76 return m_data.at(row * m_nCol + col);
78 T& at(
int row,
int col) {
79 return m_data.at(row * m_nCol + col);
81 const T& operator()(
int row,
int col)
const {
82 return m_data.at(row * m_nCol + col);
84 T& operator()(
int row,
int col) {
85 return m_data.at(row * m_nCol + col);
88 std::vector<T> col(
int col) {
91 for (
int row = 0; row < m_nRow; row++)
92 out.push_back(at(row, col));
96 std::vector<T> row(
int row) {
99 for (
int col = 0; col < m_nCol; col++)
100 out.push_back(at(row, col));
104 std::vector<T> flatten() {
109 return m_data.data();
112 return m_data.data();