1 #ifndef CLASSIC_Array2D_HH
2 #define CLASSIC_Array2D_HH
234 rows(0), cols(0), len(0), data(0)
240 rows(array.rows), cols(array.cols), len(array.len), data(new
T[len]) {
247 rows(r), cols(
c), len(r *
c), data(new
T[len])
253 rows(r), cols(
c), len(r *
c), data(new
T[len]) {
271 data =
new T[rhs.
len];
284 if(r < 0 || r >= rows || c < 0 || c >= ncols()) {
285 throw CLRangeError(
"Array2d::operator()",
"Index out of range.");
287 return data[cols*r+
c];
293 if(r < 0 || r >= rows || c < 0 || c >= ncols()) {
294 throw CLRangeError(
"Array2d::operator()",
"Index out of range.");
296 return data[cols*r+
c];
345 throw CLRangeError(
"Array2D::row_begin()",
"Row index out of range.");
347 return &data[cols*r];
354 throw CLRangeError(
"Array2D::row_end()",
"Row index out of range.");
356 return &data[cols*(r+1)];
363 throw CLRangeError(
"Array2D::row_begin()",
"Row index out of range.");
365 return &data[cols*r];
372 throw CLRangeError(
"Array2D::row_end()",
"Row index out of range.");
374 return &data[cols*(r+1)];
380 return &data[cols*r];
386 return &data[cols*r];
393 throw CLRangeError(
"Array2D::col_begin()",
"Column index out of range.");
402 throw CLRangeError(
"Array2D::col_end()",
"Column index out of range.");
411 throw CLRangeError(
"Array2D::col_begin()",
"Column index out of range.");
420 throw CLRangeError(
"Array2D::col_end()",
"Column index out of range.");
429 std::copy(col_begin(
c), col_end(
c), toArray.
begin());
436 std::copy(row_begin(r), row_end(r), toArray.
begin());
442 if(fromArray.
size() != rows) {
443 throw SizeError(
"Array2D::putColumn()",
"Dimensions inconsistent.");
445 std::copy(fromArray.
begin(), fromArray.
end(), col_begin(
c));
451 if(fromArray.
size() != cols) {
452 throw SizeError(
"Array2D::putRow()",
"Dimensions inconsistent.");
454 std::copy(fromArray.
begin(), fromArray.
end(), row_begin(r));
460 std::swap_ranges(col_begin(col1), col_end(col1), col_begin(col2));
466 std::swap_ranges(row_begin(row1), row_end(row1), row_begin(row2));
472 for(
int i = 0; i < v.
nrows(); ++i) {
473 for(
int j = 0; j < v.
ncols(); ++j) {
474 os << v(i, j) <<
" ";
std::ostream & operator<<(std::ostream &os, const Array2D< T > &v)
PartBunchBase< T, Dim >::ConstIterator begin(PartBunchBase< T, Dim > const &bunch)
Inform & endl(Inform &inf)
constexpr double c
The velocity of light in m/s.
iterator begin()
Get beginning of data.
int size() const
Get array size.
iterator end()
Get end of data.
const_col_iterator col_end(int c) const
Get column iterator.
T & operator()(int r, int c)
Get element reference.
row_iterator row_begin(int r)
Get row iterator.
T value_type
The value type of the array.
const_row_iterator operator[](int r) const
Get row iterator.
const_iterator begin() const
Get pointer to beginning of data.
void swapColumns(int c1, int c2)
Exchange columns.
int size() const
Get total size (rows times columns).
T * iterator
The iterator type for sequential access to all elements.
iterator begin()
Get pointer to beginning of data.
const T * const_row_iterator
The iterator type for access by rows for a constant array.
int nrows() const
Get number of rows.
void getColumn(Array1D< T > &toArray, int c) const
Fetch column.
Array2D< T > & operator=(const Array2D< T > &)
const_row_iterator row_end(int r) const
Get row iterator.
Array2D(int rows, int cols, const T &t)
Constructor.
row_iterator row_end(int r)
Get row iterator.
const T * const_iterator
The iterator type for sequential access to all elements.
const_row_iterator row_begin(int r) const
Get row iterator.
void putColumn(const Array1D< T > &fromArray, int c)
Store column.
void putRow(const Array1D< T > &fromArray, int r)
Store row.
void swapRows(int row1, int row2)
Exchange rows.
iterator end()
Get pointer past end of data.
const_iterator end() const
Get pointer past end of data.
const T & operator()(int r, int c) const
Get element value.
Array2D()
Default constructor.
Array2D(int rows, int cols)
Constructor.
void getRow(Array1D< T > &toArray, int r) const
Fetch row.
const_col_iterator col_begin(int c) const
Get column iterator.
T * row_iterator
The iterator type for access by rows.
ConstSliceIterator< T > const_col_iterator
The iterator type for access by columns for a constant array.
row_iterator operator[](int r)
Get row iterator.
col_iterator col_begin(int c)
Get column iterator.
col_iterator col_end(int c)
Get column iterator.
int ncols() const
Get number of columns.
SliceIterator< T > col_iterator
The iterator type for access by columns.
Iterator for array slice.
Iterator for array slice.