chsvlib
chsv helper source code

◆ FixedMatrix() [11/15]

FixedMatrix ( const std::vector< value_t, alloc_t > &  v,
array_interpretation_t  vector_interpretation,
const allocator_type alloc = allocator_type() 
)

Creates a fixed size matrix from a set of its elements given by a vector object. .

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> 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 a product of the ColumnCount and the RowCount template parameters.
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>
std::ostream& operator<<(std::ostream& os, const Chusov::Math::Matrix<value_t, alloc_t, derived_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::FixedMatrix<double, 4, 2>(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.
Specializes the Matrix template for fixed-sized matrices.
Definition: chsvmath.h:8765
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::InvalidParameterExceptionA product of the class template parameters ColumnCount and/or RowCount is greater than
v.size();
.