chsvlib
chsv helper source code

◆ Matrix() [12/16]

Matrix ( const std::vector< value_t, alloc_t > &  v,
typename std::vector< value_t, alloc_t >::size_type  cColumns,
typename std::vector< value_t, alloc_t >::size_type  cRows,
interpretation_t  vector_interpretation,
const allocator_type alloc = allocator_type() 
)

Creates a matrix from an std::vector of elements copied to the constructed matrix as a set of rows or as a set of columns depending on the interpretation mark.

Template Parameters
value_tis a type of elements of the input vector to be explicitly converted into value_type.
alloc_tis a type of an allocator object used by the vector specified as the input parameter.
interpretation_tis a type of the vector_interpretation parameter denoting a way to copy the data elements into the matrix.
Parameters
vis an std::vector<value_t,alloc_t> set of elements to be explicitly converted to elements of the value_type type and stored within the internal storage of the matrix created with respect to other parameters. The input vector must contain at least a number of elements that is determined as a product of a number of columns and a number of rows, both of which are specified parametrically. This product defines a number of elements that will be read from the vector and copied to the internal storage.
cColumnsis a number of columns in the created matrix.
cRowsis a number of rows in the created matrix.
vector_interpretationis an interpretation mark which is set to either interpret_array_as_matrix_rows_set to specify that the input vector specifies a set of adjacent rows, or interpret_array_as_matrix_columns_set to interpret the vector as a set of adjacent columns.
allocis an allocator object used to manage storage of the matrix elements.

Example code:

#include <iostream>
#include <vector>
#include <iomanip>
template <class value_t, class alloc_t, class derived_t, class policy_t>
std::ostream& operator<<(std::ostream& os, const Chusov::Math::Matrix<value_t, alloc_t, derived_t, policy_t>& m)
{
for (std::size_t iRow = 0; iRow < m.Rows(); ++iRow)
{
os << '[';
for (auto& c:m)
{
os << ' ' << std::setw(3) << c[iRow];
}
os << "]\n";
}
return os;
}
int main(int, char**)
{
std::vector<double> v =
{
1, 2, 3, 4,
4, 3, 2, 1
};
//Also, the following expression is valid and has the same effect:
//auto m1 = Chusov::Math::Matrix<double>(v, 4, 2);
std::cout << "m1:\n" << m1;
std::cout << "m2:\n" << m2;
std::cout << std::boolalpha << "m1 == m2.Transpose() is " << (m1 == m2.Transpose()) << "\n";
std::cout << std::boolalpha << "m2 == m1.Transpose() is " << (m1.Transpose() == m2) << "\n";
return 0;
}
mathematical and arithmetical functions mostly over integer operands.
A class template for matrices of elements of various types and semantics, including types which do no...
Definition: chsvmath.h:6374
size_type Rows() const
Returns a number of rows in the current matrix.
Exceptions
Chusov::Exceptions::InvalidParameterExceptionThe values of cColumns and cRows do not correspond to a size of the input vector v (i.e. size of the vector is less than a result of multiplication of cColumns and cRows).