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

Copy values in a comma-separated list into this Matrix.

This assignment operator allows the user to copy the values in a bare, comma-separated, list into this Matrix. The list should have no more elements in it than the Matrix has elements. If the list has fewer elements than the Matrix, it will be recycled until the Matrix is full.

If you wish to convert a concrete Matrix to a scalar-valued Matrix object you need to explicitly promote the scalar to a Matrix, using the parameterized type constructor (Matrix(T_type)).

Parameters:
xThe first element in the list.
See also:
operator=(const Matrix&)
operator=(const Matrix<T_type, O, S>&)
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()

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;
}