1 #ifndef CLASSIC_Matrix_HH
2 #define CLASSIC_Matrix_HH
194 std::bind(std::multiplies<T>(), std::placeholders::_2, val));
202 std::bind(std::divides<T>(), std::placeholders::_2, val));
209 if(this->nrows() != array.
nrows() || this->ncols() != array.
ncols()) {
210 throw SizeError(
"Matrix::operator+=()",
"Dimensions inconsistent.");
212 std::transform(this->
begin(), this->
end(), array.
begin(), this->begin(),
220 if(this->nrows() != array.
nrows() || this->ncols() != array.
ncols()) {
221 throw SizeError(
"Matrix::operator-=()",
"Dimensions inconsistent.");
223 std::transform(this->
begin(), this->
end(), array.
begin(), this->begin(),
231 if(this->nrows() != this->ncols()) {
232 throw SizeError(
"Matrix::operator+=()",
"Matrix is not square.");
234 int n =
std::min(this->nrows(), this->ncols());
235 for(
int i = 0; i <
n; i++) this->col_begin(i)[i] += val;
242 if(this->nrows() != this->ncols()) {
243 throw SizeError(
"Matrix::operator-=()",
"Matrix is not square.");
245 int n =
std::min(this->nrows(), this->ncols());
246 for(
int i = 0; i <
n; i++) this->col_begin(i)[i] -= val;
253 *
this = (*this).dotm(array);
260 int nr = this->nrows();
261 int nc = this->ncols();
264 for(
int i = 0; i <
nr; ++i) {
265 std::copy(this->row_begin(i), this->row_end(i),
R.col_begin(i));
278 return result += rhs;
285 return result -= rhs;
292 std::transform(
arg.begin(),
arg.end(), result.
begin(), std::negate<T>());
299 return lhs.
dotm(rhs);
341 if(this->ncols() != B.
nrows()) {
342 throw SizeError(
"Matrix::dotm()",
"Inconsistent dimensions.");
345 const int nr1 = this->nrows();
346 const int nc2 = B.
ncols();
349 for(
int i = 0; i < nr1; i++) {
353 for(
int j = 0; j < nc2; j++) {
354 R(i, j) = std::inner_product(i1, i2, B.
col_begin(j),
T(0));
363 if(this->ncols() != B.
size()) {
364 throw SizeError(
"Matrix::dotcv()",
"Inconsistent dimensions.");
367 int nr = this->nrows();
370 for(
int i = 0; i <
nr; ++i) {
371 R(i) = std::inner_product(this->row_begin(i), this->row_end(i), B.
begin(),
380 if(this->nrows() != B.
size()) {
381 throw SizeError(
"Matrix::dotrv()",
"Inconsistent dimensions.");
384 int nc = this->ncols();
387 for(
int j = 0; j < nc; j++) {
388 R(j) = std::inner_product(B.
begin(), B.
end(), this->col_begin(j),
T(0));
Matrix< T > operator+(const Matrix< T > &, const Matrix< T > &)
Matrix addition.
Matrix< T > operator/(const Matrix< T > &, const T &)
Matrix divided by scalar.
Matrix< T > operator*(const Matrix< T > &, const Matrix< T > &)
Matrix multiply.
Matrix< T > operator-(const Matrix< T > &, const Matrix< T > &)
Matrix subtraction.
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
PartBunchBase< T, Dim >::ConstIterator begin(PartBunchBase< T, Dim > const &bunch)
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
iterator begin()
Get beginning of data.
int size() const
Get array size.
iterator end()
Get end of data.
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.
Array2D< T > & operator=(const Array2D< T > &)
col_iterator col_begin(int c)
Get column iterator.
int ncols() const
Get number of columns.
Vector< T > dotrv(const Vector< T > &) const
Row vector times matrix.
Matrix< T > transpose() const
Matrix transpose.
Matrix< T > & operator-=(const Matrix< T > &)
Subtract matrix and assign.
Matrix< T > & operator*=(const T &)
Multiply by scalar and assign.
Matrix< T > & operator=(const Matrix< T > &)
Matrix()
Default constructor.
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 > &)
Add matrix and assign..
Matrix< T > & operator/=(const T &)
Divide by scalar and assign.