📄 const.htm
字号:
<html>
<head>
<link rel=stylesheet href="styles.css" type="text/css">
<title>Matrix constructors and destructor</title>
</head>
<body>
<h6 align=right>
Prev |
<a href="manual.htm">Up</a> |
<a href="submat.htm">Next</a>
</h6>
<h2>Constructors and destructor</h2>
<p>
The following constructors are available for the matrix class.
</p>
<pre><code><a href="#c1">1</a>. matrix ();
<a href="#c2">2</a>. matrix (size_t <i>nRow</i>, size_t <i>nCol</i>);
<a href="#c3">3</a>. matrix (size_t <i>nRow</i>, size_t <i>nCol</i>, const T& <i>e</i>);
<a href="#c4">4</a>. matrix (size_t <i>nRow</i>, size_t <i>nCol</i>, const T* <i>Array</i>, MatArrayType <i>aType</i> = C_ARRAY);
<a href="#c5">5</a>. matrix (size_t <i>nRow</i>, size_t <i>nCol</i>, const valarray<T>& <i>vec</i>);
<a href="#c6">6</a>. matrix (const matrix<T>& <i>m</i>);
<a href="#c7">7</a>. template <class X> matrix (const matrix<X>& <i>m</i>);
~<a href="#c8">8</a>. matrix ();
</code></pre>
<p>
Constructs a matrix class object.
</p>
<h4>Parameter</h4>
<p>
<dl>
<dt><i>nRow</i></dt>
<dd>Number of rows in the matrix.</dd>
<dt><i>nCol</i></dt>
<dd>Number of columns in the matrix.</dd>
<dt><i>e</i></dt>
<dd>Initialization value for all matrix elements.</dd>
<dt><i>Array</i></dt>
<dd>Address of an array of type <b>T</b> to initialize the elements of the matrix. The number of elements in the array must be at least equal to the number of elements in the matrix class, i.e., nRow X nCol.</dd>
<dt><i>aType</i></dt>
<dd>Memory layout of the array, i.e., it can be of "C" style (<i>C_ARRAY</i>) or Fortran style (<i>FORTRAN_ARRAY</i>). The default value for this parameter is <i>C_ARRAY</i>.</dd>
<dt><i>vec</i></dt>
<dd>Reference to a <i>valarray</i> class object to initialize the matrix elements. The size of the <i>vec</i> must be at least equal to the number of elements in the matrix class, i.e., nRow X nCol.</dd>
<dt><i>m</i></dt>
<dd>Reference to a <i>matrix</i> object to copy from.</dd>
<dt><i>m</i></dt>
<dd>Reference to a <i>matrix</i> object of type <b>X</b> to copy from.</dd>
</dl>
</p>
<p>
<ol>
<li><a name="c1">Constructs</a> a matrix object with zero element. This constructor is provided only for constructing array of matrix objects. The size should always be provided for single matrix object because zero size matrix object can't be used any operations.</li><br><br>
<li><a name="c2">Constructs</a> a matrix object of size <i>nRow</i> by <i>nCol</i> with uninitialized elements.</li><br><br>
<li><a name="c3">Constructs</a> a matrix object of size <i>nRow</i> by <i>nCol</i> with all elements initialized equal to the value of <i>e</i>. </li><br><br>
<li><a name="c4">Constructs</a> a matrix object of size <i>nRow</i> by <i>nCol</i> with elements initialized from the <i>Array</i>.</li><br><br>
<li><a name="c5">Constructs</a> a matrix object of size <i>nRow</i> by <i>nCol</i> with elements initialized from the valarray <i>vec</i>. </li><br><br>
<li><a name="c6">Constructs</a> a new matrix object by copying from an existing matrix object <i>m</i>.</li><br><br>
<li><a name="c7">Constructs</a> a matrix object from an existing matrix object of type <i>X</i>. The compiler must have support for member template for this constructor to work.</li><br><br>
<li><a name="c8">Destroys</a> a matrix object. The memory of the matrix object is not freed immediately, but kept in a small cache for future use to gain some performance. The default cache size, determined by the constant <i>MAX_MATRIX_CACHE</i>, is 4.</li><br><br>
</ol>
</p>
<h5>Examples</h5>
<pre><code>typedef matrix<double> Matrix;
typedef matrix<complex<double> > CMatrix;
Matrix m(3,3); // Constructs a 3 X 3 matrix
Matrix m2(3,3,1.0); // Constructs a 3 X 3 matrix with
// elements initialized to 1.0
CMatrix cm(4,4); // Constructs a 4 X 4 matrix of type complex<double>
float fv[] = { 1.34f, 2.54f, 8.23f,
7.34f, -2.3f, 2.45f,
-1.2f, 4.50f, 7.34f };
matrix<float> mf( 3,3,fv); // Constructs a matrix object from "C" array fv
matrix<float> mf2( 3,3,fv,FORTRAN_ARRAY); // Constructs a matrix object from Fortran array fv
matrix<float> mf3 = mf;
valarray<float> vf( fv,9);
matrix<float> mf4( 3,3,vf);
Matrix ma[5]; // Constructs an array of matrix objects
for (size_t i=0; i < 5; i++)
ma[i].resize( 4, 4); // Resize the matrix objects before use
Matrix md = mf; // Requires member template support
CMatrix cm2 = m2; // Requires member template support
</code></pre>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -