1 #ifndef CLASSIC_Matrix_HH
2 #define CLASSIC_Matrix_HH
57 Matrix(
int rows,
int cols,
const T &t);
166 for(
int i =
std::min(rows, cols); i-- > 0;) {
167 this->
data[i * (cols + 1)] =
T(1);
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.");
220 if(this->nrows() != array.
nrows() || this->ncols() != array.
ncols()) {
221 throw SizeError(
"Matrix::operator-=()",
"Dimensions inconsistent.");
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) {
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));
394 #endif // CLASSIC_Matrix_HH
Matrix< T > & operator*=(const T &)
Multiply by scalar and assign.
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a copy
Vector< T > dotcv(const Vector< T > &) const
Matrix times column vector.
iterator begin()
Get pointer to beginning of data.
iterator end()
Get pointer past end of data.
Matrix< T > & operator-=(const Matrix< T > &)
Subtract matrix and assign.
Matrix< T > operator-(const Matrix< T > &, const Matrix< T > &)
Matrix subtraction.
int size() const
Get array size.
Matrix()
Default constructor.
int ncols() const
Get number of columns.
Matrix< T > & operator/=(const T &)
Divide by scalar and assign.
int nrows() const
Get number of rows.
const T * const_row_iterator
The iterator type for access by rows for a constant array.
Matrix< T > operator*(const Matrix< T > &, const Matrix< T > &)
Matrix multiply.
clearpage the user may choose between constant or variable radius This model includes fringe fields begin
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Vector< T > dotrv(const Vector< T > &) const
Row vector times matrix.
iterator begin()
Get beginning of data.
Matrix< T > operator+(const Matrix< T > &, const Matrix< T > &)
Matrix addition.
iterator end()
Get end of data.
col_iterator col_begin(int c)
Get column iterator.
Matrix< T > transpose() const
Matrix transpose.
Matrix< T > & operator=(const Matrix< T > &)
Array2D< T > & operator=(const Array2D< T > &)
Matrix< T > operator/(const Matrix< T > &, const T &)
Matrix divided by scalar.
Matrix< T > dotm(const Matrix< T > &) const
Matrix product.
Matrix< T > & operator+=(const Matrix< T > &)
Add matrix and assign..