1 #ifndef CLASSIC_Matrix_HH
2 #define CLASSIC_Matrix_HH
56 Matrix(
int rows,
int cols,
const T &t);
165 for(
int i =
std::min(rows, cols); i-- > 0;) {
166 this->
data[i * (cols + 1)] =
T(1);
192 std::transform(this->begin(), this->end(), this->begin(),
193 std::bind2nd(std::multiplies<T>(), val));
200 std::transform(this->begin(), this->end(), this->begin(),
201 std::bind2nd(std::divides<T>(), val));
208 if(this->nrows() != array.
nrows() || this->ncols() != array.
ncols()) {
209 throw SizeError(
"Matrix::operator+=()",
"Dimensions inconsistent.");
211 std::transform(this->begin(), this->end(), array.
begin(), this->begin(),
219 if(this->nrows() != array.
nrows() || this->ncols() != array.
ncols()) {
220 throw SizeError(
"Matrix::operator-=()",
"Dimensions inconsistent.");
222 std::transform(this->begin(), this->end(), array.
begin(), this->begin(),
230 if(this->nrows() != this->ncols()) {
231 throw SizeError(
"Matrix::operator+=()",
"Matrix is not square.");
233 int n =
std::min(this->nrows(), this->ncols());
234 for(
int i = 0; i <
n; i++) this->col_begin(i)[i] += val;
241 if(this->nrows() != this->ncols()) {
242 throw SizeError(
"Matrix::operator-=()",
"Matrix is not square.");
244 int n =
std::min(this->nrows(), this->ncols());
245 for(
int i = 0; i <
n; i++) this->col_begin(i)[i] -= val;
252 *
this = (*this).dotm(array);
259 int nr = this->nrows();
260 int nc = this->ncols();
263 for(
int i = 0; i <
nr; ++i) {
264 std::copy(this->row_begin(i), this->row_end(i), R.
col_begin(i));
277 return result += rhs;
284 return result -= rhs;
291 std::transform(arg.
begin(), arg.
end(), result.begin(), std::negate<T>());
298 return lhs.
dotm(rhs);
340 if(this->ncols() != B.
nrows()) {
341 throw SizeError(
"Matrix::dotm()",
"Inconsistent dimensions.");
344 const int nr1 = this->nrows();
345 const int nc2 = B.
ncols();
348 for(
int i = 0; i < nr1; i++) {
352 for(
int j = 0; j < nc2; j++) {
353 R(i, j) = std::inner_product(i1, i2, B.
col_begin(j),
T(0));
362 if(this->ncols() != B.
size()) {
363 throw SizeError(
"Matrix::dotcv()",
"Inconsistent dimensions.");
366 int nr = this->nrows();
369 for(
int i = 0; i <
nr; ++i) {
370 R(i) = std::inner_product(this->row_begin(i), this->row_end(i), B.
begin(),
379 if(this->nrows() != B.
size()) {
380 throw SizeError(
"Matrix::dotrv()",
"Inconsistent dimensions.");
383 int nc = this->ncols();
386 for(
int j = 0; j < nc; j++) {
387 R(j) = std::inner_product(B.
begin(), B.
end(), this->col_begin(j),
T(0));
393 #endif // CLASSIC_Matrix_HH
Matrix< T > operator+(const Matrix< T > &, const Matrix< T > &)
Matrix addition.
Array2D< T > & operator=(const Array2D< T > &)
iterator begin()
Get pointer to beginning of data.
Matrix< T > operator/(const Matrix< T > &, const T &)
Matrix divided by scalar.
Matrix< T > & operator/=(const T &)
Divide by scalar and assign.
col_iterator col_begin(int c)
Get column iterator.
iterator end()
Get end of data.
int ncols() const
Get number of columns.
Matrix< T > operator*(const Matrix< T > &, const Matrix< T > &)
Matrix multiply.
Vector< T > dotrv(const Vector< T > &) const
Row vector times matrix.
int size() const
Get array size.
const T * const_row_iterator
The iterator type for access by rows for a constant array.
Matrix< T > transpose() const
Matrix transpose.
iterator begin()
Get beginning of data.
Matrix< T > & operator+=(const Matrix< T > &)
Add matrix and assign..
Matrix< T > & operator*=(const T &)
Multiply by scalar and assign.
iterator end()
Get pointer past end of data.
Matrix< T > & operator-=(const Matrix< T > &)
Subtract matrix and assign.
Vector< T > dotcv(const Vector< T > &) const
Matrix times column vector.
Matrix< T > dotm(const Matrix< T > &) const
Matrix product.
Matrix< T > operator-(const Matrix< T > &, const Matrix< T > &)
Matrix subtraction.
int nrows() const
Get number of rows.
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Matrix< T > & operator=(const Matrix< T > &)
Matrix()
Default constructor.