Scythe-1.0.3
template<typename T_type = double, matrix_order ORDER = Col, matrix_style STYLE = Concrete>
Matrix& scythe::Matrix< T_type, ORDER, STYLE >::operator= ( const Matrix< T_type, ORDER, STYLE > &  M) [inline]

Returns single element in matrix as scalar type.

This method converts a matrix object to a single scalar element of whatever type the matrix is composed of. The method simply returns the element at position zero; if error checking is turned on the method with throw an error if the matrix is not, in fact, 1x1.

Exceptions:
scythe_conformation_error(Level 1)

Assign the contents of one Matrix to another.

Like copy construction, assignment works differently for concrete matrices than it does for views. When you assign to a concrete Matrix it resizes itself to match the right hand side Matrix and copies over the values. Like all resizes, this causes this Matrix to detach() from its original DataBlock. This means that any views attached to this Matrix will no longer view this Matrix's data after the assignment; they will continue to view this Matrix's previous DataBlock. When you assign to a view it first checks that the right hand side conforms to its dimensions (by default, see below), and then copies the right hand side values over into its current DataBlock, overwriting the current contents.

Scythe also supports a slightly different model of view assignment. If the user compiled her program with the SCYTHE_VIEW_ASSIGNMENT_RECYCLE flag set then it is possible to copy into a view that is not of the same size as the Matrix on the right hand side of the equation. In this case, the operator copies elements from the right hand side object into this matrix until either this matrix runs out of room, or the right hand side one does. In the latter case, the operator starts over at the beginning of the right hand side object, recycling its values as many times as necessary to fill the left hand side object. The SCYTHE_VIEW_ASSIGNMENT_RECYCLE flag does not affect the behavior of the concrete matrices in any way.

Parameters:
MThe Matrix to copy.
See also:
operator=(const Matrix<T_type, O, S>&)
operator=(T_type x)
operator=(ListInitializer<T_type, ITERATOR, O, S>)
Matrix(const Matrix&)
Matrix(const Matrix<T_type, O, S> &)
Matrix(const Matrix<S_type, O, S> &)
copy()
copy(const Matrix<T_type, O, S> &)
reference(const Matrix<T_type, O, S> &)
resize(uint, uint, bool)
detach()
Exceptions:
scythe_conformation_error(Level 1)
scythe_alloc_error(Level 1)

Example:

#include <scythestat/matrix.h>
using namespace scythe;

/* This example shows how to use the various overloaded versions of
 * the Matrix class assignment operator.
 */

int main ()
{
  // Construct a few uninitialized matrices
  Matrix<> A(3, 3, false);
  Matrix<> B(3, 3, false);
  Matrix<> C(5, 5, false);

  // Use operator= (T_type) to fill A with values.
  A = 1, 0, 1, 0, 1, 0, 1, 0, 1;

  // Now, use it in a slightly different way to fill B
  B = 1, 0;

  // Prints true (1)
  std::cout << A.equals(B) << "\n";

  // Concrete matrices resize and disengage their underlying data
  // block when assigned to.
  Matrix<double,Col,View> CC(C);
  C = A; // uses operator=(const Matrix&)

  // Prints true false (10)
  std::cout << A.equals(C) << CC.equals(C) << "\n";

  // When you assign to a view, it copies the elements into its
  // current viewing area.
  Matrix<double,Row,View> AA (A);
  C = 1, 2, 3;
  AA = C; // uses operator=(const Matrix<T_type, O, S>&)

  // Prints true (1)
  std::cout << A.equals(C) << "\n";

  // Now, let's do a submatrix assignment.  This invokes the
  // assignment operator on a view in an indirect fashion.
  A(1,1,2,2) = Matrix<>(2, 2, true, 4); // uses operator=(const Matrix<T_type, O, S>&)

  // This is another indirect view assignment, this time using an
  // initialization list.
  A(0, 0, 1, 1) = 1, 0; // uses operator=(T_type)

  /* Prints:
   * 1.000000 1.000000 1.000000
   * 0.000000 0.000000 4.000000
   * 3.000000 4.000000 4.000000
   */
  std::cout << A << "\n";

  // This code will only work when the compiler flag
  // SCYTHE_VIEW_ASSIGNMENT_RECYCLE is set.  Otherwise it will raise
  // an exception.
  CC = AA; // uses operator=(const Matrix<T_type, O, S>&)

  /* Prints:
   * 1.000000 4.000000 0.000000 1.000000 3.000000
   * 0.000000 1.000000 3.000000 4.000000 1.000000
   * 3.000000 4.000000 1.000000 4.000000 0.000000
   * 1.000000 4.000000 0.000000 1.000000 4.000000
   * 0.000000 1.000000 4.000000 0.000000 1.000000
   */
  std::cout << CC << "\n";

  /* Here's another example of SCYTHE_VIEW_ASSIGNMENT_RECYCLE only
   * code, but it also illustrates chained assignments.  The way the
   * concretes and views interact here is somewhat subtle.
   *
   * The parentheses here are required if you want the list to be
   * processed before the assignments in the chain, because the
   * assignment operator has precedence over the comma operator.
   *
   * We're using operator=(T_type), 
   * operator=(const Matrix<T_type, O, S>&), and 
   * operator=ListInitializer<T_type, ITERATOR, O, S> li here.
   */
  C = AA = B = (CC = 1, 2);

  // Prints "9 25, 9 25"
  std::cout << C.size() << " " << B.size() << ", "
            << AA.size() << " " << CC.size() << "\n";

  return 0;
}